From 9911c406f8c56ba24aec5944f2b7ce16f827bf41 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 30 Oct 2019 14:56:30 -0700 Subject: [PATCH] Refactor some Type names and javadocs --- .../nossr50/core/adapters/NBTAdapter.java | 6 ++ .../adapters/NMS_114/BukkitNBTAdapter.java | 73 +++++++++++++++++-- .../core/adapters/PlatformAdapter.java | 4 + .../core/nbt/{NBTInteger.java => NBTInt.java} | 2 +- 4 files changed, 79 insertions(+), 6 deletions(-) rename mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/{NBTInteger.java => NBTInt.java} (90%) diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NBTAdapter.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NBTAdapter.java index 8a6ee639f..7013f0d3b 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NBTAdapter.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NBTAdapter.java @@ -3,5 +3,11 @@ package com.gmail.nossr50.core.adapters; import com.gmail.nossr50.core.nbt.NBTBase; public interface NBTAdapter { + + /** + * Transform our NBT type representation to its implementation on the target platform + * @param nbtBase target NBT type representation + * @return platform specific implementation of our NBT Type + */ Object asNative(NBTBase nbtBase); } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitNBTAdapter.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitNBTAdapter.java index 5b8791f95..8930c66ed 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitNBTAdapter.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/NMS_114/BukkitNBTAdapter.java @@ -18,7 +18,7 @@ public class BukkitNBTAdapter implements NBTAdapter { case SHORT: return asNativeNBTShort((NBTShort) nbtBase); case INT: - return asNativeNBTInt((NBTInteger) nbtBase); + return asNativeNBTInt((NBTInt) nbtBase); case LONG: return asNativeNBTLong((NBTLong) nbtBase); case FLOAT: @@ -34,9 +34,9 @@ public class BukkitNBTAdapter implements NBTAdapter { case COMPOUND: return ; case INT_ARRAY: - break; + return asNativeNBTIntArray((NBTIntArray) nbtBase); case LONG_ARRAY: - break; + return asNativeNBTLongArray((NBTLongArray) nbtBase); } return null; @@ -51,42 +51,105 @@ public class BukkitNBTAdapter implements NBTAdapter { return new NBTTagByte(nbtByte.getValue()); } + /** + * Create a NBTTagShort (NMS Type) from our NBTShort representation + * @param nbtShort target NBTShort + * @return NBTTagShort copy of our NBTShort representation + */ private NBTTagShort asNativeNBTShort(NBTShort nbtShort) { return new NBTTagShort(nbtShort.getValue()); } - private NBTTagInt asNativeNBTInt(NBTInteger nbtInteger) { - return new NBTTagInt(nbtInteger.getValue()); + /** + * Create a NBTTagInt (NMS Type) from our NBTInt representation + * @param nbtInt target NBTInt + * @return NBTTagInt copy of our NBTInt representation + */ + private NBTTagInt asNativeNBTInt(NBTInt nbtInt) { + return new NBTTagInt(nbtInt.getValue()); } + /** + * Create a NBTTagLong (NMS Type) from our NBTLong representation + * @param nbtLong target NBTLong + * @return NBTTagLong copy of our NBTLong representation + */ private NBTTagLong asNativeNBTLong(NBTLong nbtLong) { return new NBTTagLong(nbtLong.getValue()); } + /** + * Create a NBTTagFloat (NMS Type) from our NBTFloat representation + * @param nbtFloat target NBTFloat + * @return NBTTagFloat copy of our NBTFloat representation + */ private NBTTagFloat asNativeNBTFloat(NBTFloat nbtFloat) { return new NBTTagFloat(nbtFloat.getValue()); } + /** + * Create a NBTTagDouble (NMS Type) from our NBTDouble representation + * @param nbtDouble target NBTDouble + * @return NBTTagDouble copy of our NBTDouble representation + */ private NBTTagDouble asNativeNBTDouble(NBTDouble nbtDouble) { return new NBTTagDouble(nbtDouble.getValue()); } + /** + * Create a NBTTagByteArray (NMS Type) from our NBTByteArray representation + * @param nbtByteArray target NBTByteArray + * @return NBTTagByteArray copy of our NBTByteArray representation + */ private NBTTagByteArray asNativeNBTByteArray(NBTByteArray nbtByteArray) { return new NBTTagByteArray(nbtByteArray.getValues()); } + /** + * Create a NBTTagString (NMS Type) from our NBTString representation + * @param nbtString target NBTString + * @return NBTTagString copy of our NBTString representation + */ private NBTTagString asNativeNBTString(NBTString nbtString) { return new NBTTagString(nbtString.getValue()); } + /** + * Create a NBTTagList (NMS Type) from our NBTList representation + * @param nbtList target NBTList + * @return NBTTagList copy of our NBTList representation + */ private NBTTagList asNativeNBTList(NBTList nbtList) { NBTTagList nbtTagList = new NBTTagList(); nbtList.setValues(nbtList.getValues()); return nbtTagList; } + /** + * Create a NBTTagCompound (NMS Type) from our NBTCompound representation + * @param nbtCompound target NBTCompound + * @return NBTTagCompound copy of our NBTCompound representation + */ private NBTTagCompound asNativeNBTCompound(NBTCompound nbtCompound) { NBTTagCompound nbtTagCompound = new NBTTagCompound(); nbtCompound } + + /** + * Create a NBTTagIntArray (NMS Type) from our NBTIntArray representation + * @param nbtIntArray target NBTIntArray + * @return NBTTagIntArray copy of our NBTIntArray representation + */ + private NBTTagIntArray asNativeNBTIntArray(NBTIntArray nbtIntArray) { + return new NBTTagIntArray(nbtIntArray.getValues()); + } + + /** + * Create a NBTTagLongArray (NMS Type) from our NBTLongArray representation + * @param nbtLongArray target NBTLongArray + * @return NBTTagLongArray copy of our NBTLongArray representation + */ + private NBTTagLongArray asNativeNBTLongArray(NBTLongArray nbtLongArray) { + return new NBTTagLongArray(nbtLongArray.getValues()); + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/PlatformAdapter.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/PlatformAdapter.java index 3a6853e45..0d49ac52e 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/PlatformAdapter.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/adapters/PlatformAdapter.java @@ -8,6 +8,10 @@ public abstract class PlatformAdapter { this.nbtAdapter = nbtAdapter; } + /** + * Get the NBT Adapter for this platform + * @return the platform's NBT adapter + */ public NBTAdapter getNbtAdapter() { return nbtAdapter; } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInteger.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInt.java similarity index 90% rename from mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInteger.java rename to mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInt.java index 2591bba3b..a13ddca1a 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInteger.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInt.java @@ -1,6 +1,6 @@ package com.gmail.nossr50.core.nbt; -public class NBTInteger implements NBTBase { +public class NBTInt implements NBTBase { private String key; private int value;