Started implementing new structure.
This commit is contained in:
parent
cc38b286cb
commit
27c7fd16cc
29 changed files with 275 additions and 105 deletions
|
|
@ -2,7 +2,8 @@ Policies:
|
|||
# NO SPACES
|
||||
- name: "Block-illegal-items"
|
||||
type: global # global / location / permission / list of types
|
||||
allowList: false # Will deny anything that's not allowed by the nodes if set to true
|
||||
nodesAllowList: false # Will deny anything that's not allowed by the nodes if set to true
|
||||
policyAllowList: false # Inverts the policy validation logic, for example a location policy will affect all players NOT inside it's location
|
||||
nodes:
|
||||
- useItem:
|
||||
value:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package io.github.adrianvic.nemesiseye;
|
||||
|
||||
import io.github.adrianvic.nemesiseye.policy.Policy;
|
||||
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
||||
import io.github.adrianvic.nemesiseye.policy.policies.GlobalPolicy;
|
||||
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
||||
|
||||
import java.io.File;
|
||||
|
|
@ -11,7 +13,6 @@ public class Config {
|
|||
private static Config instance = new Config();
|
||||
private final Glimmer glim = Nemesis.getInstance().getGlimmer();
|
||||
private File file;
|
||||
|
||||
private List<Policy> policies = new ArrayList<>();
|
||||
|
||||
private Config() {}
|
||||
|
|
@ -19,6 +20,7 @@ public class Config {
|
|||
public void load() {
|
||||
policies = glim.loadPoliciesFromFile(glim.loadConfigFile());
|
||||
}
|
||||
|
||||
// TODO: Implement config saving
|
||||
//
|
||||
// public void save() {
|
||||
|
|
|
|||
|
|
@ -78,4 +78,15 @@ public class DataShifter {
|
|||
|
||||
return boxes;
|
||||
}
|
||||
|
||||
public static <T extends Enum<T>> T enumOrDefault(Class<T> type, String string, T def) {
|
||||
try {
|
||||
return Enum.valueOf(type, string);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return def;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return def;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package io.github.adrianvic.nemesiseye;
|
||||
|
||||
import io.github.adrianvic.nemesiseye.policy.Action;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
|
|
@ -8,18 +9,18 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
|||
|
||||
public class Events {
|
||||
public static void onBlockBreak(BlockBreakEvent event) {
|
||||
event.setCancelled(!Validator.canBreak(event.getPlayer()));
|
||||
event.setCancelled(!Validator.can(event.getPlayer(), Action.BREAK));
|
||||
}
|
||||
|
||||
public static void onInteractionEvent(PlayerInteractEvent event) {
|
||||
if (event.getItem() != null) {
|
||||
event.setCancelled(!Validator.canInteract(event.getPlayer()));
|
||||
event.setCancelled(!Validator.can(event.getPlayer(), Action.INTERACT));
|
||||
}
|
||||
}
|
||||
|
||||
public static void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
|
||||
if (event.getDamager() instanceof Player) {
|
||||
event.setCancelled(!Validator.canHit((HumanEntity) event.getDamager()));
|
||||
event.setCancelled(!Validator.can((HumanEntity) event.getDamager(), Action.HIT));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,4 +61,4 @@ public final class Nemesis extends JavaPlugin {
|
|||
public static Nemesis getInstance() { return instance; }
|
||||
public Glimmer getGlimmer() { return glim; }
|
||||
public PluginManager getPluginManager() { return this.getServer().getPluginManager(); }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package io.github.adrianvic.nemesiseye;
|
||||
|
||||
import io.github.adrianvic.nemesiseye.policy.Action;
|
||||
import io.github.adrianvic.nemesiseye.policy.NodeHandler;
|
||||
import io.github.adrianvic.nemesiseye.policy.Policy;
|
||||
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
||||
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
||||
|
|
@ -12,15 +13,8 @@ import java.util.List;
|
|||
public class Validator {
|
||||
private final static Glimmer glim = Nemesis.getInstance().getGlimmer();
|
||||
|
||||
public static boolean canInteract(HumanEntity entity) {
|
||||
return checkAgainstEntity(entity, Action.INTERACT);
|
||||
}
|
||||
public static boolean canBreak(HumanEntity entity) {
|
||||
return checkAgainstEntity(entity, Action.BREAK);
|
||||
}
|
||||
|
||||
public static boolean canHit(HumanEntity entity) {
|
||||
return checkAgainstEntity(entity, Action.HIT);
|
||||
public static boolean can(HumanEntity entity, Action action) {
|
||||
return checkAgainstEntity(entity, action);
|
||||
}
|
||||
|
||||
public static boolean checkAgainstEntity(HumanEntity entity, Action action) {
|
||||
|
|
@ -35,7 +29,12 @@ public class Validator {
|
|||
}
|
||||
|
||||
public static boolean checkAgainstNode(HumanEntity entity, PolicyNode node, Action action) {
|
||||
return node.getHandler().allows(entity, node, action);
|
||||
for (NodeHandler handler : node.getHandler()) {
|
||||
if (!handler.allows(entity, node, action)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static List<PolicyNode> getNodesForPolicies(List<Policy> policies) {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class PolicyInfo implements Subcommand {
|
|||
Type: %s
|
||||
Nodes: %s
|
||||
%s
|
||||
""", ChatColor.GREEN, policy.name(), ChatColor.WHITE, "location", policy.nodes().size(), policy.allowlist() ? "Is allowlist" : "Is blacklist"));
|
||||
""", ChatColor.GREEN, policy.name(), ChatColor.WHITE, policy.getClass().getTypeName(), policy.nodes().size(), policy.nodeAllowlist() ? "Is allowlist" : "Is blacklist"));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -5,5 +5,6 @@ public enum Action {
|
|||
BREAK,
|
||||
HIT,
|
||||
CRAFT,
|
||||
EQUIP
|
||||
EQUIP,
|
||||
USE_ENCHANTMENT
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
package io.github.adrianvic.nemesiseye.policy;
|
||||
|
||||
public enum Effect {
|
||||
DENY,
|
||||
ALLOW,
|
||||
ALLOWONLY
|
||||
}
|
||||
|
|
@ -3,5 +3,11 @@ package io.github.adrianvic.nemesiseye.policy;
|
|||
import org.bukkit.entity.HumanEntity;
|
||||
|
||||
public interface NodeHandler {
|
||||
boolean allows(HumanEntity entity, PolicyNode node, Action action);
|
||||
boolean check(HumanEntity entity, PolicyNode node, Action action);
|
||||
|
||||
default boolean allows(HumanEntity entity, PolicyNode node, Action action) {
|
||||
boolean isWhitelist = (node.effect() == Effect.ALLOWONLY);
|
||||
return check(entity, node, action) ? !isWhitelist : isWhitelist;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -8,15 +8,15 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
public class NodeHandlers {
|
||||
private static final Map<String, NodeHandler> handlers = new HashMap<>();
|
||||
private static final Map<Action, NodeHandler> handlers = new HashMap<>();
|
||||
|
||||
static {
|
||||
handlers.put("attackWithItemInHand", new attackWith());
|
||||
handlers.put("useItem", new useItem());
|
||||
handlers.put("useEnchantment", new useEnchantment());
|
||||
handlers.put(Action.HIT, new attackWith());
|
||||
handlers.put(Action.INTERACT, new useItem());
|
||||
handlers.put(Action.USE_ENCHANTMENT, new useEnchantment());
|
||||
}
|
||||
|
||||
public static NodeHandler get(String type) {
|
||||
public static NodeHandler get(Action type) {
|
||||
return handlers.get(type);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,12 @@ import java.util.List;
|
|||
public interface Policy {
|
||||
String name();
|
||||
List<PolicyNode> nodes();
|
||||
boolean allowlist();
|
||||
boolean nodeAllowlist();
|
||||
boolean policyAllowList();
|
||||
boolean applies(HumanEntity entity);
|
||||
|
||||
Effect effect();
|
||||
int weight();
|
||||
default void addNode(PolicyNode node) {
|
||||
nodes().add(node);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,36 +1,62 @@
|
|||
package io.github.adrianvic.nemesiseye.policy;
|
||||
|
||||
import io.github.adrianvic.nemesiseye.Config;
|
||||
import io.github.adrianvic.nemesiseye.DataShifter;
|
||||
import org.apache.logging.log4j.status.StatusLogger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public record PolicyNode(String type, List<Object> values, boolean isWhitelist) {
|
||||
public static List<PolicyNode> parseNodes(List<Map<String,Object>> raw, boolean isWhitelist) {
|
||||
public record PolicyNode(List<Action> actions, List<Object> values, Effect effect) {
|
||||
public static List<PolicyNode> parseNodes(List<Map<Object,Object>> raw, Effect effect) {
|
||||
List<PolicyNode> nodes = new ArrayList<>();
|
||||
|
||||
for (Map<String, Object> m : raw) {
|
||||
for (Map.Entry<String, Object> entry : m.entrySet()) {
|
||||
String type = entry.getKey();
|
||||
List<Object> values = new ArrayList<>();
|
||||
Object val = entry.getValue();
|
||||
for (Map<Object, Object> m : raw) {
|
||||
for (Map.Entry<Object, Object> rawNode : m.entrySet()) {
|
||||
List<Action> nodeActions = new ArrayList<>();
|
||||
List<Object> nodeValues = new ArrayList<>();
|
||||
Effect nodeEffect = effect;
|
||||
|
||||
if (val instanceof Map<?,?> valMap) {
|
||||
if (valMap.get("values") instanceof String s) {
|
||||
values.add(s);
|
||||
} else if (valMap.get("values") instanceof List<?> l) {
|
||||
values.addAll(l);
|
||||
} else if (valMap.get("values") instanceof Map<?,?> map) {
|
||||
values.add(map);
|
||||
if (rawNode.getKey() instanceof List<?> rawTypes && rawNode.getValue() instanceof Map<?,?> rawNodeValues) {
|
||||
for (Object rawType : rawTypes) {
|
||||
if (rawType instanceof String rts && !rts.isEmpty() && !(rts == null) && DataShifter.enumOrDefault(Action.class, rts, null) != null) {
|
||||
nodeActions.add(DataShifter.enumOrDefault(Action.class, rts, null));
|
||||
}
|
||||
}
|
||||
Map<String, Object> semiParsedNodeValue = new HashMap<>();
|
||||
for (Map.Entry<?,?> rawNodeValueEntries : rawNodeValues.entrySet()) {
|
||||
if (rawNodeValueEntries.getKey() instanceof String stringKey) {
|
||||
semiParsedNodeValue.put(stringKey, rawNodeValueEntries.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
nodes.add(new PolicyNode(type, values, isWhitelist));
|
||||
if (semiParsedNodeValue.get("values") instanceof List<?> l) {
|
||||
for (Object v : l) {
|
||||
nodeValues.add(v);
|
||||
}
|
||||
}
|
||||
|
||||
if (semiParsedNodeValue.get("effect") instanceof String efc) {
|
||||
Effect type = DataShifter.enumOrDefault(Effect.class, efc, null);
|
||||
if (type != null) {
|
||||
nodeEffect = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nodes.add(new PolicyNode(nodeActions, nodeValues, nodeEffect));
|
||||
}
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
public NodeHandler getHandler() {
|
||||
return NodeHandlers.get(type);
|
||||
public List<NodeHandler> getHandler() {
|
||||
List<NodeHandler> handlers = new ArrayList<>();
|
||||
for (Action a : actions) {
|
||||
handlers.add(NodeHandlers.get(a));
|
||||
}
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,34 @@
|
|||
package io.github.adrianvic.nemesiseye.policy;
|
||||
|
||||
import io.github.adrianvic.nemesiseye.DataShifter;
|
||||
import io.github.adrianvic.nemesiseye.policy.policies.Core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface PolicyParser {
|
||||
Policy parse(Map<?, ?> raw);
|
||||
default Policy parse(Map<?, ?> raw) {
|
||||
boolean policyAllowList = Boolean.TRUE.equals(raw.get("policyAllowList"));
|
||||
boolean nodesAllowList = Boolean.TRUE.equals(raw.get("nodesAllowList"));
|
||||
Effect effect = DataShifter.enumOrDefault(Effect.class, (String) raw.get("effect"), Effect.DENY);
|
||||
String name = (String) raw.get("name");
|
||||
int weight = (int) raw.get("weight");
|
||||
|
||||
// Nodes
|
||||
Object rawNodes = raw.get("nodes");
|
||||
List<Map<Object, Object>> nodeList = new ArrayList<>();
|
||||
|
||||
if (rawNodes instanceof List<?> list) {
|
||||
for (Object o : list) {
|
||||
if (o instanceof Map<?, ?> map)
|
||||
nodeList.add((Map<Object, Object>) map);
|
||||
}
|
||||
}
|
||||
|
||||
List<PolicyNode> nodes = PolicyNode.parseNodes(nodeList, effect);
|
||||
return parse(new Core(name, nodes, nodesAllowList, policyAllowList, effect, weight), raw);
|
||||
}
|
||||
|
||||
Policy parse(Core corePolicy, Map<?, ?> raw);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package io.github.adrianvic.nemesiseye.policy;
|
|||
|
||||
import io.github.adrianvic.nemesiseye.policy.parser.GlobalPolicyParser;
|
||||
import io.github.adrianvic.nemesiseye.policy.parser.LocationPolicyParser;
|
||||
import io.github.adrianvic.nemesiseye.policy.parser.PermissionPolicyParser;
|
||||
import io.github.adrianvic.nemesiseye.policy.parser.PlayerNamePolicyParser;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
@ -12,6 +14,8 @@ public class PolicyParsers {
|
|||
static {
|
||||
handlers.put("location", new LocationPolicyParser());
|
||||
handlers.put("global", new GlobalPolicyParser());
|
||||
handlers.put("playerName", new PlayerNamePolicyParser());
|
||||
handlers.put("permission", new PermissionPolicyParser());
|
||||
}
|
||||
|
||||
public static PolicyParser get(String type) {
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@ public class attackWith implements NodeHandler {
|
|||
private final static Glimmer glim = Nemesis.getInstance().getGlimmer();
|
||||
|
||||
@Override
|
||||
public boolean allows(HumanEntity entity, PolicyNode node, Action action) {
|
||||
public boolean check(HumanEntity entity, PolicyNode node, Action action) {
|
||||
if (action == Action.HIT) {
|
||||
for (String s : DataShifter.parseValueToStringList(node.values())) {
|
||||
boolean matches = DataShifter.safeMatches(s, glim.getItemInMainHandHumanEntity(entity).getType().toString());
|
||||
if (matches) return node.isWhitelist();
|
||||
if (matches) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public class useEnchantment implements NodeHandler {
|
|||
private final Glimmer glim = Nemesis.getInstance().getGlimmer();
|
||||
|
||||
@Override
|
||||
public boolean allows(HumanEntity entity, PolicyNode node, Action action) {
|
||||
public boolean check(HumanEntity entity, PolicyNode node, Action action) {
|
||||
ItemStack item = glim.getItemInMainHandHumanEntity(entity);
|
||||
|
||||
if (!glim.hasItemMeta(item)) return true;
|
||||
|
|
@ -22,6 +22,6 @@ public class useEnchantment implements NodeHandler {
|
|||
boolean matches = glim.hasEnchantment(item,
|
||||
DataShifter.parseValueToStringMap(node.values()));
|
||||
|
||||
return matches ? node.isWhitelist() : !node.isWhitelist();
|
||||
return matches;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,13 +13,13 @@ public class useItem implements NodeHandler {
|
|||
private final Glimmer glim = Nemesis.getInstance().getGlimmer();
|
||||
|
||||
@Override
|
||||
public boolean allows(HumanEntity entity, PolicyNode node, Action action) {
|
||||
public boolean check(HumanEntity entity, PolicyNode node, Action action) {
|
||||
String type = glim.getItemInMainHandHumanEntity(entity).getType().toString();
|
||||
|
||||
for (String s : DataShifter.parseValueToStringList(node.values())) {
|
||||
boolean matches = DataShifter.safeMatches(s, type);
|
||||
if (matches) return node.isWhitelist();
|
||||
if (matches) return false;
|
||||
}
|
||||
return !node.isWhitelist();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +1,15 @@
|
|||
package io.github.adrianvic.nemesiseye.policy.parser;
|
||||
|
||||
import io.github.adrianvic.nemesiseye.policy.Policy;
|
||||
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
||||
import io.github.adrianvic.nemesiseye.policy.PolicyParser;
|
||||
import io.github.adrianvic.nemesiseye.policy.policies.Core;
|
||||
import io.github.adrianvic.nemesiseye.policy.policies.GlobalPolicy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class GlobalPolicyParser implements PolicyParser {
|
||||
@Override
|
||||
public Policy parse(Map<?, ?> raw) {
|
||||
boolean allowlist = (boolean) raw.get("allowList");
|
||||
String name = (String) raw.get("name");
|
||||
|
||||
// Nodes
|
||||
Object rawNodes = raw.get("nodes");
|
||||
List<Map<String, Object>> nodeList = new ArrayList<>();
|
||||
if (rawNodes instanceof List<?> list) {
|
||||
for (Object o : list) {
|
||||
if (o instanceof Map<?, ?> map)
|
||||
nodeList.add((Map<String, Object>) map);
|
||||
}
|
||||
}
|
||||
|
||||
List<PolicyNode> nodes = PolicyNode.parseNodes(nodeList, allowlist);
|
||||
|
||||
return new GlobalPolicy(name, nodes, allowlist);
|
||||
public Policy parse(Core corePolicy, Map<?, ?> raw) {
|
||||
return new GlobalPolicy(corePolicy.name(), corePolicy.nodes(), corePolicy.nodeAllowlist(), corePolicy.policyAllowList(), corePolicy.effect(), corePolicy.weight());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package io.github.adrianvic.nemesiseye.policy.parser;
|
|||
import io.github.adrianvic.nemesiseye.DataShifter;
|
||||
import io.github.adrianvic.nemesiseye.Nemesis;
|
||||
import io.github.adrianvic.nemesiseye.policy.*;
|
||||
import io.github.adrianvic.nemesiseye.policy.policies.Core;
|
||||
import io.github.adrianvic.nemesiseye.policy.policies.LocationPolicy;
|
||||
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
||||
|
||||
|
|
@ -13,24 +14,8 @@ import java.util.Map;
|
|||
public class LocationPolicyParser implements PolicyParser {
|
||||
private Glimmer glim = Nemesis.getInstance().getGlimmer();
|
||||
|
||||
public Policy parse(Map<?, ?> raw) {
|
||||
String name = (String) raw.get("name");
|
||||
boolean allowlist = Boolean.TRUE.equals(raw.get("allowList"));
|
||||
|
||||
// Nodes
|
||||
Object rawNodes = raw.get("nodes");
|
||||
List<Map<String, Object>> nodeList = new ArrayList<>();
|
||||
if (rawNodes instanceof List<?> list) {
|
||||
for (Object o : list) {
|
||||
if (o instanceof Map<?, ?> map)
|
||||
nodeList.add((Map<String, Object>) map);
|
||||
}
|
||||
}
|
||||
|
||||
List<PolicyNode> nodes = PolicyNode.parseNodes(nodeList, allowlist);
|
||||
|
||||
List<Glimmer.Box> locations = DataShifter.configLocationParser(raw.get("locations"));
|
||||
|
||||
return new LocationPolicy(name, locations, nodes, allowlist);
|
||||
public Policy parse(Core corePolicy, Map<?, ?> raw) {
|
||||
List<Glimmer.Box> locations = DataShifter.configLocationParser(raw.get("locations"));
|
||||
return new LocationPolicy(corePolicy.name(), locations, corePolicy.nodes(), corePolicy.nodeAllowlist(), corePolicy.policyAllowList(), corePolicy.effect(), corePolicy.weight());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
package io.github.adrianvic.nemesiseye.policy.parser;
|
||||
|
||||
import io.github.adrianvic.nemesiseye.policy.Policy;
|
||||
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
||||
import io.github.adrianvic.nemesiseye.policy.PolicyParser;
|
||||
import io.github.adrianvic.nemesiseye.policy.policies.Core;
|
||||
import io.github.adrianvic.nemesiseye.policy.policies.PermissionPolicy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PermissionPolicyParser implements PolicyParser {
|
||||
@Override
|
||||
public Policy parse(Core corePolicy, Map<?, ?> raw) {
|
||||
Object rawPerms = raw.get("permissions");
|
||||
List<String> permissions = new ArrayList<>();
|
||||
|
||||
if (rawPerms instanceof List<?> list) {
|
||||
for (Object o : list) {
|
||||
if (o instanceof String s) {
|
||||
permissions.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new PermissionPolicy(corePolicy.name(), permissions, corePolicy.nodes(), corePolicy.nodeAllowlist(), corePolicy.policyAllowList(), corePolicy.effect(), corePolicy.weight());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package io.github.adrianvic.nemesiseye.policy.parser;
|
||||
|
||||
import io.github.adrianvic.nemesiseye.policy.Policy;
|
||||
import io.github.adrianvic.nemesiseye.policy.PolicyParser;
|
||||
import io.github.adrianvic.nemesiseye.policy.policies.Core;
|
||||
import io.github.adrianvic.nemesiseye.policy.policies.PlayerNamePolicy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PlayerNamePolicyParser implements PolicyParser {
|
||||
@Override
|
||||
public Policy parse(Core corePolicy, Map<?, ?> raw) {
|
||||
Object rawNames = raw.get("names");
|
||||
List<String> names = new ArrayList<>();
|
||||
|
||||
if (rawNames instanceof List<?> list) {
|
||||
for (Object o : list) {
|
||||
if (o instanceof String s) {
|
||||
names.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new PlayerNamePolicy(corePolicy.name(), names, corePolicy.nodes(), corePolicy.nodeAllowlist(), corePolicy.effect(), corePolicy.policyAllowList(), corePolicy.weight());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package io.github.adrianvic.nemesiseye.policy.policies;
|
||||
|
||||
import io.github.adrianvic.nemesiseye.policy.Effect;
|
||||
import io.github.adrianvic.nemesiseye.policy.Policy;
|
||||
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record Core(String name, List<PolicyNode> nodes, boolean nodeAllowlist, boolean policyAllowList, Effect effect, int weight) implements Policy {
|
||||
@Override
|
||||
public boolean applies(HumanEntity entity) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,13 @@
|
|||
package io.github.adrianvic.nemesiseye.policy.policies;
|
||||
|
||||
import io.github.adrianvic.nemesiseye.policy.Effect;
|
||||
import io.github.adrianvic.nemesiseye.policy.Policy;
|
||||
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record GlobalPolicy(String name, List<PolicyNode> nodes, boolean allowlist) implements Policy {
|
||||
public record GlobalPolicy(String name, List<PolicyNode> nodes, boolean nodeAllowlist, boolean policyAllowList, Effect effect, int weight) implements Policy {
|
||||
public boolean applies(HumanEntity entity) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package io.github.adrianvic.nemesiseye.policy.policies;
|
||||
|
||||
import io.github.adrianvic.nemesiseye.policy.Effect;
|
||||
import io.github.adrianvic.nemesiseye.policy.Policy;
|
||||
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
||||
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
||||
|
|
@ -7,12 +8,12 @@ import org.bukkit.entity.HumanEntity;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
public record LocationPolicy(String name, List<Glimmer.Box> locations, List<PolicyNode> nodes, boolean allowlist) implements Policy {
|
||||
public record LocationPolicy(String name, List<Glimmer.Box> locations, List<PolicyNode> nodes, boolean nodeAllowlist, boolean policyAllowList, Effect effect, int weight) implements Policy {
|
||||
@Override
|
||||
public boolean applies(HumanEntity entity) {
|
||||
for (Glimmer.Box box : locations) {
|
||||
if (box.contains(entity.getLocation().toVector())) return true;
|
||||
if (box.contains(entity.getLocation().toVector())) return !policyAllowList;
|
||||
}
|
||||
return false;
|
||||
return policyAllowList;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,19 @@
|
|||
package io.github.adrianvic.nemesiseye.policy.policies;
|
||||
|
||||
import io.github.adrianvic.nemesiseye.policy.Effect;
|
||||
import io.github.adrianvic.nemesiseye.policy.Policy;
|
||||
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public record PermissionPolicy(String name, ArrayList<Permission> permissions, PolicyNode nodes, boolean allowlist) {}
|
||||
public record PermissionPolicy(String name, List<String> permissions, List<PolicyNode> nodes, boolean nodeAllowlist, boolean policyAllowList, Effect effect, int weight) implements Policy {
|
||||
|
||||
@Override
|
||||
public boolean applies(HumanEntity entity) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,20 @@
|
|||
package io.github.adrianvic.nemesiseye.policy.policies;
|
||||
|
||||
import io.github.adrianvic.nemesiseye.policy.Effect;
|
||||
import io.github.adrianvic.nemesiseye.policy.Policy;
|
||||
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public record PlayerNamePolicy(String name, ArrayList<String> playerName, PolicyNode nodes, boolean allowlist) {}
|
||||
public record PlayerNamePolicy(String name, List<String> playerName, List<PolicyNode> nodes, boolean nodeAllowlist, Effect effect, boolean policyAllowList, int weight) implements Policy {
|
||||
|
||||
@Override
|
||||
public boolean applies(HumanEntity entity) {
|
||||
if (playerName.contains(entity.getName())) {
|
||||
return !policyAllowList();
|
||||
} else {
|
||||
return policyAllowList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -47,6 +47,7 @@ public class r1_21 implements Glimmer {
|
|||
|
||||
for (Map<?, ?> policyMap : rawPolicies) {
|
||||
if (policyMap.get("type") != null && policyMap.get("type") instanceof String type) {
|
||||
System.out.println(type);
|
||||
allPolicies.add(PolicyParsers.get(type).parse(policyMap));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,26 @@
|
|||
Policies:
|
||||
# NO SPACES
|
||||
- name: "Beta-1.7.3-items-only"
|
||||
type: "location"
|
||||
allowList: true # Will deny anything that's not allowed by the nodes if set to true
|
||||
- name: "Bedrock-only-admins"
|
||||
type: "permission"
|
||||
effect: ALLOW
|
||||
weight: 1
|
||||
policyAllowList: true
|
||||
permissions:
|
||||
- "server.usebedrock"
|
||||
nodes:
|
||||
- [INTERACT]:
|
||||
values:
|
||||
- BEDROCK
|
||||
|
||||
- name: "Beta-1.7.3-items-only" # No spaces here or else commands which need the name as argument will not work
|
||||
type: "location" # global | location | permission | playerName
|
||||
effect: ALLOWONLY # DENY | ALLOW (overrides deny) | ALLOWONLY (allow only if met)
|
||||
weight: 0 # Greater weight overrides lower
|
||||
policyAllowList: false # Inverts the policy validation logic, for example a location policy will affect all players NOT inside it's location
|
||||
locations:
|
||||
- corner1: { x: 2100, y: 256, z: 1400 }
|
||||
corner2: { x: 1000, y: -64, z: 2200 }
|
||||
nodes:
|
||||
- useItem:
|
||||
- [INTERACT]:
|
||||
values:
|
||||
- AIR
|
||||
- STONE
|
||||
|
|
@ -106,7 +119,7 @@ Policies:
|
|||
- FISHING_ROD
|
||||
- CLOCK
|
||||
- GLOWSTONE_DUST
|
||||
- INK_SACw
|
||||
- INK_SAC
|
||||
- BONE_MEAL
|
||||
- SUGAR
|
||||
- COOKIE
|
||||
|
|
@ -117,5 +130,5 @@ Policies:
|
|||
- MUSIC_DISK_13
|
||||
- DIRT
|
||||
- BREAD
|
||||
- useEnchantment:
|
||||
- [USE_ENCHANTMENT]:
|
||||
"flying bananas": "0"
|
||||
Loading…
Add table
Add a link
Reference in a new issue