I'm going crazy.
This commit is contained in:
parent
27c7fd16cc
commit
96005d8c86
25 changed files with 207 additions and 110 deletions
|
|
@ -3,6 +3,7 @@ package io.github.adrianvic.nemesiseye.impl;
|
||||||
import io.github.adrianvic.nemesiseye.Events;
|
import io.github.adrianvic.nemesiseye.Events;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.block.BlockListener;
|
import org.bukkit.event.block.BlockListener;
|
||||||
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
|
|
||||||
public class BlockEventListener extends BlockListener {
|
public class BlockEventListener extends BlockListener {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -10,4 +11,8 @@ public class BlockEventListener extends BlockListener {
|
||||||
Events.onBlockBreak(event);
|
Events.onBlockBreak(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBlockPlace(BlockPlaceEvent event) {
|
||||||
|
Events.onBlockPlaceEvent(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,29 @@
|
||||||
|
# __ _______ __ ___________________ _______
|
||||||
|
# / / \ _ \ \ \ \_ _____/\_____ \ \ \
|
||||||
|
# / / / /_\ \ \ \ | __)_ / | \ / | \
|
||||||
|
# \ \ \ \_/ \ / / | \/ | \/ | \
|
||||||
|
# \_\ \_____ / /_/ /_______ /\_______ /\____|__ /
|
||||||
|
# \/ \/ \/ \/
|
||||||
|
# EYE OF NEMESIS - Example config file.
|
||||||
|
# Documentation in our wiki: https://github.com/adrianvic/NemesisEye
|
||||||
|
|
||||||
Policies:
|
Policies:
|
||||||
# NO SPACES
|
- name: "Block-illegal-items" # NO SPACES
|
||||||
- name: "Block-illegal-items"
|
type: global
|
||||||
type: global # global / location / permission / list of types
|
effect: DENY
|
||||||
nodesAllowList: false # Will deny anything that's not allowed by the nodes if set to true
|
weight: 0
|
||||||
policyAllowList: false # Inverts the policy validation logic, for example a location policy will affect all players NOT inside it's location
|
policyAllowList: false
|
||||||
nodes:
|
nodes:
|
||||||
- useItem:
|
- [BREAK, PLACE, HIT, INTERACT]:
|
||||||
value:
|
value:
|
||||||
- SAND
|
- BEDROCK
|
||||||
|
- name: "Bedrock-allow-admins"
|
||||||
|
type: "permission"
|
||||||
|
effect: ALLOW
|
||||||
|
weight: 1
|
||||||
|
permissions:
|
||||||
|
- "server.usebedrock"
|
||||||
|
nodes:
|
||||||
|
- [BREAK, PLACE, HIT, INTERACT]:
|
||||||
|
values:
|
||||||
|
- BEDROCK
|
||||||
|
|
@ -7,6 +7,7 @@ import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Config {
|
public class Config {
|
||||||
|
|
@ -19,6 +20,7 @@ public class Config {
|
||||||
|
|
||||||
public void load() {
|
public void load() {
|
||||||
policies = glim.loadPoliciesFromFile(glim.loadConfigFile());
|
policies = glim.loadPoliciesFromFile(glim.loadConfigFile());
|
||||||
|
policies.sort(Comparator.comparingInt(Policy::weight).reversed());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement config saving
|
// TODO: Implement config saving
|
||||||
|
|
|
||||||
|
|
@ -4,23 +4,31 @@ 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;
|
||||||
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
|
import org.bukkit.event.player.PlayerHarvestBlockEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Events {
|
public class Events {
|
||||||
public static void onBlockBreak(BlockBreakEvent event) {
|
public static void onBlockBreak(BlockBreakEvent event) {
|
||||||
event.setCancelled(!Validator.can(event.getPlayer(), Action.BREAK));
|
event.setCancelled(!Validator.can(event.getPlayer(), List.of(Action.BREAK, Action.USE_ENCHANTMENT), event));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void onInteractionEvent(PlayerInteractEvent event) {
|
public static void onInteractionEvent(PlayerInteractEvent event) {
|
||||||
if (event.getItem() != null) {
|
if (event.getItem() != null) {
|
||||||
event.setCancelled(!Validator.can(event.getPlayer(), Action.INTERACT));
|
event.setCancelled(!Validator.can(event.getPlayer(), Action.INTERACT, event));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void onBlockPlaceEvent(BlockPlaceEvent event) {
|
||||||
|
event.setCancelled(!Validator.can(event.getPlayer(), Action.PLACE, event));
|
||||||
|
}
|
||||||
|
|
||||||
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.can((HumanEntity) event.getDamager(), Action.HIT));
|
event.setCancelled(!Validator.can((HumanEntity) event.getDamager(), List.of(Action.HIT, Action.USE_ENCHANTMENT), event));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,50 +1,51 @@
|
||||||
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.reflection.Glimmer;
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Validator {
|
public class Validator {
|
||||||
private final static Glimmer glim = Nemesis.getInstance().getGlimmer();
|
public static boolean can(HumanEntity entity, List<Action> actions, Event event) {
|
||||||
|
for (Action action : actions) {
|
||||||
public static boolean can(HumanEntity entity, Action action) {
|
System.out.println(action);
|
||||||
return checkAgainstEntity(entity, action);
|
if (!can(entity, action, event)) {
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean checkAgainstEntity(HumanEntity entity, Action action) {
|
|
||||||
return checkAgainstNodes(entity, getNodesForPolicies(getPoliciesForEntity(entity)), action);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean checkAgainstNodes(HumanEntity entity, List<PolicyNode> nodes, Action action) {
|
|
||||||
for (PolicyNode n : nodes) {
|
|
||||||
if (!checkAgainstNode(entity, n, action)) return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean checkAgainstNode(HumanEntity entity, PolicyNode node, Action action) {
|
|
||||||
for (NodeHandler handler : node.getHandler()) {
|
|
||||||
if (!handler.allows(entity, node, action)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<PolicyNode> getNodesForPolicies(List<Policy> policies) {
|
public static boolean can(HumanEntity entity, Action action, Event event) {
|
||||||
List<PolicyNode> nodes = new ArrayList<>();
|
boolean restricted = false;
|
||||||
for (Policy p : policies) {
|
boolean allowed = false;
|
||||||
nodes.addAll(p.nodes());
|
|
||||||
|
for (Policy policy : getPoliciesForEntity(entity)) {
|
||||||
|
|
||||||
|
boolean matches = policy.matches(entity, action, event);
|
||||||
|
|
||||||
|
switch (policy.effect()) {
|
||||||
|
case ALLOW:
|
||||||
|
if (matches) return true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DENY:
|
||||||
|
if (matches) return false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nodes;
|
|
||||||
|
if (restricted) {
|
||||||
|
return allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static List<Policy> getPoliciesForEntity(HumanEntity entity) {
|
public static List<Policy> getPoliciesForEntity(HumanEntity entity) {
|
||||||
List<Policy> ps = Config.getInstance().getPolicies();
|
List<Policy> ps = Config.getInstance().getPolicies();
|
||||||
List<Policy> result = new ArrayList<>();
|
List<Policy> result = new ArrayList<>();
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,7 @@ public class PolicyInfo implements Subcommand {
|
||||||
Showing info for policy %s%s%s:
|
Showing info for policy %s%s%s:
|
||||||
Type: %s
|
Type: %s
|
||||||
Nodes: %s
|
Nodes: %s
|
||||||
%s
|
""", ChatColor.GREEN, policy.name(), ChatColor.WHITE, policy.getClass().getTypeName(), policy.nodes().size()));
|
||||||
""", ChatColor.GREEN, policy.name(), ChatColor.WHITE, policy.getClass().getTypeName(), policy.nodes().size(), policy.nodeAllowlist() ? "Is allowlist" : "Is blacklist"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -6,5 +6,6 @@ public enum Action {
|
||||||
HIT,
|
HIT,
|
||||||
CRAFT,
|
CRAFT,
|
||||||
EQUIP,
|
EQUIP,
|
||||||
|
PLACE,
|
||||||
USE_ENCHANTMENT
|
USE_ENCHANTMENT
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,5 +3,4 @@ package io.github.adrianvic.nemesiseye.policy;
|
||||||
public enum Effect {
|
public enum Effect {
|
||||||
DENY,
|
DENY,
|
||||||
ALLOW,
|
ALLOW,
|
||||||
ALLOWONLY
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,8 @@
|
||||||
package io.github.adrianvic.nemesiseye.policy;
|
package io.github.adrianvic.nemesiseye.policy;
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
public interface NodeHandler {
|
public interface NodeHandler {
|
||||||
boolean check(HumanEntity entity, PolicyNode node, Action action);
|
boolean check(HumanEntity entity, PolicyNode node, Action action, Event event);
|
||||||
|
|
||||||
default boolean allows(HumanEntity entity, PolicyNode node, Action action) {
|
|
||||||
boolean isWhitelist = (node.effect() == Effect.ALLOWONLY);
|
|
||||||
return check(entity, node, action) ? !isWhitelist : isWhitelist;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package io.github.adrianvic.nemesiseye.policy;
|
package io.github.adrianvic.nemesiseye.policy;
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.policy.handlers.attackWith;
|
import io.github.adrianvic.nemesiseye.policy.handlers.bePlaced;
|
||||||
import io.github.adrianvic.nemesiseye.policy.handlers.useEnchantment;
|
import io.github.adrianvic.nemesiseye.policy.handlers.useEnchantment;
|
||||||
import io.github.adrianvic.nemesiseye.policy.handlers.useItem;
|
import io.github.adrianvic.nemesiseye.policy.handlers.useItem;
|
||||||
|
|
||||||
|
|
@ -11,7 +11,8 @@ public class NodeHandlers {
|
||||||
private static final Map<Action, NodeHandler> handlers = new HashMap<>();
|
private static final Map<Action, NodeHandler> handlers = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
handlers.put(Action.HIT, new attackWith());
|
handlers.put(Action.HIT, new useItem());
|
||||||
|
handlers.put(Action.PLACE, new bePlaced());
|
||||||
handlers.put(Action.INTERACT, new useItem());
|
handlers.put(Action.INTERACT, new useItem());
|
||||||
handlers.put(Action.USE_ENCHANTMENT, new useEnchantment());
|
handlers.put(Action.USE_ENCHANTMENT, new useEnchantment());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
package io.github.adrianvic.nemesiseye.policy;
|
package io.github.adrianvic.nemesiseye.policy;
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface Policy {
|
public interface Policy {
|
||||||
String name();
|
String name();
|
||||||
List<PolicyNode> nodes();
|
List<PolicyNode> nodes();
|
||||||
boolean nodeAllowlist();
|
|
||||||
boolean policyAllowList();
|
boolean policyAllowList();
|
||||||
boolean applies(HumanEntity entity);
|
boolean applies(HumanEntity entity);
|
||||||
Effect effect();
|
Effect effect();
|
||||||
|
|
@ -15,4 +16,12 @@ public interface Policy {
|
||||||
default void addNode(PolicyNode node) {
|
default void addNode(PolicyNode node) {
|
||||||
nodes().add(node);
|
nodes().add(node);
|
||||||
}
|
}
|
||||||
|
default boolean matches(HumanEntity entity, Action action, Event event) {
|
||||||
|
for (PolicyNode node : nodes()) {
|
||||||
|
if (node.matches(entity, action, event)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
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 io.github.adrianvic.nemesiseye.DataShifter;
|
||||||
import org.apache.logging.log4j.status.StatusLogger;
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public record PolicyNode(List<Action> actions, List<Object> values, Effect effect) {
|
public record PolicyNode(List<Action> actions, List<Object> values) {
|
||||||
public static List<PolicyNode> parseNodes(List<Map<Object,Object>> raw, Effect effect) {
|
public static List<PolicyNode> parseNodes(List<Map<Object,Object>> raw, Effect effect) {
|
||||||
List<PolicyNode> nodes = new ArrayList<>();
|
List<PolicyNode> nodes = new ArrayList<>();
|
||||||
|
|
||||||
|
|
@ -17,7 +17,6 @@ public record PolicyNode(List<Action> actions, List<Object> values, Effect effec
|
||||||
for (Map.Entry<Object, Object> rawNode : m.entrySet()) {
|
for (Map.Entry<Object, Object> rawNode : m.entrySet()) {
|
||||||
List<Action> nodeActions = new ArrayList<>();
|
List<Action> nodeActions = new ArrayList<>();
|
||||||
List<Object> nodeValues = new ArrayList<>();
|
List<Object> nodeValues = new ArrayList<>();
|
||||||
Effect nodeEffect = effect;
|
|
||||||
|
|
||||||
if (rawNode.getKey() instanceof List<?> rawTypes && rawNode.getValue() instanceof Map<?,?> rawNodeValues) {
|
if (rawNode.getKey() instanceof List<?> rawTypes && rawNode.getValue() instanceof Map<?,?> rawNodeValues) {
|
||||||
for (Object rawType : rawTypes) {
|
for (Object rawType : rawTypes) {
|
||||||
|
|
@ -37,16 +36,13 @@ public record PolicyNode(List<Action> actions, List<Object> values, Effect effec
|
||||||
nodeValues.add(v);
|
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));
|
if (!nodeActions.isEmpty() && !nodeValues.isEmpty()) {
|
||||||
|
PolicyNode newNode = new PolicyNode(nodeActions, nodeValues);
|
||||||
|
nodes.add(newNode);
|
||||||
|
System.out.println(newNode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nodes;
|
return nodes;
|
||||||
|
|
@ -59,4 +55,15 @@ public record PolicyNode(List<Action> actions, List<Object> values, Effect effec
|
||||||
}
|
}
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean matches(HumanEntity entity, Action action, Event event) {
|
||||||
|
if (!actions.contains(action)) return false;
|
||||||
|
|
||||||
|
for (NodeHandler handler : getHandler()) {
|
||||||
|
if (handler.check(entity, this, action, event)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,25 +1,25 @@
|
||||||
package io.github.adrianvic.nemesiseye.policy.handlers;
|
package io.github.adrianvic.nemesiseye.policy.handlers;
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.DataShifter;
|
import io.github.adrianvic.nemesiseye.DataShifter;
|
||||||
import io.github.adrianvic.nemesiseye.Nemesis;
|
|
||||||
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.NodeHandler;
|
||||||
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
||||||
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
|
|
||||||
public class attackWith implements NodeHandler {
|
public class bePlaced implements NodeHandler {
|
||||||
|
|
||||||
private final static Glimmer glim = Nemesis.getInstance().getGlimmer();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean check(HumanEntity entity, PolicyNode node, Action action) {
|
public boolean check(HumanEntity entity, PolicyNode node, Action action, Event event) {
|
||||||
if (action == Action.HIT) {
|
if (event instanceof BlockPlaceEvent bpe) {
|
||||||
|
String type = bpe.getBlock().getType().toString();
|
||||||
|
|
||||||
for (String s : DataShifter.parseValueToStringList(node.values())) {
|
for (String s : DataShifter.parseValueToStringList(node.values())) {
|
||||||
boolean matches = DataShifter.safeMatches(s, glim.getItemInMainHandHumanEntity(entity).getType().toString());
|
if (DataShifter.safeMatches(s, type)) {
|
||||||
if (matches) return false;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -7,17 +7,18 @@ import io.github.adrianvic.nemesiseye.policy.NodeHandler;
|
||||||
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;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class useEnchantment implements NodeHandler {
|
public class useEnchantment implements NodeHandler {
|
||||||
private final Glimmer glim = Nemesis.getInstance().getGlimmer();
|
private final Glimmer glim = Nemesis.getInstance().getGlimmer();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean check(HumanEntity entity, PolicyNode node, Action action) {
|
public boolean check(HumanEntity entity, PolicyNode node, Action action, Event event) {
|
||||||
ItemStack item = glim.getItemInMainHandHumanEntity(entity);
|
ItemStack item = glim.getItemInMainHandHumanEntity(entity);
|
||||||
|
|
||||||
if (!glim.hasItemMeta(item)) return true;
|
if (!glim.hasItemMeta(item)) return false;
|
||||||
if (!glim.hasAnyEnchantment(item)) return true;
|
if (!glim.hasAnyEnchantment(item)) return false;
|
||||||
|
|
||||||
boolean matches = glim.hasEnchantment(item,
|
boolean matches = glim.hasEnchantment(item,
|
||||||
DataShifter.parseValueToStringMap(node.values()));
|
DataShifter.parseValueToStringMap(node.values()));
|
||||||
|
|
|
||||||
|
|
@ -7,19 +7,22 @@ import io.github.adrianvic.nemesiseye.policy.NodeHandler;
|
||||||
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;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
public class useItem implements NodeHandler {
|
public class useItem implements NodeHandler {
|
||||||
|
|
||||||
private final Glimmer glim = Nemesis.getInstance().getGlimmer();
|
private final Glimmer glim = Nemesis.getInstance().getGlimmer();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean check(HumanEntity entity, PolicyNode node, Action action) {
|
public boolean check(HumanEntity entity, PolicyNode node, Action action, Event event) {
|
||||||
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);
|
if (DataShifter.safeMatches(s, type)) {
|
||||||
if (matches) return false;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,6 @@ import java.util.Map;
|
||||||
public class GlobalPolicyParser implements PolicyParser {
|
public class GlobalPolicyParser implements PolicyParser {
|
||||||
@Override
|
@Override
|
||||||
public Policy parse(Core corePolicy, Map<?, ?> raw) {
|
public Policy parse(Core corePolicy, Map<?, ?> raw) {
|
||||||
return new GlobalPolicy(corePolicy.name(), corePolicy.nodes(), corePolicy.nodeAllowlist(), corePolicy.policyAllowList(), corePolicy.effect(), corePolicy.weight());
|
return new GlobalPolicy(corePolicy.name(), corePolicy.nodes(), corePolicy.policyAllowList(), corePolicy.effect(), corePolicy.weight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ 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;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,6 @@ public class PermissionPolicyParser implements PolicyParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new PermissionPolicy(corePolicy.name(), permissions, corePolicy.nodes(), corePolicy.nodeAllowlist(), corePolicy.policyAllowList(), corePolicy.effect(), corePolicy.weight());
|
return new PermissionPolicy(corePolicy.name(), permissions, corePolicy.nodes(), corePolicy.policyAllowList(), corePolicy.effect(), corePolicy.weight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,6 @@ public class PlayerNamePolicyParser implements PolicyParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new PlayerNamePolicy(corePolicy.name(), names, corePolicy.nodes(), corePolicy.nodeAllowlist(), corePolicy.effect(), corePolicy.policyAllowList(), corePolicy.weight());
|
return new PlayerNamePolicy(corePolicy.name(), names, corePolicy.nodes(), corePolicy.effect(), corePolicy.policyAllowList(), corePolicy.weight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import org.bukkit.entity.HumanEntity;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public record GlobalPolicy(String name, List<PolicyNode> nodes, boolean nodeAllowlist, boolean policyAllowList, Effect effect, int weight) implements Policy {
|
public record GlobalPolicy(String name, List<PolicyNode> nodes, boolean policyAllowList, Effect effect, int weight) implements Policy {
|
||||||
public boolean applies(HumanEntity entity) {
|
public boolean applies(HumanEntity entity) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,16 +4,19 @@ 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 org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.permissions.Permission;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public record PermissionPolicy(String name, List<String> permissions, List<PolicyNode> nodes, boolean nodeAllowlist, boolean policyAllowList, Effect effect, int weight) implements Policy {
|
public record PermissionPolicy(String name, List<String> permissions, List<PolicyNode> nodes, boolean policyAllowList, Effect effect, int weight) implements Policy {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean applies(HumanEntity entity) {
|
public boolean applies(HumanEntity entity) {
|
||||||
return true;
|
for (String perm : permissions) {
|
||||||
|
if (entity.hasPermission(perm)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import org.bukkit.entity.HumanEntity;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public record PlayerNamePolicy(String name, List<String> playerName, List<PolicyNode> nodes, boolean nodeAllowlist, Effect effect, boolean policyAllowList, int weight) implements Policy {
|
public record PlayerNamePolicy(String name, List<String> playerName, List<PolicyNode> nodes, Effect effect, boolean policyAllowList, int weight) implements Policy {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean applies(HumanEntity entity) {
|
public boolean applies(HumanEntity entity) {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,9 @@ import io.github.adrianvic.nemesiseye.Events;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
|
import org.bukkit.event.player.PlayerHarvestBlockEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
public class EventListener implements Listener {
|
public class EventListener implements Listener {
|
||||||
|
|
@ -22,4 +24,9 @@ public class EventListener implements Listener {
|
||||||
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
|
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
|
||||||
Events.onEntityDamageByEntityEvent(event);
|
Events.onEntityDamageByEntityEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBlockPlaceEvent(BlockPlaceEvent event) {
|
||||||
|
Events.onBlockPlaceEvent(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package io.github.adrianvic.nemesiseye.impl;
|
package io.github.adrianvic.nemesiseye.impl;
|
||||||
|
|
||||||
|
import io.github.adrianvic.nemesiseye.DataShifter;
|
||||||
import io.github.adrianvic.nemesiseye.Nemesis;
|
import io.github.adrianvic.nemesiseye.Nemesis;
|
||||||
import io.github.adrianvic.nemesiseye.impl.commands.Eye;
|
import io.github.adrianvic.nemesiseye.impl.commands.Eye;
|
||||||
import io.github.adrianvic.nemesiseye.policy.Policy;
|
import io.github.adrianvic.nemesiseye.policy.Policy;
|
||||||
|
|
@ -84,10 +85,17 @@ public class r1_21 implements Glimmer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasEnchantment(ItemStack item, Map<String, String> valuesmap) {
|
public boolean hasEnchantment(ItemStack item, Map<String, String> valuesmap) {
|
||||||
Map<Enchantment, Integer> enchantmentList = item.getEnchantments();
|
Map<Enchantment, Integer> enchantments = item.getEnchantments();
|
||||||
for (Map.Entry<Enchantment, Integer> enchantmentEntry : enchantmentList.entrySet()) {
|
|
||||||
for (Map.Entry<String, String> valueEntry : valuesmap.entrySet()) {
|
for (Map.Entry<Enchantment, Integer> ench : enchantments.entrySet()) {
|
||||||
if (enchantmentEntry.getKey().getKey().getKey().equals(valueEntry.getKey()) && enchantmentEntry.getValue().toString().equals(valueEntry.getValue())) {
|
String enchKey = ench.getKey().getKey().getKey();
|
||||||
|
String enchLevel = ench.getValue().toString();
|
||||||
|
|
||||||
|
for (Map.Entry<String, String> rule : valuesmap.entrySet()) {
|
||||||
|
if (
|
||||||
|
DataShifter.safeMatches(rule.getKey(), enchKey) &&
|
||||||
|
DataShifter.safeMatches(rule.getValue(), enchLevel)
|
||||||
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,58 @@
|
||||||
|
# __ _______ __ ___________________ _______
|
||||||
|
# / / \ _ \ \ \ \_ _____/\_____ \ \ \
|
||||||
|
# / / / /_\ \ \ \ | __)_ / | \ / | \
|
||||||
|
# \ \ \ \_/ \ / / | \/ | \/ | \
|
||||||
|
# \_\ \_____ / /_/ /_______ /\_______ /\____|__ /
|
||||||
|
# \/ \/ \/ \/
|
||||||
|
# EYE OF NEMESIS - Example config file.
|
||||||
|
# Documentation in our wiki: https://github.com/adrianvic/NemesisEye
|
||||||
|
|
||||||
Policies:
|
Policies:
|
||||||
- name: "Bedrock-only-admins"
|
- name: "Bedrock-allow-admins"
|
||||||
type: "permission"
|
type: "permission"
|
||||||
effect: ALLOW
|
effect: ALLOW
|
||||||
weight: 1
|
weight: 3
|
||||||
policyAllowList: true
|
|
||||||
permissions:
|
permissions:
|
||||||
- "server.usebedrock"
|
- "server.usebedrock"
|
||||||
nodes:
|
nodes:
|
||||||
- [INTERACT]:
|
- [BREAK, PLACE, HIT, INTERACT]:
|
||||||
values:
|
values:
|
||||||
- BEDROCK
|
- BEDROCK
|
||||||
|
|
||||||
- name: "Beta-1.7.3-items-only" # No spaces here or else commands which need the name as argument will not work
|
- name: "Bedrock-deny"
|
||||||
|
type: "global"
|
||||||
|
effect: DENY
|
||||||
|
weight: 2
|
||||||
|
nodes:
|
||||||
|
- [BREAK, PLACE, HIT, INTERACT]:
|
||||||
|
values:
|
||||||
|
- BEDROCK
|
||||||
|
|
||||||
|
- name: "Block-non-beta-items" # No spaces here or else commands which need the name as argument will not work
|
||||||
type: "location" # global | location | permission | playerName
|
type: "location" # global | location | permission | playerName
|
||||||
effect: ALLOWONLY # DENY | ALLOW (overrides deny) | ALLOWONLY (allow only if met)
|
effect: DENY # DENY | ALLOW (overrides deny) | ALLOWONLY (allow only if met)
|
||||||
weight: 0 # Greater weight overrides lower
|
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
|
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:
|
||||||
- [INTERACT]:
|
- [INTERACT, BREAK, HIT, PLACE]:
|
||||||
|
values:
|
||||||
|
- '.*'
|
||||||
|
- [USE_ENCHANTMENT]:
|
||||||
|
values:
|
||||||
|
- ".*": ".*"
|
||||||
|
|
||||||
|
- name: "Allow-beta-items"
|
||||||
|
type: "location"
|
||||||
|
effect: ALLOW
|
||||||
|
weight: 1
|
||||||
|
locations:
|
||||||
|
- corner1: { x: 2100, y: 256, z: 1400 }
|
||||||
|
corner2: { x: 1000, y: -64, z: 2200 }
|
||||||
|
nodes:
|
||||||
|
- [INTERACT, BREAK, HIT, PLACE]:
|
||||||
values:
|
values:
|
||||||
- AIR
|
- AIR
|
||||||
- STONE
|
- STONE
|
||||||
|
|
@ -38,7 +70,7 @@ Policies:
|
||||||
- COBWEB
|
- COBWEB
|
||||||
- PISTON
|
- PISTON
|
||||||
- STICKY_PISTON
|
- STICKY_PISTON
|
||||||
- GRASS
|
- GRASS_BLOCK
|
||||||
- DISPENSER
|
- DISPENSER
|
||||||
- NOTE_BLOCK
|
- NOTE_BLOCK
|
||||||
- SANDSTONE
|
- SANDSTONE
|
||||||
|
|
@ -50,7 +82,7 @@ Policies:
|
||||||
- POPPY
|
- POPPY
|
||||||
- DANDELION
|
- DANDELION
|
||||||
- "^(RED|BROWN)_MUSHROOM$"
|
- "^(RED|BROWN)_MUSHROOM$"
|
||||||
- "^(OAK|COBBLESTONE)_SLAB$"
|
- "^(OAK|COBBLESTONE|SMOOTH_STONE)_SLAB$"
|
||||||
- BRICK_BLOCK
|
- BRICK_BLOCK
|
||||||
- TNT
|
- TNT
|
||||||
- BOOKSHELF
|
- BOOKSHELF
|
||||||
|
|
@ -130,5 +162,3 @@ Policies:
|
||||||
- MUSIC_DISK_13
|
- MUSIC_DISK_13
|
||||||
- DIRT
|
- DIRT
|
||||||
- BREAD
|
- BREAD
|
||||||
- [USE_ENCHANTMENT]:
|
|
||||||
"flying bananas": "0"
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue