This commit is contained in:
sky 2020-01-23 18:14:06 +08:00
parent 8f2b0f419e
commit f3aa249fdd
7 changed files with 113 additions and 17 deletions

View File

@ -6,7 +6,7 @@ plugins {
}
group = 'me.skymc'
version = '5.14'
version = '5.15'
sourceCompatibility = 1.8
targetCompatibility = 1.8

View File

@ -2,34 +2,35 @@ package io.izzel.taboolib.common.listener;
import io.izzel.taboolib.TabooLibAPI;
import io.izzel.taboolib.Version;
import io.izzel.taboolib.common.plugin.InternalPluginBridge;
import io.izzel.taboolib.module.db.local.Local;
import io.izzel.taboolib.module.db.local.LocalPlayer;
import io.izzel.taboolib.module.inject.TListener;
import io.izzel.taboolib.module.locale.TLocale;
import io.izzel.taboolib.module.locale.logger.TLogger;
import io.izzel.taboolib.module.tellraw.TellrawJson;
import io.izzel.taboolib.util.ArrayUtil;
import io.izzel.taboolib.util.Files;
import io.izzel.taboolib.util.item.Items;
import io.izzel.taboolib.util.lite.Signs;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.server.ServerCommandEvent;
import java.io.File;
import java.util.Arrays;
/**
* @author sky
*/
@TListener
public class ListenerPlayerCommand implements Listener {
public class ListenerCommand implements Listener {
@EventHandler
public void cmd(PlayerCommandPreprocessEvent e) {
if (e.getMessage().equalsIgnoreCase("/tabooLib")) {
e.setCancelled(true);
TLocale.Display.sendTitle(e.getPlayer(), "§fTabooLib", "§7TabooLib is enabled.");
TLocale.Display.sendTitle(e.getPlayer(), "§fTabooLib", "§7TabooLib Enabled.");
}
if (e.getMessage().equalsIgnoreCase("/tellrawTest") && e.getPlayer().hasPermission("*")) {
e.setCancelled(true);
@ -39,13 +40,9 @@ public class ListenerPlayerCommand implements Listener {
.append("§f]")
.send(e.getPlayer());
}
if (e.getMessage().equalsIgnoreCase("/placeholderTest") && e.getPlayer().hasPermission("*")) {
if (e.getMessage().equalsIgnoreCase("/fakesignTest") && e.getPlayer().hasPermission("*")) {
e.setCancelled(true);
e.getPlayer().sendMessage(InternalPluginBridge.handle().setPlaceholders(e.getPlayer(), "§8[§3§lTabooLib§8] §7PlaceholderAPI Test: §f%player_name%"));
}
if (e.getMessage().equalsIgnoreCase("/fakesignTest") && e.getPlayer().hasPermission("&")) {
e.setCancelled(true);
Signs.fakeSign(e.getPlayer(), ArrayUtil.asArray("§nFakeSign Test"), lines -> {
Signs.fakeSign(e.getPlayer(), lines -> {
e.getPlayer().sendMessage("§8[§3§lTabooLib§8] §7FakeSign Lines: §f" + Arrays.toString(lines));
});
}
@ -71,6 +68,19 @@ public class ListenerPlayerCommand implements Listener {
TabooLibAPI.debug(true);
TLogger.getGlobalLogger().info("&aEnabled.");
}
} else if (e.getCommand().equalsIgnoreCase("libUpdateConfirm")) {
if (Version.isAfter(Version.v1_8)) {
e.setCancelled(true);
}
Bukkit.getConsoleSender().sendMessage("§f[TabooLib] §7正在下载资源文件...");
Files.downloadFile("https://skymc.oss-cn-shanghai.aliyuncs.com/plugins/TabooLib.jar", new File("libs/TabooLib.jar"));
Bukkit.getConsoleSender().sendMessage("§f[TabooLib] §7资源文件下载完成! 服务器即将重启...");
try {
Thread.sleep(3000L);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
Bukkit.shutdown();
}
}
}

View File

@ -195,8 +195,7 @@ public class NMSImpl extends NMS {
return "entity.Villager." + name;
}
return "entity." + entity.getType().getEntityClass().getSimpleName() + ".name";
} catch (Throwable t) {
t.printStackTrace();
} catch (Throwable ignore) {
}
return "entity.null";
}

View File

@ -80,7 +80,7 @@ public class NBTBase {
}
public String toJsonSimplified(int index) {
return data instanceof String ? "\"" + data + "\"" : String.valueOf(data);
return data instanceof String ? "\"" + data + "\"" : toString();
}
public String asString() {
@ -152,6 +152,10 @@ public class NBTBase {
return new NBTBase((long) obj);
} else if (obj instanceof Byte) {
return new NBTBase((byte) obj);
} else if (obj instanceof byte[]) {
return new NBTBase((byte[]) obj);
} else if (obj instanceof int[]) {
return new NBTBase((int[]) obj);
} else if (obj instanceof List) {
return translateList(new NBTList(), (List) obj);
} else if (obj instanceof Map) {

View File

@ -1,8 +1,7 @@
package io.izzel.taboolib.module.nms.nbt;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.*;
import io.izzel.taboolib.module.nms.NMS;
import io.izzel.taboolib.util.Strings;
import org.bukkit.inventory.ItemStack;
@ -64,7 +63,67 @@ public class NBTCompound extends NBTBase implements Map<String, NBTBase> {
}
public static NBTCompound fromJson(String json) {
return new Gson().fromJson(json, NBTCompound.class);
return (NBTCompound) fromJson(new JsonParser().parse(json));
}
static NBTBase fromJson(JsonElement element) {
if (element instanceof JsonObject) {
JsonObject json = (JsonObject) element;
// base
if (json.has("type") && json.has("data") && json.size() == 2) {
switch (NBTType.parse(json.get("type").getAsString())) {
case BYTE:
return new NBTBase(json.get("data").getAsByte());
case SHORT:
return new NBTBase(json.get("data").getAsShort());
case INT:
return new NBTBase(json.get("data").getAsInt());
case LONG:
return new NBTBase(json.get("data").getAsLong());
case FLOAT:
return new NBTBase(json.get("data").getAsFloat());
case DOUBLE:
return new NBTBase(json.get("data").getAsDouble());
case STRING:
return new NBTBase(json.get("data").getAsString());
case BYTE_ARRAY: {
JsonArray array = json.get("data").getAsJsonArray();
byte[] bytes = new byte[array.size()];
for (int i = 0; i < array.size(); i++) {
bytes[i] = array.get(i).getAsByte();
}
return new NBTBase(bytes);
}
case INT_ARRAY: {
JsonArray array = json.get("data").getAsJsonArray();
int[] ints = new int[array.size()];
for (int i = 0; i < array.size(); i++) {
ints[i] = array.get(i).getAsInt();
}
return new NBTBase(ints);
}
default:
return new NBTBase("error: " + element);
}
}
// compound
else {
NBTCompound compound = new NBTCompound();
for (Entry<String, JsonElement> elementEntry : json.entrySet()) {
compound.put(elementEntry.getKey(), fromJson(elementEntry.getValue()));
}
return compound;
}
}
// list
else if (element instanceof JsonArray) {
NBTList list = new NBTList();
for (JsonElement jsonElement : (JsonArray) element) {
list.add(fromJson(jsonElement));
}
return list;
}
return new NBTBase("error: " + element);
}
@Override

View File

@ -1,5 +1,7 @@
package io.izzel.taboolib.module.nms.nbt;
import com.google.common.base.Enums;
/**
* @Author 坏黑
* @Since 2019-05-24 17:46
@ -39,4 +41,8 @@ public enum NBTType {
public int getId() {
return this.id;
}
public static NBTType parse(String in) {
return Enums.getIfPresent(NBTType.class, in).or(END);
}
}

View File

@ -10,11 +10,13 @@ import org.bukkit.plugin.Plugin;
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
import java.io.*;
import java.math.BigInteger;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.jar.JarFile;
@ -347,6 +349,22 @@ public class Files {
return new YamlConfiguration();
}
public static String getFileHash(File file, String algorithm) {
try(FileInputStream fileInputStream = new FileInputStream(file)) {
MessageDigest digest = MessageDigest.getInstance(algorithm);
byte[] buffer = new byte[1024];
int length;
while ((length = fileInputStream.read(buffer, 0, 1024)) != -1) {
digest.update(buffer, 0, length);
}
byte[] md5Bytes = digest.digest();
return new BigInteger(1, md5Bytes).toString(16);
} catch (Throwable t) {
t.printStackTrace();
}
return null;
}
private static Class getCaller(Class<?> obj) {
try {
return Class.forName(Thread.currentThread().getStackTrace()[3].getClassName(), false, obj.getClassLoader());