Formatting by project

This commit is contained in:
libraryaddict 2014-06-15 19:35:47 +12:00
parent 1edc05d9ff
commit 0496134dee
10 changed files with 92 additions and 95 deletions

View File

@ -14,9 +14,9 @@ public class DisguiseConfig {
private static String disguiseBlownMessage;
private static int disguiseCloneExpire;
private static int disguiseEntityExpire;
private static boolean equipmentEnabled;
private static boolean entityAnimationsAdded;
private static boolean entityStatusEnabled;
private static boolean equipmentEnabled;
private static boolean hearSelfDisguise;
private static boolean hidingArmor;
private static boolean hidingHeldItem;
@ -105,13 +105,13 @@ public class DisguiseConfig {
return blowDisguisesOnAttack;
}
public static boolean isEquipmentPacketsEnabled() {
return equipmentEnabled;
}
/**
* @deprecated Spelling mistake.
*/
@Deprecated public static boolean isEnquipmentPacketsEnabled() { return equipmentEnabled; }
@Deprecated
public static boolean isEnquipmentPacketsEnabled() {
return equipmentEnabled;
}
public static boolean isEntityAnimationsAdded() {
return entityAnimationsAdded;
@ -121,6 +121,10 @@ public class DisguiseConfig {
return entityStatusEnabled;
}
public static boolean isEquipmentPacketsEnabled() {
return equipmentEnabled;
}
/**
* Is the plugin modifying the inventory packets so that players when self disguised, do not see their armor floating around
*/

View File

@ -32,7 +32,8 @@ public class DisguiseCloneCommand extends BaseDisguiseCommand {
boolean doSneak = false;
boolean doSprint = false;
for (String option : args) {
if (StringUtils.startsWithIgnoreCase(option, "ignoreEquip") || StringUtils.startsWithIgnoreCase(option, "ignoreEnquip")) {
if (StringUtils.startsWithIgnoreCase(option, "ignoreEquip")
|| StringUtils.startsWithIgnoreCase(option, "ignoreEnquip")) {
doEquipment = false;
} else if (option.equalsIgnoreCase("doSneakSprint")) {
doSneak = true;
@ -62,8 +63,9 @@ public class DisguiseCloneCommand extends BaseDisguiseCommand {
protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map) {
sender.sendMessage(ChatColor.DARK_GREEN
+ "Right click a entity to get a disguise reference you can pass to other disguise commands!");
sender.sendMessage(ChatColor.DARK_GREEN + "Security note: Any references you create will be available to all players able to use disguise references.");
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseclone IgnoreEquipment" + ChatColor.DARK_GREEN + "("
+ ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")");
sender.sendMessage(ChatColor.DARK_GREEN
+ "Security note: Any references you create will be available to all players able to use disguise references.");
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseclone IgnoreEquipment" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN
+ "Optional" + ChatColor.DARK_GREEN + ")");
}
}

View File

@ -1,6 +1,5 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.DisguiseAPI;
import org.bukkit.ChatColor;
@ -10,7 +9,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
public class UndisguiseCommand implements CommandExecutor {
@Override

View File

@ -1,6 +1,5 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.DisguiseAPI;
import org.bukkit.Bukkit;
@ -10,7 +9,6 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class UndisguisePlayerCommand implements CommandExecutor {
@Override

View File

@ -1,6 +1,5 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.DisguiseAPI;
import org.bukkit.ChatColor;
@ -10,7 +9,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
public class UndisguiseRadiusCommand implements CommandExecutor {
private int maxRadius = 30;

View File

@ -62,8 +62,7 @@ public class MobDisguise extends TargetedDisguise {
}
public boolean doesDisguiseAge() {
return getWatcher() != null &&
(getWatcher() instanceof AgeableWatcher || getWatcher() instanceof ZombieWatcher);
return getWatcher() != null && (getWatcher() instanceof AgeableWatcher || getWatcher() instanceof ZombieWatcher);
}
public boolean isAdult() {

View File

@ -1,6 +1,5 @@
package me.libraryaddict.disguise.events;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import org.bukkit.entity.Entity;
@ -8,7 +7,6 @@ import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class UndisguiseEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();

View File

@ -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;

View File

@ -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)

View File

@ -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);