1.0.6-SNAPSHOT #1

Merged
tenkuma merged 4 commits from 1.0.6-SNAPSHOT into main 2026-05-19 15:36:38 -03:00
25 changed files with 207 additions and 110 deletions
Showing only changes of commit 96005d8c86 - Show all commits

I'm going crazy.

天クマ 2025-12-23 20:56:46 -03:00

View file

@ -3,6 +3,7 @@ package io.github.adrianvic.nemesiseye.impl;
import io.github.adrianvic.nemesiseye.Events;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent;
public class BlockEventListener extends BlockListener {
@Override
@ -10,4 +11,8 @@ public class BlockEventListener extends BlockListener {
Events.onBlockBreak(event);
}
@Override
public void onBlockPlace(BlockPlaceEvent event) {
Events.onBlockPlaceEvent(event);
}
}

View file

@ -1,10 +1,29 @@
# __ _______ __ ___________________ _______
# / / \ _ \ \ \ \_ _____/\_____ \ \ \
# / / / /_\ \ \ \ | __)_ / | \ / | \
# \ \ \ \_/ \ / / | \/ | \/ | \
# \_\ \_____ / /_/ /_______ /\_______ /\____|__ /
# \/ \/ \/ \/
# EYE OF NEMESIS - Example config file.
# Documentation in our wiki: https://github.com/adrianvic/NemesisEye
Policies:
# NO SPACES
- name: "Block-illegal-items"
type: global # global / location / permission / list of types
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:
- SAND
- name: "Block-illegal-items" # NO SPACES
type: global
effect: DENY
weight: 0
policyAllowList: false
nodes:
- [BREAK, PLACE, HIT, INTERACT]:
value:
- BEDROCK
- name: "Bedrock-allow-admins"
type: "permission"
effect: ALLOW
weight: 1
permissions:
- "server.usebedrock"
nodes:
- [BREAK, PLACE, HIT, INTERACT]:
values:
- BEDROCK

View file

@ -7,6 +7,7 @@ import io.github.adrianvic.nemesiseye.reflection.Glimmer;
import java.io.File;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
public class Config {
@ -19,6 +20,7 @@ public class Config {
public void load() {
policies = glim.loadPoliciesFromFile(glim.loadConfigFile());
policies.sort(Comparator.comparingInt(Policy::weight).reversed());
}
// TODO: Implement config saving

View file

@ -4,23 +4,31 @@ import io.github.adrianvic.nemesiseye.policy.Action;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerHarvestBlockEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import java.util.List;
public class Events {
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) {
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) {
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));
}
}
}

View file

@ -1,50 +1,51 @@
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;
import org.bukkit.entity.HumanEntity;
import org.bukkit.event.Event;
import java.util.ArrayList;
import java.util.List;
public class Validator {
private final static Glimmer glim = Nemesis.getInstance().getGlimmer();
public static boolean can(HumanEntity entity, Action action) {
return checkAgainstEntity(entity, action);
}
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)) {
public static boolean can(HumanEntity entity, List<Action> actions, Event event) {
for (Action action : actions) {
System.out.println(action);
if (!can(entity, action, event)) {
return false;
}
}
return true;
}
public static List<PolicyNode> getNodesForPolicies(List<Policy> policies) {
List<PolicyNode> nodes = new ArrayList<>();
for (Policy p : policies) {
nodes.addAll(p.nodes());
public static boolean can(HumanEntity entity, Action action, Event event) {
boolean restricted = false;
boolean allowed = false;
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) {
List<Policy> ps = Config.getInstance().getPolicies();
List<Policy> result = new ArrayList<>();

View file

@ -22,8 +22,7 @@ public class PolicyInfo implements Subcommand {
Showing info for policy %s%s%s:
Type: %s
Nodes: %s
%s
""", ChatColor.GREEN, policy.name(), ChatColor.WHITE, policy.getClass().getTypeName(), policy.nodes().size(), policy.nodeAllowlist() ? "Is allowlist" : "Is blacklist"));
""", ChatColor.GREEN, policy.name(), ChatColor.WHITE, policy.getClass().getTypeName(), policy.nodes().size()));
}
}
return true;

View file

@ -6,5 +6,6 @@ public enum Action {
HIT,
CRAFT,
EQUIP,
PLACE,
USE_ENCHANTMENT
}

View file

@ -3,5 +3,4 @@ package io.github.adrianvic.nemesiseye.policy;
public enum Effect {
DENY,
ALLOW,
ALLOWONLY
}

View file

@ -1,13 +1,8 @@
package io.github.adrianvic.nemesiseye.policy;
import org.bukkit.entity.HumanEntity;
import org.bukkit.event.Event;
public interface NodeHandler {
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;
}
boolean check(HumanEntity entity, PolicyNode node, Action action, Event event);
}

