mirror of
https://github.com/libraryaddict/LibsDisguises.git
synced 2025-03-02 04:01:26 +01:00
Convert legacy reflection to its own class, make entity trackers an eyesore
This commit is contained in:
parent
8a07ccff64
commit
66411563cf
@ -149,23 +149,10 @@ public class ReflectionManager extends ReflectionManagerAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AABB getBoundingBox(Entity entity) {
|
||||
return ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
}
|
||||
public double[] getBoundingBox(Entity entity) {
|
||||
AABB aabb = ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
|
||||
@Override
|
||||
public double getXBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxX - getBoundingBox(entity).minX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getYBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxY - getBoundingBox(entity).minY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getZBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxZ - getBoundingBox(entity).minZ;
|
||||
return new double[]{aabb.maxX - aabb.minX, aabb.maxY - aabb.minY, aabb.maxZ - aabb.minZ};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -150,23 +150,10 @@ public class ReflectionManager extends ReflectionManagerAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AABB getBoundingBox(Entity entity) {
|
||||
return ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
}
|
||||
public double[] getBoundingBox(Entity entity) {
|
||||
AABB aabb = ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
|
||||
@Override
|
||||
public double getXBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxX - getBoundingBox(entity).minX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getYBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxY - getBoundingBox(entity).minY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getZBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxZ - getBoundingBox(entity).minZ;
|
||||
return new double[]{aabb.maxX - aabb.minX, aabb.maxY - aabb.minY, aabb.maxZ - aabb.minZ};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -151,23 +151,10 @@ public class ReflectionManager extends ReflectionManagerAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AABB getBoundingBox(Entity entity) {
|
||||
return ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
}
|
||||
public double[] getBoundingBox(Entity entity) {
|
||||
AABB aabb = ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
|
||||
@Override
|
||||
public double getXBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxX - getBoundingBox(entity).minX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getYBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxY - getBoundingBox(entity).minY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getZBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxZ - getBoundingBox(entity).minZ;
|
||||
return new double[]{aabb.maxX - aabb.minX, aabb.maxY - aabb.minY, aabb.maxZ - aabb.minZ};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -151,23 +151,10 @@ public class ReflectionManager extends ReflectionManagerAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AABB getBoundingBox(Entity entity) {
|
||||
return ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
}
|
||||
public double[] getBoundingBox(Entity entity) {
|
||||
AABB aabb = ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
|
||||
@Override
|
||||
public double getXBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxX - getBoundingBox(entity).minX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getYBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxY - getBoundingBox(entity).minY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getZBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxZ - getBoundingBox(entity).minZ;
|
||||
return new double[]{aabb.maxX - aabb.minX, aabb.maxY - aabb.minY, aabb.maxZ - aabb.minZ};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -167,23 +167,10 @@ public class ReflectionManager extends ReflectionManagerAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AABB getBoundingBox(Entity entity) {
|
||||
return ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
}
|
||||
public double[] getBoundingBox(Entity entity) {
|
||||
AABB aabb = ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
|
||||
@Override
|
||||
public double getXBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxX - getBoundingBox(entity).minX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getYBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxY - getBoundingBox(entity).minY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getZBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxZ - getBoundingBox(entity).minZ;
|
||||
return new double[]{aabb.maxX - aabb.minX, aabb.maxY - aabb.minY, aabb.maxZ - aabb.minZ};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -162,23 +162,10 @@ public class ReflectionManager extends ReflectionManagerAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AABB getBoundingBox(Entity entity) {
|
||||
return ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
}
|
||||
public double[] getBoundingBox(Entity entity) {
|
||||
AABB aabb = ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
|
||||
@Override
|
||||
public double getXBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxX - getBoundingBox(entity).minX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getYBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxY - getBoundingBox(entity).minY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getZBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxZ - getBoundingBox(entity).minZ;
|
||||
return new double[]{aabb.maxX - aabb.minX, aabb.maxY - aabb.minY, aabb.maxZ - aabb.minZ};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -94,7 +94,6 @@ public class ReflectionManager extends ReflectionManagerAbstract {
|
||||
|
||||
Class<?> aClass = Class.forName("org.bukkit.craftbukkit.v1_20_R1.inventory.CraftMetaItem$SerializableMeta");
|
||||
itemMetaDeserialize = aClass.getDeclaredMethod("deserialize", Map.class);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -163,23 +162,10 @@ public class ReflectionManager extends ReflectionManagerAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AABB getBoundingBox(Entity entity) {
|
||||
return ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
}
|
||||
public double[] getBoundingBox(Entity entity) {
|
||||
AABB aabb = ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
|
||||
@Override
|
||||
public double getXBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxX - getBoundingBox(entity).minX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getYBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxY - getBoundingBox(entity).minY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getZBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxZ - getBoundingBox(entity).minZ;
|
||||
return new double[]{aabb.maxX - aabb.minX, aabb.maxY - aabb.minY, aabb.maxZ - aabb.minZ};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -173,23 +173,10 @@ public class ReflectionManager extends ReflectionManagerAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AABB getBoundingBox(Entity entity) {
|
||||
return ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
}
|
||||
public double[] getBoundingBox(Entity entity) {
|
||||
AABB aabb = ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
|
||||
@Override
|
||||
public double getXBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxX - getBoundingBox(entity).minX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getYBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxY - getBoundingBox(entity).minY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getZBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxZ - getBoundingBox(entity).minZ;
|
||||
return new double[]{aabb.maxX - aabb.minX, aabb.maxY - aabb.minY, aabb.maxZ - aabb.minZ};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -174,23 +174,10 @@ public class ReflectionManager extends ReflectionManagerAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AABB getBoundingBox(Entity entity) {
|
||||
return ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
}
|
||||
public double[] getBoundingBox(Entity entity) {
|
||||
AABB aabb = ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
|
||||
@Override
|
||||
public double getXBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxX - getBoundingBox(entity).minX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getYBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxY - getBoundingBox(entity).minY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getZBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxZ - getBoundingBox(entity).minZ;
|
||||
return new double[]{aabb.maxX - aabb.minX, aabb.maxY - aabb.minY, aabb.maxZ - aabb.minZ};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -174,23 +174,10 @@ public class ReflectionManager extends ReflectionManagerAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AABB getBoundingBox(Entity entity) {
|
||||
return ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
}
|
||||
public double[] getBoundingBox(Entity entity) {
|
||||
AABB aabb = ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
|
||||
@Override
|
||||
public double getXBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxX - getBoundingBox(entity).minX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getYBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxY - getBoundingBox(entity).minY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getZBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxZ - getBoundingBox(entity).minZ;
|
||||
return new double[]{aabb.maxX - aabb.minX, aabb.maxY - aabb.minY, aabb.maxZ - aabb.minZ};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -174,23 +174,10 @@ public class ReflectionManager extends ReflectionManagerAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AABB getBoundingBox(Entity entity) {
|
||||
return ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
}
|
||||
public double[] getBoundingBox(Entity entity) {
|
||||
AABB aabb = ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
|
||||
@Override
|
||||
public double getXBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxX - getBoundingBox(entity).minX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getYBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxY - getBoundingBox(entity).minY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getZBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxZ - getBoundingBox(entity).minZ;
|
||||
return new double[]{aabb.maxX - aabb.minX, aabb.maxY - aabb.minY, aabb.maxZ - aabb.minZ};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -176,23 +176,10 @@ public class ReflectionManager extends ReflectionManagerAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AABB getBoundingBox(Entity entity) {
|
||||
return ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
}
|
||||
public double[] getBoundingBox(Entity entity) {
|
||||
AABB aabb = ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
|
||||
@Override
|
||||
public double getXBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxX - getBoundingBox(entity).minX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getYBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxY - getBoundingBox(entity).minY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getZBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxZ - getBoundingBox(entity).minZ;
|
||||
return new double[]{aabb.maxX - aabb.minX, aabb.maxY - aabb.minY, aabb.maxZ - aabb.minZ};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -176,23 +176,10 @@ public class ReflectionManager extends ReflectionManagerAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AABB getBoundingBox(Entity entity) {
|
||||
return ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
}
|
||||
public double[] getBoundingBox(Entity entity) {
|
||||
AABB aabb = ((CraftEntity) entity).getHandle().getBoundingBox();
|
||||
|
||||
@Override
|
||||
public double getXBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxX - getBoundingBox(entity).minX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getYBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxY - getBoundingBox(entity).minY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getZBoundingBox(Entity entity) {
|
||||
return getBoundingBox(entity).maxZ - getBoundingBox(entity).minZ;
|
||||
return new double[]{aabb.maxX - aabb.minX, aabb.maxY - aabb.minY, aabb.maxZ - aabb.minZ};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -730,7 +730,6 @@ public class DisguiseUtilities {
|
||||
}
|
||||
|
||||
PacketEvents.getAPI().getPlayerManager().sendPacketSilently(player, packet);
|
||||
|
||||
}
|
||||
|
||||
if (NmsVersion.v1_15.isSupported()) {
|
||||
@ -2048,8 +2047,7 @@ public class DisguiseUtilities {
|
||||
}, 2);
|
||||
} else {
|
||||
final Object entityTracker = ReflectionManager.getEntityTracker(disguise.getEntity());
|
||||
final Object entityTrackerEntry = !NmsVersion.v1_14.isSupported() ? entityTracker :
|
||||
ReflectionManager.getEntityTrackerEntry(disguise.getEntity(), entityTracker);
|
||||
final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity(), entityTracker);
|
||||
|
||||
if (entityTrackerEntry == null) {
|
||||
return;
|
||||
@ -2065,7 +2063,7 @@ public class DisguiseUtilities {
|
||||
continue;
|
||||
}
|
||||
|
||||
ReflectionManager.clearEntityTracker(entityTracker, p);
|
||||
ReflectionManager.clearEntityTracker(entityTracker, entityTrackerEntry, p);
|
||||
|
||||
WrapperPlayServerDestroyEntities destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId());
|
||||
|
||||
@ -2073,7 +2071,7 @@ public class DisguiseUtilities {
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
|
||||
try {
|
||||
ReflectionManager.addEntityTracker(entityTracker, p);
|
||||
ReflectionManager.addEntityTracker(entityTracker, entityTrackerEntry, p);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@ -2099,8 +2097,7 @@ public class DisguiseUtilities {
|
||||
if (entity.isValid()) {
|
||||
try {
|
||||
final Object entityTracker = ReflectionManager.getEntityTracker(entity);
|
||||
final Object entityTrackerEntry =
|
||||
NmsVersion.v1_14.isSupported() ? entityTracker : ReflectionManager.getEntityTrackerEntry(entity, entityTracker);
|
||||
final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(entity, entityTracker);
|
||||
|
||||
if (entityTrackerEntry != null) {
|
||||
Set trackedPlayers = ReflectionManager.getClonedTrackedPlayers(entityTracker, entityTrackerEntry);
|
||||
@ -2113,19 +2110,18 @@ public class DisguiseUtilities {
|
||||
continue;
|
||||
}
|
||||
|
||||
ReflectionManager.clearEntityTracker(entityTracker, p);
|
||||
ReflectionManager.clearEntityTracker(entityTracker, entityTrackerEntry, p);
|
||||
|
||||
WrapperPlayServerDestroyEntities destroyPacket = getDestroyPacket(entity.getEntityId());
|
||||
PacketEvents.getAPI().getPlayerManager().sendPacket(player, destroyPacket);
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
|
||||
try {
|
||||
ReflectionManager.addEntityTracker(entityTracker, p);
|
||||
ReflectionManager.addEntityTracker(entityTracker, entityTrackerEntry, p);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}, 2);
|
||||
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
@ -2177,14 +2173,14 @@ public class DisguiseUtilities {
|
||||
continue;
|
||||
}
|
||||
|
||||
ReflectionManager.clearEntityTracker(entityTracker, p);
|
||||
ReflectionManager.clearEntityTracker(entityTracker, entityTrackerEntry, p);
|
||||
|
||||
WrapperPlayServerDestroyEntities destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId());
|
||||
PacketEvents.getAPI().getPlayerManager().sendPacket(player, destroyPacket);
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
|
||||
try {
|
||||
ReflectionManager.addEntityTracker(entityTracker, p);
|
||||
ReflectionManager.addEntityTracker(entityTracker, entityTrackerEntry, p);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
@ -1,16 +1,5 @@
|
||||
package me.libraryaddict.disguise.utilities.reflection;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBT;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTByteArray;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTIntArray;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTList;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTLongArray;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTNumber;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTString;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTType;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -28,25 +17,17 @@ public class ItemStackSerializer {
|
||||
String type = ReflectionManager.getItemName(item.getType());
|
||||
|
||||
if (item.hasItemMeta() && NmsVersion.v1_13.isSupported()) {
|
||||
if (ReflectionManager.getNmsReflection() != null) {
|
||||
String asString = ReflectionManager.getNmsReflection().getDataAsString(item);
|
||||
String asString = ReflectionManager.getNmsReflection().getDataAsString(item);
|
||||
|
||||
if (asString != null && asString.length() > 2) {
|
||||
// Vanilla seems to turn this into a string that contains for UUID
|
||||
// : [I; 772059800,
|
||||
// And there should be no space, so we must strip all spaces that are unneeded.
|
||||
type += stripSpacesFromString(asString);
|
||||
if (asString != null && asString.length() > 2) {
|
||||
// Vanilla seems to turn this into a string that contains for UUID
|
||||
// : [I; 772059800,
|
||||
// And there should be no space, so we must strip all spaces that are unneeded.
|
||||
if (NmsVersion.v1_17.isSupported()) {
|
||||
asString = stripSpacesFromString(asString);
|
||||
}
|
||||
} else {
|
||||
NBT nbt = DisguiseUtilities.fromBukkitItemStack(item).getNBT();
|
||||
|
||||
if (nbt != null) {
|
||||
String asString = serialize(nbt);
|
||||
|
||||
if (asString.length() > 2) {
|
||||
type += asString;
|
||||
}
|
||||
}
|
||||
type += asString;
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,14 +43,10 @@ public class ItemStackSerializer {
|
||||
}
|
||||
|
||||
if (item.hasItemMeta()) {
|
||||
NBT nbt = DisguiseUtilities.fromBukkitItemStack(item).getNBT();
|
||||
String asString = ReflectionManager.getNmsReflection().getDataAsString(item);
|
||||
|
||||
if (nbt != null) {
|
||||
String asString = serialize(nbt);
|
||||
|
||||
if (asString.length() > 2) {
|
||||
mcArray.add(serialize(nbt));
|
||||
}
|
||||
if (asString != null && asString.length() > 2) {
|
||||
mcArray.add(asString);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -101,85 +78,4 @@ public class ItemStackSerializer {
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static String serialize(NBT base) {
|
||||
return serialize(0, base);
|
||||
}
|
||||
|
||||
private static String serialize(int depth, NBT base) {
|
||||
if (base.getType() == NBTType.COMPOUND) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append("{");
|
||||
|
||||
for (String key : ((NBTCompound) base).getTagNames()) {
|
||||
NBT nbt = ((NBTCompound) base).getTagOrThrow(key);
|
||||
String val = serialize(depth + 1, nbt);
|
||||
|
||||
// Skip root empty values
|
||||
if (depth == 0 && val.matches("0(\\.0)?")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (builder.length() > 1) {
|
||||
builder.append(",");
|
||||
}
|
||||
|
||||
builder.append(key).append(":").append(val);
|
||||
}
|
||||
|
||||
builder.append("}");
|
||||
|
||||
return builder.toString();
|
||||
} else if (base.getType() == NBTType.LIST) {
|
||||
List<String> serialized = new ArrayList<>();
|
||||
|
||||
for (NBT something : ((NBTList<NBT>) base).getTags()) {
|
||||
serialized.add(serialize(depth + 1, something));
|
||||
}
|
||||
|
||||
return "[" + StringUtils.join(serialized, ",") + "]";
|
||||
} else if (base.getType() == NBTType.BYTE_ARRAY) {
|
||||
NBTByteArray byteArray = (NBTByteArray) base;
|
||||
List<String> bytes = new ArrayList<>();
|
||||
|
||||
for (byte b : byteArray.getValue()) {
|
||||
bytes.add(String.valueOf(b));
|
||||
}
|
||||
|
||||
return "[B;" + String.join(",", bytes) + "]";
|
||||
}
|
||||
if (base.getType() == NBTType.INT_ARRAY) {
|
||||
NBTIntArray byteArray = (NBTIntArray) base;
|
||||
List<String> bytes = new ArrayList<>();
|
||||
|
||||
for (int b : byteArray.getValue()) {
|
||||
bytes.add(String.valueOf(b));
|
||||
}
|
||||
|
||||
return "[I;" + String.join(",", bytes) + "]";
|
||||
}
|
||||
if (base.getType() == NBTType.LONG_ARRAY) {
|
||||
NBTLongArray byteArray = (NBTLongArray) base;
|
||||
List<String> bytes = new ArrayList<>();
|
||||
|
||||
for (long b : byteArray.getValue()) {
|
||||
bytes.add(String.valueOf(b));
|
||||
}
|
||||
|
||||
return "[L;" + String.join(",", bytes) + "]";
|
||||
} else if (base.getType() == NBTType.BYTE || base.getType() == NBTType.INT || base.getType() == NBTType.LONG ||
|
||||
base.getType() == NBTType.FLOAT || base.getType() == NBTType.SHORT || base.getType() == NBTType.DOUBLE) {
|
||||
NBTNumber number = (NBTNumber) base;
|
||||
return number.getAsNumber().toString();
|
||||
} else if (base.getType() == NBTType.STRING) {
|
||||
String val = ((NBTString) base).getValue();
|
||||
|
||||
return "\"" + val.replace("\\", "\\\\").replace("\"", "\\\"") + "\"";
|
||||
} else if (base.getType() == NBTType.END) {
|
||||
return "";
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -35,15 +35,13 @@ public abstract class ReflectionManagerAbstract {
|
||||
|
||||
public abstract Object getPlayerConnectionOrPlayer(Player player);
|
||||
|
||||
public abstract Object createEntityInstance(String entityName);
|
||||
public Object createEntityInstance(EntityType entityType, String entityName) {
|
||||
return createEntityInstance(entityName);
|
||||
}
|
||||
|
||||
public abstract Object getBoundingBox(Entity entity);
|
||||
protected abstract Object createEntityInstance(String entityName);
|
||||
|
||||
public abstract double getXBoundingBox(Entity entity);
|
||||
|
||||
public abstract double getYBoundingBox(Entity entity);
|
||||
|
||||
public abstract double getZBoundingBox(Entity entity);
|
||||
public abstract double[] getBoundingBox(Entity entity);
|
||||
|
||||
public abstract Object getPlayerFromPlayerConnection(Object nmsEntity);
|
||||
|
||||
@ -53,10 +51,6 @@ public abstract class ReflectionManagerAbstract {
|
||||
|
||||
public abstract ItemStack getCraftItem(ItemStack bukkitItem);
|
||||
|
||||
public abstract Object getEntityTracker(Entity target) throws Exception;
|
||||
|
||||
public abstract Object getTrackerEntryFromTracker(Object tracker) throws Exception;
|
||||
|
||||
public abstract Object getMinecraftServer();
|
||||
|
||||
public abstract Object getNmsEntity(Entity entity);
|
||||
@ -158,9 +152,18 @@ public abstract class ReflectionManagerAbstract {
|
||||
return itemStack.hasItemMeta() ? itemStack.getItemMeta().getAsString() : null;
|
||||
}
|
||||
|
||||
public abstract Object getEntityTracker(Entity target) throws Exception;
|
||||
|
||||
@Deprecated
|
||||
public Object getEntityTrackerEntry(Entity target, Object entityTracker) throws Exception {
|
||||
return getTrackerEntryFromTracker(entityTracker);
|
||||
}
|
||||
|
||||
protected abstract Object getTrackerEntryFromTracker(Object tracker) throws Exception;
|
||||
|
||||
public abstract Set getTrackedEntities(Object trackedEntity);
|
||||
|
||||
public abstract void addEntityTracker(Object trackedEntity, Object serverPlayer);
|
||||
|
||||
public abstract void clearEntityTracker(Object trackedEntity, Object serverPlayer);
|
||||
|
||||
public abstract Set getTrackedEntities(Object trackedEntity);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user