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
|
# NO SPACES
|
||||||
- name: "Block-illegal-items"
|
- name: "Block-illegal-items"
|
||||||
type: global # global / location / permission / list of types
|
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:
|
nodes:
|
||||||
- useItem:
|
- useItem:
|
||||||
value:
|
value:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package io.github.adrianvic.nemesiseye;
|
package io.github.adrianvic.nemesiseye;
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.policy.Policy;
|
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 io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
@ -11,7 +13,6 @@ public class Config {
|
||||||
private static Config instance = new Config();
|
private static Config instance = new Config();
|
||||||
private final Glimmer glim = Nemesis.getInstance().getGlimmer();
|
private final Glimmer glim = Nemesis.getInstance().getGlimmer();
|
||||||
private File file;
|
private File file;
|
||||||
|
|
||||||
private List<Policy> policies = new ArrayList<>();
|
private List<Policy> policies = new ArrayList<>();
|
||||||
|
|
||||||
private Config() {}
|
private Config() {}
|
||||||
|
|
@ -19,6 +20,7 @@ public class Config {
|
||||||
public void load() {
|
public void load() {
|
||||||
policies = glim.loadPoliciesFromFile(glim.loadConfigFile());
|
policies = glim.loadPoliciesFromFile(glim.loadConfigFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement config saving
|
// TODO: Implement config saving
|
||||||
//
|
//
|
||||||
// public void save() {
|
// public void save() {
|
||||||
|
|
|
||||||
|
|
@ -78,4 +78,15 @@ public class DataShifter {
|
||||||
|
|
||||||
return boxes;
|
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;
|
package io.github.adrianvic.nemesiseye;
|
||||||
|
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.Action;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
|
@ -8,18 +9,18 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
public class Events {
|
public class Events {
|
||||||
public static void onBlockBreak(BlockBreakEvent event) {
|
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) {
|
public static void onInteractionEvent(PlayerInteractEvent event) {
|
||||||
if (event.getItem() != null) {
|
if (event.getItem() != null) {
|
||||||
event.setCancelled(!Validator.canInteract(event.getPlayer()));
|
event.setCancelled(!Validator.can(event.getPlayer(), Action.INTERACT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
|
public static void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
|
||||||
if (event.getDamager() instanceof Player) {
|
if (event.getDamager() instanceof Player) {
|
||||||
event.setCancelled(!Validator.canHit((HumanEntity) event.getDamager()));
|
event.setCancelled(!Validator.can((HumanEntity) event.getDamager(), Action.HIT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package io.github.adrianvic.nemesiseye;
|
package io.github.adrianvic.nemesiseye;
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.policy.Action;
|
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.Policy;
|
||||||
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
||||||
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
||||||
|
|
@ -12,15 +13,8 @@ import java.util.List;
|
||||||
public class Validator {
|
public class Validator {
|
||||||
private final static Glimmer glim = Nemesis.getInstance().getGlimmer();
|
private final static Glimmer glim = Nemesis.getInstance().getGlimmer();
|
||||||
|
|
||||||
public static boolean canInteract(HumanEntity entity) {
|
public static boolean can(HumanEntity entity, Action action) {
|
||||||
return checkAgainstEntity(entity, Action.INTERACT);
|
return checkAgainstEntity(entity, action);
|
||||||
}
|
|
||||||
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 checkAgainstEntity(HumanEntity entity, Action 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) {
|
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) {
|
public static List<PolicyNode> getNodesForPolicies(List<Policy> policies) {
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ public class PolicyInfo implements Subcommand {
|
||||||
Type: %s
|
Type: %s
|
||||||
Nodes: %s
|
Nodes: %s
|
||||||
%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;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,6 @@ public enum Action {
|
||||||
BREAK,
|
BREAK,
|
||||||
HIT,
|
HIT,
|
||||||
CRAFT,
|
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;
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
|
||||||
public interface NodeHandler {
|
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;
|
import java.util.Map;
|
||||||
|
|
||||||
public class NodeHandlers {
|
public class NodeHandlers {
|
||||||
private static final Map<String, NodeHandler> handlers = new HashMap<>();
|
private static final Map<Action, NodeHandler> handlers = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
handlers.put("attackWithItemInHand", new attackWith());
|
handlers.put(Action.HIT, new attackWith());
|
||||||
handlers.put("useItem", new useItem());
|
handlers.put(Action.INTERACT, new useItem());
|
||||||
handlers.put("useEnchantment", new useEnchantment());
|
handlers.put(Action.USE_ENCHANTMENT, new useEnchantment());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NodeHandler get(String type) {
|
public static NodeHandler get(Action type) {
|
||||||
return handlers.get(type);
|
return handlers.get(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,12 @@ import java.util.List;
|
||||||
public interface Policy {
|
public interface Policy {
|
||||||
String name();
|
String name();
|
||||||
List<PolicyNode> nodes();
|
List<PolicyNode> nodes();
|
||||||
boolean allowlist();
|
boolean nodeAllowlist();
|
||||||
|
boolean policyAllowList();
|
||||||
boolean applies(HumanEntity entity);
|
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;
|
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.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public record PolicyNode(String type, List<Object> values, boolean isWhitelist) {
|
public record PolicyNode(List<Action> actions, List<Object> values, Effect effect) {
|
||||||
public static List<PolicyNode> parseNodes(List<Map<String,Object>> raw, boolean isWhitelist) {
|
public static List<PolicyNode> parseNodes(List<Map<Object,Object>> raw, Effect effect) {
|
||||||
List<PolicyNode> nodes = new ArrayList<>();
|
List<PolicyNode> nodes = new ArrayList<>();
|
||||||
|
|
||||||
for (Map<String, Object> m : raw) {
|
for (Map<Object, Object> m : raw) {
|
||||||
for (Map.Entry<String, Object> entry : m.entrySet()) {
|
for (Map.Entry<Object, Object> rawNode : m.entrySet()) {
|
||||||
String type = entry.getKey();
|
List<Action> nodeActions = new ArrayList<>();
|
||||||
List<Object> values = new ArrayList<>();
|
List<Object> nodeValues = new ArrayList<>();
|
||||||
Object val = entry.getValue();
|
Effect nodeEffect = effect;
|
||||||
|
|
||||||
if (val instanceof Map<?,?> valMap) {
|
if (rawNode.getKey() instanceof List<?> rawTypes && rawNode.getValue() instanceof Map<?,?> rawNodeValues) {
|
||||||
if (valMap.get("values") instanceof String s) {
|
for (Object rawType : rawTypes) {
|
||||||
values.add(s);
|
if (rawType instanceof String rts && !rts.isEmpty() && !(rts == null) && DataShifter.enumOrDefault(Action.class, rts, null) != null) {
|
||||||
} else if (valMap.get("values") instanceof List<?> l) {
|
nodeActions.add(DataShifter.enumOrDefault(Action.class, rts, null));
|
||||||
values.addAll(l);
|
}
|
||||||
} else if (valMap.get("values") instanceof Map<?,?> map) {
|
}
|
||||||
values.add(map);
|
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;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NodeHandler getHandler() {
|
public List<NodeHandler> getHandler() {
|
||||||
return NodeHandlers.get(type);
|
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;
|
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;
|
import java.util.Map;
|
||||||
|
|
||||||
public interface PolicyParser {
|
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.GlobalPolicyParser;
|
||||||
import io.github.adrianvic.nemesiseye.policy.parser.LocationPolicyParser;
|
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.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -12,6 +14,8 @@ public class PolicyParsers {
|
||||||
static {
|
static {
|
||||||
handlers.put("location", new LocationPolicyParser());
|
handlers.put("location", new LocationPolicyParser());
|
||||||
handlers.put("global", new GlobalPolicyParser());
|
handlers.put("global", new GlobalPolicyParser());
|
||||||
|
handlers.put("playerName", new PlayerNamePolicyParser());
|
||||||
|
handlers.put("permission", new PermissionPolicyParser());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PolicyParser get(String type) {
|
public static PolicyParser get(String type) {
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,11 @@ public class attackWith implements NodeHandler {
|
||||||
private final static Glimmer glim = Nemesis.getInstance().getGlimmer();
|
private final static Glimmer glim = Nemesis.getInstance().getGlimmer();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean allows(HumanEntity entity, PolicyNode node, Action action) {
|
public boolean check(HumanEntity entity, PolicyNode node, Action action) {
|
||||||
if (action == Action.HIT) {
|
if (action == Action.HIT) {
|
||||||
for (String s : DataShifter.parseValueToStringList(node.values())) {
|
for (String s : DataShifter.parseValueToStringList(node.values())) {
|
||||||
boolean matches = DataShifter.safeMatches(s, glim.getItemInMainHandHumanEntity(entity).getType().toString());
|
boolean matches = DataShifter.safeMatches(s, glim.getItemInMainHandHumanEntity(entity).getType().toString());
|
||||||
if (matches) return node.isWhitelist();
|
if (matches) return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ public class useEnchantment implements NodeHandler {
|
||||||
private final Glimmer glim = Nemesis.getInstance().getGlimmer();
|
private final Glimmer glim = Nemesis.getInstance().getGlimmer();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean allows(HumanEntity entity, PolicyNode node, Action action) {
|
public boolean check(HumanEntity entity, PolicyNode node, Action action) {
|
||||||
ItemStack item = glim.getItemInMainHandHumanEntity(entity);
|
ItemStack item = glim.getItemInMainHandHumanEntity(entity);
|
||||||
|
|
||||||
if (!glim.hasItemMeta(item)) return true;
|
if (!glim.hasItemMeta(item)) return true;
|
||||||
|
|
@ -22,6 +22,6 @@ public class useEnchantment implements NodeHandler {
|
||||||
boolean matches = glim.hasEnchantment(item,
|
boolean matches = glim.hasEnchantment(item,
|
||||||
DataShifter.parseValueToStringMap(node.values()));
|
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();
|
private final Glimmer glim = Nemesis.getInstance().getGlimmer();
|
||||||
|
|
||||||
@Override
|
@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();
|
String type = glim.getItemInMainHandHumanEntity(entity).getType().toString();
|
||||||
|
|
||||||
for (String s : DataShifter.parseValueToStringList(node.values())) {
|
for (String s : DataShifter.parseValueToStringList(node.values())) {
|
||||||
boolean matches = DataShifter.safeMatches(s, type);
|
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;
|
package io.github.adrianvic.nemesiseye.policy.parser;
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.policy.Policy;
|
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.PolicyParser;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.policies.Core;
|
||||||
import io.github.adrianvic.nemesiseye.policy.policies.GlobalPolicy;
|
import io.github.adrianvic.nemesiseye.policy.policies.GlobalPolicy;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class GlobalPolicyParser implements PolicyParser {
|
public class GlobalPolicyParser implements PolicyParser {
|
||||||
@Override
|
@Override
|
||||||
public Policy parse(Map<?, ?> raw) {
|
public Policy parse(Core corePolicy, Map<?, ?> raw) {
|
||||||
boolean allowlist = (boolean) raw.get("allowList");
|
return new GlobalPolicy(corePolicy.name(), corePolicy.nodes(), corePolicy.nodeAllowlist(), corePolicy.policyAllowList(), corePolicy.effect(), corePolicy.weight());
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package io.github.adrianvic.nemesiseye.policy.parser;
|
||||||
import io.github.adrianvic.nemesiseye.DataShifter;
|
import io.github.adrianvic.nemesiseye.DataShifter;
|
||||||
import io.github.adrianvic.nemesiseye.Nemesis;
|
import io.github.adrianvic.nemesiseye.Nemesis;
|
||||||
import io.github.adrianvic.nemesiseye.policy.*;
|
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.policy.policies.LocationPolicy;
|
||||||
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
||||||
|
|
||||||
|
|
@ -13,24 +14,8 @@ import java.util.Map;
|
||||||
public class LocationPolicyParser implements PolicyParser {
|
public class LocationPolicyParser implements PolicyParser {
|
||||||
private Glimmer glim = Nemesis.getInstance().getGlimmer();
|
private Glimmer glim = Nemesis.getInstance().getGlimmer();
|
||||||
|
|
||||||
public Policy parse(Map<?, ?> raw) {
|
public Policy parse(Core corePolicy, Map<?, ?> raw) {
|
||||||
String name = (String) raw.get("name");
|
List<Glimmer.Box> locations = DataShifter.configLocationParser(raw.get("locations"));
|
||||||
boolean allowlist = Boolean.TRUE.equals(raw.get("allowList"));
|
return new LocationPolicy(corePolicy.name(), locations, corePolicy.nodes(), corePolicy.nodeAllowlist(), corePolicy.policyAllowList(), corePolicy.effect(), corePolicy.weight());
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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;
|
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.Policy;
|
||||||
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
|
||||||
import java.util.List;
|
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) {
|
public boolean applies(HumanEntity entity) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package io.github.adrianvic.nemesiseye.policy.policies;
|
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.Policy;
|
||||||
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
||||||
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
||||||
|
|
@ -7,12 +8,12 @@ import org.bukkit.entity.HumanEntity;
|
||||||
|
|
||||||
import java.util.List;
|
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
|
@Override
|
||||||
public boolean applies(HumanEntity entity) {
|
public boolean applies(HumanEntity entity) {
|
||||||
for (Glimmer.Box box : locations) {
|
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;
|
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.policy.PolicyNode;
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.permissions.Permission;
|
import org.bukkit.permissions.Permission;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
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;
|
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.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) {
|
for (Map<?, ?> policyMap : rawPolicies) {
|
||||||
if (policyMap.get("type") != null && policyMap.get("type") instanceof String type) {
|
if (policyMap.get("type") != null && policyMap.get("type") instanceof String type) {
|
||||||
|
System.out.println(type);
|
||||||
allPolicies.add(PolicyParsers.get(type).parse(policyMap));
|
allPolicies.add(PolicyParsers.get(type).parse(policyMap));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,26 @@
|
||||||
Policies:
|
Policies:
|
||||||
# NO SPACES
|
- name: "Bedrock-only-admins"
|
||||||
- name: "Beta-1.7.3-items-only"
|
type: "permission"
|
||||||
type: "location"
|
effect: ALLOW
|
||||||
allowList: true # Will deny anything that's not allowed by the nodes if set to true
|
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:
|
locations:
|
||||||
- corner1: { x: 2100, y: 256, z: 1400 }
|
- corner1: { x: 2100, y: 256, z: 1400 }
|
||||||
corner2: { x: 1000, y: -64, z: 2200 }
|
corner2: { x: 1000, y: -64, z: 2200 }
|
||||||
nodes:
|
nodes:
|
||||||
- useItem:
|
- [INTERACT]:
|
||||||
values:
|
values:
|
||||||
- AIR
|
- AIR
|
||||||
- STONE
|
- STONE
|
||||||
|
|
@ -106,7 +119,7 @@ Policies:
|
||||||
- FISHING_ROD
|
- FISHING_ROD
|
||||||
- CLOCK
|
- CLOCK
|
||||||
- GLOWSTONE_DUST
|
- GLOWSTONE_DUST
|
||||||
- INK_SACw
|
- INK_SAC
|
||||||
- BONE_MEAL
|
- BONE_MEAL
|
||||||
- SUGAR
|
- SUGAR
|
||||||
- COOKIE
|
- COOKIE
|
||||||
|
|
@ -117,5 +130,5 @@ Policies:
|
||||||
- MUSIC_DISK_13
|
- MUSIC_DISK_13
|
||||||
- DIRT
|
- DIRT
|
||||||
- BREAD
|
- BREAD
|
||||||
- useEnchantment:
|
- [USE_ENCHANTMENT]:
|
||||||
"flying bananas": "0"
|
"flying bananas": "0"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue