Need help coding Sub-Chat Channels!

Discussion in 'Plugin Development' started by DragsZombies, Sep 28, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    DragsZombies

    I'm trying to code a plugin that will make a Chat channel for players in a "party". If I used an example, Mcmmo has a /party option on it. I am wondering how I can do that. I really don't know many methods and how they work yet since I am new to modding. I want to be able to distinguish the regular chat from the party chat. I also want ops to be able to "spy" on these party chat's without being seen there. Kinda like Social spy in a way.

    I appreciate all the help I've gotten from people here!

    DragsZombies
     
  2. Offline

    andf54

    Make a HashMap<playerName, partyID>

    When someone sends a message in a party chat, loop trough the map and send the message if the receivers ID matches with the senders ID.
     
  3. Offline

    DragsZombies

    andf54 Thanks, but where could I go to find a tutorial on how to set it up?
     
  4. Hey,

    if a player types e.g. /party a boolean for his name will be turned to true [save in a hashmap].
    You should listen for the AsyncPlayerChatEvent and check if the boolean for the sender is set to true or false.
    If it's true, make a for-loop and send the message to all players whos boolean is set to true.

    Sorry for my bad english; just don't have that much time to explain, but let me know if you need example code! :)
     
  5. Offline

    DragsZombies

    Ahmet094

    Can I get an example, along with maybe, a tutorial somewhere where I could learn how to do it? I'm really new to coding. Sorry for the trouble.
     
  6. Offline

    DragsZombies

    @Ahmet084
    I would like to have players be able to make a channel, or like, have channels for Certain ranks, like one for op's or staff, donors, members, one to ask staff for help.
     
  7. Oh, that'll be more complicated; can't do this now, sry.
     
  8. Offline

    DragsZombies

    If I could get it started with one sub channel I would be happy, can you still help if it's one?
    I might just do the one and update it later.
     
  9. Yes, I'll make it^^
     
  10. Offline

    DragsZombies

    Make it? The codes? I just need a reference or the methods for it. Well, if you insist.....
     
  11. Try to understand it; not just copy-paste it, PLS! ;)

    Code:
    HashMap<String, Boolean> PartyUser = new HashMap<String, Boolean>();
     
        @EventHandler
        public void onChat(AsyncPlayerChatEvent event) {
            String pName = event.getPlayer().getName();
            if (PartyUser.get(pName) == true) {
                for (Player p : Bukkit.getOnlinePlayers()) {
                    if (PartyUser.get(p.getName()) == true) {
                        p.sendMessage(ChatColor.GOLD + "[PartyChat]" + ChatColor.GRAY + pName + ": " + ChatColor.WHITE + event.getMessage());
                        event.setCancelled(true);
                    }
                }
            }
        }
     
        @EventHandler
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (sender instanceof Player) {
     
                if (label.equalsIgnoreCase("partychat")) {
                    Player player = (Player) sender;
                    String pName = player.getName();
                    if (!PartyUser.containsKey(pName)) {
                        PartyUser.put(pName, true);
                        player.sendMessage(ChatColor.GREEN + "PartyChat activated!");
                        return true;
                    } else {
                        if (PartyUser.get(pName) == true) {
                            PartyUser.put(pName, false);
                            player.sendMessage(ChatColor.RED + "PartyChat deactivated!");
                            return true;
                        } else {
                            PartyUser.put(pName, true);
                            player.sendMessage(ChatColor.GREEN + "PartyChat activated!");
                            return true;
                        }
                    }
                }
     
            }
            return false;
        }
     
  12. Offline

    DragsZombies

    Sure thing...
     
  13. Offline

    xXSniperzzXx_SD

    so i'm gonna assume you know how to get the cmd, check the args make sure they have perms etc

    to get there message and make it a string use a string builder, i would get the code for you but i don't have eclipse open currently, just decompile a plugin that has admin chat or mod chat and you'll see a string builder


    to send the message to people with a certain permission node
    Code:
    for(Player online: getServer().getOnlinePlayers()){
      if(online.hasPermisson(Perm node here)){
        online.sendMessage(message);
      }
    } 
     
  14. Offline

    DragsZombies

    Alright, It's starting to make sense. How would I make the sub chat a different color so that it isn't mixed up from the regular chat?
     
  15. Offline

    kroltan

    Look at ChatColor.
     
  16. Offline

    DragsZombies

    Alright, Thanks!
     
  17. Offline

    Sabersamus

    Don't add
    Code:java
    1. @EventHandler
    to onCommand(...). Its not an event.
     
    kroltan likes this.
Thread Status:
Not open for further replies.

Share This Page