From 48685db4befe6838bdc879b03c159c461bfd84fb Mon Sep 17 00:00:00 2001 From: TheBukor Date: Sun, 13 Mar 2016 04:06:43 -0300 Subject: [PATCH] Some COOL stuff Fixed PathfinderGoalMeleeAttack Fixed error when using remove/clear pathfinder goals on an armor stand (why is it considered a living entity?!?) Forgot to make NBTListIndex return a single value, now fixed Added "Minecraft ID of %itemtype%" (to return for example "minecraft:planks") Also some stuff I don't remember (see the changes!) --- src/me/TheBukor/SkStuff/SkStuff.java | 28 ++++++- .../SkStuff/effects/EffClearPathGoals.java | 3 +- .../SkStuff/effects/EffRemovePathGoal.java | 3 +- .../SkStuff/effects/EffSetPathGoal.java | 32 +++---- .../SkStuff/expressions/ExprGlideState.java | 69 +++++++++++++++ .../SkStuff/expressions/ExprMCIdOf.java | 49 +++++++++++ .../SkStuff/expressions/ExprNBTListIndex.java | 2 +- .../TheBukor/SkStuff/util/NMSInterface.java | 2 + src/me/TheBukor/SkStuff/util/NMS_v1_7_R4.java | 64 ++++++-------- src/me/TheBukor/SkStuff/util/NMS_v1_8_R1.java | 9 ++ src/me/TheBukor/SkStuff/util/NMS_v1_8_R2.java | 9 ++ src/me/TheBukor/SkStuff/util/NMS_v1_8_R3.java | 9 ++ src/me/TheBukor/SkStuff/util/NMS_v1_9_R1.java | 83 ++++++------------- 13 files changed, 239 insertions(+), 123 deletions(-) create mode 100644 src/me/TheBukor/SkStuff/expressions/ExprGlideState.java create mode 100644 src/me/TheBukor/SkStuff/expressions/ExprMCIdOf.java diff --git a/src/me/TheBukor/SkStuff/SkStuff.java b/src/me/TheBukor/SkStuff/SkStuff.java index 4c666ac..281f22f 100644 --- a/src/me/TheBukor/SkStuff/SkStuff.java +++ b/src/me/TheBukor/SkStuff/SkStuff.java @@ -6,6 +6,7 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Player; +import org.bukkit.event.entity.EntityToggleGlideEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; @@ -34,6 +35,7 @@ import me.TheBukor.SkStuff.effects.EffPasteSchematic; import me.TheBukor.SkStuff.effects.EffRememberChanges; import me.TheBukor.SkStuff.effects.EffRemovePathGoal; import me.TheBukor.SkStuff.effects.EffReplaceBlocksWE; +import me.TheBukor.SkStuff.effects.EffRestoreInv; import me.TheBukor.SkStuff.effects.EffSetBlocksWE; import me.TheBukor.SkStuff.effects.EffSetPathGoal; import me.TheBukor.SkStuff.effects.EffShowEntityEffect; @@ -48,7 +50,9 @@ import me.TheBukor.SkStuff.expressions.ExprEditSessionLimit; import me.TheBukor.SkStuff.expressions.ExprEndermanBlocks; import me.TheBukor.SkStuff.expressions.ExprFileNBT; import me.TheBukor.SkStuff.expressions.ExprFireProof; +import me.TheBukor.SkStuff.expressions.ExprGlideState; import me.TheBukor.SkStuff.expressions.ExprItemNBT; +import me.TheBukor.SkStuff.expressions.ExprMCIdOf; import me.TheBukor.SkStuff.expressions.ExprNBTListContents; import me.TheBukor.SkStuff.expressions.ExprNBTListIndex; import me.TheBukor.SkStuff.expressions.ExprNBTOf; @@ -58,6 +62,7 @@ import me.TheBukor.SkStuff.expressions.ExprSchematicArea; import me.TheBukor.SkStuff.expressions.ExprSelectionArea; import me.TheBukor.SkStuff.expressions.ExprSelectionOfPlayer; import me.TheBukor.SkStuff.expressions.ExprSelectionPos; +import me.TheBukor.SkStuff.expressions.ExprSerializedInv; import me.TheBukor.SkStuff.expressions.ExprTagOf; import me.TheBukor.SkStuff.expressions.ExprTimespanToNumber; import me.TheBukor.SkStuff.expressions.ExprToLowerCase; @@ -87,13 +92,32 @@ public class SkStuff extends JavaPlugin { getLogger().info("SkStuff " + this.getDescription().getVersion() + " has been successfully enabled!"); getLogger().info("Registering general non version specific stuff..."); Skript.registerEffect(EffShowEntityEffect.class, "(display|play|show) entity effect (0¦firework[s] explo(de|sion)|1¦hurt|2¦[[iron] golem] (give|offer) (rose|poppy)|3¦[sheep] eat grass|4¦wolf shake) at %entity%"); + Skript.registerEffect(EffRestoreInv.class, "[(skstuff|1.9)] restore %inventory% (to|from) [serialized [inventory [conents]]] %string%"); Skript.registerExpression(ExprToUpperCase.class, String.class, ExpressionType.SIMPLE, "%string% [converted] to [all] (cap[ital]s|upper[ ]case)", "convert %string% to [all] (cap[ital]s|upper[ ]case)", "capitalize [all] [char[acter]s (of|in)] %string%"); Skript.registerExpression(ExprToLowerCase.class, String.class, ExpressionType.SIMPLE, "%string% [converted] to [all] lower[ ]case", "convert %string% to [all] lower[ ]case", "un[( |-)]capitalize [all] [char[acter]s (of|in)] %string%"); Skript.registerExpression(ExprWordsToUpperCase.class, String.class, ExpressionType.SIMPLE, "(first|1st) (letter|char[acter]) (of|in) (each word|[all] words) (of|in) %string% [converted] to (cap[ital]s|upper[ ]case) (0¦|1¦ignoring [other] upper[ ]case [(char[acter]s|letters)])", "convert (first|1st) (letter|char[acter]) (of|in) (each word|[all] words) (of|in) %string% to (cap[ital]s|upper[ ]case) (0¦|1¦ignoring [other] upper[ ]case [(char[acter]s|letters)])", "capitalize (first|1st) (letter|char[acter]) (of|in) (each word|[all] words) (of|in) %string% (0¦|1¦ignoring [other] upper[ ]case [(char[acter]s|letters)])"); Skript.registerExpression(ExprTimespanToNumber.class, Number.class, ExpressionType.SIMPLE, "%timespan% [converted] [in]to (0¦ticks|1¦sec[ond]s|2¦min[ute]s|3¦hours|4¦days)"); Skript.registerExpression(ExprClickedInventory.class, Inventory.class, ExpressionType.SIMPLE, "[skstuff] clicked inventory"); - effAmount += 1; - exprAmount += 5; + Skript.registerExpression(ExprSerializedInv.class, String.class, ExpressionType.PROPERTY, "[(skstuff|1.9)] serialized [contents of] %inventory%"); + Skript.registerExpression(ExprMCIdOf.class, String.class, ExpressionType.PROPERTY, "minecraft [(string|native)] id of %itemtype%", "%itemtype%'s minecraft [(string|native)] id"); + effAmount += 2; + exprAmount += 7; + if (Skript.isRunningMinecraft(1, 9)) { + getLogger().info("WOW! You're using Minecraft 1.9! Lemme register some cool 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 %player%", "%player%'s elytra (fl(y|ight)|glid(e|ing)) state"); + /* Don't register it yet, Spigot isn't doing it properly as of now. + EventValues.registerEventValue(EntityToggleGlideEvent.class, Entity.class, new Getter() { + @Override + @Nullable + public Entity get(EntityToggleGlideEvent e) { + return e.getEntity(); + } + }, 0); + */ + evtAmount += 1; + exprAmount += 1; + } if (setupNMSVersion()) { getLogger().info("Trying to register version specific stuff..."); Skript.registerEffect(EffClearPathGoals.class, "(clear|delete) [all] pathfind[er] goals (of|from) %livingentities%"); diff --git a/src/me/TheBukor/SkStuff/effects/EffClearPathGoals.java b/src/me/TheBukor/SkStuff/effects/EffClearPathGoals.java index cc46ef4..68eafd5 100644 --- a/src/me/TheBukor/SkStuff/effects/EffClearPathGoals.java +++ b/src/me/TheBukor/SkStuff/effects/EffClearPathGoals.java @@ -2,6 +2,7 @@ package me.TheBukor.SkStuff.effects; import javax.annotation.Nullable; +import org.bukkit.entity.ArmorStand; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.Event; @@ -31,7 +32,7 @@ public class EffClearPathGoals extends Effect { protected void execute(Event e) { LivingEntity[] ents = entities.getAll(e); for (LivingEntity ent : ents) { - if (ent instanceof Player || ent == null) + if (ent instanceof Player || ent instanceof ArmorStand || ent == null) continue; SkStuff.getNMSMethods().clearPathfinderGoals(ent); } diff --git a/src/me/TheBukor/SkStuff/effects/EffRemovePathGoal.java b/src/me/TheBukor/SkStuff/effects/EffRemovePathGoal.java index cc8c3ee..aed6a2e 100644 --- a/src/me/TheBukor/SkStuff/effects/EffRemovePathGoal.java +++ b/src/me/TheBukor/SkStuff/effects/EffRemovePathGoal.java @@ -4,6 +4,7 @@ import java.lang.reflect.InvocationTargetException; import javax.annotation.Nullable; +import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Blaze; import org.bukkit.entity.Creature; import org.bukkit.entity.Ghast; @@ -45,7 +46,7 @@ public class EffRemovePathGoal extends Effect { protected void execute(Event e) { LivingEntity[] ents = entities.getAll(e); for (LivingEntity ent : ents) { - if (ent instanceof Player || ent == null) + if (ent instanceof Player || ent instanceof ArmorStand || ent == null) return; Object obcEnt = craftLivEnt.cast(ent); Object nmsEnt = null; diff --git a/src/me/TheBukor/SkStuff/effects/EffSetPathGoal.java b/src/me/TheBukor/SkStuff/effects/EffSetPathGoal.java index 99d2850..ff1518d 100644 --- a/src/me/TheBukor/SkStuff/effects/EffSetPathGoal.java +++ b/src/me/TheBukor/SkStuff/effects/EffSetPathGoal.java @@ -9,6 +9,7 @@ import javax.annotation.Nullable; import org.bukkit.Material; import org.bukkit.entity.Animals; +import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Blaze; import org.bukkit.entity.Creeper; import org.bukkit.entity.Enderman; @@ -149,7 +150,7 @@ public class EffSetPathGoal extends Effect { protected void execute(Event e) { LivingEntity[] ents = entities.getAll(e); for (LivingEntity ent : ents) { - if (ent == null || ent instanceof Player) + if (ent == null || ent instanceof Player || ent instanceof ArmorStand) return; int priority = (goalPriority == null ? 4 : goalPriority.getSingle(e).intValue()); @@ -174,7 +175,7 @@ public class EffSetPathGoal extends Effect { for (EntityData entData : types) { if (!LivingEntity.class.isAssignableFrom(entData.getType())) return; - String className = entData.getType().getClass().getSimpleName(); + String className = entData.getType().getSimpleName(); if (className.equals("HumanEntity")) { className = "Human"; } else if (className.equals("EntityLiving")) { @@ -188,7 +189,7 @@ public class EffSetPathGoal extends Effect { for (EntityData entData : types) { if (!LivingEntity.class.isAssignableFrom(entData.getType())) return; - String className = entData.getType().getClass().getSimpleName(); + String className = entData.getType().getSimpleName(); if (className.equals("HumanEntity")) { className = "Human"; } else if (className.equals("EntityLiving")) { @@ -239,7 +240,7 @@ public class EffSetPathGoal extends Effect { for (EntityData entData : types) { if (!LivingEntity.class.isAssignableFrom(entData.getType())) return; - String className = entData.getType().getClass().getSimpleName(); + String className = entData.getType().getSimpleName(); if (className.equals("HumanEntity")) { className = "Human"; } else if (className.equals("EntityLiving")) { @@ -268,7 +269,7 @@ public class EffSetPathGoal extends Effect { for (EntityData entData : types) { if (!LivingEntity.class.isAssignableFrom(entData.getType())) return; - String className = entData.getType().getClass().getSimpleName(); + String className = entData.getType().getSimpleName(); if (className.equals("HumanEntity")) { className = "Human"; } else if (className.equals("EntityLiving")) { @@ -284,7 +285,7 @@ public class EffSetPathGoal extends Effect { for (EntityData entData : types) { if (!LivingEntity.class.isAssignableFrom(entData.getType())) return; - String className = entData.getType().getClass().getSimpleName(); + String className = entData.getType().getSimpleName(); if (className.equals("HumanEntity")) { className = "Human"; } else if (className.equals("EntityLiving")) { @@ -297,18 +298,7 @@ public class EffSetPathGoal extends Effect { double spd = (meleeSpeed == null ? 1.0D : meleeSpeed.getSingle(e).doubleValue()); boolean memorize = (meleeMemorize == null ? false : meleeMemorize.getSingle(e)); Class goalMeleeAttack = ReflectionUtils.getNMSClass("PathfinderGoalMeleeAttack"); - for (EntityData entData : types) { - if (!LivingEntity.class.isAssignableFrom(entData.getType())) - return; - String className = entData.getType().getClass().getSimpleName(); - if (className.equals("HumanEntity")) { - className = "Human"; - } else if (className.equals("EntityLiving")) { - className = "Living"; - } - Class nmsClass = ReflectionUtils.getNMSClass("Entity" + className); - newGoals.add(goalMeleeAttack.getConstructor(entCreature, Class.class, double.class, boolean.class).newInstance(nmsEnt, nmsClass, spd, memorize)); - } + newGoals.add(goalMeleeAttack.getConstructor(entCreature, double.class, boolean.class).newInstance(nmsEnt, spd, memorize)); } } else if (mark == 13) { double spd = (moveTargetSpeed == null ? 1.0D : moveTargetSpeed.getSingle(e).doubleValue()); @@ -323,7 +313,7 @@ public class EffSetPathGoal extends Effect { for (EntityData entData : types) { if (!LivingEntity.class.isAssignableFrom(entData.getType())) return; - String className = entData.getType().getClass().getSimpleName(); + String className = entData.getType().getSimpleName(); if (className.equals("HumanEntity")) { className = "Human"; } else if (className.equals("EntityLiving")) { @@ -338,7 +328,7 @@ public class EffSetPathGoal extends Effect { for (EntityData entData : types) { if (!LivingEntity.class.isAssignableFrom(entData.getType())) return; - String className = entData.getType().getClass().getSimpleName(); + String className = entData.getType().getSimpleName(); if (className.equals("HumanEntity")) { className = "Human"; } else if (className.equals("EntityLiving")) { @@ -449,7 +439,7 @@ public class EffSetPathGoal extends Effect { for (EntityData entData : types) { if (!LivingEntity.class.isAssignableFrom(entData.getType())) return; - String className = entData.getType().getClass().getSimpleName(); + String className = entData.getType().getSimpleName(); if (className.equals("HumanEntity")) { className = "Human"; } else if (className.equals("EntityLiving")) { diff --git a/src/me/TheBukor/SkStuff/expressions/ExprGlideState.java b/src/me/TheBukor/SkStuff/expressions/ExprGlideState.java new file mode 100644 index 0000000..6c3e04b --- /dev/null +++ b/src/me/TheBukor/SkStuff/expressions/ExprGlideState.java @@ -0,0 +1,69 @@ +package me.TheBukor.SkStuff.expressions; + +import javax.annotation.Nullable; + +import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; + +import ch.njol.skript.classes.Changer.ChangeMode; +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 ch.njol.util.coll.CollectionUtils; +import net.minecraft.server.v1_9_R1.EntityPlayer; + +public class ExprGlideState extends SimpleExpression { + private Expression player; + + @Override + public boolean isSingle() { + return true; + } + + @Override + public Class getReturnType() { + return Boolean.class; + } + + @SuppressWarnings("unchecked") + @Override + public boolean init(Expression[] expr, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + player = (Expression) expr[0]; + return true; + } + + @Override + public String toString(@Nullable Event e, boolean debug) { + return "elytra gliding state of " + player.toString(e, debug); + } + + @Override + @Nullable + protected Boolean[] get(Event e) { + Player p = player.getSingle(e); + EntityPlayer nmsPlayer = ((CraftPlayer) p).getHandle(); + return new Boolean[] { nmsPlayer.cB() }; + } + + @SuppressWarnings("unchecked") + @Override + @Nullable + public Class[] acceptChange(ChangeMode mode) { + if (mode == ChangeMode.SET) { + return CollectionUtils.array(Boolean.class); + } + return null; + } + + @Override + public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { + Player p = player.getSingle(e); + EntityPlayer nmsPlayer = ((CraftPlayer) p).getHandle(); + if (mode == ChangeMode.SET) { + boolean newValue = (boolean) delta[0]; + nmsPlayer.setFlag(7, newValue); + } + } +} diff --git a/src/me/TheBukor/SkStuff/expressions/ExprMCIdOf.java b/src/me/TheBukor/SkStuff/expressions/ExprMCIdOf.java new file mode 100644 index 0000000..e4e70b1 --- /dev/null +++ b/src/me/TheBukor/SkStuff/expressions/ExprMCIdOf.java @@ -0,0 +1,49 @@ +package me.TheBukor.SkStuff.expressions; + +import javax.annotation.Nullable; + +import org.bukkit.event.Event; +import org.bukkit.inventory.ItemStack; + +import ch.njol.skript.aliases.ItemType; +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 ExprMCIdOf extends SimpleExpression { + private Expression itemType; + + @Override + public boolean isSingle() { + return true; + } + + @Override + public Class getReturnType() { + return String.class; + } + + @SuppressWarnings("unchecked") + @Override + public boolean init(Expression[] expr, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + itemType = (Expression) expr[0]; + return true; + } + + @Override + public String toString(@Nullable Event e, boolean debug) { + return "minecraft id of " + itemType.toString(e, debug); + } + + @SuppressWarnings("deprecation") + @Override + @Nullable + protected String[] get(Event e) { + ItemType type = itemType.getSingle(e); + ItemStack item = new ItemStack(type.getTypes().get(0).getId()); + return new String[] { SkStuff.getNMSMethods().getMCId(item) }; + } + +} diff --git a/src/me/TheBukor/SkStuff/expressions/ExprNBTListIndex.java b/src/me/TheBukor/SkStuff/expressions/ExprNBTListIndex.java index 7cf4395..cadc3d3 100644 --- a/src/me/TheBukor/SkStuff/expressions/ExprNBTListIndex.java +++ b/src/me/TheBukor/SkStuff/expressions/ExprNBTListIndex.java @@ -26,7 +26,7 @@ public class ExprNBTListIndex extends SimpleExpression { @Override public boolean isSingle() { - return false; + return true; } @SuppressWarnings("unchecked") diff --git a/src/me/TheBukor/SkStuff/util/NMSInterface.java b/src/me/TheBukor/SkStuff/util/NMSInterface.java index 08b91a3..04c8c13 100644 --- a/src/me/TheBukor/SkStuff/util/NMSInterface.java +++ b/src/me/TheBukor/SkStuff/util/NMSInterface.java @@ -55,4 +55,6 @@ public interface NMSInterface { public Object convertToNBT(Number number); public Object convertToNBT(String string); + + public String getMCId(ItemStack itemStack); } diff --git a/src/me/TheBukor/SkStuff/util/NMS_v1_7_R4.java b/src/me/TheBukor/SkStuff/util/NMS_v1_7_R4.java index 76834b1..9576693 100644 --- a/src/me/TheBukor/SkStuff/util/NMS_v1_7_R4.java +++ b/src/me/TheBukor/SkStuff/util/NMS_v1_7_R4.java @@ -30,20 +30,21 @@ import ch.njol.skript.classes.Parser; import ch.njol.skript.lang.ParseContext; import ch.njol.skript.registrations.Classes; import ch.njol.util.coll.CollectionUtils; +import net.minecraft.server.v1_7_R4.Item; import net.minecraft.server.v1_7_R4.MojangsonParser; import net.minecraft.server.v1_7_R4.NBTBase; import net.minecraft.server.v1_7_R4.NBTCompressedStreamTools; +import net.minecraft.server.v1_7_R4.NBTTagByte; import net.minecraft.server.v1_7_R4.NBTTagCompound; import net.minecraft.server.v1_7_R4.NBTTagDouble; import net.minecraft.server.v1_7_R4.NBTTagFloat; import net.minecraft.server.v1_7_R4.NBTTagInt; import net.minecraft.server.v1_7_R4.NBTTagList; +import net.minecraft.server.v1_7_R4.NBTTagLong; +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_8_R3.NBTTagByte; -import net.minecraft.server.v1_8_R3.NBTTagLong; -import net.minecraft.server.v1_8_R3.NBTTagShort; public class NMS_v1_7_R4 implements NMSInterface { @@ -456,48 +457,33 @@ public class NMS_v1_7_R4 implements NMSInterface { } } - public NBTTagByte convertToNBT(byte b) { - return new NBTTagByte(b); - } - - public NBTTagShort convertToNBT(short s) { - return new NBTTagShort(s); - } - - public NBTTagInt convertToNBT(int i) { - return new NBTTagInt(i); - } - - public NBTTagLong convertToNBT(long l) { - return new NBTTagLong(l); - } - - public NBTTagFloat convertToNBT(float f) { - return new NBTTagFloat(f); - } - - public NBTTagDouble convertToNBT(double d) { - return new NBTTagDouble(d); + @Override + public NBTBase convertToNBT(Number number) { + if (number instanceof Byte) { + return new NBTTagByte((byte) number); + } else if (number instanceof Short) { + return new NBTTagShort((short) number); + } else if (number instanceof Integer) { + return new NBTTagInt((int) number); + } else if (number instanceof Long) { + return new NBTTagLong((long) number); + } else if (number instanceof Float) { + return new NBTTagFloat((float) number); + } else if (number instanceof Double) { + return new NBTTagDouble((double) number); + } + return null; } + @Override public NBTTagString convertToNBT(String string) { return new NBTTagString(string); } @Override - public Object convertToNBT(Number number) { - if (number instanceof Byte) - return convertToNBT((byte) number); - else if (number instanceof Short) - return convertToNBT((short) number); - else if (number instanceof Integer) - return convertToNBT((int) number); - else if (number instanceof Long) - return convertToNBT((long) number); - else if (number instanceof Float) - return convertToNBT((float) number); - else if (number instanceof Double) - return convertToNBT((double) number); - return number; + public String getMCId(ItemStack itemStack) { + net.minecraft.server.v1_7_R4.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); + String test = Item.REGISTRY.c(nmsItem.getItem()); + return test; } } \ No newline at end of file diff --git a/src/me/TheBukor/SkStuff/util/NMS_v1_8_R1.java b/src/me/TheBukor/SkStuff/util/NMS_v1_8_R1.java index 15a878b..d144ab0 100644 --- a/src/me/TheBukor/SkStuff/util/NMS_v1_8_R1.java +++ b/src/me/TheBukor/SkStuff/util/NMS_v1_8_R1.java @@ -48,6 +48,8 @@ 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 { @@ -560,4 +562,11 @@ public class NMS_v1_8_R1 implements NMSInterface { public NBTTagString convertToNBT(String string) { return new NBTTagString(string); } + + @Override + public String getMCId(ItemStack itemStack) { + net.minecraft.server.v1_8_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); + MinecraftKey mcKey = (MinecraftKey) Item.REGISTRY.c(nmsItem.getItem()); + return mcKey.toString(); + } } \ No newline at end of file diff --git a/src/me/TheBukor/SkStuff/util/NMS_v1_8_R2.java b/src/me/TheBukor/SkStuff/util/NMS_v1_8_R2.java index 92c0869..430bcbd 100644 --- a/src/me/TheBukor/SkStuff/util/NMS_v1_8_R2.java +++ b/src/me/TheBukor/SkStuff/util/NMS_v1_8_R2.java @@ -50,6 +50,8 @@ 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 { @@ -566,4 +568,11 @@ public class NMS_v1_8_R2 implements NMSInterface { public NBTTagString convertToNBT(String string) { return new NBTTagString(string); } + + @Override + public String getMCId(ItemStack itemStack) { + net.minecraft.server.v1_8_R2.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); + MinecraftKey mcKey = Item.REGISTRY.c(nmsItem.getItem()); + return mcKey.toString(); + } } \ No newline at end of file diff --git a/src/me/TheBukor/SkStuff/util/NMS_v1_8_R3.java b/src/me/TheBukor/SkStuff/util/NMS_v1_8_R3.java index 0f09b2d..ced3578 100644 --- a/src/me/TheBukor/SkStuff/util/NMS_v1_8_R3.java +++ b/src/me/TheBukor/SkStuff/util/NMS_v1_8_R3.java @@ -50,6 +50,8 @@ 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 { @@ -566,4 +568,11 @@ public class NMS_v1_8_R3 implements NMSInterface { public NBTTagString convertToNBT(String string) { return new NBTTagString(string); } + + @Override + public String getMCId(ItemStack itemStack) { + net.minecraft.server.v1_8_R3.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); + MinecraftKey mcKey = Item.REGISTRY.c(nmsItem.getItem()); + return mcKey.toString(); + } } \ No newline at end of file diff --git a/src/me/TheBukor/SkStuff/util/NMS_v1_9_R1.java b/src/me/TheBukor/SkStuff/util/NMS_v1_9_R1.java index 5239fdc..4d09a87 100644 --- a/src/me/TheBukor/SkStuff/util/NMS_v1_9_R1.java +++ b/src/me/TheBukor/SkStuff/util/NMS_v1_9_R1.java @@ -11,11 +11,9 @@ import java.io.OutputStream; import java.io.StreamCorruptedException; import java.util.Iterator; import java.util.LinkedHashSet; -import java.util.List; import javax.annotation.Nullable; -import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_9_R1.CraftWorld; @@ -36,6 +34,8 @@ import ch.njol.yggdrasil.Fields; import net.minecraft.server.v1_9_R1.BlockPosition; import net.minecraft.server.v1_9_R1.EntityInsentient; import net.minecraft.server.v1_9_R1.IBlockData; +import net.minecraft.server.v1_9_R1.Item; +import net.minecraft.server.v1_9_R1.MinecraftKey; import net.minecraft.server.v1_9_R1.MojangsonParseException; import net.minecraft.server.v1_9_R1.MojangsonParser; import net.minecraft.server.v1_9_R1.NBTBase; @@ -171,7 +171,7 @@ public class NMS_v1_9_R1 implements NMSInterface { if (entity instanceof EntityInsentient) { ((EntityInsentient) entity).setGoalTarget(null); if (isTargetSelector) { - Iterator goals = ((List) ReflectionUtils.getField("b", PathfinderGoalSelector.class, ((EntityInsentient) entity).targetSelector)).iterator(); + Iterator goals = ((LinkedHashSet) ReflectionUtils.getField("b", PathfinderGoalSelector.class, ((EntityInsentient) entity).targetSelector)).iterator(); while (goals.hasNext()) { Object goal = goals.next(); if (ReflectionUtils.getField("a", goal.getClass(), goal).getClass() == goalClass) { @@ -179,7 +179,7 @@ public class NMS_v1_9_R1 implements NMSInterface { } } } else { - Iterator goals = ((List) ReflectionUtils.getField("b", PathfinderGoalSelector.class, ((EntityInsentient) entity).goalSelector)).iterator(); + Iterator goals = ((LinkedHashSet) ReflectionUtils.getField("b", PathfinderGoalSelector.class, ((EntityInsentient) entity).goalSelector)).iterator(); while (goals.hasNext()) { Object goal = goals.next(); if (ReflectionUtils.getField("a", goal.getClass(), goal).getClass() == goalClass) { @@ -208,26 +208,15 @@ public class NMS_v1_9_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) { - Bukkit.broadcastMessage("Changing a compound"); - if (mode == ChangeMode.SET) { - Bukkit.broadcastMessage("is setting"); - 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) { - Bukkit.broadcastMessage("is adding"); + if (mode == ChangeMode.ADD) { if (delta[0] instanceof String) { NBTTagCompound parsedNBT = null; parsedNBT = parseRawNBT((String) delta[0]); @@ -236,7 +225,6 @@ public class NMS_v1_9_R1 implements NMSInterface { addToCompound(NBT[0], delta[0]); } } else if (mode == ChangeMode.REMOVE) { - Bukkit.broadcastMessage("is removing"); if (delta[0] instanceof NBTTagCompound) return; for (Object s : delta) { @@ -322,7 +310,7 @@ public class NMS_v1_9_R1 implements NMSInterface { @Override @Nullable public Class[] acceptChange(ChangeMode mode) { - if (mode == ChangeMode.ADD || mode == ChangeMode.SET || mode == ChangeMode.DELETE || mode == ChangeMode.RESET) { + 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; @@ -330,46 +318,16 @@ public class NMS_v1_9_R1 implements NMSInterface { @Override public void change(NBTTagList[] nbtList, @Nullable Object[] delta, ChangeMode mode) { - Bukkit.broadcastMessage("Changing a NBTList"); - 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 { - Bukkit.broadcastMessage("No compatible class: " + delta.getClass() + "\nStopping..."); + if (delta.length == 0) return; - } - if (mode == ChangeMode.SET) { - Bukkit.broadcastMessage("is setting"); - 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]); + 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]); } - } else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) { - Bukkit.broadcastMessage("Is deleting/resetting"); - nbtList[0] = new NBTTagList(); } } }).parser(new Parser() { @@ -558,6 +516,7 @@ public class NMS_v1_9_R1 implements NMSInterface { } } + @Override public NBTBase convertToNBT(Number number) { if (number instanceof Byte) { return new NBTTagByte((byte) number); @@ -575,7 +534,15 @@ public class NMS_v1_9_R1 implements NMSInterface { return null; } + @Override public NBTTagString convertToNBT(String string) { return new NBTTagString(string); } + + @Override + public String getMCId(ItemStack itemStack) { + net.minecraft.server.v1_9_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); + MinecraftKey mcKey = Item.REGISTRY.b(nmsItem.getItem()); + return mcKey.toString(); + } } \ No newline at end of file