Togellable separate chat with permissions that divide who can see it and who can't

Discussion in 'Spigot Plugin Development' started by FergyEsHere, Jun 26, 2016.

  1. So I'm trying to create a plugin for prison "guards", so they can have their own private chat, that only people with that permissions can see. I have the toggle, I just need to set up permissions, but I'm not sure who to define that the toggle toggles the separate chat.
     
  2. Your ending is what make me not understand your question xD
     
  3. I just mean I'm not sure how to make it so the toggle toggles the separate chat.
     
  4. Oh well just use a boolean .. :)
     
  5. Try something like this :
    Code (Java):

    void onChat(Chat event)
     if (privateChat) //Check the toggle
      Iterator<Player> player = getReceipes().iterator //Iterator for the player

      while (iterator) //Whilte there are more players
       if(hasPermission("your.permission") //If the player has the permission just keep looping
        continue;

        iterator.remove(); //If the player doesn't have the permission then remove it
     
     
  6. Noice :)
     
  7. Code (Text):
    private List<Player> alist = new ArrayList<>();

    // a command
            if(alist.contains(sender)) {
                alist.remove(sender);
                return true;
            } else {
                alist.add(sender);
                return true;
            }

        @EventHandler
        public void playerChatEvent(AsyncPlayerChatEvent event) {
            if(alist.contains(event.getPlayer())) {
                Player sender = event.getPlayer();
                for(Player player : alist) {
                    player.sendMessage("");
                 }
                event.setCancelled(true);
            }
        }
     
    One of many ways you could go about it. Raw code, messy.
     
  8. Nice other solution :D
     
  9. Write an Object that has a hashmap for all players that should be part of a custom
    chat, then register the chat listener.

    The only thing about that is if you still want rank prefixes a such, you'll need to hook
    into various dependencies.
     
  10. player.getDisplayName();
     
  11. There are many solutions to this problem, but my preference would
    be a simple object so there is a real separation between chat groups.

    Kind of like different rooms on Team Speak.
     
  12. Firestar311

    Supporter

    I have done this before. It is chat channels. There are a few ways you can do this.
    1. Have a file that saves the channel that they are in and then get that each time that they chat using the chat event.
    2. Use an arraylist and put players in when they toggle

    On the command, just have the permission check and make sure that they are not already in that channel.
     
  13. If you don't have a lot of players an Arraylist is fine, but since their access is sequential with code efficiency O(n)
    use a Hashmap instead with efficiency O(1)
     
  14. You should use LinkedHashSet instead, for fast add/remove/contains and faster iteration (faster than a regular HashSet). Aside the fact that removing recipients and not cancelling is preferred.
    If you don't have any value, you should use Sets instead. Moreover, it's worst case running time (not efficiency) is theoretically O(1), in some cases it can actually be O(n) as well (depends on the hash function used)
     
  15. Code (Java):
    Bukkit.broadcast(String message, String node);
    // try this.

    or

    Code (Java):
    boolean private = true;
    List<Player> list = new ArrayList<>();
    for(Player player : Bukkit.getOnlinePlayers()) {
      if(player.hasPermission("perm.node") {
            list.add(player);
       }
    }
    if(private) {
      for(Player guard : list) {
      guard.sendMessage("hi to guards");
      }
    }
     
    #15 MadMaxCookie, Jun 28, 2016
    Last edited: Jun 28, 2016
  16. Your code will not compile, private = reserved word m8.
    But we get the idea.