Created
June 8, 2013 12:07
-
-
Save aadnk/5734964 to your computer and use it in GitHub Desktop.
How to change the "unknown command" error message with ProtocolLib.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.comphenix.example; | |
import org.bukkit.ChatColor; | |
import org.bukkit.command.Command; | |
import org.bukkit.command.CommandSender; | |
import org.bukkit.event.Listener; | |
import org.bukkit.plugin.java.JavaPlugin; | |
import com.comphenix.protocol.Packets; | |
import com.comphenix.protocol.ProtocolLibrary; | |
import com.comphenix.protocol.events.ConnectionSide; | |
import com.comphenix.protocol.events.PacketAdapter; | |
import com.comphenix.protocol.events.PacketEvent; | |
public class ChangingUnknownCommand extends JavaPlugin implements Listener { | |
@Override | |
public void onEnable() { | |
ProtocolLibrary.getProtocolManager().addPacketListener( | |
new PacketAdapter(this, ConnectionSide.SERVER_SIDE, Packets.Server.CHAT) { | |
@Override | |
public void onPacketSending(PacketEvent event) { | |
String message = event.getPacket().getStrings().read(0); | |
// Modify this exact message regardless of the coloring | |
if ("Unknown command. Type \"help\" for help.".equals(ChatColor | |
.stripColor(message))) { | |
event.getPacket().getStrings() | |
.write(0, "Wrong. Try again!"); | |
} | |
} | |
}); | |
} | |
@Override | |
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | |
sender.sendMessage(ChatColor.RED + "You don't have permission for this area."); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that this only works in Minecraft 1.5.2 and earlier. Use the following version for 1.6.0+:
https://gist.github.com/aadnk/6940010