- Changed entire project to gradle

- Updated for 1.8.3
- No more errors, woo
This commit is contained in:
NavidK0
2015-03-09 20:28:41 -04:00
parent 14757a035b
commit 573f4cdc88
81 changed files with 299 additions and 645 deletions

View File

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

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

@@ -0,0 +1,63 @@
package me.libraryaddict.disguise.commands;
import java.util.ArrayList;
import java.util.HashMap;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.DisguiseListener;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.utilities.BaseDisguiseCommand;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
public class DisguiseEntityCommand extends BaseDisguiseCommand {
private DisguiseListener listener;
public DisguiseEntityCommand(DisguiseListener listener) {
this.listener = listener;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
return true;
}
Disguise disguise;
try {
disguise = parseDisguise(sender, args, getPermissions(sender));
} catch (DisguiseParseException ex) {
if (ex.getMessage() != null) {
sender.sendMessage(ex.getMessage());
}
return true;
} catch (Exception ex) {
ex.printStackTrace();
return true;
}
listener.setDisguiseEntity(sender.getName(), disguise);
sender.sendMessage(ChatColor.RED + "Right click a entity in the next " + DisguiseConfig.getDisguiseEntityExpire()
+ " seconds to disguise it as a " + disguise.getType().toReadable() + "!");
return true;
}
/**
* Send the player the information
*/
protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map) {
ArrayList<String> allowedDisguises = getAllowedDisguises(map);
sender.sendMessage(ChatColor.DARK_GREEN + "Choose a disguise then right click a entity to disguise it!");
sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
if (allowedDisguises.contains("player"))
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

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

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

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

View File

@@ -0,0 +1,21 @@
package me.libraryaddict.disguise.commands;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class LibsDisguisesCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
sender.sendMessage(ChatColor.DARK_GREEN
+ "This server is running "
+ "Lib's Disguises "
+ (sender.getName().equals("libraryaddict") ? "v"
+ Bukkit.getPluginManager().getPlugin("LibsDisguises").getDescription().getVersion() + " " : "")
+ "by libraryaddict");
return true;
}
}

View File

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

@@ -0,0 +1,30 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.DisguiseListener;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class UndisguiseEntityCommand implements CommandExecutor {
private DisguiseListener listener;
public UndisguiseEntityCommand(DisguiseListener listener) {
this.listener = listener;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
return true;
}
if (sender.hasPermission("libsdisguises.undisguiseentity")) {
listener.setDisguiseEntity(sender.getName(), null);
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

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

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