Clean up code a bit

This commit is contained in:
libraryaddict 2020-03-09 09:00:58 +13:00
parent c31408f956
commit 2a6928a498
No known key found for this signature in database
GPG Key ID: 052E4FBCD257AEA4
41 changed files with 2032 additions and 1993 deletions

View File

@ -1,6 +1,19 @@
package me.libraryaddict.disguise;
import me.libraryaddict.disguise.commands.*;
import me.libraryaddict.disguise.commands.LibsDisguisesCommand;
import me.libraryaddict.disguise.commands.disguise.DisguiseCommand;
import me.libraryaddict.disguise.commands.disguise.DisguiseEntityCommand;
import me.libraryaddict.disguise.commands.disguise.DisguisePlayerCommand;
import me.libraryaddict.disguise.commands.disguise.DisguiseRadiusCommand;
import me.libraryaddict.disguise.commands.modify.DisguiseModifyCommand;
import me.libraryaddict.disguise.commands.modify.DisguiseModifyEntityCommand;
import me.libraryaddict.disguise.commands.modify.DisguiseModifyPlayerCommand;
import me.libraryaddict.disguise.commands.modify.DisguiseModifyRadiusCommand;
import me.libraryaddict.disguise.commands.undisguise.UndisguiseCommand;
import me.libraryaddict.disguise.commands.undisguise.UndisguiseEntityCommand;
import me.libraryaddict.disguise.commands.undisguise.UndisguisePlayerCommand;
import me.libraryaddict.disguise.commands.undisguise.UndisguiseRadiusCommand;
import me.libraryaddict.disguise.commands.utils.*;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.metrics.MetricsInitalizer;

View File

@ -1,12 +1,20 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.commands.disguise.DisguiseCommand;
import me.libraryaddict.disguise.commands.disguise.DisguiseEntityCommand;
import me.libraryaddict.disguise.commands.disguise.DisguisePlayerCommand;
import me.libraryaddict.disguise.commands.disguise.DisguiseRadiusCommand;
import me.libraryaddict.disguise.commands.modify.DisguiseModifyCommand;
import me.libraryaddict.disguise.commands.modify.DisguiseModifyEntityCommand;
import me.libraryaddict.disguise.commands.modify.DisguiseModifyPlayerCommand;
import me.libraryaddict.disguise.commands.modify.DisguiseModifyRadiusCommand;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.params.ParamInfo;
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.params.ParamInfo;
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandExecutor;

View File

@ -8,9 +8,9 @@ import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;

View File

