Renamed messages from "option" to "method" to make things clearer

Added better support for tab completion and ignoring the first arg of falling blocks and item disguises, so /disguise fallingblock setburning - Is now possible
Fixed itemstack parsing returning illegal/unwanted air block
This commit is contained in:
libraryaddict 2020-04-04 19:58:21 +13:00
parent 269a5c3aef
commit efbd6e29e3
No known key found for this signature in database
GPG Key ID: 052E4FBCD257AEA4
12 changed files with 62 additions and 53 deletions

View File

@ -9,6 +9,7 @@ import me.libraryaddict.disguise.commands.modify.DisguiseModifyEntityCommand;
import me.libraryaddict.disguise.commands.modify.DisguiseModifyPlayerCommand; import me.libraryaddict.disguise.commands.modify.DisguiseModifyPlayerCommand;
import me.libraryaddict.disguise.commands.modify.DisguiseModifyRadiusCommand; import me.libraryaddict.disguise.commands.modify.DisguiseModifyRadiusCommand;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsPremium; import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.params.ParamInfo; import me.libraryaddict.disguise.utilities.params.ParamInfo;
import me.libraryaddict.disguise.utilities.params.ParamInfoManager; import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
@ -20,6 +21,7 @@ import org.bukkit.ChatColor;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scoreboard.Team; import org.bukkit.scoreboard.Team;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -135,30 +137,39 @@ public abstract class DisguiseBaseCommand implements CommandExecutor {
boolean addMethods = true; boolean addMethods = true;
List<String> tabs = new ArrayList<>(); List<String> tabs = new ArrayList<>();
// Check what argument was used before the current argument to see what we're displaying ParamInfo info = null;
if (allArgs.length > startsAt) {
if (allArgs.length == startsAt) {
if (disguisePerm.getType() == DisguiseType.FALLING_BLOCK) {
info = ParamInfoManager.getParamInfoItemBlock();
} else if (disguisePerm.getType() == DisguiseType.DROPPED_ITEM) {
info = ParamInfoManager.getParamInfo(ItemStack.class);
}
} else if (allArgs.length > startsAt) {
// Check what argument was used before the current argument to see what we're displaying
String prevArg = allArgs[allArgs.length - 1]; String prevArg = allArgs[allArgs.length - 1];
ParamInfo info = ParamInfoManager.getParamInfo(disguisePerm, prevArg); info = ParamInfoManager.getParamInfo(disguisePerm, prevArg);
// If the previous argument is a method if (info != null && !info.isParam(boolean.class)) {
if (info != null) { addMethods = false;
if (!info.isParam(boolean.class)) { }
addMethods = false; }
}
// If there is a list of default values // If the previous argument is a method
if (info.hasValues()) { if (info != null) {
tabs.addAll(info.getEnums(currentArg)); // If there is a list of default values
} else if (info.isParam(String.class)) { if (info.hasValues()) {
for (Player player : Bukkit.getOnlinePlayers()) { tabs.addAll(info.getEnums(currentArg));
// If command user cannot see player online, don't tab-complete name } else if (info.isParam(String.class)) {
if (commandSender instanceof Player && !((Player) commandSender).canSee(player)) { for (Player player : Bukkit.getOnlinePlayers()) {
continue; // If command user cannot see player online, don't tab-complete name
} if (commandSender instanceof Player && !((Player) commandSender).canSee(player)) {
continue;
tabs.add(player.getName());
} }
tabs.add(player.getName());
} }
} }
} }

View File

