[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

    Bammerbom

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

    Hoolean

    [CHANGE TITLE]

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

    Comphenix

    You can modify it with ProtocolLib the same way I did here. Here's an updated version for changing the unknown message (download):
    Code:java
    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);
    9.  
    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. }
    19.  
    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

    Bammerbom

    Comphenix It does not work.

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

    Comphenix

    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

    Bammerbom

    Comphenix
    Here is my error:
    Code:
    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:
    Code:
    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(new CoreListener(this), this); //Colored motd
        this.logger.info("Core enabled!"); 
     
       
        //UK
        ProtocolLibrary.getProtocolManager().addPacketListener(
                new PacketAdapter(this, ConnectionSide.SERVER_SIDE, Packets.Server.CHAT){
                    @Override
                    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");
                        }
                    }
                });   
    }
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args){
        sender.sendMessage(ChatColor.GOLD + "No permissions");
        return true;
    }


    FIXED.

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

    I suck.

    Comphenix
    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

    Hoolean

    Jhtzb

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

    Bammerbom

    Hoolean
    Okay

    Hoolean
    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

    Hoolean

    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

    Bammerbom

  11. Offline

    Hoolean

    Jhtzb

    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

    Bammerbom

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

    Hoolean

    Jhtzb

    What doesn't work?

    Is there an error? :)
     
  14. Offline

    Bammerbom

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

    Kiwz

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

    Code:java
    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

    Minecrell

    Kiwz
    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

    1Rogue


    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

    Minecrell

    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

    Necrodoom

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

Share This Page