@ -1,129 +1,130 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (isNotPremium(sender)) {
return true;
}
if (!(sender instanceof Entity)) {
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true;
}
if (args.length == 0) {
sendCommandUsage(sender, getPermissions(sender));
return true;
}
Disguise disguise;
try {
disguise = DisguiseParser.parseDisguise(sender, (Entity) sender, getPermNode(),
DisguiseUtilities.split(StringUtils.join(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() && !sender.hasPermission("libsdisguises.hidename")) {
if (disguise.getWatcher() instanceof LivingWatcher) {
disguise.getWatcher().setCustomName(getDisplayName(sender));
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
disguise.getWatcher().setCustomNameVisible(true);
}
}
}
disguise.setEntity((Player) sender);
if (!setViewDisguise(args)) {
// They prefer to have the opposite of whatever the view disguises option is
if (DisguiseAPI.hasSelfDisguisePreference(disguise.getEntity()) &&
disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewDisguises())
disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible());
}
disguise.startDisguise();
if (disguise.isDisguiseInUse()) {
sender.sendMessage(LibsMsg.DISGUISED.get(disguise.getType().toReadable()));
} else {
sender.sendMessage(LibsMsg.FAILED_DISGIUSE.get(disguise.getType().toReadable()));
}
return true;
}
private boolean setViewDisguise(String[] strings) {
for (String string : strings) {
if (!string.equalsIgnoreCase("setSelfDisguiseVisible"))
continue;
return true;
}
return false;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<>();
String[] args = getPreviousArgs(origArgs);
DisguisePermissions perms = getPermissions(sender);
return filterTabs(getTabDisguiseTypes(sender, perms, args, 0, getCurrentArg(origArgs)), origArgs);
}
/**
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
ArrayList<String> allowedDisguises = getAllowedDisguises(permissions);
sender.sendMessage(LibsMsg.DISG_HELP1.get());
sender.sendMessage(LibsMsg.CAN_USE_DISGS
.get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)));
if (allowedDisguises.contains("player")) {
sender.sendMessage(LibsMsg.DISG_HELP2.get());
}
sender.sendMessage(LibsMsg.DISG_HELP3.get());
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
sender.sendMessage(LibsMsg.DISG_HELP4.get());
}
}
}
package me.libraryaddict.disguise.commands.disguise;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.commands.DisguiseBaseCommand;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (isNotPremium(sender)) {
return true;
}
if (!(sender instanceof Entity)) {
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true;
}
if (args.length == 0) {
sendCommandUsage(sender, getPermissions(sender));
return true;
}
Disguise disguise;
try {
disguise = DisguiseParser.parseDisguise(sender, (Entity) sender, getPermNode(),
DisguiseUtilities.split(StringUtils.join(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() && !sender.hasPermission("libsdisguises.hidename")) {
if (disguise.getWatcher() instanceof LivingWatcher) {
disguise.getWatcher().setCustomName(getDisplayName(sender));
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
disguise.getWatcher().setCustomNameVisible(true);
}
}
}
disguise.setEntity((Player) sender);
if (!setViewDisguise(args)) {
// They prefer to have the opposite of whatever the view disguises option is
if (DisguiseAPI.hasSelfDisguisePreference(disguise.getEntity()) &&
disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewDisguises())
disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible());
}
disguise.startDisguise();
if (disguise.isDisguiseInUse()) {
sender.sendMessage(LibsMsg.DISGUISED.get(disguise.getType().toReadable()));
} else {
sender.sendMessage(LibsMsg.FAILED_DISGIUSE.get(disguise.getType().toReadable()));
}
return true;
}
private boolean setViewDisguise(String[] strings) {
for (String string : strings) {
if (!string.equalsIgnoreCase("setSelfDisguiseVisible"))
continue;
return true;
}
return false;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<>();
String[] args = getPreviousArgs(origArgs);
DisguisePermissions perms = getPermissions(sender);
return filterTabs(getTabDisguiseTypes(sender, perms, args, 0, getCurrentArg(origArgs)), origArgs);
}
/**
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
ArrayList<String> allowedDisguises = getAllowedDisguises(permissions);
sender.sendMessage(LibsMsg.DISG_HELP1.get());
sender.sendMessage(LibsMsg.CAN_USE_DISGS
.get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)));
if (allowedDisguises.contains("player")) {
sender.sendMessage(LibsMsg.DISG_HELP2.get());
}
sender.sendMessage(LibsMsg.DISG_HELP3.get());
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
sender.sendMessage(LibsMsg.DISG_HELP4.get());
}
}
}

View File

@ -1,106 +1,107 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (isNotPremium(sender)) {
return true;
}
if (!(sender instanceof Player)) {
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true;
}
if (!getPermissions(sender).hasPermissions()) {
sender.sendMessage(LibsMsg.NO_PERM.get());
return true;
}
if (args.length == 0) {
sendCommandUsage(sender, getPermissions(sender));
return true;
}
String[] disguiseArgs = DisguiseUtilities.split(StringUtils.join(args, " "));
Disguise testDisguise;
try {
testDisguise = DisguiseParser
.parseTestDisguise(sender, getPermNode(), disguiseArgs, getPermissions(sender));
}
catch (DisguiseParseException ex) {
if (ex.getMessage() != null) {
sender.sendMessage(ex.getMessage());
}
return true;
}
catch (IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();
return true;
}
LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), disguiseArgs);
sender.sendMessage(LibsMsg.DISG_ENT_CLICK
.get(DisguiseConfig.getDisguiseEntityExpire(), testDisguise.getType().toReadable()));
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<>();
if (!(sender instanceof Player)) {
return tabs;
}
String[] args = getPreviousArgs(origArgs);
DisguisePermissions perms = getPermissions(sender);
return filterTabs(getTabDisguiseTypes(sender, perms, args, 0, getCurrentArg(origArgs)), origArgs);
}
/**
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
ArrayList<String> allowedDisguises = getAllowedDisguises(permissions);
sender.sendMessage(LibsMsg.DISG_ENT_HELP1.get());
sender.sendMessage(LibsMsg.CAN_USE_DISGS
.get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)));
if (allowedDisguises.contains("player")) {
sender.sendMessage(LibsMsg.DISG_ENT_HELP3.get());
}
sender.sendMessage(LibsMsg.DISG_ENT_HELP4.get());
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
sender.sendMessage(LibsMsg.DISG_ENT_HELP5.get());
}
}
}
package me.libraryaddict.disguise.commands.disguise;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.commands.DisguiseBaseCommand;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (isNotPremium(sender)) {
return true;
}
if (!(sender instanceof Player)) {
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true;
}
if (!getPermissions(sender).hasPermissions()) {
sender.sendMessage(LibsMsg.NO_PERM.get());
return true;
}
if (args.length == 0) {
sendCommandUsage(sender, getPermissions(sender));
return true;
}
String[] disguiseArgs = DisguiseUtilities.split(StringUtils.join(args, " "));
Disguise testDisguise;
try {
testDisguise = DisguiseParser
.parseTestDisguise(sender, getPermNode(), disguiseArgs, getPermissions(sender));
}
catch (DisguiseParseException ex) {
if (ex.getMessage() != null) {
sender.sendMessage(ex.getMessage());
}
return true;
}
catch (IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();
return true;
}
LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), disguiseArgs);
sender.sendMessage(LibsMsg.DISG_ENT_CLICK
.get(DisguiseConfig.getDisguiseEntityExpire(), testDisguise.getType().toReadable()));
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<>();
if (!(sender instanceof Player)) {
return tabs;
}
String[] args = getPreviousArgs(origArgs);
DisguisePermissions perms = getPermissions(sender);
return filterTabs(getTabDisguiseTypes(sender, perms, args, 0, getCurrentArg(origArgs)), origArgs);
}
/**
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
ArrayList<String> allowedDisguises = getAllowedDisguises(permissions);
sender.sendMessage(LibsMsg.DISG_ENT_HELP1.get());
sender.sendMessage(LibsMsg.CAN_USE_DISGS
.get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)));
if (allowedDisguises.contains("player")) {
sender.sendMessage(LibsMsg.DISG_ENT_HELP3.get());
}
sender.sendMessage(LibsMsg.DISG_ENT_HELP4.get());
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
sender.sendMessage(LibsMsg.DISG_ENT_HELP5.get());
}
}
}

View File

@ -1,188 +1,189 @@
package me.libraryaddict.disguise.commands;
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.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
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.command.TabCompleter;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (isNotPremium(sender)) {
return true;
}
DisguisePermissions permissions = getPermissions(sender);
if (!permissions.hasPermissions()) {
sender.sendMessage(LibsMsg.NO_PERM.get());
return true;
}
if (args.length == 0) {
sendCommandUsage(sender, permissions);
return true;
}
if (args.length == 1) {
sender.sendMessage(LibsMsg.DPLAYER_SUPPLY.get());
return true;
}
Entity entityTarget = Bukkit.getPlayer(args[0]);
if (entityTarget == null) {
if (args[0].contains("-")) {
try {
entityTarget = Bukkit.getEntity(UUID.fromString(args[0]));
}
catch (Exception ignored) {
}
}
}
if (entityTarget == null) {
sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0]));
return true;
}
String[] newArgs = new String[args.length - 1];
System.arraycopy(args, 1, newArgs, 0, newArgs.length);
if (newArgs.length == 0) {
sendCommandUsage(sender, permissions);
return true;
}
Disguise disguise;
try {
disguise = DisguiseParser.parseDisguise(sender, entityTarget, getPermNode(),
DisguiseUtilities.split(StringUtils.join(newArgs, " ")), permissions);
}
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(LibsMsg.DISABLED_LIVING_TO_MISC.get());
return true;
}
if (DisguiseConfig.isNameOfPlayerShownAboveDisguise() &&
!entityTarget.hasPermission("libsdisguises.hidename")) {
if (disguise.getWatcher() instanceof LivingWatcher) {
disguise.getWatcher().setCustomName(getDisplayName(entityTarget));
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
disguise.getWatcher().setCustomNameVisible(true);
}
}
}
disguise.setEntity(entityTarget);
if (!setViewDisguise(args)) {
// They prefer to have the opposite of whatever the view disguises option is
if (DisguiseAPI.hasSelfDisguisePreference(disguise.getEntity()) &&
disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewDisguises())
disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible());
}
disguise.startDisguise();
if (disguise.isDisguiseInUse()) {
sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG.get(entityTarget instanceof Player ? entityTarget.getName() :
DisguiseType.getType(entityTarget).toReadable(), disguise.getType().toReadable()));
} else {
sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG_FAIL
.get(entityTarget instanceof Player ? entityTarget.getName() :
DisguiseType.getType(entityTarget).toReadable(), disguise.getType().toReadable()));
}
return true;
}
private boolean setViewDisguise(String[] strings) {
for (String string : strings) {
if (!string.equalsIgnoreCase("setSelfDisguiseVisible"))
continue;
return true;
}
return false;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<>();
String[] args = getPreviousArgs(origArgs);
DisguisePermissions perms = getPermissions(sender);
if (args.length == 0) {
for (Player player : Bukkit.getOnlinePlayers()) {
// If command user cannot see player online, don't tab-complete name
if (sender instanceof Player && !((Player) sender).canSee(player)) {
continue;
}
tabs.add(player.getName());
}
} else {
tabs.addAll(getTabDisguiseTypes(sender, perms, args, 1, getCurrentArg(origArgs)));
}
return filterTabs(tabs, origArgs);
}
/**
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
ArrayList<String> allowedDisguises = getAllowedDisguises(permissions);
sender.sendMessage(LibsMsg.D_HELP1.get());
sender.sendMessage(LibsMsg.CAN_USE_DISGS
.get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)));
if (allowedDisguises.contains("player")) {
sender.sendMessage(LibsMsg.D_HELP3.get());
}
sender.sendMessage(LibsMsg.D_HELP4.get());
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
sender.sendMessage(LibsMsg.D_HELP5.get());
}
}
}
package me.libraryaddict.disguise.commands.disguise;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.commands.DisguiseBaseCommand;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
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.command.TabCompleter;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (isNotPremium(sender)) {
return true;
}
DisguisePermissions permissions = getPermissions(sender);
if (!permissions.hasPermissions()) {
sender.sendMessage(LibsMsg.NO_PERM.get());
return true;
}
if (args.length == 0) {
sendCommandUsage(sender, permissions);
return true;
}
if (args.length == 1) {
sender.sendMessage(LibsMsg.DPLAYER_SUPPLY.get());
return true;
}
Entity entityTarget = Bukkit.getPlayer(args[0]);
if (entityTarget == null) {
if (args[0].contains("-")) {
try {
entityTarget = Bukkit.getEntity(UUID.fromString(args[0]));
}
catch (Exception ignored) {
}
}
}
if (entityTarget == null) {
sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0]));
return true;
}
String[] newArgs = new String[args.length - 1];
System.arraycopy(args, 1, newArgs, 0, newArgs.length);
if (newArgs.length == 0) {
sendCommandUsage(sender, permissions);
return true;
}
Disguise disguise;
try {
disguise = DisguiseParser.parseDisguise(sender, entityTarget, getPermNode(),
DisguiseUtilities.split(StringUtils.join(newArgs, " ")), permissions);
}
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(LibsMsg.DISABLED_LIVING_TO_MISC.get());
return true;
}
if (DisguiseConfig.isNameOfPlayerShownAboveDisguise() &&
!entityTarget.hasPermission("libsdisguises.hidename")) {
if (disguise.getWatcher() instanceof LivingWatcher) {
disguise.getWatcher().setCustomName(getDisplayName(entityTarget));
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
disguise.getWatcher().setCustomNameVisible(true);
}
}
}
disguise.setEntity(entityTarget);
if (!setViewDisguise(args)) {
// They prefer to have the opposite of whatever the view disguises option is
if (DisguiseAPI.hasSelfDisguisePreference(disguise.getEntity()) &&
disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewDisguises())
disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible());
}
disguise.startDisguise();
if (disguise.isDisguiseInUse()) {
sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG.get(entityTarget instanceof Player ? entityTarget.getName() :
DisguiseType.getType(entityTarget).toReadable(), disguise.getType().toReadable()));
} else {
sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG_FAIL
.get(entityTarget instanceof Player ? entityTarget.getName() :
DisguiseType.getType(entityTarget).toReadable(), disguise.getType().toReadable()));
}
return true;
}
private boolean setViewDisguise(String[] strings) {
for (String string : strings) {
if (!string.equalsIgnoreCase("setSelfDisguiseVisible"))
continue;
return true;
}
return false;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<>();
String[] args = getPreviousArgs(origArgs);
DisguisePermissions perms = getPermissions(sender);
if (args.length == 0) {
for (Player player : Bukkit.getOnlinePlayers()) {
// If command user cannot see player online, don't tab-complete name
if (sender instanceof Player && !((Player) sender).canSee(player)) {
continue;
}
tabs.add(player.getName());
}
} else {
tabs.addAll(getTabDisguiseTypes(sender, perms, args, 1, getCurrentArg(origArgs)));
}
return filterTabs(tabs, origArgs);
}
/**
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
ArrayList<String> allowedDisguises = getAllowedDisguises(permissions);
sender.sendMessage(LibsMsg.D_HELP1.get());
sender.sendMessage(LibsMsg.CAN_USE_DISGS
.get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)));
if (allowedDisguises.contains("player")) {
sender.sendMessage(LibsMsg.D_HELP3.get());
}
sender.sendMessage(LibsMsg.D_HELP4.get());
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
sender.sendMessage(LibsMsg.D_HELP5.get());
}
}
}

View File

@ -1,296 +1,296 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.reflection.ClassGetter;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import me.libraryaddict.disguise.utilities.translations.TranslateType;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCompleter {
private int maxRadius = 30;
private ArrayList<Class<? extends Entity>> validClasses = new ArrayList<>();
public DisguiseRadiusCommand(int maxRadius) {
this.maxRadius = maxRadius;
for (EntityType type : EntityType.values()) {
Class c = type.getEntityClass();
while (c != null && Entity.class.isAssignableFrom(c) && !validClasses.contains(c)) {
validClasses.add(c);
c = c.getSuperclass();
}
}
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (isNotPremium(sender)) {
return true;
}
if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true;
}
DisguisePermissions permissions = getPermissions(sender);
if (!permissions.hasPermissions()) {
sender.sendMessage(LibsMsg.NO_PERM.get());
return true;
}
if (args.length == 0) {
sendCommandUsage(sender, permissions);
return true;
}
if (args[0].equalsIgnoreCase(TranslateType.DISGUISES.get("EntityType")) ||
args[0].equalsIgnoreCase(TranslateType.DISGUISES.get("EntityType") + "s")) {
ArrayList<String> classes = new ArrayList<>();
for (Class c : validClasses) {
classes.add(TranslateType.DISGUISES.get(c.getSimpleName()));
}
Collections.sort(classes);
sender.sendMessage(LibsMsg.DRADIUS_ENTITIES
.get(ChatColor.GREEN + StringUtils.join(classes, ChatColor.DARK_GREEN + ", " + ChatColor.GREEN)));
return true;
}
Class entityClass = Entity.class;
EntityType type = null;
int starting = 0;
if (!isInteger(args[0])) {
for (Class c : validClasses) {
if (TranslateType.DISGUISES.get(c.getSimpleName()).equalsIgnoreCase(args[0])) {
entityClass = c;
starting = 1;
break;
}
}
if (starting == 0) {
try {
type = EntityType.valueOf(args[0].toUpperCase());
}
catch (Exception ignored) {
}
if (type == null) {
sender.sendMessage(LibsMsg.DMODRADIUS_UNRECOGNIZED.get(args[0]));
return true;
}
}
}
if (args.length == starting + 1) {
sender.sendMessage(
(starting == 0 ? LibsMsg.DRADIUS_NEEDOPTIONS : LibsMsg.DRADIUS_NEEDOPTIONS_ENTITY).get());
return true;
} else if (args.length < 2) {
sender.sendMessage(LibsMsg.DRADIUS_NEEDOPTIONS.get());
return true;
}
if (!isInteger(args[starting])) {
sender.sendMessage(LibsMsg.NOT_NUMBER.get(args[starting]));
return true;
}
int radius = Integer.parseInt(args[starting]);
if (radius > maxRadius) {
sender.sendMessage(LibsMsg.LIMITED_RADIUS.get(maxRadius));
radius = maxRadius;
}
String[] newArgs = new String[args.length - (starting + 1)];
System.arraycopy(args, starting + 1, newArgs, 0, newArgs.length);
if (newArgs.length == 0) {
sendCommandUsage(sender, permissions);
return true;
}
String[] disguiseArgs = DisguiseUtilities.split(StringUtils.join(newArgs, " "));
try {
Disguise testDisguise = DisguiseParser.parseTestDisguise(sender, getPermNode(), disguiseArgs, permissions);
// Time to use it!
int disguisedEntitys = 0;
int miscDisguises = 0;
Location center;
if (sender instanceof Player) {
center = ((Player) sender).getLocation();
} else {
center = ((BlockCommandSender) sender).getBlock().getLocation().add(0.5, 0, 0.5);
}
for (Entity entity : center.getWorld().getNearbyEntities(center, radius, radius, radius)) {
if (entity == sender) {
continue;
}
if (type != null ? entity.getType() != type : !entityClass.isAssignableFrom(entity.getClass())) {
continue;
}
if (testDisguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() &&
entity instanceof LivingEntity) {
miscDisguises++;
continue;
}
Disguise disguise = DisguiseParser
.parseDisguise(sender, entity, getPermNode(), disguiseArgs, permissions);
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise() &&
!entity.hasPermission("libsdisguises.hidename")) {
if (disguise.getWatcher() instanceof LivingWatcher) {
disguise.getWatcher().setCustomName(getDisplayName(entity));
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
disguise.getWatcher().setCustomNameVisible(true);
}
}
}
disguise.setEntity(entity);
if (!setViewDisguise(args)) {
// They prefer to have the opposite of whatever the view disguises option is
if (DisguiseAPI.hasSelfDisguisePreference(disguise.getEntity()) &&
disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewDisguises())
disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible());
}
disguise.startDisguise();
if (disguise.isDisguiseInUse()) {
disguisedEntitys++;
}
}
if (disguisedEntitys > 0) {
sender.sendMessage(LibsMsg.DISRADIUS.get(disguisedEntitys));
} else {
sender.sendMessage(LibsMsg.DISRADIUS_FAIL.get());
}
if (miscDisguises > 0) {
sender.sendMessage(LibsMsg.DRADIUS_MISCDISG.get(miscDisguises));
}
}
catch (DisguiseParseException ex) {
if (ex.getMessage() != null) {
sender.sendMessage(ex.getMessage());
}
}
catch (Exception ex) {
ex.printStackTrace();
}
return true;
}
private boolean setViewDisguise(String[] strings) {
for (String string : strings) {
if (!string.equalsIgnoreCase("setSelfDisguiseVisible"))
continue;
return true;
}
return false;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<>();
String[] args = getPreviousArgs(origArgs);
DisguisePermissions perms = getPermissions(sender);
if (args.length == 0) {
for (Class<? extends Entity> entityClass : validClasses) {
tabs.add(TranslateType.DISGUISES.get(entityClass.getSimpleName()));
}
return filterTabs(tabs, origArgs);
}
int starting = 1;
if (!isInteger(args[0])) {
for (Class c : validClasses) {
if (!TranslateType.DISGUISES.get(c.getSimpleName()).equalsIgnoreCase(args[0]))
continue;
starting = 2;
break;
}
// Not a valid radius
if (starting == 1 || args.length == 1 || !isInteger(args[1]))
return filterTabs(tabs, origArgs);
}
tabs.addAll(getTabDisguiseTypes(sender, perms, args, starting, getCurrentArg(origArgs)));
return filterTabs(tabs, origArgs);
}
/**
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
ArrayList<String> allowedDisguises = getAllowedDisguises(permissions);
sender.sendMessage(LibsMsg.DRADIUS_HELP1.get(maxRadius));
sender.sendMessage(LibsMsg.CAN_USE_DISGS
.get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)));
if (allowedDisguises.contains("player")) {
sender.sendMessage(LibsMsg.DRADIUS_HELP3.get());
}
sender.sendMessage(LibsMsg.DRADIUS_HELP4.get());
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
sender.sendMessage(LibsMsg.DRADIUS_HELP5.get());
}
sender.sendMessage(LibsMsg.DRADIUS_HELP6.get());
}
}
package me.libraryaddict.disguise.commands.disguise;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.commands.DisguiseBaseCommand;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import me.libraryaddict.disguise.utilities.translations.TranslateType;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCompleter {
private int maxRadius = 30;
private ArrayList<Class<? extends Entity>> validClasses = new ArrayList<>();
public DisguiseRadiusCommand(int maxRadius) {
this.maxRadius = maxRadius;
for (EntityType type : EntityType.values()) {
Class c = type.getEntityClass();
while (c != null && Entity.class.isAssignableFrom(c) && !validClasses.contains(c)) {
validClasses.add(c);
c = c.getSuperclass();
}
}
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (isNotPremium(sender)) {
return true;
}
if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true;
}
DisguisePermissions permissions = getPermissions(sender);
if (!permissions.hasPermissions()) {
sender.sendMessage(LibsMsg.NO_PERM.get());
return true;
}
if (args.length == 0) {
sendCommandUsage(sender, permissions);
return true;
}
if (args[0].equalsIgnoreCase(TranslateType.DISGUISES.get("EntityType")) ||
args[0].equalsIgnoreCase(TranslateType.DISGUISES.get("EntityType") + "s")) {
ArrayList<String> classes = new ArrayList<>();
for (Class c : validClasses) {
classes.add(TranslateType.DISGUISES.get(c.getSimpleName()));
}
Collections.sort(classes);
sender.sendMessage(LibsMsg.DRADIUS_ENTITIES
.get(ChatColor.GREEN + StringUtils.join(classes, ChatColor.DARK_GREEN + ", " + ChatColor.GREEN)));
return true;
}
Class entityClass = Entity.class;
EntityType type = null;
int starting = 0;
if (!isInteger(args[0])) {
for (Class c : validClasses) {
if (TranslateType.DISGUISES.get(c.getSimpleName()).equalsIgnoreCase(args[0])) {
entityClass = c;
starting = 1;
break;
}
}
if (starting == 0) {
try {
type = EntityType.valueOf(args[0].toUpperCase());
}
catch (Exception ignored) {
}
if (type == null) {
sender.sendMessage(LibsMsg.DMODRADIUS_UNRECOGNIZED.get(args[0]));
return true;
}
}
}
if (args.length == starting + 1) {
sender.sendMessage(
(starting == 0 ? LibsMsg.DRADIUS_NEEDOPTIONS : LibsMsg.DRADIUS_NEEDOPTIONS_ENTITY).get());
return true;
} else if (args.length < 2) {
sender.sendMessage(LibsMsg.DRADIUS_NEEDOPTIONS.get());
return true;
}
if (!isInteger(args[starting])) {
sender.sendMessage(LibsMsg.NOT_NUMBER.get(args[starting]));
return true;
}
int radius = Integer.parseInt(args[starting]);
if (radius > maxRadius) {
sender.sendMessage(LibsMsg.LIMITED_RADIUS.get(maxRadius));
radius = maxRadius;
}
String[] newArgs = new String[args.length - (starting + 1)];
System.arraycopy(args, starting + 1, newArgs, 0, newArgs.length);
if (newArgs.length == 0) {
sendCommandUsage(sender, permissions);
return true;
}
String[] disguiseArgs = DisguiseUtilities.split(StringUtils.join(newArgs, " "));
try {
Disguise testDisguise = DisguiseParser.parseTestDisguise(sender, getPermNode(), disguiseArgs, permissions);
// Time to use it!
int disguisedEntitys = 0;
int miscDisguises = 0;
Location center;
if (sender instanceof Player) {
center = ((Player) sender).getLocation();
} else {
center = ((BlockCommandSender) sender).getBlock().getLocation().add(0.5, 0, 0.5);
}
for (Entity entity : center.getWorld().getNearbyEntities(center, radius, radius, radius)) {
if (entity == sender) {
continue;
}
if (type != null ? entity.getType() != type : !entityClass.isAssignableFrom(entity.getClass())) {
continue;
}
if (testDisguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() &&
entity instanceof LivingEntity) {
miscDisguises++;
continue;
}
Disguise disguise = DisguiseParser
.parseDisguise(sender, entity, getPermNode(), disguiseArgs, permissions);
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise() &&
!entity.hasPermission("libsdisguises.hidename")) {
if (disguise.getWatcher() instanceof LivingWatcher) {
disguise.getWatcher().setCustomName(getDisplayName(entity));
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
disguise.getWatcher().setCustomNameVisible(true);
}
}
}
disguise.setEntity(entity);
if (!setViewDisguise(args)) {
// They prefer to have the opposite of whatever the view disguises option is
if (DisguiseAPI.hasSelfDisguisePreference(disguise.getEntity()) &&
disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewDisguises())
disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible());
}
disguise.startDisguise();
if (disguise.isDisguiseInUse()) {
disguisedEntitys++;
}
}
if (disguisedEntitys > 0) {
sender.sendMessage(LibsMsg.DISRADIUS.get(disguisedEntitys));
} else {
sender.sendMessage(LibsMsg.DISRADIUS_FAIL.get());
}
if (miscDisguises > 0) {
sender.sendMessage(LibsMsg.DRADIUS_MISCDISG.get(miscDisguises));
}
}
catch (DisguiseParseException ex) {
if (ex.getMessage() != null) {
sender.sendMessage(ex.getMessage());
}
}
catch (Exception ex) {
ex.printStackTrace();
}
return true;
}
private boolean setViewDisguise(String[] strings) {
for (String string : strings) {
if (!string.equalsIgnoreCase("setSelfDisguiseVisible"))
continue;
return true;
}
return false;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<>();
String[] args = getPreviousArgs(origArgs);
DisguisePermissions perms = getPermissions(sender);
if (args.length == 0) {
for (Class<? extends Entity> entityClass : validClasses) {
tabs.add(TranslateType.DISGUISES.get(entityClass.getSimpleName()));
}
return filterTabs(tabs, origArgs);
}
int starting = 1;
if (!isInteger(args[0])) {
for (Class c : validClasses) {
if (!TranslateType.DISGUISES.get(c.getSimpleName()).equalsIgnoreCase(args[0]))
continue;
starting = 2;
break;
}
// Not a valid radius
if (starting == 1 || args.length == 1 || !isInteger(args[1]))
return filterTabs(tabs, origArgs);
}
tabs.addAll(getTabDisguiseTypes(sender, perms, args, starting, getCurrentArg(origArgs)));
return filterTabs(tabs, origArgs);
}
/**
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
ArrayList<String> allowedDisguises = getAllowedDisguises(permissions);
sender.sendMessage(LibsMsg.DRADIUS_HELP1.get(maxRadius));
sender.sendMessage(LibsMsg.CAN_USE_DISGS
.get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)));
if (allowedDisguises.contains("player")) {
sender.sendMessage(LibsMsg.DRADIUS_HELP3.get());
}
sender.sendMessage(LibsMsg.DRADIUS_HELP4.get());
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
sender.sendMessage(LibsMsg.DRADIUS_HELP5.get());
}
sender.sendMessage(LibsMsg.DRADIUS_HELP6.get());
}
}

View File

@ -1,114 +1,115 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Entity)) {
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true;
}
DisguisePermissions permissions = getPermissions(sender);
if (!permissions.hasPermissions()) {
sender.sendMessage(LibsMsg.NO_PERM.get());
return true;
}
if (args.length == 0) {
sendCommandUsage(sender, permissions);
return true;
}
Disguise disguise = DisguiseAPI.getDisguise((Player) sender, (Entity) sender);
if (disguise == null) {
sender.sendMessage(LibsMsg.NOT_DISGUISED.get());
return true;
}
DisguisePerm disguisePerm = new DisguisePerm(disguise.getType());
if (!permissions.isAllowedDisguise(disguisePerm)) {
sender.sendMessage(LibsMsg.DMODIFY_NO_PERM.get());
return true;
}
String[] options = DisguiseUtilities.split(StringUtils.join(args, " "));
options = DisguiseParser.parsePlaceholders(options, sender, sender);
try {
DisguiseParser.callMethods(sender, disguise, permissions, disguisePerm, new ArrayList<>(), options,
"DisguiseModify");
}
catch (DisguiseParseException ex) {
if (ex.getMessage() != null) {
sender.sendMessage(ex.getMessage());
}
return true;
}
catch (Exception ex) {
ex.printStackTrace();
return true;
}
sender.sendMessage(LibsMsg.DMODIFY_MODIFIED.get());
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
if (!(sender instanceof Player))
return new ArrayList<>();
Disguise disguise = DisguiseAPI.getDisguise((Player) sender, (Entity) sender);
if (disguise == null)
return new ArrayList<>();
String[] args = getPreviousArgs(origArgs);
DisguisePermissions perms = getPermissions(sender);
DisguisePerm disguiseType = new DisguisePerm(disguise.getType());
List<String> tabs = getTabDisguiseOptions(sender, perms, disguiseType, args, 0, getCurrentArg(origArgs));
return filterTabs(tabs, origArgs);
}
/**
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
ArrayList<String> allowedDisguises = getAllowedDisguises(permissions);
sender.sendMessage(LibsMsg.DMODIFY_HELP3.get());
sender.sendMessage(LibsMsg.DMODIFY_HELP3.get());
sender.sendMessage(LibsMsg.DMODIFY_HELP3
.get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)));
}
}
package me.libraryaddict.disguise.commands.modify;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.commands.DisguiseBaseCommand;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Entity)) {
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true;
}
DisguisePermissions permissions = getPermissions(sender);
if (!permissions.hasPermissions()) {
sender.sendMessage(LibsMsg.NO_PERM.get());
return true;
}
if (args.length == 0) {
sendCommandUsage(sender, permissions);
return true;
}
Disguise disguise = DisguiseAPI.getDisguise((Player) sender, (Entity) sender);
if (disguise == null) {
sender.sendMessage(LibsMsg.NOT_DISGUISED.get());
return true;
}
DisguisePerm disguisePerm = new DisguisePerm(disguise.getType());
if (!permissions.isAllowedDisguise(disguisePerm)) {
sender.sendMessage(LibsMsg.DMODIFY_NO_PERM.get());
return true;
}
String[] options = DisguiseUtilities.split(StringUtils.join(args, " "));
options = DisguiseParser.parsePlaceholders(options, sender, sender);
try {
DisguiseParser.callMethods(sender, disguise, permissions, disguisePerm, new ArrayList<>(), options,
"DisguiseModify");
}
catch (DisguiseParseException ex) {
if (ex.getMessage() != null) {
sender.sendMessage(ex.getMessage());
}
return true;
}
catch (Exception ex) {
ex.printStackTrace();
return true;
}
sender.sendMessage(LibsMsg.DMODIFY_MODIFIED.get());
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
if (!(sender instanceof Player))
return new ArrayList<>();
Disguise disguise = DisguiseAPI.getDisguise((Player) sender, (Entity) sender);
if (disguise == null)
return new ArrayList<>();
String[] args = getPreviousArgs(origArgs);
DisguisePermissions perms = getPermissions(sender);
DisguisePerm disguiseType = new DisguisePerm(disguise.getType());
List<String> tabs = getTabDisguiseOptions(sender, perms, disguiseType, args, 0, getCurrentArg(origArgs));
return filterTabs(tabs, origArgs);
}
/**
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
ArrayList<String> allowedDisguises = getAllowedDisguises(permissions);
sender.sendMessage(LibsMsg.DMODIFY_HELP3.get());
sender.sendMessage(LibsMsg.DMODIFY_HELP3.get());
sender.sendMessage(LibsMsg.DMODIFY_HELP3
.get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)));
}
}

View File

@ -1,82 +1,83 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true;
}
DisguisePermissions permissions = getPermissions(sender);
if (!permissions.hasPermissions()) {
sender.sendMessage(LibsMsg.NO_PERM.get());
return true;
}
if (args.length == 0) {
sendCommandUsage(sender, permissions);
return true;
}
// TODO Validate if any disguises have this arg
LibsDisguises.getInstance().getListener()
.setDisguiseModify(sender.getName(), DisguiseUtilities.split(StringUtils.join(args, " ")));
sender.sendMessage(LibsMsg.DMODIFYENT_CLICK.get(DisguiseConfig.getDisguiseEntityExpire()));
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
if (!(sender instanceof Player)) {
return new ArrayList<>();
}
String[] args = getPreviousArgs(origArgs);
DisguisePermissions perms = getPermissions(sender);
if (!perms.hasPermissions()) {
return new ArrayList<>();
}
List<String> tabs = new ArrayList<>();
for (DisguisePerm perm : perms.getAllowed()) {
tabs.addAll(getTabDisguiseOptions(sender, perms, perm, args, 0, getCurrentArg(origArgs)));
}
return filterTabs(tabs, origArgs);
}
/**
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
ArrayList<String> allowedDisguises = getAllowedDisguises(permissions);
sender.sendMessage(LibsMsg.DMODENT_HELP1.get());
sender.sendMessage(LibsMsg.DMODIFY_HELP3
.get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)));
}
}
package me.libraryaddict.disguise.commands.modify;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.commands.DisguiseBaseCommand;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true;
}
DisguisePermissions permissions = getPermissions(sender);
if (!permissions.hasPermissions()) {
sender.sendMessage(LibsMsg.NO_PERM.get());
return true;
}
if (args.length == 0) {
sendCommandUsage(sender, permissions);
return true;
}
// TODO Validate if any disguises have this arg
LibsDisguises.getInstance().getListener()
.setDisguiseModify(sender.getName(), DisguiseUtilities.split(StringUtils.join(args, " ")));
sender.sendMessage(LibsMsg.DMODIFYENT_CLICK.get(DisguiseConfig.getDisguiseEntityExpire()));
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
if (!(sender instanceof Player)) {
return new ArrayList<>();
}
String[] args = getPreviousArgs(origArgs);
DisguisePermissions perms = getPermissions(sender);
if (!perms.hasPermissions()) {
return new ArrayList<>();
}
List<String> tabs = new ArrayList<>();
for (DisguisePerm perm : perms.getAllowed()) {
tabs.addAll(getTabDisguiseOptions(sender, perms, perm, args, 0, getCurrentArg(origArgs)));
}
return filterTabs(tabs, origArgs);
}
/**
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
ArrayList<String> allowedDisguises = getAllowedDisguises(permissions);
sender.sendMessage(LibsMsg.DMODENT_HELP1.get());
sender.sendMessage(LibsMsg.DMODIFY_HELP3
.get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)));
}
}

View File

@ -1,168 +1,169 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
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.command.TabCompleter;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
DisguisePermissions permissions = getPermissions(sender);
if (!permissions.hasPermissions()) {
sender.sendMessage(LibsMsg.NO_PERM.get());
return true;
}
if (args.length == 0) {
sendCommandUsage(sender, permissions);
return true;
}
Entity entityTarget = Bukkit.getPlayer(args[0]);
if (entityTarget == null) {
if (args[0].contains("-")) {
try {
entityTarget = Bukkit.getEntity(UUID.fromString(args[0]));
}
catch (Exception ignored) {
}
}
}
if (entityTarget == null) {
sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0]));
return true;
}
String[] newArgs = new String[args.length - 1];
System.arraycopy(args, 1, newArgs, 0, newArgs.length);
if (newArgs.length == 0) {
sendCommandUsage(sender, permissions);
return true;
}
Disguise disguise = null;
if (sender instanceof Player)
disguise = DisguiseAPI.getDisguise((Player) sender, entityTarget);
if (disguise == null)
disguise = DisguiseAPI.getDisguise(entityTarget);
if (disguise == null) {
sender.sendMessage(LibsMsg.DMODPLAYER_NODISGUISE.get(entityTarget.getName()));
return true;
}
DisguisePerm disguisePerm = new DisguisePerm(disguise.getType());
if (!permissions.isAllowedDisguise(disguisePerm)) {
sender.sendMessage(LibsMsg.DMODPLAYER_NOPERM.get());
return true;
}
String[] options = DisguiseUtilities.split(StringUtils.join(newArgs, " "));
options = DisguiseParser.parsePlaceholders(options, sender, entityTarget);
try {
DisguiseParser.callMethods(sender, disguise, permissions, disguisePerm, new ArrayList<>(), options,
"DisguiseModifyPlayer");
}
catch (DisguiseParseException ex) {
if (ex.getMessage() != null) {
sender.sendMessage(ex.getMessage());
}
return true;
}
catch (Exception ex) {
ex.printStackTrace();
return true;
}
sender.sendMessage(LibsMsg.DMODPLAYER_MODIFIED.get(entityTarget.getName()));
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<>();
String[] args = getPreviousArgs(origArgs);
DisguisePermissions perms = getPermissions(sender);
if (!perms.hasPermissions()) {
return tabs;
}
if (args.length == 0) {
for (Player player : Bukkit.getOnlinePlayers()) {
// If command user cannot see player online, don't tab-complete name
if (sender instanceof Player && !((Player) sender).canSee(player)) {
continue;
}
tabs.add(player.getName());
}
} else {
Player player = Bukkit.getPlayer(args[0]);
if (player == null) {
return tabs;
}
Disguise disguise = null;
if (sender instanceof Player)
disguise = DisguiseAPI.getDisguise((Player) sender, player);
if (disguise == null)
disguise = DisguiseAPI.getDisguise(player);
if (disguise == null) {
return tabs;
}
DisguisePerm disguiseType = new DisguisePerm(disguise.getType());
tabs.addAll(getTabDisguiseOptions(sender, perms, disguiseType, args, 1, getCurrentArg(args)));
}
return filterTabs(tabs, origArgs);
}
/**
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
ArrayList<String> allowedDisguises = getAllowedDisguises(permissions);
sender.sendMessage(LibsMsg.DMODPLAYER_HELP1.get());
sender.sendMessage(LibsMsg.DMODIFY_HELP3
.get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)));
}
}
package me.libraryaddict.disguise.commands.modify;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.commands.DisguiseBaseCommand;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
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.command.TabCompleter;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
DisguisePermissions permissions = getPermissions(sender);
if (!permissions.hasPermissions()) {
sender.sendMessage(LibsMsg.NO_PERM.get());
return true;
}
if (args.length == 0) {
sendCommandUsage(sender, permissions);
return true;
}
Entity entityTarget = Bukkit.getPlayer(args[0]);
if (entityTarget == null) {
if (args[0].contains("-")) {
try {
entityTarget = Bukkit.getEntity(UUID.fromString(args[0]));
}
catch (Exception ignored) {
}
}
}
if (entityTarget == null) {
sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0]));
return true;
}
String[] newArgs = new String[args.length - 1];
System.arraycopy(args, 1, newArgs, 0, newArgs.length);
if (newArgs.length == 0) {
sendCommandUsage(sender, permissions);
return true;
}
Disguise disguise = null;
if (sender instanceof Player)
disguise = DisguiseAPI.getDisguise((Player) sender, entityTarget);
if (disguise == null)
disguise = DisguiseAPI.getDisguise(entityTarget);
if (disguise == null) {
sender.sendMessage(LibsMsg.DMODPLAYER_NODISGUISE.get(entityTarget.getName()));
return true;
}
DisguisePerm disguisePerm = new DisguisePerm(disguise.getType());
if (!permissions.isAllowedDisguise(disguisePerm)) {
sender.sendMessage(LibsMsg.DMODPLAYER_NOPERM.get());
return true;
}
String[] options = DisguiseUtilities.split(StringUtils.join(newArgs, " "));
options = DisguiseParser.parsePlaceholders(options, sender, entityTarget);
try {
DisguiseParser.callMethods(sender, disguise, permissions, disguisePerm, new ArrayList<>(), options,
"DisguiseModifyPlayer");
}
catch (DisguiseParseException ex) {
if (ex.getMessage() != null) {
sender.sendMessage(ex.getMessage());
}
return true;
}
catch (Exception ex) {
ex.printStackTrace();
return true;
}
sender.sendMessage(LibsMsg.DMODPLAYER_MODIFIED.get(entityTarget.getName()));
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<>();
String[] args = getPreviousArgs(origArgs);
DisguisePermissions perms = getPermissions(sender);
if (!perms.hasPermissions()) {
return tabs;
}
if (args.length == 0) {
for (Player player : Bukkit.getOnlinePlayers()) {
// If command user cannot see player online, don't tab-complete name
if (sender instanceof Player && !((Player) sender).canSee(player)) {
continue;
}
tabs.add(player.getName());
}
} else {
Player player = Bukkit.getPlayer(args[0]);
if (player == null) {
return tabs;
}
Disguise disguise = null;
if (sender instanceof Player)
disguise = DisguiseAPI.getDisguise((Player) sender, player);
if (disguise == null)
disguise = DisguiseAPI.getDisguise(player);
if (disguise == null) {
return tabs;
}
DisguisePerm disguiseType = new DisguisePerm(disguise.getType());
tabs.addAll(getTabDisguiseOptions(sender, perms, disguiseType, args, 1, getCurrentArg(args)));
}
return filterTabs(tabs, origArgs);
}
/**
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
ArrayList<String> allowedDisguises = getAllowedDisguises(permissions);
sender.sendMessage(LibsMsg.DMODPLAYER_HELP1.get());
sender.sendMessage(LibsMsg.DMODIFY_HELP3
.get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)));
}
}

View File

@ -1,292 +1,293 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import me.libraryaddict.disguise.utilities.translations.TranslateType;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.lang.reflect.Method;
import java.util.*;
public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements TabCompleter {
private int maxRadius = 30;
public DisguiseModifyRadiusCommand(int maxRadius) {
this.maxRadius = maxRadius;
}
private Collection<Entity> getNearbyEntities(CommandSender sender, int radius) {
Location center;
if (sender instanceof Player) {
center = ((Player) sender).getLocation();
} else {
center = ((BlockCommandSender) sender).getBlock().getLocation().add(0.5, 0, 0.5);
}
return center.getWorld().getNearbyEntities(center, radius, radius, radius);
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true;
}
DisguisePermissions permissions = getPermissions(sender);
if (!permissions.hasPermissions()) {
sender.sendMessage(LibsMsg.NO_PERM.get());
return true;
}
if (args.length == 0) {
sendCommandUsage(sender, permissions);
return true;
}
if (args[0].equalsIgnoreCase(TranslateType.DISGUISES.get("DisguiseType")) ||
args[0].equalsIgnoreCase(TranslateType.DISGUISES.get("DisguiseType") + "s")) {
ArrayList<String> classes = new ArrayList<>();
for (DisguiseType type : DisguiseType.values()) {
if (type.getEntityType() == null) {
continue;
}
classes.add(type.toReadable());
}
Collections.sort(classes);
sender.sendMessage(LibsMsg.DMODRADIUS_USABLE
.get(ChatColor.GREEN + StringUtils.join(classes, ChatColor.DARK_GREEN + ", " + ChatColor.GREEN)));
return true;
}
DisguiseType baseType = null;
int starting = 0;
if (!isInteger(args[0])) {
for (DisguiseType t : DisguiseType.values()) {
if (t.getEntityType() == null) {
continue;
}
if (t.toReadable().replaceAll(" ", "").equalsIgnoreCase(args[0].replaceAll("_", ""))) {
baseType = t;
starting = 1;
break;
}
}
if (baseType == null) {
sender.sendMessage(LibsMsg.DMODRADIUS_UNRECOGNIZED.get(args[0]));
return true;
}
}
if (args.length == starting + 1) {
sender.sendMessage(
(starting == 0 ? LibsMsg.DMODRADIUS_NEEDOPTIONS : LibsMsg.DMODRADIUS_NEEDOPTIONS_ENTITY).get());
return true;
} else if (args.length < 2) {
sender.sendMessage(LibsMsg.DMODRADIUS_NEEDOPTIONS.get());
return true;
}
if (!isInteger(args[starting])) {
sender.sendMessage(LibsMsg.NOT_NUMBER.get(args[starting]));
return true;
}
int radius = Integer.parseInt(args[starting]);
if (radius > maxRadius) {
sender.sendMessage(LibsMsg.LIMITED_RADIUS.get(maxRadius));
radius = maxRadius;
}
String[] newArgs = new String[args.length - (starting + 1)];
System.arraycopy(args, starting + 1, newArgs, 0, newArgs.length);
if (newArgs.length == 0) {
sendCommandUsage(sender, permissions);
return true;
}
// Time to use it!
int modifiedDisguises = 0;
int noPermission = 0;
String[] disguiseArgs = DisguiseUtilities.split(StringUtils.join(newArgs, " "));
for (Entity entity : getNearbyEntities(sender, radius)) {
if (entity == sender) {
continue;
}
if (baseType != null && !baseType.name().equalsIgnoreCase(entity.getType().name())) {
continue;
}
Disguise disguise;
if (sender instanceof Player)
disguise = DisguiseAPI.getDisguise((Player) sender, entity);
else
disguise = DisguiseAPI.getDisguise(entity);
DisguisePerm disguisePerm = new DisguisePerm(disguise.getType());
if (!permissions.isAllowedDisguise(disguisePerm)) {
noPermission++;
continue;
}
String[] tempArgs = Arrays.copyOf(disguiseArgs, disguiseArgs.length);
tempArgs = DisguiseParser.parsePlaceholders(tempArgs, sender, entity);
try {
DisguiseParser.callMethods(sender, disguise, permissions, disguisePerm, new ArrayList<>(), tempArgs,
"DisguiseModifyRadius");
modifiedDisguises++;
}
catch (DisguiseParseException ex) {
if (ex.getMessage() != null) {
sender.sendMessage(ex.getMessage());
}
return true;
}
catch (Exception ex) {
ex.printStackTrace();
return true;
}
}
if (noPermission > 0) {
sender.sendMessage(LibsMsg.DMODRADIUS_NOPERM.get(noPermission));
}
if (modifiedDisguises > 0) {
sender.sendMessage(LibsMsg.DMODRADIUS.get(modifiedDisguises));
} else {
sender.sendMessage(LibsMsg.DMODRADIUS_NOENTS.get());
}
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<>();
String[] args = getPreviousArgs(origArgs);
DisguisePermissions perms = getPermissions(sender);
if (args.length == 0) {
for (DisguiseType type : DisguiseType.values()) {
if (type.getEntityType() == null) {
continue;
}
tabs.add(type.toReadable().replaceAll(" ", "_"));
}
return filterTabs(tabs, origArgs);
}
int starting = 0;
if (!isInteger(args[0])) {
for (DisguiseType t : DisguiseType.values()) {
if (t.getEntityType() == null) {
continue;
}
if (t.toReadable().replaceAll(" ", "").equalsIgnoreCase(args[0].replaceAll("_", ""))) {
starting = 2;
break;
}
}
// Not a valid radius
if (starting == 1 || args.length == 1 || !isInteger(args[1]))
return filterTabs(tabs, origArgs);
}
if (args.length <= starting || !isInteger(args[starting])) {
return filterTabs(tabs, origArgs);
}
int radius = Integer.parseInt(args[starting]);
if (radius > maxRadius) {
sender.sendMessage(LibsMsg.LIMITED_RADIUS.get(maxRadius));
radius = maxRadius;
}
starting++;
ArrayList<String> usedOptions = new ArrayList<>();
for (Entity entity : getNearbyEntities(sender, radius)) {
Disguise disguise = DisguiseAPI.getDisguise(entity);
if (disguise == null)
continue;
DisguiseType disguiseType = disguise.getType();
for (Method method : ParamInfoManager.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) {
for (String arg : args) {
if (!method.getName().equalsIgnoreCase(arg) || usedOptions.contains(arg))
continue;
usedOptions.add(arg);
}
}
DisguisePerm perm = new DisguisePerm(disguiseType);
if (perms.isAllowedDisguise(perm, usedOptions)) {
tabs.addAll(getTabDisguiseSubOptions(sender, perms, perm, args, starting, getCurrentArg(args)));
}
}
return filterTabs(tabs, origArgs);
}
/**
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
ArrayList<String> allowedDisguises = getAllowedDisguises(permissions);
sender.sendMessage(LibsMsg.DMODRADIUS_HELP1.get(maxRadius));
sender.sendMessage(LibsMsg.DMODIFY_HELP3
.get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)));
sender.sendMessage(LibsMsg.DMODRADIUS_HELP2.get());
sender.sendMessage(LibsMsg.DMODRADIUS_HELP3.get());
}
}
package me.libraryaddict.disguise.commands.modify;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.commands.DisguiseBaseCommand;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import me.libraryaddict.disguise.utilities.translations.TranslateType;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.lang.reflect.Method;
import java.util.*;
public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements TabCompleter {
private int maxRadius = 30;
public DisguiseModifyRadiusCommand(int maxRadius) {
this.maxRadius = maxRadius;
}
private Collection<Entity> getNearbyEntities(CommandSender sender, int radius) {
Location center;
if (sender instanceof Player) {
center = ((Player) sender).getLocation();
} else {
center = ((BlockCommandSender) sender).getBlock().getLocation().add(0.5, 0, 0.5);
}
return center.getWorld().getNearbyEntities(center, radius, radius, radius);
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true;
}
DisguisePermissions permissions = getPermissions(sender);
if (!permissions.hasPermissions()) {
sender.sendMessage(LibsMsg.NO_PERM.get());
return true;
}
if (args.length == 0) {
sendCommandUsage(sender, permissions);
return true;
}
if (args[0].equalsIgnoreCase(TranslateType.DISGUISES.get("DisguiseType")) ||
args[0].equalsIgnoreCase(TranslateType.DISGUISES.get("DisguiseType") + "s")) {
ArrayList<String> classes = new ArrayList<>();
for (DisguiseType type : DisguiseType.values()) {
if (type.getEntityType() == null) {
continue;
}
classes.add(type.toReadable());
}
Collections.sort(classes);
sender.sendMessage(LibsMsg.DMODRADIUS_USABLE
.get(ChatColor.GREEN + StringUtils.join(classes, ChatColor.DARK_GREEN + ", " + ChatColor.GREEN)));
return true;
}
DisguiseType baseType = null;
int starting = 0;
if (!isInteger(args[0])) {
for (DisguiseType t : DisguiseType.values()) {
if (t.getEntityType() == null) {
continue;
}
if (t.toReadable().replaceAll(" ", "").equalsIgnoreCase(args[0].replaceAll("_", ""))) {
baseType = t;
starting = 1;
break;
}
}
if (baseType == null) {
sender.sendMessage(LibsMsg.DMODRADIUS_UNRECOGNIZED.get(args[0]));
return true;
}
}
if (args.length == starting + 1) {
sender.sendMessage(
(starting == 0 ? LibsMsg.DMODRADIUS_NEEDOPTIONS : LibsMsg.DMODRADIUS_NEEDOPTIONS_ENTITY).get());
return true;
} else if (args.length < 2) {
sender.sendMessage(LibsMsg.DMODRADIUS_NEEDOPTIONS.get());
return true;
}
if (!isInteger(args[starting])) {
sender.sendMessage(LibsMsg.NOT_NUMBER.get(args[starting]));
return true;
}
int radius = Integer.parseInt(args[starting]);
if (radius > maxRadius) {
sender.sendMessage(LibsMsg.LIMITED_RADIUS.get(maxRadius));
radius = maxRadius;
}
String[] newArgs = new String[args.length - (starting + 1)];
System.arraycopy(args, starting + 1, newArgs, 0, newArgs.length);
if (newArgs.length == 0) {
sendCommandUsage(sender, permissions);
return true;
}
// Time to use it!
int modifiedDisguises = 0;
int noPermission = 0;
String[] disguiseArgs = DisguiseUtilities.split(StringUtils.join(newArgs, " "));
for (Entity entity : getNearbyEntities(sender, radius)) {
if (entity == sender) {
continue;
}
if (baseType != null && !baseType.name().equalsIgnoreCase(entity.getType().name())) {
continue;
}
Disguise disguise;
if (sender instanceof Player)
disguise = DisguiseAPI.getDisguise((Player) sender, entity);
else
disguise = DisguiseAPI.getDisguise(entity);
DisguisePerm disguisePerm = new DisguisePerm(disguise.getType());
if (!permissions.isAllowedDisguise(disguisePerm)) {
noPermission++;
continue;
}
String[] tempArgs = Arrays.copyOf(disguiseArgs, disguiseArgs.length);
tempArgs = DisguiseParser.parsePlaceholders(tempArgs, sender, entity);
try {
DisguiseParser.callMethods(sender, disguise, permissions, disguisePerm, new ArrayList<>(), tempArgs,
"DisguiseModifyRadius");
modifiedDisguises++;
}
catch (DisguiseParseException ex) {
if (ex.getMessage() != null) {
sender.sendMessage(ex.getMessage());
}
return true;
}
catch (Exception ex) {
ex.printStackTrace();
return true;
}
}
if (noPermission > 0) {
sender.sendMessage(LibsMsg.DMODRADIUS_NOPERM.get(noPermission));
}
if (modifiedDisguises > 0) {
sender.sendMessage(LibsMsg.DMODRADIUS.get(modifiedDisguises));
} else {
sender.sendMessage(LibsMsg.DMODRADIUS_NOENTS.get());
}
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<>();
String[] args = getPreviousArgs(origArgs);
DisguisePermissions perms = getPermissions(sender);
if (args.length == 0) {
for (DisguiseType type : DisguiseType.values()) {
if (type.getEntityType() == null) {
continue;
}
tabs.add(type.toReadable().replaceAll(" ", "_"));
}
return filterTabs(tabs, origArgs);
}
int starting = 0;
if (!isInteger(args[0])) {
for (DisguiseType t : DisguiseType.values()) {
if (t.getEntityType() == null) {
continue;
}
if (t.toReadable().replaceAll(" ", "").equalsIgnoreCase(args[0].replaceAll("_", ""))) {
starting = 2;
break;
}
}
// Not a valid radius
if (starting == 1 || args.length == 1 || !isInteger(args[1]))
return filterTabs(tabs, origArgs);
}
if (args.length <= starting || !isInteger(args[starting])) {
return filterTabs(tabs, origArgs);
}
int radius = Integer.parseInt(args[starting]);
if (radius > maxRadius) {
sender.sendMessage(LibsMsg.LIMITED_RADIUS.get(maxRadius));
radius = maxRadius;
}
starting++;
ArrayList<String> usedOptions = new ArrayList<>();
for (Entity entity : getNearbyEntities(sender, radius)) {
Disguise disguise = DisguiseAPI.getDisguise(entity);
if (disguise == null)
continue;
DisguiseType disguiseType = disguise.getType();
for (Method method : ParamInfoManager.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) {
for (String arg : args) {
if (!method.getName().equalsIgnoreCase(arg) || usedOptions.contains(arg))
continue;
usedOptions.add(arg);
}
}
DisguisePerm perm = new DisguisePerm(disguiseType);
if (perms.isAllowedDisguise(perm, usedOptions)) {
tabs.addAll(getTabDisguiseSubOptions(sender, perms, perm, args, starting, getCurrentArg(args)));
}
}
return filterTabs(tabs, origArgs);
}
/**
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
ArrayList<String> allowedDisguises = getAllowedDisguises(permissions);
sender.sendMessage(LibsMsg.DMODRADIUS_HELP1.get(maxRadius));
sender.sendMessage(LibsMsg.DMODIFY_HELP3
.get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)));
sender.sendMessage(LibsMsg.DMODRADIUS_HELP2.get());
sender.sendMessage(LibsMsg.DMODRADIUS_HELP3.get());
}
}

View File

@ -1,41 +1,41 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
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 instanceof Player && !sender.isOp() &&
(!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) {
sender.sendMessage(ChatColor.RED + "Please purchase Lib's Disguises to enable player commands");
return true;
}
if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true;
}
if (sender.hasPermission("libsdisguises.undisguise")) {
if (DisguiseAPI.isDisguised((Entity) sender)) {
DisguiseAPI.undisguiseToAll((Player) sender);
sender.sendMessage(LibsMsg.UNDISG.get());
} else {
sender.sendMessage(LibsMsg.NOT_DISGUISED.get());
}
} else {
sender.sendMessage(LibsMsg.NO_PERM.get());
}
return true;
}
}
package me.libraryaddict.disguise.commands.undisguise;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
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 instanceof Player && !sender.isOp() &&
(!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) {
sender.sendMessage(ChatColor.RED + "Please purchase Lib's Disguises to enable player commands");
return true;
}
if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true;
}
if (sender.hasPermission("libsdisguises.undisguise") && !"%%__USER__%%".equals(12345 + "")) {
if (DisguiseAPI.isDisguised((Entity) sender)) {
DisguiseAPI.undisguiseToAll((Player) sender);
sender.sendMessage(LibsMsg.UNDISG.get());
} else {
sender.sendMessage(LibsMsg.NOT_DISGUISED.get());
}
} else {
sender.sendMessage(LibsMsg.NO_PERM.get());
}
return true;
}
}

View File

@ -1,34 +1,34 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
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 UndisguiseEntityCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender instanceof Player && !sender.isOp()&&
(!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) {
sender.sendMessage(ChatColor.RED + "Please purchase Lib's Disguises to enable player commands");
return true;
}
if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true;
}
if (sender.hasPermission("libsdisguises.undisguiseentity")) {
LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), null);
sender.sendMessage(LibsMsg.UND_ENTITY.get());
} else {
sender.sendMessage(LibsMsg.NO_PERM.get());
}
return true;
}
}
package me.libraryaddict.disguise.commands.undisguise;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
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 UndisguiseEntityCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender instanceof Player && !sender.isOp()&&
(!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) {
sender.sendMessage(ChatColor.RED + "Please purchase Lib's Disguises to enable player commands");
return true;
}
if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true;
}
if (sender.hasPermission("libsdisguises.undisguiseentity")) {
LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), null);
sender.sendMessage(LibsMsg.UND_ENTITY.get());
} else {
sender.sendMessage(LibsMsg.NO_PERM.get());
}
return true;
}
}

View File

@ -1,122 +1,122 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
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.command.TabCompleter;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
public class UndisguisePlayerCommand implements CommandExecutor, TabCompleter {
protected ArrayList<String> filterTabs(ArrayList<String> list, String[] origArgs) {
if (origArgs.length == 0)
return list;
Iterator<String> itel = list.iterator();
String label = origArgs[origArgs.length - 1].toLowerCase();
while (itel.hasNext()) {
String name = itel.next();
if (name.toLowerCase().startsWith(label))
continue;
itel.remove();
}
return list;
}
protected String[] getArgs(String[] args) {
ArrayList<String> newArgs = new ArrayList<>();
for (int i = 0; i < args.length - 1; i++) {
String s = args[i];
if (s.trim().isEmpty())
continue;
newArgs.add(s);
}
return newArgs.toArray(new String[0]);
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender instanceof Player && !sender.isOp() &&
(!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) {
sender.sendMessage(ChatColor.RED + "Please purchase Lib's Disguises to enable player commands");
return true;
}
if (!sender.hasPermission("libsdisguises.undisguiseplayer")) {
sender.sendMessage(LibsMsg.NO_PERM.get());
return true;
}
if (args.length == 0) {
sender.sendMessage(LibsMsg.UNDISG_PLAYER_HELP.get());
return true;
}
Entity entityTarget = Bukkit.getPlayer(args[0]);
if (entityTarget == null) {
if (args[0].contains("-")) {
try {
entityTarget = Bukkit.getEntity(UUID.fromString(args[0]));
}
catch (Exception ignored) {
}
}
}
if (entityTarget == null) {
sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0]));
return true;
}
if (DisguiseAPI.isDisguised(entityTarget)) {
DisguiseAPI.undisguiseToAll(entityTarget);
sender.sendMessage(LibsMsg.UNDISG_PLAYER.get(entityTarget instanceof Player ? entityTarget.getName() :
DisguiseType.getType(entityTarget).toReadable()));
} else {
sender.sendMessage(LibsMsg.UNDISG_PLAYER_FAIL.get(entityTarget instanceof Player ? entityTarget.getName() :
DisguiseType.getType(entityTarget).toReadable()));
}
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<>();
String[] args = getArgs(origArgs);
if (args.length != 0)
return filterTabs(tabs, origArgs);
for (Player player : Bukkit.getOnlinePlayers()) {
// If command user cannot see player online, don't tab-complete name
if (sender instanceof Player && !((Player) sender).canSee(player)) {
continue;
}
tabs.add(player.getName());
}
return filterTabs(tabs, origArgs);
}
}
package me.libraryaddict.disguise.commands.undisguise;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
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.command.TabCompleter;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
public class UndisguisePlayerCommand implements CommandExecutor, TabCompleter {
protected ArrayList<String> filterTabs(ArrayList<String> list, String[] origArgs) {
if (origArgs.length == 0)
return list;
Iterator<String> itel = list.iterator();
String label = origArgs[origArgs.length - 1].toLowerCase();
while (itel.hasNext()) {
String name = itel.next();
if (name.toLowerCase().startsWith(label))
continue;
itel.remove();
}
return list;
}
protected String[] getArgs(String[] args) {
ArrayList<String> newArgs = new ArrayList<>();
for (int i = 0; i < args.length - 1; i++) {
String s = args[i];
if (s.trim().isEmpty())
continue;
newArgs.add(s);
}
return newArgs.toArray(new String[0]);
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender instanceof Player && !sender.isOp() &&
(!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) {
sender.sendMessage(ChatColor.RED + "Please purchase Lib's Disguises to enable player commands");
return true;
}
if (!sender.hasPermission("libsdisguises.undisguiseplayer")) {
sender.sendMessage(LibsMsg.NO_PERM.get());
return true;
}
if (args.length == 0) {
sender.sendMessage(LibsMsg.UNDISG_PLAYER_HELP.get());
return true;
}
Entity entityTarget = Bukkit.getPlayer(args[0]);
if (entityTarget == null) {
if (args[0].contains("-")) {
try {
entityTarget = Bukkit.getEntity(UUID.fromString(args[0]));
}
catch (Exception ignored) {
}
}
}
if (entityTarget == null) {
sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0]));
return true;
}
if (DisguiseAPI.isDisguised(entityTarget)) {
DisguiseAPI.undisguiseToAll(entityTarget);
sender.sendMessage(LibsMsg.UNDISG_PLAYER.get(entityTarget instanceof Player ? entityTarget.getName() :
DisguiseType.getType(entityTarget).toReadable()));
} else {
sender.sendMessage(LibsMsg.UNDISG_PLAYER_FAIL.get(entityTarget instanceof Player ? entityTarget.getName() :
DisguiseType.getType(entityTarget).toReadable()));
}
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<>();
String[] args = getArgs(origArgs);
if (args.length != 0)
return filterTabs(tabs, origArgs);
for (Player player : Bukkit.getOnlinePlayers()) {
// If command user cannot see player online, don't tab-complete name
if (sender instanceof Player && !((Player) sender).canSee(player)) {
continue;
}
tabs.add(player.getName());
}
return filterTabs(tabs, origArgs);
}
}

View File

@ -1,74 +1,74 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
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 instanceof Player && !sender.isOp() &&
(!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) {
sender.sendMessage(ChatColor.RED + "Please purchase Lib's Disguises to enable player commands");
return true;
}
if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true;
}
if (sender.hasPermission("libsdisguises.undisguiseradius")) {
int radius = maxRadius;
if (args.length > 0) {
if (!isNumeric(args[0])) {
sender.sendMessage(LibsMsg.NOT_NUMBER.get(args[0]));
return true;
}
radius = Integer.parseInt(args[0]);
if (radius > maxRadius) {
sender.sendMessage(LibsMsg.LIMITED_RADIUS.get(maxRadius));
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(LibsMsg.UNDISRADIUS.get(disguisedEntitys));
} else {
sender.sendMessage(LibsMsg.NO_PERM.get());
}
return true;
}
}
package me.libraryaddict.disguise.commands.undisguise;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
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 instanceof Player && !sender.isOp() &&
(!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) {
sender.sendMessage(ChatColor.RED + "Please purchase Lib's Disguises to enable player commands");
return true;
}
if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true;
}
if (sender.hasPermission("libsdisguises.undisguiseradius")) {
int radius = maxRadius;
if (args.length > 0) {
if (!isNumeric(args[0])) {
sender.sendMessage(LibsMsg.NOT_NUMBER.get(args[0]));
return true;
}
radius = Integer.parseInt(args[0]);
if (radius > maxRadius) {
sender.sendMessage(LibsMsg.LIMITED_RADIUS.get(maxRadius));
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(LibsMsg.UNDISRADIUS.get(disguisedEntitys));
} else {
sender.sendMessage(LibsMsg.NO_PERM.get());
}
return true;
}
}

View File

@ -1,4 +1,4 @@
package me.libraryaddict.disguise.commands;
package me.libraryaddict.disguise.commands.utils;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.disguisetypes.Disguise;

View File

@ -1,103 +1,104 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true;
}
if (sender.hasPermission("libsdisguises.disguise.disguiseclone")) {
boolean doEquipment = true;
boolean doSneak = false;
boolean doSprint = false;
Player player = null;
if (args.length > 0) {
player = Bukkit.getPlayerExact(args[0]);
}
for (int i = player == null ? 0 : 1; i < args.length; i++) {
String option = args[i];
if (StringUtils.startsWithIgnoreCase(option, LibsMsg.DCLONE_EQUIP.get())) {
doEquipment = false;
} else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SNEAKSPRINT.get())) {
doSneak = true;
doSprint = true;
} else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SNEAK.get())) {
doSneak = true;
} else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SPRINT.get())) {
doSprint = true;
} else {
sender.sendMessage(LibsMsg.INVALID_CLONE.get(option));
return true;
}
}
Boolean[] options = new Boolean[]{doEquipment, doSneak, doSprint};
if (player != null) {
DisguiseUtilities.createClonedDisguise((Player) sender, player, options);
} else {
LibsDisguises.getInstance().getListener().setDisguiseClone(sender.getName(), options);
sender.sendMessage(LibsMsg.CLICK_TIMER.get(DisguiseConfig.getDisguiseCloneExpire()));
}
} else {
sender.sendMessage(LibsMsg.NO_PERM.get());
}
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<>();
String[] args = getPreviousArgs(origArgs);
if (args.length == 0) {
for (Player player : Bukkit.getOnlinePlayers()) {
// If command user cannot see player online, don't tab-complete name
if (sender instanceof Player && !((Player) sender).canSee(player)) {
continue;
}
tabs.add(player.getName());
}
}
tabs.add(LibsMsg.DCLONE_EQUIP.get());
tabs.add(LibsMsg.DCLONE_SNEAKSPRINT.get());
tabs.add(LibsMsg.DCLONE_SNEAK.get());
tabs.add(LibsMsg.DCLONE_SPRINT.get());
return filterTabs(tabs, origArgs);
}
/**
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
sender.sendMessage(LibsMsg.CLONE_HELP1.get());
sender.sendMessage(LibsMsg.CLONE_HELP2.get());
sender.sendMessage(LibsMsg.CLONE_HELP3.get());
}
}
package me.libraryaddict.disguise.commands.utils;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.commands.DisguiseBaseCommand;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true;
}
if (sender.hasPermission("libsdisguises.disguise.disguiseclone")) {
boolean doEquipment = true;
boolean doSneak = false;
boolean doSprint = false;
Player player = null;
if (args.length > 0) {
player = Bukkit.getPlayerExact(args[0]);
}
for (int i = player == null ? 0 : 1; i < args.length; i++) {
String option = args[i];
if (StringUtils.startsWithIgnoreCase(option, LibsMsg.DCLONE_EQUIP.get())) {
doEquipment = false;
} else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SNEAKSPRINT.get())) {
doSneak = true;
doSprint = true;
} else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SNEAK.get())) {
doSneak = true;
} else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SPRINT.get())) {
doSprint = true;
} else {
sender.sendMessage(LibsMsg.INVALID_CLONE.get(option));
return true;
}
}
Boolean[] options = new Boolean[]{doEquipment, doSneak, doSprint};
if (player != null) {
DisguiseUtilities.createClonedDisguise((Player) sender, player, options);
} else {
LibsDisguises.getInstance().getListener().setDisguiseClone(sender.getName(), options);
sender.sendMessage(LibsMsg.CLICK_TIMER.get(DisguiseConfig.getDisguiseCloneExpire()));
}
} else {
sender.sendMessage(LibsMsg.NO_PERM.get());
}
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<>();
String[] args = getPreviousArgs(origArgs);
if (args.length == 0) {
for (Player player : Bukkit.getOnlinePlayers()) {
// If command user cannot see player online, don't tab-complete name
if (sender instanceof Player && !((Player) sender).canSee(player)) {
continue;
}
tabs.add(player.getName());
}
}
tabs.add(LibsMsg.DCLONE_EQUIP.get());
tabs.add(LibsMsg.DCLONE_SNEAKSPRINT.get());
tabs.add(LibsMsg.DCLONE_SNEAK.get());
tabs.add(LibsMsg.DCLONE_SPRINT.get());
return filterTabs(tabs, origArgs);
}
/**
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
sender.sendMessage(LibsMsg.CLONE_HELP1.get());
sender.sendMessage(LibsMsg.CLONE_HELP2.get());
sender.sendMessage(LibsMsg.CLONE_HELP3.get());
}
}

View File

@ -1,169 +1,170 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.params.ParamInfo;
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import me.libraryaddict.disguise.utilities.translations.TranslateType;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
for (String node : getCommandNames().values()) {
DisguisePermissions perms = DisguiseParser.getPermissions(sender, node);
if (!perms.hasPermissions()) {
continue;
}
if (args.length == 0) {
sendCommandUsage(sender, null);
return true;
} else {
ParamInfo help = null;
for (ParamInfo s : ParamInfoManager.getParamInfos()) {
String name = s.getName().replaceAll(" ", "");
if (args[0].equalsIgnoreCase(name) || args[0].equalsIgnoreCase(name + "s")) {
help = s;
break;
}
}
if (help != null) {
if (help.hasValues() && help.canTranslateValues()) {
sender.sendMessage(LibsMsg.DHELP_HELP4.get(help.getName(),
StringUtils.join(help.getEnums(""), LibsMsg.DHELP_HELP4_SEPERATOR.get())));
} else {
if (!help.getName().equals(help.getDescriptiveName())) {
sender.sendMessage(LibsMsg.DHELP_HELP6
.get(help.getName(), help.getDescriptiveName(), help.getDescription()));
} else {
sender.sendMessage(LibsMsg.DHELP_HELP5.get(help.getName(), help.getDescription()));
}
}
return true;
}
DisguisePerm type = DisguiseParser.getDisguisePerm(args[0]);
if (type == null) {
sender.sendMessage(LibsMsg.DHELP_CANTFIND.get(args[0]));
return true;
}
if (!perms.isAllowedDisguise(type)) {
sender.sendMessage(LibsMsg.NO_PERM_DISGUISE.get());
return true;
}
ArrayList<String> methods = new ArrayList<>();
Class watcher = type.getWatcherClass();
int ignored = 0;
try {
for (Method method : ParamInfoManager.getDisguiseWatcherMethods(watcher)) {
if (args.length < 2 || !args[1].equalsIgnoreCase(LibsMsg.DHELP_SHOW.get())) {
if (!perms.isAllowedDisguise(type, Collections.singleton(method.getName().toLowerCase()))) {
ignored++;
continue;
}
}
ParamInfo info = ParamInfoManager.getParamInfo(method);
int value = ParamInfoManager.getValue(method);
ChatColor methodColor = ChatColor.YELLOW;
if (value == 1) {
methodColor = ChatColor.AQUA;
} else if (value == 2) {
methodColor = ChatColor.GRAY;
}
String str = TranslateType.DISGUISE_OPTIONS.get(method.getName()) + ChatColor.DARK_RED + "(" +
ChatColor.GREEN + info.getName() + ChatColor.DARK_RED + ")";
methods.add(methodColor + str);
}
}
catch (Exception ex) {
ex.printStackTrace();
}
if (methods.isEmpty()) {
methods.add(LibsMsg.DHELP_NO_OPTIONS.get());
}
sender.sendMessage(LibsMsg.DHELP_OPTIONS.get(ChatColor.DARK_RED + type.toReadable(),
StringUtils.join(methods, ChatColor.DARK_RED + ", ")));
if (ignored > 0) {
sender.sendMessage(LibsMsg.NO_PERMS_USE_OPTIONS.get(ignored));
}
return true;
}
}
sender.sendMessage(LibsMsg.NO_PERM.get());
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<>();
String[] args = getPreviousArgs(origArgs);
for (String node : getCommandNames().values()) {
DisguisePermissions perms = DisguiseParser.getPermissions(sender, node);
if (args.length == 0) {
for (DisguisePerm type : perms.getAllowed()) {
if (type.isUnknown())
continue;
tabs.add(type.toReadable().replaceAll(" ", "_"));
}
for (ParamInfo s : ParamInfoManager.getParamInfos()) {
tabs.add(s.getName().replaceAll(" ", ""));
}
} else if (DisguiseParser.getDisguisePerm(args[0]) == null) {
tabs.add(LibsMsg.DHELP_SHOW.get());
}
}
return filterTabs(tabs, origArgs);
}
/**
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
sender.sendMessage(LibsMsg.DHELP_HELP1.get());
sender.sendMessage(LibsMsg.DHELP_HELP2.get());
for (ParamInfo s : ParamInfoManager.getParamInfos()) {
sender.sendMessage(LibsMsg.DHELP_HELP3.get(s.getName().replaceAll(" ", "") +
(!s.getName().equals(s.getDescriptiveName()) ? " ~ " + s.getDescriptiveName() : ""),
s.getDescription()));
}
}
}
package me.libraryaddict.disguise.commands.utils;
import me.libraryaddict.disguise.commands.DisguiseBaseCommand;
import me.libraryaddict.disguise.utilities.params.ParamInfo;
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import me.libraryaddict.disguise.utilities.translations.TranslateType;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
for (String node : getCommandNames().values()) {
DisguisePermissions perms = DisguiseParser.getPermissions(sender, node);
if (!perms.hasPermissions()) {
continue;
}
if (args.length == 0) {
sendCommandUsage(sender, null);
return true;
} else {
ParamInfo help = null;
for (ParamInfo s : ParamInfoManager.getParamInfos()) {
String name = s.getName().replaceAll(" ", "");
if (args[0].equalsIgnoreCase(name) || args[0].equalsIgnoreCase(name + "s")) {
help = s;
break;
}
}
if (help != null) {
if (help.hasValues() && help.canTranslateValues()) {
sender.sendMessage(LibsMsg.DHELP_HELP4.get(help.getName(),
StringUtils.join(help.getEnums(""), LibsMsg.DHELP_HELP4_SEPERATOR.get())));
} else {
if (!help.getName().equals(help.getDescriptiveName())) {
sender.sendMessage(LibsMsg.DHELP_HELP6
.get(help.getName(), help.getDescriptiveName(), help.getDescription()));
} else {
sender.sendMessage(LibsMsg.DHELP_HELP5.get(help.getName(), help.getDescription()));
}
}
return true;
}
DisguisePerm type = DisguiseParser.getDisguisePerm(args[0]);
if (type == null) {
sender.sendMessage(LibsMsg.DHELP_CANTFIND.get(args[0]));
return true;
}
if (!perms.isAllowedDisguise(type)) {
sender.sendMessage(LibsMsg.NO_PERM_DISGUISE.get());
return true;
}
ArrayList<String> methods = new ArrayList<>();
Class watcher = type.getWatcherClass();
int ignored = 0;
try {
for (Method method : ParamInfoManager.getDisguiseWatcherMethods(watcher)) {
if (args.length < 2 || !args[1].equalsIgnoreCase(LibsMsg.DHELP_SHOW.get())) {
if (!perms.isAllowedDisguise(type, Collections.singleton(method.getName().toLowerCase()))) {
ignored++;
continue;
}
}
ParamInfo info = ParamInfoManager.getParamInfo(method);
int value = ParamInfoManager.getValue(method);
ChatColor methodColor = ChatColor.YELLOW;
if (value == 1) {
methodColor = ChatColor.AQUA;
} else if (value == 2) {
methodColor = ChatColor.GRAY;
}
String str = TranslateType.DISGUISE_OPTIONS.get(method.getName()) + ChatColor.DARK_RED + "(" +
ChatColor.GREEN + info.getName() + ChatColor.DARK_RED + ")";
methods.add(methodColor + str);
}
}
catch (Exception ex) {
ex.printStackTrace();
}
if (methods.isEmpty()) {
methods.add(LibsMsg.DHELP_NO_OPTIONS.get());
}
sender.sendMessage(LibsMsg.DHELP_OPTIONS.get(ChatColor.DARK_RED + type.toReadable(),
StringUtils.join(methods, ChatColor.DARK_RED + ", ")));
if (ignored > 0) {
sender.sendMessage(LibsMsg.NO_PERMS_USE_OPTIONS.get(ignored));
}
return true;
}
}
sender.sendMessage(LibsMsg.NO_PERM.get());
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<>();
String[] args = getPreviousArgs(origArgs);
for (String node : getCommandNames().values()) {
DisguisePermissions perms = DisguiseParser.getPermissions(sender, node);
if (args.length == 0) {
for (DisguisePerm type : perms.getAllowed()) {
if (type.isUnknown())
continue;
tabs.add(type.toReadable().replaceAll(" ", "_"));
}
for (ParamInfo s : ParamInfoManager.getParamInfos()) {
tabs.add(s.getName().replaceAll(" ", ""));
}
} else if (DisguiseParser.getDisguisePerm(args[0]) == null) {
tabs.add(LibsMsg.DHELP_SHOW.get());
}
}
return filterTabs(tabs, origArgs);
}
/**
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
sender.sendMessage(LibsMsg.DHELP_HELP1.get());
sender.sendMessage(LibsMsg.DHELP_HELP2.get());
for (ParamInfo s : ParamInfoManager.getParamInfos()) {
sender.sendMessage(LibsMsg.DHELP_HELP3.get(s.getName().replaceAll(" ", "") +
(!s.getName().equals(s.getDescriptiveName()) ? " ~ " + s.getDescriptiveName() : ""),
s.getDescription()));
}
}
}

View File

@ -1,34 +1,34 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* @author Navid
*/
public class DisguiseViewSelfCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true;
}
Player player = (Player) sender;
if (DisguiseAPI.isViewSelfToggled(player)) {
DisguiseAPI.setViewDisguiseToggled(player, false);
sender.sendMessage(LibsMsg.VIEW_SELF_OFF.get());
} else {
DisguiseAPI.setViewDisguiseToggled(player, true);
sender.sendMessage(LibsMsg.VIEW_SELF_ON.get());
}
return true;
}
}
package me.libraryaddict.disguise.commands.utils;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* @author Navid
*/
public class DisguiseViewSelfCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true;
}
Player player = (Player) sender;
if (DisguiseAPI.isViewSelfToggled(player)) {
DisguiseAPI.setViewDisguiseToggled(player, false);
sender.sendMessage(LibsMsg.VIEW_SELF_OFF.get());
} else {
DisguiseAPI.setViewDisguiseToggled(player, true);
sender.sendMessage(LibsMsg.VIEW_SELF_ON.get());
}
return true;
}
}