@ -131,7 +131,7 @@ public class MiscDisguise extends TargetedDisguise {
public int getData() { public int getData() {
switch (getType()) { switch (getType()) {
case FALLING_BLOCK: case FALLING_BLOCK:
return (int) ((FallingBlockWatcher) getWatcher()).getBlock().getDurability(); return ((FallingBlockWatcher) getWatcher()).getBlock().getDurability();
case PAINTING: case PAINTING:
return ((PaintingWatcher) getWatcher()).getArt().getId(); return ((PaintingWatcher) getWatcher()).getArt().getId();
case SPLASH_POTION: case SPLASH_POTION:

View File

@ -36,7 +36,7 @@ public class PlayerDisguise extends TargetedDisguise {
@Getter @Getter
@Setter @Setter
private boolean dynamicName; private boolean dynamicName;
private volatile DisguiseUtilities.DisguiseTeam scoreboardName; private volatile DisguiseUtilities.DScoreTeam scoreboardName;
private PlayerDisguise() { private PlayerDisguise() {
super(DisguiseType.PLAYER); super(DisguiseType.PLAYER);
@ -85,7 +85,7 @@ public class PlayerDisguise extends TargetedDisguise {
createDisguise(); createDisguise();
} }
public DisguiseUtilities.DisguiseTeam getScoreboardName() { public DisguiseUtilities.DScoreTeam getScoreboardName() {
if (getName().length() <= 16 ? !DisguiseConfig.isScoreboardDisguiseNames() : if (getName().length() <= 16 ? !DisguiseConfig.isScoreboardDisguiseNames() :
!DisguiseConfig.isExtendedDisguiseNames()) { !DisguiseConfig.isExtendedDisguiseNames()) {
throw new IllegalStateException("Cannot use this method when it's been disabled in config!"); throw new IllegalStateException("Cannot use this method when it's been disabled in config!");
@ -217,7 +217,7 @@ public class PlayerDisguise extends TargetedDisguise {
boolean resendDisguise = !DisguiseConfig.isScoreboardDisguiseNames(); boolean resendDisguise = !DisguiseConfig.isScoreboardDisguiseNames();
if (hasScoreboardName()) { if (hasScoreboardName()) {
DisguiseUtilities.DisguiseTeam team = getScoreboardName(); DisguiseUtilities.DScoreTeam team = getScoreboardName();
String[] split = DisguiseUtilities.getExtendedNameSplit(team.getPlayer(), name); String[] split = DisguiseUtilities.getExtendedNameSplit(team.getPlayer(), name);
resendDisguise = !split[1].equals(team.getPlayer()); resendDisguise = !split[1].equals(team.getPlayer());
@ -258,7 +258,7 @@ public class PlayerDisguise extends TargetedDisguise {
} }
} else { } else {
if (scoreboardName != null) { if (scoreboardName != null) {
DisguiseUtilities.DisguiseTeam team = getScoreboardName(); DisguiseUtilities.DScoreTeam team = getScoreboardName();
String[] split = DisguiseUtilities.getExtendedNameSplit(team.getPlayer(), name); String[] split = DisguiseUtilities.getExtendedNameSplit(team.getPlayer(), name);
team.setSplit(split); team.setSplit(split);

View File

@ -47,7 +47,7 @@ public class ZombieWatcher extends InsentientWatcher {
@Deprecated @Deprecated
@NmsRemovedIn(val = NmsVersion.v1_14) @NmsRemovedIn(val = NmsVersion.v1_14)
public boolean isAggressive() { public boolean isAggressive() {
return (boolean) getData(MetaIndex.ZOMBIE_AGGRESSIVE); return getData(MetaIndex.ZOMBIE_AGGRESSIVE);
} }
@Deprecated @Deprecated

View File

@ -57,8 +57,8 @@ import java.util.stream.Collectors;
public class DisguiseUtilities { public class DisguiseUtilities {
@Setter @Setter
public static class DisguiseTeam { public static class DScoreTeam {
public DisguiseTeam(String[] name) { public DScoreTeam(String[] name) {
this.split = name; this.split = name;
} }
@ -1269,10 +1269,10 @@ public class DisguiseUtilities {
return boards; return boards;
} }
public static DisguiseTeam createExtendedName(String name) { public static DScoreTeam createExtendedName(String name) {
String[] split = getExtendedNameSplit(null, name); String[] split = getExtendedNameSplit(null, name);
return new DisguiseTeam(split); return new DScoreTeam(split);
} }
public static String getUniqueTeam() { public static String getUniqueTeam() {
@ -1298,7 +1298,7 @@ public class DisguiseUtilities {
} }
public static void updateExtendedName(PlayerDisguise disguise) { public static void updateExtendedName(PlayerDisguise disguise) {
DisguiseTeam exName = disguise.getScoreboardName(); DScoreTeam exName = disguise.getScoreboardName();
for (Scoreboard board : getAllScoreboards()) { for (Scoreboard board : getAllScoreboards()) {
exName.handleTeam(board, disguise.isNameVisible()); exName.handleTeam(board, disguise.isNameVisible());
@ -1306,7 +1306,7 @@ public class DisguiseUtilities {
} }
public static void registerExtendedName(PlayerDisguise disguise) { public static void registerExtendedName(PlayerDisguise disguise) {
DisguiseTeam exName = disguise.getScoreboardName(); DScoreTeam exName = disguise.getScoreboardName();
if (exName.getTeamName() == null) { if (exName.getTeamName() == null) {
exName.setTeamName(getUniqueTeam()); exName.setTeamName(getUniqueTeam());
@ -1324,7 +1324,7 @@ public class DisguiseUtilities {
continue; continue;
} }
DisguiseTeam name = ((PlayerDisguise) disguise).getScoreboardName(); DScoreTeam name = ((PlayerDisguise) disguise).getScoreboardName();
name.handleTeam(scoreboard, ((PlayerDisguise) disguise).isNameVisible()); name.handleTeam(scoreboard, ((PlayerDisguise) disguise).isNameVisible());
} }

View File

@ -31,7 +31,7 @@ public class ParamInfoItemBlock extends ParamInfoItemStack {
material = Material.getMaterial(split[0].toUpperCase()); material = Material.getMaterial(split[0].toUpperCase());
} }
if (material == null) { if (material == null || (material == Material.AIR && !split[0].equalsIgnoreCase("air"))) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }

View File

@ -131,7 +131,7 @@ public class ParamInfoItemStack extends ParamInfoEnum {
material = Material.getMaterial(split[0].toUpperCase()); material = Material.getMaterial(split[0].toUpperCase());
} }
if (material == null) { if (material == null || (material == Material.AIR && !split[0].equalsIgnoreCase("air"))) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
@ -161,7 +161,7 @@ public class ParamInfoItemStack extends ParamInfoEnum {
Material material = Material.getMaterial(split[0].toUpperCase()); Material material = Material.getMaterial(split[0].toUpperCase());
if (material == null) { if (material == null || (material == Material.AIR && !split[0].equalsIgnoreCase("air"))) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }

View File

@ -13,7 +13,7 @@ public class DisguiseParseException extends Exception {
} }
public DisguiseParseException(LibsMsg message, String... params) { public DisguiseParseException(LibsMsg message, String... params) {
super(message.get((Object[]) params)); super(message.get(params));
} }
public DisguiseParseException(String message) { public DisguiseParseException(String message) {

View File

@ -282,7 +282,7 @@ public class DisguisePermissions {
// The permission is negated, and only has negated options. Should mean something, but to most people // The permission is negated, and only has negated options. Should mean something, but to most people
// it's nonsense and should be ignored. // it's nonsense and should be ignored.
if (parsedPermission.isNegated() && !parsedPermission.options.values().contains(true)) { if (parsedPermission.isNegated() && !parsedPermission.options.containsValue(true)) {
continue; continue;
} }

View File

@ -126,9 +126,7 @@ public class ReflectionManager {
if (obj.isAnnotationPresent(NmsRemovedIn.class)) { if (obj.isAnnotationPresent(NmsRemovedIn.class)) {
NmsRemovedIn removed = obj.getAnnotation(NmsRemovedIn.class); NmsRemovedIn removed = obj.getAnnotation(NmsRemovedIn.class);
if (removed.val().isSupported()) { return !removed.val().isSupported();
return false;
}
} }
return true; return true;
@ -716,7 +714,7 @@ public class ReflectionManager {
public static double getPing(Player player) { public static double getPing(Player player) {
try { try {
return (double) pingField.getInt(ReflectionManager.getNmsEntity(player)); return pingField.getInt(ReflectionManager.getNmsEntity(player));
} }
catch (Exception ex) { catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();

View File

@ -9,7 +9,7 @@ import java.util.Map;
* Created by libraryaddict on 17/02/2020. * Created by libraryaddict on 17/02/2020.
*/ */
public interface IAsm { public interface IAsm {
public Class<?> createClassWithoutMethods(String className, ArrayList<Map.Entry<String, String>> illegalMethods) throws IOException, InvocationTargetException, IllegalAccessException, NoSuchMethodException, NoSuchFieldException; Class<?> createClassWithoutMethods(String className, ArrayList<Map.Entry<String, String>> illegalMethods) throws IOException, InvocationTargetException, IllegalAccessException, NoSuchMethodException, NoSuchFieldException;
} }

View File

@ -27,13 +27,13 @@ public enum LibsMsg {
D_HELP3(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> player <Name>"), D_HELP3(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> player <Name>"),
D_HELP4(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> <DisguiseType> <Baby>"), D_HELP4(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> <DisguiseType> <Baby>"),
D_HELP5(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> <Dropped_Item/Falling_Block> <Id> <Durability>"), D_HELP5(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> <Dropped_Item/Falling_Block> <Id> <Durability>"),
D_PARSE_NOPERM(ChatColor.RED + "You do not have permission to use the option %s"), D_PARSE_NOPERM(ChatColor.RED + "You do not have permission to use the method %s"),
DHELP_CANTFIND(ChatColor.RED + "Cannot find the disguise %s"), DHELP_CANTFIND(ChatColor.RED + "Cannot find the disguise %s"),
DHELP_HELP1(ChatColor.RED + "/disguisehelp <DisguiseType> " + ChatColor.GREEN + DHELP_HELP1(ChatColor.RED + "/disguisehelp <DisguiseType> " + ChatColor.GREEN +
"- View the options you can set on a disguise. Add 'show' to reveal the options you don't have permission" + "- View the methods you can set on a disguise. Add 'show' to reveal the methods you don't have permission" +
" to use"), " to use"),
DHELP_HELP2(ChatColor.RED + "/disguisehelp <DisguiseOption> " + ChatColor.GREEN + "- View information about the " + DHELP_HELP2(ChatColor.RED + "/disguisehelp <DisguiseOption> " + ChatColor.GREEN + "- View information about the " +
"disguise options such as 'RabbitType'"), "disguise values such as 'RabbitType'"),
DHELP_HELP3(ChatColor.RED + "/disguisehelp " + ChatColor.DARK_GREEN + "%s" + ChatColor.GREEN + " - %s"), DHELP_HELP3(ChatColor.RED + "/disguisehelp " + ChatColor.DARK_GREEN + "%s" + ChatColor.GREEN + " - %s"),
DHELP_HELP4(ChatColor.RED + "%s: " + ChatColor.GREEN + "%s"), DHELP_HELP4(ChatColor.RED + "%s: " + ChatColor.GREEN + "%s"),
DHELP_HELP4_SEPERATOR(ChatColor.RED + ", " + ChatColor.GREEN), DHELP_HELP4_SEPERATOR(ChatColor.RED + ", " + ChatColor.GREEN),
@ -77,13 +77,13 @@ public enum LibsMsg {
DCLONE_SNEAK("doSneak"), DCLONE_SNEAK("doSneak"),
DCLONE_SPRINT("doSprint"), DCLONE_SPRINT("doSprint"),
DMODRADIUS_HELP2((ChatColor.DARK_GREEN + "/disguisemodifyradius <DisguiseType" + ChatColor.DARK_GREEN + "(" + DMODRADIUS_HELP2((ChatColor.DARK_GREEN + "/disguisemodifyradius <DisguiseType" + ChatColor.DARK_GREEN + "(" +
ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")> <Radius> <Disguise Options>") ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")> <Radius> <Disguise Methods>")
.replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")),
DMODRADIUS_HELP3(ChatColor.DARK_GREEN + "See the DisguiseType's usable by " + ChatColor.GREEN + DMODRADIUS_HELP3(ChatColor.DARK_GREEN + "See the DisguiseType's usable by " + ChatColor.GREEN +
"/disguisemodifyradius DisguiseType"), "/disguisemodifyradius DisguiseType"),
DMODRADIUS_NEEDOPTIONS(ChatColor.RED + "You need to supply the disguise options as well as the radius"), DMODRADIUS_NEEDOPTIONS(ChatColor.RED + "You need to supply the disguise methods as well as the radius"),
DMODRADIUS_NEEDOPTIONS_ENTITY( DMODRADIUS_NEEDOPTIONS_ENTITY(
ChatColor.RED + "You need to supply the disguise options as well as the radius and EntityType"), ChatColor.RED + "You need to supply the disguise methods as well as the radius and EntityType"),
DMODRADIUS_NOENTS(ChatColor.RED + "Couldn't find any disguised entities!"), DMODRADIUS_NOENTS(ChatColor.RED + "Couldn't find any disguised entities!"),
DMODRADIUS_NOPERM(ChatColor.RED + "No permission to modify %s disguises!"), DMODRADIUS_NOPERM(ChatColor.RED + "No permission to modify %s disguises!"),
DMODRADIUS_UNRECOGNIZED(ChatColor.RED + "Unrecognised DisguiseType %s"), DMODRADIUS_UNRECOGNIZED(ChatColor.RED + "Unrecognised DisguiseType %s"),
@ -112,7 +112,7 @@ public enum LibsMsg {
FAILED_DISGIUSE(ChatColor.RED + "Failed to disguise as a %s"), FAILED_DISGIUSE(ChatColor.RED + "Failed to disguise as a %s"),
GRABBED_SKIN(ChatColor.GOLD + "Grabbed skin and saved as %s!"), GRABBED_SKIN(ChatColor.GOLD + "Grabbed skin and saved as %s!"),
PLEASE_WAIT(ChatColor.GRAY + "Please wait..."), PLEASE_WAIT(ChatColor.GRAY + "Please wait..."),
INVALID_CLONE(ChatColor.DARK_RED + "Unknown option '%s' - Valid options are 'IgnoreEquipment' 'DoSneakSprint' " + INVALID_CLONE(ChatColor.DARK_RED + "Unknown method '%s' - Valid methods are 'IgnoreEquipment' 'DoSneakSprint' " +
"'DoSneak' 'DoSprint'"), "'DoSneak' 'DoSprint'"),
LIBS_COMMAND_WRONG_ARG( LIBS_COMMAND_WRONG_ARG(
ChatColor.RED + "[LibsDisguises] Did you mean 'reload', 'scoreboard', 'permtest', 'json' or 'metainfo'?"), ChatColor.RED + "[LibsDisguises] Did you mean 'reload', 'scoreboard', 'permtest', 'json' or 'metainfo'?"),
@ -136,7 +136,7 @@ public enum LibsMsg {
NO_PERM(ChatColor.RED + "You are forbidden to use this command."), NO_PERM(ChatColor.RED + "You are forbidden to use this command."),
NO_PERM_DISGUISE(ChatColor.RED + "You do not have permission for that disguise!"), NO_PERM_DISGUISE(ChatColor.RED + "You do not have permission for that disguise!"),
NO_PERMS_USE_OPTIONS(ChatColor.RED + NO_PERMS_USE_OPTIONS(ChatColor.RED +
"Ignored %s options you do not have permission to use. Add 'show' to view unusable options."), "Ignored %s methods you do not have permission to use. Add 'show' to view unusable methods."),
OWNED_BY(ChatColor.GOLD + "Plugin registered to '%%__USER__%%'!"), OWNED_BY(ChatColor.GOLD + "Plugin registered to '%%__USER__%%'!"),
NOT_DISGUISED(ChatColor.RED + "You are not disguised!"), NOT_DISGUISED(ChatColor.RED + "You are not disguised!"),
TARGET_NOT_DISGUISED(ChatColor.RED + "That entity is not disguised!"), TARGET_NOT_DISGUISED(ChatColor.RED + "That entity is not disguised!"),
@ -156,13 +156,13 @@ public enum LibsMsg {
ChatColor.RED + "Expected " + ChatColor.GREEN + "%s:Color,Size.0?" + ChatColor.RED + ", received " + ChatColor.RED + "Expected " + ChatColor.GREEN + "%s:Color,Size.0?" + ChatColor.RED + ", received " +
ChatColor.GREEN + "%s" + ChatColor.RED + " instead"), ChatColor.GREEN + "%s" + ChatColor.RED + " instead"),
PARSE_NO_ARGS("No arguments defined"), PARSE_NO_ARGS("No arguments defined"),
PARSE_NO_OPTION_VALUE(ChatColor.RED + "No value was given for the option %s"), PARSE_NO_OPTION_VALUE(ChatColor.RED + "No value was given for the method %s"),
PARSE_NO_PERM_NAME(ChatColor.RED + "Error! You don't have permission to use that name!"), PARSE_NO_PERM_NAME(ChatColor.RED + "Error! You don't have permission to use that name!"),
PARSE_NO_PERM_PARAM( PARSE_NO_PERM_PARAM(
ChatColor.RED + "Error! You do not have permission to use the parameter %s on the %s disguise!"), ChatColor.RED + "Error! You do not have permission to use the parameter %s on the %s disguise!"),
PARSE_NO_PERM_REF(ChatColor.RED + "You do not have permission to use disguise references!"), PARSE_NO_PERM_REF(ChatColor.RED + "You do not have permission to use disguise references!"),
PARSE_NO_REF(ChatColor.RED + "Cannot find a disguise under the reference %s"), PARSE_NO_REF(ChatColor.RED + "Cannot find a disguise under the reference %s"),
PARSE_OPTION_NA(ChatColor.RED + "Cannot find the option '%s'"), PARSE_OPTION_NA(ChatColor.RED + "Cannot find the method '%s'"),
PARSE_SUPPLY_PLAYER(ChatColor.RED + "Error! You need to give a player name!"), PARSE_SUPPLY_PLAYER(ChatColor.RED + "Error! You need to give a player name!"),
PARSE_TOO_MANY_ARGS(ChatColor.RED + "Error! %s doesn't know what to do with %s!"), PARSE_TOO_MANY_ARGS(ChatColor.RED + "Error! %s doesn't know what to do with %s!"),
PARSE_INVALID_TIME(ChatColor.RED + "Error! %s is not a valid time! Use s,m,h,d or secs,mins,hours,days"), PARSE_INVALID_TIME(ChatColor.RED + "Error! %s is not a valid time! Use s,m,h,d or secs,mins,hours,days"),
@ -295,7 +295,7 @@ public enum LibsMsg {
return TranslateType.MESSAGES.get(getRaw()); return TranslateType.MESSAGES.get(getRaw());
} }
return String.format(TranslateType.MESSAGES.get(getRaw()), (Object[]) strings); return String.format(TranslateType.MESSAGES.get(getRaw()), strings);
} }
public String toString() { public String toString() {