更新
This commit is contained in:
@@ -1,22 +1,49 @@
|
||||
package me.skymc.taboolib.display;
|
||||
|
||||
import com.ilummc.tlib.nms.ActionBar;
|
||||
import me.skymc.taboolib.TabooLib;
|
||||
import me.skymc.taboolib.nms.NMSUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
/**
|
||||
* @author Bkm016
|
||||
* @since 2018-04-26
|
||||
*/
|
||||
public class ActionUtils {
|
||||
|
||||
private static Class<?> Packet = NMSUtils.getNMSClass("Packet");
|
||||
private static Class<?> ChatComponentText = NMSUtils.getNMSClass("ChatComponentText");
|
||||
private static Class<?> ChatMessageType = NMSUtils.getNMSClass("ChatMessageType");
|
||||
private static Class<?> PacketPlayOutChat = NMSUtils.getNMSClass("PacketPlayOutChat");
|
||||
private static Class<?> IChatBaseComponent = NMSUtils.getNMSClass("IChatBaseComponent");
|
||||
|
||||
public static void send(Player player, String action) {
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
ActionBar.sendActionBar(player, action);
|
||||
} catch (Throwable ignored) {
|
||||
Object ab = ChatComponentText.getConstructor(String.class).newInstance(action);
|
||||
Constructor<?> ac;
|
||||
Object abPacket;
|
||||
if (TabooLib.getVerint() > 11100) {
|
||||
ac = PacketPlayOutChat.getConstructor(IChatBaseComponent, ChatMessageType);
|
||||
abPacket = ac.newInstance(ab, ChatMessageType.getMethod("a", Byte.TYPE).invoke(null, (byte) 2));
|
||||
} else {
|
||||
ac = PacketPlayOutChat.getConstructor(IChatBaseComponent, Byte.TYPE);
|
||||
abPacket = ac.newInstance(ab, (byte) 2);
|
||||
}
|
||||
sendPacket(player, abPacket);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void sendPacket(Player player, Object packet) {
|
||||
try {
|
||||
Object handle = player.getClass().getMethod("getHandle", new Class[0]).invoke(player);
|
||||
Object playerConnection = handle.getClass().getField("playerConnection").get(handle);
|
||||
playerConnection.getClass().getMethod("sendPacket", Packet).invoke(playerConnection, packet);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user