[HELP ME] Change unknown command message

Discussion in 'Plugin Development' started by Bammerbom, Jun 8, 2013.

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


    How to change unknown command message???
  2. Offline



    Seriously though, you should make your title more descriptive :p
  3. Offline


    You can modify it with ProtocolLib the same way I did here. Here's an updated version for changing the unknown message (download):
    1. public class ExampleMod extends JavaPlugin implements Listener {
    2. @Override
    3. public void onEnable() {
    4. ProtocolLibrary.getProtocolManager().addPacketListener(
    5. new PacketAdapter(this, ConnectionSide.SERVER_SIDE, Packets.Server.CHAT) {
    6. @Override
    7. public void onPacketSending(PacketEvent event) {
    8. String message = event.getPacket().getStrings().read(0);
    10. // Modify this exact message regardless of the coloring
    11. if ("Unknown command. Type \"help\" for help.".equals(ChatColor
    12. .stripColor(message))) {
    13. event.getPacket().getStrings()
    14. .write(0, "Wrong. Try again!");
    15. }
    16. }
    17. });
    18. }
    20. @Override
    21. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    22. sender.sendMessage(ChatColor.RED + "You don't have permission for this area.");
    23. return true;
    24. }
    25. }

    Looks like this is a duplicate of this thread. Please don't spam the forums.

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


    Comphenix It does not work.

    new PacketAdapter(this, ConnectionSide.SERVER_SIDE, Packets.Server.CHAT){
    give errors
  5. Offline


    It does, I just tested it.

    But you do need to install ProtocolLib, reference it in your plugin, and add it to "depend" in your plugin.yml. Here's a compiled version of the example above.
  6. Offline


    Here is my error:
    2013-06-08 15:52:51 [SEVERE] Could not load 'plugins\Core.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.NoClassDefFoundError: com/comphenix/protocol/events/PacketListener
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:184)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
        at org.bukkit.craftbukkit.v1_5_R3.CraftServer.loadPlugins(CraftServer.java:239)
        at org.bukkit.craftbukkit.v1_5_R3.CraftServer.reload(CraftServer.java:603)
        at org.bukkit.Bukkit.reload(Bukkit.java:185)
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:23)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:189)
        at org.bukkit.craftbukkit.v1_5_R3.CraftServer.dispatchCommand(CraftServer.java:523)
        at net.minecraft.server.v1_5_R3.PlayerConnection.handleCommand(PlayerConnection.java:965)
        at net.minecraft.server.v1_5_R3.PlayerConnection.chat(PlayerConnection.java:883)
        at net.minecraft.server.v1_5_R3.PlayerConnection.a(PlayerConnection.java:840)
        at net.minecraft.server.v1_5_R3.Packet3Chat.handle(Packet3Chat.java:44)
        at net.minecraft.server.v1_5_R3.NetworkManager.b(NetworkManager.java:292)
        at net.minecraft.server.v1_5_R3.PlayerConnection.d(PlayerConnection.java:109)
        at net.minecraft.server.v1_5_R3.ServerConnection.b(SourceFile:35)
        at net.minecraft.server.v1_5_R3.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.v1_5_R3.MinecraftServer.r(MinecraftServer.java:581)
        at net.minecraft.server.v1_5_R3.DedicatedServer.r(DedicatedServer.java:226)
        at net.minecraft.server.v1_5_R3.MinecraftServer.q(MinecraftServer.java:477)
        at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java:410)
        at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:573)
    Caused by: java.lang.NoClassDefFoundError: com/comphenix/protocol/events/PacketListener
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:173)
        ... 21 more
    Caused by: java.lang.ClassNotFoundException: com.comphenix.protocol.events.PacketListener
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at org.bukkit.plugin.java.PluginClassLoader.findClass0(PluginClassLoader.java:80)
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:53)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 24 more
    My code:
    public void onEnable() {
        getServer().getPluginManager().registerEvents(new CoreListener(this), this); //Colored motd
        this.logger.info("Core enabled!"); 
                new PacketAdapter(this, ConnectionSide.SERVER_SIDE, Packets.Server.CHAT){
                    public void onPacketSending(PacketEvent e){
                        String message = e.getPacket().getStrings().read(0);
                        if("Unknown command. Type \"help\" for help.".equals(ChatColor.stripColor(message))) {
                        e.getPacket().getStrings().write(0, ChatColor.GOLD + "Commando niet gevonden");
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args){
        sender.sendMessage(ChatColor.GOLD + "No permissions");
        return true;


    (I only imported protocolLib, i don't installed it in my server)

    I suck.

    Is it possible to do it without protocolLib???

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



    Possible but extremely difficult. I'd recommend using ProtocolLib :)
  8. Offline



    I want it :(
    I don't want that plugin on my server.

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


    Then get ready to do a hell of a lot of coding.

    It's really the easiest way!

    Why don't you want to use it? :p
  10. Offline


  11. Offline



    Then why didn't you just look at the source of one of them?

    On at least one of them the source is made available :/
    Minecrell likes this.
  12. Offline


    Hoolean It don't work if i pick te source from it. Can you help?
  13. Offline



    What doesn't work?

    Is there an error? :)
  14. Offline


    Hoolean Yes i gonna test it again so i can give you the error.
  15. Offline


    How about this, Works for me, dunno if its a safe way to do it though.

    1. public class CommandListener implements Listener {
    2. @EventHandler(priority = EventPriority.NORMAL)
    3. public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    4. if (!event.isCancelled()) {
    5. Player player = event.getPlayer();
    6. String cmd = event.getMessage().split(" ")[0];
    7. HelpTopic topic = Bukkit.getServer().getHelpMap().getHelpTopic(cmd);
    8. if (topic == null) {
    9. player.sendMessage(ChatColor.RED + cmd + " dont excist, type \"/help\" for help");
    10. event.setCancelled(true);
    11. }
    12. }
    13. }
    14. }
  16. Offline


    Did you test it for the worldedit commands? WorldEdit is registering it's commands dynamically to the server command map, so that's the reason why you have to get it through reflection / obc code (CraftServer.getCommandMap()) to check if the command exists. However, I don't know if worldedit adds his commands to the help map, so it may work...
  17. Offline


    CraftServer.getCommandMap() is a craftbukkit method, not a Bukkit method.

    As for reflecting to get the message, it's a hardcoded string, no variable set there. I'll toy with it.

    Edit: From the looks of it, those plugins did this through catching every command through the ComanndPreProcess event, which, while easy, is somewhat dirty. However the alternative involves modifying bytecode, so it might be the path you should take.
  18. Offline


    I know it's a craftbukkit method, that's why I wrote it may be better to get the command map through reflection, so you don't need to update your plugin with every minecraft update. :)
  19. Offline


    Locked, being a massive thread necropost.
Thread Status:
Not open for further replies.

Share This Page