Override /pl command.

Discussion in 'Plugin Development' started by dandwhit, Oct 1, 2014.

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


    I'm making (what should be) a relatively simple plugin which blocks people from using /pl and then sends them a message instead.
    However something is not working and I'm confused as to why it is not.
    Could someone tell me what I have done wrong with my code.
    1. package me.dandwhit.NoPlugins;
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.player.PlayerCommandPreprocessEvent;
    7. import org.bukkit.plugin.java.JavaPlugin;
    9. public class Main extends JavaPlugin implements Listener{
    11. public void onEnable() {
    12. //No log needed, it auto does it.
    13. saveDefaultConfig(); //No need to make a method just makes it more intensive and also it is more text.
    14. }
    16. public void onDisable() {
    18. }
    20. @EventHandler
    21. public void onCmd(PlayerCommandPreprocessEvent e){
    22. if(e.getMessage().equalsIgnoreCase("/pl")||e.getMessage().equalsIgnoreCase("/plugins")||e.getMessage().contains("/?")||e.getMessage().equalsIgnoreCase("/ver")){
    23. e.setCancelled(true);
    24. e.getPlayer().sendMessage(ChatColor.RED + "Nope! You can't do that!");
    25. }
    26. }
    27. }

  2. Offline


    You don't register that listener.
    add to onEnable:
    Bukkit.getPluginManager().registerEvents(this, this);
  3. Offline


  4. Offline


  5. Offline


    Smerfa Yes! Yes! Yes, Yes Yes! Thank You!
  6. Offline


    It's code missing a Set#contains

    dandwhit Be aware of aliases (for example, /bukkit:plugins)
  7. Offline


    Hyyym, maybe that offtop, but I have one question...
    WHY, just WHY block that /pl command?
    I only understand to block /version and /? (but not /help) command -> players don't need all commands and versions of plugins.
    But why /pl?
    In most cases that just "We have own plugins!" and command blocked because it's a lie or that scrips (in skript).
  8. Offline


    fireblast709 Yes, I will. I have added /bukkit:plugins. Also, /pl, /plugins, /ver and /? and I can't think of anymore. If there is any I've missed, could you tell me. Thanks :)

    Smerfa I'm doing it mainly because I don't like it when people come on and say "Why do you have this plugin?" "Why do you have that plugin?" and also most servers I know have blocked it so i thought I might as well too. :)
  9. Offline


    Please use .startWith not .equalsIgnoreCase because now I´m able to make /pl 1 and I´ll see all plugins :p
  10. Offline


  11. Offline


    what problem?
  12. ToPoEdiTs Just to let you know, your plugin wouldn't work. Yet it blocks /pl but you can use /bukkit:pl :)
  13. Offline


    AdamQpzm I know, but I have now added that. (not to the code I posted up there but to the code in eclipse)

    EDIT: Wait never mind! You were talking to ToPoEdiTs not me! Sorry, thought you were talking to me.
    AdamQpzm likes this.
  14. Offline


    test mi example :p
  15. Your example has been deleted
  16. Offline


    lol wtf ? i don't remove my
    Repository lol

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 14, 2016
  17. Offline


    ToPoEdiTs I see B*ngeeC*rd commands in your code like glist or server and alert.
    if you wanna block these commands you need to get into B*ngeeC*rd codig but you can't find help here for B*ngeeC*rd plugins. this is only CraftBukkit.

    EDIT: L0L I didn't realize how much censoring I've did with B*ngeeC*rd xD
  18. ToPoEdiTs Hmm. Well the github link 404'd so I assumed it had been deleted. Regardless, just wanted to let you know that your code throws errors when any of the commands are executed by anything other than a player, and someone can run /bukkit:pl to access the plugin list.
  19. Offline


    Might want to add a permission
  20. Offline


    ¿ this code is example xd
  21. Offline


    Tip: String msg = e.getMessage().toLowerCase();
    Then use that to do if(msg.contains("/pl")) insertFunnyCodeHere();
  22. Offline


    /bukkit:<no whitespace>pl, /players. The first wouldn't even be blocked, the second would break (even though it's a different command)
  23. Offline


    A very simple way to do this would use a PlayerCommandPreprocessEvent.
  24. Offline


    Please read the code he posted and has problems with..
  25. stoneminer02 This is actually hinting at the better way of doing it ;)
  26. Offline


    equalsIgnoreCase? what?
    /pl any Text
    /plugins any Text
    Return a list of plugins
    if(event.getMessage().startsWith("/pl") || event.getMessage().startsWith("/plugins")...
  27. Offline


    Basic pseudo code.
    1. Some command preprocess event{
    2. if list of all blocked commands in lower case contains message.toLowerCase(){
    3. Cancel!
    4. }
    5. }
  28. Offline


    If you're trying to block players from listing your plugins, you may as well just revoke the permission. It's 10x easier (don't forget that players can still tab commands to guess the plugins).
  29. Offline


    At least you could make a method wrapping the messages, easier to edit and less disk space to take
  30. Hawktasard Hilgert Contains is a bad way to do it. If you block plugin's alias of "/pl" then it'll block a whole range of things like /play, /players, /please give me diamonds - all sorts of possible stuff. Same can be true with startwith. I would really recommend only checking until the first space (hint: split the message).

    nzkiwi.5000 Lol. Have to say, what with computers nowadays, Programmers rarely worry about disk space usage for their code, unless it's in a case where every bit is important. Plugins generally aren't the case.
Thread Status:
Not open for further replies.

Share This Page