From ed867749f8d48405c5ba6c6cc05717e1a7cdddda Mon Sep 17 00:00:00 2001 From: tr7zw Date: Thu, 13 Jun 2024 20:56:49 +0200 Subject: [PATCH] Delete data api/injector logic --- .../java/de/tr7zw/nbtapi/plugin/NBTAPI.java | 39 +------ .../tr7zw/nbtapi/plugin/ReloadListener.java | 45 -------- .../plugin/tests/data/WorldDataTest.java | 26 ----- .../injector/EntityCustomNbtInjectorTest.java | 42 -------- .../injector/MergeTileSubCompoundTest.java | 46 -------- .../SpawnEntityCustomNbtInjectorTest.java | 41 ------- .../injector/TilesCustomNBTInjectorTest.java | 41 ------- .../plugin/tests/proxy/DataItemProxyTest.java | 102 +++++++++--------- 8 files changed, 54 insertions(+), 328 deletions(-) delete mode 100644 item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/ReloadListener.java delete mode 100644 item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/data/WorldDataTest.java delete mode 100644 item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/injector/EntityCustomNbtInjectorTest.java delete mode 100644 item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/injector/MergeTileSubCompoundTest.java delete mode 100644 item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/injector/SpawnEntityCustomNbtInjectorTest.java delete mode 100644 item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/injector/TilesCustomNBTInjectorTest.java diff --git a/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/NBTAPI.java b/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/NBTAPI.java index 9963341c6..85951e122 100644 --- a/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/NBTAPI.java +++ b/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/NBTAPI.java @@ -34,29 +34,22 @@ import de.tr7zw.nbtapi.plugin.tests.compounds.StreamTest; import de.tr7zw.nbtapi.plugin.tests.compounds.SubCompoundsTest; import de.tr7zw.nbtapi.plugin.tests.compounds.TypeTest; -import de.tr7zw.nbtapi.plugin.tests.data.WorldDataTest; import de.tr7zw.nbtapi.plugin.tests.entities.EntityCustomNbtPersistentTest; import de.tr7zw.nbtapi.plugin.tests.entities.EntityTest; -import de.tr7zw.nbtapi.plugin.tests.injector.EntityCustomNbtInjectorTest; -import de.tr7zw.nbtapi.plugin.tests.injector.MergeTileSubCompoundTest; -import de.tr7zw.nbtapi.plugin.tests.injector.SpawnEntityCustomNbtInjectorTest; -import de.tr7zw.nbtapi.plugin.tests.injector.TilesCustomNBTInjectorTest; import de.tr7zw.nbtapi.plugin.tests.items.ComponentsTest; import de.tr7zw.nbtapi.plugin.tests.items.DirectApplyMetaTest; import de.tr7zw.nbtapi.plugin.tests.items.DirectApplyTest; import de.tr7zw.nbtapi.plugin.tests.items.EmptyItemTest; import de.tr7zw.nbtapi.plugin.tests.items.ItemConversionTest; -import de.tr7zw.nbtapi.plugin.tests.tiles.TileTest; -import de.tr7zw.nbtapi.plugin.tests.tiles.TilesCustomNBTPersistentTest; -import de.tr7zw.nbtinjector.NBTInjector; import de.tr7zw.nbtapi.plugin.tests.items.ItemMergingTest; import de.tr7zw.nbtapi.plugin.tests.items.ItemStackConversionTest; import de.tr7zw.nbtapi.plugin.tests.items.LegacyItemTest; -import de.tr7zw.nbtapi.plugin.tests.proxy.DataItemProxyTest; -import de.tr7zw.nbtapi.plugin.tests.proxy.SimpleProxyTest; import de.tr7zw.nbtapi.plugin.tests.items.MetaTest; import de.tr7zw.nbtapi.plugin.tests.items.NBTModifyItemTest; import de.tr7zw.nbtapi.plugin.tests.items.SmuggleTest; +import de.tr7zw.nbtapi.plugin.tests.proxy.SimpleProxyTest; +import de.tr7zw.nbtapi.plugin.tests.tiles.TileTest; +import de.tr7zw.nbtapi.plugin.tests.tiles.TilesCustomNBTPersistentTest; public class NBTAPI extends JavaPlugin { @@ -73,7 +66,6 @@ public static NBTAPI getInstance() { public void onLoad() { getConfig().options().copyDefaults(true); - getConfig().addDefault("nbtInjector.enabled", false); getConfig().addDefault("bStats.enabled", true); getConfig().addDefault("updateCheck.enabled", true); getConfig().addDefault("silentquickstart", false); @@ -91,19 +83,6 @@ public void onLoad() { MinecraftVersion.enableUpdateCheck(); } - // Disabled by default since 2.1. Enable it yourself by calling - // NBTInjector.inject(); during onLoad/config - if (getConfig().getBoolean("nbtInjector.enabled")) { - getLogger().info("Injecting custom NBT"); - try { - NBTInjector.inject(); - getLogger().info("Injected!"); - } catch (Throwable ex) { // NOSONAR - getLogger().log(Level.SEVERE, "Error while Injecting custom Tile/Entity classes!", ex); - compatible = false; - } - } - // NBTCompounds apiTests.add(new GetterSetterTest()); apiTests.add(new TypeTest()); @@ -136,7 +115,6 @@ public void onLoad() { apiTests.add(new ComponentsTest()); apiTests.add(new EmptyItemTest()); apiTests.add(new SmuggleTest()); - apiTests.add(new DataItemProxyTest()); apiTests.add(new MetaTest()); if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_8_R3)) { // 1.7.10 not a thing apiTests.add(new ItemMergingTest()); @@ -164,15 +142,6 @@ public void onLoad() { // Files apiTests.add(new NBTFileTest()); - // Data - apiTests.add(new WorldDataTest()); - - // Injector - apiTests.add(new TilesCustomNBTInjectorTest()); - apiTests.add(new MergeTileSubCompoundTest()); - apiTests.add(new EntityCustomNbtInjectorTest()); - apiTests.add(new SpawnEntityCustomNbtInjectorTest()); - if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_8_R3)) apiTests.add(new GameprofileTest()); @@ -187,8 +156,6 @@ public void onEnable() { VersionChecker.hideOk = true; return; } - getLogger().info("Adding listeners..."); - Bukkit.getPluginManager().registerEvents(new ReloadListener(), this); MinecraftVersion.hasGsonSupport(); // init gson(if it hasn't already) getLogger().info("Checking bindings..."); MinecraftVersion.getVersion(); diff --git a/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/ReloadListener.java b/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/ReloadListener.java deleted file mode 100644 index 956ad8694..000000000 --- a/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/ReloadListener.java +++ /dev/null @@ -1,45 +0,0 @@ -package de.tr7zw.nbtapi.plugin; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; - -import de.tr7zw.nbtinjector.NBTInjector; - -/** - * This listener class tries to prevent people from reloading while the - * NBTInjector is enabled. - * - * @author tr7zw - * - */ -public class ReloadListener implements Listener { - - /** - * Console handler - * - * @param event - */ - @EventHandler - public void onCommand(org.bukkit.event.server.ServerCommandEvent event) { - if (event.getCommand().toLowerCase().startsWith("reload") && NBTInjector.isInjected()) { - event.setCancelled(true); - event.getSender().sendMessage( - "[NBTAPI] The NBTInjector is currently enabled. Reloading will turn the server into an unstable state and data-loss may accure. Please do a clean restart. Canceled reload!"); - } - } - - /** - * Player handler - * - * @param event - */ - @EventHandler - public void onCommand(org.bukkit.event.player.PlayerCommandPreprocessEvent event) { - if (event.getMessage().toLowerCase().startsWith("/reload") && NBTInjector.isInjected()) { - event.setCancelled(true); - event.getPlayer().sendMessage( - "[NBTAPI] The NBTInjector is currently enabled. Reloading will turn the server into an unstable state and data-loss may accure. Please do a clean restart. Canceled reload!"); - } - } - -} diff --git a/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/data/WorldDataTest.java b/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/data/WorldDataTest.java deleted file mode 100644 index dccf054f0..000000000 --- a/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/data/WorldDataTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package de.tr7zw.nbtapi.plugin.tests.data; - -import java.io.File; - -import org.bukkit.Bukkit; -import org.bukkit.World; - -import de.tr7zw.changeme.nbtapi.NbtApiException; -import de.tr7zw.changeme.nbtapi.data.NBTData; -import de.tr7zw.changeme.nbtapi.data.WorldData; -import de.tr7zw.nbtapi.plugin.tests.Test; - -public class WorldDataTest implements Test { - - @Override - public void test() throws Exception { - for (World world : Bukkit.getWorlds()) { - if (!new File(world.getWorldFolder(), "level.dat").exists()) - continue; - WorldData data = NBTData.getWorldData(world); - if (data.getWorldName() == null || data.getSpawnPosition() == null) - throw new NbtApiException("Got Null"); - } - } - -} diff --git a/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/injector/EntityCustomNbtInjectorTest.java b/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/injector/EntityCustomNbtInjectorTest.java deleted file mode 100644 index 7c3e25814..000000000 --- a/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/injector/EntityCustomNbtInjectorTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package de.tr7zw.nbtapi.plugin.tests.injector; - -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.entity.Animals; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Monster; - -import de.tr7zw.changeme.nbtapi.NBTCompound; -import de.tr7zw.changeme.nbtapi.NBTEntity; -import de.tr7zw.changeme.nbtapi.NbtApiException; -import de.tr7zw.nbtapi.plugin.tests.Test; -import de.tr7zw.nbtinjector.NBTInjector; - -public class EntityCustomNbtInjectorTest implements Test { - - @Override - public void test() throws Exception { - if (!NBTInjector.isInjected()) - return; - if (!Bukkit.getWorlds().isEmpty()) { - World world = Bukkit.getWorlds().get(0); - try { - if (!world.getEntitiesByClasses(Animals.class, Monster.class).isEmpty()) { - Entity ent = world.getEntitiesByClasses(Animals.class, Monster.class).iterator().next(); - ent = NBTInjector.patchEntity(ent); - NBTCompound comp = NBTInjector.getNbtData(ent); - comp.setString("Hello", "World"); - NBTEntity nbtent = new NBTEntity(ent); - if (!nbtent.toString().contains("__extraData:{Hello:\"World\"}")) { - throw new NbtApiException("Custom Data did not save to the Entity!"); - } - comp.removeKey("Hello"); - - } - } catch (Exception ex) { - throw new NbtApiException("Wasn't able to use NBTEntities!", ex); - } - } - } - -} diff --git a/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/injector/MergeTileSubCompoundTest.java b/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/injector/MergeTileSubCompoundTest.java deleted file mode 100644 index 6ca620931..000000000 --- a/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/injector/MergeTileSubCompoundTest.java +++ /dev/null @@ -1,46 +0,0 @@ -package de.tr7zw.nbtapi.plugin.tests.injector; - -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; - -import de.tr7zw.changeme.nbtapi.NBTCompound; -import de.tr7zw.changeme.nbtapi.NBTContainer; -import de.tr7zw.changeme.nbtapi.NbtApiException; -import de.tr7zw.nbtapi.plugin.tests.Test; -import de.tr7zw.nbtinjector.NBTInjector; - -public class MergeTileSubCompoundTest implements Test { - - @Override - public void test() throws Exception { - if (!NBTInjector.isInjected()) - return; - if (!Bukkit.getWorlds().isEmpty()) { - World world = Bukkit.getWorlds().get(0); - try { - boolean failed = false; - Block block = world.getBlockAt(world.getSpawnLocation().getBlockX(), 255, - world.getSpawnLocation().getBlockZ()); - if (block.getType() == Material.AIR) { - block.setType(Material.CHEST); - NBTCompound comp = NBTInjector.getNbtData(block.getState()); - comp.addCompound("subcomp").setString("hello", "world"); - NBTContainer cont = new NBTContainer(); - cont.mergeCompound(comp.getCompound("subcomp")); - if (!(cont.hasTag("hello") && "world".equals(cont.getString("hello")))) { - failed = true; - } - block.setType(Material.AIR); - if (failed) { - throw new NbtApiException("Data was not correct! " + cont); - } - } - } catch (Exception ex) { - throw new NbtApiException("Wasn't able to use NBTTiles!", ex); - } - } - } - -} diff --git a/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/injector/SpawnEntityCustomNbtInjectorTest.java b/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/injector/SpawnEntityCustomNbtInjectorTest.java deleted file mode 100644 index acd050da1..000000000 --- a/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/injector/SpawnEntityCustomNbtInjectorTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package de.tr7zw.nbtapi.plugin.tests.injector; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; - -import de.tr7zw.changeme.nbtapi.NBTCompound; -import de.tr7zw.changeme.nbtapi.NBTEntity; -import de.tr7zw.changeme.nbtapi.NbtApiException; -import de.tr7zw.nbtapi.plugin.tests.Test; -import de.tr7zw.nbtinjector.NBTInjector; - -public class SpawnEntityCustomNbtInjectorTest implements Test { - - @Override - public void test() throws Exception { - if (!NBTInjector.isInjected()) - return; - if (!Bukkit.getWorlds().isEmpty()) { - World world = Bukkit.getWorlds().get(0); - try { - Entity entity = world.spawnEntity(new Location(world, 0, 0, 0), EntityType.ARMOR_STAND); - entity = NBTInjector.patchEntity(entity); - NBTCompound comp = NBTInjector.getNbtData(entity); - comp.setString("Hello", "World"); - NBTEntity nbtent = new NBTEntity(entity); - if (!nbtent.toString().contains("__extraData:{Hello:\"World\"}")) { - throw new NbtApiException("Custom Data did not save to the Entity!"); - } - comp.removeKey("Hello"); - entity.remove(); - - } catch (Exception ex) { - throw new NbtApiException("Wasn't able to use NBTEntities!", ex); - } - } - } - -} diff --git a/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/injector/TilesCustomNBTInjectorTest.java b/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/injector/TilesCustomNBTInjectorTest.java deleted file mode 100644 index 7e779d54e..000000000 --- a/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/injector/TilesCustomNBTInjectorTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package de.tr7zw.nbtapi.plugin.tests.injector; - -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; - -import de.tr7zw.changeme.nbtapi.NBTCompound; -import de.tr7zw.changeme.nbtapi.NBTTileEntity; -import de.tr7zw.changeme.nbtapi.NbtApiException; -import de.tr7zw.nbtapi.plugin.tests.Test; -import de.tr7zw.nbtinjector.NBTInjector; - -public class TilesCustomNBTInjectorTest implements Test { - - @Override - public void test() throws Exception { - if (!NBTInjector.isInjected()) - return; - if (!Bukkit.getWorlds().isEmpty()) { - World world = Bukkit.getWorlds().get(0); - try { - Block block = world.getBlockAt(world.getSpawnLocation().getBlockX(), 255, - world.getSpawnLocation().getBlockZ()); - if (block.getType() == Material.AIR) { - block.setType(Material.CHEST); - NBTCompound comp = NBTInjector.getNbtData(block.getState()); - comp.setString("Foo", "Bar"); - if (!new NBTTileEntity(block.getState()).toString().contains("__extraData:{Foo:\"Bar\"}")) { - block.setType(Material.AIR); - throw new NbtApiException("Custom Data did not save to the Tile!"); - } - block.setType(Material.AIR); - } - } catch (Exception ex) { - throw new NbtApiException("Wasn't able to use NBTTiles!", ex); - } - } - } - -} diff --git a/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/proxy/DataItemProxyTest.java b/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/proxy/DataItemProxyTest.java index f8520e6a2..116dd1414 100644 --- a/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/proxy/DataItemProxyTest.java +++ b/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/proxy/DataItemProxyTest.java @@ -1,51 +1,51 @@ -package de.tr7zw.nbtapi.plugin.tests.proxy; - -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import de.tr7zw.changeme.nbtapi.NBT; -import de.tr7zw.changeme.nbtapi.NBTItem; -import de.tr7zw.changeme.nbtapi.NbtApiException; -import de.tr7zw.changeme.nbtapi.data.proxy.NBTItemMeta; -import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT; -import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion; -import de.tr7zw.nbtapi.plugin.tests.Test; - -public class DataItemProxyTest implements Test { - - @Override - public void test() throws Exception { - if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) { - return; // skip - } - ItemStack item = new ItemStack(Material.STONE); - ItemMeta meta = item.getItemMeta(); - meta.setDisplayName("Test"); - item.setItemMeta(meta); - NBT.modify(item, NBTItemMeta.class, nmeta -> { - nmeta.setCustomModelData(123); - nmeta.setUnbreakable(true); - if (!nmeta.getDisplayData().getRawName().contains("Test")) { - throw new NbtApiException("Raw name didn't containg the expected String: " + nmeta); - } - ReadWriteNBT container = NBT.createNBTObject(); - container.setString("foo", "bar"); - nmeta.setBlockStateTag(container); - if (!container.equals(nmeta.getBlockStateTag())) { - throw new NbtApiException("BlockStateTag did not match! " + nmeta); - } - }); - - if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_16_R1)) { - meta = item.getItemMeta(); - if (!meta.hasCustomModelData() || meta.getCustomModelData() != 123) { - throw new NbtApiException("Custom Model Data did not match! " + new NBTItem(item)); - } - if (!meta.isUnbreakable()) { - throw new NbtApiException("Unbreakable did not set!"); - } - } - } - -} +//package de.tr7zw.nbtapi.plugin.tests.proxy; +// +//import org.bukkit.Material; +//import org.bukkit.inventory.ItemStack; +//import org.bukkit.inventory.meta.ItemMeta; +// +//import de.tr7zw.changeme.nbtapi.NBT; +//import de.tr7zw.changeme.nbtapi.NBTItem; +//import de.tr7zw.changeme.nbtapi.NbtApiException; +//import de.tr7zw.changeme.nbtapi.data.proxy.NBTItemMeta; +//import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT; +//import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion; +//import de.tr7zw.nbtapi.plugin.tests.Test; +// +//public class DataItemProxyTest implements Test { +// +// @Override +// public void test() throws Exception { +// if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) { +// return; // skip +// } +// ItemStack item = new ItemStack(Material.STONE); +// ItemMeta meta = item.getItemMeta(); +// meta.setDisplayName("Test"); +// item.setItemMeta(meta); +// NBT.modify(item, NBTItemMeta.class, nmeta -> { +// nmeta.setCustomModelData(123); +// nmeta.setUnbreakable(true); +// if (!nmeta.getDisplayData().getRawName().contains("Test")) { +// throw new NbtApiException("Raw name didn't containg the expected String: " + nmeta); +// } +// ReadWriteNBT container = NBT.createNBTObject(); +// container.setString("foo", "bar"); +// nmeta.setBlockStateTag(container); +// if (!container.equals(nmeta.getBlockStateTag())) { +// throw new NbtApiException("BlockStateTag did not match! " + nmeta); +// } +// }); +// +// if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_16_R1)) { +// meta = item.getItemMeta(); +// if (!meta.hasCustomModelData() || meta.getCustomModelData() != 123) { +// throw new NbtApiException("Custom Model Data did not match! " + new NBTItem(item)); +// } +// if (!meta.isUnbreakable()) { +// throw new NbtApiException("Unbreakable did not set!"); +// } +// } +// } +// +//}