How to disallow commands

Discussion in 'Plugin Development' started by lug, Nov 8, 2014.

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

    lug

    Placed my last message in the wrong place, sorry!
    Anyway, I was just wondering what code you would have to write to disallow commands, such as ban, kick etc..
    I've gotten this far
    @EventHandler
    public void PlayerCommand(PlayerCommandPreprocessEvent event) {
    Player p = event.getPlayer();
    event.setCancelled(true);
     
  2. lug
    Use the PlayerCommandPreprocessEvent#getMessage() method to get the command and compare that to the commands you want to disallow.
     
  3. Offline

    lug

    Please could you send me all the code, for an example of /ban? I can't seem to do it, thanks for the response :)
     
  4. Offline

    Googlelover1234

    lug
    It's very simple, you just check if the message starts with "/ban" and cancel it.
     
  5. Offline

    teej107

    We aren't going to spoonfeed code. And why even code? Just revoke the permission from the players that you don't want using it.

    EDIT: Googlelover1234 RIP commands that start with "/ban" but doesn't equal /ban.
     
  6. lug
    No, sorry. If you can't follow the crystal clear instructions then spoonfeeding you would only cause harm.

    The getMessage() method returns a String. You can then compare this String to another String with String#equals(anotherString). In this case, anotherString would be the command you want to block.
     
  7. Offline

    Googlelover1234

    teej107
    Well, ban commands usually take arguments, what if the message isn't just "/ban", but perhaps "/ban Hacker Hacking"
     
  8. Googlelover1234
    Then you split the String with " " and check the first index of the array :p
     
  9. Offline

    teej107

    Googlelover1234
    What if I made a command like: /banner, /banana, /ban
    I couldn't think of anything else but here: http://www.scrabblefinder.com/starts-with/ban/

    EDIT: Ninja'D by Assist. but that's the idea. Actually not really.
     
  10. Offline

    Googlelover1234

    teej107
    Alright, but let's think about this. If we use the "equals" method, you would say "e.getMessage().equals("/ban")" and block that. That's all fine and dandy, /ban would be blocked. But would it work if someone typed "/ban someone"?

    EDIT: I see what Assist said. That would work then :)
     
  11. Offline

    teej107

    Like I said. RIP commands that start with /ban. Assist gave a better answer but I still think
     
  12. Offline

    lug

    Sorry, never have coded before, got certain lines of code off the internet.
    Brand new to this.
     
  13. Offline

    teej107

    lug *facepalm*
     
  14. lug
    This right here, gentlemen, is exactly why you should learn at least the very basics of Java before attempting to create plugins. It doesn't take too long to go through the "official" Java tutorial basics.
     
    SleepyDog and teej107 like this.
  15. Offline

    lug

    Could you please give me the code so I can see at least what is down, and seen how you have done it?
    Please?
     
  16. Offline

    SleepyDog


    Code:java
    1. String player = "lug";
    2. if (!player.getName().equals("n00b") {
    3. player.getPlayer().sendMessage("You are eligible for spoonfeeding!");
    4. }
    5. else {
    6. player.getPlayer().kickPlayer("We do not spoonfeed noobs");
    7. }
     
  17. SleepyDog
    Since when has String had a getName() and getPlayer() methods? :p

    And don't you think you're being a bit harsh?
     
  18. Offline

    teej107

    Spoonfeeding gets you nowhere. To answer your question, NO! Learn Java or request for someone who does know Java to make the plugin.
     
Thread Status:
Not open for further replies.

Share This Page