Formatting by project
This commit is contained in:
@@ -98,8 +98,8 @@ public enum DisguiseSound {
|
||||
WOLF("mob.wolf.hurt", "mob.wolf.step", "mob.wolf.death", "mob.wolf.bark", "mob.wolf.panting", "mob.wolf.whine",
|
||||
"mob.wolf.howl", "mob.wolf.growl", "mob.wolf.shake"),
|
||||
|
||||
ZOMBIE("mob.zombie.hurt", "mob.zombie.step", "mob.zombie.death", "mob.zombie.say", "mob.zombie.infect", "mob.zombie.woodbreak",
|
||||
"mob.zombie.metal", "mob.zombie.wood");
|
||||
ZOMBIE("mob.zombie.hurt", "mob.zombie.step", "mob.zombie.death", "mob.zombie.say", "mob.zombie.infect",
|
||||
"mob.zombie.woodbreak", "mob.zombie.metal", "mob.zombie.wood");
|
||||
|
||||
public enum SoundType {
|
||||
CANCEL, DEATH, HURT, IDLE, STEP;
|
||||
|
@@ -204,8 +204,8 @@ public class DisguiseUtilities {
|
||||
try {
|
||||
Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
|
||||
if (entityTrackerEntry != null) {
|
||||
HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
|
||||
.get(entityTrackerEntry);
|
||||
HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(
|
||||
entityTrackerEntry);
|
||||
HashSet cloned = (HashSet) trackedPlayers.clone();
|
||||
PacketContainer destroyPacket = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
|
||||
destroyPacket.getIntegerArrays().write(0, new int[] { disguise.getEntity().getEntityId() });
|
||||
@@ -323,8 +323,8 @@ public class DisguiseUtilities {
|
||||
try {
|
||||
Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
|
||||
if (entityTrackerEntry != null) {
|
||||
HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
|
||||
.get(entityTrackerEntry);
|
||||
HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(
|
||||
entityTrackerEntry);
|
||||
for (Object p : trackedPlayers) {
|
||||
Player player = (Player) ReflectionManager.getBukkitEntity(p);
|
||||
if (((TargetedDisguise) disguise).canSee(player)) {
|
||||
@@ -460,8 +460,8 @@ public class DisguiseUtilities {
|
||||
try {
|
||||
Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
|
||||
if (entityTrackerEntry != null) {
|
||||
HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
|
||||
.get(entityTrackerEntry);
|
||||
HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(
|
||||
entityTrackerEntry);
|
||||
Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", "clear",
|
||||
ReflectionManager.getNmsClass("EntityPlayer"));
|
||||
Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer",
|
||||
@@ -489,8 +489,8 @@ public class DisguiseUtilities {
|
||||
try {
|
||||
Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(entity);
|
||||
if (entityTrackerEntry != null) {
|
||||
HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
|
||||
.get(entityTrackerEntry);
|
||||
HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(
|
||||
entityTrackerEntry);
|
||||
Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", "clear",
|
||||
ReflectionManager.getNmsClass("EntityPlayer"));
|
||||
Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer",
|
||||
@@ -520,8 +520,8 @@ public class DisguiseUtilities {
|
||||
try {
|
||||
Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
|
||||
if (entityTrackerEntry != null) {
|
||||
HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
|
||||
.get(entityTrackerEntry);
|
||||
HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(
|
||||
entityTrackerEntry);
|
||||
Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", "clear",
|
||||
ReflectionManager.getNmsClass("EntityPlayer"));
|
||||
Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer",
|
||||
@@ -582,8 +582,8 @@ public class DisguiseUtilities {
|
||||
try {
|
||||
Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(player);
|
||||
if (entityTrackerEntry != null) {
|
||||
HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
|
||||
.get(entityTrackerEntry);
|
||||
HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(
|
||||
entityTrackerEntry);
|
||||
// If the tracker exists. Remove himself from his tracker
|
||||
trackedPlayers.remove(ReflectionManager.getNmsEntity(player));
|
||||
}
|
||||
@@ -631,7 +631,8 @@ public class DisguiseUtilities {
|
||||
}
|
||||
int fakeId = selfDisguisesIds.get(player.getUniqueId());
|
||||
// Add himself to his own entity tracker
|
||||
((HashSet<Object>) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry)).add(ReflectionManager.getNmsEntity(player));
|
||||
((HashSet<Object>) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry))
|
||||
.add(ReflectionManager.getNmsEntity(player));
|
||||
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
|
||||
// Send the player a packet with himself being spawned
|
||||
manager.sendServerPacket(player, manager.createPacketConstructor(PacketType.Play.Server.NAMED_ENTITY_SPAWN, player)
|
||||
|
@@ -64,8 +64,10 @@ public class ReflectionManager {
|
||||
}
|
||||
|
||||
private static final String bukkitVersion = Bukkit.getServer().getClass().getName().split("\\.")[3];
|
||||
private static final boolean isForge = Bukkit.getServer().getName().equalsIgnoreCase("Cauldron");
|
||||
private static final Class<?> craftItemClass;
|
||||
|
||||
private static Method damageAndIdleSoundMethod;
|
||||
private static final Field entitiesField;
|
||||
/**
|
||||
* Map of mc-dev simple class name to fully qualified Forge class name.
|
||||
*/
|
||||
@@ -74,26 +76,25 @@ public class ReflectionManager {
|
||||
* Map of Forge fully qualified class names to a map from mc-dev field names to Forge field names.
|
||||
*/
|
||||
private static Map<String, Map<String, String>> ForgeFieldMappings;
|
||||
|
||||
/**
|
||||
* Map of Forge fully qualified class names to a map from mc-dev method names to a map from method signatures to Forge method names.
|
||||
* Map of Forge fully qualified class names to a map from mc-dev method names to a map from method signatures to Forge method
|
||||
* names.
|
||||
*/
|
||||
private static Map<String, Map<String, Map<String, String>>> ForgeMethodMappings;
|
||||
private static Map<Class<?>, String> primitiveTypes;
|
||||
|
||||
private static final Method ihmGet;
|
||||
private static final boolean isForge = Bukkit.getServer().getName().equalsIgnoreCase("Cauldron");
|
||||
private static final Field pingField;
|
||||
private static Map<Class<?>, String> primitiveTypes;
|
||||
private static final Field trackerField;
|
||||
static {
|
||||
final String nameseg_class = "a-zA-Z0-9$_";
|
||||
final String fqn_class = nameseg_class + "/";
|
||||
|
||||
primitiveTypes = ImmutableMap.<Class<?>, String>builder()
|
||||
.put(boolean.class,"Z")
|
||||
.put(byte.class, "B")
|
||||
.put(char.class, "C")
|
||||
.put(short.class, "S")
|
||||
.put(int.class, "I")
|
||||
.put(long.class, "J")
|
||||
.put(float.class, "F")
|
||||
.put(double.class, "D")
|
||||
.put(void.class, "V").build();
|
||||
primitiveTypes = ImmutableMap.<Class<?>, String> builder().put(boolean.class, "Z").put(byte.class, "B")
|
||||
.put(char.class, "C").put(short.class, "S").put(int.class, "I").put(long.class, "J").put(float.class, "F")
|
||||
.put(double.class, "D").put(void.class, "V").build();
|
||||
|
||||
if (isForge) {
|
||||
// Initialize the maps by reading the srg file
|
||||
@@ -107,12 +108,14 @@ public class ReflectionManager {
|
||||
|
||||
// 1: cb-simpleName
|
||||
// 2: forge-fullName (Needs dir2fqn())
|
||||
Pattern classPattern = Pattern.compile("^CL: net/minecraft/server/([" + nameseg_class + "]+) ([" + fqn_class + "]+)$");
|
||||
Pattern classPattern = Pattern.compile("^CL: net/minecraft/server/([" + nameseg_class + "]+) ([" + fqn_class
|
||||
+ "]+)$");
|
||||
// 1: cb-simpleName
|
||||
// 2: cb-fieldName
|
||||
// 3: forge-fullName (Needs dir2fqn())
|
||||
// 4: forge-fieldName
|
||||
Pattern fieldPattern = Pattern.compile("^FD: net/minecraft/server/([" + nameseg_class + "]+)/([" + nameseg_class + "]+) ([" + fqn_class + "]+)/([" + nameseg_class + "]+)$");
|
||||
Pattern fieldPattern = Pattern.compile("^FD: net/minecraft/server/([" + nameseg_class + "]+)/([" + nameseg_class
|
||||
+ "]+) ([" + fqn_class + "]+)/([" + nameseg_class + "]+)$");
|
||||
// 1: cb-simpleName
|
||||
// 2: cb-methodName
|
||||
// 3: cb-signature-args
|
||||
@@ -121,8 +124,9 @@ public class ReflectionManager {
|
||||
// 6: forge-methodName
|
||||
// 7: forge-signature-args
|
||||
// 8: forge-signature-ret
|
||||
Pattern methodPattern = Pattern.compile("^MD: net/minecraft/server/([" + fqn_class + "]+)/([" + nameseg_class + "]+) \\(([;\\[" + fqn_class + "]*)\\)([;\\[" + fqn_class + "]+) " +
|
||||
"([" + fqn_class + "]+)/([" + nameseg_class + "]+) \\(([;\\[" + fqn_class + "]*)\\)([;\\[" + fqn_class + "]+)$");
|
||||
Pattern methodPattern = Pattern.compile("^MD: net/minecraft/server/([" + fqn_class + "]+)/([" + nameseg_class
|
||||
+ "]+) \\(([;\\[" + fqn_class + "]*)\\)([;\\[" + fqn_class + "]+) " + "([" + fqn_class + "]+)/(["
|
||||
+ nameseg_class + "]+) \\(([;\\[" + fqn_class + "]*)\\)([;\\[" + fqn_class + "]+)$");
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
@@ -169,21 +173,16 @@ public class ReflectionManager {
|
||||
System.out.println("[LibsDisguises] Loaded " + ForgeMethodMappings.size() + " Cauldron method mappings");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
System.err.println("Warning: Running on Cauldron server, but couldn't load mappings file. LibsDisguises will likely crash!");
|
||||
System.err
|
||||
.println("Warning: Running on Cauldron server, but couldn't load mappings file. LibsDisguises will likely crash!");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.err.println("Warning: Running on Cauldron server, but couldn't load mappings file. LibsDisguises will likely crash!");
|
||||
System.err
|
||||
.println("Warning: Running on Cauldron server, but couldn't load mappings file. LibsDisguises will likely crash!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final Class<?> craftItemClass;
|
||||
private static final Field pingField;
|
||||
private static final Field trackerField;
|
||||
private static final Field entitiesField;
|
||||
private static final Method ihmGet;
|
||||
private static Method damageAndIdleSoundMethod;
|
||||
|
||||
static {
|
||||
for (Method method : getNmsClass("EntityLiving").getDeclaredMethods()) {
|
||||
try {
|
||||
@@ -213,12 +212,6 @@ public class ReflectionManager {
|
||||
DisguiseType.ARROW.isMisc();
|
||||
}
|
||||
|
||||
private static String dir2fqn(String s) {
|
||||
return s.replaceAll("/", ".");
|
||||
}
|
||||
|
||||
// ===
|
||||
|
||||
public static Object createEntityInstance(String entityName) {
|
||||
try {
|
||||
Class<?> entityClass = getNmsClass("Entity" + entityName);
|
||||
@@ -248,6 +241,12 @@ public class ReflectionManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
// ===
|
||||
|
||||
private static String dir2fqn(String s) {
|
||||
return s.replaceAll("/", ".");
|
||||
}
|
||||
|
||||
public static FakeBoundingBox getBoundingBox(Entity entity) {
|
||||
try {
|
||||
Object boundingBox = getNmsField("Entity", "boundingBox").get(getNmsEntity(entity));
|
||||
@@ -328,6 +327,13 @@ public class ReflectionManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
static Object getEntityTrackerEntry(Entity target) throws Exception {
|
||||
Object world = getWorld(target.getWorld());
|
||||
Object tracker = trackerField.get(world);
|
||||
Object trackedEntities = entitiesField.get(tracker);
|
||||
return ihmGet.invoke(trackedEntities, target.getEntityId());
|
||||
}
|
||||
|
||||
public static String getEnumArt(Art art) {
|
||||
try {
|
||||
Object enumArt = getCraftClass("CraftArt").getMethod("BukkitToNotch", Art.class).invoke(null, art);
|
||||
@@ -342,13 +348,6 @@ public class ReflectionManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
static Object getEntityTrackerEntry(Entity target) throws Exception {
|
||||
Object world = getWorld(target.getWorld());
|
||||
Object tracker = trackerField.get(world);
|
||||
Object trackedEntities = entitiesField.get(tracker);
|
||||
return ihmGet.invoke(trackedEntities, target.getEntityId());
|
||||
}
|
||||
|
||||
public static WrappedGameProfile getGameProfile(Player player) {
|
||||
if (LibVersion.is1_7()) {
|
||||
return WrappedGameProfile.fromPlayer(player);
|
||||
@@ -406,19 +405,6 @@ public class ReflectionManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object getNmsItem(ItemStack itemstack) {
|
||||
try {
|
||||
return craftItemClass.getMethod("asNMSCopy", ItemStack.class).invoke(null, itemstack);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Field getNmsField(String className, String fieldName) {
|
||||
return getNmsField(getNmsClass(className), fieldName);
|
||||
}
|
||||
|
||||
public static Field getNmsField(Class clazz, String fieldName) {
|
||||
if (isForge) {
|
||||
try {
|
||||
@@ -436,18 +422,17 @@ public class ReflectionManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Method getNmsMethod(String className, String methodName, Class<?>... parameters) {
|
||||
return getNmsMethod(getNmsClass(className), methodName, parameters);
|
||||
public static Field getNmsField(String className, String fieldName) {
|
||||
return getNmsField(getNmsClass(className), fieldName);
|
||||
}
|
||||
|
||||
private static String methodSignaturePart(Class<?> param) {
|
||||
if (param.isArray()) {
|
||||
return "[" + methodSignaturePart(param.getComponentType());
|
||||
} else if (param.isPrimitive()) {
|
||||
return primitiveTypes.get(param);
|
||||
} else {
|
||||
return "L" + param.getName().replaceAll("\\.", "/") + ";";
|
||||
public static Object getNmsItem(ItemStack itemstack) {
|
||||
try {
|
||||
return craftItemClass.getMethod("asNMSCopy", ItemStack.class).invoke(null, itemstack);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Method getNmsMethod(Class<?> clazz, String methodName, Class<?>... parameters) {
|
||||
@@ -472,6 +457,10 @@ public class ReflectionManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Method getNmsMethod(String className, String methodName, Class<?>... parameters) {
|
||||
return getNmsMethod(getNmsClass(className), methodName, parameters);
|
||||
}
|
||||
|
||||
public static double getPing(Player player) {
|
||||
try {
|
||||
return (double) pingField.getInt(ReflectionManager.getNmsEntity(player));
|
||||
@@ -554,6 +543,16 @@ public class ReflectionManager {
|
||||
return !gameProfile.getProperties().isEmpty();
|
||||
}
|
||||
|
||||
private static String methodSignaturePart(Class<?> param) {
|
||||
if (param.isArray()) {
|
||||
return "[" + methodSignaturePart(param.getComponentType());
|
||||
} else if (param.isPrimitive()) {
|
||||
return primitiveTypes.get(param);
|
||||
} else {
|
||||
return "L" + param.getName().replaceAll("\\.", "/") + ";";
|
||||
}
|
||||
}
|
||||
|
||||
public static void setAllowSleep(Player player) {
|
||||
try {
|
||||
Object nmsEntity = getNmsEntity(player);
|
||||
|
Reference in New Issue
Block a user