No longer blocking these commands

Discussion in 'Plugin Development' started by Fhbgsdhkfbl, Nov 29, 2015.

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

    Fhbgsdhkfbl

    Hey guys, I made a chat enable/disable so players can't talk or use certain commands whilst it's disabled.

    it worked for awhile, but now it doesn't work since I updated the plugin?

    if there's another way to do it, let me know.

    Code:
    @EventHandler
        public void onChatDisabled(PlayerCommandPreprocessEvent e) {
            Player p = e.getPlayer();
            if ((this.chatDisabled) && (!p.hasPermission("p.mod"))) {
                if(e.getMessage().equalsIgnoreCase("me") && e.getMessage().equalsIgnoreCase("r") && e.getMessage().equalsIgnoreCase("msg") && e.getMessage().equalsIgnoreCase("tell") && e.getMessage().equalsIgnoreCase("t") && e.getMessage().equalsIgnoreCase("afk")) {
                    e.setCancelled(true);
                    e.getPlayer().sendMessage(ChatColor.GOLD + "[]" + ChatColor.RED + " Chat is currently disabled!");
                }
            }
        }
     
  2. Offline

    Zombie_Striker

    A) Why are you checking like this? All you need is to add a space/period/anything else and it will allow it.
    B) P is only used once. Please remove it.
     
  3. Offline

    Scimiguy

    Well that event will disable certain commands
    Where's the event to disable chat?

    Have you registered your events?
    Are you getting any errors?
    Is your plugin showing up in /plugins?
    ?
    Cake?
     
  4. Offline

    Fhbgsdhkfbl

    I already said, it worked before, now it doesn't. Yes the plugin shows up in the plugins list, no errors, it's a boolean in a command to disable/enable chat
     
  5. Offline

    Scimiguy

    Don't really care that it worked before. It doesn't now, and that's why we're here.

    Did you try debugging?
     
  6. Offline

    Lordloss

    Maybe thats your problem...
     
  7. Offline

    Mrs. bwfctower

    @Fhbgsdhkfbl
    I'm sorry, will this ever be true?
     
    Zombie_Striker likes this.
  8. Offline

    Lordloss

    It will not be true because if you use commands like msg, r, tell etc. this will never be the whole command. And equalsIgnoreCase obviously checks for the whole string. perhaps it will work with a combination of toLowerCase and startsWith
     
  9. Offline

    Scimiguy

    @Lordloss
    That was implied -.-
    Google "Rhetorical"
     
    Zombie_Striker likes this.
  10. Offline

    Xerox262

    Could also be that @Mrs. bwfctower was referring to the actual logic behind it, as in. How can a message be both "msg" AND "r" regardless of the rest of the message.

    Aka, if they were all changed to startsWith() it still wouldn't work, because he's using ands, not ors.
     
  11. Offline

    Lordloss

  12. Offline

    Mrs. bwfctower

Thread Status:
Not open for further replies.

Share This Page