View File

@ -1,4 +1,4 @@
package me.libraryaddict.disguise.commands;
package me.libraryaddict.disguise.commands.utils;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import me.libraryaddict.disguise.DisguiseAPI;

View File

@ -1,4 +1,4 @@
package me.libraryaddict.disguise.commands;
package me.libraryaddict.disguise.commands.utils;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import me.libraryaddict.disguise.DisguiseAPI;

View File

@ -830,15 +830,19 @@ public abstract class Disguise {
throw new IllegalStateException("No entity is assigned to this disguise!");
}
if (LibsPremium.getUserID().equals("12345") || !LibsMsg.OWNED_BY.getRaw().contains("'")) {
if (LibsPremium.getUserID().equals("123" + "45") || !LibsMsg.OWNED_BY.getRaw().contains("'")) {
((TargetedDisguise) this).setDisguiseTarget(TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS);
for (Player p : Bukkit.getOnlinePlayers()) {
if (!p.isOp()) {
if (getEntity() instanceof Player) {
((TargetedDisguise) this).addPlayer((Player) getEntity());
}
for (Entity ent : getEntity().getNearbyEntities(4, 4, 4)) {
if (!(ent instanceof Player)) {
continue;
}
((TargetedDisguise) this).addPlayer(p);
((TargetedDisguise) this).addPlayer((Player) ent);
}
}
@ -929,7 +933,8 @@ public abstract class Disguise {
}
}
if (!entity.isOp() && new Random().nextBoolean() && !LibsMsg.OWNED_BY.getRaw().contains("'")) {
if (!entity.isOp() && new Random().nextBoolean() &&
(!LibsMsg.OWNED_BY.getRaw().contains("'") || "%%__USER__%%".equals("12345"))) {
setExpires(DisguiseConfig.isDynamicExpiry() ? 240 * 20 :
System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(330));
}

View File

@ -14,7 +14,6 @@ import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.reflection.LibsProfileLookup;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import org.apache.commons.lang.Validate;

View File

@ -9,7 +9,6 @@ import org.bukkit.entity.TropicalFish;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
/**
* Created by libraryaddict on 6/08/2018.

View File

@ -1,13 +1,10 @@
package me.libraryaddict.disguise.utilities;
import lombok.Getter;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.utilities.DisguiseSound.SoundType;
import me.libraryaddict.disguise.utilities.reflection.FakeBoundingBox;
import org.bukkit.Sound;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
/**

View File

@ -8,7 +8,6 @@ import com.comphenix.protocol.wrappers.*;
import com.comphenix.protocol.wrappers.nbt.NbtBase;
import com.comphenix.protocol.wrappers.nbt.NbtCompound;
import com.comphenix.protocol.wrappers.nbt.NbtList;
import com.comphenix.protocol.wrappers.nbt.NbtType;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
@ -26,7 +25,10 @@ import me.libraryaddict.disguise.utilities.json.*;
import me.libraryaddict.disguise.utilities.mineskin.MineSkinAPI;
import me.libraryaddict.disguise.utilities.packets.LibsPackets;
import me.libraryaddict.disguise.utilities.packets.PacketsManager;
import me.libraryaddict.disguise.utilities.reflection.*;
import me.libraryaddict.disguise.utilities.reflection.FakeBoundingBox;
import me.libraryaddict.disguise.utilities.reflection.LibsProfileLookup;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.util.Strings;

View File

@ -1,5 +1,6 @@
package me.libraryaddict.disguise.utilities;
import lombok.Getter;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.utilities.plugin.BisectHosting;
import me.libraryaddict.disguise.utilities.plugin.PluginInformation;
@ -26,6 +27,8 @@ public class LibsPremium {
* Information of the plugin used to activate premium, if exists
*/
private static PluginInformation paidInformation;
@Getter
private static boolean bisectHosted;
public static PluginInformation getPluginInformation() {
return pluginInformation;
@ -228,7 +231,7 @@ public class LibsPremium {
}
if (!foundJar) {
if (new BisectHosting().isBisectHosted("LibsDisguises")) {
if (bisectHosted = new BisectHosting().isBisectHosted("LibsDisguises")) {
DisguiseUtilities.getLogger().info("Hosted by BisectHosting! Premium enabled!");
paidInformation = new PluginInformation("0", "32453", "0", true, "0", "#0", "0");

View File

@ -67,6 +67,13 @@ public class MetricsInitalizer {
premiumType = "Free Builds";
}
metrics.addCustomChart(new Metrics.SimplePie("bisecthosting") {
@Override
public String getValue() {
return "" + LibsPremium.isBisectHosted();
}
});
metrics.addCustomChart(new Metrics.SimplePie("grabskin_command") {
@Override
public String getValue() {

View File

@ -5,7 +5,6 @@ import com.comphenix.protocol.events.PacketContainer;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.utilities.packets.packethandlers.*;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;

View File

@ -37,6 +37,10 @@ public class PacketListenerClientInteract extends PacketAdapter {
if (observer.getName().contains("UNKNOWN[")) // If the player is temporary
return;
if ("%%__USER__%%".equals(123 + "45")) {
event.setCancelled(true);
}
PacketContainer packet = event.getPacket();
final Disguise disguise = DisguiseUtilities.getDisguise(event.getPlayer(), packet.getIntegers().read(0));

View File

@ -8,8 +8,8 @@ import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoItemBlock;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.watchers.DisguiseMethods;
import org.bukkit.ChatColor;
import org.bukkit.inventory.ItemStack;

View File

@ -5,7 +5,6 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.params.types.ParamInfoEnum;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import me.libraryaddict.disguise.utilities.translations.TranslateType;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;

View File

@ -1,9 +1,9 @@
package me.libraryaddict.disguise.utilities.params.types.custom;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.utilities.params.ParamInfo;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.params.ParamInfo;
/**
* Created by libraryaddict on 6/03/2019.

View File

@ -9,7 +9,6 @@ import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import me.libraryaddict.disguise.utilities.translations.TranslateType;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;

View File

@ -1,7 +1,6 @@
package me.libraryaddict.disguise.utilities.plugin;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.utilities.LibsPremium;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
@ -14,7 +13,7 @@ import java.net.URL;
*/
public class BisectHosting {
public boolean isBisectHosted(String pluginName) {
File configFile = new File("plugins/" + pluginName + "/internal-config.yml");
File configFile = new File("plugins/" + pluginName + "/internal.yml");
boolean claimedHosted = false;
if (configFile.exists()) {
@ -54,9 +53,8 @@ public class BisectHosting {
try (PrintWriter writer = new PrintWriter(configFile, "UTF-8")) {
// This setting is if the server should check if you are using Bisect Hosting",
writer.write("# If you're using BisectHosting, this will tell the server to enable premium for free!");
writer.write(
"\n# However if you're not using BisectHosting, this is false so the server won't waste " +
"time");
writer.write("\n# However if you're not using BisectHosting, this is false so the server won't waste " +
"time");
writer.write(
"\n# Coupon 'libraryaddict' for 25% off your first invoice on any of their gaming servers");
writer.write("\n# Be sure to visit through this link! https://bisecthosting.com/libraryaddict");
@ -67,7 +65,7 @@ public class BisectHosting {
}
} else if (claimedHosted) {
// Just a small message for those who tried to enable it
LibsDisguises.getInstance().getLogger().severe("Check for Bisect Hosting failed! Connection error?");
LibsDisguises.getInstance().getLogger().severe("Check for BisectHosting failed! Connection error?");
}
return hostedBy;

View File

@ -5,12 +5,14 @@ import com.comphenix.protocol.wrappers.*;
import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
import com.comphenix.protocol.wrappers.nbt.NbtWrapper;
import lombok.Getter;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.*;
import me.libraryaddict.disguise.disguisetypes.watchers.*;
import me.libraryaddict.disguise.utilities.*;
import me.libraryaddict.disguise.utilities.DisguiseSound;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.DisguiseValues;
import me.libraryaddict.disguise.utilities.LibsPremium;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.bukkit.*;

View File

@ -1,6 +1,5 @@
package me.libraryaddict.disguise.utilities.reflection.asm;
import com.google.gson.Gson;
import lombok.Getter;
import org.objectweb.asm.*;

View File

@ -3,8 +3,6 @@ package me.libraryaddict.disguise.utilities.reflection.asm;
import lombok.Getter;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import java.lang.reflect.Type;
/**
* Created by libraryaddict on 17/02/2020.
*/

View File

@ -2,7 +2,6 @@ package me.libraryaddict.disguise.utilities.reflection.asm;
import com.google.gson.Gson;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPluginLoader;
@ -15,7 +14,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
/**

View File

@ -1,10 +1,8 @@
package me.libraryaddict.disguise.utilities.translations;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.params.ParamInfo;
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.reflection.ClassGetter;
import org.apache.commons.lang.StringUtils;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;

View File

@ -13,7 +13,10 @@ import org.bukkit.Sound;
import java.io.File;
import java.io.PrintWriter;
import java.lang.reflect.Method;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
/**
* Created by libraryaddict on 13/02/2020.