View file

@ -1,6 +1,6 @@
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.useItem;
@ -11,7 +11,8 @@ public class NodeHandlers {
private static final Map<Action, NodeHandler> handlers = new HashMap<>();
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.USE_ENCHANTMENT, new useEnchantment());
}

View file

@ -1,13 +1,14 @@
package io.github.adrianvic.nemesiseye.policy;
import org.bukkit.entity.HumanEntity;
import org.bukkit.event.Event;
import java.util.List;
public interface Policy {
String name();
List<PolicyNode> nodes();
boolean nodeAllowlist();
boolean policyAllowList();
boolean applies(HumanEntity entity);
Effect effect();
@ -15,4 +16,12 @@ public interface Policy {
default void addNode(PolicyNode 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;
}
}

View file

@ -1,15 +1,15 @@
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 org.bukkit.entity.HumanEntity;
import org.bukkit.event.Event;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
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) {
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()) {
List<Action> nodeActions = new ArrayList<>();
List<Object> nodeValues = new ArrayList<>();
Effect nodeEffect = effect;
if (rawNode.getKey() instanceof List<?> rawTypes && rawNode.getValue() instanceof Map<?,?> rawNodeValues) {
for (Object rawType : rawTypes) {
@ -37,16 +36,13 @@ public record PolicyNode(List<Action> actions, List<Object> values, Effect effec
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;
@ -59,4 +55,15 @@ public record PolicyNode(List<Action> actions, List<Object> values, Effect effec
}
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;
}
}

View file

@ -1,25 +1,25 @@
package io.github.adrianvic.nemesiseye.policy.handlers;
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.NodeHandler;
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
import org.bukkit.entity.HumanEntity;
import org.bukkit.event.Event;
import org.bukkit.event.block.BlockPlaceEvent;
public class attackWith implements NodeHandler {
private final static Glimmer glim = Nemesis.getInstance().getGlimmer();
public class bePlaced implements NodeHandler {
@Override
public boolean check(HumanEntity entity, PolicyNode node, Action action) {
if (action == Action.HIT) {
public boolean check(HumanEntity entity, PolicyNode node, Action action, Event event) {
if (event instanceof BlockPlaceEvent bpe) {
String type = bpe.getBlock().getType().toString();
for (String s : DataShifter.parseValueToStringList(node.values())) {
boolean matches = DataShifter.safeMatches(s, glim.getItemInMainHandHumanEntity(entity).getType().toString());
if (matches) return false;
if (DataShifter.safeMatches(s, type)) {
return true;
}
}
}
return true;
return false;
}
}

View file

@ -7,17 +7,18 @@ import io.github.adrianvic.nemesiseye.policy.NodeHandler;
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
import org.bukkit.entity.HumanEntity;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
public class useEnchantment implements NodeHandler {
private final Glimmer glim = Nemesis.getInstance().getGlimmer();
@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);
if (!glim.hasItemMeta(item)) return true;
if (!glim.hasAnyEnchantment(item)) return true;
if (!glim.hasItemMeta(item)) return false;
if (!glim.hasAnyEnchantment(item)) return false;
boolean matches = glim.hasEnchantment(item,
DataShifter.parseValueToStringMap(node.values()));

View file

@ -7,19 +7,22 @@ import io.github.adrianvic.nemesiseye.policy.NodeHandler;
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
import org.bukkit.entity.HumanEntity;
import org.bukkit.event.Event;
public class useItem implements NodeHandler {
private final Glimmer glim = Nemesis.getInstance().getGlimmer();
@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();
for (String s : DataShifter.parseValueToStringList(node.values())) {
boolean matches = DataShifter.safeMatches(s, type);
if (matches) return false;
if (DataShifter.safeMatches(s, type)) {
return true;
}
}
return true;
return false;
}
}

View file

@ -10,6 +10,6 @@ import java.util.Map;
public class GlobalPolicyParser implements PolicyParser {
@Override
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());
}
}

View file

@ -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.reflection.Glimmer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

View file

@ -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());
}
}

View file

@ -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());
}
}

View file

@ -7,7 +7,7 @@ import org.bukkit.entity.HumanEntity;
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) {
return true;
}

View file

@ -4,16 +4,19 @@ 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, 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
public boolean applies(HumanEntity entity) {
return true;
for (String perm : permissions) {
if (entity.hasPermission(perm)) {
return true;
}
}
return false;
}
}

View file

@ -7,7 +7,7 @@ import org.bukkit.entity.HumanEntity;
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
public boolean applies(HumanEntity entity) {

View file

@ -4,7 +4,9 @@ import io.github.adrianvic.nemesiseye.Events;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerHarvestBlockEvent;
import org.bukkit.event.player.PlayerInteractEvent;
public class EventListener implements Listener {
@ -22,4 +24,9 @@ public class EventListener implements Listener {
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
Events.onEntityDamageByEntityEvent(event);
}
}
@EventHandler
public void onBlockPlaceEvent(BlockPlaceEvent event) {
Events.onBlockPlaceEvent(event);
}
}

View file

@ -1,5 +1,6 @@
package io.github.adrianvic.nemesiseye.impl;
import io.github.adrianvic.nemesiseye.DataShifter;
import io.github.adrianvic.nemesiseye.Nemesis;
import io.github.adrianvic.nemesiseye.impl.commands.Eye;
import io.github.adrianvic.nemesiseye.policy.Policy;
@ -84,10 +85,17 @@ public class r1_21 implements Glimmer {
@Override
public boolean hasEnchantment(ItemStack item, Map<String, String> valuesmap) {
Map<Enchantment, Integer> enchantmentList = item.getEnchantments();
for (Map.Entry<Enchantment, Integer> enchantmentEntry : enchantmentList.entrySet()) {
for (Map.Entry<String, String> valueEntry : valuesmap.entrySet()) {
if (enchantmentEntry.getKey().getKey().getKey().equals(valueEntry.getKey()) && enchantmentEntry.getValue().toString().equals(valueEntry.getValue())) {
Map<Enchantment, Integer> enchantments = item.getEnchantments();
for (Map.Entry<Enchantment, Integer> ench : enchantments.entrySet()) {
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;
}
}

View file

@ -1,26 +1,58 @@
# __ _______ __ ___________________ _______
# / / \ _ \ \ \ \_ _____/\_____ \ \ \
# / / / /_\ \ \ \ | __)_ / | \ / | \
# \ \ \ \_/ \ / / | \/ | \/ | \
# \_\ \_____ / /_/ /_______ /\_______ /\____|__ /
# \/ \/ \/ \/
# EYE OF NEMESIS - Example config file.
# Documentation in our wiki: https://github.com/adrianvic/NemesisEye
Policies:
- name: "Bedrock-only-admins"
- name: "Bedrock-allow-admins"
type: "permission"
effect: ALLOW
weight: 1
policyAllowList: true
weight: 3
permissions:
- "server.usebedrock"
nodes:
- [INTERACT]:
- [BREAK, PLACE, HIT, 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
- 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
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
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:
- [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:
- AIR
- STONE
@ -38,7 +70,7 @@ Policies:
- COBWEB
- PISTON
- STICKY_PISTON
- GRASS
- GRASS_BLOCK
- DISPENSER
- NOTE_BLOCK
- SANDSTONE
@ -50,7 +82,7 @@ Policies:
- POPPY
- DANDELION
- "^(RED|BROWN)_MUSHROOM$"
- "^(OAK|COBBLESTONE)_SLAB$"
- "^(OAK|COBBLESTONE|SMOOTH_STONE)_SLAB$"
- BRICK_BLOCK
- TNT
- BOOKSHELF
@ -129,6 +161,4 @@ Policies:
- MUSIC_DISK_CAT
- MUSIC_DISK_13
- DIRT
- BREAD
- [USE_ENCHANTMENT]:
"flying bananas": "0"
- BREAD