Renable some disguises, fix player sleeping? I forgot what I did

This commit is contained in:
libraryaddict 2016-06-19 03:16:32 +12:00
parent acc21a6d6e
commit bf3c11878a
30 changed files with 2647 additions and 2294 deletions

View File

@ -179,7 +179,7 @@ public class DisguiseAPI
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
}
}

View File

@ -186,7 +186,7 @@ public class DisguiseListener implements Listener
}
catch (InvocationTargetException e)
{
e.printStackTrace(System.out);
e.printStackTrace();
}
}

View File

@ -377,7 +377,7 @@ public class LibsDisguises extends JavaPlugin
System.out.print("[LibsDisguises] Development builds are available at (ProtocolLib) "
+ "http://ci.dmulloy2.net/job/ProtocolLib/ and (LibsDisguises) http://server.o2gaming.com:8080/job/LibsDisguises%201.9+/");
ex.printStackTrace(System.out);
ex.printStackTrace();
}
}
}

View File

@ -76,7 +76,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor
return getPermissions(sender, "libsdisguises." + getClass().getSimpleName().replace("Command", "").toLowerCase() + ".");
}
protected HashMap<String, Boolean> getDisguisePermission(CommandSender sender, DisguiseType type)
protected HashMap<String, Boolean> getDisguiseOptions(CommandSender sender, DisguiseType type)
{
switch (type)
{
@ -135,7 +135,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
}
@ -159,6 +159,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor
for (PermissionAttachmentInfo permission : sender.getEffectivePermissions())
{
String perm = permission.getPermission().toLowerCase();
if (perm.startsWith(permissionNode) && (!perms.containsKey(perm) || !permission.getValue()))
{
perms.put(perm, permission.getValue());
@ -192,6 +193,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor
break;
}
}
if (dType != null)
{
HashMap<ArrayList<String>, Boolean> list;
@ -255,9 +257,11 @@ public abstract class BaseDisguiseCommand implements CommandExecutor
{
options = getOptions(perm);
}
if (options != null)
{
HashMap<ArrayList<String>, Boolean> list;
if (rangeDisguises.containsKey(type))
{
list = rangeDisguises.get(type);
@ -267,13 +271,16 @@ public abstract class BaseDisguiseCommand implements CommandExecutor
list = new HashMap<>();
rangeDisguises.put(type, list);
}
HashMap<ArrayList<String>, Boolean> map1 = getOptions(perm);
list.put(map1.keySet().iterator().next(), map1.values().iterator().next());
}
}
}
}
}
for (String perm : perms.keySet())
{
if (!perms.get(perm))
@ -281,6 +288,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor
perm = perm.substring(permissionNode.length());
String disguiseType = perm.split("\\.")[0];
DisguiseType dType = null;
for (DisguiseType t : DisguiseType.values())
{
if (t.name().replace("_", "").equalsIgnoreCase(disguiseType.replace("_", "")))
@ -289,6 +297,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor
break;
}
}
if (dType != null)
{
singleDisguises.remove(dType);
@ -300,6 +309,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor
{
boolean foundHim = false;
Class entityClass = type.getEntityClass();
switch (disguiseType)
{
case "mob":
@ -307,6 +317,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor
{
foundHim = true;
}
break;
case "animal":
case "animals":
@ -314,6 +325,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor
{
foundHim = true;
}
break;
case "monster":
case "monsters":
@ -321,23 +333,27 @@ public abstract class BaseDisguiseCommand implements CommandExecutor
{
foundHim = true;
}
break;
case "misc":
if (type.isMisc())
{
foundHim = true;
}
break;
case "ageable":
if (Ageable.class.isAssignableFrom(entityClass))
{
foundHim = true;
}
break;
case "*":
foundHim = true;
break;
}
if (foundHim)
{
rangeDisguises.remove(type);
@ -346,23 +362,29 @@ public abstract class BaseDisguiseCommand implements CommandExecutor
}
}
}
HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map = new HashMap<>();
for (DisguiseType type : DisguiseType.values())
{
HashMap<ArrayList<String>, Boolean> temp = new HashMap<>();
if (singleDisguises.containsKey(type))
{
temp.putAll(singleDisguises.get(type));
}
if (rangeDisguises.containsKey(type))
{
temp.putAll(rangeDisguises.get(type));
}
if (!temp.isEmpty())
{
map.put(type, temp);
}
}
return map;
}
@ -386,8 +408,10 @@ public abstract class BaseDisguiseCommand implements CommandExecutor
}
list.add(option);
}
HashMap<ArrayList<String>, Boolean> options = new HashMap<>();
options.put(list, isRemove);
return options;
}
@ -443,6 +467,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor
sendCommandUsage(sender, map);
throw new DisguiseParseException();
}
// How many args to skip due to the disugise being constructed
// Time to start constructing the disguise.
// We will need to check between all 3 kinds of disguises
@ -450,6 +475,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor
ArrayList<String> usedOptions = new ArrayList<>();
Disguise disguise = null;
HashMap<ArrayList<String>, Boolean> optionPermissions;
if (args[0].startsWith("@"))
{
if (sender.hasPermission("libsdisguises.disguise.disguiseclone"))
@ -486,6 +512,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor
}
}
}
if (disguiseType == null)
{
throw new DisguiseParseException(
@ -509,7 +536,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor
optionPermissions = map.get(disguiseType);
HashMap<String, Boolean> disguiseOptions = this.getDisguisePermission(sender, disguiseType);
HashMap<String, Boolean> disguiseOptions = this.getDisguiseOptions(sender, disguiseType);
if (disguiseType.isPlayer())
{
@ -539,6 +566,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor
if (disguiseType.isMob())
{ // Its a mob, use the mob constructor
boolean adult = true;
if (args.length > 1)
{
if (args[1].equalsIgnoreCase("baby") || args[1].equalsIgnoreCase("adult"))
@ -549,6 +577,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor
toSkip++;
}
}
disguise = new MobDisguise(disguiseType, adult);
}
else if (disguiseType.isMisc())
@ -630,6 +659,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor
if (!disguiseOptions.isEmpty() && miscId != -1)
{
String toCheck = "" + miscId;
if (miscData == 0 || miscData == -1)
{
if (!disguiseOptions.containsKey(toCheck) || !disguiseOptions.get(toCheck))
@ -641,6 +671,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor
{
toCheck += ":" + miscData;
}
if (!disguiseOptions.containsKey(toCheck) || !disguiseOptions.get(toCheck))
{
throw new DisguiseParseException(
@ -1000,7 +1031,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
methodToUse = null;
}
}
@ -1010,17 +1041,21 @@ public abstract class BaseDisguiseCommand implements CommandExecutor
{
throw storedEx;
}
throw new DisguiseParseException(ChatColor.RED + "Cannot find the option " + methodName);
}
if (value == null)
{
throw new DisguiseParseException(ChatColor.RED + "No value was given for the option " + methodName);
}
if (!usedOptions.contains(methodName.toLowerCase()))
{
usedOptions.add(methodName.toLowerCase());
}
doCheck(optionPermissions, usedOptions);
if (FlagWatcher.class.isAssignableFrom(methodToUse.getDeclaringClass()))
{
methodToUse.invoke(disguise.getWatcher(), value);

View File

@ -12,39 +12,58 @@ import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
public class CloneDisguiseCommand extends BaseDisguiseCommand {
public class CloneDisguiseCommand extends BaseDisguiseCommand
{
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{
if (sender.getName().equals("CONSOLE"))
{
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
return true;
}
if (sender.hasPermission("libsdisguises.disguise.disguiseclone")) {
if (sender.hasPermission("libsdisguises.disguise.disguiseclone"))
{
boolean doEquipment = true;
boolean doSneak = false;
boolean doSprint = false;
for (String option : args) {
for (String option : args)
{
if (StringUtils.startsWithIgnoreCase(option, "ignoreEquip")
|| StringUtils.startsWithIgnoreCase(option, "ignoreEnquip")) {
|| StringUtils.startsWithIgnoreCase(option, "ignoreEnquip"))
{
doEquipment = false;
} else if (option.equalsIgnoreCase("doSneakSprint")) {
}
else if (option.equalsIgnoreCase("doSneakSprint"))
{
doSneak = true;
doSprint = true;
} else if (option.equalsIgnoreCase("doSneak")) {
}
else if (option.equalsIgnoreCase("doSneak"))
{
doSneak = true;
} else if (option.equalsIgnoreCase("doSprint")) {
}
else if (option.equalsIgnoreCase("doSprint"))
{
doSprint = true;
} else {
}
else
{
sender.sendMessage(ChatColor.DARK_RED + "Unknown option '" + option
+ "' - Valid options are 'IgnoreEquipment' 'DoSneakSprint' 'DoSneak' 'DoSprint'");
return true;
}
}
LibsDisguises.getInstance().getListener().setDisguiseClone(sender.getName(), new Boolean[]{doEquipment, doSneak, doSprint});
LibsDisguises.getInstance().getListener().setDisguiseClone(sender.getName(), new Boolean[]
{
doEquipment, doSneak, doSprint
});
sender.sendMessage(ChatColor.RED + "Right click a entity in the next " + DisguiseConfig.getDisguiseCloneExpire()
+ " seconds to grab the disguise reference!");
} else {
}
else
{
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
}
return true;
@ -54,7 +73,8 @@ public class CloneDisguiseCommand extends BaseDisguiseCommand {
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map) {
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

View File

@ -15,40 +15,61 @@ import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
public class DisguiseCommand extends BaseDisguiseCommand {
public class DisguiseCommand extends BaseDisguiseCommand
{
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{
if (sender.getName().equals("CONSOLE"))
{
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
return true;
}
Disguise disguise;
try {
try
{
disguise = parseDisguise(sender, args, getPermissions(sender));
} catch (DisguiseParseException ex) {
if (ex.getMessage() != null) {
}
catch (DisguiseParseException ex)
{
if (ex.getMessage() != null)
{
sender.sendMessage(ex.getMessage());
}
return true;
} catch (Exception ex) {
ex.printStackTrace(System.out);
return true;
}
if (DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
if (disguise.getWatcher() instanceof LivingWatcher) {
catch (Exception ex)
{
ex.printStackTrace();
return true;
}
if (DisguiseConfig.isNameOfPlayerShownAboveDisguise())
{
if (disguise.getWatcher() instanceof LivingWatcher)
{
disguise.getWatcher().setCustomName(((Player) sender).getDisplayName());
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
if (DisguiseConfig.isNameAboveHeadAlwaysVisible())
{
disguise.getWatcher().setCustomNameVisible(true);
}
}
}
DisguiseAPI.disguiseToAll((Player) sender, disguise);
if (disguise.isDisguiseInUse()) {
if (disguise.isDisguiseInUse())
{
sender.sendMessage(ChatColor.RED + "Now disguised as a " + disguise.getType().toReadable());
} else {
}
else
{
sender.sendMessage(ChatColor.RED + "Failed to disguise as a " + disguise.getType().toReadable());
}
return true;
}
@ -56,16 +77,19 @@ public class DisguiseCommand extends BaseDisguiseCommand {
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map) {
protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map)
{
ArrayList<String> allowedDisguises = getAllowedDisguises(map);
sender.sendMessage(ChatColor.DARK_GREEN + "Choose a disguise to become the disguise!");
sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
if (allowedDisguises.contains("player")) {
if (allowedDisguises.contains("player"))
{
sender.sendMessage(ChatColor.DARK_GREEN + "/disguise player <Name>");
}
sender.sendMessage(ChatColor.DARK_GREEN + "/disguise <DisguiseType> <Baby>");
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block"))
{
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseplayer <Dropped_Item/Falling_Block> <Id> <Durability>");
}
}

View File

@ -9,22 +9,27 @@ import org.bukkit.entity.Player;
import me.libraryaddict.disguise.DisguiseAPI;
/**
*
* @author Navid
*/
public class DisguiseViewSelf implements CommandExecutor {
public class DisguiseViewSelf implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (sender.getName().equals("CONSOLE"))
{
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
return true;
}
Player player = (Player) sender;
if (DisguiseAPI.isViewSelfToggled(player)) {
if (DisguiseAPI.isViewSelfToggled(player))
{
DisguiseAPI.setViewDisguiseToggled(player, false);
sender.sendMessage(ChatColor.GREEN + "Toggled viewing own disguise off!");
} else {
}
else
{
DisguiseAPI.setViewDisguiseToggled(player, true);
sender.sendMessage(ChatColor.GREEN + "Toggled viewing own disguise on!");
}

View File

@ -14,24 +14,33 @@ import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
public class EntityDisguiseCommand extends BaseDisguiseCommand {
public class EntityDisguiseCommand extends BaseDisguiseCommand
{
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{
if (sender.getName().equals("CONSOLE"))
{
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
return true;
}
Disguise disguise;
try {
try
{
disguise = parseDisguise(sender, args, getPermissions(sender));
} catch (DisguiseParseException ex) {
if (ex.getMessage() != null) {
}
catch (DisguiseParseException ex)
{
if (ex.getMessage() != null)
{
sender.sendMessage(ex.getMessage());
}
return true;
} catch (IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace(System.out);
}
catch (IllegalAccessException | InvocationTargetException ex)
{
ex.printStackTrace();
return true;
}
LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), disguise);
@ -47,16 +56,19 @@ public class EntityDisguiseCommand extends BaseDisguiseCommand {
* @param map
*/
@Override
protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map) {
protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map)
{
ArrayList<String> allowedDisguises = getAllowedDisguises(map);
sender.sendMessage(ChatColor.DARK_GREEN + "Choose a disguise then right click a entity to disguise it!");
sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
if (allowedDisguises.contains("player")) {
if (allowedDisguises.contains("player"))
{
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseentity player <Name>");
}
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseentity <DisguiseType> <Baby>");
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block"))
{
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseentity <Dropped_Item/Falling_Block> <Id> <Durability>");
}
}

View File

@ -20,18 +20,22 @@ import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.RabbitType;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
public class HelpDisguiseCommand extends BaseDisguiseCommand {
public class HelpDisguiseCommand extends BaseDisguiseCommand
{
private class EnumHelp {
private class EnumHelp
{
private String enumDescription;
private String enumName;
private String[] enums;
private String readableEnum;
public EnumHelp(String enumName, String enumReadable, String enumDescription, Enum[] enums) {
public EnumHelp(String enumName, String enumReadable, String enumDescription, Enum[] enums)
{
String[] strings = new String[enums.length];
for (int i = 0; i < strings.length; i++) {
for (int i = 0; i < strings.length; i++)
{
strings[i] = toReadable(enums[i].name());
}
this.enumName = enumName;
@ -40,124 +44,177 @@ public class HelpDisguiseCommand extends BaseDisguiseCommand {
this.readableEnum = enumReadable;
}
public EnumHelp(String enumName, String enumReadable, String enumDescription, String[] enums) {
public EnumHelp(String enumName, String enumReadable, String enumDescription, String[] enums)
{
this.enumName = enumName;
this.enumDescription = enumDescription;
this.enums = enums;
this.readableEnum = enumReadable;
}
public String getEnumDescription() {
public String getEnumDescription()
{
return enumDescription;
}
public String getEnumName() {
public String getEnumName()
{
return enumName;
}
public String[] getEnums() {
public String[] getEnums()
{
return enums;
}
public String getReadableEnum() {
public String getReadableEnum()
{
return readableEnum;
}
}
private ArrayList<EnumHelp> enumHelp = new ArrayList<>();
public HelpDisguiseCommand() {
try {
public HelpDisguiseCommand()
{
try
{
enumHelp.add(new EnumHelp("AnimalColor", "Animal colors", ChatColor.RED + "/disguisehelp AnimalColors "
+ ChatColor.GREEN + "- View all the colors you can use for a animal color", AnimalColor.values()));
} catch (Exception ex) {
ex.printStackTrace(System.out);
}
try {
enumHelp.add(new EnumHelp("Art", "Arts", ChatColor.RED + "/disguisehelp Art " + ChatColor.GREEN
+ "- View all the painting arts you can use on a painting disguise", (Enum[]) Class.forName("org.bukkit.Art")
.getEnumConstants()));
} catch (Exception ex) {
catch (Exception ex)
{
ex.printStackTrace();
}
try {
enumHelp.add(new EnumHelp("HorseColor", "Horse colors", ChatColor.RED + "/disguisehelp HorseColors "
+ ChatColor.GREEN + "- View all the colors you can use for a horses color", (Enum[]) Class.forName(
"org.bukkit.entity.Horse$Color").getEnumConstants()));
} catch (Exception ex) {
try
{
enumHelp.add(new EnumHelp("Art", "Arts",
ChatColor.RED + "/disguisehelp Art " + ChatColor.GREEN
+ "- View all the painting arts you can use on a painting disguise",
(Enum[]) Class.forName("org.bukkit.Art").getEnumConstants()));
}
try {
enumHelp.add(new EnumHelp("HorseStyle", "Horse styles", ChatColor.RED + "/disguisehelp HorseStyles "
+ ChatColor.GREEN + "- View all the styles you can use for a horses style", (Enum[]) Class.forName(
"org.bukkit.entity.Horse$Style").getEnumConstants()));
} catch (Exception ex) {
catch (Exception ex)
{
}
try {
enumHelp.add(new EnumHelp("OcelotType", "Ocelot types", ChatColor.RED + "/disguisehelp OcelotTypes "
+ ChatColor.GREEN + "- View all the ocelot types you can use for ocelots", (Enum[]) Class.forName(
"org.bukkit.entity.Ocelot$Type").getEnumConstants()));
} catch (Exception ex) {
try
{
enumHelp.add(new EnumHelp("HorseColor", "Horse colors",
ChatColor.RED + "/disguisehelp HorseColors " + ChatColor.GREEN
+ "- View all the colors you can use for a horses color",
(Enum[]) Class.forName("org.bukkit.entity.Horse$Color").getEnumConstants()));
}
try {
catch (Exception ex)
{
}
try
{
enumHelp.add(new EnumHelp("HorseStyle", "Horse styles",
ChatColor.RED + "/disguisehelp HorseStyles " + ChatColor.GREEN
+ "- View all the styles you can use for a horses style",
(Enum[]) Class.forName("org.bukkit.entity.Horse$Style").getEnumConstants()));
}
catch (Exception ex)
{
}
try
{
enumHelp.add(new EnumHelp("OcelotType", "Ocelot types",
ChatColor.RED + "/disguisehelp OcelotTypes " + ChatColor.GREEN
+ "- View all the ocelot types you can use for ocelots",
(Enum[]) Class.forName("org.bukkit.entity.Ocelot$Type").getEnumConstants()));
}
catch (Exception ex)
{
}
try
{
ArrayList<String> enumReturns = new ArrayList<>();
for (PotionEffectType potionType : PotionEffectType.values()) {
if (potionType != null) {
for (PotionEffectType potionType : PotionEffectType.values())
{
if (potionType != null)
{
enumReturns.add(toReadable(potionType.getName()) + ChatColor.RED + "(" + ChatColor.GREEN + potionType.getId()
+ ChatColor.RED + ")");
}
}
enumHelp.add(new EnumHelp("PotionEffect", "PotionEffect", ChatColor.RED + "/disguisehelp PotionEffect "
+ ChatColor.GREEN + "- View all the potion effects you can set", enumReturns.toArray(new String[enumReturns
.size()])));
} catch (Exception ex) {
ex.printStackTrace(System.out);
enumHelp.add(new EnumHelp("PotionEffect", "PotionEffect",
ChatColor.RED + "/disguisehelp PotionEffect " + ChatColor.GREEN + "- View all the potion effects you can set",
enumReturns.toArray(new String[enumReturns.size()])));
}
try {
enumHelp.add(new EnumHelp("Profession", "Villager professions", ChatColor.RED + "/disguisehelp Professions "
+ ChatColor.GREEN + "- View all the professions you can set on a villager", (Enum[]) Class.forName(
"org.bukkit.entity.Villager$Profession").getEnumConstants()));
} catch (Exception ex) {
catch (Exception ex)
{
ex.printStackTrace();
}
enumHelp.add(new EnumHelp("Direction", "Directions", ChatColor.RED + "/disguisehelp Directions " + ChatColor.GREEN
+ "- View the five directions usable on player setsleeping disguise", Arrays.copyOf(BlockFace.values(), 5)));
enumHelp.add(new EnumHelp("RabbitType", "RabbitType", ChatColor.RED + "/disguisehelp RabbitType " + ChatColor.GREEN
+ "View the kinds of rabbits you can turn into", RabbitType.values()));
try
{
enumHelp.add(new EnumHelp("Profession", "Villager professions",
ChatColor.RED + "/disguisehelp Professions " + ChatColor.GREEN
+ "- View all the professions you can set on a villager",
(Enum[]) Class.forName("org.bukkit.entity.Villager$Profession").getEnumConstants()));
}
catch (Exception ex)
{
}
enumHelp.add(new EnumHelp("Direction", "Directions",
ChatColor.RED + "/disguisehelp Directions " + ChatColor.GREEN
+ "- View the five directions usable on player setsleeping disguise",
Arrays.copyOf(BlockFace.values(), 5)));
enumHelp.add(new EnumHelp("RabbitType", "RabbitType",
ChatColor.RED + "/disguisehelp RabbitType " + ChatColor.GREEN + "View the kinds of rabbits you can turn into",
RabbitType.values()));
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
for (String node : new String[]{"disguise", "disguiseradius", "disguiseentity", "disguiseplayer"}) {
HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> permMap = getPermissions(sender, "libsdisguises." + node
+ ".");
if (!permMap.isEmpty()) {
if (args.length == 0) {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{
for (String node : new String[]
{
"disguise", "disguiseradius", "disguiseentity", "disguiseplayer"
})
{
HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> permMap = getPermissions(sender,
"libsdisguises." + node + ".");
if (!permMap.isEmpty())
{
if (args.length == 0)
{
sendCommandUsage(sender, null);
return true;
} else {
}
else
{
EnumHelp help = null;
for (EnumHelp s : enumHelp) {
if (args[0].equalsIgnoreCase(s.getEnumName()) || args[0].equalsIgnoreCase(s.getEnumName() + "s")) {
for (EnumHelp s : enumHelp)
{
if (args[0].equalsIgnoreCase(s.getEnumName()) || args[0].equalsIgnoreCase(s.getEnumName() + "s"))
{
help = s;
break;
}
}
if (help != null) {
if (help != null)
{
sender.sendMessage(ChatColor.RED + help.getReadableEnum() + ": " + ChatColor.GREEN
+ StringUtils.join(help.getEnums(), ChatColor.RED + ", " + ChatColor.GREEN));
return true;
}
DisguiseType type = null;
for (DisguiseType disguiseType : DisguiseType.values()) {
for (DisguiseType disguiseType : DisguiseType.values())
{
if (args[0].equalsIgnoreCase(disguiseType.name())
|| disguiseType.name().replace("_", "").equalsIgnoreCase(args[0])) {
|| disguiseType.name().replace("_", "").equalsIgnoreCase(args[0]))
{
type = disguiseType;
break;
}
}
if (type == null) {
if (type == null)
{
sender.sendMessage(ChatColor.RED + "Cannot find the disguise " + args[0]);
return true;
}
if (!permMap.containsKey(type)) {
if (!permMap.containsKey(type))
{
sender.sendMessage(ChatColor.RED + "You do not have permission for that disguise!");
return true;
}
@ -165,67 +222,110 @@ public class HelpDisguiseCommand extends BaseDisguiseCommand {
HashMap<String, ChatColor> map = new HashMap<>();
Class watcher = type.getWatcherClass();
int ignored = 0;
try {
for (Method method : this.getDisguiseWatcherMethods(watcher)) {
try
{
for (Method method : this.getDisguiseWatcherMethods(watcher))
{
if (!method.getName().startsWith("get") && method.getParameterTypes().length == 1
&& method.getAnnotation(Deprecated.class) == null) {
if (args.length < 2 || !args[1].equalsIgnoreCase("show")) {
&& method.getAnnotation(Deprecated.class) == null)
{
if (args.length < 2 || !args[1].equalsIgnoreCase("show"))
{
boolean allowed = false;
for (ArrayList<String> key : permMap.get(type).keySet()) {
if (permMap.get(type).get(key)) {
if (key.contains("*") || key.contains(method.getName().toLowerCase())) {
for (ArrayList<String> key : permMap.get(type).keySet())
{
if (permMap.get(type).get(key))
{
if (key.contains("*") || key.contains(method.getName().toLowerCase()))
{
allowed = true;
break;
}
} else if (!key.contains(method.getName().toLowerCase())) {
}
else if (!key.contains(method.getName().toLowerCase()))
{
allowed = true;
break;
}
}
if (!allowed) {
if (!allowed)
{
ignored++;
continue;
}
}
Class c = method.getParameterTypes()[0];
String valueType = null;
if (c == String.class) {
if (c == String.class)
{
valueType = "String";
} else if (boolean.class == c) {
}
else if (boolean.class == c)
{
valueType = "True/False";
} else if (int.class == c) {
}
else if (int.class == c)
{
valueType = "Number";
} else if (float.class == c || double.class == c) {
}
else if (float.class == c || double.class == c)
{
valueType = "Decimal";
} else if (AnimalColor.class == c) {
}
else if (AnimalColor.class == c)
{
valueType = "Color";
} else if (ItemStack.class == c) {
}
else if (ItemStack.class == c)
{
valueType = "Item (id:damage)";
} else if (ItemStack[].class == c) {
}
else if (ItemStack[].class == c)
{
valueType = "4 items (id:damage,id,...)";
} else if (c.getSimpleName().equals("Style")) {
}
else if (c.getSimpleName().equals("Style"))
{
valueType = "Horse Style";
} else if (c.getSimpleName().equals("Color")) {
}
else if (c.getSimpleName().equals("Color"))
{
valueType = "Horse Color";
} else if (c.getSimpleName().equals("Type")) {
}
else if (c.getSimpleName().equals("Type"))
{
valueType = "Ocelot type";
} else if (c.getSimpleName().equals("Profession")) {
}
else if (c.getSimpleName().equals("Profession"))
{
valueType = "Villager Profession";
} else if (PotionEffectType.class == c) {
}
else if (PotionEffectType.class == c)
{
valueType = "Potion effect";
} else if (c == int[].class) {
}
else if (c == int[].class)
{
valueType = "number,number,number...";
} else if (c == BlockFace.class) {
}
else if (c == BlockFace.class)
{
valueType = "direction";
} else if (c == RabbitType.class) {
}
else if (c == RabbitType.class)
{
valueType = "rabbit type";
}
if (valueType != null) {
if (valueType != null)
{
ChatColor methodColor = ChatColor.YELLOW;
Class<?> declaring = method.getDeclaringClass();
if (declaring == LivingWatcher.class) {
if (declaring == LivingWatcher.class)
{
methodColor = ChatColor.AQUA;
} else if (!(FlagWatcher.class.isAssignableFrom(declaring)) || declaring == FlagWatcher.class) {
}
else if (!(FlagWatcher.class.isAssignableFrom(declaring)) || declaring == FlagWatcher.class)
{
methodColor = ChatColor.GRAY;
}
String str = method.getName() + ChatColor.DARK_RED + "(" + ChatColor.GREEN + valueType
@ -235,19 +335,24 @@ public class HelpDisguiseCommand extends BaseDisguiseCommand {
}
}
}
} catch (Exception ex) {
ex.printStackTrace(System.out);
}
catch (Exception ex)
{
ex.printStackTrace();
}
Collections.sort(methods, String.CASE_INSENSITIVE_ORDER);
for (int i = 0; i < methods.size(); i++) {
for (int i = 0; i < methods.size(); i++)
{
methods.set(i, map.get(methods.get(i)) + methods.get(i));
}
if (methods.isEmpty()) {
if (methods.isEmpty())
{
methods.add(ChatColor.RED + "No options with permission to use");
}
sender.sendMessage(ChatColor.DARK_RED + type.toReadable() + " options: "
+ StringUtils.join(methods, ChatColor.DARK_RED + ", "));
if (ignored > 0) {
if (ignored > 0)
{
sender.sendMessage(ChatColor.RED + "Ignored " + ignored
+ " options you do not have permission to view. Add 'show' to view unusable options.");
}
@ -263,19 +368,21 @@ public class HelpDisguiseCommand extends BaseDisguiseCommand {
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map) {
sender.sendMessage(ChatColor.RED
+ "/disguisehelp <DisguiseType> "
+ ChatColor.GREEN
protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map)
{
sender.sendMessage(ChatColor.RED + "/disguisehelp <DisguiseType> " + ChatColor.GREEN
+ "- View the options you can set on a disguise. Add 'show' to reveal the options you don't have permission to use");
for (EnumHelp s : enumHelp) {
for (EnumHelp s : enumHelp)
{
sender.sendMessage(s.getEnumDescription());
}
}
public String toReadable(String string) {
public String toReadable(String string)
{
String[] split = string.split("_");
for (int i = 0; i < split.length; i++) {
for (int i = 0; i < split.length; i++)
{
split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase();
}
return StringUtils.join(split, "_");

View File

@ -8,27 +8,36 @@ import org.bukkit.command.CommandSender;
import me.libraryaddict.disguise.LibsDisguises;
public class LibsDisguisesCommand implements CommandExecutor {
public class LibsDisguisesCommand implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (args.length == 0) {
sender.sendMessage(ChatColor.DARK_GREEN
+ "This server is running "
+ "Lib's Disguises v."
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{
if (args.length == 0)
{
sender.sendMessage(ChatColor.DARK_GREEN + "This server is running " + "Lib's Disguises v."
+ Bukkit.getPluginManager().getPlugin("LibsDisguises").getDescription().getVersion()
+ " by libraryaddict, maintained by NavidK0.\n"
+ "Use /libsdisguises reload to reload the config. All disguises will be blown by doing this.");
} else if (args.length > 0) {
if (sender.hasPermission("libsdisguises.reload")) {
if (args[0].equalsIgnoreCase("reload")) {
}
else if (args.length > 0)
{
if (sender.hasPermission("libsdisguises.reload"))
{
if (args[0].equalsIgnoreCase("reload"))
{
LibsDisguises.getInstance().reload();
sender.sendMessage(ChatColor.GREEN + "[LibsDisguises] Reloaded config.");
return true;
} else {
}
else
{
sender.sendMessage(ChatColor.RED + "[LibsDisguises] That command doesn't exist!");
}
} else {
}
else
{
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
}
}

View File

@ -16,62 +16,81 @@ import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
public class PlayerDisguiseCommand extends BaseDisguiseCommand {
public class PlayerDisguiseCommand extends BaseDisguiseCommand
{
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{
HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map = getPermissions(sender);
if (map.isEmpty()) {
if (map.isEmpty())
{
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
return true;
}
if (args.length == 0) {
if (args.length == 0)
{
sendCommandUsage(sender, map);
return true;
}
if (args.length == 1) {
if (args.length == 1)
{
sender.sendMessage(ChatColor.RED + "You need to supply a disguise as well as the player");
return true;
}
Player player = Bukkit.getPlayer(args[0]);
if (player == null) {
if (player == null)
{
sender.sendMessage(ChatColor.RED + "Cannot find the player '" + args[0] + "'");
return true;
}
String[] newArgs = new String[args.length - 1];
System.arraycopy(args, 1, newArgs, 0, newArgs.length);
Disguise disguise;
try {
try
{
disguise = parseDisguise(sender, newArgs, map);
} catch (DisguiseParseException ex) {
if (ex.getMessage() != null) {
}
catch (DisguiseParseException ex)
{
if (ex.getMessage() != null)
{
sender.sendMessage(ex.getMessage());
}
return true;
} catch (Exception ex) {
ex.printStackTrace(System.out);
}
catch (Exception ex)
{
ex.printStackTrace();
return true;
}
if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled()) {
sender.sendMessage(ChatColor.RED
+ "Can't disguise a living entity as a misc disguise. This has been disabled in the config!");
if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled())
{
sender.sendMessage(
ChatColor.RED + "Can't disguise a living entity as a misc disguise. This has been disabled in the config!");
return true;
}
if (DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
if (disguise.getWatcher() instanceof LivingWatcher) {
if (DisguiseConfig.isNameOfPlayerShownAboveDisguise())
{
if (disguise.getWatcher() instanceof LivingWatcher)
{
disguise.getWatcher().setCustomName(player.getDisplayName());
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
if (DisguiseConfig.isNameAboveHeadAlwaysVisible())
{
disguise.getWatcher().setCustomNameVisible(true);
}
}
}
DisguiseAPI.disguiseToAll(player, disguise);
if (disguise.isDisguiseInUse()) {
if (disguise.isDisguiseInUse())
{
sender.sendMessage(ChatColor.RED + "Successfully disguised " + player.getName() + " as a "
+ disguise.getType().toReadable() + "!");
} else {
sender.sendMessage(ChatColor.RED + "Failed to disguise " + player.getName() + " as a "
+ disguise.getType().toReadable() + "!");
}
else
{
sender.sendMessage(
ChatColor.RED + "Failed to disguise " + player.getName() + " as a " + disguise.getType().toReadable() + "!");
}
return true;
}
@ -80,18 +99,21 @@ public class PlayerDisguiseCommand extends BaseDisguiseCommand {
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map) {
protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map)
{
ArrayList<String> allowedDisguises = getAllowedDisguises(map);
sender.sendMessage(ChatColor.DARK_GREEN + "Disguise another player!");
sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
if (allowedDisguises.contains("player")) {
if (allowedDisguises.contains("player"))
{
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> player <Name>");
}
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> <DisguiseType> <Baby>");
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
sender.sendMessage(ChatColor.DARK_GREEN
+ "/disguiseplayer <PlayerName> <Dropped_Item/Falling_Block> <Id> <Durability>");
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block"))
{
sender.sendMessage(
ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> <Dropped_Item/Falling_Block> <Id> <Durability>");
}
}
}

View File

@ -22,7 +22,6 @@ import me.libraryaddict.disguise.utilities.ClassGetter;
public class RadiusDisguiseCommand extends BaseDisguiseCommand
{
private int maxRadius = 30;
private ArrayList<Class> validClasses = new ArrayList<>();
@ -152,7 +151,7 @@ public class RadiusDisguiseCommand extends BaseDisguiseCommand
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
return true;
}

View File

@ -9,22 +9,31 @@ import org.bukkit.entity.Player;
import me.libraryaddict.disguise.DisguiseAPI;
public class UndisguiseCommand implements CommandExecutor {
public class UndisguiseCommand implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{
if (sender.getName().equals("CONSOLE"))
{
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
return true;
}
if (sender.hasPermission("libsdisguises.undisguise")) {
if (DisguiseAPI.isDisguised((Entity) sender)) {
if (sender.hasPermission("libsdisguises.undisguise"))
{
if (DisguiseAPI.isDisguised((Entity) sender))
{
DisguiseAPI.undisguiseToAll((Player) sender);
sender.sendMessage(ChatColor.RED + "You are no longer disguised");
} else {
}
else
{
sender.sendMessage(ChatColor.RED + "You are not disguised!");
}
} else {
}
else
{
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
}
return true;

View File

@ -7,18 +7,24 @@ import org.bukkit.command.CommandSender;
import me.libraryaddict.disguise.LibsDisguises;
public class UndisguiseEntityCommand implements CommandExecutor {
public class UndisguiseEntityCommand implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{
if (sender.getName().equals("CONSOLE"))
{
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
return true;
}
if (sender.hasPermission("libsdisguises.undisguiseentity")) {
if (sender.hasPermission("libsdisguises.undisguiseentity"))
{
LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), null);
sender.sendMessage(ChatColor.RED + "Right click a disguised entity to undisguise them!");
} else {
}
else
{
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
}
return true;

View File

@ -9,27 +9,41 @@ import org.bukkit.entity.Player;
import me.libraryaddict.disguise.DisguiseAPI;
public class UndisguisePlayerCommand implements CommandExecutor {
public class UndisguisePlayerCommand implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.hasPermission("libsdisguises.undisguiseplayer")) {
if (args.length > 0) {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{
if (sender.hasPermission("libsdisguises.undisguiseplayer"))
{
if (args.length > 0)
{
Player p = Bukkit.getPlayer(args[0]);
if (p != null) {
if (DisguiseAPI.isDisguised(p)) {
if (p != null)
{
if (DisguiseAPI.isDisguised(p))
{
DisguiseAPI.undisguiseToAll(p);
sender.sendMessage(ChatColor.RED + "The player is no longer disguised");
} else {
}
else
{
sender.sendMessage(ChatColor.RED + "The player is not disguised!");
}
} else {
}
else
{
sender.sendMessage(ChatColor.RED + "Player not found");
}
} else {
}
else
{
sender.sendMessage(ChatColor.RED + "/undisguiseplayer <Name>");
}
} else {
}
else
{
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
}
return true;

View File

@ -9,56 +9,73 @@ import org.bukkit.entity.Player;
import me.libraryaddict.disguise.DisguiseAPI;
public class UndisguiseRadiusCommand implements CommandExecutor {
public class UndisguiseRadiusCommand implements CommandExecutor
{
private int maxRadius = 30;
public UndisguiseRadiusCommand(int maxRadius) {
public UndisguiseRadiusCommand(int maxRadius)
{
this.maxRadius = maxRadius;
}
private boolean isNumeric(String string) {
try {
private boolean isNumeric(String string)
{
try
{
Integer.parseInt(string);
return true;
} catch (Exception ex) {
}
catch (Exception ex)
{
return false;
}
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{
if (sender.getName().equals("CONSOLE"))
{
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
return true;
}
if (sender.hasPermission("libsdisguises.undisguiseradius")) {
if (sender.hasPermission("libsdisguises.undisguiseradius"))
{
int radius = maxRadius;
if (args.length > 0) {
if (!isNumeric(args[0])) {
sender.sendMessage(ChatColor.RED + "Error! " + ChatColor.GREEN + args[0] + ChatColor.RED
+ " is not a number!");
if (args.length > 0)
{
if (!isNumeric(args[0]))
{
sender.sendMessage(
ChatColor.RED + "Error! " + ChatColor.GREEN + args[0] + ChatColor.RED + " is not a number!");
return true;
}
radius = Integer.parseInt(args[0]);
if (radius > maxRadius) {
sender.sendMessage(ChatColor.RED + "Limited radius to " + maxRadius
+ "! Don't want to make too much lag right?");
if (radius > maxRadius)
{
sender.sendMessage(
ChatColor.RED + "Limited radius to " + maxRadius + "! Don't want to make too much lag right?");
radius = maxRadius;
}
}
int disguisedEntitys = 0;
for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) {
if (entity == sender) {
for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius))
{
if (entity == sender)
{
continue;
}
if (DisguiseAPI.isDisguised(entity)) {
if (DisguiseAPI.isDisguised(entity))
{
DisguiseAPI.undisguiseToAll(entity);
disguisedEntitys++;
}
}
sender.sendMessage(ChatColor.RED + "Successfully undisguised " + disguisedEntitys + " entities!");
} else {
}
else
{
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
}
return true;

View File

@ -102,7 +102,7 @@ public abstract class Disguise
}
catch (Exception e)
{
e.printStackTrace(System.out);
e.printStackTrace();
}
// Set the disguise if its a baby or not
@ -355,7 +355,7 @@ public abstract class Disguise
}
catch (InvocationTargetException e)
{
e.printStackTrace(System.out);
e.printStackTrace();
}
}
}
@ -398,7 +398,7 @@ public abstract class Disguise
}
catch (Exception e)
{
e.printStackTrace(System.out);
e.printStackTrace();
}
}
// If we need to send a packet to update the exp position as it likes to gravitate client sided to
@ -430,14 +430,14 @@ public abstract class Disguise
}
catch (InvocationTargetException e)
{
e.printStackTrace(System.out);
e.printStackTrace();
}
}
}
}
catch (InvocationTargetException e)
{
e.printStackTrace(System.out);
e.printStackTrace();
}
}
}

View File

@ -116,10 +116,11 @@ public class FlagType<Y>
public static FlagType<Integer> CREEPER_STATE = new FlagType<Integer>(CreeperWatcher.class, 0, -1);
public static FlagType<ItemStack> DROPPED_ITEM = new FlagType<ItemStack>(DroppedItemWatcher.class, 0,
new ItemStack(Material.AIR));
public static FlagType<Optional<ItemStack>> DROPPED_ITEM = new FlagType<Optional<ItemStack>>(DroppedItemWatcher.class, 0,
Optional.<ItemStack> of(new ItemStack(Material.STONE)));
public static FlagType<Optional> ENDER_CRYSTAL_BEAM = new FlagType<Optional>(EnderCrystalWatcher.class, 0, Optional.absent());
public static FlagType<Optional<BlockPosition>> ENDER_CRYSTAL_BEAM = new FlagType<Optional<BlockPosition>>(EnderCrystalWatcher.class, 0,
Optional.<BlockPosition> absent());
public static FlagType<Boolean> ENDER_CRYSTAL_PLATE = new FlagType<Boolean>(EnderCrystalWatcher.class, 1, false);
@ -180,7 +181,7 @@ public class FlagType<Y>
public static FlagType<Byte> LIVING_HAND = new FlagType<Byte>(LivingWatcher.class, 0, (byte) 0);
public static FlagType<Float> LIVING_HEALTH = new FlagType<Float>(LivingWatcher.class, 1, 0F);
public static FlagType<Float> LIVING_HEALTH = new FlagType<Float>(LivingWatcher.class, 1, 1F);
public static FlagType<Boolean> LIVING_POTION_AMBIENT = new FlagType<Boolean>(LivingWatcher.class, 3, false);
@ -208,7 +209,7 @@ public class FlagType<Y>
public static FlagType<Integer> PLAYER_SCORE = new FlagType<Integer>(PlayerWatcher.class, 1, 0);
public static FlagType<Byte> PLAYER_SKIN = new FlagType<Byte>(PlayerWatcher.class, 2, (byte) 0);
public static FlagType<Byte> PLAYER_SKIN = new FlagType<Byte>(PlayerWatcher.class, 2, (byte) 127);
public static FlagType<Boolean> POLAR_BEAR_STANDING = new FlagType<Boolean>(PolarBearWatcher.class, 0, false);

View File

@ -28,22 +28,22 @@ import me.libraryaddict.disguise.utilities.ReflectionManager;
public class FlagWatcher
{
private boolean addEntityAnimations = DisguiseConfig.isEntityAnimationsAdded();
private boolean _addEntityAnimations = DisguiseConfig.isEntityAnimationsAdded();
/**
* These are the entity values I need to add else it could crash them..
*/
private HashMap<Integer, Object> backupEntityValues = new HashMap<>();
private TargetedDisguise disguise;
private HashMap<Integer, Object> entityValues = new HashMap<>();
private EntityEquipment equipment;
private boolean hasDied;
private HashSet<Integer> modifiedEntityAnimations = new HashSet<>();
private List<WrappedWatchableObject> watchableObjects;
private HashMap<Integer, Object> _backupEntityValues = new HashMap<>();
private TargetedDisguise _disguise;
private HashMap<Integer, Object> _entityValues = new HashMap<>();
private EntityEquipment _equipment;
private boolean _hasDied;
private HashSet<Integer> _modifiedEntityAnimations = new HashSet<>();
private List<WrappedWatchableObject> _watchableObjects;
public FlagWatcher(Disguise disguise)
{
this.disguise = (TargetedDisguise) disguise;
equipment = ReflectionManager.createEntityEquipment(disguise.getEntity());
_disguise = (TargetedDisguise) disguise;
_equipment = ReflectionManager.createEntityEquipment(disguise.getEntity());
}
private byte addEntityAnimations(byte originalValue, byte entityValue)
@ -52,7 +52,7 @@ public class FlagWatcher
for (int i = 0; i < 6; i++)
{
if ((entityValue & 1 << i) != 0 && !modifiedEntityAnimations.contains(i))
if ((entityValue & 1 << i) != 0 && !_modifiedEntityAnimations.contains(i))
{
valueByte = (byte) (valueByte | 1 << i);
}
@ -73,14 +73,14 @@ public class FlagWatcher
}
catch (Exception e)
{
e.printStackTrace(System.out);
e.printStackTrace();
cloned = new FlagWatcher(getDisguise());
}
cloned.entityValues = (HashMap<Integer, Object>) entityValues.clone();
cloned.equipment = ReflectionManager.createEntityEquipment(cloned.getDisguise().getEntity());
cloned.modifiedEntityAnimations = (HashSet<Integer>) modifiedEntityAnimations.clone();
cloned.addEntityAnimations = addEntityAnimations;
cloned._entityValues = (HashMap<Integer, Object>) _entityValues.clone();
cloned._equipment = ReflectionManager.createEntityEquipment(cloned.getDisguise().getEntity());
cloned._modifiedEntityAnimations = (HashSet<Integer>) _modifiedEntityAnimations.clone();
cloned._addEntityAnimations = _addEntityAnimations;
return cloned;
}
@ -105,35 +105,38 @@ public class FlagWatcher
Object value = null;
if (entityValues.containsKey(id))
if (_entityValues.containsKey(id))
{
if (entityValues.get(id) == null)
if (_entityValues.get(id) == null)
{
continue;
}
value = entityValues.get(id);
value = _entityValues.get(id);
}
else if (backupEntityValues.containsKey(id))
else if (_backupEntityValues.containsKey(id))
{
if (backupEntityValues.get(id) == null)
if (_backupEntityValues.get(id) == null)
{
continue;
}
value = backupEntityValues.get(id);
value = _backupEntityValues.get(id);
}
if (value != null)
{
if (isEntityAnimationsAdded() && id == 0)
{
value = this.addEntityAnimations((byte) value, (byte) watch.getValue());
value = addEntityAnimations((byte) value, (byte) watch.getValue());
}
boolean isDirty = watch.getDirtyState();
watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(id, value));
watch = ReflectionManager.createWatchable(id, value);
if (watch == null)
continue;
if (!isDirty)
{
@ -144,7 +147,10 @@ public class FlagWatcher
{
boolean isDirty = watch.getDirtyState();
watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(id, watch.getValue()));
watch = ReflectionManager.createWatchable(id, watch.getValue());
if (watch == null)
continue;
if (!isDirty)
{
@ -158,21 +164,24 @@ public class FlagWatcher
if (sendAllCustom)
{
// Its sending the entire meta data. Better add the custom meta
for (Integer id : entityValues.keySet())
for (Integer id : _entityValues.keySet())
{
if (sentValues.contains(id))
{
continue;
}
Object value = entityValues.get(id);
Object value = _entityValues.get(id);
if (value == null)
{
continue;
}
WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(id, value));
WrappedWatchableObject watch = ReflectionManager.createWatchable(id, value);
if (watch == null)
continue;
newList.add(watch);
}
@ -192,9 +201,9 @@ public class FlagWatcher
{
float newHealth = (Float) value;
if (newHealth > 0 && hasDied)
if (newHealth > 0 && _hasDied)
{
hasDied = false;
_hasDied = false;
Bukkit.getScheduler().scheduleSyncDelayedTask(DisguiseUtilities.getPlugin(), new Runnable()
{
@ -203,18 +212,18 @@ public class FlagWatcher
{
try
{
DisguiseUtilities.sendSelfDisguise((Player) getDisguise().getEntity(), disguise);
DisguiseUtilities.sendSelfDisguise((Player) getDisguise().getEntity(), _disguise);
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
}
}, 2);
}
else if (newHealth <= 0 && !hasDied)
else if (newHealth <= 0 && !_hasDied)
{
hasDied = true;
_hasDied = true;
}
}
}
@ -239,7 +248,7 @@ public class FlagWatcher
protected TargetedDisguise getDisguise()
{
return disguise;
return _disguise;
}
private boolean getEntityFlag(int byteValue)
@ -249,44 +258,44 @@ public class FlagWatcher
public EntityEquipment getEquipment()
{
return equipment;
return _equipment;
}
public ItemStack getItemInMainHand()
{
if (equipment == null)
if (_equipment == null)
return null;
return equipment.getItemInMainHand();
return _equipment.getItemInMainHand();
}
public ItemStack getItemInOffHand()
{
if (equipment == null)
if (_equipment == null)
return null;
return equipment.getItemInOffHand();
return _equipment.getItemInOffHand();
}
public ItemStack getItemStack(EquipmentSlot slot)
{
if (equipment == null)
if (_equipment == null)
return null;
switch (slot)
{
case CHEST:
return equipment.getChestplate();
return _equipment.getChestplate();
case FEET:
return equipment.getBoots();
return _equipment.getBoots();
case HAND:
return equipment.getItemInMainHand();
return _equipment.getItemInMainHand();
case HEAD:
return equipment.getHelmet();
return _equipment.getHelmet();
case LEGS:
return equipment.getLeggings();
return _equipment.getLeggings();
case OFF_HAND:
return equipment.getItemInOffHand();
return _equipment.getItemInOffHand();
}
return null;
@ -294,9 +303,9 @@ public class FlagWatcher
protected <Y> Y getValue(FlagType<Y> flagType)
{
if (entityValues.containsKey(flagType.getIndex()))
if (_entityValues.containsKey(flagType.getIndex()))
{
return (Y) entityValues.get(flagType.getIndex());
return (Y) _entityValues.get(flagType.getIndex());
}
return flagType.getDefault();
@ -304,12 +313,12 @@ public class FlagWatcher
public List<WrappedWatchableObject> getWatchableObjects()
{
if (watchableObjects == null)
if (_watchableObjects == null)
{
rebuildWatchableObjects();
}
return watchableObjects;
return _watchableObjects;
}
public boolean hasCustomName()
@ -319,7 +328,7 @@ public class FlagWatcher
protected boolean hasValue(FlagType no)
{
return entityValues.containsKey(no.getIndex());
return _entityValues.containsKey(no.getIndex());
}
public boolean isBurning()
@ -334,7 +343,7 @@ public class FlagWatcher
public boolean isEntityAnimationsAdded()
{
return addEntityAnimations;
return _addEntityAnimations;
}
public boolean isFlyingWithElytra()
@ -374,25 +383,29 @@ public class FlagWatcher
public void rebuildWatchableObjects()
{
watchableObjects = new ArrayList<>();
_watchableObjects = new ArrayList<>();
for (int i = 0; i <= 31; i++)// TODO
for (int i = 0; i <= 31; i++)
{
WrappedWatchableObject watchable = null;
if (this.entityValues.containsKey(i) && this.entityValues.get(i) != null)
if (_entityValues.containsKey(i) && _entityValues.get(i) != null)
{
watchable = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(i, entityValues.get(i)));
watchable = ReflectionManager.createWatchable(i, _entityValues.get(i));
}
else if (this.backupEntityValues.containsKey(i) && this.backupEntityValues.get(i) != null)
else if (_backupEntityValues.containsKey(i) && _backupEntityValues.get(i) != null)
{
watchable = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(i, entityValues.get(i)));
watchable = ReflectionManager.createWatchable(i, _backupEntityValues.get(i));
}
else
{
continue;
}
if (watchable != null)
{
watchableObjects.add(watchable);
}
if (watchable == null)
continue;
_watchableObjects.add(watchable);
}
}
@ -407,24 +420,26 @@ public class FlagWatcher
for (FlagType data : dataValues)
{
if (!entityValues.containsKey(data) || entityValues.get(data) == null)
if (!_entityValues.containsKey(data) || _entityValues.get(data) == null)
{
continue;
}
Object value = entityValues.get(data);
Object value = _entityValues.get(data);
if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == FlagType.ENTITY_META)
{
if (!PacketsManager.isStaticMetadataDisguiseType(disguise))
if (!PacketsManager.isStaticMetadataDisguiseType(_disguise))
{
value = addEntityAnimations((byte) value,
WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0));
WrappedDataWatcher.getEntityWatcher(_disguise.getEntity()).getByte(0));
}
}
WrappedWatchableObject watch = new WrappedWatchableObject(
ReflectionManager.createDataWatcherItem(data.getIndex(), value));
WrappedWatchableObject watch = ReflectionManager.createWatchable(data.getIndex(), value);
if (watch == null)
continue;
list.add(watch);
}
@ -446,7 +461,7 @@ public class FlagWatcher
}
catch (InvocationTargetException e)
{
e.printStackTrace(System.out);
e.printStackTrace();
}
}
}
@ -454,7 +469,7 @@ public class FlagWatcher
public void setAddEntityAnimations(boolean isEntityAnimationsAdded)
{
this.addEntityAnimations = isEntityAnimationsAdded;
_addEntityAnimations = isEntityAnimationsAdded;
}
public void setArmor(ItemStack[] itemstack)
@ -467,7 +482,7 @@ public class FlagWatcher
protected void setBackupValue(FlagType no, Object value)
{
backupEntityValues.put(no.getIndex(), value);
_backupEntityValues.put(no.getIndex(), value);
}
public void setBurning(boolean setBurning)
@ -496,7 +511,7 @@ public class FlagWatcher
private void setEntityFlag(int byteValue, boolean flag)
{
modifiedEntityAnimations.add(byteValue);
_modifiedEntityAnimations.add(byteValue);
byte b0 = (byte) getValue(FlagType.ENTITY_META);
@ -579,7 +594,7 @@ public class FlagWatcher
public void setItemStack(EquipmentSlot slot, ItemStack itemStack)
{
if (equipment == null)
if (_equipment == null)
return;
// Itemstack which is null means that its not replacing the disguises itemstack.
@ -600,7 +615,7 @@ public class FlagWatcher
itemToSend = ReflectionManager.getNmsItem(itemStack);
}
setItemStack(equipment, slot, itemStack);
setItemStack(_equipment, slot, itemStack);
if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this)
{
@ -620,7 +635,7 @@ public class FlagWatcher
}
catch (InvocationTargetException e)
{
e.printStackTrace(System.out);
e.printStackTrace();
}
}
}
@ -652,11 +667,11 @@ public class FlagWatcher
protected <Y> void setValue(FlagType<Y> id, Y value)
{
entityValues.put(id.getIndex(), value);
_entityValues.put(id.getIndex(), value);
if (!DisguiseConfig.isMetadataPacketsEnabled())
{
this.rebuildWatchableObjects();
rebuildWatchableObjects();
}
}

View File

@ -14,7 +14,6 @@ import me.libraryaddict.disguise.disguisetypes.watchers.SplashPotionWatcher;
public class MiscDisguise extends TargetedDisguise
{
private int id = -1, data = 0;
public MiscDisguise(DisguiseType disguiseType)
@ -51,9 +50,10 @@ public class MiscDisguise extends TargetedDisguise
((SplashPotionWatcher) getWatcher()).setPotionId(Math.max(0, id));
break;
case DROPPED_ITEM:
if (id > 0)
{
((DroppedItemWatcher) getWatcher()).setItemStack(new ItemStack(id, Math.max(0, data)));
((DroppedItemWatcher) getWatcher()).setItemStack(new ItemStack(id, Math.max(1, data)));
}
break;
case FISHING_HOOK: // Entity ID of whoever is holding fishing rod

View File

@ -2,14 +2,14 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.inventory.ItemStack;
import com.google.common.base.Optional;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
//TODO: Add support for custom items instead of just stone
public class DroppedItemWatcher extends FlagWatcher
{
public DroppedItemWatcher(Disguise disguise)
{
super(disguise);
@ -17,12 +17,12 @@ public class DroppedItemWatcher extends FlagWatcher
public ItemStack getItemStack()
{
return getValue(FlagType.DROPPED_ITEM);
return getValue(FlagType.DROPPED_ITEM).get();
}
public void setItemStack(ItemStack item)
{
setValue(FlagType.DROPPED_ITEM, item);
setValue(FlagType.DROPPED_ITEM, Optional.<ItemStack> of(item));
sendData(FlagType.DROPPED_ITEM);
}
}

View File

@ -45,7 +45,7 @@ public class LivingWatcher extends FlagWatcher
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
}
@ -121,7 +121,7 @@ public class LivingWatcher extends FlagWatcher
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
f1 = f1 / f4 * 255.0F;
@ -211,7 +211,7 @@ public class LivingWatcher extends FlagWatcher
}
catch (InvocationTargetException e)
{
e.printStackTrace(System.out);
e.printStackTrace();
}
}
}

View File

@ -25,6 +25,8 @@ public class PlayerWatcher extends LivingWatcher
public PlayerWatcher(Disguise disguise)
{
super(disguise);
setValue(FlagType.PLAYER_SKIN, FlagType.PLAYER_SKIN.getDefault());
}
@Override
@ -248,7 +250,7 @@ public class PlayerWatcher extends LivingWatcher
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
}
}

View File

@ -89,7 +89,7 @@ public class ClassGetter
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
}
}

View File

@ -142,7 +142,7 @@ public class DisguiseUtilities
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
}
@ -375,7 +375,7 @@ public class DisguiseUtilities
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
}
@ -631,7 +631,7 @@ public class DisguiseUtilities
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
return players;
@ -807,7 +807,7 @@ public class DisguiseUtilities
runnables.get(playerName).add(runnable);
}
return ReflectionManager.getGameProfile(null, origName);
return null;
}
/**
@ -895,7 +895,7 @@ public class DisguiseUtilities
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
}
}, 2);
@ -941,7 +941,7 @@ public class DisguiseUtilities
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
}
}, 2);
@ -954,7 +954,7 @@ public class DisguiseUtilities
Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
}
@ -1008,7 +1008,7 @@ public class DisguiseUtilities
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
}
}, 2);
@ -1018,7 +1018,7 @@ public class DisguiseUtilities
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
}
}
@ -1055,7 +1055,7 @@ public class DisguiseUtilities
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
}
}, 2);
@ -1098,7 +1098,7 @@ public class DisguiseUtilities
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
}
}, 2);
@ -1110,7 +1110,7 @@ public class DisguiseUtilities
Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
}
@ -1162,7 +1162,7 @@ public class DisguiseUtilities
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
// Code to stop player pushing in 1.9
@ -1204,7 +1204,7 @@ public class DisguiseUtilities
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
// Resend entity metadata else he will be invisible to himself until its resent
@ -1218,7 +1218,7 @@ public class DisguiseUtilities
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
player.updateInventory();
@ -1313,7 +1313,7 @@ public class DisguiseUtilities
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
// Send the velocity packets
@ -1396,7 +1396,7 @@ public class DisguiseUtilities
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
}
@ -1449,7 +1449,7 @@ public class DisguiseUtilities
}
catch (InvocationTargetException e)
{
e.printStackTrace(System.out);
e.printStackTrace();
}
}
});
@ -1457,7 +1457,7 @@ public class DisguiseUtilities
}
catch (InvocationTargetException e)
{
e.printStackTrace(System.out);
e.printStackTrace();
}
}

View File

@ -491,7 +491,7 @@ public class Metrics
}
catch (IOException e)
{
e.printStackTrace(System.out);
e.printStackTrace();
}
finally
{

View File

@ -1053,8 +1053,8 @@ public class PacketsManager
if (DisguiseConfig.isMetadataPacketsEnabled() && !isStaticMetadataDisguiseType(disguise))
{
WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager
.createDataWatcherItem(0, WrappedDataWatcher.getEntityWatcher(entity).getByte(0)));
WrappedWatchableObject watch = ReflectionManager.createWatchable(0,
WrappedDataWatcher.getEntityWatcher(entity).getByte(0));
list.add(watch);
@ -1172,9 +1172,10 @@ public class PacketsManager
*/
public static boolean isStaticMetadataDisguiseType(Disguise disguise)
{
return (disguise.getType() == DisguiseType.WOLF || disguise.getType() == DisguiseType.OCELOT
return false;
/* return (disguise.getType() == DisguiseType.WOLF || disguise.getType() == DisguiseType.OCELOT
|| disguise.getType() == DisguiseType.ENDERMAN || disguise.getType() == DisguiseType.SHULKER
|| disguise.getType() == DisguiseType.SPLASH_POTION || disguise.getType() == DisguiseType.FIREWORK
|| disguise.getType() == DisguiseType.DROPPED_ITEM || disguise.getType() == DisguiseType.ENDER_CRYSTAL);
|| disguise.getType() == DisguiseType.DROPPED_ITEM || disguise.getType() == DisguiseType.ENDER_CRYSTAL);*/
}
}

View File

@ -25,11 +25,14 @@ import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.MinecraftKey;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
import com.google.common.base.Optional;
import com.mojang.authlib.GameProfile;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
@ -71,7 +74,7 @@ public class ReflectionManager
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
}
@ -137,7 +140,7 @@ public class ReflectionManager
}
catch (Exception e)
{
e.printStackTrace(System.out);
e.printStackTrace();
}
return null;
@ -175,7 +178,7 @@ public class ReflectionManager
}
catch (Exception e)
{
e.printStackTrace(System.out);
e.printStackTrace();
}
return null;
@ -226,7 +229,7 @@ public class ReflectionManager
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
return null;
@ -240,7 +243,7 @@ public class ReflectionManager
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
return null;
@ -254,7 +257,7 @@ public class ReflectionManager
}
catch (Exception e)
{
e.printStackTrace(System.out);
e.printStackTrace();
}
return null;
@ -273,7 +276,7 @@ public class ReflectionManager
}
catch (Exception e)
{
e.printStackTrace(System.out);
e.printStackTrace();
}
return null;
@ -289,7 +292,7 @@ public class ReflectionManager
}
catch (NoSuchMethodException e)
{
e.printStackTrace(System.out);
e.printStackTrace();
}
return null;
@ -308,7 +311,7 @@ public class ReflectionManager
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
return null;
@ -351,7 +354,7 @@ public class ReflectionManager
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
return null;
@ -365,7 +368,7 @@ public class ReflectionManager
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
return null;
@ -379,7 +382,7 @@ public class ReflectionManager
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
return null;
@ -393,7 +396,7 @@ public class ReflectionManager
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
return null;
@ -414,7 +417,7 @@ public class ReflectionManager
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
return null;
@ -433,7 +436,7 @@ public class ReflectionManager
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
return null;
}
@ -455,7 +458,7 @@ public class ReflectionManager
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
return null;
@ -469,7 +472,7 @@ public class ReflectionManager
}
catch (Exception e)
{
e.printStackTrace(System.out);
e.printStackTrace();
}
return null;
@ -485,7 +488,7 @@ public class ReflectionManager
}
catch (NoSuchMethodException e)
{
e.printStackTrace(System.out);
e.printStackTrace();
}
return null;
@ -504,7 +507,7 @@ public class ReflectionManager
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
return null;
@ -521,7 +524,7 @@ public class ReflectionManager
}
catch (NoSuchFieldException e)
{
e.printStackTrace(System.out);
e.printStackTrace();
}
return null;
@ -540,7 +543,7 @@ public class ReflectionManager
}
catch (Exception e)
{
e.printStackTrace(System.out);
e.printStackTrace();
}
return null;
@ -562,7 +565,7 @@ public class ReflectionManager
}
catch (NoSuchMethodException e)
{
e.printStackTrace(System.out);
e.printStackTrace();
}
return null;
@ -579,7 +582,7 @@ public class ReflectionManager
}
catch (NoSuchMethodException e)
{
e.printStackTrace(System.out);
e.printStackTrace();
}
return null;
@ -598,7 +601,7 @@ public class ReflectionManager
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
return 0;
@ -619,7 +622,7 @@ public class ReflectionManager
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
return null;
@ -645,7 +648,7 @@ public class ReflectionManager
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
return null;
@ -698,7 +701,7 @@ public class ReflectionManager
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
return null;
@ -723,7 +726,7 @@ public class ReflectionManager
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
ex.printStackTrace();
}
}
@ -915,12 +918,21 @@ public class ReflectionManager
* @param value
* @return
*/
public static Object createDataWatcherItem(int id, Object value)
private static Object createDataWatcherItem(int id, Object value)
{
if (value == null)
return null;
Serializer serializer = Registry.get(value.getClass());
Serializer serializer;
if (value instanceof Optional)
{
serializer = Registry.get(((Optional) value).get().getClass(), true);
}
else
{
serializer = Registry.get(value.getClass());
}
WrappedDataWatcherObject watcherObject = new WrappedDataWatcherObject(id, serializer);
@ -938,6 +950,35 @@ public class ReflectionManager
return null;
}
public static WrappedWatchableObject createWatchable(int index, Object obj)
{
if (obj instanceof Optional)
{
Object value = ((Optional) obj).get();
if (value instanceof BlockPosition)
{
value = BlockPosition.getConverter().getSpecific(value);
if (value == null)
return null;
obj = Optional.of(value);
}
else if (value instanceof ItemStack)
{
value = ReflectionManager.getNmsItem((ItemStack) value);
if (value == null)
return null;
obj = Optional.of(value);
}
}
return new WrappedWatchableObject(createDataWatcherItem(index, obj));
}
public static EntityEquipment createEntityEquipment(Entity entity)
{
if (!(entity instanceof LivingEntity))

View File

@ -6,53 +6,67 @@ import java.net.HttpURLConnection;
import java.net.URL;
import java.util.regex.Pattern;
public class UpdateChecker {
public class UpdateChecker
{
private String latestVersion;
private boolean checkHigher(String currentVersion, String newVersion) {
private boolean checkHigher(String currentVersion, String newVersion)
{
String current = toReadable(currentVersion);
String newVers = toReadable(newVersion);
return current.compareTo(newVers) < 0;
}
public void checkUpdate(String currentVersion) {
public void checkUpdate(String currentVersion)
{
String version = getSpigotVersion();
if (version != null) {
if (checkHigher(currentVersion, version)) {
latestVersion = version;
}
}
if (version == null)
return;
if (!checkHigher(currentVersion, version))
return;
latestVersion = version;
}
public String getLatestVersion() {
public String getLatestVersion()
{
return latestVersion;
}
/**
* Asks spigot for the version
*/
private String getSpigotVersion() {
try {
private String getSpigotVersion()
{
try
{
HttpURLConnection con = (HttpURLConnection) new URL("http://www.spigotmc.org/api/general.php").openConnection();
con.setDoOutput(true);
con.setRequestMethod("POST");
con.getOutputStream().write(
("key=98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4&resource=81").getBytes("UTF-8"));
String version = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
if (version.length() <= 7) {
if (version.length() <= 7)
{
return version;
}
} catch (Exception ex) {
System.out.print("[LibsDisguises] Failed to check for a update on spigot. Now checking bukkit..");
}
catch (Exception ex)
{
System.out.print("[LibsDisguises] Failed to check for a update on spigot.");
}
return null;
}
private String toReadable(String version) {
private String toReadable(String version)
{
String[] split = Pattern.compile(".", Pattern.LITERAL).split(version.replace("v", ""));
version = "";
for (String s : split) {
for (String s : split)
{
version += String.format("%4s", s);
}
return version;

View File

@ -150,7 +150,7 @@ public class PacketListenerViewDisguises extends PacketAdapter
if (observer.isSprinting())
b = (byte) (b | 1 << 3);
WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(0, b));
WrappedWatchableObject watch = ReflectionManager.createWatchable(0, b);
watchableList.add(watch);
packet.getWatchableCollectionModifier().write(0, watchableList);