Solved Why isn't this code working?

Discussion in 'Plugin Development' started by Urag, Jul 17, 2016.

Thread Status:
Not open for further replies.
  1. Code:
        @EventHandler
        public void onPlayerCommandPreprocessEvent(PlayerCommandPreprocessEvent e){
            if(!e.getMessage().equalsIgnoreCase("/changepassword") || !e.getMessage().equalsIgnoreCase("/changepass") || !e.getMessage().equalsIgnoreCase("/unreg") || !e.getMessage().equalsIgnoreCase("/unregister") || !e.getMessage().equalsIgnoreCase("/reply") || !e.getMessage().equalsIgnoreCase("/r") || !e.getMessage().equalsIgnoreCase("/reg") || !e.getMessage().equalsIgnoreCase("/register") || !e.getMessage().equalsIgnoreCase("/l") || !e.getMessage().equalsIgnoreCase("/login") || !e.getMessage().equalsIgnoreCase("/spawn") || !e.getMessage().equalsIgnoreCase("/w") || !e.getMessage().equalsIgnoreCase("/whisper") || !e.getMessage().equalsIgnoreCase("/ewhisper") || !e.getMessage().equalsIgnoreCase("/t") || !e.getMessage().equalsIgnoreCase("/tell") || !e.getMessage().equalsIgnoreCase("/etell") || !e.getMessage().equalsIgnoreCase("/msg") || !e.getMessage().equalsIgnoreCase("/m") || !e.getMessage().equalsIgnoreCase("/emsg") || !e.getMessage().equalsIgnoreCase("/?") || !e.getMessage().equalsIgnoreCase("/informacje") || !e.getMessage().equalsIgnoreCase("/regulamin") && !e.getPlayer().hasPermission("commandblocker.prevent")) {
                e.setCancelled(true);
                e.getPlayer().sendMessage("§f§lUnknown command.");
            }
        }
    I have "commandblocker.prevent" permission, but plugin blocks all commands.
     
  2. Offline

    mine-care

    Why not putting the allowed commands in a data structure such as an array or a Collection Instead of countless or operators?
    Have you debuged the code?
     
  3. @Urag Check your backets.
     
  4. @mine-care
    I'm noob-programmer. I only know basics, but i'm trying to make plugins instead of using Skript. What does mean "debugging code"? How to chceck if command is one from the allowed comamnds list?

    @bwfcwalshy
    Bracket's are fine
     
    Last edited: Jul 17, 2016
  5. Debugging is a procedure to try to figure the problem with your own code by inserting new "test code". This is often done with putting print statements in certain parts of the code to see whether certain code is run.
     
  6. You sure about that? Your if statement wont fire correctly. Check your brackets, remember Java is kinda like maths

    1 + 6 * 2 is different than (1 + 6) * 2
     
  7. Isn't this code working, beacuse i didn't mark arguments in commands?
     
  8. Offline

    iSexyChocobo

    Code:
         List<String> whitelist = Arrays.asList(new String[] {
                "/command1", "/command2", "command3", "command4"
                });
    //Put your commands in a list like this
    
    //then to check if it is not part of the whitelist
    //to lowercase to allow both /cOMMand and /command
    if(!whitelist.contains(e.getMessage().toLowerCase())){
    //permission check
    if(!e.getPlayer().hasPermission("your.permission"){
    //disallow.
    e.setCancelled(true); p.sendMessage("nope!");
    }
     } 
     
    AlvinB likes this.
  9. I have a problem:
     
  10. @Urag Have you imported them? Remember to import java.util List
     
  11. Sorry, I have imported wrong list :)

    @bwfcwalshy @iSexyChocobo

    How to make this list public? I have this list in "onEnable void", and i can't get it from EventHandler.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 17, 2016
  12. @Urag Move the list out of onEnable and just into the class
     
  13. As i told - I'm noob. Thank you for help! :)
     
    iSexyChocobo likes this.
Thread Status:
Not open for further replies.

Share This Page