Actually applied the changes I did to the 1.9 NMS methods into the 1.8..
..and the 1.7 NMS methods. Added a new expression to get the item type from a minecraft ID (e.g minecraft:clock) Little cleanup on the NMS methods.
This commit is contained in:
@@ -14,8 +14,6 @@ public interface NMSInterface {
|
||||
|
||||
public Object parseRawNBT(String rawNBT);
|
||||
|
||||
public int getContentsId(Object nbtList);
|
||||
|
||||
public Object[] getContents(Object nbtList);
|
||||
|
||||
public void addToList(Object nbtList, Object toAdd);
|
||||
@@ -57,4 +55,6 @@ public interface NMSInterface {
|
||||
public Object convertToNBT(String string);
|
||||
|
||||
public String getMCId(ItemStack itemStack);
|
||||
|
||||
public ItemStack getItemFromMcId(String mcId);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,9 @@ import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.NotSerializableException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.StreamCorruptedException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -27,9 +29,11 @@ import ch.njol.skript.Skript;
|
||||
import ch.njol.skript.classes.Changer;
|
||||
import ch.njol.skript.classes.ClassInfo;
|
||||
import ch.njol.skript.classes.Parser;
|
||||
import ch.njol.skript.classes.Serializer;
|
||||
import ch.njol.skript.lang.ParseContext;
|
||||
import ch.njol.skript.registrations.Classes;
|
||||
import ch.njol.util.coll.CollectionUtils;
|
||||
import ch.njol.yggdrasil.Fields;
|
||||
import net.minecraft.server.v1_7_R4.Item;
|
||||
import net.minecraft.server.v1_7_R4.MojangsonParser;
|
||||
import net.minecraft.server.v1_7_R4.NBTBase;
|
||||
@@ -45,6 +49,7 @@ import net.minecraft.server.v1_7_R4.NBTTagShort;
|
||||
import net.minecraft.server.v1_7_R4.NBTTagString;
|
||||
import net.minecraft.server.v1_7_R4.TileEntity;
|
||||
import net.minecraft.server.v1_7_R4.World;
|
||||
import net.minecraft.server.v1_9_R1.MinecraftKey;
|
||||
|
||||
public class NMS_v1_7_R4 implements NMSInterface {
|
||||
|
||||
@@ -89,14 +94,6 @@ public class NMS_v1_7_R4 implements NMSInterface {
|
||||
return parsedNBT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getContentsId(Object nbtList) {
|
||||
if (nbtList instanceof NBTTagList) {
|
||||
return ((NBTTagList) nbtList).d();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getContents(Object nbtList) {
|
||||
if (nbtList instanceof NBTTagList) {
|
||||
@@ -132,7 +129,7 @@ public class NMS_v1_7_R4 implements NMSInterface {
|
||||
@Override
|
||||
public void setIndex(Object nbtList, int index, Object toSet) {
|
||||
if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) {
|
||||
int typeId = getContentsId(nbtList);
|
||||
int typeId = ((NBTTagList) nbtList).d(); //Contents ID
|
||||
NBTBase toSetNBT = null;
|
||||
if (toSet instanceof NBTBase)
|
||||
toSetNBT = (NBTBase) toSet;
|
||||
@@ -149,8 +146,7 @@ public class NMS_v1_7_R4 implements NMSInterface {
|
||||
Skript.warning("Adding mismatching tag types to NBT list");
|
||||
return;
|
||||
}
|
||||
List<Object> actualList = null;
|
||||
actualList = (List<Object>) ReflectionUtils.getField("list", NBTTagList.class, nbtList);
|
||||
List<Object> actualList = (List<Object>) ReflectionUtils.getField("list", NBTTagList.class, nbtList);
|
||||
actualList.set(index, toSetNBT);
|
||||
}
|
||||
}
|
||||
@@ -190,22 +186,15 @@ public class NMS_v1_7_R4 implements NMSInterface {
|
||||
@Override
|
||||
@Nullable
|
||||
public Class<?>[] acceptChange(ChangeMode mode) {
|
||||
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.SET) {
|
||||
return CollectionUtils.array(String[].class, NBTTagCompound[].class);
|
||||
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) {
|
||||
return CollectionUtils.array(String.class, NBTTagCompound.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void change(NBTTagCompound[] NBT, @Nullable Object[] delta, ChangeMode mode) {
|
||||
if (mode == ChangeMode.SET) {
|
||||
if (delta[0] instanceof NBTTagCompound) {
|
||||
NBT[0] = (NBTTagCompound) delta[0];
|
||||
} else {
|
||||
NBTTagCompound parsedNBT = parseRawNBT((String) delta[0]);
|
||||
NBT[0] = parsedNBT;
|
||||
}
|
||||
} else if (mode == ChangeMode.ADD) {
|
||||
if (mode == ChangeMode.ADD) {
|
||||
if (delta[0] instanceof String) {
|
||||
NBTTagCompound parsedNBT = parseRawNBT((String) delta[0]);
|
||||
addToCompound(NBT[0], parsedNBT);
|
||||
@@ -233,9 +222,6 @@ public class NMS_v1_7_R4 implements NMSInterface {
|
||||
if (rawNBT.startsWith("nbt:{") && rawNBT.endsWith("}")) {
|
||||
rawNBT.substring(4);
|
||||
NBTTagCompound NBT = parseRawNBT(rawNBT);
|
||||
if (NBT.toString().equals("{}")) {
|
||||
return null;
|
||||
}
|
||||
return NBT;
|
||||
}
|
||||
return null;
|
||||
@@ -248,7 +234,7 @@ public class NMS_v1_7_R4 implements NMSInterface {
|
||||
|
||||
@Override
|
||||
public String toVariableNameString(NBTTagCompound compound) {
|
||||
return "nbt:" + compound.toString();
|
||||
return compound.toString();
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -262,53 +248,22 @@ public class NMS_v1_7_R4 implements NMSInterface {
|
||||
@Override
|
||||
@Nullable
|
||||
public Class<?>[] acceptChange(ChangeMode mode) {
|
||||
if (mode == ChangeMode.ADD || mode == ChangeMode.SET || mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
|
||||
return CollectionUtils.array(Float[].class, Double[].class, String[].class, NBTTagCompound[].class, Integer[].class, NBTTagList[].class);
|
||||
if (mode == ChangeMode.ADD) {
|
||||
return CollectionUtils.array(Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, String.class, NBTBase.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void change(NBTTagList[] nbtList, @Nullable Object[] delta, ChangeMode mode) {
|
||||
int typeId = 0;
|
||||
if (delta instanceof Float[]) {
|
||||
typeId = 5;
|
||||
} else if (delta instanceof Double[]) {
|
||||
typeId = 6;
|
||||
} else if (delta instanceof String[]) {
|
||||
typeId = 8;
|
||||
} else if (delta instanceof NBTTagList[]) {
|
||||
typeId = 9;
|
||||
} else if (delta instanceof NBTTagCompound[]) {
|
||||
typeId = 10;
|
||||
} else if (delta instanceof Integer[]) {
|
||||
typeId = 11;
|
||||
} else {
|
||||
if (delta.length == 0)
|
||||
return;
|
||||
}
|
||||
if (mode == ChangeMode.SET) {
|
||||
if (typeId == 9)
|
||||
nbtList[0] = (NBTTagList) delta[0];
|
||||
} else if (mode == ChangeMode.ADD) {
|
||||
if (getContentsId(nbtList[0]) == typeId) {
|
||||
if (typeId == 5) {
|
||||
NBTTagFloat floatTag = new NBTTagFloat((float) delta[0]);
|
||||
addToList(nbtList[0], floatTag);
|
||||
} else if (typeId == 6) {
|
||||
NBTTagDouble doubleTag = new NBTTagDouble((double) delta[0]);
|
||||
addToList(nbtList[0], doubleTag);
|
||||
} else if (typeId == 8) {
|
||||
NBTTagString stringTag = new NBTTagString((String) delta [0]);
|
||||
addToList(nbtList[0], stringTag);
|
||||
} else if (typeId == 10) {
|
||||
addToList(nbtList[0], delta[0]);
|
||||
} else if (typeId == 11) {
|
||||
NBTTagInt intTag = new NBTTagInt((int) delta[0]);
|
||||
addToList(nbtList[0], intTag);
|
||||
}
|
||||
}
|
||||
} else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
|
||||
nbtList[0] = new NBTTagList();
|
||||
if (delta[0] instanceof Number) {
|
||||
addToList(nbtList, convertToNBT((Number) delta[0]));
|
||||
} else if (delta[0] instanceof String) {
|
||||
addToList(nbtList, convertToNBT((String) delta[0]));
|
||||
} else if (delta[0] instanceof NBTBase) {
|
||||
addToList(nbtList, delta[0]);
|
||||
}
|
||||
}
|
||||
}).parser(new Parser<NBTTagList>() {
|
||||
@@ -320,7 +275,12 @@ public class NMS_v1_7_R4 implements NMSInterface {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public NBTTagList parse(String ignored, ParseContext context) {
|
||||
public NBTTagList parse(String listString, ParseContext context) {
|
||||
if (listString.startsWith("[") && listString.endsWith("]")) {
|
||||
NBTTagCompound tempNBT = parseRawNBT("{SkStuffIsCool:[0:" + listString.substring(1) + "}");
|
||||
NBTTagList parsedList = (NBTTagList) tempNBT.get("SkStuffIsCool");
|
||||
return parsedList;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -333,6 +293,45 @@ public class NMS_v1_7_R4 implements NMSInterface {
|
||||
public String toVariableNameString(NBTTagList nbtList) {
|
||||
return nbtList.toString();
|
||||
}
|
||||
}).serializer(new Serializer<NBTTagList>() {
|
||||
|
||||
@Override
|
||||
public Fields serialize(NBTTagList nbtList) throws NotSerializableException {
|
||||
Fields f = new Fields();
|
||||
f.putObject("asString", nbtList.toString());
|
||||
return f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserialize(NBTTagList nbtList, Fields f) throws StreamCorruptedException, NotSerializableException {
|
||||
assert false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canBeInstantiated() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NBTTagList deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException {
|
||||
String s = fields.getObject("asString", String.class);
|
||||
NBTTagCompound tempNBT = parseRawNBT("{SkStuffIsCool:" + s + "}");
|
||||
NBTTagList nbtList = (NBTTagList) tempNBT.get("SkStuffIsCool");
|
||||
return nbtList;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public NBTTagList deserialize(String s) {
|
||||
NBTTagCompound tempNBT = parseRawNBT("{SkStuffIsCool:" + s + "}");
|
||||
NBTTagList nbtList = (NBTTagList) tempNBT.get("SkStuffIsCool");
|
||||
return nbtList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mustSyncDeserialization() {
|
||||
return true;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -357,13 +356,9 @@ public class NMS_v1_7_R4 implements NMSInterface {
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getItemNBT(ItemStack itemStack) {
|
||||
if (itemStack.getType() == Material.AIR)
|
||||
return null;
|
||||
NBTTagCompound NBT = new NBTTagCompound();
|
||||
net.minecraft.server.v1_7_R4.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
|
||||
NBT = nmsItem.getTag();
|
||||
if (NBT == null || NBT.toString().equals("{}")) //Null or empty.
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR)
|
||||
return null;
|
||||
NBTTagCompound NBT = CraftItemStack.asNMSCopy(itemStack).getTag();
|
||||
return NBT;
|
||||
}
|
||||
|
||||
@@ -390,17 +385,21 @@ public class NMS_v1_7_R4 implements NMSInterface {
|
||||
|
||||
@Override
|
||||
public ItemStack getItemWithNBT(ItemStack itemStack, Object compound) {
|
||||
if (compound instanceof NBTTagCompound) {
|
||||
if (itemStack.getType() == Material.AIR || itemStack == null)
|
||||
net.minecraft.server.v1_7_R4.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
|
||||
if (compound instanceof NBTTagCompound && itemStack != null) {
|
||||
if (itemStack.getType() == Material.AIR)
|
||||
return null;
|
||||
if (compound == null || compound.toString().equals("{}"))
|
||||
if (((NBTTagCompound) compound).isEmpty())
|
||||
return itemStack;
|
||||
net.minecraft.server.v1_7_R4.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
|
||||
nmsItem.setTag((NBTTagCompound) compound);
|
||||
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
|
||||
ItemStack newItem = CraftItemStack.asBukkitCopy(nmsItem);
|
||||
return newItem;
|
||||
} else if (compound == null) {
|
||||
nmsItem.setTag(null);
|
||||
ItemStack newItem = CraftItemStack.asBukkitCopy(nmsItem);
|
||||
return newItem;
|
||||
}
|
||||
return null;
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -486,4 +485,11 @@ public class NMS_v1_7_R4 implements NMSInterface {
|
||||
String test = Item.REGISTRY.c(nmsItem.getItem());
|
||||
return test;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemFromMcId(String mcId) {
|
||||
MinecraftKey mcKey = new MinecraftKey(mcId);
|
||||
Item nmsItem = (Item) Item.REGISTRY.get(mcKey);
|
||||
return CraftItemStack.asNewCraftStack(nmsItem);
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,8 @@ import ch.njol.util.coll.CollectionUtils;
|
||||
import ch.njol.yggdrasil.Fields;
|
||||
import net.minecraft.server.v1_8_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_8_R1.EntityInsentient;
|
||||
import net.minecraft.server.v1_8_R1.Item;
|
||||
import net.minecraft.server.v1_8_R1.MinecraftKey;
|
||||
import net.minecraft.server.v1_8_R1.MojangsonParser;
|
||||
import net.minecraft.server.v1_8_R1.NBTBase;
|
||||
import net.minecraft.server.v1_8_R1.NBTCompressedStreamTools;
|
||||
@@ -48,8 +50,6 @@ import net.minecraft.server.v1_8_R1.PathfinderGoal;
|
||||
import net.minecraft.server.v1_8_R1.PathfinderGoalSelector;
|
||||
import net.minecraft.server.v1_8_R1.TileEntity;
|
||||
import net.minecraft.server.v1_8_R1.World;
|
||||
import net.minecraft.server.v1_8_R1.Item;
|
||||
import net.minecraft.server.v1_8_R1.MinecraftKey;
|
||||
|
||||
public class NMS_v1_8_R1 implements NMSInterface {
|
||||
|
||||
@@ -76,14 +76,6 @@ public class NMS_v1_8_R1 implements NMSInterface {
|
||||
return parsedNBT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getContentsId(Object nbtList) {
|
||||
if (nbtList instanceof NBTTagList) {
|
||||
return ((NBTTagList) nbtList).f();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getContents(Object nbtList) {
|
||||
if (nbtList instanceof NBTTagList) {
|
||||
@@ -143,7 +135,7 @@ public class NMS_v1_8_R1 implements NMSInterface {
|
||||
return ((NBTTagDouble) value).g(); //Double inside a NBTNumber
|
||||
} else if (value instanceof NBTTagString) {
|
||||
return ((NBTTagString) value).a_(); //String inside the NBTTagString
|
||||
} else if (value instanceof NBTTagList || value instanceof NBTTagCompound) {
|
||||
} else if (value instanceof NBTBase) {
|
||||
return value; //No need to convert anything, these are registered by the addon.
|
||||
}
|
||||
}
|
||||
@@ -201,26 +193,17 @@ public class NMS_v1_8_R1 implements NMSInterface {
|
||||
@Override
|
||||
@Nullable
|
||||
public Class<?>[] acceptChange(ChangeMode mode) {
|
||||
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.SET) {
|
||||
return CollectionUtils.array(String[].class, NBTTagCompound[].class);
|
||||
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) {
|
||||
return CollectionUtils.array(String.class, NBTTagCompound.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void change(NBTTagCompound[] NBT, @Nullable Object[] delta, ChangeMode mode) {
|
||||
if (mode == ChangeMode.SET) {
|
||||
if (delta[0] instanceof NBTTagCompound) {
|
||||
NBT[0] = (NBTTagCompound) delta[0];
|
||||
} else {
|
||||
NBTTagCompound parsedNBT = null;
|
||||
parsedNBT = parseRawNBT((String) delta[0]);
|
||||
NBT[0] = parsedNBT;
|
||||
}
|
||||
} else if (mode == ChangeMode.ADD) {
|
||||
if (mode == ChangeMode.ADD) {
|
||||
if (delta[0] instanceof String) {
|
||||
NBTTagCompound parsedNBT = null;
|
||||
parsedNBT = parseRawNBT((String) delta[0]);
|
||||
NBTTagCompound parsedNBT = parseRawNBT((String) delta[0]);
|
||||
addToCompound(NBT[0], parsedNBT);
|
||||
} else {
|
||||
addToCompound(NBT[0], delta[0]);
|
||||
@@ -258,7 +241,7 @@ public class NMS_v1_8_R1 implements NMSInterface {
|
||||
|
||||
@Override
|
||||
public String toVariableNameString(NBTTagCompound compound) {
|
||||
return "nbt:" + compound.toString();
|
||||
return compound.toString();
|
||||
}
|
||||
}).serializer(new Serializer<NBTTagCompound>() {
|
||||
|
||||
@@ -282,16 +265,14 @@ public class NMS_v1_8_R1 implements NMSInterface {
|
||||
@Override
|
||||
protected NBTTagCompound deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException {
|
||||
String s = fields.getObject("asString", String.class);
|
||||
NBTTagCompound compound = null;
|
||||
compound = parseRawNBT(s);
|
||||
NBTTagCompound compound = parseRawNBT(s);
|
||||
return compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public NBTTagCompound deserialize(String s) {
|
||||
NBTTagCompound compound = null;
|
||||
compound = parseRawNBT(s);
|
||||
NBTTagCompound compound = parseRawNBT(s);
|
||||
return compound;
|
||||
}
|
||||
|
||||
@@ -312,49 +293,21 @@ public class NMS_v1_8_R1 implements NMSInterface {
|
||||
@Nullable
|
||||
public Class<?>[] acceptChange(ChangeMode mode) {
|
||||
if (mode == ChangeMode.ADD || mode == ChangeMode.SET || mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
|
||||
return CollectionUtils.array(Float[].class, Double[].class, String[].class, NBTTagCompound[].class, Integer[].class, NBTTagList[].class);
|
||||
return CollectionUtils.array(Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, String.class, NBTBase.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void change(NBTTagList[] nbtList, @Nullable Object[] delta, ChangeMode mode) {
|
||||
int typeId = 0;
|
||||
if (delta instanceof Byte[]) {
|
||||
typeId = 1;
|
||||
} else if (delta instanceof Short[]) {
|
||||
typeId = 2;
|
||||
} else if (delta instanceof Integer[]) {
|
||||
typeId = 3;
|
||||
} else if (delta instanceof Long[]) {
|
||||
typeId = 4;
|
||||
} else if (delta instanceof Float[]) {
|
||||
typeId = 5;
|
||||
} else if (delta instanceof Double[]) {
|
||||
typeId = 6;
|
||||
} else if (delta instanceof String[]) {
|
||||
typeId = 8;
|
||||
} else if (delta instanceof NBTTagList[]) {
|
||||
typeId = 9;
|
||||
} else if (delta instanceof NBTTagCompound[]) {
|
||||
typeId = 10;
|
||||
} else {
|
||||
if (delta.length == 0)
|
||||
return;
|
||||
}
|
||||
if (mode == ChangeMode.SET) {
|
||||
if (typeId == 9)
|
||||
nbtList[0] = (NBTTagList) delta[0];
|
||||
} else if (mode == ChangeMode.ADD) {
|
||||
if (getContentsId(nbtList[0]) == typeId) {
|
||||
if (delta[0] instanceof Number)
|
||||
addToList(nbtList, convertToNBT((Number) delta[0]));
|
||||
else if (delta[0] instanceof String)
|
||||
addToList(nbtList, convertToNBT((String) delta[0]));
|
||||
else if (delta[0] instanceof NBTTagCompound || delta[0] instanceof NBTTagList)
|
||||
addToList(nbtList, delta[0]);
|
||||
}
|
||||
} else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
|
||||
nbtList[0] = new NBTTagList();
|
||||
if (delta[0] instanceof Number) {
|
||||
addToList(nbtList, convertToNBT((Number) delta[0]));
|
||||
} else if (delta[0] instanceof String) {
|
||||
addToList(nbtList, convertToNBT((String) delta[0]));
|
||||
} else if (delta[0] instanceof NBTBase) {
|
||||
addToList(nbtList, delta[0]);
|
||||
}
|
||||
}
|
||||
}).parser(new Parser<NBTTagList>() {
|
||||
@@ -368,8 +321,7 @@ public class NMS_v1_8_R1 implements NMSInterface {
|
||||
@Nullable
|
||||
public NBTTagList parse(String listString, ParseContext context) {
|
||||
if (listString.startsWith("[") && listString.endsWith("]")) {
|
||||
NBTTagCompound tempNBT = null;
|
||||
tempNBT = parseRawNBT("{SkStuffIsCool:[0:" + listString.substring(1) + "}");
|
||||
NBTTagCompound tempNBT = parseRawNBT("{SkStuffIsCool:[0:" + listString.substring(1) + "}");
|
||||
NBTTagList parsedList = (NBTTagList) tempNBT.get("SkStuffIsCool");
|
||||
return parsedList;
|
||||
}
|
||||
@@ -407,8 +359,7 @@ public class NMS_v1_8_R1 implements NMSInterface {
|
||||
@Override
|
||||
protected NBTTagList deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException {
|
||||
String s = fields.getObject("asString", String.class);
|
||||
NBTTagCompound tempNBT = null;
|
||||
tempNBT = parseRawNBT("{SkStuffIsCool:" + s + "}");
|
||||
NBTTagCompound tempNBT = parseRawNBT("{SkStuffIsCool:" + s + "}");
|
||||
NBTTagList nbtList = (NBTTagList) tempNBT.get("SkStuffIsCool");
|
||||
return nbtList;
|
||||
}
|
||||
@@ -416,8 +367,7 @@ public class NMS_v1_8_R1 implements NMSInterface {
|
||||
@Override
|
||||
@Nullable
|
||||
public NBTTagList deserialize(String s) {
|
||||
NBTTagCompound tempNBT = null;
|
||||
tempNBT = parseRawNBT("{SkStuffIsCool:" + s + "}");
|
||||
NBTTagCompound tempNBT = parseRawNBT("{SkStuffIsCool:" + s + "}");
|
||||
NBTTagList nbtList = (NBTTagList) tempNBT.get("SkStuffIsCool");
|
||||
return nbtList;
|
||||
}
|
||||
@@ -450,10 +400,10 @@ public class NMS_v1_8_R1 implements NMSInterface {
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getItemNBT(ItemStack itemStack) {
|
||||
if (itemStack.getType() == Material.AIR)
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR)
|
||||
return null;
|
||||
NBTTagCompound itemNBT = CraftItemStack.asNMSCopy(itemStack).getTag();
|
||||
if (String.valueOf(itemNBT).equals("{}"))
|
||||
if (itemNBT.isEmpty())
|
||||
itemNBT = null;
|
||||
return itemNBT;
|
||||
}
|
||||
@@ -569,4 +519,11 @@ public class NMS_v1_8_R1 implements NMSInterface {
|
||||
MinecraftKey mcKey = (MinecraftKey) Item.REGISTRY.c(nmsItem.getItem());
|
||||
return mcKey.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemFromMcId(String mcId) {
|
||||
MinecraftKey mcKey = new MinecraftKey(mcId);
|
||||
Item nmsItem = (Item) Item.REGISTRY.get(mcKey);
|
||||
return CraftItemStack.asNewCraftStack(nmsItem);
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,8 @@ import ch.njol.util.coll.CollectionUtils;
|
||||
import ch.njol.yggdrasil.Fields;
|
||||
import net.minecraft.server.v1_8_R2.BlockPosition;
|
||||
import net.minecraft.server.v1_8_R2.EntityInsentient;
|
||||
import net.minecraft.server.v1_8_R2.Item;
|
||||
import net.minecraft.server.v1_8_R2.MinecraftKey;
|
||||
import net.minecraft.server.v1_8_R2.MojangsonParseException;
|
||||
import net.minecraft.server.v1_8_R2.MojangsonParser;
|
||||
import net.minecraft.server.v1_8_R2.NBTBase;
|
||||
@@ -50,8 +52,6 @@ import net.minecraft.server.v1_8_R2.PathfinderGoal;
|
||||
import net.minecraft.server.v1_8_R2.PathfinderGoalSelector;
|
||||
import net.minecraft.server.v1_8_R2.TileEntity;
|
||||
import net.minecraft.server.v1_8_R2.World;
|
||||
import net.minecraft.server.v1_8_R2.Item;
|
||||
import net.minecraft.server.v1_8_R2.MinecraftKey;
|
||||
|
||||
public class NMS_v1_8_R2 implements NMSInterface {
|
||||
|
||||
@@ -78,18 +78,11 @@ public class NMS_v1_8_R2 implements NMSInterface {
|
||||
parsedNBT = MojangsonParser.parse(rawNBT);
|
||||
} catch (MojangsonParseException ex) {
|
||||
Skript.warning("Error when parsing NBT - " + ex.getMessage());
|
||||
return null;
|
||||
}
|
||||
return parsedNBT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getContentsId(Object nbtList) {
|
||||
if (nbtList instanceof NBTTagList) {
|
||||
return ((NBTTagList) nbtList).f();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getContents(Object nbtList) {
|
||||
if (nbtList instanceof NBTTagList) {
|
||||
@@ -207,26 +200,17 @@ public class NMS_v1_8_R2 implements NMSInterface {
|
||||
@Override
|
||||
@Nullable
|
||||
public Class<?>[] acceptChange(ChangeMode mode) {
|
||||
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.SET) {
|
||||
return CollectionUtils.array(String[].class, NBTTagCompound[].class);
|
||||
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) {
|
||||
return CollectionUtils.array(String.class, NBTTagCompound.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void change(NBTTagCompound[] NBT, @Nullable Object[] delta, ChangeMode mode) {
|
||||
if (mode == ChangeMode.SET) {
|
||||
if (delta[0] instanceof NBTTagCompound) {
|
||||
NBT[0] = (NBTTagCompound) delta[0];
|
||||
} else {
|
||||
NBTTagCompound parsedNBT = null;
|
||||
parsedNBT = parseRawNBT((String) delta[0]);
|
||||
NBT[0] = parsedNBT;
|
||||
}
|
||||
} else if (mode == ChangeMode.ADD) {
|
||||
if (mode == ChangeMode.ADD) {
|
||||
if (delta[0] instanceof String) {
|
||||
NBTTagCompound parsedNBT = null;
|
||||
parsedNBT = parseRawNBT((String) delta[0]);
|
||||
NBTTagCompound parsedNBT = parseRawNBT((String) delta[0]);
|
||||
addToCompound(NBT[0], parsedNBT);
|
||||
} else {
|
||||
addToCompound(NBT[0], delta[0]);
|
||||
@@ -250,8 +234,7 @@ public class NMS_v1_8_R2 implements NMSInterface {
|
||||
@Nullable
|
||||
public NBTTagCompound parse(String rawNBT, ParseContext context) {
|
||||
if (rawNBT.startsWith("nbt:{") && rawNBT.endsWith("}")) {
|
||||
NBTTagCompound NBT = null;
|
||||
NBT = parseRawNBT(rawNBT.substring(4));
|
||||
NBTTagCompound NBT = parseRawNBT(rawNBT.substring(4));
|
||||
return NBT;
|
||||
}
|
||||
return null;
|
||||
@@ -264,7 +247,7 @@ public class NMS_v1_8_R2 implements NMSInterface {
|
||||
|
||||
@Override
|
||||
public String toVariableNameString(NBTTagCompound compound) {
|
||||
return "nbt:" + compound.toString();
|
||||
return compound.toString();
|
||||
}
|
||||
}).serializer(new Serializer<NBTTagCompound>() {
|
||||
|
||||
@@ -288,16 +271,14 @@ public class NMS_v1_8_R2 implements NMSInterface {
|
||||
@Override
|
||||
protected NBTTagCompound deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException {
|
||||
String s = fields.getObject("asString", String.class);
|
||||
NBTTagCompound compound = null;
|
||||
compound = parseRawNBT(s);
|
||||
NBTTagCompound compound = parseRawNBT(s);
|
||||
return compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public NBTTagCompound deserialize(String s) {
|
||||
NBTTagCompound compound = null;
|
||||
compound = parseRawNBT(s);
|
||||
NBTTagCompound compound = parseRawNBT(s);
|
||||
return compound;
|
||||
}
|
||||
|
||||
@@ -317,50 +298,22 @@ public class NMS_v1_8_R2 implements NMSInterface {
|
||||
@Override
|
||||
@Nullable
|
||||
public Class<?>[] acceptChange(ChangeMode mode) {
|
||||
if (mode == ChangeMode.ADD || mode == ChangeMode.SET || mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
|
||||
return CollectionUtils.array(Float[].class, Double[].class, String[].class, NBTTagCompound[].class, Integer[].class, NBTTagList[].class);
|
||||
if (mode == ChangeMode.ADD) {
|
||||
return CollectionUtils.array(Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, String.class, NBTBase.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void change(NBTTagList[] nbtList, @Nullable Object[] delta, ChangeMode mode) {
|
||||
int typeId = 0;
|
||||
if (delta instanceof Byte[]) {
|
||||
typeId = 1;
|
||||
} else if (delta instanceof Short[]) {
|
||||
typeId = 2;
|
||||
} else if (delta instanceof Integer[]) {
|
||||
typeId = 3;
|
||||
} else if (delta instanceof Long[]) {
|
||||
typeId = 4;
|
||||
} else if (delta instanceof Float[]) {
|
||||
typeId = 5;
|
||||
} else if (delta instanceof Double[]) {
|
||||
typeId = 6;
|
||||
} else if (delta instanceof String[]) {
|
||||
typeId = 8;
|
||||
} else if (delta instanceof NBTTagList[]) {
|
||||
typeId = 9;
|
||||
} else if (delta instanceof NBTTagCompound[]) {
|
||||
typeId = 10;
|
||||
} else {
|
||||
if (delta.length == 0)
|
||||
return;
|
||||
}
|
||||
if (mode == ChangeMode.SET) {
|
||||
if (typeId == 9)
|
||||
nbtList[0] = (NBTTagList) delta[0];
|
||||
} else if (mode == ChangeMode.ADD) {
|
||||
if (getContentsId(nbtList[0]) == typeId) {
|
||||
if (delta[0] instanceof Number)
|
||||
addToList(nbtList, convertToNBT((Number) delta[0]));
|
||||
else if (delta[0] instanceof String)
|
||||
addToList(nbtList, convertToNBT((String) delta[0]));
|
||||
else if (delta[0] instanceof NBTTagCompound || delta[0] instanceof NBTTagList)
|
||||
addToList(nbtList, delta[0]);
|
||||
}
|
||||
} else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
|
||||
nbtList[0] = new NBTTagList();
|
||||
if (delta[0] instanceof Number) {
|
||||
addToList(nbtList, convertToNBT((Number) delta[0]));
|
||||
} else if (delta[0] instanceof String) {
|
||||
addToList(nbtList, convertToNBT((String) delta[0]));
|
||||
} else if (delta[0] instanceof NBTBase) {
|
||||
addToList(nbtList, delta[0]);
|
||||
}
|
||||
}
|
||||
}).parser(new Parser<NBTTagList>() {
|
||||
@@ -374,8 +327,7 @@ public class NMS_v1_8_R2 implements NMSInterface {
|
||||
@Nullable
|
||||
public NBTTagList parse(String listString, ParseContext context) {
|
||||
if (listString.startsWith("[") && listString.endsWith("]")) {
|
||||
NBTTagCompound tempNBT = null;
|
||||
tempNBT = parseRawNBT("{SkStuffIsCool:[0:" + listString.substring(1) + "}");
|
||||
NBTTagCompound tempNBT = parseRawNBT("{SkStuffIsCool:[0:" + listString.substring(1) + "}");
|
||||
NBTTagList parsedList = (NBTTagList) tempNBT.get("SkStuffIsCool");
|
||||
return parsedList;
|
||||
}
|
||||
@@ -413,8 +365,7 @@ public class NMS_v1_8_R2 implements NMSInterface {
|
||||
@Override
|
||||
protected NBTTagList deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException {
|
||||
String s = fields.getObject("asString", String.class);
|
||||
NBTTagCompound tempNBT = null;
|
||||
tempNBT = parseRawNBT("{SkStuffIsCool:" + s + "}");
|
||||
NBTTagCompound tempNBT = parseRawNBT("{SkStuffIsCool:" + s + "}");
|
||||
NBTTagList nbtList = (NBTTagList) tempNBT.get("SkStuffIsCool");
|
||||
return nbtList;
|
||||
}
|
||||
@@ -422,8 +373,7 @@ public class NMS_v1_8_R2 implements NMSInterface {
|
||||
@Override
|
||||
@Nullable
|
||||
public NBTTagList deserialize(String s) {
|
||||
NBTTagCompound tempNBT = null;
|
||||
tempNBT = parseRawNBT("{SkStuffIsCool:" + s + "}");
|
||||
NBTTagCompound tempNBT = parseRawNBT("{SkStuffIsCool:" + s + "}");
|
||||
NBTTagList nbtList = (NBTTagList) tempNBT.get("SkStuffIsCool");
|
||||
return nbtList;
|
||||
}
|
||||
@@ -456,10 +406,10 @@ public class NMS_v1_8_R2 implements NMSInterface {
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getItemNBT(ItemStack itemStack) {
|
||||
if (itemStack.getType() == Material.AIR)
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR)
|
||||
return null;
|
||||
NBTTagCompound itemNBT = CraftItemStack.asNMSCopy(itemStack).getTag();
|
||||
if (String.valueOf(itemNBT).equals("{}"))
|
||||
if (itemNBT.isEmpty())
|
||||
itemNBT = null;
|
||||
return itemNBT;
|
||||
}
|
||||
@@ -575,4 +525,11 @@ public class NMS_v1_8_R2 implements NMSInterface {
|
||||
MinecraftKey mcKey = Item.REGISTRY.c(nmsItem.getItem());
|
||||
return mcKey.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemFromMcId(String mcId) {
|
||||
MinecraftKey mcKey = new MinecraftKey(mcId);
|
||||
Item nmsItem = (Item) Item.REGISTRY.get(mcKey);
|
||||
return CraftItemStack.asNewCraftStack(nmsItem);
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,8 @@ import ch.njol.util.coll.CollectionUtils;
|
||||
import ch.njol.yggdrasil.Fields;
|
||||
import net.minecraft.server.v1_8_R3.BlockPosition;
|
||||
import net.minecraft.server.v1_8_R3.EntityInsentient;
|
||||
import net.minecraft.server.v1_8_R3.Item;
|
||||
import net.minecraft.server.v1_8_R3.MinecraftKey;
|
||||
import net.minecraft.server.v1_8_R3.MojangsonParseException;
|
||||
import net.minecraft.server.v1_8_R3.MojangsonParser;
|
||||
import net.minecraft.server.v1_8_R3.NBTBase;
|
||||
@@ -50,8 +52,6 @@ import net.minecraft.server.v1_8_R3.PathfinderGoal;
|
||||
import net.minecraft.server.v1_8_R3.PathfinderGoalSelector;
|
||||
import net.minecraft.server.v1_8_R3.TileEntity;
|
||||
import net.minecraft.server.v1_8_R3.World;
|
||||
import net.minecraft.server.v1_8_R3.Item;
|
||||
import net.minecraft.server.v1_8_R3.MinecraftKey;
|
||||
|
||||
public class NMS_v1_8_R3 implements NMSInterface {
|
||||
|
||||
@@ -78,18 +78,11 @@ public class NMS_v1_8_R3 implements NMSInterface {
|
||||
parsedNBT = MojangsonParser.parse(rawNBT);
|
||||
} catch (MojangsonParseException ex) {
|
||||
Skript.warning("Error when parsing NBT - " + ex.getMessage());
|
||||
return null;
|
||||
}
|
||||
return parsedNBT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getContentsId(Object nbtList) {
|
||||
if (nbtList instanceof NBTTagList) {
|
||||
return ((NBTTagList) nbtList).f();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getContents(Object nbtList) {
|
||||
if (nbtList instanceof NBTTagList) {
|
||||
@@ -149,8 +142,8 @@ public class NMS_v1_8_R3 implements NMSInterface {
|
||||
return ((NBTTagDouble) value).g(); //Double inside a NBTNumber
|
||||
} else if (value instanceof NBTTagString) {
|
||||
return ((NBTTagString) value).a_(); //String inside the NBTTagString
|
||||
} else if (value instanceof NBTTagList || value instanceof NBTTagCompound) {
|
||||
return value; //No need to convert anything, these are registered by the addon.
|
||||
} else if (value instanceof NBTBase) {
|
||||
return value; //No need to convert this.
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -207,26 +200,17 @@ public class NMS_v1_8_R3 implements NMSInterface {
|
||||
@Override
|
||||
@Nullable
|
||||
public Class<?>[] acceptChange(ChangeMode mode) {
|
||||
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.SET) {
|
||||
return CollectionUtils.array(String[].class, NBTTagCompound[].class);
|
||||
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) {
|
||||
return CollectionUtils.array(String.class, NBTTagCompound.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void change(NBTTagCompound[] NBT, @Nullable Object[] delta, ChangeMode mode) {
|
||||
if (mode == ChangeMode.SET) {
|
||||
if (delta[0] instanceof NBTTagCompound) {
|
||||
NBT[0] = (NBTTagCompound) delta[0];
|
||||
} else {
|
||||
NBTTagCompound parsedNBT = null;
|
||||
parsedNBT = parseRawNBT((String) delta[0]);
|
||||
NBT[0] = parsedNBT;
|
||||
}
|
||||
} else if (mode == ChangeMode.ADD) {
|
||||
if (mode == ChangeMode.ADD) {
|
||||
if (delta[0] instanceof String) {
|
||||
NBTTagCompound parsedNBT = null;
|
||||
parsedNBT = parseRawNBT((String) delta[0]);
|
||||
NBTTagCompound parsedNBT = parseRawNBT((String) delta[0]);
|
||||
addToCompound(NBT[0], parsedNBT);
|
||||
} else {
|
||||
addToCompound(NBT[0], delta[0]);
|
||||
@@ -250,8 +234,7 @@ public class NMS_v1_8_R3 implements NMSInterface {
|
||||
@Nullable
|
||||
public NBTTagCompound parse(String rawNBT, ParseContext context) {
|
||||
if (rawNBT.startsWith("nbt:{") && rawNBT.endsWith("}")) {
|
||||
NBTTagCompound NBT = null;
|
||||
NBT = parseRawNBT(rawNBT.substring(4));
|
||||
NBTTagCompound NBT = parseRawNBT(rawNBT.substring(4));
|
||||
return NBT;
|
||||
}
|
||||
return null;
|
||||
@@ -264,7 +247,7 @@ public class NMS_v1_8_R3 implements NMSInterface {
|
||||
|
||||
@Override
|
||||
public String toVariableNameString(NBTTagCompound compound) {
|
||||
return "nbt:" + compound.toString();
|
||||
return compound.toString();
|
||||
}
|
||||
}).serializer(new Serializer<NBTTagCompound>() {
|
||||
|
||||
@@ -288,16 +271,14 @@ public class NMS_v1_8_R3 implements NMSInterface {
|
||||
@Override
|
||||
protected NBTTagCompound deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException {
|
||||
String s = fields.getObject("asString", String.class);
|
||||
NBTTagCompound compound = null;
|
||||
compound = parseRawNBT(s);
|
||||
NBTTagCompound compound = parseRawNBT(s);
|
||||
return compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public NBTTagCompound deserialize(String s) {
|
||||
NBTTagCompound compound = null;
|
||||
compound = parseRawNBT(s);
|
||||
NBTTagCompound compound = parseRawNBT(s);
|
||||
return compound;
|
||||
}
|
||||
|
||||
@@ -317,50 +298,22 @@ public class NMS_v1_8_R3 implements NMSInterface {
|
||||
@Override
|
||||
@Nullable
|
||||
public Class<?>[] acceptChange(ChangeMode mode) {
|
||||
if (mode == ChangeMode.ADD || mode == ChangeMode.SET || mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
|
||||
return CollectionUtils.array(Float[].class, Double[].class, String[].class, NBTTagCompound[].class, Integer[].class, NBTTagList[].class);
|
||||
if (mode == ChangeMode.ADD) {
|
||||
return CollectionUtils.array(Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, String.class, NBTTagCompound.class, NBTTagList.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void change(NBTTagList[] nbtList, @Nullable Object[] delta, ChangeMode mode) {
|
||||
int typeId = 0;
|
||||
if (delta instanceof Byte[]) {
|
||||
typeId = 1;
|
||||
} else if (delta instanceof Short[]) {
|
||||
typeId = 2;
|
||||
} else if (delta instanceof Integer[]) {
|
||||
typeId = 3;
|
||||
} else if (delta instanceof Long[]) {
|
||||
typeId = 4;
|
||||
} else if (delta instanceof Float[]) {
|
||||
typeId = 5;
|
||||
} else if (delta instanceof Double[]) {
|
||||
typeId = 6;
|
||||
} else if (delta instanceof String[]) {
|
||||
typeId = 8;
|
||||
} else if (delta instanceof NBTTagList[]) {
|
||||
typeId = 9;
|
||||
} else if (delta instanceof NBTTagCompound[]) {
|
||||
typeId = 10;
|
||||
} else {
|
||||
if (delta.length == 0)
|
||||
return;
|
||||
}
|
||||
if (mode == ChangeMode.SET) {
|
||||
if (typeId == 9)
|
||||
nbtList[0] = (NBTTagList) delta[0];
|
||||
} else if (mode == ChangeMode.ADD) {
|
||||
if (getContentsId(nbtList[0]) == typeId) {
|
||||
if (delta[0] instanceof Number)
|
||||
addToList(nbtList, convertToNBT((Number) delta[0]));
|
||||
else if (delta[0] instanceof String)
|
||||
addToList(nbtList, convertToNBT((String) delta[0]));
|
||||
else if (delta[0] instanceof NBTTagCompound || delta[0] instanceof NBTTagList)
|
||||
addToList(nbtList, delta[0]);
|
||||
}
|
||||
} else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
|
||||
nbtList[0] = new NBTTagList();
|
||||
if (delta[0] instanceof Number) {
|
||||
addToList(nbtList, convertToNBT((Number) delta[0]));
|
||||
} else if (delta[0] instanceof String) {
|
||||
addToList(nbtList, convertToNBT((String) delta[0]));
|
||||
} else if (delta[0] instanceof NBTBase) {
|
||||
addToList(nbtList, delta[0]);
|
||||
}
|
||||
}
|
||||
}).parser(new Parser<NBTTagList>() {
|
||||
@@ -374,8 +327,7 @@ public class NMS_v1_8_R3 implements NMSInterface {
|
||||
@Nullable
|
||||
public NBTTagList parse(String listString, ParseContext context) {
|
||||
if (listString.startsWith("[") && listString.endsWith("]")) {
|
||||
NBTTagCompound tempNBT = null;
|
||||
tempNBT = parseRawNBT("{SkStuffIsCool:[0:" + listString.substring(1) + "}");
|
||||
NBTTagCompound tempNBT = parseRawNBT("{SkStuffIsCool:[0:" + listString.substring(1) + "}");
|
||||
NBTTagList parsedList = (NBTTagList) tempNBT.get("SkStuffIsCool");
|
||||
return parsedList;
|
||||
}
|
||||
@@ -413,8 +365,7 @@ public class NMS_v1_8_R3 implements NMSInterface {
|
||||
@Override
|
||||
protected NBTTagList deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException {
|
||||
String s = fields.getObject("asString", String.class);
|
||||
NBTTagCompound tempNBT = null;
|
||||
tempNBT = parseRawNBT("{SkStuffIsCool:" + s + "}");
|
||||
NBTTagCompound tempNBT = parseRawNBT("{SkStuffIsCool:" + s + "}");
|
||||
NBTTagList nbtList = (NBTTagList) tempNBT.get("SkStuffIsCool");
|
||||
return nbtList;
|
||||
}
|
||||
@@ -422,8 +373,7 @@ public class NMS_v1_8_R3 implements NMSInterface {
|
||||
@Override
|
||||
@Nullable
|
||||
public NBTTagList deserialize(String s) {
|
||||
NBTTagCompound tempNBT = null;
|
||||
tempNBT = parseRawNBT("{SkStuffIsCool:" + s + "}");
|
||||
NBTTagCompound tempNBT = parseRawNBT("{SkStuffIsCool:" + s + "}");
|
||||
NBTTagList nbtList = (NBTTagList) tempNBT.get("SkStuffIsCool");
|
||||
return nbtList;
|
||||
}
|
||||
@@ -456,11 +406,9 @@ public class NMS_v1_8_R3 implements NMSInterface {
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getItemNBT(ItemStack itemStack) {
|
||||
if (itemStack.getType() == Material.AIR)
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR)
|
||||
return null;
|
||||
NBTTagCompound itemNBT = CraftItemStack.asNMSCopy(itemStack).getTag();
|
||||
if (String.valueOf(itemNBT).equals("{}"))
|
||||
itemNBT = null;
|
||||
return itemNBT;
|
||||
}
|
||||
|
||||
@@ -548,6 +496,7 @@ public class NMS_v1_8_R3 implements NMSInterface {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase convertToNBT(Number number) {
|
||||
if (number instanceof Byte) {
|
||||
return new NBTTagByte((byte) number);
|
||||
@@ -575,4 +524,11 @@ public class NMS_v1_8_R3 implements NMSInterface {
|
||||
MinecraftKey mcKey = Item.REGISTRY.c(nmsItem.getItem());
|
||||
return mcKey.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemFromMcId(String mcId) {
|
||||
MinecraftKey mcKey = new MinecraftKey(mcId);
|
||||
Item nmsItem = (Item) Item.REGISTRY.get(mcKey);
|
||||
return CraftItemStack.asNewCraftStack(nmsItem);
|
||||
}
|
||||
}
|
||||
@@ -79,18 +79,11 @@ public class NMS_v1_9_R1 implements NMSInterface {
|
||||
parsedNBT = MojangsonParser.parse(rawNBT);
|
||||
} catch (MojangsonParseException ex) {
|
||||
Skript.warning("Error when parsing NBT - " + ex.getMessage());
|
||||
return null;
|
||||
}
|
||||
return parsedNBT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getContentsId(Object nbtList) {
|
||||
if (nbtList instanceof NBTTagList) {
|
||||
return ((NBTTagList) nbtList).d();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getContents(Object nbtList) {
|
||||
if (nbtList instanceof NBTTagList) {
|
||||
@@ -150,8 +143,8 @@ public class NMS_v1_9_R1 implements NMSInterface {
|
||||
return ((NBTTagDouble) value).g(); //Double inside a NBTNumber
|
||||
} else if (value instanceof NBTTagString) {
|
||||
return ((NBTTagString) value).a_(); //String inside the NBTTagString
|
||||
} else if (value instanceof NBTTagList || value instanceof NBTTagCompound) {
|
||||
return value; //No need to convert anything, these are registered by the addon.
|
||||
} else if (value instanceof NBTBase) {
|
||||
return value; //No need to convert this
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -218,8 +211,7 @@ public class NMS_v1_9_R1 implements NMSInterface {
|
||||
public void change(NBTTagCompound[] NBT, @Nullable Object[] delta, ChangeMode mode) {
|
||||
if (mode == ChangeMode.ADD) {
|
||||
if (delta[0] instanceof String) {
|
||||
NBTTagCompound parsedNBT = null;
|
||||
parsedNBT = parseRawNBT((String) delta[0]);
|
||||
NBTTagCompound parsedNBT = parseRawNBT((String) delta[0]);
|
||||
addToCompound(NBT[0], parsedNBT);
|
||||
} else {
|
||||
addToCompound(NBT[0], delta[0]);
|
||||
@@ -243,8 +235,7 @@ public class NMS_v1_9_R1 implements NMSInterface {
|
||||
@Nullable
|
||||
public NBTTagCompound parse(String rawNBT, ParseContext context) {
|
||||
if (rawNBT.startsWith("nbt:{") && rawNBT.endsWith("}")) {
|
||||
NBTTagCompound NBT = null;
|
||||
NBT = parseRawNBT(rawNBT.substring(4));
|
||||
NBTTagCompound NBT = parseRawNBT(rawNBT.substring(4));
|
||||
return NBT;
|
||||
}
|
||||
return null;
|
||||
@@ -257,7 +248,7 @@ public class NMS_v1_9_R1 implements NMSInterface {
|
||||
|
||||
@Override
|
||||
public String toVariableNameString(NBTTagCompound compound) {
|
||||
return "nbt:" + compound.toString();
|
||||
return compound.toString();
|
||||
}
|
||||
}).serializer(new Serializer<NBTTagCompound>() {
|
||||
|
||||
@@ -281,16 +272,14 @@ public class NMS_v1_9_R1 implements NMSInterface {
|
||||
@Override
|
||||
protected NBTTagCompound deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException {
|
||||
String s = fields.getObject("asString", String.class);
|
||||
NBTTagCompound compound = null;
|
||||
compound = parseRawNBT(s);
|
||||
NBTTagCompound compound = parseRawNBT(s);
|
||||
return compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public NBTTagCompound deserialize(String s) {
|
||||
NBTTagCompound compound = null;
|
||||
compound = parseRawNBT(s);
|
||||
NBTTagCompound compound = parseRawNBT(s);
|
||||
return compound;
|
||||
}
|
||||
|
||||
@@ -320,14 +309,12 @@ public class NMS_v1_9_R1 implements NMSInterface {
|
||||
public void change(NBTTagList[] nbtList, @Nullable Object[] delta, ChangeMode mode) {
|
||||
if (delta.length == 0)
|
||||
return;
|
||||
if (mode == ChangeMode.ADD) {
|
||||
if (delta[0] instanceof Number) {
|
||||
addToList(nbtList[0], convertToNBT((Number) delta[0]));
|
||||
} else if (delta[0] instanceof String) {
|
||||
addToList(nbtList[0], convertToNBT((String) delta[0]));
|
||||
} else if (delta[0] instanceof NBTBase) {
|
||||
addToList(nbtList[0], delta[0]);
|
||||
}
|
||||
if (delta[0] instanceof Number) {
|
||||
addToList(nbtList[0], convertToNBT((Number) delta[0]));
|
||||
} else if (delta[0] instanceof String) {
|
||||
addToList(nbtList[0], convertToNBT((String) delta[0]));
|
||||
} else if (delta[0] instanceof NBTBase) {
|
||||
addToList(nbtList[0], delta[0]);
|
||||
}
|
||||
}
|
||||
}).parser(new Parser<NBTTagList>() {
|
||||
@@ -341,8 +328,7 @@ public class NMS_v1_9_R1 implements NMSInterface {
|
||||
@Nullable
|
||||
public NBTTagList parse(String listString, ParseContext context) {
|
||||
if (listString.startsWith("[") && listString.endsWith("]")) {
|
||||
NBTTagCompound tempNBT = null;
|
||||
tempNBT = parseRawNBT("{SkStuffIsCool:[0:" + listString.substring(1) + "}");
|
||||
NBTTagCompound tempNBT = parseRawNBT("{SkStuffIsCool:[0:" + listString.substring(1) + "}");
|
||||
NBTTagList parsedList = (NBTTagList) tempNBT.get("SkStuffIsCool");
|
||||
return parsedList;
|
||||
}
|
||||
@@ -380,8 +366,7 @@ public class NMS_v1_9_R1 implements NMSInterface {
|
||||
@Override
|
||||
protected NBTTagList deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException {
|
||||
String s = fields.getObject("asString", String.class);
|
||||
NBTTagCompound tempNBT = null;
|
||||
tempNBT = parseRawNBT("{SkStuffIsCool:" + s + "}");
|
||||
NBTTagCompound tempNBT = parseRawNBT("{SkStuffIsCool:" + s + "}");
|
||||
NBTTagList nbtList = (NBTTagList) tempNBT.get("SkStuffIsCool");
|
||||
return nbtList;
|
||||
}
|
||||
@@ -389,8 +374,7 @@ public class NMS_v1_9_R1 implements NMSInterface {
|
||||
@Override
|
||||
@Nullable
|
||||
public NBTTagList deserialize(String s) {
|
||||
NBTTagCompound tempNBT = null;
|
||||
tempNBT = parseRawNBT("{SkStuffIsCool:" + s + "}");
|
||||
NBTTagCompound tempNBT = parseRawNBT("{SkStuffIsCool:" + s + "}");
|
||||
NBTTagList nbtList = (NBTTagList) tempNBT.get("SkStuffIsCool");
|
||||
return nbtList;
|
||||
}
|
||||
@@ -426,7 +410,7 @@ public class NMS_v1_9_R1 implements NMSInterface {
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR)
|
||||
return null;
|
||||
NBTTagCompound itemNBT = CraftItemStack.asNMSCopy(itemStack).getTag();
|
||||
if (String.valueOf(itemNBT).equals("{}"))
|
||||
if (itemNBT.isEmpty())
|
||||
itemNBT = null;
|
||||
return itemNBT;
|
||||
}
|
||||
@@ -545,4 +529,11 @@ public class NMS_v1_9_R1 implements NMSInterface {
|
||||
MinecraftKey mcKey = Item.REGISTRY.b(nmsItem.getItem());
|
||||
return mcKey.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemFromMcId(String mcId) {
|
||||
MinecraftKey mcKey = new MinecraftKey(mcId);
|
||||
Item nmsItem = (Item) Item.REGISTRY.get(mcKey);
|
||||
return CraftItemStack.asNewCraftStack(nmsItem);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user