AsmClassTransformer
This commit is contained in:
@@ -1,52 +1,20 @@
|
||||
package me.skymc.taboolib.display;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
import com.ilummc.tlib.nms.ActionBar;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.skymc.taboolib.TabooLib;
|
||||
import me.skymc.taboolib.nms.NMSUtils;
|
||||
|
||||
/**
|
||||
* @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) {
|
||||
if (player == null)
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Object ab = ChatComponentText.getConstructor(String.class).newInstance(action);
|
||||
Constructor<?> ac = null;
|
||||
Object abPacket = null;
|
||||
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) {
|
||||
ActionBar.sendActionBar(player, action);
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,37 @@
|
||||
package me.skymc.taboolib.display;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import me.skymc.taboolib.nms.NMSUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.skymc.taboolib.nms.NMSUtils;
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
/**
|
||||
* @author Bkm016
|
||||
* @since 2018-04-26
|
||||
*/
|
||||
public class TitleUtils {
|
||||
|
||||
private static Class<?> Packet = NMSUtils.getNMSClass("Packet");
|
||||
private static Class<?> PacketPlayOutTitle = NMSUtils.getNMSClass("PacketPlayOutTitle");
|
||||
private static Class<?> IChatBaseComponent = NMSUtils.getNMSClass("IChatBaseComponent");
|
||||
private static Class<?> EnumTitleAction = PacketPlayOutTitle.getDeclaredClasses()[0];
|
||||
|
||||
|
||||
private static Class<?> Packet = NMSUtils.getNMSClass("Packet");
|
||||
private static Class<?> PacketPlayOutTitle = NMSUtils.getNMSClass("PacketPlayOutTitle");
|
||||
private static Class<?> IChatBaseComponent = NMSUtils.getNMSClass("IChatBaseComponent");
|
||||
private static Class<?> EnumTitleAction = PacketPlayOutTitle.getDeclaredClasses()[0];
|
||||
|
||||
public static void sendTitle(Player p, String title, String subtitle, int fadein, int stay, int fadeout) {
|
||||
sendTitle(p, title, fadein, stay, fadeout, subtitle, fadein, stay, fadeout);
|
||||
sendTitle(p, title, fadein, stay, fadeout, subtitle, fadein, stay, fadeout);
|
||||
}
|
||||
|
||||
|
||||
public static void sendTitle(Player p, String title, int fadeint, int stayt, int fadeoutt, String subtitle, int fadeinst, int stayst, int fadeoutst) {
|
||||
if (p == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (p == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (title != null) {
|
||||
Object times = EnumTitleAction.getField("TIMES").get(null);
|
||||
Object chatTitle = IChatBaseComponent.getDeclaredClasses()[0].getMethod("a", String.class).invoke(null, "{\"text\":\"" + title + "\"}");
|
||||
Constructor<?> subtitleConstructor = PacketPlayOutTitle.getConstructor(EnumTitleAction, IChatBaseComponent, Integer.TYPE, Integer.TYPE, Integer.TYPE);
|
||||
Object titlePacket = subtitleConstructor.newInstance(times, chatTitle, fadeint, stayt, fadeoutt);
|
||||
sendPacket(p, titlePacket);
|
||||
|
||||
|
||||
times = EnumTitleAction.getField("TITLE").get(null);
|
||||
chatTitle = IChatBaseComponent.getDeclaredClasses()[0].getMethod("a", String.class).invoke(null, "{\"text\":\"" + title + "\"}");
|
||||
subtitleConstructor = PacketPlayOutTitle.getConstructor(EnumTitleAction, IChatBaseComponent);
|
||||
@@ -46,18 +44,17 @@ public class TitleUtils {
|
||||
Constructor<?> subtitleConstructor = PacketPlayOutTitle.getConstructor(EnumTitleAction, IChatBaseComponent, Integer.TYPE, Integer.TYPE, Integer.TYPE);
|
||||
Object subtitlePacket = subtitleConstructor.newInstance(times, chatSubtitle, fadeinst, stayst, fadeoutst);
|
||||
sendPacket(p, subtitlePacket);
|
||||
|
||||
|
||||
times = EnumTitleAction.getField("SUBTITLE").get(null);
|
||||
chatSubtitle = IChatBaseComponent.getDeclaredClasses()[0].getMethod("a", String.class).invoke(null, "{\"text\":\"" + subtitle + "\"}");
|
||||
subtitleConstructor = PacketPlayOutTitle.getConstructor(EnumTitleAction, IChatBaseComponent, Integer.TYPE, Integer.TYPE, Integer.TYPE);
|
||||
subtitlePacket = subtitleConstructor.newInstance(times, chatSubtitle, fadeinst, stayst, fadeoutst);
|
||||
sendPacket(p, subtitlePacket);
|
||||
}
|
||||
}
|
||||
catch (Exception ignored) {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void sendPacket(Player player, Object packet) {
|
||||
try {
|
||||
Object handle = player.getClass().getDeclaredMethod("getHandle").invoke(player);
|
||||
|
||||
@@ -3,6 +3,7 @@ package me.skymc.taboolib.fileutils;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.io.Files;
|
||||
import com.ilummc.tlib.TLib;
|
||||
import com.ilummc.tlib.bean.Property;
|
||||
import com.ilummc.tlib.util.Ref;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.MemoryConfiguration;
|
||||
@@ -86,13 +87,20 @@ public class ConfigUtils {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T mapToObj(Map<String, Object> map, T obj) {
|
||||
Class<?> clazz = obj.getClass();
|
||||
map.forEach((string, value) -> Ref.getFieldBySerializedName(clazz, string).ifPresent(field -> {
|
||||
if (!field.isAccessible())
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
field.set(obj, value);
|
||||
if (Property.class.isAssignableFrom(field.getType())) {
|
||||
Property<Object> property = (Property) field.get(obj);
|
||||
if (property != null) property.set(value);
|
||||
else field.set(obj, Property.of(value));
|
||||
} else {
|
||||
field.set(obj, value);
|
||||
}
|
||||
} catch (IllegalAccessException ignored) {
|
||||
}
|
||||
}));
|
||||
@@ -108,7 +116,9 @@ public class ConfigUtils {
|
||||
for (Field field : Ref.getDeclaredFields(object.getClass(), excludedModifiers, false)) {
|
||||
try {
|
||||
if (!field.isAccessible()) field.setAccessible(true);
|
||||
map.put(Ref.getSerializedName(field), field.get(object));
|
||||
Object obj = field.get(object);
|
||||
if (obj instanceof Property) obj = ((Property) obj).get();
|
||||
map.put(Ref.getSerializedName(field), obj);
|
||||
} catch (IllegalAccessException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,14 @@
|
||||
package me.skymc.taboolib.fileutils;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import ch.njol.util.Closeable;
|
||||
import me.skymc.taboolib.message.MsgUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.channels.FileChannel;
|
||||
|
||||
import ch.njol.util.Closeable;
|
||||
import me.skymc.taboolib.message.MsgUtils;
|
||||
|
||||
public class FileUtils {
|
||||
|
||||
public static String ip() {
|
||||
@@ -247,6 +239,11 @@ public class FileUtils {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getStringFromURL(String url, String def) {
|
||||
String s = getStringFromURL(url, 1024);
|
||||
return s == null ? def : s;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
package me.skymc.taboolib.update;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import me.skymc.taboolib.Main;
|
||||
import me.skymc.taboolib.TabooLib;
|
||||
import me.skymc.taboolib.fileutils.FileUtils;
|
||||
import me.skymc.taboolib.message.MsgUtils;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
* @author sky
|
||||
* @since 2018年2月23日 下午10:39:14
|
||||
*/
|
||||
public class UpdateTask {
|
||||
|
||||
private static final String API = "https://api.github.com/repos/Bkm016/TabooLib/releases/latest";
|
||||
|
||||
/**
|
||||
* 检测更新
|
||||
@@ -27,14 +27,10 @@ public class UpdateTask {
|
||||
if (!Main.getInst().getConfig().getBoolean("UPDATE-CHECK")) {
|
||||
return;
|
||||
}
|
||||
String value = FileUtils.getStringFromURL("https://github.com/Bkm016/TabooLib/releases", 1024);
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
Pattern pattern = Pattern.compile("<a href=\"/Bkm016/TabooLib/releases/tag/(\\S+)\">");
|
||||
Matcher matcher = pattern.matcher(value);
|
||||
if (matcher.find()) {
|
||||
double newVersion = Double.valueOf(matcher.group(1));
|
||||
String value = FileUtils.getStringFromURL(API, "{}");
|
||||
JsonObject json = new JsonParser().parse(value).getAsJsonObject();
|
||||
if (json.entrySet().size() > 0) {
|
||||
double newVersion = Double.parseDouble(json.get("tag_name").getAsString());
|
||||
if (TabooLib.getPluginVersion() >= newVersion) {
|
||||
MsgUtils.send("插件已是最新版, 无需更新!");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user