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) catch (Exception ex)
{ {
ex.printStackTrace(System.out); ex.printStackTrace();
} }
} }
} }

View File

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

View File

@ -1,65 +1,85 @@
package me.libraryaddict.disguise.commands; package me.libraryaddict.disguise.commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; 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) { @Override
if (sender.getName().equals("CONSOLE")) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); {
return true; if (sender.getName().equals("CONSOLE"))
} {
if (sender.hasPermission("libsdisguises.disguise.disguiseclone")) { sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
boolean doEquipment = true; return true;
boolean doSneak = false; }
boolean doSprint = false; if (sender.hasPermission("libsdisguises.disguise.disguiseclone"))
for (String option : args) { {
if (StringUtils.startsWithIgnoreCase(option, "ignoreEquip") boolean doEquipment = true;
|| StringUtils.startsWithIgnoreCase(option, "ignoreEnquip")) { boolean doSneak = false;
doEquipment = false; boolean doSprint = false;
} else if (option.equalsIgnoreCase("doSneakSprint")) { for (String option : args)
doSneak = true; {
doSprint = true; if (StringUtils.startsWithIgnoreCase(option, "ignoreEquip")
} else if (option.equalsIgnoreCase("doSneak")) { || StringUtils.startsWithIgnoreCase(option, "ignoreEnquip"))
doSneak = true; {
} else if (option.equalsIgnoreCase("doSprint")) { doEquipment = false;
doSprint = true; }
} else { else if (option.equalsIgnoreCase("doSneakSprint"))
sender.sendMessage(ChatColor.DARK_RED + "Unknown option '" + option {
+ "' - Valid options are 'IgnoreEquipment' 'DoSneakSprint' 'DoSneak' 'DoSprint'"); doSneak = true;
return true; doSprint = true;
} }
} else if (option.equalsIgnoreCase("doSneak"))
LibsDisguises.getInstance().getListener().setDisguiseClone(sender.getName(), new Boolean[]{doEquipment, doSneak, doSprint}); {
sender.sendMessage(ChatColor.RED + "Right click a entity in the next " + DisguiseConfig.getDisguiseCloneExpire() doSneak = true;
+ " seconds to grab the disguise reference!"); }
} else { else if (option.equalsIgnoreCase("doSprint"))
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); {
} doSprint = true;
return true; }
} else
{
/** sender.sendMessage(ChatColor.DARK_RED + "Unknown option '" + option
* Send the player the information + "' - Valid options are 'IgnoreEquipment' 'DoSneakSprint' 'DoSneak' 'DoSprint'");
*/ return true;
@Override }
protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map) { }
sender.sendMessage(ChatColor.DARK_GREEN LibsDisguises.getInstance().getListener().setDisguiseClone(sender.getName(), new Boolean[]
+ "Right click a entity to get a disguise reference you can pass to other disguise commands!"); {
sender.sendMessage(ChatColor.DARK_GREEN doEquipment, doSneak, doSprint
+ "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 sender.sendMessage(ChatColor.RED + "Right click a entity in the next " + DisguiseConfig.getDisguiseCloneExpire()
+ "Optional" + ChatColor.DARK_GREEN + ")"); + " seconds to grab the disguise reference!");
} }
} else
{
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
}
return true;
}
/**
* Send the player the information
*/
@Override
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 + ")");
}
}

View File

@ -1,72 +1,96 @@
package me.libraryaddict.disguise.commands; package me.libraryaddict.disguise.commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; 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) { @Override
if (sender.getName().equals("CONSOLE")) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); {
return true; if (sender.getName().equals("CONSOLE"))
} {
Disguise disguise; sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
try { return true;
disguise = parseDisguise(sender, args, getPermissions(sender)); }
} catch (DisguiseParseException ex) { Disguise disguise;
if (ex.getMessage() != null) { try
sender.sendMessage(ex.getMessage()); {
} disguise = parseDisguise(sender, args, getPermissions(sender));
return true; }
} catch (Exception ex) { catch (DisguiseParseException ex)
ex.printStackTrace(System.out); {
return true; if (ex.getMessage() != null)
} {
if (DisguiseConfig.isNameOfPlayerShownAboveDisguise()) { sender.sendMessage(ex.getMessage());
if (disguise.getWatcher() instanceof LivingWatcher) { }
disguise.getWatcher().setCustomName(((Player) sender).getDisplayName());
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) { return true;
disguise.getWatcher().setCustomNameVisible(true); }
} catch (Exception ex)
} {
} ex.printStackTrace();
DisguiseAPI.disguiseToAll((Player) sender, disguise); return true;
if (disguise.isDisguiseInUse()) { }
sender.sendMessage(ChatColor.RED + "Now disguised as a " + disguise.getType().toReadable());
} else { if (DisguiseConfig.isNameOfPlayerShownAboveDisguise())
sender.sendMessage(ChatColor.RED + "Failed to disguise as a " + disguise.getType().toReadable()); {
} if (disguise.getWatcher() instanceof LivingWatcher)
return true; {
} disguise.getWatcher().setCustomName(((Player) sender).getDisplayName());
/** if (DisguiseConfig.isNameAboveHeadAlwaysVisible())
* Send the player the information {
*/ disguise.getWatcher().setCustomNameVisible(true);
@Override }
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 DisguiseAPI.disguiseToAll((Player) sender, disguise);
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
if (allowedDisguises.contains("player")) { if (disguise.isDisguiseInUse())
sender.sendMessage(ChatColor.DARK_GREEN + "/disguise player <Name>"); {
} sender.sendMessage(ChatColor.RED + "Now disguised as a " + disguise.getType().toReadable());
sender.sendMessage(ChatColor.DARK_GREEN + "/disguise <DisguiseType> <Baby>"); }
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { else
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseplayer <Dropped_Item/Falling_Block> <Id> <Durability>"); {
} sender.sendMessage(ChatColor.RED + "Failed to disguise as a " + disguise.getType().toReadable());
} }
}
return true;
}
/**
* Send the player the information
*/
@Override
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"))
{
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"))
{
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseplayer <Dropped_Item/Falling_Block> <Id> <Durability>");
}
}
}

View File

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

View File

@ -1,64 +1,76 @@
package me.libraryaddict.disguise.commands; package me.libraryaddict.disguise.commands;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; 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) { @Override
if (sender.getName().equals("CONSOLE")) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); {
return true; if (sender.getName().equals("CONSOLE"))
} {
Disguise disguise; sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
try { return true;
disguise = parseDisguise(sender, args, getPermissions(sender)); }
} catch (DisguiseParseException ex) { Disguise disguise;
if (ex.getMessage() != null) { try
sender.sendMessage(ex.getMessage()); {
} disguise = parseDisguise(sender, args, getPermissions(sender));
return true; }
} catch (IllegalAccessException | InvocationTargetException ex) { catch (DisguiseParseException ex)
ex.printStackTrace(System.out); {
return true; if (ex.getMessage() != null)
} {
LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), disguise); sender.sendMessage(ex.getMessage());
sender.sendMessage(ChatColor.RED + "Right click a entity in the next " + DisguiseConfig.getDisguiseEntityExpire() }
+ " seconds to disguise it as a " + disguise.getType().toReadable() + "!"); return true;
return true; }
} catch (IllegalAccessException | InvocationTargetException ex)
{
/** ex.printStackTrace();
* Send the player the information return true;
* }
* @param sender LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), disguise);
* @param map sender.sendMessage(ChatColor.RED + "Right click a entity in the next " + DisguiseConfig.getDisguiseEntityExpire()
*/ + " seconds to disguise it as a " + disguise.getType().toReadable() + "!");
@Override return true;
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 * Send the player the information
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); *
if (allowedDisguises.contains("player")) { * @param sender
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseentity player <Name>"); * @param map
} */
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseentity <DisguiseType> <Baby>"); @Override
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map)
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseentity <Dropped_Item/Falling_Block> <Id> <Durability>"); {
} 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"))
{
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"))
{
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseentity <Dropped_Item/Falling_Block> <Id> <Durability>");
}
}
}

View File

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

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

View File

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

View File

@ -1,254 +1,253 @@
package me.libraryaddict.disguise.commands; package me.libraryaddict.disguise.commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.ClassGetter; import me.libraryaddict.disguise.utilities.ClassGetter;
public class RadiusDisguiseCommand extends BaseDisguiseCommand public class RadiusDisguiseCommand extends BaseDisguiseCommand
{ {
private int maxRadius = 30;
private int maxRadius = 30; private ArrayList<Class> validClasses = new ArrayList<>();
private ArrayList<Class> validClasses = new ArrayList<>();
public RadiusDisguiseCommand(int maxRadius)
public RadiusDisguiseCommand(int maxRadius) {
{ this.maxRadius = maxRadius;
this.maxRadius = maxRadius;
for (Class c : ClassGetter.getClassesForPackage("org.bukkit.entity"))
for (Class c : ClassGetter.getClassesForPackage("org.bukkit.entity")) {
{ if (c != Entity.class && Entity.class.isAssignableFrom(c) && c.getAnnotation(Deprecated.class) == null)
if (c != Entity.class && Entity.class.isAssignableFrom(c) && c.getAnnotation(Deprecated.class) == null) {
{ validClasses.add(c);
validClasses.add(c); }
} }
} }
}
@Override
@Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
{ if (sender.getName().equals("CONSOLE"))
if (sender.getName().equals("CONSOLE")) {
{ sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); return true;
return true; }
}
HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map = getPermissions(sender);
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.");
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); return true;
return true; }
}
if (args.length == 0)
if (args.length == 0) {
{ sendCommandUsage(sender, map);
sendCommandUsage(sender, map); return true;
return true; }
}
if (args[0].equalsIgnoreCase("entitytype") || args[0].equalsIgnoreCase("entitytypes"))
if (args[0].equalsIgnoreCase("entitytype") || args[0].equalsIgnoreCase("entitytypes")) {
{ ArrayList<String> classes = new ArrayList<>();
ArrayList<String> classes = new ArrayList<>();
for (Class c : validClasses)
for (Class c : validClasses) {
{ classes.add(c.getSimpleName());
classes.add(c.getSimpleName()); }
}
Collections.sort(classes);
Collections.sort(classes);
sender.sendMessage(ChatColor.DARK_GREEN + "EntityTypes usable are: " + ChatColor.GREEN
sender.sendMessage(ChatColor.DARK_GREEN + "EntityTypes usable are: " + ChatColor.GREEN + StringUtils.join(classes, ChatColor.DARK_GREEN + ", " + ChatColor.GREEN) + ChatColor.DARK_GREEN + ".");
+ StringUtils.join(classes, ChatColor.DARK_GREEN + ", " + ChatColor.GREEN) + ChatColor.DARK_GREEN + "."); return true;
return true; }
}
Class entityClass = Entity.class;
Class entityClass = Entity.class; EntityType type = null;
EntityType type = null; int starting = 0;
int starting = 0;
if (!isNumeric(args[0]))
if (!isNumeric(args[0])) {
{ for (Class c : validClasses)
for (Class c : validClasses) {
{ if (c.getSimpleName().equalsIgnoreCase(args[0]))
if (c.getSimpleName().equalsIgnoreCase(args[0])) {
{ entityClass = c;
entityClass = c; starting = 1;
starting = 1; break;
break; }
} }
}
if (starting == 0)
if (starting == 0) {
{ try
try {
{ type = EntityType.valueOf(args[0].toUpperCase());
type = EntityType.valueOf(args[0].toUpperCase()); }
} catch (Exception ex)
catch (Exception ex) {
{ }
}
if (type == null)
if (type == null) {
{ sender.sendMessage(ChatColor.RED + "Unrecognised EntityType " + args[0]);
sender.sendMessage(ChatColor.RED + "Unrecognised EntityType " + args[0]); return true;
return true; }
} }
} }
}
if (args.length == starting + 1)
if (args.length == starting + 1) {
{ sender.sendMessage(ChatColor.RED + "You need to supply a disguise as well as the radius"
sender.sendMessage(ChatColor.RED + "You need to supply a disguise as well as the radius" + (starting != 0 ? " and EntityType" : ""));
+ (starting != 0 ? " and EntityType" : "")); return true;
return true; }
}
if (!isNumeric(args[starting]))
if (!isNumeric(args[starting])) {
{ sender.sendMessage(ChatColor.RED + args[starting] + " is not a number");
sender.sendMessage(ChatColor.RED + args[starting] + " is not a number"); return true;
return true; }
}
int radius = Integer.parseInt(args[starting]);
int radius = Integer.parseInt(args[starting]);
if (radius > maxRadius)
if (radius > maxRadius) {
{ sender.sendMessage(ChatColor.RED + "Limited radius to " + maxRadius + "! Don't want to make too much lag right?");
sender.sendMessage(ChatColor.RED + "Limited radius to " + maxRadius + "! Don't want to make too much lag right?"); radius = maxRadius;
radius = maxRadius; }
}
String[] newArgs = new String[args.length - (starting + 1)];
String[] newArgs = new String[args.length - (starting + 1)]; System.arraycopy(args, starting + 1, newArgs, 0, newArgs.length);
System.arraycopy(args, starting + 1, newArgs, 0, newArgs.length); Disguise disguise;
Disguise disguise;
try
try {
{ disguise = parseDisguise(sender, newArgs, map);
disguise = parseDisguise(sender, newArgs, map); }
} catch (DisguiseParseException ex)
catch (DisguiseParseException ex) {
{ if (ex.getMessage() != null)
if (ex.getMessage() != null) {
{ sender.sendMessage(ex.getMessage());
sender.sendMessage(ex.getMessage()); }
}
return true;
return true; }
} catch (Exception ex)
catch (Exception ex) {
{ ex.printStackTrace();
ex.printStackTrace(System.out); return true;
return true; }
}
// Time to use it!
// Time to use it! int disguisedEntitys = 0;
int disguisedEntitys = 0; int miscDisguises = 0;
int miscDisguises = 0;
for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius))
for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) {
{ if (entity == sender)
if (entity == sender) {
{ continue;
continue; }
}
if (type != null ? entity.getType() == type : entityClass.isAssignableFrom(entity.getClass()))
if (type != null ? entity.getType() == type : entityClass.isAssignableFrom(entity.getClass())) {
{ if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled()
if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() && entity instanceof LivingEntity)
&& entity instanceof LivingEntity) {
{ miscDisguises++;
miscDisguises++; continue;
continue; }
}
disguise = disguise.clone();
disguise = disguise.clone();
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise())
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
{ if (disguise.getWatcher() instanceof LivingWatcher)
if (disguise.getWatcher() instanceof LivingWatcher) {
{ disguise.getWatcher().setCustomName(((Player) entity).getDisplayName());
disguise.getWatcher().setCustomName(((Player) entity).getDisplayName()); if (DisguiseConfig.isNameAboveHeadAlwaysVisible())
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
{ disguise.getWatcher().setCustomNameVisible(true);
disguise.getWatcher().setCustomNameVisible(true); }
} }
} }
}
DisguiseAPI.disguiseToAll(entity, disguise);
DisguiseAPI.disguiseToAll(entity, disguise);
if (disguise.isDisguiseInUse())
if (disguise.isDisguiseInUse()) {
{ disguisedEntitys++;
disguisedEntitys++; }
} }
} }
}
if (disguisedEntitys > 0)
if (disguisedEntitys > 0) {
{ sender.sendMessage(ChatColor.RED + "Successfully disguised " + disguisedEntitys + " entities!");
sender.sendMessage(ChatColor.RED + "Successfully disguised " + disguisedEntitys + " entities!"); }
} else
else {
{ sender.sendMessage(ChatColor.RED + "Couldn't find any entities to disguise!");
sender.sendMessage(ChatColor.RED + "Couldn't find any entities to disguise!"); }
}
if (miscDisguises > 0)
if (miscDisguises > 0) {
{ sender.sendMessage(ChatColor.RED + "Failed to disguise " + miscDisguises
sender.sendMessage(ChatColor.RED + "Failed to disguise " + miscDisguises + " entities because the option to disguise a living entity as a non-living has been disabled in the config");
+ " entities because the option to disguise a living entity as a non-living has been disabled in the config"); }
}
return true;
return true; }
}
/**
/** * Send the player the information
* Send the player the information */
*/ @Override
@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);
ArrayList<String> allowedDisguises = getAllowedDisguises(map);
sender.sendMessage(ChatColor.DARK_GREEN + "Disguise all entities in a radius! Caps at 30 blocks!");
sender.sendMessage(ChatColor.DARK_GREEN + "Disguise all entities in a radius! Caps at 30 blocks!"); sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN
sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
String optional = ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")";
String optional = ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")";
if (allowedDisguises.contains("player"))
if (allowedDisguises.contains("player")) {
{ sender.sendMessage((ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional + "> <Radius> player <Name>")
sender.sendMessage((ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional + "> <Radius> player <Name>") .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"));
.replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")); }
}
sender.sendMessage((ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional + "> <Radius> <DisguiseType> <Baby"
sender.sendMessage((ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional + "> <Radius> <DisguiseType> <Baby" + optional + ">").replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"));
+ optional + ">").replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"));
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block"))
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
{ sender.sendMessage((ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional
sender.sendMessage((ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional + "> <Radius> <Dropped_Item/Falling_Block> <Id> <Durability" + optional + ">")
+ "> <Radius> <Dropped_Item/Falling_Block> <Id> <Durability" + optional + ">") .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"));
.replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")); }
}
sender.sendMessage(
sender.sendMessage( ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguiseradius EntityTypes");
ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguiseradius EntityTypes"); }
}
}
}

View File

@ -1,32 +1,41 @@
package me.libraryaddict.disguise.commands; package me.libraryaddict.disguise.commands;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import me.libraryaddict.disguise.DisguiseAPI; 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) { @Override
if (sender.getName().equals("CONSOLE")) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); {
return true; if (sender.getName().equals("CONSOLE"))
} {
if (sender.hasPermission("libsdisguises.undisguise")) { sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
if (DisguiseAPI.isDisguised((Entity) sender)) { return true;
DisguiseAPI.undisguiseToAll((Player) sender); }
sender.sendMessage(ChatColor.RED + "You are no longer disguised"); if (sender.hasPermission("libsdisguises.undisguise"))
} else { {
sender.sendMessage(ChatColor.RED + "You are not disguised!"); if (DisguiseAPI.isDisguised((Entity) sender))
} {
} else { DisguiseAPI.undisguiseToAll((Player) sender);
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); sender.sendMessage(ChatColor.RED + "You are no longer disguised");
} }
return true; else
} {
} sender.sendMessage(ChatColor.RED + "You are not disguised!");
}
}
else
{
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
}
return true;
}
}

View File

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

View File

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

View File

@ -1,66 +1,83 @@
package me.libraryaddict.disguise.commands; package me.libraryaddict.disguise.commands;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseAPI;
public class UndisguiseRadiusCommand implements CommandExecutor { public class UndisguiseRadiusCommand implements CommandExecutor
{
private int maxRadius = 30;
private int maxRadius = 30;
public UndisguiseRadiusCommand(int maxRadius) {
this.maxRadius = maxRadius; public UndisguiseRadiusCommand(int maxRadius)
} {
this.maxRadius = maxRadius;
private boolean isNumeric(String string) { }
try {
Integer.parseInt(string); private boolean isNumeric(String string)
return true; {
} catch (Exception ex) { try
return false; {
} Integer.parseInt(string);
} return true;
}
@Override catch (Exception ex)
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { {
if (sender.getName().equals("CONSOLE")) { return false;
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); }
return true; }
}
if (sender.hasPermission("libsdisguises.undisguiseradius")) { @Override
int radius = maxRadius; public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
if (args.length > 0) { {
if (!isNumeric(args[0])) { if (sender.getName().equals("CONSOLE"))
sender.sendMessage(ChatColor.RED + "Error! " + ChatColor.GREEN + args[0] + ChatColor.RED {
+ " is not a number!"); sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
return true; return true;
} }
radius = Integer.parseInt(args[0]); if (sender.hasPermission("libsdisguises.undisguiseradius"))
if (radius > maxRadius) { {
sender.sendMessage(ChatColor.RED + "Limited radius to " + maxRadius int radius = maxRadius;
+ "! Don't want to make too much lag right?"); if (args.length > 0)
radius = maxRadius; {
} if (!isNumeric(args[0]))
} {
int disguisedEntitys = 0; sender.sendMessage(
for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) { ChatColor.RED + "Error! " + ChatColor.GREEN + args[0] + ChatColor.RED + " is not a number!");
if (entity == sender) { return true;
continue; }
} radius = Integer.parseInt(args[0]);
if (DisguiseAPI.isDisguised(entity)) { if (radius > maxRadius)
DisguiseAPI.undisguiseToAll(entity); {
disguisedEntitys++; sender.sendMessage(
} ChatColor.RED + "Limited radius to " + maxRadius + "! Don't want to make too much lag right?");
} radius = maxRadius;
sender.sendMessage(ChatColor.RED + "Successfully undisguised " + disguisedEntitys + " entities!"); }
} else { }
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); int disguisedEntitys = 0;
} for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius))
return true; {
} if (entity == sender)
} {
continue;
}
if (DisguiseAPI.isDisguised(entity))
{
DisguiseAPI.undisguiseToAll(entity);
disguisedEntitys++;
}
}
sender.sendMessage(ChatColor.RED + "Successfully undisguised " + disguisedEntitys + " entities!");
}
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) catch (Exception e)
{ {
e.printStackTrace(System.out); e.printStackTrace();
} }
// Set the disguise if its a baby or not // Set the disguise if its a baby or not
@ -355,7 +355,7 @@ public abstract class Disguise
} }
catch (InvocationTargetException e) catch (InvocationTargetException e)
{ {
e.printStackTrace(System.out); e.printStackTrace();
} }
} }
} }
@ -398,7 +398,7 @@ public abstract class Disguise
} }
catch (Exception e) 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 // 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) catch (InvocationTargetException e)
{ {
e.printStackTrace(System.out); e.printStackTrace();
} }
} }
} }
} }
catch (InvocationTargetException e) 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<Integer> CREEPER_STATE = new FlagType<Integer>(CreeperWatcher.class, 0, -1);
public static FlagType<ItemStack> DROPPED_ITEM = new FlagType<ItemStack>(DroppedItemWatcher.class, 0, public static FlagType<Optional<ItemStack>> DROPPED_ITEM = new FlagType<Optional<ItemStack>>(DroppedItemWatcher.class, 0,
new ItemStack(Material.AIR)); 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); 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<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); 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<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); 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 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.. * These are the entity values I need to add else it could crash them..
*/ */
private HashMap<Integer, Object> backupEntityValues = new HashMap<>(); private HashMap<Integer, Object> _backupEntityValues = new HashMap<>();
private TargetedDisguise disguise; private TargetedDisguise _disguise;
private HashMap<Integer, Object> entityValues = new HashMap<>(); private HashMap<Integer, Object> _entityValues = new HashMap<>();
private EntityEquipment equipment; private EntityEquipment _equipment;
private boolean hasDied; private boolean _hasDied;
private HashSet<Integer> modifiedEntityAnimations = new HashSet<>(); private HashSet<Integer> _modifiedEntityAnimations = new HashSet<>();
private List<WrappedWatchableObject> watchableObjects; private List<WrappedWatchableObject> _watchableObjects;
public FlagWatcher(Disguise disguise) public FlagWatcher(Disguise disguise)
{ {
this.disguise = (TargetedDisguise) disguise; _disguise = (TargetedDisguise) disguise;
equipment = ReflectionManager.createEntityEquipment(disguise.getEntity()); _equipment = ReflectionManager.createEntityEquipment(disguise.getEntity());
} }
private byte addEntityAnimations(byte originalValue, byte entityValue) private byte addEntityAnimations(byte originalValue, byte entityValue)
@ -52,7 +52,7 @@ public class FlagWatcher
for (int i = 0; i < 6; i++) 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); valueByte = (byte) (valueByte | 1 << i);
} }
@ -73,14 +73,14 @@ public class FlagWatcher
} }
catch (Exception e) catch (Exception e)
{ {
e.printStackTrace(System.out); e.printStackTrace();
cloned = new FlagWatcher(getDisguise()); cloned = new FlagWatcher(getDisguise());
} }
cloned.entityValues = (HashMap<Integer, Object>) entityValues.clone(); cloned._entityValues = (HashMap<Integer, Object>) _entityValues.clone();
cloned.equipment = ReflectionManager.createEntityEquipment(cloned.getDisguise().getEntity()); cloned._equipment = ReflectionManager.createEntityEquipment(cloned.getDisguise().getEntity());
cloned.modifiedEntityAnimations = (HashSet<Integer>) modifiedEntityAnimations.clone(); cloned._modifiedEntityAnimations = (HashSet<Integer>) _modifiedEntityAnimations.clone();
cloned.addEntityAnimations = addEntityAnimations; cloned._addEntityAnimations = _addEntityAnimations;
return cloned; return cloned;
} }
@ -105,35 +105,38 @@ public class FlagWatcher
Object value = null; Object value = null;
if (entityValues.containsKey(id)) if (_entityValues.containsKey(id))
{ {
if (entityValues.get(id) == null) if (_entityValues.get(id) == null)
{ {
continue; 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; continue;
} }
value = backupEntityValues.get(id); value = _backupEntityValues.get(id);
} }
if (value != null) if (value != null)
{ {
if (isEntityAnimationsAdded() && id == 0) if (isEntityAnimationsAdded() && id == 0)
{ {
value = this.addEntityAnimations((byte) value, (byte) watch.getValue()); value = addEntityAnimations((byte) value, (byte) watch.getValue());
} }
boolean isDirty = watch.getDirtyState(); boolean isDirty = watch.getDirtyState();
watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(id, value)); watch = ReflectionManager.createWatchable(id, value);
if (watch == null)
continue;
if (!isDirty) if (!isDirty)
{ {
@ -144,7 +147,10 @@ public class FlagWatcher
{ {
boolean isDirty = watch.getDirtyState(); boolean isDirty = watch.getDirtyState();
watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(id, watch.getValue())); watch = ReflectionManager.createWatchable(id, watch.getValue());
if (watch == null)
continue;
if (!isDirty) if (!isDirty)
{ {
@ -158,21 +164,24 @@ public class FlagWatcher
if (sendAllCustom) if (sendAllCustom)
{ {
// Its sending the entire meta data. Better add the custom meta // 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)) if (sentValues.contains(id))
{ {
continue; continue;
} }
Object value = entityValues.get(id); Object value = _entityValues.get(id);
if (value == null) if (value == null)
{ {
continue; continue;
} }
WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(id, value)); WrappedWatchableObject watch = ReflectionManager.createWatchable(id, value);
if (watch == null)
continue;
newList.add(watch); newList.add(watch);
} }
@ -192,9 +201,9 @@ public class FlagWatcher
{ {
float newHealth = (Float) value; float newHealth = (Float) value;
if (newHealth > 0 && hasDied) if (newHealth > 0 && _hasDied)
{ {
hasDied = false; _hasDied = false;
Bukkit.getScheduler().scheduleSyncDelayedTask(DisguiseUtilities.getPlugin(), new Runnable() Bukkit.getScheduler().scheduleSyncDelayedTask(DisguiseUtilities.getPlugin(), new Runnable()
{ {
@ -203,18 +212,18 @@ public class FlagWatcher
{ {
try try
{ {
DisguiseUtilities.sendSelfDisguise((Player) getDisguise().getEntity(), disguise); DisguiseUtilities.sendSelfDisguise((Player) getDisguise().getEntity(), _disguise);
} }
catch (Exception ex) catch (Exception ex)
{ {
ex.printStackTrace(System.out); ex.printStackTrace();
} }
} }
}, 2); }, 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() protected TargetedDisguise getDisguise()
{ {
return disguise; return _disguise;
} }
private boolean getEntityFlag(int byteValue) private boolean getEntityFlag(int byteValue)
@ -249,44 +258,44 @@ public class FlagWatcher
public EntityEquipment getEquipment() public EntityEquipment getEquipment()
{ {
return equipment; return _equipment;
} }
public ItemStack getItemInMainHand() public ItemStack getItemInMainHand()
{ {
if (equipment == null) if (_equipment == null)
return null; return null;
return equipment.getItemInMainHand(); return _equipment.getItemInMainHand();
} }
public ItemStack getItemInOffHand() public ItemStack getItemInOffHand()
{ {
if (equipment == null) if (_equipment == null)
return null; return null;
return equipment.getItemInOffHand(); return _equipment.getItemInOffHand();
} }
public ItemStack getItemStack(EquipmentSlot slot) public ItemStack getItemStack(EquipmentSlot slot)
{ {
if (equipment == null) if (_equipment == null)
return null; return null;
switch (slot) switch (slot)
{ {
case CHEST: case CHEST:
return equipment.getChestplate(); return _equipment.getChestplate();
case FEET: case FEET:
return equipment.getBoots(); return _equipment.getBoots();
case HAND: case HAND:
return equipment.getItemInMainHand(); return _equipment.getItemInMainHand();
case HEAD: case HEAD:
return equipment.getHelmet(); return _equipment.getHelmet();
case LEGS: case LEGS:
return equipment.getLeggings(); return _equipment.getLeggings();
case OFF_HAND: case OFF_HAND:
return equipment.getItemInOffHand(); return _equipment.getItemInOffHand();
} }
return null; return null;
@ -294,9 +303,9 @@ public class FlagWatcher
protected <Y> Y getValue(FlagType<Y> flagType) 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(); return flagType.getDefault();
@ -304,12 +313,12 @@ public class FlagWatcher
public List<WrappedWatchableObject> getWatchableObjects() public List<WrappedWatchableObject> getWatchableObjects()
{ {
if (watchableObjects == null) if (_watchableObjects == null)
{ {
rebuildWatchableObjects(); rebuildWatchableObjects();
} }
return watchableObjects; return _watchableObjects;
} }
public boolean hasCustomName() public boolean hasCustomName()
@ -319,7 +328,7 @@ public class FlagWatcher
protected boolean hasValue(FlagType no) protected boolean hasValue(FlagType no)
{ {
return entityValues.containsKey(no.getIndex()); return _entityValues.containsKey(no.getIndex());
} }
public boolean isBurning() public boolean isBurning()
@ -334,7 +343,7 @@ public class FlagWatcher
public boolean isEntityAnimationsAdded() public boolean isEntityAnimationsAdded()
{ {
return addEntityAnimations; return _addEntityAnimations;
} }
public boolean isFlyingWithElytra() public boolean isFlyingWithElytra()
@ -374,25 +383,29 @@ public class FlagWatcher
public void rebuildWatchableObjects() 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; 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) if (watchable == null)
{ continue;
watchableObjects.add(watchable);
} _watchableObjects.add(watchable);
} }
} }
@ -407,24 +420,26 @@ public class FlagWatcher
for (FlagType data : dataValues) for (FlagType data : dataValues)
{ {
if (!entityValues.containsKey(data) || entityValues.get(data) == null) if (!_entityValues.containsKey(data) || _entityValues.get(data) == null)
{ {
continue; continue;
} }
Object value = entityValues.get(data); Object value = _entityValues.get(data);
if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == FlagType.ENTITY_META) if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == FlagType.ENTITY_META)
{ {
if (!PacketsManager.isStaticMetadataDisguiseType(disguise)) if (!PacketsManager.isStaticMetadataDisguiseType(_disguise))
{ {
value = addEntityAnimations((byte) value, value = addEntityAnimations((byte) value,
WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0)); WrappedDataWatcher.getEntityWatcher(_disguise.getEntity()).getByte(0));
} }
} }
WrappedWatchableObject watch = new WrappedWatchableObject( WrappedWatchableObject watch = ReflectionManager.createWatchable(data.getIndex(), value);
ReflectionManager.createDataWatcherItem(data.getIndex(), value));
if (watch == null)
continue;
list.add(watch); list.add(watch);
} }
@ -446,7 +461,7 @@ public class FlagWatcher
} }
catch (InvocationTargetException e) catch (InvocationTargetException e)
{ {
e.printStackTrace(System.out); e.printStackTrace();
} }
} }
} }
@ -454,7 +469,7 @@ public class FlagWatcher
public void setAddEntityAnimations(boolean isEntityAnimationsAdded) public void setAddEntityAnimations(boolean isEntityAnimationsAdded)
{ {
this.addEntityAnimations = isEntityAnimationsAdded; _addEntityAnimations = isEntityAnimationsAdded;
} }
public void setArmor(ItemStack[] itemstack) public void setArmor(ItemStack[] itemstack)
@ -467,7 +482,7 @@ public class FlagWatcher
protected void setBackupValue(FlagType no, Object value) protected void setBackupValue(FlagType no, Object value)
{ {
backupEntityValues.put(no.getIndex(), value); _backupEntityValues.put(no.getIndex(), value);
} }
public void setBurning(boolean setBurning) public void setBurning(boolean setBurning)
@ -496,7 +511,7 @@ public class FlagWatcher
private void setEntityFlag(int byteValue, boolean flag) private void setEntityFlag(int byteValue, boolean flag)
{ {
modifiedEntityAnimations.add(byteValue); _modifiedEntityAnimations.add(byteValue);
byte b0 = (byte) getValue(FlagType.ENTITY_META); byte b0 = (byte) getValue(FlagType.ENTITY_META);
@ -579,7 +594,7 @@ public class FlagWatcher
public void setItemStack(EquipmentSlot slot, ItemStack itemStack) public void setItemStack(EquipmentSlot slot, ItemStack itemStack)
{ {
if (equipment == null) if (_equipment == null)
return; return;
// Itemstack which is null means that its not replacing the disguises itemstack. // Itemstack which is null means that its not replacing the disguises itemstack.
@ -600,7 +615,7 @@ public class FlagWatcher
itemToSend = ReflectionManager.getNmsItem(itemStack); itemToSend = ReflectionManager.getNmsItem(itemStack);
} }
setItemStack(equipment, slot, itemStack); setItemStack(_equipment, slot, itemStack);
if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this)
{ {
@ -620,7 +635,7 @@ public class FlagWatcher
} }
catch (InvocationTargetException e) 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) protected <Y> void setValue(FlagType<Y> id, Y value)
{ {
entityValues.put(id.getIndex(), value); _entityValues.put(id.getIndex(), value);
if (!DisguiseConfig.isMetadataPacketsEnabled()) if (!DisguiseConfig.isMetadataPacketsEnabled())
{ {
this.rebuildWatchableObjects(); rebuildWatchableObjects();
} }
} }

