Created
October 11, 2013 18:49
-
-
Save aadnk/6940010 to your computer and use it in GitHub Desktop.
How to change the "unknown command" error message with ProtocolLib. Updated for Minecraft 1.6.4.
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.event.Listener; | |
import org.bukkit.plugin.java.JavaPlugin; | |
import org.json.simple.JSONObject; | |
import org.json.simple.parser.JSONParser; | |
import org.json.simple.parser.ParseException; | |
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.PacketContainer; | |
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) { | |
private JSONParser parser = new JSONParser(); | |
@SuppressWarnings("unchecked") | |
@Override | |
public void onPacketSending(PacketEvent event) { | |
try { | |
PacketContainer packet = event.getPacket(); | |
String json = packet.getStrings().read(0); | |
JSONObject data = (JSONObject) parser.parse(json); | |
String message = ChatColor.stripColor((String) data.get("text")); | |
if ("Unknown command. Type \"/help\" for help.".equals(message)) { | |
// Change the output | |
data.put("text", "Wrong. Try again!"); | |
// Write back the resulting JSON | |
packet.getStrings().write(0, data.toJSONString()); | |
} | |
} catch (ParseException e) { | |
throw new RuntimeException("Cannot parse JSON.", e); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use this version for 1.7.2:
https://gist.github.com/aadnk/8129389