Solved Can't disable certain commands with arguments

Discussion in 'Plugin Development' started by sgavster, Feb 24, 2016.

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

    sgavster

    I'm working on a plugin but I can't disable certain commands, the ones I want to work won't:

    Code:
        @EventHandler
        public void onCommand(PlayerCommandPreprocessEvent e) {
            Player p = e.getPlayer();
            if(InGame.contains(p)) {
                if(!e.getMessage().equalsIgnoreCase("paintball leave") || !e.getMessage().equalsIgnoreCase("paintball forceend") || !e.getMessage().equalsIgnoreCase("paintball l") || !e.getMessage().equalsIgnoreCase("paintball fe")) {
                    e.setCancelled(true);
                    p.sendMessage("§4Paintball> §c§oYou can't use that command in the arena, you can do /paintball leave.");
                }
            }
        }
    Thanks for any help.
     
  2. Offline

    Zombie_Striker

    @sgavster
    Are you sure those are the exact commands the player will send? If you're trying to stop the player from using the "paintball" commands, you can test if the message.toLowerCase().startsWith("paintball"). This will return true if the command starts with the command "paintball", meaning you just have to test for this one command.
     
  3. Offline

    sgavster

    @Zombie_Striker I want them to beable to use /paintball join, /paintball j, /paintball forceend, /paintball fe but it blocks all commands.
     
  4. Offline

    ItsMas_

    You need to put the "/" in front of the message :p

    Should be:
    Code:
    if(!e.getMessage().equalsIgnoreCase("/paintball leave") || !e.getMessage().equalsIgnoreCase("/paintball forceend") || !e.getMessage().equalsIgnoreCase("/paintball l") || !e.getMessage().equalsIgnoreCase("/paintball fe")) {
     
  5. Offline

    sgavster

    @ItsMas_ I tried that, I'll try it again..
    EDIT: Still doesn't work: Current Code:

    Code:
        @EventHandler
        public void onCommand(PlayerCommandPreprocessEvent e) {
            Player p = e.getPlayer();
            if(InGame.contains(p)) {
                if(!e.getMessage().equalsIgnoreCase("/paintball leave") || !e.getMessage().equalsIgnoreCase("/paintball forceend") || !e.getMessage().equalsIgnoreCase("/paintball l") || !e.getMessage().equalsIgnoreCase("/paintball fe")) {
                    e.setCancelled(true);
                    p.sendMessage("§4Paintball> §c§oYou can't use that command in the arena, you can do /paintball leave.");
                }
            }
        }
     
    Last edited: Feb 24, 2016
  6. Offline

    Zombie_Striker

    @sgavster
    So if it's NOT Paintball Leave OR it is NOT Paintball forceend.... cancel it.

    Having both the NOTs and the ORs mean that this if statement will allways be true, even if the command send is the one you're testing for.
     
  7. Offline

    sgavster

Thread Status:
Not open for further replies.

Share This Page