1
0
mirror of https://e.coding.net/circlecloud/YumCore.git synced 2024-11-22 01:48:50 +00:00

release: update to 1.9.0

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2020-10-10 09:43:30 +08:00
parent d438c9a5f1
commit 1e115b3cab
2 changed files with 70 additions and 109 deletions

View File

@ -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.8.9</version> <version>1.9.0</version>
<build> <build>
<finalName>${project.artifactId}</finalName> <finalName>${project.artifactId}</finalName>
<plugins> <plugins>
@ -123,7 +123,7 @@
<dependency> <dependency>
<groupId>com.comphenix.protocol</groupId> <groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId> <artifactId>ProtocolLib</artifactId>
<version>4.2.1</version> <version>4.5.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.sk89q.worldedit</groupId> <groupId>com.sk89q.worldedit</groupId>

View File

@ -1,5 +1,13 @@
package pw.yumc.YumCore.bukkit.compatible; package pw.yumc.YumCore.bukkit.compatible;
import com.google.common.base.Charsets;
import org.bukkit.*;
import org.bukkit.scheduler.BukkitRunnable;
import org.json.simple.JSONObject;
import pw.yumc.YumCore.annotation.NotProguard;
import pw.yumc.YumCore.bukkit.Log;
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;
@ -7,69 +15,54 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.scheduler.BukkitRunnable;
import org.json.simple.JSONObject;
import com.google.common.base.Charsets;
import pw.yumc.YumCore.annotation.NotProguard;
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.bukkit.P;
/** /**
* Bukkit兼容类 * Bukkit兼容类
* *
* @since 2016年7月23日 下午1:04:56
* @author * @author
* @since 2016年7月23日 下午1:04:56
*/ */
public class C { public class C {
private static Class<?> nmsChatSerializer; public static boolean init;
private static boolean above_1_16 = false;
private static Class<?> nmsIChatBaseComponent; private static Class<?> nmsIChatBaseComponent;
private static Class<?> packetType;
private static Class<?> nmsChatMessageTypeClass;
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;
public static boolean init;
static { static {
try { try {
version = getNMSVersion(); version = getNMSVersion();
newversion = Integer.parseInt(version.split("_")[1]) > 7; newversion = Integer.parseInt(version.split("_")[1]) > 7;
nmsChatSerializer = Class.forName(a(newversion ? "IChatBaseComponent$ChatSerializer" : "ChatSerializer")); Class<?> nmsChatSerializer = Class.forName(a(newversion ? "IChatBaseComponent$ChatSerializer" : "ChatSerializer"));
chatSerializer = nmsChatSerializer.getMethod("a", String.class); chatSerializer = nmsChatSerializer.getMethod("a", String.class);
nmsIChatBaseComponent = Class.forName(a("IChatBaseComponent")); nmsIChatBaseComponent = Class.forName(a("IChatBaseComponent"));
packetType = Class.forName(a("PacketPlayOutChat")); Class<?> packetType = Class.forName(a("PacketPlayOutChat"));
Arrays.stream(packetType.getConstructors()).forEach(c -> { Arrays.stream(packetType.getConstructors()).forEach(c -> {
if (c.getParameterTypes().length == 2) { if (c.getParameterTypes().length == 2) {
packetTypeConstructor = c; packetTypeConstructor = c;
} }
if (c.getParameterTypes().length == 3) {
packetTypeConstructor = c;
above_1_16 = true;
}
}); });
nmsChatMessageTypeClass = packetTypeConstructor.getParameterTypes()[1]; Class<?> nmsChatMessageTypeClass = packetTypeConstructor.getParameterTypes()[1];
if (nmsChatMessageTypeClass.isEnum()) { if (nmsChatMessageTypeClass.isEnum()) {
chatMessageTypes = nmsChatMessageTypeClass.getEnumConstants(); chatMessageTypes = nmsChatMessageTypeClass.getEnumConstants();
} else { } else {
switch (nmsChatMessageTypeClass.getName()) { switch (nmsChatMessageTypeClass.getName()) {
case "int": case "int":
nmsChatMessageTypeClass = Integer.class; nmsChatMessageTypeClass = Integer.class;
case "byte": break;
nmsChatMessageTypeClass = Byte.class; case "byte":
nmsChatMessageTypeClass = Byte.class;
break;
} }
nmsChatMessageTypeClassValueOf = nmsChatMessageTypeClass.getDeclaredMethod("valueOf", String.class); nmsChatMessageTypeClassValueOf = nmsChatMessageTypeClass.getDeclaredMethod("valueOf", String.class);
} }
@ -109,14 +102,11 @@ public class C {
/** /**
* 给玩家发送Json消息 * 给玩家发送Json消息
* *
* @param receivingPacket * @param receivingPacket 接受信息的玩家
* 接受信息的玩家 * @param json Json信息
* @param json * @param type 类型
* Json信息 * 0. 消息
* @param type * 2. ActionBar
* 类型
* 0. 消息
* 2. ActionBar
*/ */
public static void sendJson(org.bukkit.entity.Player receivingPacket, String json, int type) { public static void sendJson(org.bukkit.entity.Player receivingPacket, String json, int type) {
try { try {
@ -124,7 +114,9 @@ public class C {
Object player = getHandle.invoke(receivingPacket); Object player = getHandle.invoke(receivingPacket);
Object connection = playerConnection.get(player); Object connection = playerConnection.get(player);
Object typeObj = chatMessageTypes == null ? nmsChatMessageTypeClassValueOf.invoke(null, String.valueOf(type)) : chatMessageTypes[type]; Object typeObj = chatMessageTypes == null ? nmsChatMessageTypeClassValueOf.invoke(null, String.valueOf(type)) : chatMessageTypes[type];
sendPacket.invoke(connection, packetTypeConstructor.newInstance(serialized, typeObj)); sendPacket.invoke(connection, above_1_16
? packetTypeConstructor.newInstance(serialized, typeObj, receivingPacket.getUniqueId())
: packetTypeConstructor.newInstance(serialized, typeObj));
} catch (Exception ex) { } catch (Exception ex) {
Log.d("Json发包错误 " + version, ex); Log.d("Json发包错误 " + version, ex);
} }
@ -137,8 +129,7 @@ public class C {
/** /**
* 公告发送ActionBar * 公告发送ActionBar
* *
* @param message * @param message 需要发送的消息
* 需要发送的消息
*/ */
@NotProguard @NotProguard
public static void broadcast(String message) { public static void broadcast(String message) {
@ -150,10 +141,8 @@ public class C {
/** /**
* 公告发送ActionBar * 公告发送ActionBar
* *
* @param message * @param message 需要发送的消息
* 需要发送的消息 * @param times 需要显示的时间
* @param times
* 需要显示的时间
*/ */
@NotProguard @NotProguard
public static void broadcast(final String message, final int times) { public static void broadcast(final String message, final int times) {
@ -174,12 +163,9 @@ public class C {
/** /**
* 公告发送ActionBar(分世界) * 公告发送ActionBar(分世界)
* *
* @param world * @param world 需要发送的世界
* 需要发送的世界 * @param message 需要发送的消息
* @param message * @param times 需要显示的时间
* 需要发送的消息
* @param times
* 需要显示的时间
*/ */
@NotProguard @NotProguard
public static void broadcast(final World world, final String message, final int times) { public static void broadcast(final World world, final String message, final int times) {
@ -200,10 +186,8 @@ public class C {
/** /**
* 给玩家发送ActionBar消息 * 给玩家发送ActionBar消息
* *
* @param receivingPacket * @param receivingPacket 接受信息的玩家
* 接受信息的玩家 * @param msg ActionBar信息
* @param msg
* ActionBar信息
*/ */
@NotProguard @NotProguard
public static void send(org.bukkit.entity.Player receivingPacket, String msg) { public static void send(org.bukkit.entity.Player receivingPacket, String msg) {
@ -213,12 +197,9 @@ public class C {
/** /**
* 给玩家发送ActionBar消息 * 给玩家发送ActionBar消息
* *
* @param receivingPacket * @param receivingPacket 接受信息的玩家
* 接受信息的玩家 * @param msg 需要发送的消息
* @param msg * @param times 需要显示的时间
* 需要发送的消息
* @param times
* 需要显示的时间
*/ */
@NotProguard @NotProguard
public static void send(final org.bukkit.entity.Player receivingPacket, final String msg, final int times) { public static void send(final org.bukkit.entity.Player receivingPacket, final String msg, final int times) {
@ -240,14 +221,15 @@ public class C {
/** /**
* Bukkit Player兼容类 * Bukkit Player兼容类
* *
* @since 2016年7月23日 下午4:33:40
* @author * @author
* @since 2016年7月23日 下午4:33:40
*/ */
public static class Player { public static class Player {
private static Class<?> gameProfileClass; private static Class<?> gameProfileClass;
private static Constructor<?> gameProfileConstructor; private static Constructor<?> gameProfileConstructor;
private static Constructor<?> craftOfflinePlayerConstructor; private static Constructor<?> craftOfflinePlayerConstructor;
private static Method getOnlinePlayers; private static Method getOnlinePlayers;
static { static {
try { try {
// getOnlinePlayers start // getOnlinePlayers start
@ -291,8 +273,7 @@ public class C {
/** /**
* 获取离线玩家(跳过网络获取) * 获取离线玩家(跳过网络获取)
* *
* @param playerName * @param playerName 玩家名称
* 玩家名称
* @return {@link OfflinePlayer} * @return {@link OfflinePlayer}
*/ */
@NotProguard @NotProguard
@ -327,6 +308,7 @@ public class C {
private static Constructor<?> packetTitleSendConstructor; private static Constructor<?> packetTitleSendConstructor;
private static Constructor<?> packetTitleSetTimeConstructor; private static Constructor<?> packetTitleSetTimeConstructor;
private static Object[] actions; private static Object[] actions;
static { static {
try { try {
packetActions = Class.forName(a(newversion ? "PacketPlayOutTitle$EnumTitleAction" : "EnumTitleAction")); packetActions = Class.forName(a(newversion ? "PacketPlayOutTitle$EnumTitleAction" : "EnumTitleAction"));
@ -345,10 +327,8 @@ public class C {
/** /**
* 发送Title公告 * 发送Title公告
* *
* @param title * @param title 标题
* 标题 * @param subtitle 子标题
* @param subtitle
* 子标题
*/ */
@NotProguard @NotProguard
public static void broadcast(String title, String subtitle) { public static void broadcast(String title, String subtitle) {
@ -360,16 +340,11 @@ public class C {
/** /**
* 发送Title公告 * 发送Title公告
* *
* @param title * @param title 标题
* 标题 * @param subtitle 子标题
* @param subtitle * @param fadeInTime 淡入时间
* 子标题 * @param stayTime 持续时间
* @param fadeInTime * @param fadeOutTime 淡出时间
* 淡入时间
* @param stayTime
* 持续时间
* @param fadeOutTime
* 淡出时间
*/ */
@NotProguard @NotProguard
public static void broadcast(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) { public static void broadcast(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
@ -381,12 +356,9 @@ public class C {
/** /**
* 发送Title公告 * 发送Title公告
* *
* @param world * @param world 世界
* 世界 * @param title 标题
* @param title * @param subtitle 子标题
* 标题
* @param subtitle
* 子标题
*/ */
@NotProguard @NotProguard
public static void broadcast(World world, String title, String subtitle) { public static void broadcast(World world, String title, String subtitle) {
@ -396,10 +368,8 @@ public class C {
/** /**
* 重置玩家的Title * 重置玩家的Title
* *
* @param recoverPlayer * @param recoverPlayer 接受的玩家
* 接受的玩家 * @throws Exception 异常
* @throws Exception
* 异常
*/ */
@NotProguard @NotProguard
public static void reset(org.bukkit.entity.Player recoverPlayer) throws Exception { public static void reset(org.bukkit.entity.Player recoverPlayer) throws Exception {
@ -413,12 +383,9 @@ public class C {
/** /**
* 发送Titile(默认时间 1 2 1) * 发送Titile(默认时间 1 2 1)
* *
* @param receivingPacket * @param receivingPacket 接受信息的玩家
* 接受信息的玩家 * @param title 标题
* @param title * @param subtitle 子标题
* 标题
* @param subtitle
* 子标题
*/ */
@NotProguard @NotProguard
public static void send(org.bukkit.entity.Player receivingPacket, String title, String subtitle) { public static void send(org.bukkit.entity.Player receivingPacket, String title, String subtitle) {
@ -428,18 +395,12 @@ public class C {
/** /**
* 发送Titile * 发送Titile
* *
* @param receivingPacket * @param receivingPacket 接受信息的玩家
* 接受信息的玩家 * @param title 标题
* @param title * @param subtitle 子标题
* 标题 * @param fadeInTime 淡入时间
* @param subtitle * @param stayTime 持续时间
* 子标题 * @param fadeOutTime 淡出时间
* @param fadeInTime
* 淡入时间
* @param stayTime
* 持续时间
* @param fadeOutTime
* 淡出时间
*/ */
@NotProguard @NotProguard
public static void send(org.bukkit.entity.Player receivingPacket, String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) { public static void send(org.bukkit.entity.Player receivingPacket, String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {