Cleaned up disguise permissions parsing and allowed negating parameters through negated permissions instead of "-" parameters. #307
This commit is contained in:
parent
383c9ecaca
commit
b42cf5cc43
@ -18,7 +18,7 @@ import me.libraryaddict.disguise.utilities.LibsMsg;
|
|||||||
import me.libraryaddict.disguise.utilities.UpdateChecker;
|
import me.libraryaddict.disguise.utilities.UpdateChecker;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm;
|
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
@ -1,19 +1,14 @@
|
|||||||
package me.libraryaddict.disguise.commands;
|
package me.libraryaddict.disguise.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||||
import java.util.Collections;
|
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scoreboard.Team;
|
import org.bukkit.scoreboard.Team;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author libraryaddict
|
* @author libraryaddict
|
||||||
*/
|
*/
|
||||||
|
@ -2,7 +2,7 @@ package me.libraryaddict.disguise.commands;
|
|||||||
|
|
||||||
import me.libraryaddict.disguise.DisguiseConfig;
|
import me.libraryaddict.disguise.DisguiseConfig;
|
||||||
import me.libraryaddict.disguise.LibsDisguises;
|
import me.libraryaddict.disguise.LibsDisguises;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm;
|
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
||||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||||
import me.libraryaddict.disguise.utilities.LibsMsg;
|
import me.libraryaddict.disguise.utilities.LibsMsg;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
@ -8,7 +8,7 @@ import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
|||||||
import me.libraryaddict.disguise.utilities.LibsMsg;
|
import me.libraryaddict.disguise.utilities.LibsMsg;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm;
|
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
||||||
import me.libraryaddict.disguise.utilities.parser.ParamInfoManager;
|
import me.libraryaddict.disguise.utilities.parser.ParamInfoManager;
|
||||||
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
@ -7,7 +7,7 @@ import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
|||||||
import me.libraryaddict.disguise.utilities.LibsMsg;
|
import me.libraryaddict.disguise.utilities.LibsMsg;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm;
|
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
||||||
import me.libraryaddict.disguise.utilities.parser.ParamInfoManager;
|
import me.libraryaddict.disguise.utilities.parser.ParamInfoManager;
|
||||||
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
@ -3,7 +3,7 @@ package me.libraryaddict.disguise.commands;
|
|||||||
import me.libraryaddict.disguise.utilities.LibsMsg;
|
import me.libraryaddict.disguise.utilities.LibsMsg;
|
||||||
import me.libraryaddict.disguise.utilities.TranslateType;
|
import me.libraryaddict.disguise.utilities.TranslateType;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm;
|
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
||||||
import me.libraryaddict.disguise.utilities.parser.ParamInfoManager;
|
import me.libraryaddict.disguise.utilities.parser.ParamInfoManager;
|
||||||
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
@ -6,7 +6,7 @@ import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
|||||||
import me.libraryaddict.disguise.utilities.LibsMsg;
|
import me.libraryaddict.disguise.utilities.LibsMsg;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm;
|
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
||||||
import me.libraryaddict.disguise.utilities.parser.ParamInfoManager;
|
import me.libraryaddict.disguise.utilities.parser.ParamInfoManager;
|
||||||
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
@ -4,7 +4,7 @@ import me.libraryaddict.disguise.DisguiseConfig;
|
|||||||
import me.libraryaddict.disguise.LibsDisguises;
|
import me.libraryaddict.disguise.LibsDisguises;
|
||||||
import me.libraryaddict.disguise.utilities.LibsMsg;
|
import me.libraryaddict.disguise.utilities.LibsMsg;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm;
|
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
||||||
import me.libraryaddict.disguise.utilities.parser.ParamInfoManager;
|
import me.libraryaddict.disguise.utilities.parser.ParamInfoManager;
|
||||||
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
@ -5,7 +5,7 @@ import me.libraryaddict.disguise.disguisetypes.Disguise;
|
|||||||
import me.libraryaddict.disguise.utilities.LibsMsg;
|
import me.libraryaddict.disguise.utilities.LibsMsg;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm;
|
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
||||||
import me.libraryaddict.disguise.utilities.parser.ParamInfoManager;
|
import me.libraryaddict.disguise.utilities.parser.ParamInfoManager;
|
||||||
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
@ -7,7 +7,7 @@ import me.libraryaddict.disguise.utilities.LibsMsg;
|
|||||||
import me.libraryaddict.disguise.utilities.TranslateType;
|
import me.libraryaddict.disguise.utilities.TranslateType;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm;
|
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
||||||
import me.libraryaddict.disguise.utilities.parser.ParamInfoManager;
|
import me.libraryaddict.disguise.utilities.parser.ParamInfoManager;
|
||||||
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
@ -8,7 +8,7 @@ import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
|||||||
import me.libraryaddict.disguise.utilities.LibsMsg;
|
import me.libraryaddict.disguise.utilities.LibsMsg;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm;
|
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
||||||
import me.libraryaddict.disguise.utilities.parser.ParamInfoManager;
|
import me.libraryaddict.disguise.utilities.parser.ParamInfoManager;
|
||||||
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
@ -10,7 +10,7 @@ import me.libraryaddict.disguise.utilities.LibsMsg;
|
|||||||
import me.libraryaddict.disguise.utilities.TranslateType;
|
import me.libraryaddict.disguise.utilities.TranslateType;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm;
|
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
||||||
import me.libraryaddict.disguise.utilities.parser.ParamInfoManager;
|
import me.libraryaddict.disguise.utilities.parser.ParamInfoManager;
|
||||||
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
@ -6,99 +6,28 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
|||||||
import me.libraryaddict.disguise.utilities.LibsMsg;
|
import me.libraryaddict.disguise.utilities.LibsMsg;
|
||||||
import me.libraryaddict.disguise.utilities.TranslateType;
|
import me.libraryaddict.disguise.utilities.TranslateType;
|
||||||
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.*;
|
import org.bukkit.entity.Ageable;
|
||||||
|
import org.bukkit.entity.Animals;
|
||||||
|
import org.bukkit.entity.Monster;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class DisguiseParser {
|
public class DisguiseParser {
|
||||||
public static class DisguisePerm {
|
|
||||||
private DisguiseType disguiseType;
|
|
||||||
private String permName;
|
|
||||||
|
|
||||||
public DisguisePerm(DisguiseType disguiseType) {
|
|
||||||
this.disguiseType = disguiseType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DisguisePerm(DisguiseType disguiseType, String disguisePerm) {
|
|
||||||
this.disguiseType = disguiseType;
|
|
||||||
permName = disguisePerm;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Class getEntityClass() {
|
|
||||||
return getType().getEntityClass();
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityType getEntityType() {
|
|
||||||
return getType().getEntityType();
|
|
||||||
}
|
|
||||||
|
|
||||||
public DisguiseType getType() {
|
|
||||||
return disguiseType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Class<? extends FlagWatcher> getWatcherClass() {
|
|
||||||
return getType().getWatcherClass();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isMisc() {
|
|
||||||
return getType().isMisc();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isMob() {
|
|
||||||
return getType().isMob();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPlayer() {
|
|
||||||
return getType().isPlayer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isUnknown() {
|
|
||||||
return getType().isUnknown();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toReadable() {
|
|
||||||
return permName == null ? getType().toReadable() : permName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
final int prime = 31;
|
|
||||||
int result = 1;
|
|
||||||
result = prime * result + ((disguiseType == null) ? 0 : disguiseType.hashCode());
|
|
||||||
result = prime * result + ((permName == null) ? 0 : permName.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (obj == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!(obj instanceof DisguisePerm))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
DisguisePerm other = (DisguisePerm) obj;
|
|
||||||
|
|
||||||
if (disguiseType != other.disguiseType)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return Objects.equals(permName, other.permName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void doCheck(CommandSender sender, HashMap<ArrayList<String>, Boolean> optionPermissions,
|
private static void doCheck(CommandSender sender, HashMap<ArrayList<String>, Boolean> optionPermissions,
|
||||||
ArrayList<String> usedOptions) throws DisguiseParseException {
|
ArrayList<String> usedOptions) throws DisguiseParseException {
|
||||||
|
|
||||||
@ -172,9 +101,8 @@ public class DisguiseParser {
|
|||||||
return perms;
|
return perms;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HashMap<ArrayList<String>, Boolean> getOptions(String perm) {
|
private static Pair<ArrayList<String>, Boolean> getOptions(String perm, boolean permitted) {
|
||||||
ArrayList<String> list = new ArrayList<>();
|
ArrayList<String> list = new ArrayList<>();
|
||||||
boolean isRemove = true;
|
|
||||||
String[] split = perm.split("\\.");
|
String[] split = perm.split("\\.");
|
||||||
|
|
||||||
for (int i = 1; i < split.length; i++) {
|
for (int i = 1; i < split.length; i++) {
|
||||||
@ -183,7 +111,7 @@ public class DisguiseParser {
|
|||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
option = option.substring(1);
|
option = option.substring(1);
|
||||||
isRemove = false;
|
permitted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (option.equals("baby")) {
|
if (option.equals("baby")) {
|
||||||
@ -193,10 +121,7 @@ public class DisguiseParser {
|
|||||||
list.add(option);
|
list.add(option);
|
||||||
}
|
}
|
||||||
|
|
||||||
HashMap<ArrayList<String>, Boolean> options = new HashMap<>();
|
return Pair.of(list, permitted);
|
||||||
options.put(list, isRemove);
|
|
||||||
|
|
||||||
return options;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -224,129 +149,141 @@ public class DisguiseParser {
|
|||||||
perms.put(permissionNode + "*.*", true);
|
perms.put(permissionNode + "*.*", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String perm : perms.keySet()) {
|
// The first passthrough
|
||||||
if (perms.get(perm)) {
|
// This sets what permissions they can use where a negated permission is refering to the parameters
|
||||||
perm = perm.substring(permissionNode.length());
|
for (Entry<String, Boolean> entry : perms.entrySet()) {
|
||||||
|
String perm = entry.getKey().substring(permissionNode.length());
|
||||||
|
String[] split = perm.split("\\.");
|
||||||
|
|
||||||
String disguiseType = perm.split("\\.")[0];
|
String disguiseType = split[0];
|
||||||
DisguisePerm dPerm = DisguiseParser.getDisguisePerm(disguiseType);
|
|
||||||
|
|
||||||
if (dPerm != null) {
|
// Permission was negated, wasn't refering to parameters
|
||||||
HashMap<ArrayList<String>, Boolean> list;
|
if (!entry.getValue() && split.length == 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (singleDisguises.containsKey(dPerm)) {
|
DisguisePerm dPerm = DisguiseParser.getDisguisePerm(disguiseType);
|
||||||
list = singleDisguises.get(dPerm);
|
|
||||||
} else {
|
if (dPerm != null) {
|
||||||
list = new HashMap<>();
|
HashMap<ArrayList<String>, Boolean> list;
|
||||||
singleDisguises.put(dPerm, list);
|
|
||||||
|
if (singleDisguises.containsKey(dPerm)) {
|
||||||
|
list = singleDisguises.get(dPerm);
|
||||||
|
} else {
|
||||||
|
list = new HashMap<>();
|
||||||
|
singleDisguises.put(dPerm, list);
|
||||||
|
}
|
||||||
|
|
||||||
|
Pair<ArrayList<String>, Boolean> options = getOptions(perm, entry.getValue());
|
||||||
|
|
||||||
|
list.put(options.getKey(), options.getValue());
|
||||||
|
} else {
|
||||||
|
for (DisguisePerm type : getDisguisePerms()) {
|
||||||
|
Pair<ArrayList<String>, Boolean> options = null;
|
||||||
|
Class entityClass = type.getEntityClass();
|
||||||
|
|
||||||
|
if (disguiseType.equals("mob")) {
|
||||||
|
if (type.isMob()) {
|
||||||
|
options = getOptions(perm, entry.getValue());
|
||||||
|
}
|
||||||
|
} else if (disguiseType.equals("animal") || disguiseType.equals("animals")) {
|
||||||
|
if (Animals.class.isAssignableFrom(entityClass)) {
|
||||||
|
options = getOptions(perm, entry.getValue());
|
||||||
|
}
|
||||||
|
} else if (disguiseType.equals("monster") || disguiseType.equals("monsters")) {
|
||||||
|
if (Monster.class.isAssignableFrom(entityClass)) {
|
||||||
|
options = getOptions(perm, entry.getValue());
|
||||||
|
}
|
||||||
|
} else if (disguiseType.equals("misc")) {
|
||||||
|
if (type.isMisc()) {
|
||||||
|
options = getOptions(perm, entry.getValue());
|
||||||
|
}
|
||||||
|
} else if (disguiseType.equals("ageable")) {
|
||||||
|
if (Ageable.class.isAssignableFrom(entityClass)) {
|
||||||
|
options = getOptions(perm, entry.getValue());
|
||||||
|
}
|
||||||
|
} else if (disguiseType.equals("*")) {
|
||||||
|
options = getOptions(perm, entry.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
HashMap<ArrayList<String>, Boolean> map1 = getOptions(perm);
|
if (options != null) {
|
||||||
list.put(map1.keySet().iterator().next(), map1.values().iterator().next());
|
HashMap<ArrayList<String>, Boolean> list = rangeDisguises
|
||||||
} else {
|
.computeIfAbsent(type, k -> new HashMap<>());
|
||||||
for (DisguisePerm type : getDisguisePerms()) {
|
|
||||||
HashMap<ArrayList<String>, Boolean> options = null;
|
|
||||||
Class entityClass = type.getEntityClass();
|
|
||||||
|
|
||||||
if (disguiseType.equals("mob")) {
|
list.put(new ArrayList<>(options.getKey()), options.getValue());
|
||||||
if (type.isMob()) {
|
|
||||||
options = getOptions(perm);
|
|
||||||
}
|
|
||||||
} else if (disguiseType.equals("animal") || disguiseType.equals("animals")) {
|
|
||||||
if (Animals.class.isAssignableFrom(entityClass)) {
|
|
||||||
options = getOptions(perm);
|
|
||||||
}
|
|
||||||
} else if (disguiseType.equals("monster") || disguiseType.equals("monsters")) {
|
|
||||||
if (Monster.class.isAssignableFrom(entityClass)) {
|
|
||||||
options = getOptions(perm);
|
|
||||||
}
|
|
||||||
} else if (disguiseType.equals("misc")) {
|
|
||||||
if (type.isMisc()) {
|
|
||||||
options = getOptions(perm);
|
|
||||||
}
|
|
||||||
} else if (disguiseType.equals("ageable")) {
|
|
||||||
if (Ageable.class.isAssignableFrom(entityClass)) {
|
|
||||||
options = getOptions(perm);
|
|
||||||
}
|
|
||||||
} else if (disguiseType.equals("*")) {
|
|
||||||
options = getOptions(perm);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options != null) {
|
|
||||||
HashMap<ArrayList<String>, Boolean> list;
|
|
||||||
|
|
||||||
if (rangeDisguises.containsKey(type)) {
|
|
||||||
list = rangeDisguises.get(type);
|
|
||||||
} else {
|
|
||||||
list = new HashMap<>();
|
|
||||||
rangeDisguises.put(type, list);
|
|
||||||
}
|
|
||||||
|
|
||||||
HashMap<ArrayList<String>, Boolean> map1 = getOptions(perm);
|
|
||||||
|
|
||||||
list.put(map1.keySet().iterator().next(), map1.values().iterator().next());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find disguises to negate, only removes does not add
|
||||||
for (String perm : perms.keySet()) {
|
for (String perm : perms.keySet()) {
|
||||||
if (!perms.get(perm)) {
|
// If not negated, continue
|
||||||
perm = perm.substring(permissionNode.length());
|
if (perms.get(perm)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
String disguiseType = perm.split("\\.")[0];
|
perm = perm.substring(permissionNode.length());
|
||||||
DisguisePerm dType = DisguiseParser.getDisguisePerm(disguiseType);
|
|
||||||
|
|
||||||
if (dType != null) {
|
String[] split = perm.split("\\.");
|
||||||
singleDisguises.remove(dType);
|
|
||||||
rangeDisguises.remove(dType);
|
|
||||||
} else {
|
|
||||||
for (DisguisePerm type : getDisguisePerms()) {
|
|
||||||
boolean foundHim = false;
|
|
||||||
Class entityClass = type.getEntityClass();
|
|
||||||
|
|
||||||
switch (disguiseType) {
|
// Permission has parameters, which means the parameters were negated not the disguise
|
||||||
case "mob":
|
if (split.length > 1) {
|
||||||
if (type.isMob()) {
|
continue;
|
||||||
foundHim = true;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
String disguiseType = split[0];
|
||||||
case "animal":
|
|
||||||
case "animals":
|
|
||||||
if (Animals.class.isAssignableFrom(entityClass)) {
|
|
||||||
foundHim = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
DisguisePerm dType = DisguiseParser.getDisguisePerm(disguiseType);
|
||||||
case "monster":
|
|
||||||
case "monsters":
|
|
||||||
if (Monster.class.isAssignableFrom(entityClass)) {
|
|
||||||
foundHim = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
if (dType != null) {
|
||||||
case "misc":
|
singleDisguises.remove(dType);
|
||||||
if (type.isMisc()) {
|
rangeDisguises.remove(dType);
|
||||||
foundHim = true;
|
} else {
|
||||||
}
|
for (DisguisePerm type : getDisguisePerms()) {
|
||||||
|
boolean foundDisguiseType = false;
|
||||||
|
Class entityClass = type.getEntityClass();
|
||||||
|
|
||||||
break;
|
switch (disguiseType) {
|
||||||
case "ageable":
|
case "mob":
|
||||||
if (Ageable.class.isAssignableFrom(entityClass)) {
|
if (type.isMob()) {
|
||||||
foundHim = true;
|
foundDisguiseType = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "*":
|
case "animal":
|
||||||
foundHim = true;
|
case "animals":
|
||||||
break;
|
if (Animals.class.isAssignableFrom(entityClass)) {
|
||||||
}
|
foundDisguiseType = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (foundHim) {
|
break;
|
||||||
rangeDisguises.remove(type);
|
case "monster":
|
||||||
}
|
case "monsters":
|
||||||
|
if (Monster.class.isAssignableFrom(entityClass)) {
|
||||||
|
foundDisguiseType = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "misc":
|
||||||
|
if (type.isMisc()) {
|
||||||
|
foundDisguiseType = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "ageable":
|
||||||
|
if (Ageable.class.isAssignableFrom(entityClass)) {
|
||||||
|
foundDisguiseType = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "*":
|
||||||
|
foundDisguiseType = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (foundDisguiseType) {
|
||||||
|
rangeDisguises.remove(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,88 @@
|
|||||||
|
package me.libraryaddict.disguise.utilities.parser;
|
||||||
|
|
||||||
|
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||||
|
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by libraryaddict on 5/10/2018.
|
||||||
|
*/
|
||||||
|
public class DisguisePerm {
|
||||||
|
private DisguiseType disguiseType;
|
||||||
|
private String permName;
|
||||||
|
|
||||||
|
public DisguisePerm(DisguiseType disguiseType) {
|
||||||
|
this.disguiseType = disguiseType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DisguisePerm(DisguiseType disguiseType, String disguisePerm) {
|
||||||
|
this.disguiseType = disguiseType;
|
||||||
|
permName = disguisePerm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class getEntityClass() {
|
||||||
|
return getType().getEntityClass();
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityType getEntityType() {
|
||||||
|
return getType().getEntityType();
|
||||||
|
}
|
||||||
|
|
||||||
|
public DisguiseType getType() {
|
||||||
|
return disguiseType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class<? extends FlagWatcher> getWatcherClass() {
|
||||||
|
return getType().getWatcherClass();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMisc() {
|
||||||
|
return getType().isMisc();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMob() {
|
||||||
|
return getType().isMob();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPlayer() {
|
||||||
|
return getType().isPlayer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUnknown() {
|
||||||
|
return getType().isUnknown();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toReadable() {
|
||||||
|
return permName == null ? getType().toReadable() : permName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((disguiseType == null) ? 0 : disguiseType.hashCode());
|
||||||
|
result = prime * result + ((permName == null) ? 0 : permName.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!(obj instanceof DisguisePerm))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
DisguisePerm other = (DisguisePerm) obj;
|
||||||
|
|
||||||
|
if (disguiseType != other.disguiseType)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Objects.equals(permName, other.permName);
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,7 @@ import me.libraryaddict.disguise.disguisetypes.Disguise;
|
|||||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser.DisguisePerm;
|
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
||||||
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
||||||
import me.libraryaddict.disguise.utilities.parser.params.ParamInfoTypes;
|
import me.libraryaddict.disguise.utilities.parser.params.ParamInfoTypes;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
Loading…
Reference in New Issue
Block a user