mirror of
https://github.com/tr7zw/Item-NBT-API.git
synced 2026-11-13 12:31:58 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c377927ee6 | ||
|
|
0653f47bc1 | ||
|
|
5588fc60b4 | ||
|
|
7c27630c10 | ||
|
|
45dd70afad | ||
|
|
280ce7a50d | ||
|
|
175065dac4 | ||
|
|
f4bfca8ba8 | ||
|
|
37378b4ee1 | ||
|
|
662c0bb92d | ||
|
|
c485f8c967 | ||
|
|
5759b68d89 | ||
|
|
c22cbaaaf0 | ||
|
|
4a0e1b5557 | ||
|
|
1c2e61875e |
No files matched your search
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-parent</artifactId>
|
||||
<version>2.11.2</version>
|
||||
<version>2.11.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>item-nbt-api</artifactId>
|
||||
|
||||
@@ -600,6 +600,8 @@ public class NBTCompound implements ReadWriteNBT {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the provided key exists
|
||||
*
|
||||
* @param key String key
|
||||
* @return True if the key is set
|
||||
* @deprecated Use {@link #hasTag(String)} instead
|
||||
@@ -610,6 +612,8 @@ public class NBTCompound implements ReadWriteNBT {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the provided key exists
|
||||
*
|
||||
* @param key String key
|
||||
* @return true, if the key is set
|
||||
*/
|
||||
@@ -856,8 +860,8 @@ public class NBTCompound implements ReadWriteNBT {
|
||||
* Returns the stored value if exists, or provided value otherwise.
|
||||
* <p>
|
||||
* Supported types:
|
||||
* {@code byte/Byte, short/Short, int/Integer, long/Long, float/Float, double/Double, byte[], int[]},
|
||||
* {@link String}, {@link UUID}
|
||||
* {@code Boolean, Byte, Short, Integer, Long, Float, Double, byte[], int[]},
|
||||
* {@link String}, {@link UUID}, and {@link Enum}
|
||||
*
|
||||
* @param key key
|
||||
* @param defaultValue default non-null value
|
||||
@@ -873,6 +877,8 @@ public class NBTCompound implements ReadWriteNBT {
|
||||
return defaultValue;
|
||||
|
||||
Class<?> clazz = defaultValue.getClass();
|
||||
if (clazz == Boolean.class)
|
||||
return (T) getBoolean(key);
|
||||
if (clazz == Byte.class)
|
||||
return (T) getByte(key);
|
||||
if (clazz == Short.class)
|
||||
@@ -908,13 +914,13 @@ public class NBTCompound implements ReadWriteNBT {
|
||||
* Returns the stored value if exists, or null.
|
||||
* <p>
|
||||
* Supported types:
|
||||
* {@code Byte, Short, Integer, Long, Float, Double, byte[], int[]},
|
||||
* {@link String}, {@link UUID}
|
||||
* {@code Boolean, Byte, Short, Integer, Long, Float, Double, byte[], int[]},
|
||||
* {@link String}, {@link UUID}, and {@link Enum}
|
||||
*
|
||||
* @param key key
|
||||
* @param type data type
|
||||
* @param <T> value type
|
||||
* @return Stored or provided value
|
||||
* @return Stored value or null
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@@ -924,6 +930,8 @@ public class NBTCompound implements ReadWriteNBT {
|
||||
if (!hasTag(key))
|
||||
return null;
|
||||
|
||||
if (type == Boolean.class)
|
||||
return (T) getBoolean(key);
|
||||
if (type == Byte.class)
|
||||
return (T) getByte(key);
|
||||
if (type == Short.class)
|
||||
|
||||
@@ -294,7 +294,7 @@ public class NBTReflectionUtil {
|
||||
if ((boolean) ReflectionMethod.COMPOUND_HAS_KEY.run(compound, name)) {
|
||||
return ReflectionMethod.COMPOUND_GET_COMPOUND.run(compound, name);
|
||||
} else {
|
||||
throw new NbtApiException("Tried getting invalide compound '" + name + "' from '" + compound + "'!");
|
||||
throw new NbtApiException("Tried getting invalid compound '" + name + "' from '" + compound + "'!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new NbtApiException("Exception while getting NBT subcompounds!", e);
|
||||
@@ -445,7 +445,7 @@ public class NBTReflectionUtil {
|
||||
* @param key
|
||||
* @param type
|
||||
* @param clazz
|
||||
* @return The list at that key. Null if it's an invalide type
|
||||
* @return The list at that key. Null if it's an invalid type
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> NBTList<T> getList(NBTCompound comp, String key, NBTType type, Class<T> clazz) {
|
||||
|
||||
@@ -132,11 +132,24 @@ public interface ReadableNBT {
|
||||
UUID getUUID(String key);
|
||||
|
||||
/**
|
||||
* Checks whether the provided key exists
|
||||
*
|
||||
* @param key String key
|
||||
* @return true, if the key is set
|
||||
*/
|
||||
boolean hasTag(String key);
|
||||
|
||||
/**
|
||||
* Checks whether the provided key exists and has the specified type
|
||||
*
|
||||
* @param key String key
|
||||
* @param type nbt tag type
|
||||
* @return whether the key is set and has the specified type
|
||||
*/
|
||||
default boolean hasTag(String key, NBTType type) {
|
||||
return hasTag(key) && getType(key) == type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Set of all stored Keys
|
||||
*/
|
||||
|
||||
@@ -19,21 +19,21 @@ 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_19_R2(1192, true), MC1_19_R3(1193, true), MC1_20_R1(1201, true);
|
||||
|
||||
private static MinecraftVersion version;
|
||||
private static Boolean hasGsonSupport;
|
||||
private static Boolean isForgePresent;
|
||||
private static boolean bStatsDisabled = false;
|
||||
private static boolean disablePackageWarning = false;
|
||||
private static boolean updateCheckDisabled = false;
|
||||
private static boolean updateCheckDisabled = true;
|
||||
/**
|
||||
* Logger used by the api
|
||||
*/
|
||||
private static Logger logger = Logger.getLogger("NBTAPI");
|
||||
|
||||
// NBT-API Version
|
||||
protected static final String VERSION = "2.11.2";
|
||||
protected static final String VERSION = "2.11.3";
|
||||
|
||||
private final int versionId;
|
||||
private final boolean mojangMapping;
|
||||
@@ -116,7 +116,7 @@ public enum MinecraftVersion {
|
||||
logger.info("[NBTAPI] NMS support '" + version.name() + "' loaded!");
|
||||
} else {
|
||||
logger.warning("[NBTAPI] This Server-Version(" + ver + ") is not supported by this NBT-API Version("
|
||||
+ VERSION + ") located at " + MinecraftVersion.class.getName()
|
||||
+ VERSION + ") located in " + VersionChecker.getPlugin()
|
||||
+ ". The NBT-API will try to work as good as it can! Some functions may not work!");
|
||||
}
|
||||
init();
|
||||
@@ -156,6 +156,18 @@ public enum MinecraftVersion {
|
||||
logger.warning(
|
||||
"#########################################- NBTAPI -#########################################");
|
||||
}
|
||||
if (!disablePackageWarning && !"NBTAPI".equals(VersionChecker.getPlugin())
|
||||
&& MinecraftVersion.class.getPackage().getName().equals("de.tr7zw.nbtapi.utils")) {
|
||||
logger.warning(
|
||||
"#########################################- NBTAPI -#########################################");
|
||||
logger.warning(
|
||||
"The NBT-API inside " + VersionChecker.getPlugin() + " is located at 'de.tr7zw.nbtapi.utils'!");
|
||||
logger.warning(
|
||||
"This package name is reserved for the official NBTAPI plugin, and not intended to be used for shading!");
|
||||
logger.warning("Please change the relocate to something else. For example: com.example.util.nbtapi");
|
||||
logger.warning(
|
||||
"#########################################- NBTAPI -#########################################");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,6 +222,14 @@ public enum MinecraftVersion {
|
||||
updateCheckDisabled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the update check. Uses Spiget to get the current version and prints a
|
||||
* warning when outdated.
|
||||
*/
|
||||
public static void enableUpdateCheck() {
|
||||
updateCheckDisabled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forcefully disables the log message for plugins not shading the API to
|
||||
* another location. This may be helpful for networks or development
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package de.tr7zw.changeme.nbtapi.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -44,7 +46,7 @@ public class VersionChecker {
|
||||
int versionDifference = getVersionDifference(latest.get("name").getAsString());
|
||||
if (versionDifference == -1) { // Outdated
|
||||
MinecraftVersion.getLogger().log(Level.WARNING,
|
||||
"[NBTAPI] The NBT-API located at '" + NBTItem.class.getPackage() + "' seems to be outdated!");
|
||||
"[NBTAPI] The NBT-API in '" + getPlugin() + "' seems to be outdated!");
|
||||
MinecraftVersion.getLogger().log(Level.WARNING, "[NBTAPI] Current Version: '" + MinecraftVersion.VERSION
|
||||
+ "' Newest Version: " + latest.get("name").getAsString() + "'");
|
||||
MinecraftVersion.getLogger().log(Level.WARNING,
|
||||
@@ -54,7 +56,7 @@ public class VersionChecker {
|
||||
if (!hideOk)
|
||||
MinecraftVersion.getLogger().log(Level.INFO, "[NBTAPI] The NBT-API seems to be up-to-date!");
|
||||
} else if (versionDifference == 1) {
|
||||
MinecraftVersion.getLogger().log(Level.INFO, "[NBTAPI] The NBT-API at '" + NBTItem.class.getPackage()
|
||||
MinecraftVersion.getLogger().log(Level.INFO, "[NBTAPI] The NBT-API in '" + getPlugin()
|
||||
+ "' seems to be a future Version, not yet released on Spigot/CurseForge! This is not an error!");
|
||||
MinecraftVersion.getLogger().log(Level.INFO, "[NBTAPI] Current Version: '" + MinecraftVersion.VERSION
|
||||
+ "' Newest Version: " + latest.get("name").getAsString() + "'");
|
||||
@@ -105,4 +107,19 @@ public class VersionChecker {
|
||||
return 1;
|
||||
}
|
||||
|
||||
protected static String getPlugin() {
|
||||
ClassLoader classLoader = VersionChecker.class.getClassLoader();
|
||||
InputStream inputStream = classLoader.getResourceAsStream("plugin.yml");
|
||||
|
||||
if (inputStream != null) {
|
||||
try (InputStreamReader reader = new InputStreamReader(inputStream)) {
|
||||
YamlConfiguration pluginYml = YamlConfiguration.loadConfiguration(reader);
|
||||
return pluginYml.getString("name");
|
||||
} catch (IOException e) {
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
return NBTItem.class.getPackage().getName();
|
||||
}
|
||||
|
||||
}
|
||||
+14
-1
@@ -41,7 +41,6 @@ public class MojangToMapping {
|
||||
put("net.minecraft.nbt.CompoundTag#getShort(java.lang.String)", "g");
|
||||
put("net.minecraft.nbt.CompoundTag#putByte(java.lang.String,byte)", "a");
|
||||
put("net.minecraft.nbt.CompoundTag#getAllKeys()", "d");
|
||||
put("net.minecraft.nbt.CompoundTag#getAllKeys()", "d");
|
||||
put("net.minecraft.nbt.CompoundTag#putUUID(java.lang.String,java.util.UUID)", "a");
|
||||
put("net.minecraft.nbt.CompoundTag#putShort(java.lang.String,short)", "a");
|
||||
put("net.minecraft.nbt.CompoundTag#getLong(java.lang.String)", "i");
|
||||
@@ -108,8 +107,22 @@ public class MojangToMapping {
|
||||
|
||||
};
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private static Map<String, String> MC1_20R1 = new HashMap<String, String>() {
|
||||
|
||||
{
|
||||
putAll(MC1_19R2);
|
||||
|
||||
put("net.minecraft.world.entity.Entity#getEncodeId()", "br");
|
||||
put("net.minecraft.world.item.ItemStack#getTag()", "v");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public static Map<String, String> getMapping() {
|
||||
switch (MinecraftVersion.getVersion()) {
|
||||
case MC1_20_R1:
|
||||
return MC1_20R1;
|
||||
case MC1_19_R2:
|
||||
return MC1_19R2;
|
||||
case MC1_19_R1:
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-parent</artifactId>
|
||||
<version>2.11.2</version>
|
||||
<version>2.11.3</version>
|
||||
</parent>
|
||||
<artifactId>item-nbt-api-plugin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
@@ -12,19 +12,19 @@
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-api</artifactId>
|
||||
<version>2.11.2</version>
|
||||
<version>2.11.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>nbt-injector</artifactId>
|
||||
<version>2.11.2</version>
|
||||
<version>2.11.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>nbt-data-api</artifactId>
|
||||
<version>2.11.2</version>
|
||||
<version>2.11.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -78,6 +78,8 @@ public class NBTAPI extends JavaPlugin {
|
||||
if (!getConfig().getBoolean("updateCheck.enabled")) {
|
||||
getLogger().info("Update check disabled");
|
||||
MinecraftVersion.disableUpdateCheck();
|
||||
} else {
|
||||
MinecraftVersion.enableUpdateCheck();
|
||||
}
|
||||
|
||||
// Disabled by default since 2.1. Enable it yourself by calling
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-parent</artifactId>
|
||||
<version>2.11.2</version>
|
||||
<version>2.11.3</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.11.2</version>
|
||||
<version>2.11.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -24,7 +24,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.18.2.txt");
|
||||
File input = new File("minecraft_server.1.20.txt");
|
||||
List<String> lines = Files.readAllLines(input.toPath());
|
||||
|
||||
Map<String, ClassWrapper> classes = new HashMap<>();
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-parent</artifactId>
|
||||
<version>2.11.2</version>
|
||||
<version>2.11.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>nbt-data-api</artifactId>
|
||||
@@ -14,7 +14,7 @@
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-api</artifactId>
|
||||
<version>2.11.2</version>
|
||||
<version>2.11.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-parent</artifactId>
|
||||
<version>2.11.2</version>
|
||||
<version>2.11.3</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.11.2</version>
|
||||
<version>2.11.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -52,7 +52,7 @@ public class NBTInjector {
|
||||
if (MinecraftVersion.getVersion() == MinecraftVersion.MC1_7_R4
|
||||
|| MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_16_R1)) {
|
||||
logger.warning(
|
||||
"[NBTINJECTOR] The NBT-Injector is not compatibel with this Minecraft Version! For 1.16+ please use the persistent storage API.");
|
||||
"[NBTINJECTOR] The NBT-Injector is not compatible with this Minecraft Version! For 1.16+ please use the persistent storage API.");
|
||||
return;
|
||||
}
|
||||
isInjected = true;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-parent</artifactId>
|
||||
<version>2.11.2</version>
|
||||
<version>2.11.3</version>
|
||||
<packaging>pom</packaging>
|
||||
<inceptionYear>2015</inceptionYear>
|
||||
<organization>
|
||||
@@ -99,7 +99,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.2.1</version>
|
||||
<version>3.3.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
@@ -154,7 +154,7 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>license-maven-plugin</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<version>2.0.1</version>
|
||||
<configuration>
|
||||
<licenseName>mit</licenseName>
|
||||
<licenseFile>LICENSE</licenseFile>
|
||||
|
||||
@@ -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.11.2</version>
|
||||
<version>2.11.3</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.11.2</version>
|
||||
<version>2.11.3</version>
|
||||
</dependency>
|
||||
...
|
||||
<plugins>
|
||||
|
||||
Reference in new issue
Block a user