Created
January 1, 2014 03:36
-
-
Save aadnk/8204789 to your computer and use it in GitHub Desktop.
Send a raw tell command to a player through 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 java.lang.reflect.InvocationTargetException; | |
import org.bukkit.command.Command; | |
import org.bukkit.command.CommandSender; | |
import org.bukkit.entity.Player; | |
import org.bukkit.event.Listener; | |
import org.bukkit.plugin.java.JavaPlugin; | |
import com.comphenix.protocol.PacketType; | |
import com.comphenix.protocol.ProtocolLibrary; | |
import com.comphenix.protocol.events.PacketContainer; | |
import com.comphenix.protocol.wrappers.WrappedChatComponent; | |
public class SendRawTellPacket extends JavaPlugin implements Listener { | |
// Look at this example for the rest of the syntax: | |
// https://gist.github.com/thinkofdeath/e882ce057ed83bac0a1c | |
private static final String MESSAGE = | |
"{" + | |
"\"text\": \"Hello world\"," + | |
"\"clickEvent\": {" + | |
"\"action\":\"run_command\", " + "" + | |
"\"value\": \"/time set day\"" + | |
"}" + | |
"}"; | |
@Override | |
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | |
if (sender instanceof Player) { | |
Player player = (Player) sender; | |
PacketContainer chat = new PacketContainer(PacketType.Play.Server.CHAT); | |
chat.getChatComponents().write(0, WrappedChatComponent.fromJson(MESSAGE)); | |
try { | |
ProtocolLibrary.getProtocolManager().sendServerPacket(player, chat); | |
} catch (InvocationTargetException e) { | |
e.printStackTrace(); | |
} | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment