entities) {
- for (Entity entity : entities) {
- remove(key, entity);
- }
- }
-
- /**
- * 检查数据
- *
- * @param entity 实体
- * @return boolean
- */
- public boolean contains(Entity entity) {
- return entityData.containsKey(entity.getUniqueId());
- }
-
- /**
- * 检查标签
- *
- * @param key 键
- * @param entity 实体
- * @return boolean
- */
- public boolean hasKey(String key, Entity entity) {
- return contains(entity) && entityData.get(entity.getUniqueId()).containsKey(key);
- }
-
- /**
- * 获取数据
- *
- * @param key 键
- * @param entity 实体
- * @return Object
- */
- public Object get(String key, Entity entity) {
- if (contains(entity)) {
- return entityData.get(entity.getUniqueId()).get(key);
- }
- return null;
- }
-
- /**
- * 获取数据
- *
- * @param key 键
- * @param entity 值
- * @return String
- */
- public String getString(String key, Entity entity) {
- Object object = get(key, entity);
- if (object instanceof String) {
- return (String) object;
- }
- return null;
- }
-
- /**
- * 获取数据
- *
- * @param key 键
- * @param entity 值
- * @return int
- */
- public int getInteger(String key, Entity entity) {
- Object object = get(key, entity);
- if (object != null) {
- return (int) object;
- }
- return 0;
- }
-
- /**
- * 获取数据
- *
- * @param key 键
- * @param entity 值
- * @return long
- */
- public long getLong(String key, Entity entity) {
- Object object = get(key, entity);
- if (object != null) {
- return (long) object;
- }
- return 0L;
- }
-
- /**
- * 获取数据
- *
- * @param key 键
- * @param entity 实体
- * @return boolean
- */
- public boolean getBoolean(String key, Entity entity) {
- Object object = get(key, entity);
- return object != null && (boolean) object;
- }
-
- /**
- * 获取数据
- *
- * @param key 键
- * @param entity 实体
- * @return double
- */
- public double getDouble(String key, Entity entity) {
- Object object = get(key, entity);
- if (object != null) {
- return (double) object;
- }
- return 0D;
- }
-
- /**
- * 获取数据
- *
- * @param key 键
- * @param entity 实体
- * @return float
- */
- public double getFloat(String key, Entity entity) {
- Object object = get(key, entity);
- if (object != null) {
- return (float) object;
- }
- return 0F;
- }
-
- /**
- * 获取数据
- *
- * @param key 键
- * @param entity 实体
- * @return short
- */
- public short getShort(String key, Entity entity) {
- Object object = get(key, entity);
- if (object != null) {
- return (short) object;
- }
- return (short) 0;
- }
-
- /**
- * 获取数据
- *
- * @param key 键
- * @param entity 实体
- * @return byte
- */
- public byte getByte(String key, Entity entity) {
- Object object = get(key, entity);
- if (object != null) {
- return (byte) object;
- }
- return (byte) 0;
- }
-}
diff --git a/src/main/java/me/skymc/taboolib/entity/EntityUtils.java b/src/main/java/me/skymc/taboolib/entity/EntityUtils.java
deleted file mode 100644
index d324e00..0000000
--- a/src/main/java/me/skymc/taboolib/entity/EntityUtils.java
+++ /dev/null
@@ -1,111 +0,0 @@
-package me.skymc.taboolib.entity;
-
-import com.comphenix.protocol.PacketType;
-import com.comphenix.protocol.ProtocolLibrary;
-import com.comphenix.protocol.events.PacketContainer;
-import com.comphenix.protocol.wrappers.WrappedDataWatcher;
-import com.ilummc.tlib.resources.TLocale;
-import me.skymc.taboolib.TabooLib;
-import me.skymc.taboolib.listener.TListener;
-import org.bukkit.Bukkit;
-import org.bukkit.World;
-import org.bukkit.entity.Entity;
-import org.bukkit.entity.Player;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.Listener;
-import org.bukkit.event.entity.EntitySpawnEvent;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.UUID;
-
-/**
- * @author sky
- */
-@TListener(condition = "check")
-public class EntityUtils implements Listener {
-
- private static Entity lastSpawnedEntity = null;
-
- public static Entity getLastSpawnedEntity() {
- return lastSpawnedEntity;
- }
-
- public static boolean check() {
- return TabooLib.getVerint() > 10700;
- }
-
- /**
- * 根据 UUID 获取生物
- *
- * @param u
- * @return
- */
- public static Entity getEntityWithUUID(UUID u) {
- return Bukkit.getWorlds().stream().flatMap(w -> w.getLivingEntities().stream()).filter(e -> e.getUniqueId().equals(u)).findFirst().orElse(null);
- }
-
- /**
- * 根据 UUID 获取生物(单世界)
- *
- * @param u
- * @param world
- * @return
- */
- public static Entity getEntityWithUUID(UUID u, World world) {
- return world.getLivingEntities().stream().filter(e -> e.getUniqueId().equals(u)).findFirst().orElse(null);
- }
-
- /**
- * 设置生物发光(ProcotolLib)
- *
- * @param player
- * @param entity
- */
- public static void addGlow(Player player, Entity entity) {
- if (Bukkit.getPluginManager().getPlugin("ProtocolLib") == null) {
- TLocale.sendToConsole("ENTITY-UTILS.NOTFOUND-PROTOCOLLIB");
- }
- PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_METADATA);
- packet.getIntegers().write(0, entity.getEntityId());
- WrappedDataWatcher watcher = new WrappedDataWatcher();
- WrappedDataWatcher.Serializer serializer = WrappedDataWatcher.Registry.get(Byte.class);
- watcher.setEntity(player);
- watcher.setObject(0, serializer, (byte) (0x40));
- packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects());
- try {
- ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- }
- }
-
- /**
- * 取消生物发光(ProcotolLib)
- *
- * @param player
- * @param entity
- */
- public static void delGlow(Player player, Entity entity) {
- if (Bukkit.getPluginManager().getPlugin("ProtocolLib") == null) {
- TLocale.sendToConsole("ENTITY-UTILS.NOTFOUND-PROTOCOLLIB");
- }
- PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_METADATA);
- packet.getIntegers().write(0, entity.getEntityId());
- WrappedDataWatcher watcher = new WrappedDataWatcher();
- WrappedDataWatcher.Serializer serializer = WrappedDataWatcher.Registry.get(Byte.class);
- watcher.setEntity(player);
- watcher.setObject(0, serializer, (byte) (0x0));
- packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects());
- try {
- ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- }
- }
-
- @EventHandler
- public void spawn(EntitySpawnEvent e) {
- lastSpawnedEntity = e.getEntity();
- }
-
-}
diff --git a/src/main/java/me/skymc/taboolib/entity/VectorUtils.java b/src/main/java/me/skymc/taboolib/entity/VectorUtils.java
deleted file mode 100644
index e174206..0000000
--- a/src/main/java/me/skymc/taboolib/entity/VectorUtils.java
+++ /dev/null
@@ -1,122 +0,0 @@
-package me.skymc.taboolib.entity;
-
-import me.skymc.taboolib.other.NumberUtils;
-import org.bukkit.Location;
-import org.bukkit.entity.Entity;
-import org.bukkit.entity.Item;
-import org.bukkit.entity.Player;
-import org.bukkit.inventory.ItemStack;
-import org.bukkit.util.Vector;
-
-import java.util.stream.IntStream;
-
-/**
- * @Author sky
- * @Since 2018-06-24 16:32
- */
-public class VectorUtils {
-
- /**
- * 物品丢弃
- *
- * 常用参数:
- * itemDrop(player, itemStack, 0.2, 0.5)
- *
- * @param player 玩家
- * @param itemStack 丢弃物品
- * @param bulletSpread 视角偏移
- * @param radius 距离
- * @return {@link Item}
- */
- public static Item itemDrop(Player player, ItemStack itemStack, double bulletSpread, double radius) {
- Location location = player.getLocation().add(0, 1.5, 0);
- Item item = player.getWorld().dropItem(location, itemStack);
-
- double yaw = Math.toRadians(-player.getLocation().getYaw() - 90.0F);
- double pitch = Math.toRadians(-player.getLocation().getPitch());
- double x;
- double y;
- double z;
-
- if (bulletSpread > 0) {
- double[] spread = {1.0D, 1.0D, 1.0D};
- IntStream.range(0, 3).forEach(t -> spread[t] = ((NumberUtils.getRandom().nextDouble() - NumberUtils.getRandom().nextDouble()) * bulletSpread * 0.1D));
- x = Math.cos(pitch) * Math.cos(yaw) + spread[0];
- y = Math.sin(pitch) + spread[1];
- z = -Math.sin(yaw) * Math.cos(pitch) + spread[2];
- } else {
- x = Math.cos(pitch) * Math.cos(yaw);
- y = Math.sin(pitch);
- z = -Math.sin(yaw) * Math.cos(pitch);
- }
-
- Vector dirVel = new Vector(x, y, z);
- item.setVelocity(dirVel.normalize().multiply(radius));
- return item;
- }
-
- /**
- * 生物抛射
- *
- * 常用参数:
- * entityPush(entity, location, 15)
- *
- * @param entity 目标生物
- * @param to 目标坐标
- * @param velocity 力量
- */
- public static void entityPush(Entity entity, Location to, double velocity) {
- Location from = entity.getLocation();
-
- Vector test = to.clone().subtract(from).toVector();
- double elevation = test.getY();
-
- Double launchAngle = calculateLaunchAngle(from, to, velocity, elevation, 20.0D);
- double distance = Math.sqrt(Math.pow(test.getX(), 2.0D) + Math.pow(test.getZ(), 2.0D));
- if (distance == 0.0D) {
- return;
- }
- if (launchAngle == null) {
- launchAngle = Math.atan((40.0D * elevation + Math.pow(velocity, 2.0D)) / (40.0D * elevation + 2.0D * Math.pow(velocity, 2.0D)));
- }
- double hangTime = calculateHangTime(launchAngle, velocity, elevation, 20.0D);
-
- test.setY(Math.tan(launchAngle) * distance);
- test = normalizeVector(test);
-
- Vector noise = Vector.getRandom();
- noise = noise.multiply(1 / 10.0D);
- test.add(noise);
-
- velocity = velocity + 1.188D * Math.pow(hangTime, 2.0D) + (NumberUtils.getRandom().nextDouble() - 0.8D) / 2.0D;
- test = test.multiply(velocity / 20.0D);
-
- entity.setVelocity(test);
- }
-
- // *********************************
- //
- // Private Methods
- //
- // *********************************
-
- private static double calculateHangTime(double launchAngle, double v, double elev, double g) {
- double a = v * Math.sin(launchAngle);
- double b = -2.0D * g * elev;
- return Math.pow(a, 2.0D) + b < 0.0D ? 0.0D : (a + Math.sqrt(Math.pow(a, 2.0D) + b)) / g;
- }
-
- private static Vector normalizeVector(Vector victor) {
- double mag = Math.sqrt(Math.pow(victor.getX(), 2.0D) + Math.pow(victor.getY(), 2.0D) + Math.pow(victor.getZ(), 2.0D));
- return mag != 0.0D ? victor.multiply(1.0D / mag) : victor.multiply(0);
- }
-
- private static Double calculateLaunchAngle(Location from, Location to, double v, double elevation, double g) {
- Vector vector = from.clone().subtract(to).toVector();
- double distance = Math.sqrt(Math.pow(vector.getX(), 2.0D) + Math.pow(vector.getZ(), 2.0D));
- double v2 = Math.pow(v, 2.0D);
- double v4 = Math.pow(v, 4.0D);
- double check = g * (g * Math.pow(distance, 2.0D) + 2.0D * elevation * v2);
- return v4 < check ? null : Math.atan((v2 - Math.sqrt(v4 - check)) / (g * distance));
- }
-}
diff --git a/src/main/java/me/skymc/taboolib/events/DefaultEvent.java b/src/main/java/me/skymc/taboolib/events/DefaultEvent.java
deleted file mode 100644
index cc24099..0000000
--- a/src/main/java/me/skymc/taboolib/events/DefaultEvent.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package me.skymc.taboolib.events;
-
-import org.bukkit.entity.Player;
-import org.bukkit.event.Event;
-import org.bukkit.event.HandlerList;
-
-public class DefaultEvent extends Event {
-
- private static final HandlerList handlers = new HandlerList();
- private Player player;
-
- public DefaultEvent(Player player) {
- this.player = player;
- }
-
- public Player getPlayer() {
- return this.player;
- }
-
- @Override
- public HandlerList getHandlers() {
- return handlers;
- }
-
- public static HandlerList getHandlerList() {
- return handlers;
- }
-}
diff --git a/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java b/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java
index f11b99f..5c3ad6a 100644
--- a/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java
+++ b/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java
@@ -160,6 +160,20 @@ public class FileUtils {
}
}
+ /**
+ * 释放资源文件
+ *
+ * @param plugin 所属插件
+ * @param path 地址
+ * @param replace 是否替换
+ */
+ public static void releaseResource(Plugin plugin, String path, boolean replace) {
+ File file = new File(plugin.getDataFolder(), path);
+ if (!file.exists() || replace) {
+ inputStreamToFile(getResource(plugin, path), file);
+ }
+ }
+
/**
* 检测文件并创建
*
diff --git a/src/main/java/me/skymc/taboolib/inventory/DropUtils.java b/src/main/java/me/skymc/taboolib/inventory/DropUtils.java
deleted file mode 100644
index 0da14da..0000000
--- a/src/main/java/me/skymc/taboolib/inventory/DropUtils.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package me.skymc.taboolib.inventory;
-
-import me.skymc.taboolib.entity.VectorUtils;
-import me.skymc.taboolib.other.NumberUtils;
-import org.bukkit.Location;
-import org.bukkit.entity.Item;
-import org.bukkit.entity.Player;
-import org.bukkit.inventory.ItemStack;
-import org.bukkit.util.Vector;
-
-import java.util.stream.IntStream;
-
-@Deprecated
-public class DropUtils {
-
- public static Item drop(Player player, ItemStack itemStack, double bulletSpread, double radius) {
- return VectorUtils.itemDrop(player, itemStack, bulletSpread, radius);
- }
-
-}
diff --git a/src/main/java/me/skymc/taboolib/inventory/InventoryUtil.java b/src/main/java/me/skymc/taboolib/inventory/InventoryUtil.java
deleted file mode 100644
index 67bd4da..0000000
--- a/src/main/java/me/skymc/taboolib/inventory/InventoryUtil.java
+++ /dev/null
@@ -1,120 +0,0 @@
-package me.skymc.taboolib.inventory;
-
-import org.bukkit.entity.Player;
-import org.bukkit.inventory.Inventory;
-import org.bukkit.inventory.ItemStack;
-
-import java.util.Arrays;
-import java.util.LinkedList;
-
-/**
- * @author sky
- */
-public class InventoryUtil {
-
- public final static LinkedList SLOT_OF_CENTENTS = new LinkedList<>(Arrays.asList(
- 10, 11, 12, 13, 14, 15, 16,
- 19, 20, 21, 22, 23, 24, 25,
- 28, 29, 30, 31, 32, 33, 34,
- 37, 38, 39, 40, 41, 42, 43));
-
- @Deprecated
- public static boolean isEmpey(Player p) {
- return isEmpty(p, 0);
- }
-
- /**
- * 检查背包是否有空位
- *
- * @param p 玩家
- * @param i 起始位置
- */
- public static boolean isEmpty(Player p, int i) {
- while (i < 35) {
- if (p.getInventory().getItem(i) == null) {
- return true;
- }
- i++;
- }
- return false;
- }
-
- /**
- * 检测玩家是否有指定物品
- *
- * @param player 玩家
- * @param item 物品
- * @param amount 数量
- * @param remove 是否删除
- */
- public static boolean hasItem(Player player, ItemStack item, int amount, boolean remove) {
- int hasAmount = 0;
- for (ItemStack _item : player.getInventory()) {
- if (item.isSimilar(_item)) {
- hasAmount += _item.getAmount();
- }
- }
- if (hasAmount < amount) {
- return false;
- }
- int requireAmount = amount;
- for (int i = 0; i < player.getInventory().getSize() && remove; i++) {
- ItemStack _item = player.getInventory().getItem(i);
- if (_item != null && _item.isSimilar(item)) {
- if (_item.getAmount() < requireAmount) {
- player.getInventory().setItem(i, null);
- requireAmount -= _item.getAmount();
- } else if (_item.getAmount() == requireAmount) {
- player.getInventory().setItem(i, null);
- return true;
- } else {
- _item.setAmount(_item.getAmount() - requireAmount);
- return true;
- }
- }
- }
- return true;
- }
-
- @Deprecated
- public static boolean hasItem(Inventory targetInventory, ItemStack targetItem, Integer amount) {
- int inventoryAmount = 0;
- for (ItemStack item : targetInventory) {
- if (item != null) {
- if (item.isSimilar(targetItem)) {
- inventoryAmount += item.getAmount();
- }
- }
- }
- return inventoryAmount >= amount;
- }
-
- @Deprecated
- public static boolean takeItem2(Inventory inv, ItemStack takeitem, Integer amount) {
- for (int i = 0; i < inv.getSize(); ++i) {
- if (amount <= 0) {
- return true;
- }
-
- ItemStack item = inv.getItem(i);
- if (item == null) {
- continue;
- }
- if (!item.isSimilar(takeitem)) {
- continue;
- }
- if (item.getAmount() >= amount) {
- if (item.getAmount() - amount == 0) {
- inv.setItem(i, null);
- } else {
- item.setAmount(item.getAmount() - amount);
- }
- return true;
- } else {
- amount -= item.getAmount();
- inv.setItem(i, null);
- }
- }
- return false;
- }
-}
diff --git a/src/main/java/me/skymc/taboolib/inventory/builder/ItemBuilder.java b/src/main/java/me/skymc/taboolib/inventory/builder/ItemBuilder.java
index 6e3a7d5..b418223 100644
--- a/src/main/java/me/skymc/taboolib/inventory/builder/ItemBuilder.java
+++ b/src/main/java/me/skymc/taboolib/inventory/builder/ItemBuilder.java
@@ -42,6 +42,11 @@ public class ItemBuilder {
itemMeta = itemStack.getItemMeta();
}
+ public ItemBuilder(ItemStack itemStack) {
+ this.itemStack = itemStack;
+ this.itemMeta = itemStack.getItemMeta();
+ }
+
public ItemBuilder(OfflinePlayer player) {
this(Material.SKULL_ITEM, 1, 3);
this.skullOwner(player.getName());
diff --git a/src/main/java/me/skymc/taboolib/inventory/speciaitem/AbstractSpecialItem.java b/src/main/java/me/skymc/taboolib/inventory/speciaitem/AbstractSpecialItem.java
deleted file mode 100644
index b29164a..0000000
--- a/src/main/java/me/skymc/taboolib/inventory/speciaitem/AbstractSpecialItem.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package me.skymc.taboolib.inventory.speciaitem;
-
-import org.bukkit.entity.Player;
-import org.bukkit.inventory.ItemStack;
-import org.bukkit.plugin.Plugin;
-
-/**
- * @author sky
- * @since 2018年2月17日 下午8:35:42
- */
-public interface AbstractSpecialItem {
-
- /**
- * 当接口被载入
- */
- default void onEnable() {}
-
- /**
- * 当接口被卸载
- */
- default void onDisable() {}
-
- /**
- * 获取识别名称
- *
- * @return String
- */
- String getName();
-
- /**
- * 获取载入插件
- *
- * @return {@link Plugin}
- */
- Plugin getPlugin();
-
- /**
- * 是否进行点击事件
- *
- * @param player 玩家
- * @param currentItem 点击物品
- * @param cursorItem 持有物品
- * @return {@link SpecialItemResult[]}
- */
- SpecialItemResult[] isCorrectClick(Player player, ItemStack currentItem, ItemStack cursorItem);
-}
diff --git a/src/main/java/me/skymc/taboolib/inventory/speciaitem/SpecialItem.java b/src/main/java/me/skymc/taboolib/inventory/speciaitem/SpecialItem.java
deleted file mode 100644
index 6a5c9c8..0000000
--- a/src/main/java/me/skymc/taboolib/inventory/speciaitem/SpecialItem.java
+++ /dev/null
@@ -1,184 +0,0 @@
-package me.skymc.taboolib.inventory.speciaitem;
-
-import me.skymc.taboolib.Main;
-import me.skymc.taboolib.inventory.ItemUtils;
-import me.skymc.taboolib.message.MsgUtils;
-import org.bukkit.Bukkit;
-import org.bukkit.entity.Player;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.EventPriority;
-import org.bukkit.event.Listener;
-import org.bukkit.event.inventory.InventoryClickEvent;
-import org.bukkit.event.server.PluginDisableEvent;
-import org.bukkit.plugin.Plugin;
-
-import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-/**
- * @author sky
- * @since 2018年2月17日 下午8:34:12
- */
-public class SpecialItem implements Listener {
-
- private static SpecialItem specialItem = null;
-
- private final List ITEM_DATA = new CopyOnWriteArrayList<>();
-
- private boolean isLoaded;
-
- /**
- * 构造方法
- */
- private SpecialItem() {
-
- }
-
- /**
- * 获取工具对象
- *
- * @return {@link SpecialItem}
- */
- public static SpecialItem getInst() {
- if (specialItem == null) {
- synchronized (SpecialItem.class) {
- if (specialItem == null) {
- specialItem = new SpecialItem();
- // 注册监听器
- Bukkit.getPluginManager().registerEvents(specialItem, Main.getInst());
- }
- }
- }
- return specialItem;
- }
-
- public boolean isLoaded() {
- return isLoaded;
- }
-
- /**
- * 注册接口
- *
- * @param item 接口对象
- */
- public void register(AbstractSpecialItem item) {
- if (contains(item.getName())) {
- MsgUtils.warn("特殊物品接口已存在, 检查名称 &4" + item.getName() + " &c是否重复");
- } else {
- ITEM_DATA.add(item);
- if (isLoaded) {
- item.onEnable();
- }
- }
- }
-
- /**
- * 注销接口
- *
- * @param name 注册名称
- */
- public void cancel(String name) {
- for (AbstractSpecialItem specialitem : ITEM_DATA) {
- if (specialitem.getName() != null && specialitem.getName().equals(specialitem.getName())) {
- specialitem.onDisable();
- ITEM_DATA.remove(specialitem);
- }
- }
- }
-
- /**
- * 注销接口
- *
- * @param plugin 注册插件
- */
- public void cancel(Plugin plugin) {
- for (AbstractSpecialItem specialitem : ITEM_DATA) {
- if (specialitem.getPlugin() != null && specialitem.getPlugin().equals(plugin)) {
- specialitem.onDisable();
- ITEM_DATA.remove(specialitem);
- }
- }
- }
-
- /**
- * 判断名称是否存在
- *
- * @param name 注册名称
- * @return boolean
- */
- public boolean contains(String name) {
- for (AbstractSpecialItem specialitem : ITEM_DATA) {
- if (specialitem.getName().equals(name)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * 载入所有已注册接口
- */
- public void loadItems() {
- ITEM_DATA.forEach(AbstractSpecialItem::onEnable);
- isLoaded = true;
- }
-
- /**
- * 注销所有已注册接口
- */
- public void unloadItems() {
- ITEM_DATA.forEach(AbstractSpecialItem::onDisable);
- ITEM_DATA.clear();
- }
-
- @EventHandler
- public void onDisable(PluginDisableEvent e) {
- cancel(e.getPlugin());
- }
-
- @EventHandler(priority = EventPriority.MONITOR)
- public void click(InventoryClickEvent e) {
- if (e.isCancelled()) {
- return;
- }
- if (ItemUtils.isNull(e.getCurrentItem()) || ItemUtils.isNull(e.getCursor())) {
- return;
- }
- Player player = (Player) e.getWhoClicked();
- for (AbstractSpecialItem specialItem : ITEM_DATA) {
- for (SpecialItemResult result : specialItem.isCorrectClick(player, e.getCurrentItem(), e.getCursor())) {
- if (result == null) {
- break;
- }
- switch (result) {
- case CANCEL:
- e.setCancelled(true);
- break;
- case BREAK:
- return;
- case REMOVE_ITEM_CURRENT:
- e.setCurrentItem(null);
- break;
- case REMOVE_ITEM_CURSOR:
- e.getWhoClicked().setItemOnCursor(null);
- break;
- case REMOVE_ITEM_CURRENT_AMOUNT_1:
- if (e.getCurrentItem().getAmount() > 1) {
- e.getCurrentItem().setAmount(e.getCurrentItem().getAmount() - 1);
- } else {
- e.setCurrentItem(null);
- }
- break;
- case REMOVE_ITEM_CURSOR_AMOUNT_1:
- if (e.getCursor().getAmount() > 1) {
- e.getCursor().setAmount(e.getCursor().getAmount() - 1);
- } else {
- e.getWhoClicked().setItemOnCursor(null);
- }
- break;
- default:
- }
- }
- }
- }
-}
diff --git a/src/main/java/me/skymc/taboolib/inventory/speciaitem/SpecialItemResult.java b/src/main/java/me/skymc/taboolib/inventory/speciaitem/SpecialItemResult.java
deleted file mode 100644
index 4e06ae2..0000000
--- a/src/main/java/me/skymc/taboolib/inventory/speciaitem/SpecialItemResult.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package me.skymc.taboolib.inventory.speciaitem;
-
-/**
- * @author sky
- * @since 2018年2月17日 下午8:55:36
- */
-public enum SpecialItemResult {
-
- /**
- * 停止接口检测
- */
- BREAK,
-
- /**
- * 取消点击事件
- */
- CANCEL,
-
- /**
- * 移除点击物品
- */
- REMOVE_ITEM_CURRENT,
-
- /**
- * 移除鼠标物品
- */
- REMOVE_ITEM_CURSOR,
-
- /**
- * 移除一个点击物品
- */
- REMOVE_ITEM_CURRENT_AMOUNT_1,
-
- /**
- * 移除一个鼠标物品
- */
- REMOVE_ITEM_CURSOR_AMOUNT_1
-
-}
diff --git a/src/main/java/me/skymc/taboolib/itagapi/TagPacket.java b/src/main/java/me/skymc/taboolib/itagapi/TagPacket.java
index d4d19f8..ca76c61 100644
--- a/src/main/java/me/skymc/taboolib/itagapi/TagPacket.java
+++ b/src/main/java/me/skymc/taboolib/itagapi/TagPacket.java
@@ -37,7 +37,7 @@ class TagPacket implements Listener {
}
public static void inst() {
- assert !loaded : "TagAPI is already instanced!";
+ Preconditions.checkArgument(!loaded, "TagAPI is already instanced!");
loaded = true;
Bukkit.getServer().getOnlinePlayers().forEach(player -> entityIdMap.put(player.getEntityId(), player));
@@ -79,7 +79,6 @@ class TagPacket implements Listener {
Preconditions.checkState(Main.getInst().isEnabled(), "Not Enabled!");
Preconditions.checkNotNull(player, "player");
Preconditions.checkNotNull(forWhom, "forWhom");
-
if (player != forWhom && player.getWorld() == forWhom.getWorld() && forWhom.canSee(player)) {
forWhom.hidePlayer(player);
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.getInst(), () -> forWhom.showPlayer(player), 2);
@@ -90,13 +89,11 @@ class TagPacket implements Listener {
Preconditions.checkState(Main.getInst().isEnabled(), "Not Enabled!");
Preconditions.checkNotNull(player, "player");
Preconditions.checkNotNull(forWhom, "forWhom");
-
forWhom.forEach(playerFor -> refreshPlayer(player, playerFor));
}
private static WrappedGameProfile getSentName(int sentEntityId, WrappedGameProfile sent, Player destinationPlayer) {
- Preconditions.checkState(Bukkit.getServer().isPrimaryThread(), "Can only process events on main thread.");
-
+// Preconditions.checkState(Bukkit.getServer().isPrimaryThread(), "Can only process events on main thread.");
Player namedPlayer = entityIdMap.get(sentEntityId);
if (namedPlayer == null) {
// They probably were dead when we reloaded
diff --git a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTCompound.java b/src/main/java/me/skymc/taboolib/itemnbtapi/NBTCompound.java
deleted file mode 100644
index d02e435..0000000
--- a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTCompound.java
+++ /dev/null
@@ -1,196 +0,0 @@
-package me.skymc.taboolib.itemnbtapi;
-
-import me.skymc.taboolib.TabooLib;
-
-import java.util.Set;
-
-public class NBTCompound {
-
- private String compundName;
- private NBTCompound parent;
-
- protected NBTCompound(NBTCompound owner, String name) {
- this.compundName = name;
- this.parent = owner;
- }
-
- public String getName() {
- return compundName;
- }
-
- protected Object getCompound() {
- return parent.getCompound();
- }
-
- protected void setCompound(Object compound) {
- parent.setCompound(compound);
- }
-
- public NBTCompound getParent() {
- return parent;
- }
-
- public void mergeCompound(NBTCompound comp){
- NBTReflectionUtil.addOtherNBTCompound(this, comp);
- }
-
- public void setString(String key, String value) {
- NBTReflectionUtil.setString(this, key, value);
- }
-
- public String getString(String key) {
- return NBTReflectionUtil.getString(this, key);
- }
-
- protected String getContent(String key) {
- return NBTReflectionUtil.getContent(this, key);
- }
-
- public void setInteger(String key, Integer value) {
- NBTReflectionUtil.setInt(this, key, value);
- }
-
- public Integer getInteger(String key) {
- return NBTReflectionUtil.getInt(this, key);
- }
-
- public void setDouble(String key, Double value) {
- NBTReflectionUtil.setDouble(this, key, value);
- }
-
- public Double getDouble(String key) {
- return NBTReflectionUtil.getDouble(this, key);
- }
-
- public void setByte(String key, Byte value) {
- NBTReflectionUtil.setByte(this, key, value);
- }
-
- public Byte getByte(String key) {
- return NBTReflectionUtil.getByte(this, key);
- }
-
- public void setShort(String key, Short value) {
- NBTReflectionUtil.setShort(this, key, value);
- }
-
- public Short getShort(String key) {
- return NBTReflectionUtil.getShort(this, key);
- }
-
- public void setLong(String key, Long value) {
- NBTReflectionUtil.setLong(this, key, value);
- }
-
- public Long getLong(String key) {
- return NBTReflectionUtil.getLong(this, key);
- }
-
- public void setFloat(String key, Float value) {
- NBTReflectionUtil.setFloat(this, key, value);
- }
-
- public Float getFloat(String key) {
- return NBTReflectionUtil.getFloat(this, key);
- }
-
- public void setByteArray(String key, byte[] value) {
- NBTReflectionUtil.setByteArray(this, key, value);
- }
-
- public byte[] getByteArray(String key) {
- return NBTReflectionUtil.getByteArray(this, key);
- }
-
- public void setIntArray(String key, int[] value) {
- NBTReflectionUtil.setIntArray(this, key, value);
- }
-
- public int[] getIntArray(String key) {
- return NBTReflectionUtil.getIntArray(this, key);
- }
-
- public void setBoolean(String key, Boolean value) {
- NBTReflectionUtil.setBoolean(this, key, value);
- }
-
- protected void set(String key, Object val) {
- NBTReflectionUtil.set(this, key, val);
- }
-
- public Boolean getBoolean(String key) {
- return NBTReflectionUtil.getBoolean(this, key);
- }
-
- public void setObject(String key, Object value) {
- NBTReflectionUtil.setObject(this, key, value);
- }
-
- public T getObject(String key, Class type) {
- return NBTReflectionUtil.getObject(this, key, type);
- }
-
- public Boolean hasKey(String key) {
- return NBTReflectionUtil.hasKey(this, key);
- }
-
- public void removeKey(String key) {
- NBTReflectionUtil.remove(this, key);
- }
-
- public Set getKeys() {
- return NBTReflectionUtil.getKeys(this);
- }
-
- public NBTCompound addCompound(String name) {
- NBTReflectionUtil.addNBTTagCompound(this, name);
- return getCompound(name);
- }
-
- public NBTCompound getCompound(String name) {
- NBTCompound next = new NBTCompound(this, name);
- if (NBTReflectionUtil.valideCompound(next)) {
- return next;
- }
- return null;
- }
-
- public NBTList getList(String name, NBTType type) {
- return NBTReflectionUtil.getList(this, name, type);
- }
-
- public NBTType getType(String name) {
- if (TabooLib.getVerint() == 10700) {
- return NBTType.NBTTagEnd;
- }
- return NBTType.valueOf(NBTReflectionUtil.getType(this, name));
- }
-
- @Override
- public String toString() {
- StringBuilder result = new StringBuilder();
- for (String key : getKeys()) {
- result.append(toString(key));
- }
- return result.toString();
- }
-
- public String toString(String key) {
- StringBuilder result = new StringBuilder();
- NBTCompound compound = this;
- while (compound.getParent() != null) {
- result.append(" ");
- compound = compound.getParent();
- }
- if (this.getType(key) == NBTType.NBTTagCompound) {
- return this.getCompound(key).toString();
- } else {
- return result + "-" + key + ": " + getContent(key) + System.lineSeparator();
- }
- }
-
- public String asNBTString(){
- return getCompound() == null ? "" : getCompound().toString();
- }
-
-}
diff --git a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTContainer.java b/src/main/java/me/skymc/taboolib/itemnbtapi/NBTContainer.java
deleted file mode 100644
index 119a0d8..0000000
--- a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTContainer.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package me.skymc.taboolib.itemnbtapi;
-
-public class NBTContainer extends NBTCompound {
-
- private Object nbt;
-
- public NBTContainer() {
- super(null, null);
- nbt = NBTReflectionUtil.getNewNBTTag();
- }
-
- protected NBTContainer(Object nbt) {
- super(null, null);
- this.nbt = nbt;
- }
-
- public NBTContainer(String nbtString) throws IllegalArgumentException {
- super(null, null);
- try {
- nbt = NBTReflectionUtil.parseNBT(nbtString);
- } catch (Exception ex) {
- ex.printStackTrace();
- throw new IllegalArgumentException("Malformed Json: " + ex.getMessage());
- }
- }
-
- @Override
- protected Object getCompound() {
- return nbt;
- }
-
- @Override
- protected void setCompound(Object tag) {
- nbt = tag;
- }
-
-}
diff --git a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTEntity.java b/src/main/java/me/skymc/taboolib/itemnbtapi/NBTEntity.java
deleted file mode 100644
index 43e4cee..0000000
--- a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTEntity.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package me.skymc.taboolib.itemnbtapi;
-
-import org.bukkit.entity.Entity;
-
-public class NBTEntity extends NBTCompound {
-
- private final Entity ent;
-
- public NBTEntity(Entity entity) {
- super(null, null);
- ent = entity;
- }
-
- @Override
- protected Object getCompound() {
- return NBTReflectionUtil.getEntityNBTTagCompound(NBTReflectionUtil.getNMSEntity(ent));
- }
-
- @Override
- protected void setCompound(Object compound) {
- NBTReflectionUtil.setEntityNBTTag(compound, NBTReflectionUtil.getNMSEntity(ent));
- }
-
-}
diff --git a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTFile.java b/src/main/java/me/skymc/taboolib/itemnbtapi/NBTFile.java
deleted file mode 100644
index 2bc2faa..0000000
--- a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTFile.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package me.skymc.taboolib.itemnbtapi;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-
-public class NBTFile extends NBTCompound {
-
- private final File file;
- private Object nbt;
-
- public NBTFile(File file) throws IOException {
- super(null, null);
- this.file = file;
- if (file.exists()) {
- FileInputStream inputsteam = new FileInputStream(file);
- nbt = NBTReflectionUtil.readNBTFile(inputsteam);
- } else {
- nbt = NBTReflectionUtil.getNewNBTTag();
- save();
- }
- }
-
- public void save() throws IOException {
- if (!file.exists()) {
- file.getParentFile().mkdirs();
- file.createNewFile();
- }
- FileOutputStream outStream = new FileOutputStream(file);
- NBTReflectionUtil.saveNBTFile(nbt, outStream);
- }
-
- public File getFile() {
- return file;
- }
-
- @Override
- protected Object getCompound() {
- return nbt;
- }
-
- @Override
- protected void setCompound(Object compound) {
- nbt = compound;
- }
-
-}
diff --git a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTItem.java b/src/main/java/me/skymc/taboolib/itemnbtapi/NBTItem.java
deleted file mode 100644
index a2ce653..0000000
--- a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTItem.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package me.skymc.taboolib.itemnbtapi;
-
-import org.bukkit.inventory.ItemStack;
-
-public class NBTItem extends NBTCompound {
-
- private ItemStack bukkitItem;
-
- public NBTItem(ItemStack item) {
- super(null, null);
- bukkitItem = item.clone();
- }
-
- public static NBTContainer convertItemtoNBT(ItemStack item) {
- return NBTReflectionUtil.convertNMSItemtoNBTCompound(NBTReflectionUtil.getNMSItemStack(item));
- }
-
- public static ItemStack convertNBTtoItem(NBTCompound comp) {
- return NBTReflectionUtil.getBukkitItemStack(NBTReflectionUtil.convertNBTCompoundtoNMSItem(comp));
- }
-
- public ItemStack getItem() {
- return bukkitItem;
- }
-
- protected void setItem(ItemStack item) {
- bukkitItem = item;
- }
-
- @Override
- protected Object getCompound() {
- return NBTReflectionUtil.getItemRootNBTTagCompound(NBTReflectionUtil.getNMSItemStack(bukkitItem));
- }
-
- @Override
- protected void setCompound(Object compound) {
- bukkitItem = NBTReflectionUtil.getBukkitItemStack(NBTReflectionUtil.setNBTTag(compound, NBTReflectionUtil.getNMSItemStack(bukkitItem)));
- }
-
-}
diff --git a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTList.java b/src/main/java/me/skymc/taboolib/itemnbtapi/NBTList.java
deleted file mode 100644
index 86f1a8a..0000000
--- a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTList.java
+++ /dev/null
@@ -1,128 +0,0 @@
-package me.skymc.taboolib.itemnbtapi;
-
-import me.skymc.taboolib.itemnbtapi.utils.MethodNames;
-import me.skymc.taboolib.message.MsgUtils;
-
-import java.lang.reflect.Method;
-
-public class NBTList {
-
- private String listName;
- private NBTCompound parent;
- private NBTType type;
- private Object listObject;
-
- protected NBTList(NBTCompound owner, String name, NBTType type, Object list) {
- parent = owner;
- listName = name;
- this.type = type;
- this.listObject = list;
- if (!(type == NBTType.NBTTagString || type == NBTType.NBTTagCompound)) {
- System.err.println("List types != String/Compound are currently not implemented!");
- }
- }
-
- protected void save() {
- parent.set(listName, listObject);
- }
-
- public NBTListCompound addCompound() {
- if (type != NBTType.NBTTagCompound) {
- new Throwable("Using Compound method on a non Compound list!").printStackTrace();
- return null;
- }
- try {
- Method method = listObject.getClass().getMethod("add", NBTReflectionUtil.getNBTBase());
- Object compound = NBTReflectionUtil.getNBTTagCompound().newInstance();
- method.invoke(listObject, compound);
- return new NBTListCompound(this, compound);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return null;
- }
-
- public NBTListCompound getCompound(int id) {
- if (type != NBTType.NBTTagCompound) {
- new Throwable("Using Compound method on a non Compound list!").printStackTrace();
- return null;
- }
- try {
- Method method = listObject.getClass().getMethod("get", int.class);
- Object compound = method.invoke(listObject, id);
- return new NBTListCompound(this, compound);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return null;
- }
-
- public String getString(int i) {
- if (type != NBTType.NBTTagString) {
- new Throwable("Using String method on a non String list!").printStackTrace();
- return null;
- }
- try {
- Method method = listObject.getClass().getMethod("getString", int.class);
- return (String) method.invoke(listObject, i);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return null;
- }
-
- @SuppressWarnings("unchecked")
- public void addString(String s) {
- if (type != NBTType.NBTTagString) {
- new Throwable("Using String method on a non String list!").printStackTrace();
- return;
- }
- try {
- Method method = listObject.getClass().getMethod("add", NBTReflectionUtil.getNBTBase());
- method.invoke(listObject, NBTReflectionUtil.getNBTTagString().getConstructor(String.class).newInstance(s));
- save();
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- }
-
- @SuppressWarnings("unchecked")
- public void setString(int i, String s) {
- if (type != NBTType.NBTTagString) {
- new Throwable("Using String method on a non String list!").printStackTrace();
- return;
- }
- try {
- Method method = listObject.getClass().getMethod("a", int.class, NBTReflectionUtil.getNBTBase());
- method.invoke(listObject, i, NBTReflectionUtil.getNBTTagString().getConstructor(String.class).newInstance(s));
- save();
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- }
-
- public void remove(int i) {
- try {
- Method method = listObject.getClass().getMethod(MethodNames.getRemoveMethodName(), int.class);
- method.invoke(listObject, i);
- save();
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- }
-
- public int size() {
- try {
- Method method = listObject.getClass().getMethod("size");
- return (int) method.invoke(listObject);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return -1;
- }
-
- public NBTType getType() {
- return type;
- }
-
-}
diff --git a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTListCompound.java b/src/main/java/me/skymc/taboolib/itemnbtapi/NBTListCompound.java
deleted file mode 100644
index 750f968..0000000
--- a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTListCompound.java
+++ /dev/null
@@ -1,104 +0,0 @@
-package me.skymc.taboolib.itemnbtapi;
-
-import me.skymc.taboolib.message.MsgUtils;
-
-import java.util.HashSet;
-import java.util.Set;
-
-public class NBTListCompound {
-
- private NBTList owner;
- private Object compound;
-
- protected NBTListCompound(NBTList parent, Object obj) {
- owner = parent;
- compound = obj;
- }
-
- public void setString(String key, String value) {
- if (value == null) {
- remove(key);
- return;
- }
- try {
- compound.getClass().getMethod("setString", String.class, String.class).invoke(compound, key, value);
- owner.save();
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- }
-
- public void setInteger(String key, int value) {
- try {
- compound.getClass().getMethod("setInt", String.class, int.class).invoke(compound, key, value);
- owner.save();
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- }
-
- public int getInteger(String value) {
- try {
- return (int) compound.getClass().getMethod("getInt", String.class).invoke(compound, value);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return 0;
- }
-
- public void setDouble(String key, double value) {
- try {
- compound.getClass().getMethod("setDouble", String.class, double.class).invoke(compound, key, value);
- owner.save();
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- }
-
- public double getDouble(String key) {
- try {
- return (double) compound.getClass().getMethod("getDouble", String.class).invoke(compound, key);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return 0;
- }
-
-
- public String getString(String key) {
- try {
- return (String) compound.getClass().getMethod("getString", String.class).invoke(compound, key);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return "";
- }
-
- public boolean hasKey(String key) {
- try {
- return (boolean) compound.getClass().getMethod("hasKey", String.class).invoke(compound, key);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return false;
- }
-
- @SuppressWarnings("unchecked")
- public Set getKeys() {
- try {
- return (Set) compound.getClass().getMethod("c").invoke(compound);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return new HashSet<>();
- }
-
- public void remove(String key) {
- try {
- compound.getClass().getMethod("remove", String.class).invoke(compound, key);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- }
-
-}
diff --git a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTReflectionUtil.java b/src/main/java/me/skymc/taboolib/itemnbtapi/NBTReflectionUtil.java
deleted file mode 100644
index 01fd1ca..0000000
--- a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTReflectionUtil.java
+++ /dev/null
@@ -1,1018 +0,0 @@
-package me.skymc.taboolib.itemnbtapi;
-
-import me.skymc.taboolib.TabooLib;
-import me.skymc.taboolib.itemnbtapi.utils.GsonWrapper;
-import me.skymc.taboolib.itemnbtapi.utils.MethodNames;
-import me.skymc.taboolib.message.MsgUtils;
-import org.bukkit.Bukkit;
-import org.bukkit.block.BlockState;
-import org.bukkit.entity.Entity;
-import org.bukkit.inventory.ItemStack;
-
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.lang.reflect.Method;
-import java.util.Set;
-import java.util.Stack;
-
-// TODO: finish codestyle cleanup -sgdc3
-public class NBTReflectionUtil {
-
- private static final String version = TabooLib.getVersion();
-
- @SuppressWarnings("rawtypes")
- private static Class getCraftItemStack() {
-
- try {
- return Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack");
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- return null;
- }
- }
-
- @SuppressWarnings("rawtypes")
- private static Class getCraftEntity() {
- try {
- return Class.forName("org.bukkit.craftbukkit." + version + ".entity.CraftEntity");
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- return null;
- }
- }
-
- @SuppressWarnings("rawtypes")
- protected static Class getNBTBase() {
- try {
- return Class.forName("net.minecraft.server." + version + ".NBTBase");
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- return null;
- }
- }
-
- @SuppressWarnings("rawtypes")
- protected static Class getNBTTagString() {
- try {
- return Class.forName("net.minecraft.server." + version + ".NBTTagString");
- } catch (Exception ex) {
-
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- return null;
- }
- }
-
- @SuppressWarnings("rawtypes")
- protected static Class getNMSItemStack() {
- try {
- return Class.forName("net.minecraft.server." + version + ".ItemStack");
- } catch (Exception ex) {
-
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- return null;
- }
- }
-
- @SuppressWarnings("rawtypes")
- protected static Class getNBTTagCompound() {
- try {
- return Class.forName("net.minecraft.server." + version + ".NBTTagCompound");
- } catch (Exception ex) {
-
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- return null;
- }
- }
-
- @SuppressWarnings("rawtypes")
- protected static Class getNBTCompressedStreamTools() {
- try {
- return Class.forName("net.minecraft.server." + version + ".NBTCompressedStreamTools");
- } catch (Exception ex) {
-
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- return null;
- }
- }
-
- @SuppressWarnings("rawtypes")
- protected static Class getMojangsonParser() {
- try {
- return Class.forName("net.minecraft.server." + version + ".MojangsonParser");
- } catch (Exception ex) {
-
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- return null;
- }
- }
-
- @SuppressWarnings("rawtypes")
- protected static Class getTileEntity() {
- try {
- return Class.forName("net.minecraft.server." + version + ".TileEntity");
- } catch (Exception ex) {
-
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- return null;
- }
- }
-
- @SuppressWarnings("rawtypes")
- protected static Class getCraftWorld() {
- try {
- return Class.forName("org.bukkit.craftbukkit." + version + ".CraftWorld");
- } catch (Exception ex) {
-
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- return null;
- }
- }
-
- public static Object getNewNBTTag() {
- String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
- try {
- @SuppressWarnings("rawtypes")
- Class c = Class.forName("net.minecraft.server." + version + ".NBTTagCompound");
- return c.newInstance();
- } catch (Exception ex) {
-
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- return null;
- }
- }
-
- private static Object getNewBlockPosition(int x, int y, int z) {
- String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
- try {
- @SuppressWarnings("rawtypes")
- Class clazz = Class.forName("net.minecraft.server." + version + ".BlockPosition");
- return clazz.getConstructor(int.class, int.class, int.class).newInstance(x, y, z);
- } catch (Exception ex) {
-
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- return null;
- }
- }
-
- public static Object setNBTTag(Object NBTTag, Object NMSItem) {
- try {
- Method method;
- method = NMSItem.getClass().getMethod("setTag", NBTTag.getClass());
- method.invoke(NMSItem, NBTTag);
- return NMSItem;
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return null;
- }
-
- @SuppressWarnings("unchecked")
- public static Object getNMSItemStack(ItemStack item) {
- @SuppressWarnings("rawtypes")
- Class clazz = getCraftItemStack();
- Method method;
- try {
- method = clazz.getMethod("asNMSCopy", ItemStack.class);
- return method.invoke(clazz, item);
- } catch (Exception e) {
- MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage());
- }
- return null;
- }
-
- @SuppressWarnings("unchecked")
- public static Object getNMSEntity(Entity entity) {
- @SuppressWarnings("rawtypes")
- Class clazz = getCraftEntity();
- Method method;
- try {
- method = clazz.getMethod("getHandle");
- return method.invoke(getCraftEntity().cast(entity));
- } catch (Exception e) {
- MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage());
- }
- return null;
- }
-
- @SuppressWarnings({"unchecked"})
- public static Object parseNBT(String json) {
- @SuppressWarnings("rawtypes")
- Class cis = getMojangsonParser();
- java.lang.reflect.Method method;
- try {
- method = cis.getMethod("parse", String.class);
- return method.invoke(null, json);
- } catch (Exception e) {
- MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage());
- }
- return null;
- }
-
- @SuppressWarnings({"unchecked"})
- public static Object readNBTFile(FileInputStream stream) {
- @SuppressWarnings("rawtypes")
- Class clazz = getNBTCompressedStreamTools();
- Method method;
- try {
- method = clazz.getMethod("a", InputStream.class);
- return method.invoke(clazz, stream);
- } catch (Exception e) {
- MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage());
- }
- return null;
- }
-
- @SuppressWarnings({"unchecked"})
- public static Object saveNBTFile(Object nbt, FileOutputStream stream) {
- @SuppressWarnings("rawtypes")
- Class clazz = getNBTCompressedStreamTools();
- Method method;
- try {
- method = clazz.getMethod("a", getNBTTagCompound(), OutputStream.class);
- return method.invoke(clazz, nbt, stream);
- } catch (Exception e) {
- MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage());
- }
- return null;
- }
-
- @SuppressWarnings({"unchecked"})
- public static ItemStack getBukkitItemStack(Object item) {
- @SuppressWarnings("rawtypes")
- Class clazz = getCraftItemStack();
- Method method;
- try {
- method = clazz.getMethod("asCraftMirror", item.getClass());
- Object answer = method.invoke(clazz, item);
- return (ItemStack) answer;
- } catch (Exception e) {
- MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage());
- }
- return null;
- }
-
- @SuppressWarnings({"unchecked"})
- public static Object getItemRootNBTTagCompound(Object nmsitem) {
- @SuppressWarnings("rawtypes")
- Class clazz = nmsitem.getClass();
- Method method;
- try {
- method = clazz.getMethod("getTag");
- return method.invoke(nmsitem);
- } catch (Exception e) {
- MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage());
- }
- return null;
- }
-
- @SuppressWarnings({"unchecked"})
- public static Object convertNBTCompoundtoNMSItem(NBTCompound nbtcompound) {
- @SuppressWarnings("rawtypes")
- Class clazz = getNMSItemStack();
- try {
- return clazz.getConstructor(getNBTTagCompound()).newInstance(nbtcompound.getCompound());
- } catch (Exception e) {
- MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage());
- }
- return null;
- }
-
- @SuppressWarnings({"unchecked"})
- public static NBTContainer convertNMSItemtoNBTCompound(Object nmsitem) {
- @SuppressWarnings("rawtypes")
- Class clazz = nmsitem.getClass();
- Method method;
- try {
- method = clazz.getMethod("save", getNBTTagCompound());
- Object answer = method.invoke(nmsitem, getNewNBTTag());
- return new NBTContainer(answer);
- } catch (Exception e) {
- MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage());
- }
- return null;
- }
-
- @SuppressWarnings({"unchecked"})
- public static Object getEntityNBTTagCompound(Object nmsitem) {
- @SuppressWarnings("rawtypes")
- Class c = nmsitem.getClass();
- Method method;
- try {
- method = c.getMethod(MethodNames.getEntityNbtGetterMethodName(), getNBTTagCompound());
- Object nbt = getNBTTagCompound().newInstance();
- Object answer = method.invoke(nmsitem, nbt);
- if (answer == null) {
- answer = nbt;
- }
- return answer;
- } catch (Exception e) {
- MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage());
- }
- return null;
- }
-
- public static Object setEntityNBTTag(Object NBTTag, Object NMSItem) {
- try {
- Method method;
- method = NMSItem.getClass().getMethod(MethodNames.getEntityNbtSetterMethodName(), getNBTTagCompound());
- method.invoke(NMSItem, NBTTag);
- return NMSItem;
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return null;
- }
-
- public static Object getTileEntityNBTTagCompound(BlockState tile) {
- Method method;
- try {
- Object pos = getNewBlockPosition(tile.getX(), tile.getY(), tile.getZ());
- Object cworld = getCraftWorld().cast(tile.getWorld());
- Object nmsworld = cworld.getClass().getMethod("getHandle").invoke(cworld);
- Object o = nmsworld.getClass().getMethod("getTileEntity", pos.getClass()).invoke(nmsworld, pos);
- method = getTileEntity().getMethod(MethodNames.getTileDataMethodName(), getNBTTagCompound());
- Object tag = getNBTTagCompound().newInstance();
- Object answer = method.invoke(o, tag);
- if (answer == null) {
- answer = tag;
- }
- return answer;
- } catch (Exception e) {
- MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage());
- }
- return null;
- }
-
- public static void setTileEntityNBTTagCompound(BlockState tile, Object comp) {
- Method method;
- try {
- Object pos = getNewBlockPosition(tile.getX(), tile.getY(), tile.getZ());
- Object cworld = getCraftWorld().cast(tile.getWorld());
- Object nmsworld = cworld.getClass().getMethod("getHandle").invoke(cworld);
- Object o = nmsworld.getClass().getMethod("getTileEntity", pos.getClass()).invoke(nmsworld, pos);
- method = getTileEntity().getMethod("a", getNBTTagCompound());
- method.invoke(o, comp);
- } catch (Exception e) {
- MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage());
- }
- }
-
-
- @SuppressWarnings("unchecked")
- public static Object getSubNBTTagCompound(Object compound, String name) {
- @SuppressWarnings("rawtypes")
- Class c = compound.getClass();
- Method method;
- try {
- method = c.getMethod("getCompound", String.class);
- return method.invoke(compound, name);
- } catch (Exception e) {
- MsgUtils.warn("NBT 操作出现异常: §7" + e.getMessage());
- }
- return null;
- }
-
- public static void addNBTTagCompound(NBTCompound comp, String name) {
- if (name == null) {
- remove(comp, name);
- return;
- }
- Object nbttag = comp.getCompound();
- if (nbttag == null) {
- nbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return;
- }
- Object workingtag = gettoCompount(nbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("set", String.class, getNBTBase());
- method.invoke(workingtag, name, getNBTTagCompound().newInstance());
- comp.setCompound(nbttag);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- }
-
- public static Boolean valideCompound(NBTCompound comp) {
- Object root = comp.getCompound();
- if (root == null) {
- root = getNewNBTTag();
- }
- return (gettoCompount(root, comp)) != null;
- }
-
- private static Object gettoCompount(Object nbttag, NBTCompound comp) {
- Stack structure = new Stack<>();
- while (comp.getParent() != null) {
- structure.add(comp.getName());
- comp = comp.getParent();
- }
- while (!structure.isEmpty()) {
- nbttag = getSubNBTTagCompound(nbttag, structure.pop());
- if (nbttag == null) {
- return null;
- }
- }
- return nbttag;
- }
-
- public static void addOtherNBTCompound(NBTCompound comp, NBTCompound nbtcompound) {
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("a", getNBTTagCompound());
- method.invoke(workingtag, nbtcompound.getCompound());
- comp.setCompound(rootnbttag);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- }
-
- public static void setString(NBTCompound comp, String key, String text) {
- if (text == null) {
- remove(comp, key);
- return;
- }
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("setString", String.class, String.class);
- method.invoke(workingtag, key, text);
- comp.setCompound(rootnbttag);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- }
-
- public static String getString(NBTCompound comp, String key) {
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return null;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("getString", String.class);
- return (String) method.invoke(workingtag, key);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return null;
- }
-
- public static String getContent(NBTCompound comp, String key) {
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return null;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("get", String.class);
- return method.invoke(workingtag, key).toString();
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return null;
- }
-
- public static void setInt(NBTCompound comp, String key, Integer i) {
- if (i == null) {
- remove(comp, key);
- return;
- }
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("setInt", String.class, int.class);
- method.invoke(workingtag, key, i);
- comp.setCompound(rootnbttag);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- }
-
- public static Integer getInt(NBTCompound comp, String key) {
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return null;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("getInt", String.class);
- return (Integer) method.invoke(workingtag, key);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return null;
- }
-
- public static void setByteArray(NBTCompound comp, String key, byte[] b) {
- if (b == null) {
- remove(comp, key);
- return;
- }
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("setByteArray", String.class, byte[].class);
- method.invoke(workingtag, key, b);
- comp.setCompound(rootnbttag);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- }
-
- public static byte[] getByteArray(NBTCompound comp, String key) {
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return null;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("getByteArray", String.class);
- return (byte[]) method.invoke(workingtag, key);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return null;
- }
-
- public static void setIntArray(NBTCompound comp, String key, int[] i) {
- if (i == null) {
- remove(comp, key);
- return;
- }
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("setIntArray", String.class, int[].class);
- method.invoke(workingtag, key, i);
- comp.setCompound(rootnbttag);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- }
-
- public static int[] getIntArray(NBTCompound comp, String key) {
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return null;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("getIntArray", String.class);
- return (int[]) method.invoke(workingtag, key);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return null;
- }
-
- public static void setFloat(NBTCompound comp, String key, Float f) {
- if (f == null) {
- remove(comp, key);
- return;
- }
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("setFloat", String.class, float.class);
- method.invoke(workingtag, key, f);
- comp.setCompound(rootnbttag);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- }
-
- public static Float getFloat(NBTCompound comp, String key) {
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return null;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("getFloat", String.class);
- return (Float) method.invoke(workingtag, key);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return null;
- }
-
- public static void setLong(NBTCompound comp, String key, Long f) {
- if (f == null) {
- remove(comp, key);
- return;
- }
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("setLong", String.class, long.class);
- method.invoke(workingtag, key, f);
- comp.setCompound(rootnbttag);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- }
-
- public static Long getLong(NBTCompound comp, String key) {
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return null;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("getLong", String.class);
- return (Long) method.invoke(workingtag, key);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return null;
- }
-
- public static void setShort(NBTCompound comp, String key, Short f) {
- if (f == null) {
- remove(comp, key);
- return;
- }
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("setShort", String.class, short.class);
- method.invoke(workingtag, key, f);
- comp.setCompound(rootnbttag);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- }
-
- public static Short getShort(NBTCompound comp, String key) {
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return null;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("getShort", String.class);
- return (Short) method.invoke(workingtag, key);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return null;
- }
-
- public static void setByte(NBTCompound comp, String key, Byte f) {
- if (f == null) {
- remove(comp, key);
- return;
- }
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("setByte", String.class, byte.class);
- method.invoke(workingtag, key, f);
- comp.setCompound(rootnbttag);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- }
-
- public static Byte getByte(NBTCompound comp, String key) {
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return null;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("getByte", String.class);
- return (Byte) method.invoke(workingtag, key);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return null;
- }
-
- public static void setDouble(NBTCompound comp, String key, Double d) {
- if (d == null) {
- remove(comp, key);
- return;
- }
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("setDouble", String.class, double.class);
- method.invoke(workingtag, key, d);
- comp.setCompound(rootnbttag);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- }
-
- public static Double getDouble(NBTCompound comp, String key) {
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return null;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("getDouble", String.class);
- return (Double) method.invoke(workingtag, key);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return null;
- }
-
- public static byte getType(NBTCompound comp, String key) {
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return 0;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod(MethodNames.getTypeMethodName(), String.class);
- return (byte) method.invoke(workingtag, key);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return 0;
- }
-
- public static void setBoolean(NBTCompound comp, String key, Boolean d) {
- if (d == null) {
- remove(comp, key);
- return;
- }
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("setBoolean", String.class, boolean.class);
- method.invoke(workingtag, key, d);
- comp.setCompound(rootnbttag);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- }
-
- public static Boolean getBoolean(NBTCompound comp, String key) {
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return null;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("getBoolean", String.class);
- return (Boolean) method.invoke(workingtag, key);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return null;
- }
-
- public static void set(NBTCompound comp, String key, Object val) {
- if (val == null) {
- remove(comp, key);
- return;
- }
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- new Throwable("InvalideCompound").printStackTrace();
- return;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("set", String.class, getNBTBase());
- method.invoke(workingtag, key, val);
- comp.setCompound(rootnbttag);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- }
-
- public static NBTList getList(NBTCompound comp, String key, NBTType type) {
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return null;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("getList", String.class, int.class);
- return new NBTList(comp, key, type, method.invoke(workingtag, key, type.getId()));
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return null;
- }
-
- public static void setObject(NBTCompound comp, String key, Object value) {
- try {
- String json = GsonWrapper.getString(value);
- setString(comp, key, json);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- }
-
- public static T getObject(NBTCompound comp, String key, Class type) {
- String json = getString(comp, key);
- if (json == null) {
- return null;
- }
- return GsonWrapper.deserializeJson(json, type);
- }
-
- public static void remove(NBTCompound comp, String key) {
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("remove", String.class);
- method.invoke(workingtag, key);
- comp.setCompound(rootnbttag);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- }
-
- public static Boolean hasKey(NBTCompound comp, String key) {
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return null;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("hasKey", String.class);
- return (Boolean) method.invoke(workingtag, key);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return null;
- }
-
- @SuppressWarnings("unchecked")
- public static Set getKeys(NBTCompound comp) {
- Object rootnbttag = comp.getCompound();
- if (rootnbttag == null) {
- rootnbttag = getNewNBTTag();
- }
- if (!valideCompound(comp)) {
- return null;
- }
- Object workingtag = gettoCompount(rootnbttag, comp);
- Method method;
- try {
- method = workingtag.getClass().getMethod("c");
- return (Set) method.invoke(workingtag);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- }
- return null;
- }
-
-}
diff --git a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTTileEntity.java b/src/main/java/me/skymc/taboolib/itemnbtapi/NBTTileEntity.java
deleted file mode 100644
index 3b25d70..0000000
--- a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTTileEntity.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package me.skymc.taboolib.itemnbtapi;
-
-import org.bukkit.block.BlockState;
-
-public class NBTTileEntity extends NBTCompound {
-
- private final BlockState tile;
-
- public NBTTileEntity(BlockState tile) {
- super(null, null);
- this.tile = tile;
- }
-
- @Override
- protected Object getCompound() {
- return NBTReflectionUtil.getTileEntityNBTTagCompound(tile);
- }
-
- @Override
- protected void setCompound(Object compound) {
- NBTReflectionUtil.setTileEntityNBTTagCompound(tile, compound);
- }
-
-}
diff --git a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTType.java b/src/main/java/me/skymc/taboolib/itemnbtapi/NBTType.java
deleted file mode 100644
index 1d3d4e2..0000000
--- a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTType.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package me.skymc.taboolib.itemnbtapi;
-
-public enum NBTType {
-
- NBTTagEnd(0),
- NBTTagByte(1),
- NBTTagShort(2),
- NBTTagInt(3),
- NBTTagLong(4),
- NBTTagFloat(5),
- NBTTagDouble(6),
- NBTTagByteArray(7),
- NBTTagIntArray(11),
- NBTTagString(8),
- NBTTagList(9),
- NBTTagCompound(10);
-
- NBTType(int i) {
- id = i;
- }
-
- private final int id;
-
- public int getId() {
- return id;
- }
-
- public static NBTType valueOf(int id) {
- for (NBTType t : values()) {
- if (t.getId() == id) {
- return t;
- }
- }
- return NBTType.NBTTagEnd;
- }
-
-}
diff --git a/src/main/java/me/skymc/taboolib/itemnbtapi/utils/GsonWrapper.java b/src/main/java/me/skymc/taboolib/itemnbtapi/utils/GsonWrapper.java
deleted file mode 100644
index 581a6d7..0000000
--- a/src/main/java/me/skymc/taboolib/itemnbtapi/utils/GsonWrapper.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package me.skymc.taboolib.itemnbtapi.utils;
-
-import com.google.gson.Gson;
-import me.skymc.taboolib.message.MsgUtils;
-
-public class GsonWrapper {
-
- private static final Gson gson = new Gson();
-
- public static String getString(Object obj) {
- return gson.toJson(obj);
- }
-
- public static T deserializeJson(String json, Class type) {
- try {
- if (json == null) {
- return null;
- }
-
- T obj = gson.fromJson(json, type);
- return type.cast(obj);
- } catch (Exception ex) {
- MsgUtils.warn("NBT 操作出现异常: §7" + ex.getMessage());
- return null;
- }
- }
-
-}
diff --git a/src/main/java/me/skymc/taboolib/itemnbtapi/utils/MethodNames.java b/src/main/java/me/skymc/taboolib/itemnbtapi/utils/MethodNames.java
deleted file mode 100644
index 7c02ebe..0000000
--- a/src/main/java/me/skymc/taboolib/itemnbtapi/utils/MethodNames.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package me.skymc.taboolib.itemnbtapi.utils;
-
-import me.skymc.taboolib.TabooLib;
-
-public class MethodNames {
-
- public static String getEntityNbtGetterMethodName() {
- return "b";
- }
-
- public static String getEntityNbtSetterMethodName() {
- return "a";
- }
-
- public static String getTileDataMethodName() {
- if (TabooLib.getVerint() <= 10800) {
- return "b";
- }
- return "save";
- }
-
- public static String getTypeMethodName() {
- if (TabooLib.getVerint() <= 10800) {
- return "b";
- }
- return "d";
- }
-
- public static String getRemoveMethodName() {
- if (TabooLib.getVerint() <= 10800) {
- return "a";
- }
- return "remove";
- }
-}
diff --git a/src/main/java/me/skymc/taboolib/json/CDL.java b/src/main/java/me/skymc/taboolib/json/CDL.java
deleted file mode 100644
index 22b7947..0000000
--- a/src/main/java/me/skymc/taboolib/json/CDL.java
+++ /dev/null
@@ -1,155 +0,0 @@
-package me.skymc.taboolib.json;
-
-public class CDL {
-
- private static String getValue(JSONTokener x) throws JSONException {
- char c;
- char q;
- StringBuffer sb;
- do {
- c = x.next();
- } while (c == ' ' || c == '\t');
- switch (c) {
- case 0:
- return null;
- case '"':
- case '\'':
- q = c;
- sb = new StringBuffer();
- for (; ; ) {
- c = x.next();
- if (c == q) {
- break;
- }
- if (c == 0 || c == '\n' || c == '\r') {
- throw x.syntaxError("Missing close quote '" + q + "'.");
- }
- sb.append(c);
- }
- return sb.toString();
- case ',':
- x.back();
- return "";
- default:
- x.back();
- return x.nextTo(',');
- }
- }
-
- public static JSONArray rowToJSONArray(JSONTokener x) throws JSONException {
- JSONArray ja = new JSONArray();
- for (; ; ) {
- String value = getValue(x);
- char c = x.next();
- if (value == null ||
- (ja.length() == 0 && value.length() == 0 && c != ',')) {
- return null;
- }
- ja.put(value);
- while (c != ',') {
- if (c != ' ') {
- if (c == '\n' || c == '\r' || c == 0) {
- return ja;
- }
- throw x.syntaxError("Bad character '" + c + "' (" +
- (int) c + ").");
- }
- c = x.next();
- }
- }
- }
-
- public static JSONObject rowToJSONObject(JSONArray names, JSONTokener x)
- throws JSONException {
- JSONArray ja = rowToJSONArray(x);
- return ja != null ? ja.toJSONObject(names) : null;
- }
-
- public static String rowToString(JSONArray ja) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < ja.length(); i += 1) {
- if (i > 0) {
- sb.append(',');
- }
- Object object = ja.opt(i);
- if (object != null) {
- String string = object.toString();
- if (string.length() > 0 && (string.indexOf(',') >= 0 ||
- string.indexOf('\n') >= 0 || string.indexOf('\r') >= 0 ||
- string.indexOf(0) >= 0 || string.charAt(0) == '"')) {
- sb.append('"');
- int length = string.length();
- for (int j = 0; j < length; j += 1) {
- char c = string.charAt(j);
- if (c >= ' ' && c != '"') {
- sb.append(c);
- }
- }
- sb.append('"');
- } else {
- sb.append(string);
- }
- }
- }
- sb.append('\n');
- return sb.toString();
- }
-
- public static JSONArray toJSONArray(String string) throws JSONException {
- return toJSONArray(new JSONTokener(string));
- }
-
- public static JSONArray toJSONArray(JSONTokener x) throws JSONException {
- return toJSONArray(rowToJSONArray(x), x);
- }
-
- public static JSONArray toJSONArray(JSONArray names, String string)
- throws JSONException {
- return toJSONArray(names, new JSONTokener(string));
- }
-
- public static JSONArray toJSONArray(JSONArray names, JSONTokener x)
- throws JSONException {
- if (names == null || names.length() == 0) {
- return null;
- }
- JSONArray ja = new JSONArray();
- for (; ; ) {
- JSONObject jo = rowToJSONObject(names, x);
- if (jo == null) {
- break;
- }
- ja.put(jo);
- }
- if (ja.length() == 0) {
- return null;
- }
- return ja;
- }
-
- public static String toString(JSONArray ja) throws JSONException {
- JSONObject jo = ja.optJSONObject(0);
- if (jo != null) {
- JSONArray names = jo.names();
- if (names != null) {
- return rowToString(names) + toString(names, ja);
- }
- }
- return null;
- }
-
- public static String toString(JSONArray names, JSONArray ja)
- throws JSONException {
- if (names == null || names.length() == 0) {
- return null;
- }
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < ja.length(); i += 1) {
- JSONObject jo = ja.optJSONObject(i);
- if (jo != null) {
- sb.append(rowToString(jo.toJSONArray(names)));
- }
- }
- return sb.toString();
- }
-}
diff --git a/src/main/java/me/skymc/taboolib/json/Cookie.java b/src/main/java/me/skymc/taboolib/json/Cookie.java
deleted file mode 100644
index d1e014f..0000000
--- a/src/main/java/me/skymc/taboolib/json/Cookie.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package me.skymc.taboolib.json;
-
-public class Cookie {
-
- public static String escape(String string) {
- char c;
- String s = string.trim();
- StringBuilder sb = new StringBuilder();
- int length = s.length();
- for (int i = 0; i < length; i += 1) {
- c = s.charAt(i);
- if (c < ' ' || c == '+' || c == '%' || c == '=' || c == ';') {
- sb.append('%');
- sb.append(Character.forDigit((char) ((c >>> 4) & 0x0f), 16));
- sb.append(Character.forDigit((char) (c & 0x0f), 16));
- } else {
- sb.append(c);
- }
- }
- return sb.toString();
- }
-
- public static JSONObject toJSONObject(String string) throws JSONException {
- String name;
- JSONObject jo = new JSONObject();
- Object value;
- JSONTokener x = new JSONTokener(string);
- jo.put("name", x.nextTo('='));
- x.next('=');
- jo.put("value", x.nextTo(';'));
- x.next();
- while (x.more()) {
- name = unescape(x.nextTo("=;"));
- if (x.next() != '=') {
- if ("secure".equals(name)) {
- value = Boolean.TRUE;
- } else {
- throw x.syntaxError("Missing '=' in cookie parameter.");
- }
- } else {
- value = unescape(x.nextTo(';'));
- x.next();
- }
- jo.put(name, value);
- }
- return jo;
- }
-
- public static String toString(JSONObject jo) throws JSONException {
- StringBuilder sb = new StringBuilder();
-
- sb.append(escape(jo.getString("name")));
- sb.append("=");
- sb.append(escape(jo.getString("value")));
- if (jo.has("expires")) {
- sb.append(";expires=");
- sb.append(jo.getString("expires"));
- }
- if (jo.has("domain")) {
- sb.append(";domain=");
- sb.append(escape(jo.getString("domain")));
- }
- if (jo.has("path")) {
- sb.append(";path=");
- sb.append(escape(jo.getString("path")));
- }
- if (jo.optBoolean("secure")) {
- sb.append(";secure");
- }
- return sb.toString();
- }
-
- public static String unescape(String string) {
- int length = string.length();
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < length; ++i) {
- char c = string.charAt(i);
- if (c == '+') {
- c = ' ';
- } else if (c == '%' && i + 2 < length) {
- int d = JSONTokener.dehexchar(string.charAt(i + 1));
- int e = JSONTokener.dehexchar(string.charAt(i + 2));
- if (d >= 0 && e >= 0) {
- c = (char) (d * 16 + e);
- i += 2;
- }
- }
- sb.append(c);
- }
- return sb.toString();
- }
-}
diff --git a/src/main/java/me/skymc/taboolib/json/CookieList.java b/src/main/java/me/skymc/taboolib/json/CookieList.java
deleted file mode 100644
index 439ed6f..0000000
--- a/src/main/java/me/skymc/taboolib/json/CookieList.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package me.skymc.taboolib.json;
-
-import java.util.Iterator;
-
-public class CookieList {
-
- public static JSONObject toJSONObject(String string) throws JSONException {
- JSONObject jo = new JSONObject();
- JSONTokener x = new JSONTokener(string);
- while (x.more()) {
- String name = Cookie.unescape(x.nextTo('='));
- x.next('=');
- jo.put(name, Cookie.unescape(x.nextTo(';')));
- x.next();
- }
- return jo;
- }
-
- @SuppressWarnings("rawtypes")
- public static String toString(JSONObject jo) throws JSONException {
- boolean b = false;
- Iterator keys = jo.keys();
- String string;
- StringBuilder sb = new StringBuilder();
- while (keys.hasNext()) {
- string = keys.next().toString();
- if (!jo.isNull(string)) {
- if (b) {
- sb.append(';');
- }
- sb.append(Cookie.escape(string));
- sb.append("=");
- sb.append(Cookie.escape(jo.getString(string)));
- b = true;
- }
- }
- return sb.toString();
- }
-}
diff --git a/src/main/java/me/skymc/taboolib/json/HTTP.java b/src/main/java/me/skymc/taboolib/json/HTTP.java
deleted file mode 100644
index b0b4552..0000000
--- a/src/main/java/me/skymc/taboolib/json/HTTP.java
+++ /dev/null
@@ -1,71 +0,0 @@
-package me.skymc.taboolib.json;
-
-import java.util.Iterator;
-
-public class HTTP {
-
- public static final String CRLF = "\r\n";
-
- public static JSONObject toJSONObject(String string) throws JSONException {
- JSONObject jo = new JSONObject();
- HTTPTokener x = new HTTPTokener(string);
- String token;
-
- token = x.nextToken();
- if (token.toUpperCase().startsWith("HTTP")) {
- jo.put("HTTP-Version", token);
- jo.put("Status-Code", x.nextToken());
- jo.put("Reason-Phrase", x.nextTo('\0'));
- x.next();
- } else {
- jo.put("Method", token);
- jo.put("Request-URI", x.nextToken());
- jo.put("HTTP-Version", x.nextToken());
- }
- while (x.more()) {
- String name = x.nextTo(':');
- x.next(':');
- jo.put(name, x.nextTo('\0'));
- x.next();
- }
- return jo;
- }
-
- @SuppressWarnings("rawtypes")
- public static String toString(JSONObject jo) throws JSONException {
- Iterator keys = jo.keys();
- String string;
- StringBuilder sb = new StringBuilder();
- if (jo.has("Status-Code") && jo.has("Reason-Phrase")) {
- sb.append(jo.getString("HTTP-Version"));
- sb.append(' ');
- sb.append(jo.getString("Status-Code"));
- sb.append(' ');
- sb.append(jo.getString("Reason-Phrase"));
- } else if (jo.has("Method") && jo.has("Request-URI")) {
- sb.append(jo.getString("Method"));
- sb.append(' ');
- sb.append('"');
- sb.append(jo.getString("Request-URI"));
- sb.append('"');
- sb.append(' ');
- sb.append(jo.getString("HTTP-Version"));
- } else {
- throw new JSONException("Not enough material for an HTTP header.");
- }
- sb.append(CRLF);
- while (keys.hasNext()) {
- string = keys.next().toString();
- if (!"HTTP-Version".equals(string) && !"Status-Code".equals(string) &&
- !"Reason-Phrase".equals(string) && !"Method".equals(string) &&
- !"Request-URI".equals(string) && !jo.isNull(string)) {
- sb.append(string);
- sb.append(": ");
- sb.append(jo.getString(string));
- sb.append(CRLF);
- }
- }
- sb.append(CRLF);
- return sb.toString();
- }
-}
diff --git a/src/main/java/me/skymc/taboolib/json/HTTPTokener.java b/src/main/java/me/skymc/taboolib/json/HTTPTokener.java
deleted file mode 100644
index d04b607..0000000
--- a/src/main/java/me/skymc/taboolib/json/HTTPTokener.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package me.skymc.taboolib.json;
-
-public class HTTPTokener extends JSONTokener {
-
- public HTTPTokener(String string) {
- super(string);
- }
-
- public String nextToken() throws JSONException {
- char c;
- char q;
- StringBuilder sb = new StringBuilder();
- do {
- c = next();
- } while (Character.isWhitespace(c));
- if (c == '"' || c == '\'') {
- q = c;
- for (; ; ) {
- c = next();
- if (c < ' ') {
- throw syntaxError("Unterminated string.");
- }
- if (c == q) {
- return sb.toString();
- }
- sb.append(c);
- }
- }
- for (; ; ) {
- if (c == 0 || Character.isWhitespace(c)) {
- return sb.toString();
- }
- sb.append(c);
- c = next();
- }
- }
-}
diff --git a/src/main/java/me/skymc/taboolib/json/JSONArray.java b/src/main/java/me/skymc/taboolib/json/JSONArray.java
deleted file mode 100644
index 6277d3a..0000000
--- a/src/main/java/me/skymc/taboolib/json/JSONArray.java
+++ /dev/null
@@ -1,413 +0,0 @@
-package me.skymc.taboolib.json;
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.lang.reflect.Array;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Map;
-
-@SuppressWarnings({"rawtypes", "unchecked"})
-public class JSONArray {
-
- private final ArrayList myArrayList;
-
- public JSONArray() {
- this.myArrayList = new ArrayList();
- }
-
- public JSONArray(JSONTokener x) throws JSONException {
- this();
- if (x.nextClean() != '[') {
- throw x.syntaxError("A JSONArray text must start with '['");
- }
- if (x.nextClean() != ']') {
- x.back();
- for (; ; ) {
- if (x.nextClean() == ',') {
- x.back();
- this.myArrayList.add(JSONObject.NULL);
- } else {
- x.back();
- this.myArrayList.add(x.nextValue());
- }
- switch (x.nextClean()) {
- case ';':
- case ',':
- if (x.nextClean() == ']') {
- return;
- }
- x.back();
- break;
- case ']':
- return;
- default:
- throw x.syntaxError("Expected a ',' or ']'");
- }
- }
- }
- }
-
- public JSONArray(String source) throws JSONException {
- this(new JSONTokener(source));
- }
-
- public JSONArray(Collection collection) {
- this.myArrayList = new ArrayList();
- if (collection != null) {
- for (Object aCollection : collection) {
- this.myArrayList.add(JSONObject.wrap(aCollection));
- }
- }
- }
-
- public JSONArray(Object array) throws JSONException {
- this();
- if (array.getClass().isArray()) {
- int length = Array.getLength(array);
- for (int i = 0; i < length; i += 1) {
- this.put(JSONObject.wrap(Array.get(array, i)));
- }
- } else {
- throw new JSONException("JSONArray initial value should be a string or collection or array.");
- }
- }
-
- public Object get(int index) throws JSONException {
- Object object = this.opt(index);
- if (object == null) {
- throw new JSONException("JSONArray[" + index + "] not found.");
- }
- return object;
- }
-
- public boolean getBoolean(int index) throws JSONException {
- Object object = this.get(index);
- if (object.equals(Boolean.FALSE) ||
- (object instanceof String &&
- "false".equalsIgnoreCase((String) object))) {
- return false;
- } else if (object.equals(Boolean.TRUE) ||
- (object instanceof String &&
- "true".equalsIgnoreCase((String) object))) {
- return true;
- }
- throw new JSONException("JSONArray[" + index + "] is not a boolean.");
- }
-
- public double getDouble(int index) throws JSONException {
- Object object = this.get(index);
- try {
- return object instanceof Number
- ? ((Number) object).doubleValue()
- : Double.parseDouble((String) object);
- } catch (Exception e) {
- throw new JSONException("JSONArray[" + index +
- "] is not a number.");
- }
- }
-
- public int getInt(int index) throws JSONException {
- Object object = this.get(index);
- try {
- return object instanceof Number
- ? ((Number) object).intValue()
- : Integer.parseInt((String) object);
- } catch (Exception e) {
- throw new JSONException("JSONArray[" + index +
- "] is not a number.");
- }
- }
-
- public JSONArray getJSONArray(int index) throws JSONException {
- Object object = this.get(index);
- if (object instanceof JSONArray) {
- return (JSONArray) object;
- }
- throw new JSONException("JSONArray[" + index +
- "] is not a JSONArray.");
- }
-
- public JSONObject getJSONObject(int index) throws JSONException {
- Object object = this.get(index);
- if (object instanceof JSONObject) {
- return (JSONObject) object;
- }
- throw new JSONException("JSONArray[" + index +
- "] is not a JSONObject.");
- }
-
- public long getLong(int index) throws JSONException {
- Object object = this.get(index);
- try {
- return object instanceof Number
- ? ((Number) object).longValue()
- : Long.parseLong((String) object);
- } catch (Exception e) {
- throw new JSONException("JSONArray[" + index +
- "] is not a number.");
- }
- }
-
- public String getString(int index) throws JSONException {
- Object object = this.get(index);
- if (object instanceof String) {
- return (String) object;
- }
- throw new JSONException("JSONArray[" + index + "] not a string.");
- }
-
- public boolean isNull(int index) {
- return JSONObject.NULL.equals(this.opt(index));
- }
-
- public String join(String separator) throws JSONException {
- int len = this.length();
- StringBuilder sb = new StringBuilder();
-
- for (int i = 0; i < len; i += 1) {
- if (i > 0) {
- sb.append(separator);
- }
- sb.append(JSONObject.valueToString(this.myArrayList.get(i)));
- }
- return sb.toString();
- }
-
- public int length() {
- return this.myArrayList.size();
- }
-
- public Object opt(int index) {
- return (index < 0 || index >= this.length())
- ? null
- : this.myArrayList.get(index);
- }
-
- public boolean optBoolean(int index) {
- return this.optBoolean(index, false);
- }
-
- public boolean optBoolean(int index, boolean defaultValue) {
- try {
- return this.getBoolean(index);
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
- public double optDouble(int index) {
- return this.optDouble(index, Double.NaN);
- }
-
- public double optDouble(int index, double defaultValue) {
- try {
- return this.getDouble(index);
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
- public int optInt(int index) {
- return this.optInt(index, 0);
- }
-
- public int optInt(int index, int defaultValue) {
- try {
- return this.getInt(index);
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
- public JSONArray optJSONArray(int index) {
- Object o = this.opt(index);
- return o instanceof JSONArray ? (JSONArray) o : null;
- }
-
- public JSONObject optJSONObject(int index) {
- Object o = this.opt(index);
- return o instanceof JSONObject ? (JSONObject) o : null;
- }
-
- public long optLong(int index) {
- return this.optLong(index, 0);
- }
-
- public long optLong(int index, long defaultValue) {
- try {
- return this.getLong(index);
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
- public String optString(int index) {
- return this.optString(index, "");
- }
-
- public String optString(int index, String defaultValue) {
- Object object = this.opt(index);
- return JSONObject.NULL.equals(object)
- ? defaultValue : object
- .toString();
- }
-
- public JSONArray put(boolean value) {
- this.put(value ? Boolean.TRUE : Boolean.FALSE);
- return this;
- }
-
- public JSONArray put(Collection value) {
- this.put(new JSONArray(value));
- return this;
- }
-
- public JSONArray put(double value) throws JSONException {
- Double d = value;
- JSONObject.testValidity(d);
- this.put(d);
- return this;
- }
-
- public JSONArray put(int value) {
- this.put(new Integer(value));
- return this;
- }
-
- public JSONArray put(long value) {
- this.put(new Long(value));
- return this;
- }
-
- public JSONArray put(Map value) {
- this.put(new JSONObject(value));
- return this;
- }
-
- public JSONArray put(Object value) {
- this.myArrayList.add(value);
- return this;
- }
-
- public JSONArray put(int index, boolean value) throws JSONException {
- this.put(index, value ? Boolean.TRUE : Boolean.FALSE);
- return this;
- }
-
- public JSONArray put(int index, Collection value) throws JSONException {
- this.put(index, new JSONArray(value));
- return this;
- }
-
- public JSONArray put(int index, double value) throws JSONException {
- this.put(index, new Double(value));
- return this;
- }
-
- public JSONArray put(int index, int value) throws JSONException {
- this.put(index, new Integer(value));
- return this;
- }
-
- public JSONArray put(int index, long value) throws JSONException {
- this.put(index, new Long(value));
- return this;
- }
-
- public JSONArray put(int index, Map value) throws JSONException {
- this.put(index, new JSONObject(value));
- return this;
- }
-
- public JSONArray put(int index, Object value) throws JSONException {
- JSONObject.testValidity(value);
- if (index < 0) {
- throw new JSONException("JSONArray[" + index + "] not found.");
- }
- if (index < this.length()) {
- this.myArrayList.set(index, value);
- } else {
- while (index != this.length()) {
- this.put(JSONObject.NULL);
- }
- this.put(value);
- }
- return this;
- }
-
- public Object remove(int index) {
- Object o = this.opt(index);
- this.myArrayList.remove(index);
- return o;
- }
-
- public JSONObject toJSONObject(JSONArray names) throws JSONException {
- if (names == null || names.length() == 0 || this.length() == 0) {
- return null;
- }
- JSONObject jo = new JSONObject();
- for (int i = 0; i < names.length(); i += 1) {
- jo.put(names.getString(i), this.opt(i));
- }
- return jo;
- }
-
- @Override
- public String toString() {
- try {
- return '[' + this.join(",") + ']';
- } catch (Exception e) {
- return null;
- }
- }
-
- public String toString(int indentFactor) throws JSONException {
- StringWriter sw = new StringWriter();
- synchronized (sw.getBuffer()) {
- return this.write(sw, indentFactor, 0).toString();
- }
- }
-
- public Writer write(Writer writer) throws JSONException {
- return this.write(writer, 0, 0);
- }
-
- Writer write(Writer writer, int indentFactor, int indent)
- throws JSONException {
- try {
- boolean commanate = false;
- int length = this.length();
- writer.write('[');
-
- if (length == 1) {
- JSONObject.writeValue(writer, this.myArrayList.get(0),
- indentFactor, indent);
- } else if (length != 0) {
- final int newindent = indent + indentFactor;
-
- for (int i = 0; i < length; i += 1) {
- if (commanate) {
- writer.write(',');
- }
- if (indentFactor > 0) {
- writer.write('\n');
- }
- JSONObject.indent(writer, newindent);
- JSONObject.writeValue(writer, this.myArrayList.get(i),
- indentFactor, newindent);
- commanate = true;
- }
- if (indentFactor > 0) {
- writer.write('\n');
- }
- JSONObject.indent(writer, indent);
- }
- writer.write(']');
- return writer;
- } catch (IOException e) {
- throw new JSONException(e);
- }
- }
-}
diff --git a/src/main/java/me/skymc/taboolib/json/JSONException.java b/src/main/java/me/skymc/taboolib/json/JSONException.java
deleted file mode 100644
index 5827e53..0000000
--- a/src/main/java/me/skymc/taboolib/json/JSONException.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package me.skymc.taboolib.json;
-
-
-public class JSONException extends Exception {
-
- private static final long serialVersionUID = 0;
- private Throwable cause;
-
- public JSONException(String message) {
- super(message);
- }
-
- public JSONException(Throwable cause) {
- super(cause.getMessage());
- this.cause = cause;
- }
-
- @Override
- public Throwable getCause() {
- return this.cause;
- }
-}
diff --git a/src/main/java/me/skymc/taboolib/json/JSONML.java b/src/main/java/me/skymc/taboolib/json/JSONML.java
deleted file mode 100644
index 2a3ca14..0000000
--- a/src/main/java/me/skymc/taboolib/json/JSONML.java
+++ /dev/null
@@ -1,310 +0,0 @@
-package me.skymc.taboolib.json;
-
-import java.util.Iterator;
-
-@SuppressWarnings({"rawtypes"})
-public class JSONML {
-
- private static Object parse(XMLTokener x, boolean arrayForm, JSONArray ja) throws JSONException {
- String attribute;
- char c;
- String closeTag;
- int i;
- JSONArray newja;
- JSONObject newjo;
- Object token;
- String tagName;
-
- while (true) {
- if (!x.more()) {
- throw x.syntaxError("Bad XML");
- }
- token = x.nextContent();
- if (token == XML.LT) {
- token = x.nextToken();
- if (token instanceof Character) {
- if (token == XML.SLASH) {
- token = x.nextToken();
- if (!(token instanceof String)) {
- throw new JSONException(
- "Expected a closing name instead of '" +
- token + "'.");
- }
- if (x.nextToken() != XML.GT) {
- throw x.syntaxError("Misshaped close tag");
- }
- return token;
- } else if (token == XML.BANG) {
- c = x.next();
- switch (c) {
- case '-':
- if (x.next() == '-') {
- x.skipPast("-->");
- } else {
- x.back();
- }
- break;
- case '[':
- token = x.nextToken();
- if ("CDATA".equals(token) && x.next() == '[') {
- if (ja != null) {
- ja.put(x.nextCDATA());
- }
- } else {
- throw x.syntaxError("Expected 'CDATA['");
- }
- break;
- default:
- i = 1;
- do {
- token = x.nextMeta();
- if (token == null) {
- throw x.syntaxError("Missing '>' after ' 0);
- break;
- }
- } else if (token == XML.QUEST) {
- x.skipPast("?>");
- } else {
- throw x.syntaxError("Misshaped tag");
- }
- } else {
- if (!(token instanceof String)) {
- throw x.syntaxError("Bad tagName '" + token + "'.");
- }
- tagName = (String) token;
- newja = new JSONArray();
- newjo = new JSONObject();
- if (arrayForm) {
- newja.put(tagName);
- if (ja != null) {
- ja.put(newja);
- }
- } else {
- newjo.put("tagName", tagName);
- if (ja != null) {
- ja.put(newjo);
- }
- }
- token = null;
- for (; ; ) {
- if (token == null) {
- token = x.nextToken();
- }
- if (token == null) {
- throw x.syntaxError("Misshaped tag");
- }
- if (!(token instanceof String)) {
- break;
- }
- attribute = (String) token;
- if (!arrayForm && ("tagName".equals(attribute) || "childNode".equals(attribute))) {
- throw x.syntaxError("Reserved attribute.");
- }
- token = x.nextToken();
- if (token == XML.EQ) {
- token = x.nextToken();
- if (!(token instanceof String)) {
- throw x.syntaxError("Missing value");
- }
- newjo.accumulate(attribute, XML.stringToValue((String) token));
- token = null;
- } else {
- newjo.accumulate(attribute, "");
- }
- }
- if (arrayForm && newjo.length() > 0) {
- newja.put(newjo);
- }
- if (token == XML.SLASH) {
- if (x.nextToken() != XML.GT) {
- throw x.syntaxError("Misshaped tag");
- }
- if (ja == null) {
- if (arrayForm) {
- return newja;
- } else {
- return newjo;
- }
- }
- } else {
- if (token != XML.GT) {
- throw x.syntaxError("Misshaped tag");
- }
- closeTag = (String) parse(x, arrayForm, newja);
- if (closeTag != null) {
- if (!closeTag.equals(tagName)) {
- throw x.syntaxError("Mismatched '" + tagName +
- "' and '" + closeTag + "'");
- }
- if (!arrayForm && newja.length() > 0) {
- newjo.put("childNodes", newja);
- }
- if (ja == null) {
- if (arrayForm) {
- return newja;
- } else {
- return newjo;
- }
- }
- }
- }
- }
- } else {
- if (ja != null) {
- ja.put(token instanceof String
- ? XML.stringToValue((String) token)
- : token);
- }
- }
- }
- }
-
- public static JSONArray toJSONArray(String string) throws JSONException {
- return toJSONArray(new XMLTokener(string));
- }
-
- public static JSONArray toJSONArray(XMLTokener x) throws JSONException {
- return (JSONArray) parse(x, true, null);
- }
-
- public static JSONObject toJSONObject(XMLTokener x) throws JSONException {
- return (JSONObject) parse(x, false, null);
- }
-
- public static JSONObject toJSONObject(String string) throws JSONException {
- return toJSONObject(new XMLTokener(string));
- }
-
- public static String toString(JSONArray ja) throws JSONException {
- int i;
- JSONObject jo;
- String key;
- Iterator keys;
- int length;
- Object object;
- StringBuilder sb = new StringBuilder();
- String tagName;
- String value;
- tagName = ja.getString(0);
- XML.noSpace(tagName);
- tagName = XML.escape(tagName);
- sb.append('<');
- sb.append(tagName);
-
- object = ja.opt(1);
- if (object instanceof JSONObject) {
- i = 2;
- jo = (JSONObject) object;
- keys = jo.keys();
- while (keys.hasNext()) {
- key = keys.next().toString();
- XML.noSpace(key);
- value = jo.optString(key);
- if (value != null) {
- sb.append(' ');
- sb.append(XML.escape(key));
- sb.append('=');
- sb.append('"');
- sb.append(XML.escape(value));
- sb.append('"');
- }
- }
- } else {
- i = 1;
- }
- length = ja.length();
- if (i >= length) {
- sb.append('/');
- sb.append('>');
- } else {
- sb.append('>');
- do {
- object = ja.get(i);
- i += 1;
- if (object != null) {
- if (object instanceof String) {
- sb.append(XML.escape(object.toString()));
- } else if (object instanceof JSONObject) {
- sb.append(toString((JSONObject) object));
- } else if (object instanceof JSONArray) {
- sb.append(toString((JSONArray) object));
- }
- }
- } while (i < length);
- sb.append('<');
- sb.append('/');
- sb.append(tagName);
- sb.append('>');
- }
- return sb.toString();
- }
-
- public static String toString(JSONObject jo) throws JSONException {
- StringBuilder sb = new StringBuilder();
- int i;
- JSONArray ja;
- String key;
- Iterator keys;
- int length;
- Object object;
- String tagName;
- String value;
- tagName = jo.optString("tagName");
- if (tagName == null) {
- return XML.escape(jo.toString());
- }
- XML.noSpace(tagName);
- tagName = XML.escape(tagName);
- sb.append('<');
- sb.append(tagName);
- keys = jo.keys();
- while (keys.hasNext()) {
- key = keys.next().toString();
- if (!"tagName".equals(key) && !"childNodes".equals(key)) {
- XML.noSpace(key);
- value = jo.optString(key);
- if (value != null) {
- sb.append(' ');
- sb.append(XML.escape(key));
- sb.append('=');
- sb.append('"');
- sb.append(XML.escape(value));
- sb.append('"');
- }
- }
- }
- ja = jo.optJSONArray("childNodes");
- if (ja == null) {
- sb.append('/');
- sb.append('>');
- } else {
- sb.append('>');
- length = ja.length();
- for (i = 0; i < length; i += 1) {
- object = ja.get(i);
- if (object != null) {
- if (object instanceof String) {
- sb.append(XML.escape(object.toString()));
- } else if (object instanceof JSONObject) {
- sb.append(toString((JSONObject) object));
- } else if (object instanceof JSONArray) {
- sb.append(toString((JSONArray) object));
- } else {
- sb.append(object.toString());
- }
- }
- }
- sb.append('<');
- sb.append('/');
- sb.append(tagName);
- sb.append('>');
- }
- return sb.toString();
- }
-}
diff --git a/src/main/java/me/skymc/taboolib/json/JSONObject.java b/src/main/java/me/skymc/taboolib/json/JSONObject.java
deleted file mode 100644
index f335cf8..0000000
--- a/src/main/java/me/skymc/taboolib/json/JSONObject.java
+++ /dev/null
@@ -1,872 +0,0 @@
-package me.skymc.taboolib.json;
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.*;
-
-@SuppressWarnings({"rawtypes", "unchecked"})
-public class JSONObject {
-
- private static final class Null {
-
- @Override
- protected final Object clone() {
- return this;
- }
-
- @Override
- public boolean equals(Object object) {
- return object == null || object == this;
- }
-
- @Override
- public String toString() {
- return "null";
- }
- }
-
- private final Map map;
-
- public static final Object NULL = new Null();
-
- public JSONObject() {
- this.map = new HashMap();
- }
-
- public JSONObject(JSONObject jo, String[] names) {
- this();
- for (String name : names) {
- try {
- this.putOnce(name, jo.opt(name));
- } catch (Exception ignore) {
- }
- }
- }
-
- public JSONObject(JSONTokener x) throws JSONException {
- this();
- char c;
- String key;
-
- if (x.nextClean() != '{') {
- throw x.syntaxError("A JSONObject text must begin with '{'");
- }
- for (; ; ) {
- c = x.nextClean();
- switch (c) {
- case 0:
- throw x.syntaxError("A JSONObject text must end with '}'");
- case '}':
- return;
- default:
- x.back();
- key = x.nextValue().toString();
- }
- c = x.nextClean();
- if (c == '=') {
- if (x.next() != '>') {
- x.back();
- }
- } else if (c != ':') {
- throw x.syntaxError("Expected a ':' after a key");
- }
- this.putOnce(key, x.nextValue());
- switch (x.nextClean()) {
- case ';':
- case ',':
- if (x.nextClean() == '}') {
- return;
- }
- x.back();
- break;
- case '}':
- return;
- default:
- throw x.syntaxError("Expected a ',' or '}'");
- }
- }
- }
-
- public JSONObject(Map map) {
- this.map = new HashMap();
- if (map != null) {
- for (Object o : map.entrySet()) {
- Map.Entry e = (Map.Entry) o;
- Object value = e.getValue();
- if (value != null) {
- this.map.put(e.getKey(), wrap(value));
- }
- }
- }
- }
-
- public JSONObject(Object bean) {
- this();
- this.populateMap(bean);
- }
-
- public JSONObject(Object object, String[] names) {
- this();
- Class c = object.getClass();
- for (String name : names) {
- try {
- this.putOpt(name, c.getField(name).get(object));
- } catch (Exception ignore) {
- }
- }
- }
-
- public JSONObject(String source) throws JSONException {
- this(new JSONTokener(source));
- }
-
- public JSONObject(String baseName, Locale locale) throws JSONException {
- this();
- ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale,
- Thread.currentThread().getContextClassLoader());
- Enumeration keys = bundle.getKeys();
- while (keys.hasMoreElements()) {
- Object key = keys.nextElement();
- if (key instanceof String) {
- String[] path = ((String) key).split("\\.");
- int last = path.length - 1;
- JSONObject target = this;
- for (int i = 0; i < last; i += 1) {
- String segment = path[i];
- JSONObject nextTarget = target.optJSONObject(segment);
- if (nextTarget == null) {
- nextTarget = new JSONObject();
- target.put(segment, nextTarget);
- }
- target = nextTarget;
- }
- target.put(path[last], bundle.getString((String) key));
- }
- }
- }
-
- public void accumulate(String key, Object value) throws JSONException {
- testValidity(value);
- Object object = this.opt(key);
- if (object == null) {
- this.put(key, value instanceof JSONArray
- ? new JSONArray().put(value)
- : value);
- } else if (object instanceof JSONArray) {
- ((JSONArray) object).put(value);
- } else {
- this.put(key, new JSONArray().put(object).put(value));
- }
- }
-
- public JSONObject append(String key, Object value) throws JSONException {
- testValidity(value);
- Object object = this.opt(key);
- if (object == null) {
- this.put(key, new JSONArray().put(value));
- } else if (object instanceof JSONArray) {
- this.put(key, ((JSONArray) object).put(value));
- } else {
- throw new JSONException("JSONObject[" + key +
- "] is not a JSONArray.");
- }
- return this;
- }
-
- public static String doubleToString(double d) {
- if (Double.isInfinite(d) || Double.isNaN(d)) {
- return "null";
- }
- String string = Double.toString(d);
- if (string.indexOf('.') > 0 && string.indexOf('e') < 0 &&
- string.indexOf('E') < 0) {
- while (string.endsWith("0")) {
- string = string.substring(0, string.length() - 1);
- }
- if (string.endsWith(".")) {
- string = string.substring(0, string.length() - 1);
- }
- }
- return string;
- }
-
- public Object get(String key) throws JSONException {
- if (key == null) {
- throw new JSONException("Null key.");
- }
- Object object = this.opt(key);
- if (object == null) {
- throw new JSONException("JSONObject[" + quote(key) +
- "] not found.");
- }
- return object;
- }
-
- public boolean getBoolean(String key) throws JSONException {
- Object object = this.get(key);
- if (object.equals(Boolean.FALSE) ||
- (object instanceof String &&
- "false".equalsIgnoreCase((String) object))) {
- return false;
- } else if (object.equals(Boolean.TRUE) ||
- (object instanceof String &&
- "true".equalsIgnoreCase((String) object))) {
- return true;
- }
- throw new JSONException("JSONObject[" + quote(key) +
- "] is not a Boolean.");
- }
-
- public double getDouble(String key) throws JSONException {
- Object object = this.get(key);
- try {
- return object instanceof Number
- ? ((Number) object).doubleValue()
- : Double.parseDouble((String) object);
- } catch (Exception e) {
- throw new JSONException("JSONObject[" + quote(key) +
- "] is not a number.");
- }
- }
-
- public int getInt(String key) throws JSONException {
- Object object = this.get(key);
- try {
- return object instanceof Number
- ? ((Number) object).intValue()
- : Integer.parseInt((String) object);
- } catch (Exception e) {
- throw new JSONException("JSONObject[" + quote(key) +
- "] is not an int.");
- }
- }
-
- public JSONArray getJSONArray(String key) throws JSONException {
- Object object = this.get(key);
- if (object instanceof JSONArray) {
- return (JSONArray) object;
- }
- throw new JSONException("JSONObject[" + quote(key) +
- "] is not a JSONArray.");
- }
-
- public JSONObject getJSONObject(String key) throws JSONException {
- Object object = this.get(key);
- if (object instanceof JSONObject) {
- return (JSONObject) object;
- }
- throw new JSONException("JSONObject[" + quote(key) +
- "] is not a JSONObject.");
- }
-
- public long getLong(String key) throws JSONException {
- Object object = this.get(key);
- try {
- return object instanceof Number
- ? ((Number) object).longValue()
- : Long.parseLong((String) object);
- } catch (Exception e) {
- throw new JSONException("JSONObject[" + quote(key) +
- "] is not a long.");
- }
- }
-
- public static String[] getNames(JSONObject jo) {
- int length = jo.length();
- if (length == 0) {
- return null;
- }
- Iterator iterator = jo.keys();
- String[] names = new String[length];
- int i = 0;
- while (iterator.hasNext()) {
- names[i] = (String) iterator.next();
- i += 1;
- }
- return names;
- }
-
- public static String[] getNames(Object object) {
- if (object == null) {
- return null;
- }
- Class klass = object.getClass();
- Field[] fields = klass.getFields();
- int length = fields.length;
- if (length == 0) {
- return null;
- }
- String[] names = new String[length];
- for (int i = 0; i < length; i += 1) {
- names[i] = fields[i].getName();
- }
- return names;
- }
-
- public String getString(String key) throws JSONException {
- Object object = this.get(key);
- if (object instanceof String) {
- return (String) object;
- }
- throw new JSONException("JSONObject[" + quote(key) +
- "] not a string.");
- }
-
- public boolean has(String key) {
- return this.map.containsKey(key);
- }
-
- public static Object stringToValue(String string) {
- Double d;
- if ("".equals(string)) {
- return string;
- }
- if ("true".equalsIgnoreCase(string)) {
- return Boolean.TRUE;
- }
- if ("false".equalsIgnoreCase(string)) {
- return Boolean.FALSE;
- }
- if ("null".equalsIgnoreCase(string)) {
- return JSONObject.NULL;
- }
- char b = string.charAt(0);
- if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') {
- try {
- if (string.indexOf('.') > -1 ||
- string.indexOf('e') > -1 || string.indexOf('E') > -1) {
- d = Double.valueOf(string);
- if (!d.isInfinite() && !d.isNaN()) {
- return d;
- }
- } else {
- Long myLong = new Long(string);
- if (myLong == myLong.intValue()) {
- return myLong.intValue();
- } else {
- return myLong;
- }
- }
- } catch (Exception ignore) {
- }
- }
- return string;
- }
-
- public boolean isNull(String key) {
- return JSONObject.NULL.equals(this.opt(key));
- }
-
- public Iterator keys() {
- return this.map.keySet().iterator();
- }
-
- public int length() {
- return this.map.size();
- }
-
- public JSONArray names() {
- JSONArray ja = new JSONArray();
- Iterator keys = this.keys();
- while (keys.hasNext()) {
- ja.put(keys.next());
- }
- return ja.length() == 0 ? null : ja;
- }
-
- public static String numberToString(Number number)
- throws JSONException {
- if (number == null) {
- throw new JSONException("Null pointer");
- }
- testValidity(number);
- String string = number.toString();
- if (string.indexOf('.') > 0 && string.indexOf('e') < 0 &&
- string.indexOf('E') < 0) {
- while (string.endsWith("0")) {
- string = string.substring(0, string.length() - 1);
- }
- if (string.endsWith(".")) {
- string = string.substring(0, string.length() - 1);
- }
- }
- return string;
- }
-
- public Object opt(String key) {
- return key == null ? null : this.map.get(key);
- }
-
- public boolean optBoolean(String key) {
- return this.optBoolean(key, false);
- }
-
- public boolean optBoolean(String key, boolean defaultValue) {
- try {
- return this.getBoolean(key);
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
- public double optDouble(String key) {
- return this.optDouble(key, Double.NaN);
- }
-
- public double optDouble(String key, double defaultValue) {
- try {
- return this.getDouble(key);
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
- public int optInt(String key) {
- return this.optInt(key, 0);
- }
-
- public int optInt(String key, int defaultValue) {
- try {
- return this.getInt(key);
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
- public JSONArray optJSONArray(String key) {
- Object o = this.opt(key);
- return o instanceof JSONArray ? (JSONArray) o : null;
- }
-
- public JSONObject optJSONObject(String key) {
- Object object = this.opt(key);
- return object instanceof JSONObject ? (JSONObject) object : null;
- }
-
- public long optLong(String key) {
- return this.optLong(key, 0);
- }
-
- public long optLong(String key, long defaultValue) {
- try {
- return this.getLong(key);
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
- public String optString(String key) {
- return this.optString(key, "");
- }
-
- public String optString(String key, String defaultValue) {
- Object object = this.opt(key);
- return NULL.equals(object) ? defaultValue : object.toString();
- }
-
- public static String valueToString(Object value) throws JSONException {
- if (value == null || value == null) {
- return "null";
- }
- if (value instanceof JSONString) {
- Object object;
- try {
- object = ((JSONString) value).toJSONString();
- } catch (Exception e) {
- throw new JSONException(e);
- }
- if (object != null) {
- return (String) object;
- }
- throw new JSONException("Bad value from toJSONString: " + object);
- }
- if (value instanceof Number) {
- return numberToString((Number) value);
- }
- if (value instanceof Boolean || value instanceof JSONObject ||
- value instanceof JSONArray) {
- return value.toString();
- }
- if (value instanceof Map) {
- return new JSONObject((Map) value).toString();
- }
- if (value instanceof Collection) {
- return new JSONArray((Collection) value).toString();
- }
- if (value.getClass().isArray()) {
- return new JSONArray(value).toString();
- }
- return quote(value.toString());
- }
-
- public JSONObject put(String key, boolean value) throws JSONException {
- this.put(key, value ? Boolean.TRUE : Boolean.FALSE);
- return this;
- }
-
- public JSONObject put(String key, Collection value) throws JSONException {
- this.put(key, new JSONArray(value));
- return this;
- }
-
- public JSONObject put(String key, double value) throws JSONException {
- this.put(key, new Double(value));
- return this;
- }
-
- public JSONObject put(String key, int value) throws JSONException {
- this.put(key, new Integer(value));
- return this;
- }
-
- public JSONObject put(String key, long value) throws JSONException {
- this.put(key, new Long(value));
- return this;
- }
-
- public JSONObject put(String key, Map value) throws JSONException {
- this.put(key, new JSONObject(value));
- return this;
- }
-
- public JSONObject put(String key, Object value) throws JSONException {
- if (key == null) {
- throw new JSONException("Null key.");
- }
- if (value != null) {
- testValidity(value);
- this.map.put(key, value);
- } else {
- this.remove(key);
- }
- return this;
- }
-
- public JSONObject putOnce(String key, Object value) throws JSONException {
- if (key != null && value != null) {
- if (this.opt(key) != null) {
- throw new JSONException("Duplicate key \"" + key + "\"");
- }
- this.put(key, value);
- }
- return this;
- }
-
- public JSONObject putOpt(String key, Object value) throws JSONException {
- if (key != null && value != null) {
- this.put(key, value);
- }
- return this;
- }
-
- public static String quote(String string) {
- StringWriter sw = new StringWriter();
- synchronized (sw.getBuffer()) {
- try {
- return quote(string, sw).toString();
- } catch (IOException ignored) {
- return "";
- }
- }
- }
-
- public static Writer quote(String string, Writer w) throws IOException {
- if (string == null || string.length() == 0) {
- w.write("\"\"");
- return w;
- }
-
- char b;
- char c = 0;
- String hhhh;
- int i;
- int len = string.length();
-
- w.write('"');
- for (i = 0; i < len; i += 1) {
- b = c;
- c = string.charAt(i);
- switch (c) {
- case '\\':
- case '"':
- w.write('\\');
- w.write(c);
- break;
- case '/':
- if (b == '<') {
- w.write('\\');
- }
- w.write(c);
- break;
- case '\b':
- w.write("\\b");
- break;
- case '\t':
- w.write("\\t");
- break;
- case '\n':
- w.write("\\n");
- break;
- case '\f':
- w.write("\\f");
- break;
- case '\r':
- w.write("\\r");
- break;
- default:
- if (c < ' ' || (c >= '\u0080' && c < '\u00a0')
- || (c >= '\u2000' && c < '\u2100')) {
- hhhh = "000" + Integer.toHexString(c);
- w.write("\\u" + hhhh.substring(hhhh.length() - 4));
- } else {
- w.write(c);
- }
- }
- }
- w.write('"');
- return w;
- }
-
- public Object remove(String key) {
- return this.map.remove(key);
- }
-
- static void writeValue(Writer writer, Object value, int indentFactor, int indent) throws JSONException, IOException {
- if (value == null) {
- writer.write("null");
- } else if (value instanceof JSONObject) {
- ((JSONObject) value).write(writer, indentFactor, indent);
- } else if (value instanceof JSONArray) {
- ((JSONArray) value).write(writer, indentFactor, indent);
- } else if (value instanceof Map) {
- new JSONObject((Map) value).write(writer, indentFactor, indent);
- } else if (value instanceof Collection) {
- new JSONArray((Collection) value).write(writer, indentFactor,
- indent);
- } else if (value.getClass().isArray()) {
- new JSONArray(value).write(writer, indentFactor, indent);
- } else if (value instanceof Number) {
- writer.write(numberToString((Number) value));
- } else if (value instanceof Boolean) {
- writer.write(value.toString());
- } else if (value instanceof JSONString) {
- Object o;
- try {
- o = ((JSONString) value).toJSONString();
- } catch (Exception e) {
- throw new JSONException(e);
- }
- writer.write(o != null ? o.toString() : quote(value.toString()));
- } else {
- quote(value.toString(), writer);
- }
- }
-
- public static void testValidity(Object o) throws JSONException {
- if (o != null) {
- if (o instanceof Double) {
- if (((Double) o).isInfinite() || ((Double) o).isNaN()) {
- throw new JSONException(
- "JSON does not allow non-finite numbers.");
- }
- } else if (o instanceof Float) {
- if (((Float) o).isInfinite() || ((Float) o).isNaN()) {
- throw new JSONException(
- "JSON does not allow non-finite numbers.");
- }
- }
- }
- }
-
- public JSONArray toJSONArray(JSONArray names) throws JSONException {
- if (names == null || names.length() == 0) {
- return null;
- }
- JSONArray ja = new JSONArray();
- for (int i = 0; i < names.length(); i += 1) {
- ja.put(this.opt(names.getString(i)));
- }
- return ja;
- }
-
- @Override
- public String toString() {
- try {
- return this.toString(0);
- } catch (Exception e) {
- return null;
- }
- }
-
- public String toString(int indentFactor) throws JSONException {
- StringWriter w = new StringWriter();
- synchronized (w.getBuffer()) {
- return this.write(w, indentFactor, 0).toString();
- }
- }
-
- static void indent(Writer writer, int indent) throws IOException {
- for (int i = 0; i < indent; i += 1) {
- writer.write(' ');
- }
- }
-
- public static Object wrap(Object object) {
- try {
- if (object == null) {
- return NULL;
- }
- if (object instanceof JSONObject || object instanceof JSONArray ||
- NULL.equals(object) || object instanceof JSONString ||
- object instanceof Byte || object instanceof Character ||
- object instanceof Short || object instanceof Integer ||
- object instanceof Long || object instanceof Boolean ||
- object instanceof Float || object instanceof Double ||
- object instanceof String || object instanceof Enum) {
- return object;
- }
-
- if (object instanceof Collection) {
- return new JSONArray((Collection) object);
- }
- if (object.getClass().isArray()) {
- return new JSONArray(object);
- }
- if (object instanceof Map) {
- return new JSONObject((Map) object);
- }
- Package objectPackage = object.getClass().getPackage();
- String objectPackageName = objectPackage != null
- ? objectPackage.getName()
- : "";
- if (
- objectPackageName.startsWith("java.") ||
- objectPackageName.startsWith("javax.") ||
- object.getClass().getClassLoader() == null
- ) {
- return object.toString();
- }
- return new JSONObject(object);
- } catch (Exception exception) {
- return null;
- }
- }
-
- public Writer write(Writer writer) throws JSONException {
- return this.write(writer, 0, 0);
- }
-
- public JSONObject increment(String key) throws JSONException {
- Object value = this.opt(key);
- if (value == null) {
- this.put(key, 1);
- } else if (value instanceof Integer) {
- this.put(key, (Integer) value + 1);
- } else if (value instanceof Long) {
- this.put(key, (Long) value + 1);
- } else if (value instanceof Double) {
- this.put(key, (Double) value + 1);
- } else if (value instanceof Float) {
- this.put(key, (Float) value + 1);
- } else {
- throw new JSONException("Unable to increment [" + quote(key) + "].");
- }
- return this;
- }
-
- private void populateMap(Object bean) {
- Class klass = bean.getClass();
- boolean includeSuperClass = klass.getClassLoader() != null;
-
- Method[] methods = includeSuperClass
- ? klass.getMethods()
- : klass.getDeclaredMethods();
- for (Method method1 : methods) {
- try {
- Method method = method1;
- if (Modifier.isPublic(method.getModifiers())) {
- String name = method.getName();
- String key = "";
- if (name.startsWith("get")) {
- if ("getClass".equals(name) ||
- "getDeclaringClass".equals(name)) {
- key = "";
- } else {
- key = name.substring(3);
- }
- } else if (name.startsWith("is")) {
- key = name.substring(2);
- }
- if (key.length() > 0 &&
- Character.isUpperCase(key.charAt(0)) &&
- method.getParameterTypes().length == 0) {
- if (key.length() == 1) {
- key = key.toLowerCase();
- } else if (!Character.isUpperCase(key.charAt(1))) {
- key = key.substring(0, 1).toLowerCase() +
- key.substring(1);
- }
-
- Object result = method.invoke(bean, (Object[]) null);
- if (result != null) {
- this.map.put(key, wrap(result));
- }
- }
- }
- } catch (Exception ignore) {
- }
- }
- }
-
- Writer write(Writer writer, int indentFactor, int indent)
- throws JSONException {
- try {
- boolean commanate = false;
- final int length = this.length();
- Iterator keys = this.keys();
- writer.write('{');
-
- if (length == 1) {
- Object key = keys.next();
- writer.write(quote(key.toString()));
- writer.write(':');
- if (indentFactor > 0) {
- writer.write(' ');
- }
- writeValue(writer, this.map.get(key), indentFactor, indent);
- } else if (length != 0) {
- final int newindent = indent + indentFactor;
- while (keys.hasNext()) {
- Object key = keys.next();
- if (commanate) {
- writer.write(',');
- }
- if (indentFactor > 0) {
- writer.write('\n');
- }
- indent(writer, newindent);
- writer.write(quote(key.toString()));
- writer.write(':');
- if (indentFactor > 0) {
- writer.write(' ');
- }
- writeValue(writer, this.map.get(key), indentFactor,
- newindent);
- commanate = true;
- }
- if (indentFactor > 0) {
- writer.write('\n');
- }
- indent(writer, indent);
- }
- writer.write('}');
- return writer;
- } catch (IOException exception) {
- throw new JSONException(exception);
- }
- }
-}
diff --git a/src/main/java/me/skymc/taboolib/json/JSONReader.java b/src/main/java/me/skymc/taboolib/json/JSONReader.java
deleted file mode 100644
index 393cdd0..0000000
--- a/src/main/java/me/skymc/taboolib/json/JSONReader.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package me.skymc.taboolib.json;
-
-import java.util.regex.Pattern;
-
-/**
- * @Author sky
- * @Since 2018-07-01 11:10
- */
-public class JSONReader {
-
- private static Pattern pattern = Pattern.compile("[\t\n]");
-
- public static String formatJson(String content) {
- StringBuilder builder = new StringBuilder();
- int index = 0;
- int count = 0;
- while (index < content.length()) {
- char ch = content.charAt(index);
- if (ch == '{' || ch == '[') {
- builder.append(ch);
- builder.append('\n');
- count++;
- for (int i = 0; i < count; i++) {
- builder.append('\t');
- }
- } else if (ch == '}' || ch == ']') {
- builder.append('\n');
- count--;
- for (int i = 0; i < count; i++) {
- builder.append('\t');
- }
- builder.append(ch);
- } else if (ch == ',') {
- builder.append(ch);
- builder.append('\n');
- for (int i = 0; i < count; i++) {
- builder.append('\t');
- }
- } else {
- builder.append(ch);
- }
- index++;
- }
- return compactJson(builder.toString());
- }
-
- private static String compactJson(String content) {
- return pattern.matcher(content).replaceAll("").trim();
- }
-}
diff --git a/src/main/java/me/skymc/taboolib/json/JSONString.java b/src/main/java/me/skymc/taboolib/json/JSONString.java
deleted file mode 100644
index c7842f6..0000000
--- a/src/main/java/me/skymc/taboolib/json/JSONString.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package me.skymc.taboolib.json;
-
-public interface JSONString {
-
- String toJSONString();
-}
diff --git a/src/main/java/me/skymc/taboolib/json/JSONStringer.java b/src/main/java/me/skymc/taboolib/json/JSONStringer.java
deleted file mode 100644
index dddfca5..0000000
--- a/src/main/java/me/skymc/taboolib/json/JSONStringer.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package me.skymc.taboolib.json;
-
-import java.io.StringWriter;
-
-public class JSONStringer extends JSONWriter {
-
- public JSONStringer() {
- super(new StringWriter());
- }
-
- @Override
- public String toString() {
- return this.mode == 'd' ? this.writer.toString() : null;
- }
-}
diff --git a/src/main/java/me/skymc/taboolib/json/JSONTokener.java b/src/main/java/me/skymc/taboolib/json/JSONTokener.java
deleted file mode 100644
index d659a66..0000000
--- a/src/main/java/me/skymc/taboolib/json/JSONTokener.java
+++ /dev/null
@@ -1,283 +0,0 @@
-package me.skymc.taboolib.json;
-
-
-import java.io.*;
-
-public class JSONTokener {
-
- private long character;
- private boolean eof;
- private long index;
- private long line;
- private char previous;
- private Reader reader;
- private boolean usePrevious;
-
- public JSONTokener(Reader reader) {
- this.reader = reader.markSupported()
- ? reader
- : new BufferedReader(reader);
- this.eof = false;
- this.usePrevious = false;
- this.previous = 0;
- this.index = 0;
- this.character = 1;
- this.line = 1;
- }
-
- public JSONTokener(InputStream inputStream) {
- this(new InputStreamReader(inputStream));
- }
-
- public JSONTokener(String s) {
- this(new StringReader(s));
- }
-
- public void back() throws JSONException {
- if (this.usePrevious || this.index <= 0) {
- throw new JSONException("Stepping back two steps is not supported");
- }
- this.index -= 1;
- this.character -= 1;
- this.usePrevious = true;
- this.eof = false;
- }
-
- public static int dehexchar(char c) {
- if (c >= '0' && c <= '9') {
- return c - '0';
- }
- if (c >= 'A' && c <= 'F') {
- return c - ('A' - 10);
- }
- if (c >= 'a' && c <= 'f') {
- return c - ('a' - 10);
- }
- return -1;
- }
-
- public boolean end() {
- return this.eof && !this.usePrevious;
- }
-
- public boolean more() throws JSONException {
- this.next();
- if (this.end()) {
- return false;
- }
- this.back();
- return true;
- }
-
- public char next() throws JSONException {
- int c;
- if (this.usePrevious) {
- this.usePrevious = false;
- c = this.previous;
- } else {
- try {
- c = this.reader.read();
- } catch (IOException exception) {
- throw new JSONException(exception);
- }
-
- if (c <= 0) {
- this.eof = true;
- c = 0;
- }
- }
- this.index += 1;
- if (this.previous == '\r') {
- this.line += 1;
- this.character = c == '\n' ? 0 : 1;
- } else if (c == '\n') {
- this.line += 1;
- this.character = 0;
- } else {
- this.character += 1;
- }
- this.previous = (char) c;
- return this.previous;
- }
-
- public char next(char c) throws JSONException {
- char n = this.next();
- if (n != c) {
- throw this.syntaxError("Expected '" + c + "' and instead saw '" +
- n + "'");
- }
- return n;
- }
-
- public String next(int n) throws JSONException {
- if (n == 0) {
- return "";
- }
-
- char[] chars = new char[n];
- int pos = 0;
-
- while (pos < n) {
- chars[pos] = this.next();
- if (this.end()) {
- throw this.syntaxError("Substring bounds error");
- }
- pos += 1;
- }
- return new String(chars);
- }
-
- public char nextClean() throws JSONException {
- for (; ; ) {
- char c = this.next();
- if (c == 0 || c > ' ') {
- return c;
- }
- }
- }
-
- public String nextString(char quote) throws JSONException {
- char c;
- StringBuilder sb = new StringBuilder();
- for (; ; ) {
- c = this.next();
- switch (c) {
- case 0:
- case '\n':
- case '\r':
- throw this.syntaxError("Unterminated string");
- case '\\':
- c = this.next();
- switch (c) {
- case 'b':
- sb.append('\b');
- break;
- case 't':
- sb.append('\t');
- break;
- case 'n':
- sb.append('\n');
- break;
- case 'f':
- sb.append('\f');
- break;
- case 'r':
- sb.append('\r');
- break;
- case 'u':
- sb.append((char) Integer.parseInt(this.next(4), 16));
- break;
- case '"':
- case '\'':
- case '\\':
- case '/':
- sb.append(c);
- break;
- default:
- throw this.syntaxError("Illegal escape.");
- }
- break;
- default:
- if (c == quote) {
- return sb.toString();
- }
- sb.append(c);
- }
- }
- }
-
- public String nextTo(char delimiter) throws JSONException {
- StringBuilder sb = new StringBuilder();
- for (; ; ) {
- char c = this.next();
- if (c == delimiter || c == 0 || c == '\n' || c == '\r') {
- if (c != 0) {
- this.back();
- }
- return sb.toString().trim();
- }
- sb.append(c);
- }
- }
-
- public String nextTo(String delimiters) throws JSONException {
- char c;
- StringBuilder sb = new StringBuilder();
- for (; ; ) {
- c = this.next();
- if (delimiters.indexOf(c) >= 0 || c == 0 ||
- c == '\n' || c == '\r') {
- if (c != 0) {
- this.back();
- }
- return sb.toString().trim();
- }
- sb.append(c);
- }
- }
-
- public Object nextValue() throws JSONException {
- char c = this.nextClean();
- String string;
-
- switch (c) {
- case '"':
- case '\'':
- return this.nextString(c);
- case '{':
- this.back();
- return new JSONObject(this);
- case '[':
- this.back();
- return new JSONArray(this);
- }
-
- StringBuilder sb = new StringBuilder();
- while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) {
- sb.append(c);
- c = this.next();
- }
- this.back();
-
- string = sb.toString().trim();
- if ("".equals(string)) {
- throw this.syntaxError("Missing value");
- }
- return JSONObject.stringToValue(string);
- }
-
- public char skipTo(char to) throws JSONException {
- char c;
- try {
- long startIndex = this.index;
- long startCharacter = this.character;
- long startLine = this.line;
- this.reader.mark(1000000);
- do {
- c = this.next();
- if (c == 0) {
- this.reader.reset();
- this.index = startIndex;
- this.character = startCharacter;
- this.line = startLine;
- return c;
- }
- } while (c != to);
- } catch (IOException exc) {
- throw new JSONException(exc);
- }
-
- this.back();
- return c;
- }
-
- public JSONException syntaxError(String message) {
- return new JSONException(message + this.toString());
- }
-
- @Override
- public String toString() {
- return " at " + this.index + " [character " + this.character + " line " +
- this.line + "]";
- }
-}
diff --git a/src/main/java/me/skymc/taboolib/json/JSONWriter.java b/src/main/java/me/skymc/taboolib/json/JSONWriter.java
deleted file mode 100644
index 399056d..0000000
--- a/src/main/java/me/skymc/taboolib/json/JSONWriter.java
+++ /dev/null
@@ -1,160 +0,0 @@
-package me.skymc.taboolib.json;
-
-import java.io.IOException;
-import java.io.Writer;
-
-public class JSONWriter {
-
- private static final int maxdepth = 200;
-
- private boolean comma;
-
- protected char mode;
-
- private final JSONObject[] stack;
-
- private int top;
-
- protected Writer writer;
-
- public JSONWriter(Writer w) {
- this.comma = false;
- this.mode = 'i';
- this.stack = new JSONObject[maxdepth];
- this.top = 0;
- this.writer = w;
- }
-
- private JSONWriter append(String string) throws JSONException {
- if (string == null) {
- throw new JSONException("Null pointer");
- }
- if (this.mode == 'o' || this.mode == 'a') {
- try {
- if (this.comma && this.mode == 'a') {
- this.writer.write(',');
- }
- this.writer.write(string);
- } catch (IOException e) {
- throw new JSONException(e);
- }
- if (this.mode == 'o') {
- this.mode = 'k';
- }
- this.comma = true;
- return this;
- }
- throw new JSONException("Value out of sequence.");
- }
-
- public JSONWriter array() throws JSONException {
- if (this.mode == 'i' || this.mode == 'o' || this.mode == 'a') {
- this.push(null);
- this.append("[");
- this.comma = false;
- return this;
- }
- throw new JSONException("Misplaced array.");
- }
-
- private JSONWriter end(char mode, char c) throws JSONException {
- if (this.mode != mode) {
- throw new JSONException(mode == 'a'
- ? "Misplaced endArray."
- : "Misplaced endObject.");
- }
- this.pop(mode);
- try {
- this.writer.write(c);
- } catch (IOException e) {
- throw new JSONException(e);
- }
- this.comma = true;
- return this;
- }
-
- public JSONWriter endArray() throws JSONException {
- return this.end('a', ']');
- }
-
- public JSONWriter endObject() throws JSONException {
- return this.end('k', '}');
- }
-
- public JSONWriter key(String string) throws JSONException {
- if (string == null) {
- throw new JSONException("Null key.");
- }
- if (this.mode == 'k') {
- try {
- this.stack[this.top - 1].putOnce(string, Boolean.TRUE);
- if (this.comma) {
- this.writer.write(',');
- }
- this.writer.write(JSONObject.quote(string));
- this.writer.write(':');
- this.comma = false;
- this.mode = 'o';
- return this;
- } catch (IOException e) {
- throw new JSONException(e);
- }
- }
- throw new JSONException("Misplaced key.");
- }
-
- public JSONWriter object() throws JSONException {
- if (this.mode == 'i') {
- this.mode = 'o';
- }
- if (this.mode == 'o' || this.mode == 'a') {
- this.append("{");
- this.push(new JSONObject());
- this.comma = false;
- return this;
- }
- throw new JSONException("Misplaced object.");
-
- }
-
- private void pop(char c) throws JSONException {
- if (this.top <= 0) {
- throw new JSONException("Nesting error.");
- }
- char m = this.stack[this.top - 1] == null ? 'a' : 'k';
- if (m != c) {
- throw new JSONException("Nesting error.");
- }
- this.top -= 1;
- this.mode = this.top == 0
- ? 'd'
- : this.stack[this.top - 1] == null
- ? 'a'
- : 'k';
- }
-
- private void push(JSONObject jo) throws JSONException {
- if (this.top >= maxdepth) {
- throw new JSONException("Nesting too deep.");
- }
- this.stack[this.top] = jo;
- this.mode = jo == null ? 'a' : 'k';
- this.top += 1;
- }
-
- public JSONWriter value(boolean b) throws JSONException {
- return this.append(b ? "true" : "false");
- }
-
- public JSONWriter value(double d) throws JSONException {
- return this.value(new Double(d));
- }
-
- public JSONWriter value(long l) throws JSONException {
- return this.append(Long.toString(l));
- }
-
- public JSONWriter value(Object object) throws JSONException {
- return this.append(JSONObject.valueToString(object));
- }
-}
diff --git a/src/main/java/me/skymc/taboolib/json/XML.java b/src/main/java/me/skymc/taboolib/json/XML.java
deleted file mode 100644
index 6d98271..0000000
--- a/src/main/java/me/skymc/taboolib/json/XML.java
+++ /dev/null
@@ -1,338 +0,0 @@
-package me.skymc.taboolib.json;
-
-
-import java.util.Iterator;
-
-@SuppressWarnings({"rawtypes"})
-public class XML {
-
- public static final Character AMP = '&';
-
- public static final Character APOS = '\'';
-
- public static final Character BANG = '!';
-
- public static final Character EQ = '=';
-
- public static final Character GT = '>';
-
- public static final Character LT = '<';
-
- public static final Character QUEST = '?';
-
- public static final Character QUOT = '"';
-
- public static final Character SLASH = '/';
-
- public static String escape(String string) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0, length = string.length(); i < length; i++) {
- char c = string.charAt(i);
- switch (c) {
- case '&':
- sb.append("&");
- break;
- case '<':
- sb.append("<");
- break;
- case '>':
- sb.append(">");
- break;
- case '"':
- sb.append(""");
- break;
- case '\'':
- sb.append("'");
- break;
- default:
- sb.append(c);
- }
- }
- return sb.toString();
- }
-
- public static void noSpace(String string) throws JSONException {
- int i, length = string.length();
- if (length == 0) {
- throw new JSONException("Empty string.");
- }
- for (i = 0; i < length; i += 1) {
- if (Character.isWhitespace(string.charAt(i))) {
- throw new JSONException("'" + string +
- "' contains a space character.");
- }
- }
- }
-
- private static boolean parse(XMLTokener x, JSONObject context,
- String name) throws JSONException {
- char c;
- int i;
- JSONObject jsonobject = null;
- String string;
- String tagName;
- Object token;
- token = x.nextToken();
- if (token == BANG) {
- c = x.next();
- if (c == '-') {
- if (x.next() == '-') {
- x.skipPast("-->");
- return false;
- }
- x.back();
- } else if (c == '[') {
- token = x.nextToken();
- if ("CDATA".equals(token)) {
- if (x.next() == '[') {
- string = x.nextCDATA();
- if (string.length() > 0) {
- context.accumulate("content", string);
- }
- return false;
- }
- }
- throw x.syntaxError("Expected 'CDATA['");
- }
- i = 1;
- do {
- token = x.nextMeta();
- if (token == null) {
- throw x.syntaxError("Missing '>' after ' 0);
- return false;
- } else if (token == QUEST) {
- x.skipPast("?>");
- return false;
- } else if (token == SLASH) {
- token = x.nextToken();
- if (name == null) {
- throw x.syntaxError("Mismatched close tag " + token);
- }
- if (!token.equals(name)) {
- throw x.syntaxError("Mismatched " + name + " and " + token);
- }
- if (x.nextToken() != GT) {
- throw x.syntaxError("Misshaped close tag");
- }
- return true;
-
- } else if (token instanceof Character) {
- throw x.syntaxError("Misshaped tag");
- } else {
- tagName = (String) token;
- token = null;
- jsonobject = new JSONObject();
- for (; ; ) {
- if (token == null) {
- token = x.nextToken();
- }
- if (token instanceof String) {
- string = (String) token;
- token = x.nextToken();
- if (token == EQ) {
- token = x.nextToken();
- if (!(token instanceof String)) {
- throw x.syntaxError("Missing value");
- }
- jsonobject.accumulate(string,
- XML.stringToValue((String) token));
- token = null;
- } else {
- jsonobject.accumulate(string, "");
- }
- } else if (token == SLASH) {
- if (x.nextToken() != GT) {
- throw x.syntaxError("Misshaped tag");
- }
- if (jsonobject.length() > 0) {
- context.accumulate(tagName, jsonobject);
- } else {
- context.accumulate(tagName, "");
- }
- return false;
- } else if (token == GT) {
- for (; ; ) {
- token = x.nextContent();
- if (token == null) {
- if (tagName != null) {
- throw x.syntaxError("Unclosed tag " + tagName);
- }
- return false;
- } else if (token instanceof String) {
- string = (String) token;
- if (string.length() > 0) {
- jsonobject.accumulate("content",
- XML.stringToValue(string));
- }
- } else if (token == LT) {
- if (parse(x, jsonobject, tagName)) {
- if (jsonobject.length() == 0) {
- context.accumulate(tagName, "");
- } else if (jsonobject.length() == 1 &&
- jsonobject.opt("content") != null) {
- context.accumulate(tagName,
- jsonobject.opt("content"));
- } else {
- context.accumulate(tagName, jsonobject);
- }
- return false;
- }
- }
- }
- } else {
- throw x.syntaxError("Misshaped tag");
- }
- }
- }
- }
-
- public static Object stringToValue(String string) {
- if ("".equals(string)) {
- return string;
- }
- if ("true".equalsIgnoreCase(string)) {
- return Boolean.TRUE;
- }
- if ("false".equalsIgnoreCase(string)) {
- return Boolean.FALSE;
- }
- if ("null".equalsIgnoreCase(string)) {
- return JSONObject.NULL;
- }
- if ("0".equals(string)) {
- return 0;
- }
- try {
- char initial = string.charAt(0);
- boolean negative = false;
- if (initial == '-') {
- initial = string.charAt(1);
- negative = true;
- }
- if (initial == '0' && string.charAt(negative ? 2 : 1) == '0') {
- return string;
- }
- if ((initial >= '0' && initial <= '9')) {
- if (string.indexOf('.') >= 0) {
- return Double.valueOf(string);
- } else if (string.indexOf('e') < 0 && string.indexOf('E') < 0) {
- Long myLong = new Long(string);
- if (myLong == myLong.intValue()) {
- return myLong.intValue();
- } else {
- return myLong;
- }
- }
- }
- } catch (Exception ignore) {
- }
- return string;
- }
-
- public static JSONObject toJSONObject(String string) throws JSONException {
- JSONObject jo = new JSONObject();
- XMLTokener x = new XMLTokener(string);
- while (x.more() && x.skipPast("<")) {
- parse(x, jo, null);
- }
- return jo;
- }
-
- public static String toString(Object object) throws JSONException {
- return toString(object, null);
- }
-
- public static String toString(Object object, String tagName) throws JSONException {
- StringBuilder sb = new StringBuilder();
- int i;
- JSONArray ja;
- JSONObject jo;
- String key;
- Iterator keys;
- int length;
- String string;
- Object value;
- if (object instanceof JSONObject) {
- if (tagName != null) {
- sb.append('<');
- sb.append(tagName);
- sb.append('>');
- }
- jo = (JSONObject) object;
- keys = jo.keys();
- while (keys.hasNext()) {
- key = keys.next().toString();
- value = jo.opt(key);
- if (value == null) {
- value = "";
- }
- if ("content".equals(key)) {
- if (value instanceof JSONArray) {
- ja = (JSONArray) value;
- length = ja.length();
- for (i = 0; i < length; i += 1) {
- if (i > 0) {
- sb.append('\n');
- }
- sb.append(escape(ja.get(i).toString()));
- }
- } else {
- sb.append(escape(value.toString()));
- }
- } else if (value instanceof JSONArray) {
- ja = (JSONArray) value;
- length = ja.length();
- for (i = 0; i < length; i += 1) {
- value = ja.get(i);
- if (value instanceof JSONArray) {
- sb.append('<');
- sb.append(key);
- sb.append('>');
- sb.append(toString(value));
- sb.append("");
- sb.append(key);
- sb.append('>');
- } else {
- sb.append(toString(value, key));
- }
- }
- } else if ("".equals(value)) {
- sb.append('<');
- sb.append(key);
- sb.append("/>");
- } else {
- sb.append(toString(value, key));
- }
- }
- if (tagName != null) {
- sb.append("");
- sb.append(tagName);
- sb.append('>');
- }
- return sb.toString();
- } else {
- if (object.getClass().isArray()) {
- object = new JSONArray(object);
- }
- if (object instanceof JSONArray) {
- ja = (JSONArray) object;
- length = ja.length();
- for (i = 0; i < length; i += 1) {
- sb.append(toString(ja.opt(i), tagName == null ? "array" : tagName));
- }
- return sb.toString();
- } else {
- string = escape(object.toString());
- return (tagName == null) ? "\"" + string + "\"" :
- (string.length() == 0) ? "<" + tagName + "/>" :
- "<" + tagName + ">" + string + "" + tagName + ">";
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/skymc/taboolib/json/XMLTokener.java b/src/main/java/me/skymc/taboolib/json/XMLTokener.java
deleted file mode 100644
index c242bd0..0000000
--- a/src/main/java/me/skymc/taboolib/json/XMLTokener.java
+++ /dev/null
@@ -1,252 +0,0 @@
-package me.skymc.taboolib.json;
-
-@SuppressWarnings({"rawtypes", "unchecked"})
-public class XMLTokener extends JSONTokener {
-
- public static final java.util.HashMap entity;
-
- static {
- entity = new java.util.HashMap(8);
- entity.put("amp", XML.AMP);
- entity.put("apos", XML.APOS);
- entity.put("gt", XML.GT);
- entity.put("lt", XML.LT);
- entity.put("quot", XML.QUOT);
- }
-
- public XMLTokener(String s) {
- super(s);
- }
-
- public String nextCDATA() throws JSONException {
- char c;
- int i;
- StringBuilder sb = new StringBuilder();
- for (; ; ) {
- c = next();
- if (end()) {
- throw syntaxError("Unclosed CDATA");
- }
- sb.append(c);
- i = sb.length() - 3;
- if (i >= 0 && sb.charAt(i) == ']' &&
- sb.charAt(i + 1) == ']' && sb.charAt(i + 2) == '>') {
- sb.setLength(i);
- return sb.toString();
- }
- }
- }
-
- public Object nextContent() throws JSONException {
- char c;
- StringBuffer sb;
- do {
- c = next();
- } while (Character.isWhitespace(c));
- if (c == 0) {
- return null;
- }
- if (c == '<') {
- return XML.LT;
- }
- sb = new StringBuffer();
- for (; ; ) {
- if (c == '<' || c == 0) {
- back();
- return sb.toString().trim();
- }
- if (c == '&') {
- sb.append(nextEntity(c));
- } else {
- sb.append(c);
- }
- c = next();
- }
- }
-
- public Object nextEntity(char ampersand) throws JSONException {
- StringBuilder sb = new StringBuilder();
- for (; ; ) {
- char c = next();
- if (Character.isLetterOrDigit(c) || c == '#') {
- sb.append(Character.toLowerCase(c));
- } else if (c == ';') {
- break;
- } else {
- throw syntaxError("Missing ';' in XML entity: &" + sb);
- }
- }
- String string = sb.toString();
- Object object = entity.get(string);
- return object != null ? object : ampersand + string + ";";
- }
-
- public Object nextMeta() throws JSONException {
- char c;
- char q;
- do {
- c = next();
- } while (Character.isWhitespace(c));
- switch (c) {
- case 0:
- throw syntaxError("Misshaped meta tag");
- case '<':
- return XML.LT;
- case '>':
- return XML.GT;
- case '/':
- return XML.SLASH;
- case '=':
- return XML.EQ;
- case '!':
- return XML.BANG;
- case '?':
- return XML.QUEST;
- case '"':
- case '\'':
- q = c;
- for (; ; ) {
- c = next();
- if (c == 0) {
- throw syntaxError("Unterminated string");
- }
- if (c == q) {
- return Boolean.TRUE;
- }
- }
- default:
- for (; ; ) {
- c = next();
- if (Character.isWhitespace(c)) {
- return Boolean.TRUE;
- }
- switch (c) {
- case 0:
- case '<':
- case '>':
- case '/':
- case '=':
- case '!':
- case '?':
- case '"':
- case '\'':
- back();
- return Boolean.TRUE;
- }
- }
- }
- }
-
- public Object nextToken() throws JSONException {
- char c;
- char q;
- StringBuffer sb;
- do {
- c = next();
- } while (Character.isWhitespace(c));
- switch (c) {
- case 0:
- throw syntaxError("Misshaped element");
- case '<':
- throw syntaxError("Misplaced '<'");
- case '>':
- return XML.GT;
- case '/':
- return XML.SLASH;
- case '=':
- return XML.EQ;
- case '!':
- return XML.BANG;
- case '?':
- return XML.QUEST;
- case '"':
- case '\'':
- q = c;
- sb = new StringBuffer();
- for (; ; ) {
- c = next();
- if (c == 0) {
- throw syntaxError("Unterminated string");
- }
- if (c == q) {
- return sb.toString();
- }
- if (c == '&') {
- sb.append(nextEntity(c));
- } else {
- sb.append(c);
- }
- }
- default:
- sb = new StringBuffer();
- for (; ; ) {
- sb.append(c);
- c = next();
- if (Character.isWhitespace(c)) {
- return sb.toString();
- }
- switch (c) {
- case 0:
- return sb.toString();
- case '>':
- case '/':
- case '=':
- case '!':
- case '?':
- case '[':
- case ']':
- back();
- return sb.toString();
- case '<':
- case '"':
- case '\'':
- throw syntaxError("Bad character in a name");
- }
- }
- }
- }
-
- public boolean skipPast(String to) throws JSONException {
- boolean b;
- char c;
- int i;
- int j;
- int offset = 0;
- int length = to.length();
- char[] circle = new char[length];
-
- for (i = 0; i < length; i += 1) {
- c = next();
- if (c == 0) {
- return false;
- }
- circle[i] = c;
- }
- for (; ; ) {
- j = offset;
- b = true;
- for (i = 0; i < length; i += 1) {
- if (circle[j] != to.charAt(i)) {
- b = false;
- break;
- }
- j += 1;
- if (j >= length) {
- j -= length;
- }
- }
- if (b) {
- return true;
- }
- c = next();
- if (c == 0) {
- return false;
- }
- circle[offset] = c;
- offset += 1;
- if (offset >= length) {
- offset -= length;
- }
- }
- }
-}
diff --git a/src/main/java/me/skymc/taboolib/jsonformatter/JSONFormatter.java b/src/main/java/me/skymc/taboolib/jsonformatter/JSONFormatter.java
deleted file mode 100644
index 6ac0c21..0000000
--- a/src/main/java/me/skymc/taboolib/jsonformatter/JSONFormatter.java
+++ /dev/null
@@ -1,465 +0,0 @@
-package me.skymc.taboolib.jsonformatter;
-
-import com.ilummc.tlib.resources.TLocale;
-import me.skymc.taboolib.json.JSONArray;
-import me.skymc.taboolib.json.JSONObject;
-import me.skymc.taboolib.jsonformatter.click.ClickEvent;
-import me.skymc.taboolib.jsonformatter.hover.HoverEvent;
-import me.skymc.taboolib.nms.NMSUtils;
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
-import org.bukkit.entity.Player;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Unknown
- */
-@Deprecated
-public class JSONFormatter {
-
- public static void sendRawMessage(Player player, String message) {
- TLocale.Tellraw.send(player, message);
- }
-
- private JSONArray ja = new JSONArray();
- private Builder builder = new Builder();
- private String color = "";
- private List all = new ArrayList<>();
- private boolean newline = true;
-
- public JSONFormatter() {
- }
-
- public JSONFormatter(boolean newline) {
- this.newline = newline;
- }
-
- public JSONFormatter append(JSONFormatter json) {
- if (json.ja.length() == 0) {
- return this;
- }
- try {
- if (newline && json.newline) {
- all.addAll(json.all);
- }
- for (int i = 0; i < json.ja.length(); i++) {
- add(json.ja.get(i));
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return this;
- }
-
- public int getSize() {
- if (newline) {
- return 1;
- }
- return all.size() + 1;
- }
-
- public JSONFormatter newLine() {
- if (newline) {
- append("\n");
- } else {
- all.add(ja);
- ja = new JSONArray();
- }
- resetAll();
- return this;
- }
-
- public JSONFormatter newLine(int amount) {
- for (int i = 0; i < amount; i++) {
- newLine();
- }
- return this;
- }
-
- public void clear() {
- ja = new JSONArray();
- builder = new Builder();
- color = "";
- }
-
- public JSONFormatter resetAll() {
- return resetColors().resetModifiers();
- }
-
- public JSONFormatter resetColors() {
- color = "";
- return this;
- }
-
- public JSONFormatter resetModifiers() {
- builder = new Builder();
- return this;
- }
-
- public String toJSON() {
- JSONObject jo = new JSONObject();
- try {
- if (ja.length() > 0) {
- jo.put("extra", ja);
- }
- jo.put("text", "");
- } catch (Exception e) {
- e.printStackTrace();
- }
- return jo.toString();
- }
-
- public List toJSONList() {
- List list = new ArrayList<>();
- try {
- for (JSONArray ja : all) {
- JSONObject jo = new JSONObject();
- if (ja.length() > 0) {
- jo.put("extra", ja);
- }
- jo.put("text", "");
- list.add(jo.toString());
- }
- JSONObject jo = new JSONObject();
- if (ja.length() > 0) {
- jo.put("extra", ja);
- }
- jo.put("text", "");
- list.add(jo.toString());
- return list;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- public Object toSerialized() {
- try {
- return a.invoke(null, toJSON());
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- public List