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:
parent
e3a902c773
commit
0b4cb17ca1
@ -65,6 +65,7 @@ import me.TheBukor.SkStuff.expressions.ExprFlagsOfWGRegion;
|
||||
import me.TheBukor.SkStuff.expressions.ExprGlideState;
|
||||
import me.TheBukor.SkStuff.expressions.ExprItemNBT;
|
||||
import me.TheBukor.SkStuff.expressions.ExprMCIdOf;
|
||||
import me.TheBukor.SkStuff.expressions.ExprMCIdToItem;
|
||||
import me.TheBukor.SkStuff.expressions.ExprNBTListContents;
|
||||
import me.TheBukor.SkStuff.expressions.ExprNBTListIndex;
|
||||
import me.TheBukor.SkStuff.expressions.ExprNBTOf;
|
||||
@ -115,7 +116,7 @@ public class SkStuff extends JavaPlugin {
|
||||
effAmount += 2;
|
||||
exprAmount += 6;
|
||||
if (Skript.isRunningMinecraft(1, 9)) {
|
||||
getLogger().info("WOW! You're using Minecraft 1.9! Lemme register some cool stuff right away!");
|
||||
getLogger().info("WOW! You're using Minecraft 1.9! Lemme register some cool elytra stuff right away!");
|
||||
Skript.registerEvent("Elytra glide toggle", SimpleEvent.class, EntityToggleGlideEvent.class, "[entity] elytra (fl(y|ight)|glid(e|ing)) toggl(e|ing)", "[entity] toggle elytra (fl(y|ight)|glid(e|ing))");
|
||||
Skript.registerExpression(ExprGlideState.class, Boolean.class, ExpressionType.PROPERTY, "elytra (fl(y|ight)|glid(e|ing)) state of %livingentity%", "%livingentity%'s elytra (fl(y|ight)|glid(e|ing)) state");
|
||||
|
||||
@ -146,11 +147,12 @@ public class SkStuff extends JavaPlugin {
|
||||
Skript.registerExpression(ExprNoClip.class, Boolean.class, ExpressionType.PROPERTY, "no[( |-)]clip (state|mode) of %entities%", "%entities%'s no[( |-)]clip (state|mode)");
|
||||
Skript.registerExpression(ExprFireProof.class, Boolean.class, ExpressionType.PROPERTY, "fire[ ]proof (state|mode) of %entities%", "%entities%'s fire[ ]proof (state|mode)");
|
||||
Skript.registerExpression(ExprEndermanBlocks.class, ItemStack.class, ExpressionType.PROPERTY, "blocks that %entity% can (carry|hold|grab|steal)");
|
||||
Skript.registerExpression(ExprMCIdOf.class, String.class, ExpressionType.PROPERTY, "minecraft [(string|native)] id of %itemtype%", "%itemtype%'s minecraft [(string|native)] id");
|
||||
Skript.registerExpression(ExprMCIdOf.class, String.class, ExpressionType.PROPERTY, "(mc|minecraft) [(string|native)] id of %itemtype%", "%itemtype%'s minecraft [(string|native)] id");
|
||||
Skript.registerExpression(ExprMCIdToItem.class, ItemStack.class, ExpressionType.SIMPLE, "item[[ ](stack|type)] (of|from) (mc|minecraft) [(string|native)] id %string%");
|
||||
nmsMethods.registerCompoundClassInfo();
|
||||
nmsMethods.registerNBTListClassInfo();
|
||||
effAmount += 5;
|
||||
exprAmount += 10;
|
||||
exprAmount += 11;
|
||||
typeAmount += 2;
|
||||
}
|
||||
if (Bukkit.getPluginManager().getPlugin("WorldEdit") != null) {
|
||||
@ -208,7 +210,7 @@ public class SkStuff extends JavaPlugin {
|
||||
Plugin skRambled = Bukkit.getPluginManager().getPlugin("SkRambled");
|
||||
boolean registerNewTypes = (umbaska == null && skRambled == null);
|
||||
if (registerNewTypes) {
|
||||
Skript.registerExpression(ExprFlagOfWGRegion.class, Flag.class, ExpressionType.PROPERTY, "[w[orld[ ]]g[uard]] flag %wgflag% of %wgregion%");
|
||||
Skript.registerExpression(ExprFlagOfWGRegion.class, String.class, ExpressionType.PROPERTY, "[w[orld[ ]]g[uard]] flag %wgflag% of %wgregion%");
|
||||
Skript.registerExpression(ExprFlagsOfWGRegion.class, Flag.class, ExpressionType.PROPERTY, "all [w[orld[ ]]g[uard]] flags of %wgregion%");
|
||||
Classes.registerClass(new ClassInfo<Flag>(Flag.class, "wgflag").name("WorldGuard Flag").user("(w(orld ?)?g(uard)? )?flags?").defaultExpression(new EventValueExpression<Flag>(Flag.class)).parser(new Parser<Flag<?>>() {
|
||||
|
||||
@ -263,7 +265,7 @@ public class SkStuff extends JavaPlugin {
|
||||
|
||||
}));
|
||||
} else {
|
||||
Skript.registerExpression(ExprFlagOfWGRegion.class, Flag.class, ExpressionType.PROPERTY, "[skstuff] [w[orld[ ]]g[uard]] flag %flag% of %protectedregion%");
|
||||
Skript.registerExpression(ExprFlagOfWGRegion.class, String.class, ExpressionType.PROPERTY, "[skstuff] [w[orld[ ]]g[uard]] flag %flag% of %protectedregion%");
|
||||
Skript.registerExpression(ExprFlagsOfWGRegion.class, Flag.class, ExpressionType.PROPERTY, "[skstuff] [all] [w[orld[ ]]g[uard]] flags of %protectedregion%");
|
||||
}
|
||||
exprAmount += 2;
|
||||
|
@ -1,5 +1,7 @@
|
||||
package me.TheBukor.SkStuff.conditions;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -7,8 +9,6 @@ import org.bukkit.event.Event;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import ch.njol.skript.lang.Condition;
|
||||
import ch.njol.skript.lang.Expression;
|
||||
import ch.njol.skript.lang.SkriptParser.ParseResult;
|
||||
|
@ -1,16 +1,10 @@
|
||||
package me.TheBukor.SkStuff.expressions;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.craftbukkit.libs.jline.internal.Nullable;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import com.sk89q.worldguard.protection.flags.BooleanFlag;
|
||||
import com.sk89q.worldguard.protection.flags.EntityTypeFlag;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.SetFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag.State;
|
||||
import com.sk89q.worldguard.protection.flags.StringFlag;
|
||||
@ -25,8 +19,7 @@ import ch.njol.skript.lang.util.SimpleExpression;
|
||||
import ch.njol.util.Kleenean;
|
||||
import ch.njol.util.coll.CollectionUtils;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class ExprFlagOfWGRegion extends SimpleExpression<Flag> {
|
||||
public class ExprFlagOfWGRegion extends SimpleExpression<String> {
|
||||
private Expression<Flag<?>> flag;
|
||||
private Expression<ProtectedRegion> region;
|
||||
|
||||
@ -39,10 +32,10 @@ public class ExprFlagOfWGRegion extends SimpleExpression<Flag> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Flag<?>[] get(final Event e) {
|
||||
protected String[] get(final Event e) {
|
||||
ProtectedRegion region = this.region.getSingle(e);
|
||||
Flag<?> flag = this.flag.getSingle(e);
|
||||
return new Flag<?>[] { (Flag<?>) region.getFlag(flag) };
|
||||
return new String[] { region.getFlag(flag).toString() };
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -50,10 +43,9 @@ public class ExprFlagOfWGRegion extends SimpleExpression<Flag> {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Class<? extends Flag<?>> getReturnType() {
|
||||
return (Class<? extends Flag<?>>) Flag.class;
|
||||
public Class<? extends String> getReturnType() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -61,7 +53,6 @@ public class ExprFlagOfWGRegion extends SimpleExpression<Flag> {
|
||||
return "worldguard flag " + flag.toString(e, debug) + " of " + region.toString(e, debug);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void change(Event e, Object[] delta, ChangeMode mode) {
|
||||
ProtectedRegion region = this.region.getSingle(e);
|
||||
@ -82,6 +73,7 @@ public class ExprFlagOfWGRegion extends SimpleExpression<Flag> {
|
||||
} else if (flag instanceof BooleanFlag && delta[0] instanceof Boolean) {
|
||||
boolean newValue = (boolean) delta[0];
|
||||
region.setFlag((BooleanFlag) flag, newValue);
|
||||
/*
|
||||
} else if (flag instanceof SetFlag) {
|
||||
if (delta instanceof EntityData[]) {
|
||||
if (((SetFlag) flag).getType() instanceof EntityTypeFlag) {
|
||||
@ -98,10 +90,7 @@ public class ExprFlagOfWGRegion extends SimpleExpression<Flag> {
|
||||
}
|
||||
}
|
||||
region.setFlag((SetFlag<EntityType>) flag, newSet);
|
||||
} else {
|
||||
Skript.error("Sorry, this flag type isn't supported yet! Flag type: SetFlag of type " + ((SetFlag) flag).getType().getName());
|
||||
}
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
Skript.error("Sorry, this flag type isn't supported yet! Flag type: " + flag.getClass().getSimpleName());
|
||||
}
|
||||
|
46
src/me/TheBukor/SkStuff/expressions/ExprMCIdToItem.java
Normal file
46
src/me/TheBukor/SkStuff/expressions/ExprMCIdToItem.java
Normal file
@ -0,0 +1,46 @@
|
||||
package me.TheBukor.SkStuff.expressions;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import ch.njol.skript.lang.Expression;
|
||||
import ch.njol.skript.lang.SkriptParser.ParseResult;
|
||||
import ch.njol.skript.lang.util.SimpleExpression;
|
||||
import ch.njol.util.Kleenean;
|
||||
import me.TheBukor.SkStuff.SkStuff;
|
||||
|
||||
public class ExprMCIdToItem extends SimpleExpression<ItemStack> {
|
||||
private Expression<String> mcId;
|
||||
|
||||
@Override
|
||||
public boolean isSingle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends ItemStack> getReturnType() {
|
||||
return ItemStack.class;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
|
||||
mcId = (Expression<String>) expr[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean debug) {
|
||||
return "item from minecraft id " + mcId.toString(e, debug);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected ItemStack[] get(Event e) {
|
||||
String id = mcId.getSingle(e);
|
||||
return new ItemStack[] { SkStuff.getNMSMethods().getItemFromMcId(id) };
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package me.TheBukor.SkStuff.expressions;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
@ -7,8 +9,6 @@ import org.bukkit.event.Event;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.bukkit.selections.Selection;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import ch.njol.skript.lang.Expression;
|
||||
import ch.njol.skript.lang.SkriptParser.ParseResult;
|
||||
import ch.njol.skript.lang.util.SimpleExpression;
|
||||
|
@ -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)
|
||||
return null;
|
||||
if (compound == null || compound.toString().equals("{}"))
|
||||
return itemStack;
|
||||
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 (((NBTTagCompound) compound).isEmpty())
|
||||
return 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,50 +293,22 @@ 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)
|
||||
if (delta[0] instanceof Number) {
|
||||
addToList(nbtList, convertToNBT((Number) delta[0]));
|
||||
else if (delta[0] instanceof String)
|
||||
} else if (delta[0] instanceof String) {
|
||||
addToList(nbtList, convertToNBT((String) delta[0]));
|
||||
else if (delta[0] instanceof NBTTagCompound || delta[0] instanceof NBTTagList)
|
||||
} else if (delta[0] instanceof NBTBase) {
|
||||
addToList(nbtList, delta[0]);
|
||||
}
|
||||
} else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
|
||||
nbtList[0] = new NBTTagList();
|
||||
}
|
||||
}
|
||||
}).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,51 +298,23 @@ 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)
|
||||
if (delta[0] instanceof Number) {
|
||||
addToList(nbtList, convertToNBT((Number) delta[0]));
|
||||
else if (delta[0] instanceof String)
|
||||
} else if (delta[0] instanceof String) {
|
||||
addToList(nbtList, convertToNBT((String) delta[0]));
|
||||
else if (delta[0] instanceof NBTTagCompound || delta[0] instanceof NBTTagList)
|
||||
} else if (delta[0] instanceof NBTBase) {
|
||||
addToList(nbtList, delta[0]);
|
||||
}
|
||||
} else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
|
||||
nbtList[0] = new NBTTagList();
|
||||
}
|
||||
}
|
||||
}).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,51 +298,23 @@ 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)
|
||||
if (delta[0] instanceof Number) {
|
||||
addToList(nbtList, convertToNBT((Number) delta[0]));
|
||||
else if (delta[0] instanceof String)
|
||||
} else if (delta[0] instanceof String) {
|
||||
addToList(nbtList, convertToNBT((String) delta[0]));
|
||||
else if (delta[0] instanceof NBTTagCompound || delta[0] instanceof NBTTagList)
|
||||
} else if (delta[0] instanceof NBTBase) {
|
||||
addToList(nbtList, delta[0]);
|
||||
}
|
||||
} else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
|
||||
nbtList[0] = new NBTTagList();
|
||||
}
|
||||
}
|
||||
}).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,7 +309,6 @@ 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) {
|
||||
@ -329,7 +317,6 @@ public class NMS_v1_9_R1 implements NMSInterface {
|
||||
addToList(nbtList[0], delta[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).parser(new Parser<NBTTagList>() {
|
||||
|
||||
@Override
|
||||
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user