1.6.3 final commit. Some new effects/expressions.

This commit is contained in:
TheBukor
2016-04-03 00:49:25 -03:00
parent 7d938de291
commit 226d0dc931
20 changed files with 785 additions and 271 deletions

View File

@@ -1,63 +1,92 @@
package me.TheBukor.SkStuff.util;
import java.io.File;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public interface NMSInterface {
public void addToCompound(Object compound, Object toAdd);
public void removeFromCompound(Object compound, String ... toRemove);
public Object parseRawNBT(String rawNBT);
public Object[] getContents(Object nbtList);
public void addToList(Object nbtList, Object toAdd);
public void removeFromList(Object nbtList, int index);
public void setIndex(Object nbtList, int index, Object toSet);
public Object getIndex(Object nbtList, int index);
public void clearPathfinderGoals(Entity entity);
public void removePathfinderGoal(Object entity, Class<?> goalClass, boolean isTargetSelector);
public void addPathfinderGoal(Object entity, int priority, Object goal, boolean isTargetSelector);
public void registerCompoundClassInfo();
public void registerNBTListClassInfo();
public Object getEntityNBT(Entity entity);
public Object getTileNBT(Block block);
public Object getItemNBT(ItemStack itemStack);
public void setEntityNBT(Entity entity, Object newCompound);
public void setTileNBT(Block block, Object newCompound);
public ItemStack getItemWithNBT(ItemStack itemStack, Object compound);
public Object getFileNBT(File file);
public void setFileNBT(File file, Object newCompound);
public Object convertToNBT(Number number);
public Object convertToNBT(String string);
public String getMCId(ItemStack itemStack);
public ItemStack getItemFromMcId(String mcId);
void makeClientSay(String msg, Player p);
}
package me.TheBukor.SkStuff.util;
import java.io.File;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
public interface NMSInterface {
public Object getNBTTag(Object compound, String tag);
public void setNBTTag(Object compound, String tag, Object toSet);
public void removeNBTTag(Object compound, String tag);
public byte getTypeId(Object nbtBase);
public Object getNBTTagValue(Object compound, String tag, byte typeId);
public void addToCompound(Object compound, Object toAdd);
public void removeFromCompound(Object compound, String ... toRemove);
public Object parseRawNBT(String rawNBT);
public Object[] getContents(Object nbtList);
public void addToList(Object nbtList, Object toAdd);
public void removeFromList(Object nbtList, int index);
public void setIndex(Object nbtList, int index, Object toSet);
public Object getIndex(Object nbtList, int index);
public void clearPathfinderGoals(Entity entity);
public void removePathfinderGoal(Object entity, Class<?> goalClass, boolean isTargetSelector);
public void addPathfinderGoal(Object entity, int priority, Object goal, boolean isTargetSelector);
public void registerCompoundClassInfo();
public void registerNBTListClassInfo();
public Object getEntityNBT(Entity entity);
public Object getTileNBT(Block block);
public Object getItemNBT(ItemStack itemStack);
public void setEntityNBT(Entity entity, Object newCompound);
public void setTileNBT(Block block, Object newCompound);
public ItemStack getItemWithNBT(ItemStack itemStack, Object compound);
public Object getFileNBT(File file);
public void setFileNBT(File file, Object newCompound);
public Object convertToNBT(Number number);
public Object convertToNBT(String string);
public String getMCId(ItemStack itemStack);
public ItemStack getItemFromMcId(String mcId);
public boolean getNoClip(Entity entity);
public void setNoClip(Entity entity, boolean noclip);
public boolean getFireProof(Entity entity);
public void setFireProof(Entity entity, boolean fireProof);
/*
public ItemStack[] getEndermanBlocks(Entity enderman);
public void setEndermanBlocks(Entity enderman, ItemStack... blocks);
*/
public Location getLastLocation(Entity entity);
public float getEntityStepLength(Entity entity);
public void setEntityStepLength(Entity entity, float length);
}

View File

