Solved How to make a togglechat/staffchat plugin?

Discussion in 'BungeeCord Plugin Development' started by Lyzone, Feb 10, 2018.

  1. Hi. I'm new to developing plugins and I'm wondering how to make a togglechat plugin. Since I've never done a toggle plugin, only message plugin, this is what I've got.
    Code (Text):

    @Override
        public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
            String cmd = command.getName();
            if (cmd.equalsIgnoreCase("staffchat")) {
                if (!(sender instanceof Player)) {
                    sender.sendMessage(ChatColor.RED.toString() + ChatColor.BOLD + "You must be online to perform that command.");
                    return true;
                }
                if (args.length == 0) {
                    sender.sendMessage(ChatColor.GOLD + "You must specify enable or disable!");
                }
               
                //I know this if is unnecessary
                if (args.length == 1) {
                    String enableOrDisable = args[0];
                    if (enableOrDisable.equalsIgnoreCase("enable")) {
                        boolean enable = true;
                        sender.sendMessage(ChatColor.DARK_GRAY.toString() + ChatColor.BOLD + "You have " + ChatColor.GREEN.toString() + ChatColor.BOLD + "enabled" + ChatColor.DARK_GRAY.toString() + ChatColor.BOLD + " staff chat!");
                    }
                   
                    //I know this if is unnecessary
                    if (enableOrDisable.equalsIgnoreCase("disable")) {
                        boolean enable = false;
                        sender.sendMessage(ChatColor.DARK_GRAY.toString() + ChatColor.BOLD + "You have " + ChatColor.RED.toString() + ChatColor.BOLD + "disabled" + ChatColor.DARK_GRAY.toString() + ChatColor.BOLD + " staff chat!");
                    }
                }
            }
            return true;
        }
    I know that if the sender isn't a player, chat colors wont work, but I like to put them there anyways.
    I will add the permission check later. Also, a for loop would work in this scenario, if enable = true? I was planning on putting this code in my listener class because I don't know how to retrieve booleans from another class. I'm new to Java, so go easy on me please, thanks. Not asking for code either, just a simple explanation / pseudocode will do.
     
  2. I could be missing something but im not exactly sure what you are looking for. Do you want to know what to do next? (make it go to different places) or something else? If you are looking for what to do with the message if staffchat is enabled then you want to catch the chat event and cancel it while also sending it to all online players with the staffchat permission (or who have it enabled). If you had a different question or want to know some more let me know.
     
  3. Thats why I mentioned putting it in the listener, but I don't know how because it's a command. implements Listener implements CommandExecutor? anyways someone else is helping me
     
  4. Uhh, I don't think using booleans for that is a good idea. Use HashMap<UUID, Boolean> or HashSet
     
  5. Do not use HashMap<something, Boolean> for any reason - this is just the same as a Set or List. Anyways, it's solved - him and I keep hashing these problems out over Discord.
     
  6. did you read my post? i said I've never done anything like this before, and i had no idea how to use it.
    either way, i got some help and what I got was
    Code (Text):

    private List<UUID> hasPermission = new ArrayList<UUID>();

        private List<UUID> isToggled = new ArrayList<UUID>();

        public List<UUID> getPermission() {
            return hasPermission;
        }

        public List<UUID> getToggled() {
            return isToggled;
        }
    this has been solved for days now.
     
    • Like Like x 1
  7. Oops. Sorry my bad :/
     
    • Like Like x 1
  8. he heh, hashing em' out - but don't use a HashMap. ;)
     
  9. I was gonna italicize it but I wanted to see who the intellectual to discover it would be XD
     

Share This Page