Compare commits

...
13 Commits
Author SHA1 Message Date
tr7zw 956ef15a1d Bump version 2024-06-13 21:15:01 +02:00
tr7zw ed867749f8 Delete data api/injector logic 2024-06-13 20:56:49 +02:00
tr7zw 88fbc0140e Remove nbt-injector and nbt-data-api 2024-06-13 20:48:36 +02:00
tr7zw 82e52267b8 More deprecation, use the NBT class 2024-06-13 20:27:23 +02:00
tr7zw c16548ff4e New "modifyComponents" api 2024-06-13 20:26:39 +02:00
tr7zw cf30cf996e Update to 1.21 2024-06-13 19:56:59 +02:00
tr7zw 633433d6d0 Merge pull request #278 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-shade-plugin-3.6.0
Bump org.apache.maven.plugins:maven-shade-plugin from 3.5.3 to 3.6.0
2024-06-08 21:02:14 +02:00
tr7zw 153c72818a Merge pull request #279 from tr7zw/dependabot/maven/org.apache.maven.plugins-maven-javadoc-plugin-3.7.0
Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.6.3 to 3.7.0
2024-06-08 21:02:06 +02:00
dependabot[bot] 4798880a53 Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.6.3 to 3.7.0
Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.6.3 to 3.7.0.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.6.3...maven-javadoc-plugin-3.7.0)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-javadoc-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-05-31 23:20:47 +00:00
dependabot[bot] 1f149dbae4 Bump org.apache.maven.plugins:maven-shade-plugin from 3.5.3 to 3.6.0
Bumps [org.apache.maven.plugins:maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.5.3 to 3.6.0.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.5.3...maven-shade-plugin-3.6.0)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-shade-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-05-31 23:20:38 +00:00
tr7zw 8570c6f77e Improve error when trying to get NBT from non BlockEntity BlockStates. Fix #276 2024-05-19 01:07:24 +02:00
tr7zw 30f75e0714 Deprecate usage of NBTItem/NBTEntity/NBTTileEntity 2024-05-19 00:55:15 +02:00
tr7zw af7a6b0a1c Start 2.12.5-SNAPSHOT 2024-05-19 00:47:46 +02:00
25 changed files with 203 additions and 367 deletions

No files matched your search

