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:
parent
269a5c3aef
commit
efbd6e29e3
@ -9,6 +9,7 @@ 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.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||
import me.libraryaddict.disguise.utilities.params.ParamInfo;
|
||||
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
|
||||
@ -20,6 +21,7 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
@ -135,18 +137,28 @@ public abstract class DisguiseBaseCommand implements CommandExecutor {
|
||||
boolean addMethods = true;
|
||||
List<String> tabs = new ArrayList<>();
|
||||
|
||||
ParamInfo info = null;
|
||||
|
||||
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
|
||||
if (allArgs.length > startsAt) {
|
||||
|
||||
String prevArg = allArgs[allArgs.length - 1];
|
||||
|
||||
ParamInfo info = ParamInfoManager.getParamInfo(disguisePerm, prevArg);
|
||||
info = ParamInfoManager.getParamInfo(disguisePerm, prevArg);
|
||||
|
||||
if (info != null && !info.isParam(boolean.class)) {
|
||||
addMethods = false;
|
||||
}
|
||||
}
|
||||
|
||||
// If the previous argument is a method
|
||||
if (info != null) {
|
||||
if (!info.isParam(boolean.class)) {
|
||||
addMethods = false;
|
||||
}
|
||||
|
||||
// If there is a list of default values
|
||||
if (info.hasValues()) {
|
||||
tabs.addAll(info.getEnums(currentArg));
|
||||
@ -161,7 +173,6 @@ public abstract class DisguiseBaseCommand implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (addMethods) {
|
||||
// If this is a method, add. Else if it can be a param of the previous argument, add.
|
||||
|
@ -131,7 +131,7 @@ public class MiscDisguise extends TargetedDisguise {
|
||||
public int getData() {
|
||||
switch (getType()) {
|
||||
case FALLING_BLOCK:
|
||||
return (int) ((FallingBlockWatcher) getWatcher()).getBlock().getDurability();
|
||||
return ((FallingBlockWatcher) getWatcher()).getBlock().getDurability();
|
||||
case PAINTING:
|
||||
return ((PaintingWatcher) getWatcher()).getArt().getId();
|
||||
case SPLASH_POTION:
|
||||
|
@ -36,7 +36,7 @@ public class PlayerDisguise extends TargetedDisguise {
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean dynamicName;
|
||||
private volatile DisguiseUtilities.DisguiseTeam scoreboardName;
|
||||
private volatile DisguiseUtilities.DScoreTeam scoreboardName;
|
||||
|
||||
private PlayerDisguise() {
|
||||
super(DisguiseType.PLAYER);
|
||||
@ -85,7 +85,7 @@ public class PlayerDisguise extends TargetedDisguise {
|
||||
createDisguise();
|
||||
}
|
||||
|
||||
public DisguiseUtilities.DisguiseTeam getScoreboardName() {
|
||||
public DisguiseUtilities.DScoreTeam getScoreboardName() {
|
||||
if (getName().length() <= 16 ? !DisguiseConfig.isScoreboardDisguiseNames() :
|
||||
!DisguiseConfig.isExtendedDisguiseNames()) {
|
||||
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();
|
||||
|
||||
if (hasScoreboardName()) {
|
||||
DisguiseUtilities.DisguiseTeam team = getScoreboardName();
|
||||
DisguiseUtilities.DScoreTeam team = getScoreboardName();
|
||||
String[] split = DisguiseUtilities.getExtendedNameSplit(team.getPlayer(), name);
|
||||
|
||||
resendDisguise = !split[1].equals(team.getPlayer());
|
||||
@ -258,7 +258,7 @@ public class PlayerDisguise extends TargetedDisguise {
|
||||
}
|
||||
} else {
|
||||
if (scoreboardName != null) {
|
||||
DisguiseUtilities.DisguiseTeam team = getScoreboardName();
|
||||
DisguiseUtilities.DScoreTeam team = getScoreboardName();
|
||||
String[] split = DisguiseUtilities.getExtendedNameSplit(team.getPlayer(), name);
|
||||
|
||||
team.setSplit(split);
|
||||
|
@ -47,7 +47,7 @@ public class ZombieWatcher extends InsentientWatcher {
|
||||
@Deprecated
|
||||
@NmsRemovedIn(val = NmsVersion.v1_14)
|
||||
public boolean isAggressive() {
|
||||
return (boolean) getData(MetaIndex.ZOMBIE_AGGRESSIVE);
|
||||
return getData(MetaIndex.ZOMBIE_AGGRESSIVE);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
|
@ -57,8 +57,8 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class DisguiseUtilities {
|
||||
@Setter
|
||||
public static class DisguiseTeam {
|
||||
public DisguiseTeam(String[] name) {
|
||||
public static class DScoreTeam {
|
||||
public DScoreTeam(String[] name) {
|
||||
this.split = name;
|
||||
}
|
||||
|
||||
@ -1269,10 +1269,10 @@ public class DisguiseUtilities {
|
||||
return boards;
|
||||
}
|
||||
|
||||
public static DisguiseTeam createExtendedName(String name) {
|
||||
public static DScoreTeam createExtendedName(String name) {
|
||||
String[] split = getExtendedNameSplit(null, name);
|
||||
|
||||
return new DisguiseTeam(split);
|
||||
return new DScoreTeam(split);
|
||||
}
|
||||
|
||||
public static String getUniqueTeam() {
|
||||
@ -1298,7 +1298,7 @@ public class DisguiseUtilities {
|
||||
}
|
||||
|
||||
public static void updateExtendedName(PlayerDisguise disguise) {
|
||||
DisguiseTeam exName = disguise.getScoreboardName();
|
||||
DScoreTeam exName = disguise.getScoreboardName();
|
||||
|
||||
for (Scoreboard board : getAllScoreboards()) {
|
||||
exName.handleTeam(board, disguise.isNameVisible());
|
||||
@ -1306,7 +1306,7 @@ public class DisguiseUtilities {
|
||||
}
|
||||
|
||||
public static void registerExtendedName(PlayerDisguise disguise) {
|
||||
DisguiseTeam exName = disguise.getScoreboardName();
|
||||
DScoreTeam exName = disguise.getScoreboardName();
|
||||
|
||||
if (exName.getTeamName() == null) {
|
||||
exName.setTeamName(getUniqueTeam());
|
||||
@ -1324,7 +1324,7 @@ public class DisguiseUtilities {
|
||||
continue;
|
||||
}
|
||||
|
||||
DisguiseTeam name = ((PlayerDisguise) disguise).getScoreboardName();
|
||||
DScoreTeam name = ((PlayerDisguise) disguise).getScoreboardName();
|
||||
|
||||
name.handleTeam(scoreboard, ((PlayerDisguise) disguise).isNameVisible());
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public class ParamInfoItemBlock extends ParamInfoItemStack {
|
||||
material = Material.getMaterial(split[0].toUpperCase());
|
||||
}
|
||||
|
||||
if (material == null) {
|
||||
if (material == null || (material == Material.AIR && !split[0].equalsIgnoreCase("air"))) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
|
@ -131,7 +131,7 @@ public class ParamInfoItemStack extends ParamInfoEnum {
|
||||
material = Material.getMaterial(split[0].toUpperCase());
|
||||
}
|
||||
|
||||
if (material == null) {
|
||||
if (material == null || (material == Material.AIR && !split[0].equalsIgnoreCase("air"))) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
@ -161,7 +161,7 @@ public class ParamInfoItemStack extends ParamInfoEnum {
|
||||
|
||||
Material material = Material.getMaterial(split[0].toUpperCase());
|
||||
|
||||
if (material == null) {
|
||||
if (material == null || (material == Material.AIR && !split[0].equalsIgnoreCase("air"))) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ public class DisguiseParseException extends Exception {
|
||||
}
|
||||
|
||||
public DisguiseParseException(LibsMsg message, String... params) {
|
||||
super(message.get((Object[]) params));
|
||||
super(message.get(params));
|
||||
}
|
||||
|
||||
public DisguiseParseException(String message) {
|
||||
|
@ -282,7 +282,7 @@ public class DisguisePermissions {
|
||||
|
||||
// The permission is negated, and only has negated options. Should mean something, but to most people
|
||||
// it's nonsense and should be ignored.
|
||||
if (parsedPermission.isNegated() && !parsedPermission.options.values().contains(true)) {
|
||||
if (parsedPermission.isNegated() && !parsedPermission.options.containsValue(true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -126,9 +126,7 @@ public class ReflectionManager {
|
||||
if (obj.isAnnotationPresent(NmsRemovedIn.class)) {
|
||||
NmsRemovedIn removed = obj.getAnnotation(NmsRemovedIn.class);
|
||||
|
||||
if (removed.val().isSupported()) {
|
||||
return false;
|
||||
}
|
||||
return !removed.val().isSupported();
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -716,7 +714,7 @@ public class ReflectionManager {
|
||||
|
||||
public static double getPing(Player player) {
|
||||
try {
|
||||
return (double) pingField.getInt(ReflectionManager.getNmsEntity(player));
|
||||
return pingField.getInt(ReflectionManager.getNmsEntity(player));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
@ -9,7 +9,7 @@ import java.util.Map;
|
||||
* Created by libraryaddict on 17/02/2020.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -27,13 +27,13 @@ public enum LibsMsg {
|
||||
D_HELP3(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> player <Name>"),
|
||||
D_HELP4(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> <DisguiseType> <Baby>"),
|
||||
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_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"),
|
||||
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_HELP4(ChatColor.RED + "%s: " + ChatColor.GREEN + "%s"),
|
||||
DHELP_HELP4_SEPERATOR(ChatColor.RED + ", " + ChatColor.GREEN),
|
||||
@ -77,13 +77,13 @@ public enum LibsMsg {
|
||||
DCLONE_SNEAK("doSneak"),
|
||||
DCLONE_SPRINT("doSprint"),
|
||||
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 + ">")),
|
||||
DMODRADIUS_HELP3(ChatColor.DARK_GREEN + "See the DisguiseType's usable by " + ChatColor.GREEN +
|
||||
"/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(
|
||||
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_NOPERM(ChatColor.RED + "No permission to modify %s disguises!"),
|
||||
DMODRADIUS_UNRECOGNIZED(ChatColor.RED + "Unrecognised DisguiseType %s"),
|
||||
@ -112,7 +112,7 @@ public enum LibsMsg {
|
||||
FAILED_DISGIUSE(ChatColor.RED + "Failed to disguise as a %s"),
|
||||
GRABBED_SKIN(ChatColor.GOLD + "Grabbed skin and saved as %s!"),
|
||||
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'"),
|
||||
LIBS_COMMAND_WRONG_ARG(
|
||||
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_DISGUISE(ChatColor.RED + "You do not have permission for that disguise!"),
|
||||
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__%%'!"),
|
||||
NOT_DISGUISED(ChatColor.RED + "You are 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.GREEN + "%s" + ChatColor.RED + " instead"),
|
||||
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_PARAM(
|
||||
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_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_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"),
|
||||
@ -295,7 +295,7 @@ public enum LibsMsg {
|
||||
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() {
|
||||
|
Loading…
Reference in New Issue
Block a user