Solved Permission nodes within plugin.

Discussion in 'Plugin Development' started by TidalRyan, Oct 16, 2016.

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


    Expected outcome: If player has x permission, let them have coloured chat (after their coloured tags), else they have uncoloured chat (after their coloured tags).

    Actual result: Noone gets coloured chat.

    Have tried: Stripping chatcolors, translating alternate colours.

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    public class TaroChat implements Listener {
        public void onChat(AsyncPlayerChatEvent event){
            Player player = event.getPlayer();
            String sender = event.getPlayer().getName();
            String message = event.getMessage();
            String first = message.substring(0, 1);
            String chattype;
            int radius;
                chattype = ChatColor.DARK_GREEN + "[G]";
                radius = -1;
            } else if(first.equals(".")){
                chattype = ChatColor.DARK_GRAY + "[W]";
                radius = 5;
            } else {
                chattype = ChatColor.LIGHT_PURPLE + "[L]";
                radius = 50;
                Bukkit.broadcastMessage(chattype + " " + ChatColor.RESET + sender + ": " + ChatColor.translateAlternateColorCodes('&', message));       
            } else {
            Bukkit.broadcastMessage(chattype + " " + ChatColor.RESET + ChatColor.stripColor(sender + ": " + message));
  2. Offline

    I Al Istannen

    Debug. Place a sysout in the if statement and see if it gets through.
    TidalRyan likes this.
  3. Offline


    As Al stated, try some debug messages by printing some random strings and see where it gets to..
    Also, I have to ask... Are you registering your events?
  4. Offline


    Considering you only use "sender"twice, and you only use player once, there is no need to create these variables. Delete them, and adjust your code accordingly.

    Not only is this variable easy to get to, this is only used twice. Same as above.

    Why not use charAt if you're looking just for the first char? Using this method, you are creating another string instance that just contains 1 character.

    Main problem: Have you debuged? Are you registering this class?
    I Al Istannen likes this.
  5. Offline


    public void onEnable(){
         PluginManager pm = Bukkit.getServer().getPluginManager();
         pm.registerEvents(<yourclass>(), this);
         Bukkit.getServer().getLogger().info("[Startup] Registered your listeners"); // DEBUG CODE
    Omg just realised what you might of done

    Replace "Bukkit.broadcastMessage(msg)" with "Bukkit.getServer().broadcastMessage()" or "e.setFormat("")"

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
  6. Offline


    A little reference for you: The whole "I expected this but got an unexpected result" thing is called a semantic error.
    TidalRyan likes this.
  7. Offline


    I will try debugging. Yes, they are registered.

    Will make changes accordingly, thanks.

    Makes no difference?
Thread Status:
Not open for further replies.

Share This Page