+2 -2
View File
@@ -5,7 +5,7 @@
<parent>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-parent</artifactId>
<version>2.12.4</version>
<version>2.13.0</version>
</parent>
<artifactId>item-nbt-api</artifactId>
@@ -32,7 +32,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.3</version>
<version>3.6.0</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<transformers>
@@ -18,6 +18,7 @@ import de.tr7zw.changeme.nbtapi.iface.ReadableNBT;
import de.tr7zw.changeme.nbtapi.wrapper.NBTProxy;
import de.tr7zw.changeme.nbtapi.wrapper.ProxyBuilder;
import de.tr7zw.changeme.nbtapi.iface.ReadableNBTList;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
/**
* General utility class for a clean and simple nbt access.
@@ -25,6 +26,7 @@ import de.tr7zw.changeme.nbtapi.iface.ReadableNBTList;
* @author tr7zw
*
*/
@SuppressWarnings("deprecation")
public class NBT {
private NBT() {
@@ -225,6 +227,44 @@ public class NBT {
nbtEnt.setClosed();
return ret;
}
/**
* It takes an ItemStack and a Consumer&lt;ReadWriteNBT&gt;, and then applies
* the Consumer to the ItemStacks Components as NBT. This is for 1.20.5+ only.
* This method is quiet expensive, so don't overuse it.
*
* @param item The item you want to modify the components of
* @param consumer The consumer that will be used to modify the components.
*/
public static void modifyComponents(ItemStack item, Consumer<ReadWriteNBT> consumer) {
if(!MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
throw new NbtApiException("This method only works for 1.20.5+!");
}
ReadWriteNBT nbti = NBT.itemStackToNBT(item);
consumer.accept(nbti.getOrCreateCompound("components"));
ItemStack tmp = NBT.itemStackFromNBT(nbti);
item.setItemMeta(tmp.getItemMeta());
}
/**
* It takes an ItemStack and a Consumer&lt;ReadWriteNBT&gt;, and then applies
* the Consumer to the ItemStacks Components as NBT. This is for 1.20.5+ only.
* This method is quiet expensive, so don't overuse it.
*
* @param item The item you want to modify the components of
* @param function The consumer that will be used to modify the components.
* @return The return type is the same as the return type of the function.
*/
public static <T> T modifyComponents(ItemStack item, Function<ReadWriteNBT, T> function) {
if(!MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
throw new NbtApiException("This method only works for 1.20.5+!");
}
ReadWriteNBT nbti = NBT.itemStackToNBT(item);
T ret = function.apply(nbti.getOrCreateCompound("components"));
ItemStack tmp = NBT.itemStackFromNBT(nbti);
item.setItemMeta(tmp.getItemMeta());
return ret;
}
/**
* It takes an entity and a function that takes a ReadWriteNBT and applies the
@@ -40,8 +40,11 @@ public class NBTEntity extends NBTCompound {
}
/**
* Deprecated: Please use the NBT class
*
* @param entity Any valid Bukkit Entity
*/
@Deprecated
public NBTEntity(Entity entity) {
super(null, null);
if (entity == null) {
@@ -15,6 +15,7 @@ public class NBTGameProfile {
* @param profile
* @return A NBTContainer with all the GameProfile data
*/
@Deprecated
public static NBTCompound toNBT(GameProfile profile) {
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
return (NBTCompound) GameprofileUtil.writeGameProfile(NBT.createNBTObject(), profile);
@@ -29,6 +30,7 @@ public class NBTGameProfile {
* @param compound Has to contain GameProfile data
* @return The reconstructed GameProfile
*/
@Deprecated
public static GameProfile fromNBT(NBTCompound compound) {
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
return GameprofileUtil.readGameProfile(compound);
@@ -33,10 +33,13 @@ public class NBTItem extends NBTCompound implements ReadWriteItemNBT {
private boolean closed = false;
/**
* Constructor for NBTItems. The ItemStack will be cloned!
* Constructor for NBTItems. The ItemStack will be cloned! Deprecated: Please
* use the NBT class to work with items. It's up to 400% faster and provides
* less ways to mess up code.
*
* @param item
*/
@Deprecated
public NBTItem(ItemStack item) {
this(item, false);
}
@@ -186,6 +189,7 @@ public class NBTItem extends NBTCompound implements ReadWriteItemNBT {
*
* @param item ItemStack that should get the new NBT data
*/
@Deprecated
public void applyNBT(ItemStack item) {
if (item == null || item.getType() == Material.AIR) {
throw new NullPointerException("ItemStack can't be null/Air! This is not a NBTAPI bug!");
@@ -200,6 +204,7 @@ public class NBTItem extends NBTCompound implements ReadWriteItemNBT {
*
* @param item ItemStack that should get the new NBT data
*/
@Deprecated
public void mergeNBT(ItemStack item) {
NBTItem nbti = new NBTItem(item);
nbti.mergeCompound(this);
@@ -216,7 +221,7 @@ public class NBTItem extends NBTCompound implements ReadWriteItemNBT {
if (item == null || item.getType() == Material.AIR) {
throw new NullPointerException("ItemStack can't be null/Air!");
}
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
// 1.20.5+ doesn't have any vanilla tags
NBT.modify(item, nbt -> {
nbt.mergeCompound(this);
@@ -236,7 +241,7 @@ public class NBTItem extends NBTCompound implements ReadWriteItemNBT {
*/
@Deprecated
public boolean hasCustomNbtData() {
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
// 1.20.5+ doesn't have any vanilla tags
return hasNBTData();
}
@@ -251,7 +256,7 @@ public class NBTItem extends NBTCompound implements ReadWriteItemNBT {
@Deprecated
public void clearCustomNBT() {
finalizeChanges();
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
// 1.20.5+ doesn't have any vanilla tags
setCompound(null);
return;
@@ -300,8 +305,9 @@ public class NBTItem extends NBTCompound implements ReadWriteItemNBT {
bukkitItem.setItemMeta(meta);
updateCachedCompound();
if (directApply) {
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
throw new NbtApiException("Direct apply mode meta changes don't work anymore in 1.20.5+. Please switch to the modern NBT.modify sytnax!");
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
throw new NbtApiException(
"Direct apply mode meta changes don't work anymore in 1.20.5+. Please switch to the modern NBT.modify sytnax!");
}
applyNBT(originalSrcStack);
}
@@ -336,6 +342,7 @@ public class NBTItem extends NBTCompound implements ReadWriteItemNBT {
* @param item
* @return Standalone {@link NBTContainer} with the Item's data
*/
@Deprecated
public static NBTContainer convertItemtoNBT(ItemStack item) {
return NBTReflectionUtil.convertNMSItemtoNBTCompound(ReflectionMethod.ITEMSTACK_NMSCOPY.run(null, item));
}
@@ -348,6 +355,7 @@ public class NBTItem extends NBTCompound implements ReadWriteItemNBT {
* @return ItemStack using the {@link NBTCompound}'s data
*/
@Nullable
@Deprecated
public static ItemStack convertNBTtoItem(NBTCompound comp) {
return (ItemStack) ReflectionMethod.ITEMSTACK_BUKKITMIRROR.run(null,
NBTReflectionUtil.convertNBTCompoundtoNMSItem(comp));
@@ -361,6 +369,7 @@ public class NBTItem extends NBTCompound implements ReadWriteItemNBT {
* @param items
* @return Standalone {@link NBTContainer} with the Item's data
*/
@Deprecated
public static NBTContainer convertItemArraytoNBT(ItemStack[] items) {
NBTContainer container = new NBTContainer();
container.setInteger("size", items.length);
@@ -389,6 +398,7 @@ public class NBTItem extends NBTCompound implements ReadWriteItemNBT {
* @return ItemStack[] using the {@link NBTCompound}'s data
*/
@Nullable
@Deprecated
public static ItemStack[] convertNBTtoItemArray(NBTCompound comp) {
if (!comp.hasTag("size")) {
return null;
@@ -213,8 +213,9 @@ public class NBTReflectionUtil {
try {
Object nmsComp = getToCompount(nbtcompound.getCompound(), nbtcompound);
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
if(nbtcompound.hasTag("tag")) {
nmsComp = DataFixerUtil.fixUpRawItemData(nmsComp, DataFixerUtil.VERSION1_20_4, DataFixerUtil.getCurrentVersion());
if (nbtcompound.hasTag("tag")) {
nmsComp = DataFixerUtil.fixUpRawItemData(nmsComp, DataFixerUtil.VERSION1_20_4,
DataFixerUtil.getCurrentVersion());
}
return ReflectionMethod.NMSITEM_LOAD.run(null, registry_access, nmsComp);
} else if (MinecraftVersion.getVersion().getVersionId() >= MinecraftVersion.MC1_11_R1.getVersionId()) {
@@ -316,6 +317,11 @@ public class NBTReflectionUtil {
o = ReflectionMethod.NMS_WORLD_GET_TILEENTITY.run(nmsworld, pos);
}
if (o == null) {
throw new NbtApiException("The passed BlockState(" + tile.getType()
+ ") doesn't point to a BlockEntity. Only BlockEntities like Chest/Signs/Furnance/etc have NBT.");
}
Object answer = null;
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
answer = ReflectionMethod.TILEENTITY_GET_NBT_1205.run(o, registry_access);
@@ -26,7 +26,7 @@ public class NBTTileEntity extends NBTCompound {
* @param tile BlockState from any TileEntity
* @param readonly Readonly makes a copy at init, only reading from that copy
*/
public NBTTileEntity(BlockState tile, boolean readonly) {
protected NBTTileEntity(BlockState tile, boolean readonly) {
super(null, null);
if (tile == null || (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_8_R3) && !tile.isPlaced())) {
throw new NullPointerException("Tile can't be null/not placed!");
@@ -41,8 +41,11 @@ public class NBTTileEntity extends NBTCompound {
}
/**
* Deprecated: Please use the NBT class
*
* @param tile BlockState from any TileEntity
*/
@Deprecated
public NBTTileEntity(BlockState tile) {
super(null, null);
if (tile == null || (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_8_R3) && !tile.isPlaced())) {
@@ -23,7 +23,8 @@ public enum MinecraftVersion {
MC1_7_R4(174), MC1_8_R3(183), MC1_9_R1(191), MC1_9_R2(192), MC1_10_R1(1101), MC1_11_R1(1111), MC1_12_R1(1121),
MC1_13_R1(1131), MC1_13_R2(1132), MC1_14_R1(1141), MC1_15_R1(1151), MC1_16_R1(1161), MC1_16_R2(1162),
MC1_16_R3(1163), MC1_17_R1(1171), MC1_18_R1(1181, true), MC1_18_R2(1182, true), MC1_19_R1(1191, true),
MC1_19_R2(1192, true), MC1_19_R3(1193, true), MC1_20_R1(1201, true), MC1_20_R2(1202, true), MC1_20_R3(1203, true), MC1_20_R4(1204, true);
MC1_19_R2(1192, true), MC1_19_R3(1193, true), MC1_20_R1(1201, true), MC1_20_R2(1202, true), MC1_20_R3(1203, true),
MC1_20_R4(1204, true), MC1_21_R1(1211, true);
private static MinecraftVersion version;
private static Boolean hasGsonSupport;
@@ -38,7 +39,7 @@ public enum MinecraftVersion {
private static Logger logger = Logger.getLogger("NBTAPI");
// NBT-API Version
protected static final String VERSION = "2.12.4";
protected static final String VERSION = "2.13.0";
private final int versionId;
private final boolean mojangMapping;
@@ -54,6 +55,7 @@ public enum MinecraftVersion {
this.put("1.20.4", MC1_20_R3);
this.put("1.20.5", MC1_20_R4);
this.put("1.20.6", MC1_20_R4);
this.put("1.21.0", MC1_21_R1);
}
};
@@ -8,6 +8,7 @@ import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
/**
* Temporary solution to hold Mojang to unmapped Spigot mappings.
* Note years later: nothing is more permanent than a temporary solution.
*
* @author tr7zw
*
@@ -171,10 +172,23 @@ public class MojangToMapping {
}
};
@SuppressWarnings("serial")
private static Map<String, String> MC1_21R1 = new HashMap<String, String>() {
{
putAll(MC1_20R4);
put("net.minecraft.world.entity.Entity#getEncodeId()", "bD");
}
};
public static Map<String, String> getMapping() {
switch (MinecraftVersion.getVersion()) {
case MC1_21_R1:
return MC1_21R1;
case MC1_20_R4:
return MC1_20R4;
case MC1_20_R3:
+3 -15
View File
@@ -4,7 +4,7 @@
<parent>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-parent</artifactId>
<version>2.12.4</version>
<version>2.13.0</version>
</parent>
<artifactId>item-nbt-api-plugin</artifactId>
<packaging>jar</packaging>
@@ -12,19 +12,7 @@
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api</artifactId>
<version>2.12.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>nbt-injector</artifactId>
<version>2.12.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>nbt-data-api</artifactId>
<version>2.12.4</version>
<version>2.13.0</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -45,7 +33,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.3</version>
<version>3.6.0</version>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<relocations>
@@ -34,28 +34,22 @@ import de.tr7zw.nbtapi.plugin.tests.compounds.ResolveTest;
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 {
@@ -72,7 +66,6 @@ public class NBTAPI extends JavaPlugin {
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);
@@ -90,19 +83,6 @@ public class NBTAPI extends JavaPlugin {
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());
@@ -132,9 +112,9 @@ public class NBTAPI extends JavaPlugin {
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
apiTests.add(new LegacyItemTest());
}
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());
@@ -162,15 +142,6 @@ public class NBTAPI extends JavaPlugin {
// 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());
@@ -185,8 +156,6 @@ public class NBTAPI extends JavaPlugin {
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();
@@ -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!");
}
}
}
@@ -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");
}
}
}
@@ -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);
}
}
}
}
@@ -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);
}
}
}
}
@@ -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);
}
}
}
}
@@ -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);
}
}
}
}
@@ -0,0 +1,37 @@
package de.tr7zw.nbtapi.plugin.tests.items;
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.NbtApiException;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
import de.tr7zw.nbtapi.plugin.tests.Test;
public class ComponentsTest implements Test {
@Override
public void test() throws Exception {
if(!MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
return;
}
ItemStack item = new ItemStack(Material.STICK);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("test");
item.setItemMeta(meta);
String comp = NBT.modifyComponents(item, n -> {
return n.toString();
});
if(!comp.contains("test")) {
throw new NbtApiException("ReadComponent didn't work!");
}
NBT.modifyComponents(item, nbt -> {
nbt.setString("minecraft:custom_name", "{\"extra\":[\"foobar\"],\"text\":\"\"}");
});
if(!item.getItemMeta().getDisplayName().equals("foobar")) {
throw new NbtApiException("ModifyComponent didn't work!");
}
}
}
@@ -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!");
// }
// }
// }
//
//}
+2 -2
View File
@@ -4,7 +4,7 @@
<parent>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-parent</artifactId>
<version>2.12.4</version>
<version>2.13.0</version>
</parent>
<artifactId>mappings-parser</artifactId>
<packaging>jar</packaging>
@@ -12,7 +12,7 @@
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api</artifactId>
<version>2.12.4</version>
<version>2.13.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
@@ -10,6 +10,7 @@ import java.util.Map;
import java.util.Map.Entry;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ClassWrapper;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.MojangToMapping;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;
/**
@@ -24,7 +25,7 @@ public class MappingsParser {
public static StringBuilder builder = new StringBuilder();
public static void main(String[] args) throws IOException {
File input = new File("minecraft_server.1.20.5.txt");
File input = new File("minecraft_server.1.21.txt");
List<String> lines = Files.readAllLines(input.toPath());
Map<String, ClassWrapper> classes = new HashMap<>();
@@ -84,6 +85,8 @@ public class MappingsParser {
System.out.println(
"Missing mapping in class " + nmsWrapper.getMojangName() + " method " + entry.getKey().name());
} else {
if(!entry.getValue().equals(MojangToMapping.getMapping().get(nmsWrapper.getMojangName() + "#"
+ entry.getKey().getSelectedVersionInfo().name)))
builder.append("put(\"" + nmsWrapper.getMojangName() + "#"
+ entry.getKey().getSelectedVersionInfo().name + "\", \"" + entry.getValue() + "\");\n");
}
+2 -2
View File
@@ -5,7 +5,7 @@
<parent>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-parent</artifactId>
<version>2.12.4</version>
<version>2.13.0</version>
</parent>
<artifactId>nbt-data-api</artifactId>
@@ -14,7 +14,7 @@
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api</artifactId>
<version>2.12.4</version>
<version>2.13.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
+2 -2
View File
@@ -4,7 +4,7 @@
<parent>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-parent</artifactId>
<version>2.12.4</version>
<version>2.13.0</version>
</parent>
<artifactId>nbt-injector</artifactId>
<packaging>jar</packaging>
@@ -12,7 +12,7 @@
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api</artifactId>
<version>2.12.4</version>
<version>2.13.0</version>
<scope>compile</scope>
</dependency>
<dependency>
+2 -2
View File
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-parent</artifactId>
<version>2.12.4</version>
<version>2.13.0</version>
<packaging>pom</packaging>
<inceptionYear>2015</inceptionYear>
<organization>
@@ -112,7 +112,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.6.3</version>
<version>3.7.0</version>
<configuration>
<source>8</source>
</configuration>
+2 -2
View File
@@ -112,7 +112,7 @@ Just use the Plugin as Maven dependency and remember to add "NBTAPI" as dependen
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api-plugin</artifactId>
<version>2.12.4</version>
<version>2.13.0</version>
</dependency>
[/CODE]
[/SPOILER]
@@ -122,7 +122,7 @@ Using this method the API gets copied into your plugin. Server owners don't have
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api</artifactId>
<version>2.12.4</version>
<version>2.13.0</version>
</dependency>
...
<plugins>