View File

@ -14,7 +14,6 @@ import me.libraryaddict.disguise.disguisetypes.watchers.SplashPotionWatcher;
public class MiscDisguise extends TargetedDisguise public class MiscDisguise extends TargetedDisguise
{ {
private int id = -1, data = 0; private int id = -1, data = 0;
public MiscDisguise(DisguiseType disguiseType) public MiscDisguise(DisguiseType disguiseType)
@ -51,9 +50,10 @@ public class MiscDisguise extends TargetedDisguise
((SplashPotionWatcher) getWatcher()).setPotionId(Math.max(0, id)); ((SplashPotionWatcher) getWatcher()).setPotionId(Math.max(0, id));
break; break;
case DROPPED_ITEM: case DROPPED_ITEM:
if (id > 0) if (id > 0)
{ {
((DroppedItemWatcher) getWatcher()).setItemStack(new ItemStack(id, Math.max(0, data))); ((DroppedItemWatcher) getWatcher()).setItemStack(new ItemStack(id, Math.max(1, data)));
} }
break; break;
case FISHING_HOOK: // Entity ID of whoever is holding fishing rod 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 org.bukkit.inventory.ItemStack;
import com.google.common.base.Optional;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
//TODO: Add support for custom items instead of just stone
public class DroppedItemWatcher extends FlagWatcher public class DroppedItemWatcher extends FlagWatcher
{ {
public DroppedItemWatcher(Disguise disguise) public DroppedItemWatcher(Disguise disguise)
{ {
super(disguise); super(disguise);
@ -17,12 +17,12 @@ public class DroppedItemWatcher extends FlagWatcher
public ItemStack getItemStack() public ItemStack getItemStack()
{ {
return getValue(FlagType.DROPPED_ITEM); return getValue(FlagType.DROPPED_ITEM).get();
} }
public void setItemStack(ItemStack item) public void setItemStack(ItemStack item)
{ {
setValue(FlagType.DROPPED_ITEM, item); setValue(FlagType.DROPPED_ITEM, Optional.<ItemStack> of(item));
sendData(FlagType.DROPPED_ITEM); sendData(FlagType.DROPPED_ITEM);
} }
} }

View File

@ -1,220 +1,220 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import com.comphenix.protocol.PacketType.Play.Server; import com.comphenix.protocol.PacketType.Play.Server;
import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.WrappedAttribute; import com.comphenix.protocol.wrappers.WrappedAttribute;
import com.comphenix.protocol.wrappers.WrappedAttribute.Builder; import com.comphenix.protocol.wrappers.WrappedAttribute.Builder;
import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.ReflectionManager; import me.libraryaddict.disguise.utilities.ReflectionManager;
public class LivingWatcher extends FlagWatcher public class LivingWatcher extends FlagWatcher
{ {
static Map<Integer, Object> list = new HashMap<>(); static Map<Integer, Object> list = new HashMap<>();
static Method getId; static Method getId;
static static
{ {
try try
{ {
getId = ReflectionManager.getNmsMethod("MobEffectList", "getId", ReflectionManager.getNmsClass("MobEffectList")); getId = ReflectionManager.getNmsMethod("MobEffectList", "getId", ReflectionManager.getNmsClass("MobEffectList"));
Object REGISTRY = ReflectionManager.getNmsField("MobEffectList", "REGISTRY").get(null); Object REGISTRY = ReflectionManager.getNmsField("MobEffectList", "REGISTRY").get(null);
for (Object next : ((Iterable) REGISTRY)) for (Object next : ((Iterable) REGISTRY))
{ {
int id = (int) getId.invoke(null, next); int id = (int) getId.invoke(null, next);
list.put(id, next); list.put(id, next);
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
ex.printStackTrace(System.out); ex.printStackTrace();
} }
} }
private double maxHealth; private double maxHealth;
private boolean maxHealthSet; private boolean maxHealthSet;
private HashSet<Integer> potionEffects = new HashSet<>(); private HashSet<Integer> potionEffects = new HashSet<>();
public LivingWatcher(Disguise disguise) public LivingWatcher(Disguise disguise)
{ {
super(disguise); super(disguise);
} }
public void addPotionEffect(PotionEffectType potionEffect) public void addPotionEffect(PotionEffectType potionEffect)
{ {
if (!hasPotionEffect(potionEffect)) if (!hasPotionEffect(potionEffect))
{ {
removePotionEffect(potionEffect); removePotionEffect(potionEffect);
potionEffects.add(potionEffect.getId()); potionEffects.add(potionEffect.getId());
sendPotionEffects(); sendPotionEffects();
} }
} }
@Override @Override
public LivingWatcher clone(Disguise disguise) public LivingWatcher clone(Disguise disguise)
{ {
LivingWatcher clone = (LivingWatcher) super.clone(disguise); LivingWatcher clone = (LivingWatcher) super.clone(disguise);
clone.potionEffects = (HashSet<Integer>) potionEffects.clone(); clone.potionEffects = (HashSet<Integer>) potionEffects.clone();
clone.maxHealth = maxHealth; clone.maxHealth = maxHealth;
clone.maxHealthSet = maxHealthSet; clone.maxHealthSet = maxHealthSet;
return clone; return clone;
} }
public float getHealth() public float getHealth()
{ {
return (float) getValue(FlagType.LIVING_HEALTH); return (float) getValue(FlagType.LIVING_HEALTH);
} }
public double getMaxHealth() public double getMaxHealth()
{ {
return maxHealth; return maxHealth;
} }
public boolean isPotionParticlesAmbient() public boolean isPotionParticlesAmbient()
{ {
return (boolean) getValue(FlagType.LIVING_POTION_AMBIENT); return (boolean) getValue(FlagType.LIVING_POTION_AMBIENT);
} }
private int getPotions() private int getPotions()
{ {
int m = 3694022; int m = 3694022;
if (potionEffects.isEmpty()) if (potionEffects.isEmpty())
{ {
return m; return m;
} }
float f1 = 0.0F; float f1 = 0.0F;
float f2 = 0.0F; float f2 = 0.0F;
float f3 = 0.0F; float f3 = 0.0F;
float f4 = 0.0F; float f4 = 0.0F;
try try
{ {
for (int localMobEffect : potionEffects) for (int localMobEffect : potionEffects)
{ {
int n = (Integer) getId.invoke(list.get(localMobEffect)); int n = (Integer) getId.invoke(list.get(localMobEffect));
f1 += (n >> 16 & 0xFF) / 255.0F; f1 += (n >> 16 & 0xFF) / 255.0F;
f2 += (n >> 8 & 0xFF) / 255.0F; f2 += (n >> 8 & 0xFF) / 255.0F;
f3 += (n & 0xFF) / 255.0F; f3 += (n & 0xFF) / 255.0F;
f4 += 1.0F; f4 += 1.0F;
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
ex.printStackTrace(System.out); ex.printStackTrace();
} }
f1 = f1 / f4 * 255.0F; f1 = f1 / f4 * 255.0F;
f2 = f2 / f4 * 255.0F; f2 = f2 / f4 * 255.0F;
f3 = f3 / f4 * 255.0F; f3 = f3 / f4 * 255.0F;
return (int) f1 << 16 | (int) f2 << 8 | (int) f3; return (int) f1 << 16 | (int) f2 << 8 | (int) f3;
} }
public boolean hasPotionEffect(PotionEffectType type) public boolean hasPotionEffect(PotionEffectType type)
{ {
return potionEffects.contains(type.getId()); return potionEffects.contains(type.getId());
} }
public boolean isMaxHealthSet() public boolean isMaxHealthSet()
{ {
return maxHealthSet; return maxHealthSet;
} }
public void removePotionEffect(PotionEffectType type) public void removePotionEffect(PotionEffectType type)
{ {
if (potionEffects.contains(type.getId())) if (potionEffects.contains(type.getId()))
{ {
potionEffects.remove(type.getId()); potionEffects.remove(type.getId());
sendPotionEffects(); sendPotionEffects();
} }
} }
public void setPotionParticlesAmbient(boolean particles) public void setPotionParticlesAmbient(boolean particles)
{ {
setValue(FlagType.LIVING_POTION_AMBIENT, particles); setValue(FlagType.LIVING_POTION_AMBIENT, particles);
sendData(FlagType.LIVING_POTION_AMBIENT); sendData(FlagType.LIVING_POTION_AMBIENT);
} }
private void sendPotionEffects() private void sendPotionEffects()
{ {
setValue(FlagType.LIVING_POTIONS, getPotions()); setValue(FlagType.LIVING_POTIONS, getPotions());
sendData(FlagType.LIVING_POTIONS); sendData(FlagType.LIVING_POTIONS);
} }
public void setHealth(float health) public void setHealth(float health)
{ {
setValue(FlagType.LIVING_HEALTH, health); setValue(FlagType.LIVING_HEALTH, health);
sendData(FlagType.LIVING_HEALTH); sendData(FlagType.LIVING_HEALTH);
} }
public int getArrowsSticking() public int getArrowsSticking()
{ {
return (int) getValue(FlagType.LIVING_ARROWS); return (int) getValue(FlagType.LIVING_ARROWS);
} }
public void setArrowsSticking(int arrowsNo) public void setArrowsSticking(int arrowsNo)
{ {
setValue(FlagType.LIVING_ARROWS, arrowsNo); setValue(FlagType.LIVING_ARROWS, arrowsNo);
sendData(FlagType.LIVING_ARROWS); sendData(FlagType.LIVING_ARROWS);
} }
public void setMaxHealth(double newHealth) public void setMaxHealth(double newHealth)
{ {
this.maxHealth = newHealth; this.maxHealth = newHealth;
this.maxHealthSet = true; this.maxHealthSet = true;
if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this)
{ {
PacketContainer packet = new PacketContainer(Server.UPDATE_ATTRIBUTES); PacketContainer packet = new PacketContainer(Server.UPDATE_ATTRIBUTES);
List<WrappedAttribute> attributes = new ArrayList<>(); List<WrappedAttribute> attributes = new ArrayList<>();
Builder builder; Builder builder;
builder = WrappedAttribute.newBuilder(); builder = WrappedAttribute.newBuilder();
builder.attributeKey("generic.maxHealth"); builder.attributeKey("generic.maxHealth");
builder.baseValue(getMaxHealth()); builder.baseValue(getMaxHealth());
builder.packet(packet); builder.packet(packet);
attributes.add(builder.build()); attributes.add(builder.build());
Entity entity = getDisguise().getEntity(); Entity entity = getDisguise().getEntity();
packet.getIntegers().write(0, entity.getEntityId()); packet.getIntegers().write(0, entity.getEntityId());
packet.getAttributeCollectionModifier().write(0, attributes); packet.getAttributeCollectionModifier().write(0, attributes);
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) for (Player player : DisguiseUtilities.getPerverts(getDisguise()))
{ {
try try
{ {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false); ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
} }
catch (InvocationTargetException e) catch (InvocationTargetException e)
{ {
e.printStackTrace(System.out); e.printStackTrace();
} }
} }
} }
} }
} }

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -1053,8 +1053,8 @@ public class PacketsManager
if (DisguiseConfig.isMetadataPacketsEnabled() && !isStaticMetadataDisguiseType(disguise)) if (DisguiseConfig.isMetadataPacketsEnabled() && !isStaticMetadataDisguiseType(disguise))
{ {
WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager WrappedWatchableObject watch = ReflectionManager.createWatchable(0,
.createDataWatcherItem(0, WrappedDataWatcher.getEntityWatcher(entity).getByte(0))); WrappedDataWatcher.getEntityWatcher(entity).getByte(0));
list.add(watch); list.add(watch);
@ -1172,9 +1172,10 @@ public class PacketsManager
*/ */
public static boolean isStaticMetadataDisguiseType(Disguise disguise) 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.ENDERMAN || disguise.getType() == DisguiseType.SHULKER
|| disguise.getType() == DisguiseType.SPLASH_POTION || disguise.getType() == DisguiseType.FIREWORK || 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.inventory.ItemStack;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.MinecraftKey; import com.comphenix.protocol.wrappers.MinecraftKey;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry; import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer; import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject; import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
import com.comphenix.protocol.wrappers.WrappedGameProfile; import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
import com.google.common.base.Optional;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.DisguiseType;
@ -71,7 +74,7 @@ public class ReflectionManager
} }
catch (Exception ex) catch (Exception ex)
{ {
ex.printStackTrace(System.out); ex.printStackTrace();
} }
} }
@ -137,7 +140,7 @@ public class ReflectionManager
} }
catch (Exception e) catch (Exception e)
{ {
e.printStackTrace(System.out); e.printStackTrace();
} }
return null; return null;
@ -175,7 +178,7 @@ public class ReflectionManager
} }
catch (Exception e) catch (Exception e)
{ {
e.printStackTrace(System.out); e.printStackTrace();
} }
return null; return null;
@ -226,7 +229,7 @@ public class ReflectionManager
} }
catch (Exception ex) catch (Exception ex)
{ {
ex.printStackTrace(System.out); ex.printStackTrace();
} }
return null; return null;
@ -240,7 +243,7 @@ public class ReflectionManager
} }
catch (Exception ex) catch (Exception ex)
{ {
ex.printStackTrace(System.out); ex.printStackTrace();
} }
return null; return null;
@ -254,7 +257,7 @@ public class ReflectionManager
} }
catch (Exception e) catch (Exception e)
{ {
e.printStackTrace(System.out); e.printStackTrace();
} }
return null; return null;
@ -273,7 +276,7 @@ public class ReflectionManager
} }
catch (Exception e) catch (Exception e)
{ {
e.printStackTrace(System.out); e.printStackTrace();
} }
return null; return null;
@ -289,7 +292,7 @@ public class ReflectionManager
} }
catch (NoSuchMethodException e) catch (NoSuchMethodException e)
{ {
e.printStackTrace(System.out); e.printStackTrace();
} }
return null; return null;
@ -308,7 +311,7 @@ public class ReflectionManager
} }
catch (Exception ex) catch (Exception ex)
{ {
ex.printStackTrace(System.out); ex.printStackTrace();
} }
return null; return null;
@ -351,7 +354,7 @@ public class ReflectionManager
} }
catch (Exception ex) catch (Exception ex)
{ {
ex.printStackTrace(System.out); ex.printStackTrace();
} }
return null; return null;
@ -365,7 +368,7 @@ public class ReflectionManager
} }
catch (Exception ex) catch (Exception ex)
{ {
ex.printStackTrace(System.out); ex.printStackTrace();
} }
return null; return null;
@ -379,7 +382,7 @@ public class ReflectionManager
} }
catch (Exception ex) catch (Exception ex)
{ {
ex.printStackTrace(System.out); ex.printStackTrace();
} }
return null; return null;
@ -393,7 +396,7 @@ public class ReflectionManager
} }
catch (Exception ex) catch (Exception ex)
{ {
ex.printStackTrace(System.out); ex.printStackTrace();
} }
return null; return null;
@ -414,7 +417,7 @@ public class ReflectionManager
} }
catch (Exception ex) catch (Exception ex)
{ {
ex.printStackTrace(System.out); ex.printStackTrace();
} }
return null; return null;
@ -433,7 +436,7 @@ public class ReflectionManager
} }
catch (Exception ex) catch (Exception ex)
{ {
ex.printStackTrace(System.out); ex.printStackTrace();
} }
return null; return null;
} }
@ -455,7 +458,7 @@ public class ReflectionManager
} }
catch (Exception ex) catch (Exception ex)
{ {
ex.printStackTrace(System.out); ex.printStackTrace();
} }
return null; return null;
@ -469,7 +472,7 @@ public class ReflectionManager
} }
catch (Exception e) catch (Exception e)
{ {
e.printStackTrace(System.out); e.printStackTrace();
} }
return null; return null;
@ -485,7 +488,7 @@ public class ReflectionManager
} }
catch (NoSuchMethodException e) catch (NoSuchMethodException e)
{ {
e.printStackTrace(System.out); e.printStackTrace();
} }
return null; return null;
@ -504,7 +507,7 @@ public class ReflectionManager
} }
catch (Exception ex) catch (Exception ex)
{ {
ex.printStackTrace(System.out); ex.printStackTrace();
} }
return null; return null;
@ -521,7 +524,7 @@ public class ReflectionManager
} }
catch (NoSuchFieldException e) catch (NoSuchFieldException e)
{ {
e.printStackTrace(System.out); e.printStackTrace();
} }
return null; return null;
@ -540,7 +543,7 @@ public class ReflectionManager
} }
catch (Exception e) catch (Exception e)
{ {
e.printStackTrace(System.out); e.printStackTrace();
} }
return null; return null;
@ -562,7 +565,7 @@ public class ReflectionManager
} }
catch (NoSuchMethodException e) catch (NoSuchMethodException e)
{ {
e.printStackTrace(System.out); e.printStackTrace();
} }
return null; return null;
@ -579,7 +582,7 @@ public class ReflectionManager
} }
catch (NoSuchMethodException e) catch (NoSuchMethodException e)
{ {
e.printStackTrace(System.out); e.printStackTrace();
} }
return null; return null;
@ -598,7 +601,7 @@ public class ReflectionManager
} }
catch (Exception ex) catch (Exception ex)
{ {
ex.printStackTrace(System.out); ex.printStackTrace();
} }
return 0; return 0;
@ -619,7 +622,7 @@ public class ReflectionManager
} }
catch (Exception ex) catch (Exception ex)
{ {
ex.printStackTrace(System.out); ex.printStackTrace();
} }
return null; return null;
@ -645,7 +648,7 @@ public class ReflectionManager
} }
catch (Exception ex) catch (Exception ex)
{ {
ex.printStackTrace(System.out); ex.printStackTrace();
} }
return null; return null;
@ -698,7 +701,7 @@ public class ReflectionManager
} }
catch (Exception ex) catch (Exception ex)
{ {
ex.printStackTrace(System.out); ex.printStackTrace();
} }
return null; return null;
@ -723,7 +726,7 @@ public class ReflectionManager
} }
catch (Exception ex) catch (Exception ex)
{ {
ex.printStackTrace(System.out); ex.printStackTrace();
} }
} }
@ -915,12 +918,21 @@ public class ReflectionManager
* @param value * @param value
* @return * @return
*/ */
public static Object createDataWatcherItem(int id, Object value) private static Object createDataWatcherItem(int id, Object value)
{ {
if (value == null) if (value == null)
return 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); WrappedDataWatcherObject watcherObject = new WrappedDataWatcherObject(id, serializer);
@ -938,6 +950,35 @@ public class ReflectionManager
return null; 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) public static EntityEquipment createEntityEquipment(Entity entity)
{ {
if (!(entity instanceof LivingEntity)) if (!(entity instanceof LivingEntity))

View File

@ -1,60 +1,74 @@
package me.libraryaddict.disguise.utilities; package me.libraryaddict.disguise.utilities;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class UpdateChecker { public class UpdateChecker
{
private String latestVersion;
private String latestVersion;
private boolean checkHigher(String currentVersion, String newVersion) {
String current = toReadable(currentVersion); private boolean checkHigher(String currentVersion, String newVersion)
String newVers = toReadable(newVersion); {
return current.compareTo(newVers) < 0; String current = toReadable(currentVersion);
} String newVers = toReadable(newVersion);
return current.compareTo(newVers) < 0;
public void checkUpdate(String currentVersion) { }
String version = getSpigotVersion();
if (version != null) { public void checkUpdate(String currentVersion)
if (checkHigher(currentVersion, version)) { {
latestVersion = version; String version = getSpigotVersion();
}
} if (version == null)
} return;
public String getLatestVersion() { if (!checkHigher(currentVersion, version))
return latestVersion; return;
}
latestVersion = version;
/** }
* Asks spigot for the version
*/ public String getLatestVersion()
private String getSpigotVersion() { {
try { return latestVersion;
HttpURLConnection con = (HttpURLConnection) new URL("http://www.spigotmc.org/api/general.php").openConnection(); }
con.setDoOutput(true);
con.setRequestMethod("POST"); /**
con.getOutputStream().write( * Asks spigot for the version
("key=98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4&resource=81").getBytes("UTF-8")); */
String version = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine(); private String getSpigotVersion()
if (version.length() <= 7) { {
return version; try
} {
} catch (Exception ex) { HttpURLConnection con = (HttpURLConnection) new URL("http://www.spigotmc.org/api/general.php").openConnection();
System.out.print("[LibsDisguises] Failed to check for a update on spigot. Now checking bukkit.."); con.setDoOutput(true);
} con.setRequestMethod("POST");
return null; con.getOutputStream().write(
} ("key=98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4&resource=81").getBytes("UTF-8"));
String version = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
private String toReadable(String version) { if (version.length() <= 7)
String[] split = Pattern.compile(".", Pattern.LITERAL).split(version.replace("v", "")); {
version = ""; return version;
for (String s : split) { }
version += String.format("%4s", s); }
} catch (Exception ex)
return version; {
} System.out.print("[LibsDisguises] Failed to check for a update on spigot.");
} }
return null;
}
private String toReadable(String version)
{
String[] split = Pattern.compile(".", Pattern.LITERAL).split(version.replace("v", ""));
version = "";
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()) if (observer.isSprinting())
b = (byte) (b | 1 << 3); b = (byte) (b | 1 << 3);
WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(0, b)); WrappedWatchableObject watch = ReflectionManager.createWatchable(0, b);
watchableList.add(watch); watchableList.add(watch);
packet.getWatchableCollectionModifier().write(0, watchableList); packet.getWatchableCollectionModifier().write(0, watchableList);