@@ -17,14 +17,13 @@ import java.util.Set;
import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import ch.njol.skript.Skript;
@@ -51,10 +50,89 @@ 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_7_R4.PacketPlayInChat;
public class NMS_v1_7_R4 implements NMSInterface {
@Override
public Object getNBTTag(Object compound, String tag) {
if (compound instanceof NBTTagCompound) {
return ((NBTTagCompound) compound).get(tag);
}
return null;
}
@Override
public void setNBTTag(Object compound, String tag, Object toSet) {
if (compound instanceof NBTTagCompound && (toSet instanceof NBTBase || toSet instanceof Number || toSet instanceof String)) {
NBTBase converted = null;
if (toSet instanceof Number) {
converted = convertToNBT((Number) toSet);
} else if (toSet instanceof String) {
converted = convertToNBT((String) toSet);
} else { //Already an NBTBase
converted = (NBTBase) toSet; //No need to convert anything
}
((NBTTagCompound) compound).set(tag, converted);
}
}
@Override
public void removeNBTTag(Object compound, String tag) {
if (compound instanceof NBTTagCompound) {
((NBTTagCompound) compound).remove(tag);
}
}
@Override
public byte getTypeId(Object nbtBase) {
if (nbtBase instanceof NBTBase) {
return ((NBTBase) nbtBase).getTypeId();
}
return 0;
}
@Override
public Object getNBTTagValue(Object compound, String tag, byte typeId) {
if (compound instanceof NBTTagCompound) {
switch (typeId) {
case 1:
return ((NBTTagCompound) compound).getByte(tag);
case 2:
return ((NBTTagCompound) compound).getShort(tag);
case 3:
return ((NBTTagCompound) compound).getInt(tag);
case 4:
return ((NBTTagCompound) compound).getLong(tag);
case 5:
return ((NBTTagCompound) compound).getFloat(tag);
case 6:
return ((NBTTagCompound) compound).getDouble(tag);
case 7: //Byte array, only used in chunk files. Also doesn't have support for the MojangsonParser.
break;
case 8:
return ((NBTTagCompound) compound).getString(tag);
case 9:
int i;
NBTTagList list = null;
for (i = 1; i <= 11; i++) { //To get a list I need to know the type of the tags it contains inside,
//since I can't predict what type the list will have, I just loop all of the IDs until I find a non-empty list.
list = ((NBTTagCompound) compound).getList(tag, i); //Try to get the list with the ID "loop-number".
if (!list.toString().equals("[]")) { //If list is not empty.
break; //Stop loop.
}
}
return list; //May be null
case 10:
return ((NBTTagCompound) compound).getCompound(tag);
case 11: //Integer array, this one is only used on the chunk files (and maybe schematic files?).
return ((NBTTagCompound) compound).getIntArray(tag);
default: //This should never happen, but it's better to have this just in case it spills errors everywhere.
break;
}
}
return null;
}
@SuppressWarnings("unchecked")
@Override
public void addToCompound(Object compound, Object toAdd) {
@@ -496,8 +574,44 @@ public class NMS_v1_7_R4 implements NMSInterface {
}
@Override
public void makeClientSay(String msg, Player p) {
PacketPlayInChat chatPacket = new PacketPlayInChat(msg);
((CraftPlayer) p).getHandle().playerConnection.a(chatPacket);
public boolean getNoClip(Entity entity) {
return false; //Not supported in 1.7
}
@Override
public void setNoClip(Entity entity, boolean noclip) {
return; //Not supported in 1.7
}
@Override
public boolean getFireProof(Entity entity) {
net.minecraft.server.v1_7_R4.Entity nmsEntity = ((CraftEntity) entity).getHandle();
return (boolean) ReflectionUtils.getField("fireProof", nmsEntity.getClass(), nmsEntity);
}
@Override
public void setFireProof(Entity entity, boolean fireProof) {
net.minecraft.server.v1_7_R4.Entity nmsEntity = ((CraftEntity) entity).getHandle();
ReflectionUtils.setField("fireProof", nmsEntity.getClass(), nmsEntity, fireProof);
}
@Override
public Location getLastLocation(Entity entity) {
net.minecraft.server.v1_7_R4.Entity nmsEntity = ((CraftEntity) entity).getHandle();
org.bukkit.World world = nmsEntity.world.getWorld();
Location lastEntLoc = new Location(world, nmsEntity.S, nmsEntity.T, nmsEntity.U);
return lastEntLoc;
}
@Override
public float getEntityStepLength(Entity entity) {
net.minecraft.server.v1_7_R4.Entity nmsEntity = ((CraftEntity) entity).getHandle();
return nmsEntity.V;
}
@Override
public void setEntityStepLength(Entity entity, float length) {
net.minecraft.server.v1_7_R4.Entity nmsEntity = ((CraftEntity) entity).getHandle();
nmsEntity.V = length;
}
}

View File

@@ -14,14 +14,13 @@ import java.util.List;
import javax.annotation.Nullable;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import ch.njol.skript.Skript;
@@ -54,10 +53,89 @@ 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.PacketPlayInChat;
public class NMS_v1_8_R3 implements NMSInterface {
@Override
public Object getNBTTag(Object compound, String tag) {
if (compound instanceof NBTTagCompound) {
return ((NBTTagCompound) compound).get(tag);
}
return null;
}
@Override
public void setNBTTag(Object compound, String tag, Object toSet) {
if (compound instanceof NBTTagCompound && (toSet instanceof NBTBase || toSet instanceof Number || toSet instanceof String)) {
NBTBase converted = null;
if (toSet instanceof Number) {
converted = convertToNBT((Number) toSet);
} else if (toSet instanceof String) {
converted = convertToNBT((String) toSet);
} else { //Already an NBTBase
converted = (NBTBase) toSet; //No need to convert anything
}
((NBTTagCompound) compound).set(tag, converted);
}
}
@Override
public void removeNBTTag(Object compound, String tag) {
if (compound instanceof NBTTagCompound) {
((NBTTagCompound) compound).remove(tag);
}
}
@Override
public byte getTypeId(Object nbtBase) {
if (nbtBase instanceof NBTBase) {
return ((NBTBase) nbtBase).getTypeId();
}
return 0;
}
@Override
public Object getNBTTagValue(Object compound, String tag, byte typeId) {
if (compound instanceof NBTTagCompound) {
switch (typeId) {
case 1:
return ((NBTTagCompound) compound).getByte(tag);
case 2:
return ((NBTTagCompound) compound).getShort(tag);
case 3:
return ((NBTTagCompound) compound).getInt(tag);
case 4:
return ((NBTTagCompound) compound).getLong(tag);
case 5:
return ((NBTTagCompound) compound).getFloat(tag);
case 6:
return ((NBTTagCompound) compound).getDouble(tag);
case 7: //Byte array, only used in chunk files. Also doesn't have support for the MojangsonParser.
break;
case 8:
return ((NBTTagCompound) compound).getString(tag);
case 9:
int i;
NBTTagList list = null;
for (i = 1; i <= 11; i++) { //To get a list I need to know the type of the tags it contains inside,
//since I can't predict what type the list will have, I just loop all of the IDs until I find a non-empty list.
list = ((NBTTagCompound) compound).getList(tag, i); //Try to get the list with the ID "loop-number".
if (!list.isEmpty()) { //If list is not empty.
break; //Stop loop.
}
}
return list; //May be null
case 10:
return ((NBTTagCompound) compound).getCompound(tag);
case 11: //Integer array, this one is only used on the chunk files (and maybe schematic files?).
return ((NBTTagCompound) compound).getIntArray(tag);
default: //This should never happen, but it's better to have this just in case it spills errors everywhere.
break;
}
}
return null;
}
@Override
public void addToCompound(Object compound, Object toAdd) {
if (compound instanceof NBTTagCompound && toAdd instanceof NBTTagCompound) {
@@ -538,8 +616,46 @@ public class NMS_v1_8_R3 implements NMSInterface {
}
@Override
public void makeClientSay(String msg, Player p) {
PacketPlayInChat chatPacket = new PacketPlayInChat(msg);
((CraftPlayer) p).getHandle().playerConnection.a(chatPacket);
public boolean getNoClip(Entity entity) {
net.minecraft.server.v1_8_R3.Entity nmsEntity = ((CraftEntity) entity).getHandle();
return nmsEntity.noclip;
}
@Override
public void setNoClip(Entity entity, boolean noclip) {
net.minecraft.server.v1_8_R3.Entity nmsEntity = ((CraftEntity) entity).getHandle();
nmsEntity.noclip = noclip;
}
@Override
public boolean getFireProof(Entity entity) {
net.minecraft.server.v1_8_R3.Entity nmsEntity = ((CraftEntity) entity).getHandle();
return nmsEntity.isFireProof();
}
@Override
public void setFireProof(Entity entity, boolean fireProof) {
net.minecraft.server.v1_8_R3.Entity nmsEntity = ((CraftEntity) entity).getHandle();
ReflectionUtils.setField("fireProof", nmsEntity.getClass(), nmsEntity, fireProof);
}
@Override
public Location getLastLocation(Entity entity) {
net.minecraft.server.v1_8_R3.Entity nmsEntity = ((CraftEntity) entity).getHandle();
org.bukkit.World world = nmsEntity.world.getWorld();
Location lastEntLoc = new Location(world, nmsEntity.P, nmsEntity.Q, nmsEntity.R);
return lastEntLoc;
}
@Override
public float getEntityStepLength(Entity entity) {
net.minecraft.server.v1_8_R3.Entity nmsEntity = ((CraftEntity) entity).getHandle();
return nmsEntity.S;
}
@Override
public void setEntityStepLength(Entity entity, float length) {
net.minecraft.server.v1_8_R3.Entity nmsEntity = ((CraftEntity) entity).getHandle();
nmsEntity.S = length;
}
}

View File

@@ -14,14 +14,13 @@ import java.util.LinkedHashSet;
import javax.annotation.Nullable;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_9_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import ch.njol.skript.Skript;
@@ -51,7 +50,6 @@ import net.minecraft.server.v1_9_R1.NBTTagList;
import net.minecraft.server.v1_9_R1.NBTTagLong;
import net.minecraft.server.v1_9_R1.NBTTagShort;
import net.minecraft.server.v1_9_R1.NBTTagString;
import net.minecraft.server.v1_9_R1.PacketPlayInChat;
import net.minecraft.server.v1_9_R1.PathfinderGoal;
import net.minecraft.server.v1_9_R1.PathfinderGoalSelector;
import net.minecraft.server.v1_9_R1.TileEntity;
@@ -59,6 +57,86 @@ import net.minecraft.server.v1_9_R1.World;
public class NMS_v1_9_R1 implements NMSInterface {
@Override
public Object getNBTTag(Object compound, String tag) {
if (compound instanceof NBTTagCompound) {
return ((NBTTagCompound) compound).get(tag);
}
return null;
}
@Override
public void setNBTTag(Object compound, String tag, Object toSet) {
if (compound instanceof NBTTagCompound && (toSet instanceof NBTBase || toSet instanceof Number || toSet instanceof String)) {
NBTBase converted = null;
if (toSet instanceof Number) {
converted = convertToNBT((Number) toSet);
} else if (toSet instanceof String) {
converted = convertToNBT((String) toSet);
} else { //Already an NBTBase
converted = (NBTBase) toSet; //No need to convert anything
}
((NBTTagCompound) compound).set(tag, converted);
}
}
@Override
public void removeNBTTag(Object compound, String tag) {
if (compound instanceof NBTTagCompound) {
((NBTTagCompound) compound).remove(tag);
}
}
@Override
public byte getTypeId(Object nbtBase) {
if (nbtBase instanceof NBTBase) {
return ((NBTBase) nbtBase).getTypeId();
}
return 0;
}
@Override
public Object getNBTTagValue(Object compound, String tag, byte typeId) {
if (compound instanceof NBTTagCompound) {
switch (typeId) {
case 1:
return ((NBTTagCompound) compound).getByte(tag);
case 2:
return ((NBTTagCompound) compound).getShort(tag);
case 3:
return ((NBTTagCompound) compound).getInt(tag);
case 4:
return ((NBTTagCompound) compound).getLong(tag);
case 5:
return ((NBTTagCompound) compound).getFloat(tag);
case 6:
return ((NBTTagCompound) compound).getDouble(tag);
case 7: //Byte array, only used in chunk files. Also doesn't have support for the MojangsonParser.
break;
case 8:
return ((NBTTagCompound) compound).getString(tag);
case 9:
int i;
NBTTagList list = null;
for (i = 1; i <= 11; i++) { //To get a list I need to know the type of the tags it contains inside,
//since I can't predict what type the list will have, I just loop all of the IDs until I find a non-empty list.
list = ((NBTTagCompound) compound).getList(tag, i); //Try to get the list with the ID "loop-number".
if (!list.isEmpty()) { //If list is not empty.
break; //Stop loop.
}
}
return list; //May be null
case 10:
return ((NBTTagCompound) compound).getCompound(tag);
case 11: //Integer array, this one is only used on the chunk files (and maybe schematic files?).
return ((NBTTagCompound) compound).getIntArray(tag);
default: //This should never happen, but it's better to have this just in case it spills errors everywhere.
break;
}
}
return null;
}
@Override
public void addToCompound(Object compound, Object toAdd) {
if (compound instanceof NBTTagCompound && toAdd instanceof NBTTagCompound) {
@@ -541,8 +619,79 @@ public class NMS_v1_9_R1 implements NMSInterface {
}
@Override
public void makeClientSay(String msg, Player p) {
PacketPlayInChat chatPacket = new PacketPlayInChat(msg);
((CraftPlayer) p).getHandle().playerConnection.a(chatPacket);
public boolean getNoClip(Entity entity) {
net.minecraft.server.v1_9_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
return nmsEntity.noclip;
}
@Override
public void setNoClip(Entity entity, boolean noclip) {
net.minecraft.server.v1_9_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
nmsEntity.noclip = noclip;
}
@Override
public boolean getFireProof(Entity entity) {
net.minecraft.server.v1_9_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
return nmsEntity.isFireProof();
}
@Override
public void setFireProof(Entity entity, boolean fireProof) {
net.minecraft.server.v1_9_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
ReflectionUtils.setField("fireProof", nmsEntity.getClass(), nmsEntity, fireProof);
}
/*
@SuppressWarnings("unchecked")
@Override
public ItemStack[] getEndermanBlocks(Entity enderman) {
EntityEnderman nmsEnder = ((CraftEnderman) enderman).getHandle();
Set<net.minecraft.server.v1_9_R1.Block> nmsBlocks = (Set<net.minecraft.server.v1_9_R1.Block>) ReflectionUtils.getField("c", EntityEnderman.class, nmsEnder);
ItemStack[] items = new ItemStack[nmsBlocks.size()];
int i = 0;
for (net.minecraft.server.v1_9_R1.Block nmsBlock : nmsBlocks) {
IBlockData nmsBlockData = nmsBlock.getBlockData();
int dataValue = nmsBlock.toLegacyData(nmsBlockData);
net.minecraft.server.v1_9_R1.ItemStack nmsItem = new net.minecraft.server.v1_9_R1.ItemStack(nmsBlock, 1, dataValue);
ItemStack bukkitItem = CraftItemStack.asCraftMirror(nmsItem);
items[i] = bukkitItem;
i++;
}
return items;
}
@SuppressWarnings("unchecked")
@Override
public void setEndermanBlocks(Entity enderman, ItemStack... blocks) {
EntityEnderman nmsEnder = ((CraftEnderman) enderman).getHandle();
Set<net.minecraft.server.v1_9_R1.Block> nmsBlocks = (Set<net.minecraft.server.v1_9_R1.Block>) ReflectionUtils.getField("c", EntityEnderman.class, nmsEnder);
for (ItemStack block : blocks) {
if (!block.getType().isBlock())
return;
// TODO Figure out how to get a Blocks from a Bukkit ItemStack
// Blocks.class has a PRIVATE method to get from a MC id.
}
}
*/
@Override
public Location getLastLocation(Entity entity) {
net.minecraft.server.v1_9_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
org.bukkit.World world = nmsEntity.world.getWorld();
Location lastEntLoc = new Location(world, nmsEntity.M, nmsEntity.N, nmsEntity.O);
return lastEntLoc;
}
@Override
public float getEntityStepLength(Entity entity) {
net.minecraft.server.v1_9_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
return nmsEntity.P;
}
@Override
public void setEntityStepLength(Entity entity, float length) {
net.minecraft.server.v1_9_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
nmsEntity.P = length;
}
}