Little fixes, area/volume/width/height/length of schematic should work.
This commit is contained in:
parent
5665f39cb5
commit
2718e2f763
@ -1,6 +1,6 @@
|
|||||||
name: SkStuff
|
name: SkStuff
|
||||||
author: TheBukor
|
author: TheBukor
|
||||||
description: A Skript addon which adds extra functionalities such as NBT and extended WorldEdit support.
|
description: A Skript addon which adds extra functionalities such as NBT and extended WorldEdit support.
|
||||||
version: 1.4.2
|
version: 1.4.2.1
|
||||||
main: me.TheBukor.SkStuff.SkStuff
|
main: me.TheBukor.SkStuff.SkStuff
|
||||||
softdepend: [Skript, WorldEdit]
|
softdepend: [Skript, WorldEdit]
|
@ -106,28 +106,29 @@ public class SkStuff extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void change(Object[] NBT, @Nullable Object[] delta, ChangeMode mode) {
|
public void change(Object[] NBT, @Nullable Object[] delta, ChangeMode mode) {
|
||||||
String newTags = (String) delta[0];
|
if (NBT[0].getClass().getName().contains("NBTTagCompound")) {
|
||||||
if (mode == ChangeMode.ADD) {
|
if (!(delta[0] instanceof String))
|
||||||
Object NBT1 = null;
|
return;
|
||||||
try {
|
String newTags = (String) delta[0];
|
||||||
NBT1 = nbtParserClass.getMethod("parse", String.class).invoke(NBT1, newTags);
|
if (mode == ChangeMode.ADD) {
|
||||||
NBTUtil.addCompound(NBT[0], NBT1);
|
Object NBT1 = null;
|
||||||
} catch (Exception ex) {
|
try {
|
||||||
if (ex instanceof InvocationTargetException) {
|
NBT1 = nbtParserClass.getMethod("parse", String.class).invoke(NBT1, newTags);
|
||||||
if (ex.getCause().getClass().getName().contains("MojangsonParseException") ) {
|
} catch (Exception ex) {
|
||||||
|
if (ex instanceof InvocationTargetException && ex.getCause().getClass().getName().contains("MojangsonParseException")) {
|
||||||
Bukkit.getConsoleSender().sendMessage("[SkStuff] " + ChatColor.RED + "Error when parsing NBT - " + ex.getCause().getMessage());
|
Bukkit.getConsoleSender().sendMessage("[SkStuff] " + ChatColor.RED + "Error when parsing NBT - " + ex.getCause().getMessage());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
ex.printStackTrace();
|
NBTUtil.addCompound(NBT[0], NBT1);
|
||||||
}
|
} else if (mode == ChangeMode.REMOVE) {
|
||||||
} else if (mode == ChangeMode.REMOVE) {
|
for (Object s : delta) {
|
||||||
for (Object s : delta) {
|
try {
|
||||||
try {
|
nbtClass.getMethod("remove", String.class).invoke(NBT[0], (String) s);
|
||||||
NBT.getClass().getMethod("remove", String.class).invoke(NBT, (String) s);
|
} catch (Exception ex) {
|
||||||
} catch (Exception ex) {
|
ex.printStackTrace();
|
||||||
ex.printStackTrace();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -141,24 +142,14 @@ public class SkStuff extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public Object parse(String s, ParseContext context) {
|
public Object parse(String rawNBT, ParseContext context) {
|
||||||
if (s.startsWith("{") && s.endsWith("}")) {
|
if (rawNBT.startsWith("{") && rawNBT.contains(":") && rawNBT.endsWith("}")) {
|
||||||
Object NBT = null;
|
Object NBT = null;
|
||||||
try {
|
try {
|
||||||
NBT = nbtClass.newInstance();
|
NBT = nbtParserClass.getMethod("parse", String.class).invoke(NBT, rawNBT);
|
||||||
} catch (InstantiationException | IllegalAccessException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Object NBT1 = null;
|
|
||||||
NBT1 = nbtParserClass.getMethod("parse", String.class).invoke(NBT1, s);
|
|
||||||
nbtClass.getMethod("a", nbtClass).invoke(NBT, NBT1);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (ex instanceof InvocationTargetException) {
|
if (ex instanceof InvocationTargetException && ex.getCause().getClass().getName().contains("MojangsonParseException")) {
|
||||||
if (ex.getCause().getClass().getName().contains("MojangsonParseException") ) {
|
return null;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,8 @@ public class EffDrawLineWE extends Effect {
|
|||||||
editSession = (Expression<EditSession>) expr[2];
|
editSession = (Expression<EditSession>) expr[2];
|
||||||
blockList = (Expression<ItemStack>) expr[3];
|
blockList = (Expression<ItemStack>) expr[3];
|
||||||
thickness = (Expression<Double>) expr[4];
|
thickness = (Expression<Double>) expr[4];
|
||||||
if (result.mark == 1) filled = false;
|
if (result.mark == 1)
|
||||||
|
filled = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,8 @@ public class EffMakeCylinder extends Effect {
|
|||||||
radius2 = (Expression<Double>) expr[3];
|
radius2 = (Expression<Double>) expr[3];
|
||||||
editSession = (Expression<EditSession>) expr[4];
|
editSession = (Expression<EditSession>) expr[4];
|
||||||
blockList = (Expression<ItemStack>) expr[5];
|
blockList = (Expression<ItemStack>) expr[5];
|
||||||
if (result.mark == 1) filled = false;
|
if (result.mark == 1)
|
||||||
|
filled = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -34,7 +34,8 @@ public class EffMakePyramid extends Effect {
|
|||||||
radius = (Expression<Integer>) expr[1];
|
radius = (Expression<Integer>) expr[1];
|
||||||
editSession = (Expression<EditSession>) expr[2];
|
editSession = (Expression<EditSession>) expr[2];
|
||||||
blockList = (Expression<ItemStack>) expr[3];
|
blockList = (Expression<ItemStack>) expr[3];
|
||||||
if (result.mark == 1) filled = false;
|
if (result.mark == 1)
|
||||||
|
filled = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -38,7 +38,8 @@ public class EffMakeSphere extends Effect {
|
|||||||
radius3 = (Expression<Double>) expr[3];
|
radius3 = (Expression<Double>) expr[3];
|
||||||
editSession = (Expression<EditSession>) expr[4];
|
editSession = (Expression<EditSession>) expr[4];
|
||||||
blockList = (Expression<ItemStack>) expr[5];
|
blockList = (Expression<ItemStack>) expr[5];
|
||||||
if (result.mark == 1) filled = false;
|
if (result.mark == 1)
|
||||||
|
filled = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -19,7 +19,8 @@ public class EffUndoRedoSession extends Effect {
|
|||||||
@Override
|
@Override
|
||||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
|
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
|
||||||
editSession = (Expression<EditSession>) expr[0];
|
editSession = (Expression<EditSession>) expr[0];
|
||||||
if (result.mark == 1) redo = true;
|
if (result.mark == 1)
|
||||||
|
redo = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@ public class ExprFileNBT extends SimpleExpression<Object> {
|
|||||||
private Expression<String> input;
|
private Expression<String> input;
|
||||||
|
|
||||||
private Class<?> nbtClass = ReflectionUtils.getNMSClass("NBTTagCompound");
|
private Class<?> nbtClass = ReflectionUtils.getNMSClass("NBTTagCompound");
|
||||||
private Class<?> nbtCompressedClass = ReflectionUtils.getNMSClass("NBTCompressedStreamTools");
|
|
||||||
private Class<?> nbtParserClass = ReflectionUtils.getNMSClass("MojangsonParser");
|
private Class<?> nbtParserClass = ReflectionUtils.getNMSClass("MojangsonParser");
|
||||||
|
private Class<?> nbtCompressedClass = ReflectionUtils.getNMSClass("NBTCompressedStreamTools");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<? extends Object> getReturnType() {
|
public Class<? extends Object> getReturnType() {
|
||||||
@ -69,13 +69,6 @@ public class ExprFileNBT extends SimpleExpression<Object> {
|
|||||||
NBT = nbtCompressedClass.getMethod("a", FileInputStream.class).invoke(NBT, fis);
|
NBT = nbtCompressedClass.getMethod("a", FileInputStream.class).invoke(NBT, fis);
|
||||||
fis.close();
|
fis.close();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (ex instanceof InvocationTargetException) {
|
|
||||||
if (ex.getCause().getClass().getName().contains("MojangsonParseException") ) {
|
|
||||||
Bukkit.getConsoleSender().sendMessage("[SkStuff] " + ChatColor.RED + "Error when parsing NBT - " + ex.getCause().getMessage());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
@ -104,18 +97,15 @@ public class ExprFileNBT extends SimpleExpression<Object> {
|
|||||||
Object NBT = null;
|
Object NBT = null;
|
||||||
NBT = nbtCompressedClass.getMethod("a", FileInputStream.class).invoke(NBT, fis);
|
NBT = nbtCompressedClass.getMethod("a", FileInputStream.class).invoke(NBT, fis);
|
||||||
Object NBT1 = null;
|
Object NBT1 = null;
|
||||||
NBT1 = nbtParserClass.getMethod("parse", nbtClass).invoke(NBT1, tags);
|
NBT1 = nbtParserClass.getMethod("parse", String.class).invoke(NBT1, tags);
|
||||||
NBTUtil.addCompound(NBT, NBT1);
|
NBTUtil.addCompound(NBT, NBT1);
|
||||||
nbtCompressedClass.getMethod("a", nbtClass, FileOutputStream.class).invoke(nbtCompressedClass.newInstance(), NBT, os);
|
nbtCompressedClass.getMethod("a", nbtClass, FileOutputStream.class).invoke(nbtCompressedClass.newInstance(), NBT, os);
|
||||||
fis.close();
|
fis.close();
|
||||||
os.close();
|
os.close();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (ex instanceof InvocationTargetException) {
|
if (ex instanceof InvocationTargetException && ex.getCause().getClass().getName().contains("MojangsonParseException")) {
|
||||||
if (ex.getCause().getClass().getName().contains("MojangsonParseException") ) {
|
Bukkit.getConsoleSender().sendMessage("[SkStuff] " + ChatColor.RED + "Error when parsing NBT - " + ex.getCause().getMessage());
|
||||||
Bukkit.getConsoleSender().sendMessage("[SkStuff] " + ChatColor.RED + "Error when parsing NBT - " + ex.getCause().getMessage());
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
@ -137,16 +127,11 @@ public class ExprFileNBT extends SimpleExpression<Object> {
|
|||||||
fis.close();
|
fis.close();
|
||||||
os.close();
|
os.close();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (ex instanceof InvocationTargetException) {
|
if (ex instanceof EOFException) {
|
||||||
if (ex.getCause().getClass().getName().contains("MojangsonParseException") ) {
|
// No actual error, just end of the file. Ignore it.
|
||||||
Bukkit.getConsoleSender().sendMessage("[SkStuff] " + ChatColor.RED + "Error when parsing NBT - " + ex.getCause().getMessage());
|
} else {
|
||||||
return;
|
|
||||||
}
|
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
} else if (ex instanceof EOFException) {
|
|
||||||
//No actual error, just end of the file. Ignore it.
|
|
||||||
}
|
}
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package me.TheBukor.SkStuff.expressions;
|
package me.TheBukor.SkStuff.expressions;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -69,10 +71,11 @@ public class ExprItemNBT extends SimpleExpression<ItemStack> {
|
|||||||
}
|
}
|
||||||
nmsItem.getClass().getMethod("setTag", nbtClass).invoke(nmsItem, NBT);
|
nmsItem.getClass().getMethod("setTag", nbtClass).invoke(nmsItem, NBT);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (ex.getCause().getClass().getName().contains("MojangsonParseException") ) {
|
if (ex instanceof InvocationTargetException && ex.getCause().getClass().getName().contains("MojangsonParseException")) {
|
||||||
Bukkit.getConsoleSender().sendMessage("[SkStuff] " + ChatColor.RED + "Error when parsing NBT - " + ex.getCause().getMessage());
|
Bukkit.getConsoleSender().sendMessage("[SkStuff] " + ChatColor.RED + "Error when parsing NBT - " + ex.getCause().getMessage());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
Object newItem = null;
|
Object newItem = null;
|
||||||
try {
|
try {
|
||||||
|
@ -115,6 +115,8 @@ public class ExprNBTOf extends SimpleExpression<Object> {
|
|||||||
@Override
|
@Override
|
||||||
public void change(Event e, Object[] delta, ChangeMode mode) {
|
public void change(Event e, Object[] delta, ChangeMode mode) {
|
||||||
Object tar = target.getSingle(e);
|
Object tar = target.getSingle(e);
|
||||||
|
if (!(delta[0] instanceof String))
|
||||||
|
return;
|
||||||
if (tar instanceof Entity) {
|
if (tar instanceof Entity) {
|
||||||
Object NBT = null;
|
Object NBT = null;
|
||||||
Object nmsEnt = null;
|
Object nmsEnt = null;
|
||||||
@ -138,12 +140,9 @@ public class ExprNBTOf extends SimpleExpression<Object> {
|
|||||||
NBTUtil.addCompound(NBT, NBT1);
|
NBTUtil.addCompound(NBT, NBT1);
|
||||||
nmsEnt.getClass().getMethod("f", nbtClass).invoke(nmsEnt, NBT);
|
nmsEnt.getClass().getMethod("f", nbtClass).invoke(nmsEnt, NBT);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (ex instanceof InvocationTargetException) {
|
if (ex instanceof InvocationTargetException && ex.getCause().getClass().getName().contains("MojangsonParseException")) {
|
||||||
if (ex.getCause().getClass().getName().contains("MojangsonParseException")) {
|
Bukkit.getConsoleSender().sendMessage("[SkStuff] " + ChatColor.RED + "Error when parsing NBT - " + ex.getCause().getMessage());
|
||||||
Bukkit.getConsoleSender().sendMessage("[SkStuff] " + ChatColor.RED + "Error when parsing NBT - " + ex.getCause().getMessage());
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -193,12 +192,9 @@ public class ExprNBTOf extends SimpleExpression<Object> {
|
|||||||
tileEntity.getClass().getMethod("update").invoke(tileEntity);
|
tileEntity.getClass().getMethod("update").invoke(tileEntity);
|
||||||
nmsWorld.getClass().getMethod("notify", nmsPosClass).invoke(nmsWorld, tileEntity.getClass().getMethod("getPosition").invoke(tileEntity));
|
nmsWorld.getClass().getMethod("notify", nmsPosClass).invoke(nmsWorld, tileEntity.getClass().getMethod("getPosition").invoke(tileEntity));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (ex instanceof InvocationTargetException) {
|
if (ex instanceof InvocationTargetException && ex.getCause().getClass().getName().contains("MojangsonParseException")) {
|
||||||
if (ex.getCause().getClass().getName().contains("MojangsonParseException")) {
|
Bukkit.getConsoleSender().sendMessage("[SkStuff] " + ChatColor.RED + "Error when parsing NBT - " + ex.getCause().getMessage());
|
||||||
Bukkit.getConsoleSender().sendMessage("[SkStuff] " + ChatColor.RED + "Error when parsing NBT - " + ex.getCause().getMessage());
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -256,12 +252,9 @@ public class ExprNBTOf extends SimpleExpression<Object> {
|
|||||||
}
|
}
|
||||||
((Slot) slot[0]).setItem((ItemStack) newItem);
|
((Slot) slot[0]).setItem((ItemStack) newItem);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (ex instanceof InvocationTargetException) {
|
if (ex instanceof InvocationTargetException && ex.getCause().getClass().getName().contains("MojangsonParseException")) {
|
||||||
if (ex.getCause().getClass().getName().contains("MojangsonParseException") ) {
|
Bukkit.getConsoleSender().sendMessage("[SkStuff] " + ChatColor.RED + "Error when parsing NBT - " + ex.getCause().getMessage());
|
||||||
Bukkit.getConsoleSender().sendMessage("[SkStuff] " + ChatColor.RED + "Error when parsing NBT - " + ex.getCause().getMessage());
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
@ -20,6 +19,9 @@ import ch.njol.util.Kleenean;
|
|||||||
public class ExprSchematicArea extends SimpleExpression<Integer> {
|
public class ExprSchematicArea extends SimpleExpression<Integer> {
|
||||||
private Expression<String> schematic;
|
private Expression<String> schematic;
|
||||||
|
|
||||||
|
private int parseMark;
|
||||||
|
private String toStringMark;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<? extends Integer> getReturnType() {
|
public Class<? extends Integer> getReturnType() {
|
||||||
return Integer.class;
|
return Integer.class;
|
||||||
@ -32,14 +34,26 @@ public class ExprSchematicArea extends SimpleExpression<Integer> {
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
|
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
|
||||||
schematic = (Expression<String>) expr[0];
|
schematic = (Expression<String>) expr[0];
|
||||||
|
parseMark = result.mark;
|
||||||
|
if (parseMark == 0) {
|
||||||
|
toStringMark = "volume";
|
||||||
|
} else if (parseMark == 1) {
|
||||||
|
toStringMark = "width (x-size)";
|
||||||
|
} else if (parseMark == 2) {
|
||||||
|
toStringMark = "height (y-size)";
|
||||||
|
} else if (parseMark == 3) {
|
||||||
|
toStringMark = "length (z-size)";
|
||||||
|
} else if (parseMark == 4) {
|
||||||
|
toStringMark = "area";
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(@Nullable Event e, boolean arg1) {
|
public String toString(@Nullable Event e, boolean arg1) {
|
||||||
return "the volume of the schematic from " + schematic.toString(e, false);
|
return "the " + toStringMark + " of the schematic from " + schematic.toString(e, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@ -48,13 +62,24 @@ public class ExprSchematicArea extends SimpleExpression<Integer> {
|
|||||||
protected Integer[] get(Event e) {
|
protected Integer[] get(Event e) {
|
||||||
String schem = schematic.getSingle(e);
|
String schem = schematic.getSingle(e);
|
||||||
File schemFile = new File((schem.endsWith(".schematic") ? schem : (schem + ".schematic")));
|
File schemFile = new File((schem.endsWith(".schematic") ? schem : (schem + ".schematic")));
|
||||||
Vector v = null;
|
Vector size = null;
|
||||||
try {
|
try {
|
||||||
v = MCEditSchematicFormat.getFormat(schemFile).load(schemFile).getSize();
|
size = MCEditSchematicFormat.getFormat(schemFile).load(schemFile).getSize();
|
||||||
} catch (DataException | IOException ex) {
|
} catch (DataException | IOException ex) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Bukkit.broadcastMessage("vector: " + v.getX() + v.getY() + v.getZ());
|
Number result = null;
|
||||||
return new Integer[] { 1 };
|
if (parseMark == 0) {
|
||||||
|
result = (size.getX() * size.getY() * size.getZ());
|
||||||
|
} else if (parseMark == 1) {
|
||||||
|
result = size.getX();
|
||||||
|
} else if (parseMark == 2) {
|
||||||
|
result = size.getY();
|
||||||
|
} else if (parseMark == 3) {
|
||||||
|
result = size.getZ();
|
||||||
|
} else if (parseMark == 4) {
|
||||||
|
result = (size.getX() * size.getZ());
|
||||||
|
}
|
||||||
|
return new Integer[] { result.intValue() };
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,14 +10,16 @@ public class NBTUtil {
|
|||||||
private static Class<?> nbtClass = ReflectionUtils.getNMSClass("NBTTagCompound");
|
private static Class<?> nbtClass = ReflectionUtils.getNMSClass("NBTTagCompound");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is actually a copy of the "a(NBTTagCompound)" method in the NBTTagCompound class using reflection
|
* This is actually a copy of the "a(NBTTagCompound)" method in the NBTTagCompound class.
|
||||||
* I needed to add this because the 1.7 and before versions of the NBTTagCompound class didn't have this method,
|
* I needed to add this because the 1.7 and before versions of the NBTTagCompound class didn't have this method,
|
||||||
* so there wasn't actually a reliable way to multiple tags at once into a compound.
|
* so there wasn't actually a reliable way to multiple tags at once into a compound.
|
||||||
* For the original code for the method, check https://github.com/linouxis9/mc-dev-1.8.7/blob/master/net/minecraft/server/NBTTagCompound.java#L348
|
* For the original code for the method, check https://github.com/linouxis9/mc-dev-1.8.7/blob/master/net/minecraft/server/NBTTagCompound.java#L348
|
||||||
|
*
|
||||||
|
* Please note that I adapted it to work using reflection.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static void addCompound(Object source, Object toAdd) {
|
public static void addCompound(Object NBT, Object toAdd) {
|
||||||
if (source.getClass().getName().contains("NBTTagCompound") && toAdd.getClass().getName().contains("NBTTagCompound")) {
|
if (NBT.getClass().getName().contains("NBTTagCompound") && toAdd.getClass().getName().contains("NBTTagCompound")) {
|
||||||
try {
|
try {
|
||||||
Field map = nbtClass.getDeclaredField("map");
|
Field map = nbtClass.getDeclaredField("map");
|
||||||
map.setAccessible(true);
|
map.setAccessible(true);
|
||||||
@ -28,15 +30,15 @@ public class NBTUtil {
|
|||||||
String string = (String) iterator.next();
|
String string = (String) iterator.next();
|
||||||
Object base = nbtBaseClass.cast((((HashMap<String, Object>) map.get(toAdd)).get(string)));
|
Object base = nbtBaseClass.cast((((HashMap<String, Object>) map.get(toAdd)).get(string)));
|
||||||
if((byte) nbtBaseClass.getMethod("getTypeId").invoke(base) == 10) {
|
if((byte) nbtBaseClass.getMethod("getTypeId").invoke(base) == 10) {
|
||||||
if((boolean) nbtClass.getMethod("hasKeyOfType", String.class, int.class).invoke(source, string, 10)) {
|
if((boolean) nbtClass.getMethod("hasKeyOfType", String.class, int.class).invoke(NBT, string, 10)) {
|
||||||
Object NBT = null;
|
Object localNBT = null;
|
||||||
NBT = nbtClass.getMethod("getCompound", String.class).invoke(NBT, string);
|
localNBT = nbtClass.getMethod("getCompound", String.class).invoke(localNBT, string);
|
||||||
NBTUtil.addCompound(NBT, base.getClass().cast(nbtClass));
|
NBTUtil.addCompound(localNBT.toString(), base.getClass().cast(nbtClass));
|
||||||
} else {
|
} else {
|
||||||
nbtClass.getMethod("set", String.class, nbtBaseClass).invoke(source, string, base.getClass().getMethod("clone").invoke(base));
|
nbtClass.getMethod("set", String.class, nbtBaseClass).invoke(NBT, string, base.getClass().getMethod("clone").invoke(base));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
nbtClass.getMethod("set", String.class, nbtBaseClass).invoke(source, string, base.getClass().getMethod("clone").invoke(base));
|
nbtClass.getMethod("set", String.class, nbtBaseClass).invoke(NBT, string, base.getClass().getMethod("clone").invoke(base));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
map.setAccessible(false);
|
map.setAccessible(false);
|
||||||
|
Loading…
Reference in New Issue
Block a user