Override /pl command.

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

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

    dandwhit

    Hi
    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.
    Code:java
    1. package me.dandwhit.NoPlugins;
    2.  
    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;
    8.  
    9. public class Main extends JavaPlugin implements Listener{
    10.  
    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. }
    15.  
    16. public void onDisable() {
    17.  
    18. }
    19.  
    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. }


    Thanks,
    Dan
     
  2. Offline

    Smerfa

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

    ToPoEdiTs

  4. Offline

    es359

  5. Offline

    dandwhit

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

    fireblast709

    It's code missing a Set#contains

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

    Smerfa

    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

    dandwhit

    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

    Landen22

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

    dandwhit

  11. Offline

    ToPoEdiTs

    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

    dandwhit

    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

    ToPoEdiTs

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

    ToPoEdiTs

    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

    Funergy

    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

    Evaluations

    Might want to add a permission
     
  20. Offline

    ToPoEdiTs

    ¿ this code is example xd
     
  21. Offline

    stoneminer02

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

    fireblast709

    /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

    MCraftGamer35

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

    stoneminer02

    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

    Hilgert

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

    Hawktasard

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

    CakePvP

    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

    nzkiwi.5000

    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