mirror of
https://e.coding.net/circlecloud/YumCore.git
synced 2024-11-21 01:38:51 +00:00
feat: 兼容 1.17
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
f130cfed60
commit
834f3d7d58
4
pom.xml
4
pom.xml
@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>pw.yumc</groupId>
|
<groupId>pw.yumc</groupId>
|
||||||
<artifactId>YumCore</artifactId>
|
<artifactId>YumCore</artifactId>
|
||||||
<version>1.9.1</version>
|
<version>1.9.2</version>
|
||||||
<build>
|
<build>
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
@ -92,7 +92,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>me.clip</groupId>
|
<groupId>me.clip</groupId>
|
||||||
<artifactId>placeholderapi</artifactId>
|
<artifactId>placeholderapi</artifactId>
|
||||||
<version>2.9.2</version>
|
<version>2.10.9</version>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
|
@ -1,436 +1,445 @@
|
|||||||
package pw.yumc.YumCore.bukkit.compatible;
|
package pw.yumc.YumCore.bukkit.compatible;
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import pw.yumc.YumCore.annotation.NotProguard;
|
import pw.yumc.YumCore.annotation.NotProguard;
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
import pw.yumc.YumCore.bukkit.P;
|
import pw.yumc.YumCore.bukkit.P;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bukkit兼容类
|
* Bukkit兼容类
|
||||||
*
|
*
|
||||||
* @author 喵♂呜
|
* @author 喵♂呜
|
||||||
* @since 2016年7月23日 下午1:04:56
|
* @since 2016年7月23日 下午1:04:56
|
||||||
*/
|
*/
|
||||||
public class C {
|
public class C {
|
||||||
public static boolean init;
|
public static boolean init;
|
||||||
private static boolean above_1_16 = false;
|
private static boolean above_1_16 = false;
|
||||||
private static Class<?> nmsIChatBaseComponent;
|
private static Class<?> nmsIChatBaseComponent;
|
||||||
private static Constructor<?> packetTypeConstructor;
|
private static Constructor<?> packetTypeConstructor;
|
||||||
private static Method chatSerializer;
|
private static Method chatSerializer;
|
||||||
private static Method getHandle;
|
private static Method getHandle;
|
||||||
private static Method nmsChatMessageTypeClassValueOf;
|
private static Method nmsChatMessageTypeClassValueOf;
|
||||||
private static String version;
|
private static String version;
|
||||||
private static boolean newversion;
|
private static boolean newversion;
|
||||||
private static Field playerConnection;
|
private static Field playerConnection;
|
||||||
private static Method sendPacket;
|
private static Method sendPacket;
|
||||||
private static Object[] chatMessageTypes;
|
private static Object[] chatMessageTypes;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
version = getNMSVersion();
|
version = getNMSVersion();
|
||||||
newversion = Integer.parseInt(version.split("_")[1]) > 7;
|
Integer subVersion = Integer.parseInt(version.split("_")[1]);
|
||||||
Class<?> nmsChatSerializer = Class.forName(a(newversion ? "IChatBaseComponent$ChatSerializer" : "ChatSerializer"));
|
newversion = subVersion > 7;
|
||||||
chatSerializer = nmsChatSerializer.getMethod("a", String.class);
|
Class<?> nmsChatSerializer = subVersion < 17 ?
|
||||||
nmsIChatBaseComponent = Class.forName(a("IChatBaseComponent"));
|
Class.forName(a(newversion ? "IChatBaseComponent$ChatSerializer" : "ChatSerializer")) :
|
||||||
Class<?> packetType = Class.forName(a("PacketPlayOutChat"));
|
Class.forName("net.minecraft.network.chat.IChatBaseComponent$ChatSerializer");
|
||||||
Arrays.stream(packetType.getConstructors()).forEach(c -> {
|
chatSerializer = nmsChatSerializer.getMethod("a", String.class);
|
||||||
if (c.getParameterTypes().length == 2) {
|
nmsIChatBaseComponent = subVersion < 17 ?
|
||||||
packetTypeConstructor = c;
|
Class.forName(a("IChatBaseComponent")) :
|
||||||
}
|
Class.forName("net.minecraft.network.chat.IChatBaseComponent");
|
||||||
if (c.getParameterTypes().length == 3) {
|
Class<?> packetType = subVersion < 17 ?
|
||||||
packetTypeConstructor = c;
|
Class.forName(a("PacketPlayOutChat")) :
|
||||||
above_1_16 = true;
|
Class.forName("net.minecraft.network.protocol.game.PacketPlayOutChat");
|
||||||
}
|
Arrays.stream(packetType.getConstructors()).forEach(c -> {
|
||||||
});
|
if (c.getParameterTypes().length == 2) {
|
||||||
Class<?> nmsChatMessageTypeClass = packetTypeConstructor.getParameterTypes()[1];
|
packetTypeConstructor = c;
|
||||||
if (nmsChatMessageTypeClass.isEnum()) {
|
}
|
||||||
chatMessageTypes = nmsChatMessageTypeClass.getEnumConstants();
|
if (c.getParameterTypes().length == 3) {
|
||||||
} else {
|
packetTypeConstructor = c;
|
||||||
switch (nmsChatMessageTypeClass.getName()) {
|
above_1_16 = true;
|
||||||
case "int":
|
}
|
||||||
nmsChatMessageTypeClass = Integer.class;
|
});
|
||||||
break;
|
Class<?> nmsChatMessageTypeClass = packetTypeConstructor.getParameterTypes()[1];
|
||||||
case "byte":
|
if (nmsChatMessageTypeClass.isEnum()) {
|
||||||
nmsChatMessageTypeClass = Byte.class;
|
chatMessageTypes = nmsChatMessageTypeClass.getEnumConstants();
|
||||||
break;
|
} else {
|
||||||
}
|
switch (nmsChatMessageTypeClass.getName()) {
|
||||||
nmsChatMessageTypeClassValueOf = nmsChatMessageTypeClass.getDeclaredMethod("valueOf", String.class);
|
case "int":
|
||||||
}
|
nmsChatMessageTypeClass = Integer.class;
|
||||||
Class<?> typeCraftPlayer = Class.forName(b("entity.CraftPlayer"));
|
break;
|
||||||
Class<?> typeNMSPlayer = Class.forName(a("EntityPlayer"));
|
case "byte":
|
||||||
Class<?> typePlayerConnection = Class.forName(a("PlayerConnection"));
|
nmsChatMessageTypeClass = Byte.class;
|
||||||
getHandle = typeCraftPlayer.getMethod("getHandle");
|
break;
|
||||||
playerConnection = typeNMSPlayer.getField("playerConnection");
|
}
|
||||||
sendPacket = typePlayerConnection.getMethod("sendPacket", Class.forName(a("Packet")));
|
nmsChatMessageTypeClassValueOf = nmsChatMessageTypeClass.getDeclaredMethod("valueOf", String.class);
|
||||||
init = true;
|
}
|
||||||
} catch (Exception e) {
|
Class<?> typeCraftPlayer = Class.forName(b("entity.CraftPlayer"));
|
||||||
Log.w("C 兼容性工具初始化失败 可能造成部分功能不可用!");
|
Class<?> typeNMSPlayer = subVersion < 17 ? Class.forName(a("EntityPlayer")) : Class.forName("net.minecraft.server.level.EntityPlayer");
|
||||||
Log.d(e);
|
Class<?> typePlayerConnection = subVersion < 17 ? Class.forName(a("PlayerConnection")) : Class.forName("net.minecraft.server.network.PlayerConnection");
|
||||||
}
|
getHandle = typeCraftPlayer.getMethod("getHandle");
|
||||||
}
|
playerConnection = subVersion < 17 ? typeNMSPlayer.getField("playerConnection") : typeNMSPlayer.getField("b");
|
||||||
|
sendPacket = typePlayerConnection.getMethod("sendPacket", subVersion < 17 ?
|
||||||
private C() {
|
Class.forName(a("Packet")) :
|
||||||
}
|
Class.forName("net.minecraft.network.protocol.Packet"));
|
||||||
|
init = true;
|
||||||
public static String a(String str) {
|
} catch (Exception e) {
|
||||||
return "net.minecraft.server." + version + "." + str;
|
Log.w("C 兼容性工具初始化失败 可能造成部分功能不可用!");
|
||||||
}
|
Log.d(e);
|
||||||
|
}
|
||||||
public static String b(String str) {
|
}
|
||||||
return "org.bukkit.craftbukkit." + version + "." + str;
|
|
||||||
}
|
private C() {
|
||||||
|
}
|
||||||
/**
|
|
||||||
* 获得NMS版本号
|
public static String a(String str) {
|
||||||
*
|
return "net.minecraft.server." + version + "." + str;
|
||||||
* @return NMS版本号
|
}
|
||||||
*/
|
|
||||||
public static String getNMSVersion() {
|
public static String b(String str) {
|
||||||
return Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
return "org.bukkit.craftbukkit." + version + "." + str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 给玩家发送Json消息
|
* 获得NMS版本号
|
||||||
*
|
*
|
||||||
* @param receivingPacket 接受信息的玩家
|
* @return NMS版本号
|
||||||
* @param json Json信息
|
*/
|
||||||
* @param type 类型
|
public static String getNMSVersion() {
|
||||||
* 0. 消息
|
return Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
||||||
* 2. ActionBar
|
}
|
||||||
*/
|
|
||||||
public static void sendJson(org.bukkit.entity.Player receivingPacket, String json, int type) {
|
/**
|
||||||
try {
|
* 给玩家发送Json消息
|
||||||
Object serialized = chatSerializer.invoke(null, json);
|
*
|
||||||
Object player = getHandle.invoke(receivingPacket);
|
* @param receivingPacket 接受信息的玩家
|
||||||
Object connection = playerConnection.get(player);
|
* @param json Json信息
|
||||||
Object typeObj = chatMessageTypes == null ? nmsChatMessageTypeClassValueOf.invoke(null, String.valueOf(type)) : chatMessageTypes[type];
|
* @param type 类型
|
||||||
sendPacket.invoke(connection, above_1_16
|
* 0. 消息
|
||||||
? packetTypeConstructor.newInstance(serialized, typeObj, receivingPacket.getUniqueId())
|
* 2. ActionBar
|
||||||
: packetTypeConstructor.newInstance(serialized, typeObj));
|
*/
|
||||||
} catch (Exception ex) {
|
public static void sendJson(org.bukkit.entity.Player receivingPacket, String json, int type) {
|
||||||
Log.d("Json发包错误 " + version, ex);
|
try {
|
||||||
}
|
Object serialized = chatSerializer.invoke(null, json);
|
||||||
}
|
Object player = getHandle.invoke(receivingPacket);
|
||||||
|
Object connection = playerConnection.get(player);
|
||||||
public static class ActionBar {
|
Object typeObj = chatMessageTypes == null ? nmsChatMessageTypeClassValueOf.invoke(null, String.valueOf(type)) : chatMessageTypes[type];
|
||||||
private ActionBar() {
|
sendPacket.invoke(connection, above_1_16
|
||||||
}
|
? packetTypeConstructor.newInstance(serialized, typeObj, receivingPacket.getUniqueId())
|
||||||
|
: packetTypeConstructor.newInstance(serialized, typeObj));
|
||||||
/**
|
} catch (Exception ex) {
|
||||||
* 公告发送ActionBar
|
Log.d("Json发包错误 " + version, ex);
|
||||||
*
|
}
|
||||||
* @param message 需要发送的消息
|
}
|
||||||
*/
|
|
||||||
@NotProguard
|
public static class ActionBar {
|
||||||
public static void broadcast(String message) {
|
private ActionBar() {
|
||||||
for (org.bukkit.entity.Player player : C.Player.getOnlinePlayers()) {
|
}
|
||||||
send(player, message);
|
|
||||||
}
|
/**
|
||||||
}
|
* 公告发送ActionBar
|
||||||
|
*
|
||||||
/**
|
* @param message 需要发送的消息
|
||||||
* 公告发送ActionBar
|
*/
|
||||||
*
|
@NotProguard
|
||||||
* @param message 需要发送的消息
|
public static void broadcast(String message) {
|
||||||
* @param times 需要显示的时间
|
for (org.bukkit.entity.Player player : C.Player.getOnlinePlayers()) {
|
||||||
*/
|
send(player, message);
|
||||||
@NotProguard
|
}
|
||||||
public static void broadcast(final String message, final int times) {
|
}
|
||||||
new BukkitRunnable() {
|
|
||||||
int time = times;
|
/**
|
||||||
|
* 公告发送ActionBar
|
||||||
@Override
|
*
|
||||||
public void run() {
|
* @param message 需要发送的消息
|
||||||
C.Player.getOnlinePlayers().forEach(player -> send(player, message));
|
* @param times 需要显示的时间
|
||||||
time--;
|
*/
|
||||||
if (time <= 0) {
|
@NotProguard
|
||||||
cancel();
|
public static void broadcast(final String message, final int times) {
|
||||||
}
|
new BukkitRunnable() {
|
||||||
}
|
int time = times;
|
||||||
}.runTaskTimerAsynchronously(P.instance, 0, 20);
|
|
||||||
}
|
@Override
|
||||||
|
public void run() {
|
||||||
/**
|
C.Player.getOnlinePlayers().forEach(player -> send(player, message));
|
||||||
* 公告发送ActionBar(分世界)
|
time--;
|
||||||
*
|
if (time <= 0) {
|
||||||
* @param world 需要发送的世界
|
cancel();
|
||||||
* @param message 需要发送的消息
|
}
|
||||||
* @param times 需要显示的时间
|
}
|
||||||
*/
|
}.runTaskTimerAsynchronously(P.instance, 0, 20);
|
||||||
@NotProguard
|
}
|
||||||
public static void broadcast(final World world, final String message, final int times) {
|
|
||||||
new BukkitRunnable() {
|
/**
|
||||||
int time = times;
|
* 公告发送ActionBar(分世界)
|
||||||
|
*
|
||||||
@Override
|
* @param world 需要发送的世界
|
||||||
public void run() {
|
* @param message 需要发送的消息
|
||||||
C.Player.getOnlinePlayers().stream().filter(player -> player.getWorld().getName().equalsIgnoreCase(world.getName())).forEach(player -> send(player, message));
|
* @param times 需要显示的时间
|
||||||
time--;
|
*/
|
||||||
if (time <= 0) {
|
@NotProguard
|
||||||
cancel();
|
public static void broadcast(final World world, final String message, final int times) {
|
||||||
}
|
new BukkitRunnable() {
|
||||||
}
|
int time = times;
|
||||||
}.runTaskTimerAsynchronously(P.instance, 0, 20);
|
|
||||||
}
|
@Override
|
||||||
|
public void run() {
|
||||||
/**
|
C.Player.getOnlinePlayers().stream().filter(player -> player.getWorld().getName().equalsIgnoreCase(world.getName())).forEach(player -> send(player, message));
|
||||||
* 给玩家发送ActionBar消息
|
time--;
|
||||||
*
|
if (time <= 0) {
|
||||||
* @param receivingPacket 接受信息的玩家
|
cancel();
|
||||||
* @param msg ActionBar信息
|
}
|
||||||
*/
|
}
|
||||||
@NotProguard
|
}.runTaskTimerAsynchronously(P.instance, 0, 20);
|
||||||
public static void send(org.bukkit.entity.Player receivingPacket, String msg) {
|
}
|
||||||
sendJson(receivingPacket, "{\"text\":\"" + ChatColor.translateAlternateColorCodes('&', JSONObject.escape(msg)) + "\"}", 2);
|
|
||||||
}
|
/**
|
||||||
|
* 给玩家发送ActionBar消息
|
||||||
/**
|
*
|
||||||
* 给玩家发送ActionBar消息
|
* @param receivingPacket 接受信息的玩家
|
||||||
*
|
* @param msg ActionBar信息
|
||||||
* @param receivingPacket 接受信息的玩家
|
*/
|
||||||
* @param msg 需要发送的消息
|
@NotProguard
|
||||||
* @param times 需要显示的时间
|
public static void send(org.bukkit.entity.Player receivingPacket, String msg) {
|
||||||
*/
|
sendJson(receivingPacket, "{\"text\":\"" + ChatColor.translateAlternateColorCodes('&', JSONObject.escape(msg)) + "\"}", 2);
|
||||||
@NotProguard
|
}
|
||||||
public static void send(final org.bukkit.entity.Player receivingPacket, final String msg, final int times) {
|
|
||||||
new BukkitRunnable() {
|
/**
|
||||||
int time = times;
|
* 给玩家发送ActionBar消息
|
||||||
|
*
|
||||||
@Override
|
* @param receivingPacket 接受信息的玩家
|
||||||
public void run() {
|
* @param msg 需要发送的消息
|
||||||
send(receivingPacket, msg);
|
* @param times 需要显示的时间
|
||||||
time--;
|
*/
|
||||||
if (time <= 0) {
|
@NotProguard
|
||||||
cancel();
|
public static void send(final org.bukkit.entity.Player receivingPacket, final String msg, final int times) {
|
||||||
}
|
new BukkitRunnable() {
|
||||||
}
|
int time = times;
|
||||||
}.runTaskTimerAsynchronously(P.instance, 0, 20);
|
|
||||||
}
|
@Override
|
||||||
}
|
public void run() {
|
||||||
|
send(receivingPacket, msg);
|
||||||
/**
|
time--;
|
||||||
* Bukkit Player兼容类
|
if (time <= 0) {
|
||||||
*
|
cancel();
|
||||||
* @author 喵♂呜
|
}
|
||||||
* @since 2016年7月23日 下午4:33:40
|
}
|
||||||
*/
|
}.runTaskTimerAsynchronously(P.instance, 0, 20);
|
||||||
public static class Player {
|
}
|
||||||
private static Class<?> gameProfileClass;
|
}
|
||||||
private static Constructor<?> gameProfileConstructor;
|
|
||||||
private static Constructor<?> craftOfflinePlayerConstructor;
|
/**
|
||||||
private static Method getOnlinePlayers;
|
* Bukkit Player兼容类
|
||||||
|
*
|
||||||
static {
|
* @author 喵♂呜
|
||||||
try {
|
* @since 2016年7月23日 下午4:33:40
|
||||||
// getOnlinePlayers start
|
*/
|
||||||
getOnlinePlayers = Bukkit.class.getDeclaredMethod("getOnlinePlayers");
|
public static class Player {
|
||||||
if (getOnlinePlayers.getReturnType() != org.bukkit.entity.Player[].class) {
|
private static Class<?> gameProfileClass;
|
||||||
for (Method method : Bukkit.class.getDeclaredMethods()) {
|
private static Constructor<?> gameProfileConstructor;
|
||||||
if (method.getReturnType() == org.bukkit.entity.Player[].class && method.getName().endsWith("getOnlinePlayers")) {
|
private static Constructor<?> craftOfflinePlayerConstructor;
|
||||||
getOnlinePlayers = method;
|
private static Method getOnlinePlayers;
|
||||||
}
|
|
||||||
}
|
static {
|
||||||
}
|
try {
|
||||||
// getOnlinePlayers end
|
// getOnlinePlayers start
|
||||||
} catch (Exception e) {
|
getOnlinePlayers = Bukkit.class.getDeclaredMethod("getOnlinePlayers");
|
||||||
Log.w("Player 兼容性工具初始化失败 可能造成部分功能不可用!");
|
if (getOnlinePlayers.getReturnType() != org.bukkit.entity.Player[].class) {
|
||||||
}
|
for (Method method : Bukkit.class.getDeclaredMethods()) {
|
||||||
try {
|
if (method.getReturnType() == org.bukkit.entity.Player[].class && method.getName().endsWith("getOnlinePlayers")) {
|
||||||
// getOfflinePlayer start
|
getOnlinePlayers = method;
|
||||||
try {
|
}
|
||||||
gameProfileClass = Class.forName("net.minecraft.util.com.mojang.authlib.GameProfile");
|
}
|
||||||
} catch (Exception e) {
|
}
|
||||||
try {
|
// getOnlinePlayers end
|
||||||
gameProfileClass = Class.forName("com.mojang.authlib.GameProfile");
|
} catch (Exception e) {
|
||||||
} catch (Exception ignored) {
|
Log.w("Player 兼容性工具初始化失败 可能造成部分功能不可用!");
|
||||||
}
|
}
|
||||||
}
|
try {
|
||||||
gameProfileConstructor = gameProfileClass.getDeclaredConstructor(UUID.class, String.class);
|
// getOfflinePlayer start
|
||||||
gameProfileConstructor.setAccessible(true);
|
try {
|
||||||
Class<? extends Server> craftServer = Bukkit.getServer().getClass();
|
gameProfileClass = Class.forName("net.minecraft.util.com.mojang.authlib.GameProfile");
|
||||||
Class<?> craftOfflinePlayer = Class.forName(craftServer.getName().replace("CraftServer", "CraftOfflinePlayer"));
|
} catch (Exception e) {
|
||||||
craftOfflinePlayerConstructor = craftOfflinePlayer.getDeclaredConstructor(craftServer, gameProfileClass);
|
try {
|
||||||
craftOfflinePlayerConstructor.setAccessible(true);
|
gameProfileClass = Class.forName("com.mojang.authlib.GameProfile");
|
||||||
// getOfflinePlayer end
|
} catch (Exception ignored) {
|
||||||
} catch (Exception e) {
|
}
|
||||||
Log.d(e);
|
}
|
||||||
}
|
gameProfileConstructor = gameProfileClass.getDeclaredConstructor(UUID.class, String.class);
|
||||||
}
|
gameProfileConstructor.setAccessible(true);
|
||||||
|
Class<? extends Server> craftServer = Bukkit.getServer().getClass();
|
||||||
private Player() {
|
Class<?> craftOfflinePlayer = Class.forName(craftServer.getName().replace("CraftServer", "CraftOfflinePlayer"));
|
||||||
}
|
craftOfflinePlayerConstructor = craftOfflinePlayer.getDeclaredConstructor(craftServer, gameProfileClass);
|
||||||
|
craftOfflinePlayerConstructor.setAccessible(true);
|
||||||
/**
|
// getOfflinePlayer end
|
||||||
* 获取离线玩家(跳过网络获取)
|
} catch (Exception e) {
|
||||||
*
|
Log.d(e);
|
||||||
* @param playerName 玩家名称
|
}
|
||||||
* @return {@link OfflinePlayer}
|
}
|
||||||
*/
|
|
||||||
@NotProguard
|
private Player() {
|
||||||
public static OfflinePlayer getOfflinePlayer(String playerName) {
|
}
|
||||||
try {
|
|
||||||
Object gameProfile = gameProfileConstructor.newInstance(UUID.nameUUIDFromBytes(("OfflinePlayer:" + playerName).getBytes(Charsets.UTF_8)), playerName);
|
/**
|
||||||
Object offlinePlayer = craftOfflinePlayerConstructor.newInstance(Bukkit.getServer(), gameProfile);
|
* 获取离线玩家(跳过网络获取)
|
||||||
return (OfflinePlayer) offlinePlayer;
|
*
|
||||||
} catch (Exception e) {
|
* @param playerName 玩家名称
|
||||||
return Bukkit.getOfflinePlayer(playerName);
|
* @return {@link OfflinePlayer}
|
||||||
}
|
*/
|
||||||
}
|
@NotProguard
|
||||||
|
public static OfflinePlayer getOfflinePlayer(String playerName) {
|
||||||
/**
|
try {
|
||||||
* 获取在线玩家
|
Object gameProfile = gameProfileConstructor.newInstance(UUID.nameUUIDFromBytes(("OfflinePlayer:" + playerName).getBytes(Charsets.UTF_8)), playerName);
|
||||||
*
|
Object offlinePlayer = craftOfflinePlayerConstructor.newInstance(Bukkit.getServer(), gameProfile);
|
||||||
* @return 在线玩家
|
return (OfflinePlayer) offlinePlayer;
|
||||||
*/
|
} catch (Exception e) {
|
||||||
@NotProguard
|
return Bukkit.getOfflinePlayer(playerName);
|
||||||
public static Collection<? extends org.bukkit.entity.Player> getOnlinePlayers() {
|
}
|
||||||
try {
|
}
|
||||||
return Arrays.asList((org.bukkit.entity.Player[]) getOnlinePlayers.invoke(null));
|
|
||||||
} catch (Exception e) {
|
/**
|
||||||
return Bukkit.getOnlinePlayers();
|
* 获取在线玩家
|
||||||
}
|
*
|
||||||
}
|
* @return 在线玩家
|
||||||
}
|
*/
|
||||||
|
@NotProguard
|
||||||
public static class Title {
|
public static Collection<? extends org.bukkit.entity.Player> getOnlinePlayers() {
|
||||||
private static Class<?> packetActions;
|
try {
|
||||||
private static Class<?> packetTitle;
|
return Arrays.asList((org.bukkit.entity.Player[]) getOnlinePlayers.invoke(null));
|
||||||
private static Constructor<?> packetTitleSendConstructor;
|
} catch (Exception e) {
|
||||||
private static Constructor<?> packetTitleSetTimeConstructor;
|
return Bukkit.getOnlinePlayers();
|
||||||
private static Object[] actions;
|
}
|
||||||
|
}
|
||||||
static {
|
}
|
||||||
try {
|
|
||||||
packetActions = Class.forName(a(newversion ? "PacketPlayOutTitle$EnumTitleAction" : "EnumTitleAction"));
|
public static class Title {
|
||||||
packetTitle = Class.forName(a("PacketPlayOutTitle"));
|
private static Class<?> packetActions;
|
||||||
packetTitleSendConstructor = packetTitle.getConstructor(packetActions, nmsIChatBaseComponent);
|
private static Class<?> packetTitle;
|
||||||
packetTitleSetTimeConstructor = packetTitle.getConstructor(packetActions, nmsIChatBaseComponent, Integer.TYPE, Integer.TYPE, Integer.TYPE);
|
private static Constructor<?> packetTitleSendConstructor;
|
||||||
actions = packetActions.getEnumConstants();
|
private static Constructor<?> packetTitleSetTimeConstructor;
|
||||||
} catch (Exception ignore) {
|
private static Object[] actions;
|
||||||
Log.w("Title 兼容性工具初始化失败 可能造成部分功能不可用!");
|
|
||||||
}
|
static {
|
||||||
}
|
try {
|
||||||
|
packetActions = Class.forName(a(newversion ? "PacketPlayOutTitle$EnumTitleAction" : "EnumTitleAction"));
|
||||||
private Title() {
|
packetTitle = Class.forName(a("PacketPlayOutTitle"));
|
||||||
}
|
packetTitleSendConstructor = packetTitle.getConstructor(packetActions, nmsIChatBaseComponent);
|
||||||
|
packetTitleSetTimeConstructor = packetTitle.getConstructor(packetActions, nmsIChatBaseComponent, Integer.TYPE, Integer.TYPE, Integer.TYPE);
|
||||||
/**
|
actions = packetActions.getEnumConstants();
|
||||||
* 发送Title公告
|
} catch (Exception ignore) {
|
||||||
*
|
Log.w("Title 兼容性工具初始化失败 可能造成部分功能不可用!");
|
||||||
* @param title 标题
|
}
|
||||||
* @param subtitle 子标题
|
}
|
||||||
*/
|
|
||||||
@NotProguard
|
private Title() {
|
||||||
public static void broadcast(String title, String subtitle) {
|
}
|
||||||
for (org.bukkit.entity.Player player : Player.getOnlinePlayers()) {
|
|
||||||
send(player, title, subtitle);
|
/**
|
||||||
}
|
* 发送Title公告
|
||||||
}
|
*
|
||||||
|
* @param title 标题
|
||||||
/**
|
* @param subtitle 子标题
|
||||||
* 发送Title公告
|
*/
|
||||||
*
|
@NotProguard
|
||||||
* @param title 标题
|
public static void broadcast(String title, String subtitle) {
|
||||||
* @param subtitle 子标题
|
for (org.bukkit.entity.Player player : Player.getOnlinePlayers()) {
|
||||||
* @param fadeInTime 淡入时间
|
send(player, title, subtitle);
|
||||||
* @param stayTime 持续时间
|
}
|
||||||
* @param fadeOutTime 淡出时间
|
}
|
||||||
*/
|
|
||||||
@NotProguard
|
/**
|
||||||
public static void broadcast(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
|
* 发送Title公告
|
||||||
for (org.bukkit.entity.Player player : Player.getOnlinePlayers()) {
|
*
|
||||||
send(player, title, subtitle, fadeInTime, stayTime, fadeOutTime);
|
* @param title 标题
|
||||||
}
|
* @param subtitle 子标题
|
||||||
}
|
* @param fadeInTime 淡入时间
|
||||||
|
* @param stayTime 持续时间
|
||||||
/**
|
* @param fadeOutTime 淡出时间
|
||||||
* 发送Title公告
|
*/
|
||||||
*
|
@NotProguard
|
||||||
* @param world 世界
|
public static void broadcast(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
|
||||||
* @param title 标题
|
for (org.bukkit.entity.Player player : Player.getOnlinePlayers()) {
|
||||||
* @param subtitle 子标题
|
send(player, title, subtitle, fadeInTime, stayTime, fadeOutTime);
|
||||||
*/
|
}
|
||||||
@NotProguard
|
}
|
||||||
public static void broadcast(World world, String title, String subtitle) {
|
|
||||||
C.Player.getOnlinePlayers().stream().filter(player -> player.getWorld().getName().equalsIgnoreCase(world.getName())).forEach(player -> send(player, title, subtitle));
|
/**
|
||||||
}
|
* 发送Title公告
|
||||||
|
*
|
||||||
/**
|
* @param world 世界
|
||||||
* 重置玩家的Title
|
* @param title 标题
|
||||||
*
|
* @param subtitle 子标题
|
||||||
* @param recoverPlayer 接受的玩家
|
*/
|
||||||
* @throws Exception 异常
|
@NotProguard
|
||||||
*/
|
public static void broadcast(World world, String title, String subtitle) {
|
||||||
@NotProguard
|
C.Player.getOnlinePlayers().stream().filter(player -> player.getWorld().getName().equalsIgnoreCase(world.getName())).forEach(player -> send(player, title, subtitle));
|
||||||
public static void reset(org.bukkit.entity.Player recoverPlayer) throws Exception {
|
}
|
||||||
// Send timings first
|
|
||||||
Object player = getHandle.invoke(recoverPlayer);
|
/**
|
||||||
Object connection = playerConnection.get(player);
|
* 重置玩家的Title
|
||||||
Object packet = packetTitleSendConstructor.newInstance(actions[4], null);
|
*
|
||||||
sendPacket.invoke(connection, packet);
|
* @param recoverPlayer 接受的玩家
|
||||||
}
|
* @throws Exception 异常
|
||||||
|
*/
|
||||||
/**
|
@NotProguard
|
||||||
* 发送Titile(默认时间 1 2 1)
|
public static void reset(org.bukkit.entity.Player recoverPlayer) throws Exception {
|
||||||
*
|
// Send timings first
|
||||||
* @param receivingPacket 接受信息的玩家
|
Object player = getHandle.invoke(recoverPlayer);
|
||||||
* @param title 标题
|
Object connection = playerConnection.get(player);
|
||||||
* @param subtitle 子标题
|
Object packet = packetTitleSendConstructor.newInstance(actions[4], null);
|
||||||
*/
|
sendPacket.invoke(connection, packet);
|
||||||
@NotProguard
|
}
|
||||||
public static void send(org.bukkit.entity.Player receivingPacket, String title, String subtitle) {
|
|
||||||
send(receivingPacket, title, subtitle, 1, 2, 1);
|
/**
|
||||||
}
|
* 发送Titile(默认时间 1 2 1)
|
||||||
|
*
|
||||||
/**
|
* @param receivingPacket 接受信息的玩家
|
||||||
* 发送Titile
|
* @param title 标题
|
||||||
*
|
* @param subtitle 子标题
|
||||||
* @param receivingPacket 接受信息的玩家
|
*/
|
||||||
* @param title 标题
|
@NotProguard
|
||||||
* @param subtitle 子标题
|
public static void send(org.bukkit.entity.Player receivingPacket, String title, String subtitle) {
|
||||||
* @param fadeInTime 淡入时间
|
send(receivingPacket, title, subtitle, 1, 2, 1);
|
||||||
* @param stayTime 持续时间
|
}
|
||||||
* @param fadeOutTime 淡出时间
|
|
||||||
*/
|
/**
|
||||||
@NotProguard
|
* 发送Titile
|
||||||
public static void send(org.bukkit.entity.Player receivingPacket, String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
|
*
|
||||||
if (packetTitle != null) {
|
* @param receivingPacket 接受信息的玩家
|
||||||
try {
|
* @param title 标题
|
||||||
// First reset previous settings
|
* @param subtitle 子标题
|
||||||
reset(receivingPacket);
|
* @param fadeInTime 淡入时间
|
||||||
// Send timings first
|
* @param stayTime 持续时间
|
||||||
Object player = getHandle.invoke(receivingPacket);
|
* @param fadeOutTime 淡出时间
|
||||||
Object connection = playerConnection.get(player);
|
*/
|
||||||
Object packet;
|
@NotProguard
|
||||||
// Send if set
|
public static void send(org.bukkit.entity.Player receivingPacket, String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
|
||||||
if ((fadeInTime != -1) && (fadeOutTime != -1) && (stayTime != -1)) {
|
if (packetTitle != null) {
|
||||||
packet = packetTitleSetTimeConstructor.newInstance(actions[2], null, fadeInTime * 20, stayTime * 20, fadeOutTime * 20);
|
try {
|
||||||
sendPacket.invoke(connection, packet);
|
// First reset previous settings
|
||||||
}
|
reset(receivingPacket);
|
||||||
// Send title
|
// Send timings first
|
||||||
Object serialized = chatSerializer.invoke(null, "{\"text\":\"" + ChatColor.translateAlternateColorCodes('&', title) + "\"}");
|
Object player = getHandle.invoke(receivingPacket);
|
||||||
packet = packetTitleSendConstructor.newInstance(actions[0], serialized);
|
Object connection = playerConnection.get(player);
|
||||||
sendPacket.invoke(connection, packet);
|
Object packet;
|
||||||
if (!"".equals(subtitle)) {
|
// Send if set
|
||||||
// Send subtitle if present
|
if ((fadeInTime != -1) && (fadeOutTime != -1) && (stayTime != -1)) {
|
||||||
serialized = chatSerializer.invoke(null, "{\"text\":\"" + ChatColor.translateAlternateColorCodes('&', subtitle) + "\"}");
|
packet = packetTitleSetTimeConstructor.newInstance(actions[2], null, fadeInTime * 20, stayTime * 20, fadeOutTime * 20);
|
||||||
packet = packetTitleSendConstructor.newInstance(actions[1], serialized);
|
sendPacket.invoke(connection, packet);
|
||||||
sendPacket.invoke(connection, packet);
|
}
|
||||||
}
|
// Send title
|
||||||
} catch (Exception e) {
|
Object serialized = chatSerializer.invoke(null, "{\"text\":\"" + ChatColor.translateAlternateColorCodes('&', title) + "\"}");
|
||||||
Log.d(e);
|
packet = packetTitleSendConstructor.newInstance(actions[0], serialized);
|
||||||
}
|
sendPacket.invoke(connection, packet);
|
||||||
}
|
if (!"".equals(subtitle)) {
|
||||||
}
|
// Send subtitle if present
|
||||||
}
|
serialized = chatSerializer.invoke(null, "{\"text\":\"" + ChatColor.translateAlternateColorCodes('&', subtitle) + "\"}");
|
||||||
|
packet = packetTitleSendConstructor.newInstance(actions[1], serialized);
|
||||||
|
sendPacket.invoke(connection, packet);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.d(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user