Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BungeeCord Cross-server Flags Denizen Hook? #864

Closed
adambkehl opened this issue Oct 12, 2014 · 3 comments
Closed

BungeeCord Cross-server Flags Denizen Hook? #864

adambkehl opened this issue Oct 12, 2014 · 3 comments
Labels
Feature A new feature to add. Suggestion Possibly going to be added.

Comments

@adambkehl
Copy link
Contributor

Example implementation of BungeeCord's listeners for a cross-server messaging plugin:

package net.thegamingcraft.BungeeMsg;

import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;

import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin;

public class BungeeMsg extends Plugin
  implements Listener
{

        private Map<String, String> messagers = new HashMap<String, String>();

  public void onEnable()
  {
    getProxy().getPluginManager().registerListener(this, this);
    getProxy().getPluginManager().registerCommand(this, new Command("msg")
    {
        @SuppressWarnings("deprecation")
                public void execute(CommandSender sender, String[] args) {
                  if (args.length == 0) {
                          sender.sendMessage(ChatColor.RED + "Usage: /msg <player> <message>");
                  } else if (args.length == 1) {
                          sender.sendMessage(ChatColor.RED + "Usage: /msg <player> <message>");
                  } else {

                          if (!(sender instanceof ProxiedPlayer)) {

                                  if (args[0].equalsIgnoreCase("proxy")) {

                                          sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "You cannot send message to yourself");

                                  } else {

                                          StringBuilder str = new StringBuilder();
                                  for (int i = 1; i < args.length; i++) {
                                          str.append(args[i] + " ");
                                  }
                                  String nmessage = str.toString();
                                  String message = nmessage.replace("&", "§");
                                  ProxiedPlayer p1 = getProxy().getPlayer(args[0]);
                                  if (p1 != null) {
                                  sender.sendMessage(ChatColor.LIGHT_PURPLE + "To " + args[0] + ": " + ChatColor.RESET + message);
                                          p1.sendMessage(ChatColor.LIGHT_PURPLE + "From proxy: " + ChatColor.RESET + message);
                                        messagers.put(p1.getName(), "proxy");
                                        messagers.put("proxy", p1.getName());
                                  } else {
                                          sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Could not find player " + args[0]);
                                  }

                                  }

                          } else {

                                  if (args[0].equals(sender.getName())) {

                                          sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "You cannot send message to yourself");

                                  } else {

                  StringBuilder str = new StringBuilder();
                  for (int i = 1; i < args.length; i++) {
                          str.append(args[i] + " ");
                  }
                  String nmessage = str.toString();
                  String message = nmessage.replace("&", "§");
                  ProxiedPlayer p1 = getProxy().getPlayer(args[0]);
                  if (p1 != null) {
                  sender.sendMessage(ChatColor.LIGHT_PURPLE + "To " + args[0] + ": " + ChatColor.RESET + message);
                          p1.sendMessage(ChatColor.LIGHT_PURPLE + "From " + sender.getName() + ": " + ChatColor.RESET + message);
                        messagers.put(p1.getName(), sender.getName());
                        messagers.put(sender.getName(), p1.getName());

                        logToConsole((ProxiedPlayer) sender, p1, message);
                  } else {
                          sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Could not find player " + args[0]);
                  }
                         }
                        }
                  }
          }

    });
    getProxy().getPluginManager().registerCommand(this, new Command("tell") {
        @SuppressWarnings("deprecation")
                public void execute(CommandSender sender, String[] args) {
                  if (args.length == 0) {
                          sender.sendMessage(ChatColor.RED + "Usage: /tell <player> <message>");
                  } else if (args.length == 1) {
                          sender.sendMessage(ChatColor.RED + "Usage: /tell <player> <message>");
                  } else {

                          if (!(sender instanceof ProxiedPlayer)) {

                          if (args[0].equalsIgnoreCase("proxy")) {

                                  sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "You cannot send message to yourself");

                          } else {

                                  StringBuilder str = new StringBuilder();
                               for (int i = 1; i < args.length; i++) {
                                       str.append(args[i] + " ");
                               }
                               String nmessage = str.toString();
                               String message = nmessage.replace("&", "§");
                               ProxiedPlayer p1 = getProxy().getPlayer(args[0]);
                               if (p1 != null) {
                               sender.sendMessage(ChatColor.LIGHT_PURPLE + "To " + args[0] + ": " + ChatColor.RESET + message);
                                       p1.sendMessage(ChatColor.LIGHT_PURPLE + "From proxy: " + ChatColor.RESET + message);
                                     messagers.put(p1.getName(), "proxy");
                                     messagers.put("proxy", p1.getName());

                                     logToConsole((ProxiedPlayer) sender, p1, message);
                               } else {
                                       sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Could not find player " + args[0]);
                               }

                          }

                       } else {

                                  if (args[0].equals(sender.getName())) {

                                          sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "You cannot send message to yourself");

                                  } else {

                  StringBuilder str = new StringBuilder();
                  for (int i = 1; i < args.length; i++) {
                          str.append(args[i] + " ");
                  }
                  String nmessage = str.toString();
                  String message = nmessage.replace("&", "§");
                  ProxiedPlayer p1 = getProxy().getPlayer(args[0]);
                  if (p1 != null) {
                  sender.sendMessage(ChatColor.LIGHT_PURPLE + "To " + args[0] + ": " + ChatColor.RESET + message);
                          p1.sendMessage(ChatColor.LIGHT_PURPLE + "From " + sender.getName() + ": " + ChatColor.RESET + message);
                        messagers.put(p1.getName(), sender.getName());
                        messagers.put(sender.getName(), p1.getName());

                        logToConsole((ProxiedPlayer) sender, p1, message);
                  } else {
                          sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Could not find player " + args[0]);
                  }
                         }
                        }
                  }
          }
        });
    getProxy().getPluginManager().registerCommand(this, new Command("w") {
        @SuppressWarnings("deprecation")
                public void execute(CommandSender sender, String[] args) {
          if (args.length == 0) {
                  sender.sendMessage(ChatColor.RED + "Usage: /w <player> <message>");
          } else if (args.length == 1) {
                  sender.sendMessage(ChatColor.RED + "Usage: /w <player> <message>");
          } else {

                  if (!(sender instanceof ProxiedPlayer)) {

                  if (args[0].equalsIgnoreCase("proxy")) {

                          sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "You cannot send message to yourself");

                  } else {

                          StringBuilder str = new StringBuilder();
                       for (int i = 1; i < args.length; i++) {
                               str.append(args[i] + " ");
                       }
                       String nmessage = str.toString();
                       String message = nmessage.replace("&", "§");
                       ProxiedPlayer p1 = getProxy().getPlayer(args[0]);
                       if (p1 != null) {
                       sender.sendMessage(ChatColor.LIGHT_PURPLE + "To " + args[0] + ": " + ChatColor.RESET + message);
                               p1.sendMessage(ChatColor.LIGHT_PURPLE + "From proxy: " + ChatColor.RESET + message);
                             messagers.put(p1.getName(), "proxy");
                             messagers.put("proxy", p1.getName());

                             logToConsole((ProxiedPlayer) sender, p1, message);
                       } else {
                               sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Could not find player " + args[0]);
                       }

                  }

               } else {

                          if (args[0].equals(sender.getName())) {

                                  sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "You cannot send message to yourself");

                          } else {

                StringBuilder str = new StringBuilder();
                for (int i = 1; i < args.length; i++) {
                        str.append(args[i] + " ");
                }
                String nmessage = str.toString();
                String message = nmessage.replace("&", "§");
                ProxiedPlayer p1 = getProxy().getPlayer(args[0]);
                if (p1 != null) {
                sender.sendMessage(ChatColor.LIGHT_PURPLE + "To " + args[0] + ": " + ChatColor.RESET + message);
                  p1.sendMessage(ChatColor.LIGHT_PURPLE + "From " + sender.getName() + ": " + ChatColor.RESET + message);
                messagers.put(p1.getName(), sender.getName());
                messagers.put(sender.getName(), p1.getName());

                logToConsole((ProxiedPlayer) sender, p1, message);
                } else {
                  sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Could not find player " + args[0]);
                }
                 }
                }
          }
        }
      });
    getProxy().getPluginManager().registerCommand(this, new Command("r") {
        @SuppressWarnings("deprecation")
                public void execute(CommandSender sender, String[] args) {
                if (args.length == 0) {

                        sender.sendMessage(ChatColor.RED + "Usage: /r <message>");

                } else {

                        if (!(sender instanceof ProxiedPlayer)) {

                            if (!messagers.containsKey("proxy")) {
                                sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "You have nobody to reply to, you must reieve a message first");
                                return;
                            }

                            ProxiedPlayer target = getProxy().getPlayer(messagers.get("proxy"));
                            if (target == null) {
                                sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "The player you last got a message from is not online");
                                return;
                            }

                            StringBuilder str = new StringBuilder();
                            for (int i = 0; i < args.length; i++) {
                                    str.append(args[i] + " ");
                            }
                            String nmessage = str.toString();
                            String message = nmessage.replace("&", "§");

                            sender.sendMessage(ChatColor.LIGHT_PURPLE + "To " + target.getName() + ": " + ChatColor.RESET + message);
                            target.sendMessage(ChatColor.LIGHT_PURPLE + "From proxy: " + ChatColor.RESET + message);

                            messagers.put(target.getName(), "proxy");
                            messagers.put("proxy", target.getName());

                            logToConsole((ProxiedPlayer) sender, target, message);

                        } else {

                    if (!messagers.containsKey(sender.getName())) {

                        sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "You have nobody to reply to, you must reieve a message first");
                        return;

                    } else {

                        if (messagers.get(sender.getName()).equalsIgnoreCase("proxy")) {
                                StringBuilder str = new StringBuilder();
                            for (int i = 0; i < args.length; i++) {
                                    str.append(args[i] + " ");
                            }
                            String nmessage = str.toString();
                            String message = nmessage.replace("&", "§");

                            sender.sendMessage(ChatColor.LIGHT_PURPLE + "To proxy: " + ChatColor.RESET + message);
                            getProxy().getLogger().log(Level.INFO, ChatColor.LIGHT_PURPLE + "From " + sender.getName() + ": " + ChatColor.RESET + message);

                            messagers.put("proxy", sender.getName());
                            messagers.put(sender.getName(), "proxy");
                                return;
                        }

                        ProxiedPlayer target = getProxy().getPlayer(messagers.get(sender.getName()));
                        if (target == null) {

                                sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "The player you last got a message from is not online");

                        } else {

                            StringBuilder str = new StringBuilder();
                            for (int i = 0; i < args.length; i++) {
                                    str.append(args[i] + " ");
                            }
                            String nmessage = str.toString();
                            String message = nmessage.replace("&", "§");

                            sender.sendMessage(ChatColor.LIGHT_PURPLE + "To " + target.getName() + ": " + ChatColor.RESET + message);
                            target.sendMessage(ChatColor.LIGHT_PURPLE + "From " + sender.getName() + ": " + ChatColor.RESET + message);

                            messagers.put(target.getName(), sender.getName());
                            messagers.put(sender.getName(), target.getName());

                            logToConsole((ProxiedPlayer) sender, target, message);
                        }

                    }

                        }

                }
        }
      });    
  }

  public void logToConsole(ProxiedPlayer player, ProxiedPlayer target, String message) {
          getProxy().getLogger().log(Level.INFO, "*** BungePrivateMessage *** " + player.getName() + " to " + target.getName() + " >> " + message);
  }
}
@adambkehl
Copy link
Contributor Author

Plugin to plugin packet sending library for BungeeCord/Bukkit:
https://github.com/iKeirNez/PluginMessageAPI-Plus

@adambkehl
Copy link
Contributor Author

EDIT: Plugin requires a player to be online to execute any command with Command Sync

Plugin source that, "allows commands and more to be synced across multiple Minecraft server instances through BungeeCord."

https://github.com/YoFuzzy3/CommandSync

@mcmonkey4eva mcmonkey4eva added Suggestion Possibly going to be added. Feature A new feature to add. labels Nov 9, 2014
@mcmonkey4eva
Copy link
Member

Redirecting to DenizenScript/Depenizen#33

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature A new feature to add. Suggestion Possibly going to be added.
Projects
None yet
Development

No branches or pull requests

2 participants