Finished r1_21 implementation.
- Better NodeHandler evaluation.
This commit is contained in:
parent
b7b43d6aef
commit
90d43ac3de
20 changed files with 326 additions and 148 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -2,3 +2,4 @@
|
||||||
build/
|
build/
|
||||||
out/
|
out/
|
||||||
.idea/
|
.idea/
|
||||||
|
libs/
|
||||||
|
|
@ -53,7 +53,7 @@ mcVersions.forEach { ver ->
|
||||||
dependencies {
|
dependencies {
|
||||||
add("compileOnly", "io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT")
|
add("compileOnly", "io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT")
|
||||||
add("r1_21CompileOnly", "io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT")
|
add("r1_21CompileOnly", "io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT")
|
||||||
add("b1_7_3CompileOnly", files("libs/beta173-api.jar"))
|
add("b1_7_3CompileOnly", files("libs/craftbukkit-1060.jar"))
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------- */
|
/* ----------------------------------------- */
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,19 @@
|
||||||
package io.github.adrianvic.nemesiseye.impl;
|
package io.github.adrianvic.nemesiseye.impl;
|
||||||
|
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.Policy;
|
||||||
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class b1_7_3 implements Glimmer {
|
public class b1_7_3 implements Glimmer {
|
||||||
|
@Override
|
||||||
|
public File loadConfigFile() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Policy> loadPoliciesFromFile(File file) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,62 +1,38 @@
|
||||||
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.PolicyParsers;
|
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class Config {
|
public class Config {
|
||||||
private final static Config instance = new Config();
|
private static Config instance = new Config();
|
||||||
|
private Glimmer glim = Nemesis.getInstance().getGlimmer();
|
||||||
private File file;
|
private File file;
|
||||||
private YamlConfiguration config;
|
|
||||||
|
|
||||||
private List<Policy> policies = new ArrayList<>();
|
private List<Policy> policies = new ArrayList<>();
|
||||||
|
|
||||||
private Config() {
|
private Config() {}
|
||||||
}
|
|
||||||
|
|
||||||
public void load() {
|
public void load() {
|
||||||
file = new File(Nemesis.getInstance().getDataFolder(), "settings.yml");
|
List<Policy> newPolicies = glim.loadPoliciesFromFile(glim.loadConfigFile());
|
||||||
|
policies = newPolicies;
|
||||||
if (!file.exists())
|
|
||||||
Nemesis.getInstance().saveResource("settings.yml", false);
|
|
||||||
|
|
||||||
config = new YamlConfiguration();
|
|
||||||
config.options().parseComments(true);
|
|
||||||
|
|
||||||
try {
|
|
||||||
config.load(file);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Map<?, ?>> rawPolicies = config.getMapList("Policies");
|
// public void save() {
|
||||||
for (Map<?, ?> map : rawPolicies) {
|
// try {
|
||||||
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
// config.save(file);
|
||||||
if (entry.getKey() instanceof String k && entry.getValue() instanceof List<?> v) {
|
// } catch (Exception e) {
|
||||||
List<Policy> parsed = PolicyParsers.get(k).parse(v);
|
// e.printStackTrace();
|
||||||
policies.addAll(parsed);
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//
|
||||||
}
|
// public void set(String path, Object value) {
|
||||||
}
|
// config.set(path, value);
|
||||||
|
// save();
|
||||||
public void save() {
|
// }
|
||||||
try {
|
|
||||||
config.save(file);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(String path, Object value) {
|
|
||||||
config.set(path, value);
|
|
||||||
save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Policy> getPolicies() {
|
public List<Policy> getPolicies() {
|
||||||
return policies;
|
return policies;
|
||||||
|
|
|
||||||
|
|
@ -21,19 +21,23 @@ public class DataShifter {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, String> parseValueToStringMap(List<Object> values) {
|
public static Map<String,String> parseValueToStringMap(List<Object> raw) {
|
||||||
Map<String, String> result = new HashMap<>();
|
Map<String,String> out = new HashMap<>();
|
||||||
|
|
||||||
for (Object o : values) {
|
for (Object o : raw) {
|
||||||
if (o instanceof Map<?, ?> raw) {
|
if (o instanceof Map<?,?> map) {
|
||||||
for (Map.Entry<?, ?> e : raw.entrySet()) {
|
for (Map.Entry<?,?> e : map.entrySet()) {
|
||||||
if (e.getKey() instanceof String k && e.getValue() instanceof String v) {
|
out.put(String.valueOf(e.getKey()), String.valueOf(e.getValue()));
|
||||||
result.put(k, v);
|
}
|
||||||
|
} else if (o instanceof String s) {
|
||||||
|
|
||||||
|
String[] parts = s.split(":", 2);
|
||||||
|
if (parts.length == 2) {
|
||||||
|
out.put(parts[0].trim(), parts[1].trim());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return out;
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Map<?, ?>> parseValueToListOfMaps(List<?> values) {
|
public static List<Map<?, ?>> parseValueToListOfMaps(List<?> values) {
|
||||||
|
|
|
||||||
|
|
@ -2,27 +2,22 @@ package io.github.adrianvic.nemesiseye;
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
public class EventListener implements Listener {
|
public class Events {
|
||||||
@EventHandler
|
public static void onBlockBreak(BlockBreakEvent event) {
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
|
||||||
event.setCancelled(!Validator.canBreak(event.getPlayer()));
|
event.setCancelled(!Validator.canBreak(event.getPlayer()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
public static void onInteractionEvent(PlayerInteractEvent event) {
|
||||||
public void onInteractionEvent(PlayerInteractEvent event) {
|
|
||||||
if (event.getItem() != null) {
|
if (event.getItem() != null) {
|
||||||
event.setCancelled(!Validator.canInteract(event.getPlayer()));
|
event.setCancelled(!Validator.canInteract(event.getPlayer()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
public static void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
|
||||||
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
|
|
||||||
if (event.getDamager() instanceof Player) {
|
if (event.getDamager() instanceof Player) {
|
||||||
event.setCancelled(!Validator.canHit((HumanEntity) event.getDamager()));
|
event.setCancelled(!Validator.canHit((HumanEntity) event.getDamager()));
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
package io.github.adrianvic.nemesiseye;
|
package io.github.adrianvic.nemesiseye;
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.commands.Eye;
|
import io.github.adrianvic.nemesiseye.commands.EyeCore;
|
||||||
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
@ -17,9 +18,8 @@ public final class Nemesis extends JavaPlugin {
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
instance = this;
|
instance = this;
|
||||||
glim = loadGlim();
|
glim = loadGlim();
|
||||||
getServer().getPluginManager().registerEvents(new EventListener(), this);
|
|
||||||
Config.getInstance().load();
|
Config.getInstance().load();
|
||||||
getCommand("eye").setExecutor(new Eye());
|
glim.onLoad();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String readImplVersion() {
|
private String readImplVersion() {
|
||||||
|
|
@ -59,9 +59,7 @@ public final class Nemesis extends JavaPlugin {
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Nemesis getInstance() {
|
public static Nemesis getInstance() { return instance; }
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Glimmer getGlimmer() { return glim; }
|
public Glimmer getGlimmer() { return glim; }
|
||||||
|
public PluginManager getPluginManager() { return this.getServer().getPluginManager(); }
|
||||||
}
|
}
|
||||||
|
|
@ -1,16 +1,17 @@
|
||||||
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.policies.LocationPolicy;
|
|
||||||
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 org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.util.BoundingBox;
|
|
||||||
|
|
||||||
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 canInteract(HumanEntity entity) {
|
public static boolean canInteract(HumanEntity entity) {
|
||||||
return checkAgainstEntity(entity, Action.INTERACT);
|
return checkAgainstEntity(entity, Action.INTERACT);
|
||||||
}
|
}
|
||||||
|
|
@ -30,13 +31,11 @@ public class Validator {
|
||||||
for (PolicyNode n : nodes) {
|
for (PolicyNode n : nodes) {
|
||||||
if (!checkAgainstNode(entity, n, action)) return false;
|
if (!checkAgainstNode(entity, n, action)) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkAgainstNode(HumanEntity entity, PolicyNode node, Action action) {
|
public static boolean checkAgainstNode(HumanEntity entity, PolicyNode node, Action action) {
|
||||||
boolean allowed = node.getHandler().allows(entity, node, action);
|
return node.getHandler().allows(entity, node, action);
|
||||||
return node.isWhitelist() != allowed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<PolicyNode> getNodesForPolicies(List<Policy> policies) {
|
public static List<PolicyNode> getNodesForPolicies(List<Policy> policies) {
|
||||||
|
|
@ -49,18 +48,6 @@ public class Validator {
|
||||||
|
|
||||||
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> applyingLPS = new ArrayList<>();
|
return glim.getApplyingPoliciesForEntity(entity, ps);
|
||||||
for (Policy p : ps) {
|
|
||||||
if (p instanceof LocationPolicy lp) {
|
|
||||||
for (ArrayList<BoundingBox> boxes : lp.locations()) {
|
|
||||||
for (BoundingBox box : boxes) {
|
|
||||||
if (box.contains(entity.getLocation().toVector())) {
|
|
||||||
applyingLPS.add(lp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return applyingLPS;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,14 @@ package io.github.adrianvic.nemesiseye.commands;
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.Nemesis;
|
import io.github.adrianvic.nemesiseye.Nemesis;
|
||||||
import io.github.adrianvic.nemesiseye.commands.sub.*;
|
import io.github.adrianvic.nemesiseye.commands.sub.*;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabCompleter;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class Eye implements CommandExecutor, TabCompleter {
|
public class EyeCore {
|
||||||
private final Map<String, Subcommand> subs = new HashMap<>();
|
public final Map<String, Subcommand> subs = new HashMap<>();
|
||||||
|
|
||||||
public Eye() {
|
public EyeCore() {
|
||||||
register(new Reload());
|
register(new Reload());
|
||||||
register(new ListPolicies());
|
register(new ListPolicies());
|
||||||
register(new PolicyInfo());
|
register(new PolicyInfo());
|
||||||
|
|
@ -26,14 +20,13 @@ public class Eye implements CommandExecutor, TabCompleter {
|
||||||
subs.put(sub.name(), sub);
|
subs.put(sub.name(), sub);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public boolean onCommand(CommandSender commandSender, Command command, String s, String [] strings) {
|
||||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String @NotNull [] strings) {
|
|
||||||
if (strings.length == 0) {
|
if (strings.length == 0) {
|
||||||
commandSender.sendMessage("""
|
commandSender.sendMessage("""
|
||||||
%sEye of Nemesis%s version %s
|
Eye of Nemesis version %s
|
||||||
Usage: '/eye <command>'
|
Usage: '/eye <command>'
|
||||||
Use '/eye help' for a list of available commands
|
Use '/eye help' for a list of available commands
|
||||||
""".formatted(ChatColor.RED, ChatColor.RESET, Nemesis.getInstance().getDescription().getVersion()));
|
""".formatted(Nemesis.getInstance().getDescription().getVersion()));
|
||||||
} else {
|
} else {
|
||||||
Subcommand sub = subs.get(strings[0].toLowerCase());
|
Subcommand sub = subs.get(strings[0].toLowerCase());
|
||||||
if (sub == null) {
|
if (sub == null) {
|
||||||
|
|
@ -45,8 +38,7 @@ public class Eye implements CommandExecutor, TabCompleter {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String [] strings) {
|
||||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String @NotNull [] strings) {
|
|
||||||
if (strings.length == 1) {
|
if (strings.length == 1) {
|
||||||
return new ArrayList<>(subs.keySet());
|
return new ArrayList<>(subs.keySet());
|
||||||
}
|
}
|
||||||
|
|
@ -56,4 +48,6 @@ public class Eye implements CommandExecutor, TabCompleter {
|
||||||
}
|
}
|
||||||
return List.of();
|
return List.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, Subcommand> getSubs() { return subs; };
|
||||||
}
|
}
|
||||||
|
|
@ -20,11 +20,11 @@ public class PolicyInfo implements Subcommand {
|
||||||
for (Policy policy : policies) {
|
for (Policy policy : policies) {
|
||||||
if (policy.name().equals(strings[0])) {
|
if (policy.name().equals(strings[0])) {
|
||||||
commandSender.sendMessage(String.format("""
|
commandSender.sendMessage(String.format("""
|
||||||
Showing info for policy "%s%s%s":
|
Showing info for policy "%s":
|
||||||
Type: %s
|
Type: %s
|
||||||
Nodes: %s
|
Nodes: %s
|
||||||
%s
|
%s
|
||||||
""", ChatColor.UNDERLINE, policy.name(), ChatColor.RESET, "location", policy.nodes().size(), policy.allowlist() ? "Is allowlist" : "Is blacklist"));
|
""", policy.name(), "location", policy.nodes().size(), policy.allowlist() ? "Is allowlist" : "Is blacklist"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -1,20 +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;
|
||||||
|
|
||||||
public class attackWith implements NodeHandler {
|
public class attackWith implements NodeHandler {
|
||||||
|
|
||||||
|
private final static Glimmer glim = Nemesis.getInstance().getGlimmer();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean allows(HumanEntity entity, PolicyNode node, Action action) {
|
public boolean allows(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())) {
|
||||||
if (DataShifter.safeMatches(s, entity.getInventory().getItemInMainHand().getType().toString())) return false;
|
boolean matches = DataShifter.safeMatches(s, glim.getItemInMainHandHumanEntity(entity).getType().toString());
|
||||||
|
if (matches) return node.isWhitelist();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return !node.isWhitelist();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,41 +1,27 @@
|
||||||
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 org.bukkit.enchantments.Enchantment;
|
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class useEnchantment implements NodeHandler {
|
public class useEnchantment implements NodeHandler {
|
||||||
|
private Glimmer glim = Nemesis.getInstance().getGlimmer();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean allows(HumanEntity entity, PolicyNode node, Action action) {
|
public boolean allows(HumanEntity entity, PolicyNode node, Action action) {
|
||||||
ItemStack item = entity.getInventory().getItemInMainHand();
|
ItemStack item = glim.getItemInMainHandHumanEntity(entity);
|
||||||
if (item.getItemMeta() == null) {
|
|
||||||
return !node.isWhitelist();
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<Enchantment, Integer> enchants = item.getItemMeta().getEnchants();
|
if (!glim.hasItemMeta(item)) return true;
|
||||||
|
if (!glim.hasAnyEnchantment(item)) return true;
|
||||||
|
|
||||||
if (enchants.isEmpty()) {
|
boolean matches = glim.hasEnchantment(item,
|
||||||
return !node.isWhitelist();
|
DataShifter.parseValueToStringMap(node.values()));
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, String> valuesmap = DataShifter.parseValueToStringMap(node.values());
|
return matches ? node.isWhitelist() : !node.isWhitelist();
|
||||||
|
|
||||||
for (Map.Entry<Enchantment, Integer> e : enchants.entrySet()) {
|
|
||||||
String enchantment = e.getKey().getKey().getKey();
|
|
||||||
String level = e.getValue().toString();
|
|
||||||
|
|
||||||
for (Map.Entry<String, String> entry : valuesmap.entrySet()) {
|
|
||||||
if (DataShifter.safeMatches(entry.getKey().trim(), enchantment) && DataShifter.safeMatches(entry.getValue().trim(), level)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,22 +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;
|
||||||
|
|
||||||
public class useItem implements NodeHandler {
|
public class useItem implements NodeHandler {
|
||||||
|
|
||||||
|
private Glimmer glim = Nemesis.getInstance().getGlimmer();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean allows(HumanEntity entity, PolicyNode node, Action action) {
|
public boolean allows(HumanEntity entity, PolicyNode node, Action action) {
|
||||||
String type = entity.getInventory().getItemInMainHand().getType().toString();
|
String type = glim.getItemInMainHandHumanEntity(entity).getType().toString();
|
||||||
|
|
||||||
for (String s : DataShifter.parseValueToStringList(node.values())) {
|
for (String s : DataShifter.parseValueToStringList(node.values())) {
|
||||||
if (DataShifter.safeMatches(s, type)) {
|
boolean matches = DataShifter.safeMatches(s, type);
|
||||||
return false;
|
if (matches) return node.isWhitelist();
|
||||||
}
|
}
|
||||||
}
|
return !node.isWhitelist();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,19 @@
|
||||||
package io.github.adrianvic.nemesiseye.policy.parser;
|
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.policy.*;
|
import io.github.adrianvic.nemesiseye.policy.*;
|
||||||
import io.github.adrianvic.nemesiseye.policy.policies.LocationPolicy;
|
import io.github.adrianvic.nemesiseye.policy.policies.LocationPolicy;
|
||||||
import org.bukkit.Bukkit;
|
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.util.BoundingBox;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class LocationPolicyParser implements PolicyParser {
|
public class LocationPolicyParser implements PolicyParser {
|
||||||
|
private Glimmer glim = Nemesis.getInstance().getGlimmer();
|
||||||
|
|
||||||
public List<Policy> parse(List<?> raw) {
|
public List<Policy> parse(List<?> raw) {
|
||||||
List<Policy> out = new ArrayList<>(raw.size());
|
List<Policy> out = new ArrayList<>(raw.size());
|
||||||
List<Map<?, ?>> parsedRawMap = DataShifter.parseValueToListOfMaps(raw);
|
List<Map<?, ?>> parsedRawMap = DataShifter.parseValueToListOfMaps(raw);
|
||||||
|
|
@ -33,12 +35,12 @@ public class LocationPolicyParser implements PolicyParser {
|
||||||
List<PolicyNode> nodes = PolicyNode.parseNodes(nodeList, allowlist);
|
List<PolicyNode> nodes = PolicyNode.parseNodes(nodeList, allowlist);
|
||||||
|
|
||||||
// Parsing locations
|
// Parsing locations
|
||||||
List<ArrayList<BoundingBox>> locations = new ArrayList<>();
|
List<ArrayList<Glimmer.Box>> locations = new ArrayList<>();
|
||||||
|
|
||||||
Object rawLocations = m.get("locations");
|
Object rawLocations = m.get("locations");
|
||||||
List<?> groups = rawLocations instanceof List ? (List<?>) rawLocations : List.of();
|
List<?> groups = rawLocations instanceof List ? (List<?>) rawLocations : List.of();
|
||||||
|
|
||||||
ArrayList<BoundingBox> boxes = new ArrayList<>(groups.size());
|
ArrayList<Glimmer.Box> boxes = new ArrayList<>(groups.size());
|
||||||
|
|
||||||
// Now iterate over regions
|
// Now iterate over regions
|
||||||
for (Object rObj : groups) {
|
for (Object rObj : groups) {
|
||||||
|
|
@ -54,10 +56,10 @@ public class LocationPolicyParser implements PolicyParser {
|
||||||
double y2 = ((Number) c2.get("y")).doubleValue();
|
double y2 = ((Number) c2.get("y")).doubleValue();
|
||||||
double z2 = ((Number) c2.get("z")).doubleValue();
|
double z2 = ((Number) c2.get("z")).doubleValue();
|
||||||
|
|
||||||
Location loc1 = new Location(Bukkit.getWorlds().getFirst(), x1, y1, z1);
|
Location loc1 = new Location(glim.getWorlds().getFirst(), x1, y1, z1);
|
||||||
Location loc2 = new Location(Bukkit.getWorlds().getFirst(), x2, y2, z2);
|
Location loc2 = new Location(glim.getWorlds().getFirst(), x2, y2, z2);
|
||||||
|
|
||||||
boxes.add(BoundingBox.of(loc1, loc2));
|
boxes.add(Glimmer.Box.of(loc1, loc2));
|
||||||
}
|
}
|
||||||
locations.add(boxes);
|
locations.add(boxes);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@ package io.github.adrianvic.nemesiseye.policy.policies;
|
||||||
|
|
||||||
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.util.BoundingBox;
|
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public record LocationPolicy(String name, List<ArrayList<BoundingBox>> locations, List<PolicyNode> nodes, boolean allowlist) implements Policy {}
|
public record LocationPolicy(String name, List<ArrayList<Glimmer.Box>> locations, List<PolicyNode> nodes, boolean allowlist) implements Policy {}
|
||||||
|
|
@ -1,5 +1,52 @@
|
||||||
package io.github.adrianvic.nemesiseye.reflection;
|
package io.github.adrianvic.nemesiseye.reflection;
|
||||||
|
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.Policy;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public interface Glimmer {
|
public interface Glimmer {
|
||||||
|
File loadConfigFile();
|
||||||
|
List<Policy> loadPoliciesFromFile(File file);
|
||||||
|
List<Policy> getApplyingPoliciesForEntity(HumanEntity entity, List<Policy> policies);
|
||||||
|
void onLoad();
|
||||||
|
ItemStack getItemInMainHandHumanEntity(HumanEntity entity);
|
||||||
|
boolean hasItemMeta(ItemStack item);
|
||||||
|
List<World> getWorlds();
|
||||||
|
boolean hasEnchantment(ItemStack item, Map<String, String> valuesmap);
|
||||||
|
boolean hasAnyEnchantment(ItemStack itemStack);
|
||||||
|
|
||||||
|
class Box {
|
||||||
|
public final double x1, y1, z1, x2, y2, z2;
|
||||||
|
|
||||||
|
public Box(double x1, double y1, double z1, double x2, double y2, double z2) {
|
||||||
|
this.x1 = Math.min(x1, x2);
|
||||||
|
this.y1 = Math.min(y1, y2);
|
||||||
|
this.z1 = Math.min(z1, z2);
|
||||||
|
this.x2 = Math.max(x1, x2);
|
||||||
|
this.y2 = Math.max(y1, y2);
|
||||||
|
this.z2 = Math.max(z1, z2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(double x, double y, double z) {
|
||||||
|
return x >= x1 && x <= x2
|
||||||
|
&& y >= y1 && y <= y2
|
||||||
|
&& z >= z1 && z <= z2;
|
||||||
|
}
|
||||||
|
public boolean contains(Vector v) {
|
||||||
|
return v.getX() >= x1 && v.getX() <= x2
|
||||||
|
&& v.getY() >= y1 && v.getY() <= y2
|
||||||
|
&& v.getZ() >= z1 && v.getZ() <= z2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Box of(Location loc1, Location loc2) { return new Box(loc1.getX(), loc1.getY(), loc1.getZ(), loc2.getX(), loc2.getY(), loc2.getZ()); }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ Policies:
|
||||||
- FISHING_ROD
|
- FISHING_ROD
|
||||||
- CLOCK
|
- CLOCK
|
||||||
- GLOWSTONE_DUST
|
- GLOWSTONE_DUST
|
||||||
- INK_SAC
|
- INK_SACw
|
||||||
- BONE_MEAL
|
- BONE_MEAL
|
||||||
- SUGAR
|
- SUGAR
|
||||||
- COOKIE
|
- COOKIE
|
||||||
|
|
@ -115,7 +115,7 @@ Policies:
|
||||||
- DIRT
|
- DIRT
|
||||||
- BREAD
|
- BREAD
|
||||||
- useEnchantment:
|
- useEnchantment:
|
||||||
"gibberish": 999999
|
"theresnoenchantmentwiththisname": "3"
|
||||||
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 }
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
package io.github.adrianvic.nemesiseye.impl;
|
||||||
|
|
||||||
|
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.entity.EntityDamageByEntityEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
|
public class EventListener implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
|
Events.onBlockBreak(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInteractionEvent(PlayerInteractEvent event) {
|
||||||
|
Events.onInteractionEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
|
||||||
|
Events.onEntityDamageByEntityEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
package io.github.adrianvic.nemesiseye.impl.commands;
|
||||||
|
|
||||||
|
import io.github.adrianvic.nemesiseye.commands.EyeCore;
|
||||||
|
import io.github.adrianvic.nemesiseye.commands.sub.*;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabCompleter;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class Eye implements CommandExecutor, TabCompleter {
|
||||||
|
private EyeCore core;
|
||||||
|
|
||||||
|
public Eye() {
|
||||||
|
core = new EyeCore();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String @NotNull [] strings) {
|
||||||
|
return core.onCommand(commandSender, command, s, strings);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String @NotNull [] strings) {
|
||||||
|
return core.onTabComplete(commandSender, command, s, strings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,116 @@
|
||||||
package io.github.adrianvic.nemesiseye.impl;
|
package io.github.adrianvic.nemesiseye.impl;
|
||||||
|
|
||||||
public class r1_21 {
|
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;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.PolicyParsers;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.policies.LocationPolicy;
|
||||||
|
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class r1_21 implements Glimmer {
|
||||||
|
@Override
|
||||||
|
public File loadConfigFile() {
|
||||||
|
File file = new File(Nemesis.getInstance().getDataFolder(), "settings.yml");
|
||||||
|
|
||||||
|
if (!file.exists())
|
||||||
|
Nemesis.getInstance().saveResource("settings.yml", false);
|
||||||
|
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Policy> loadPoliciesFromFile(File file) {
|
||||||
|
YamlConfiguration config = new YamlConfiguration();
|
||||||
|
config.options().parseComments(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
config.load(file);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Map<?, ?>> rawPolicies = config.getMapList("Policies");
|
||||||
|
List<Policy> allPolicies = new ArrayList<>();
|
||||||
|
for (Map<?, ?> map : rawPolicies) {
|
||||||
|
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
||||||
|
if (entry.getKey() instanceof String k && entry.getValue() instanceof List<?> v) {
|
||||||
|
List<Policy> parsed = PolicyParsers.get(k).parse(v);
|
||||||
|
allPolicies.addAll(parsed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return allPolicies;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Policy> getApplyingPoliciesForEntity(HumanEntity entity, List<Policy> policies) {
|
||||||
|
List<Policy> applyingLPS = new ArrayList<>();
|
||||||
|
for (Policy p : policies) {
|
||||||
|
if (p instanceof LocationPolicy lp) {
|
||||||
|
for (ArrayList<Box> boxes : lp.locations()) {
|
||||||
|
for (Box box : boxes) {
|
||||||
|
if (box.contains(entity.getLocation().toVector())) {
|
||||||
|
applyingLPS.add(lp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return applyingLPS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoad() {
|
||||||
|
PluginManager pm = Nemesis.getInstance().getPluginManager();
|
||||||
|
Nemesis.getInstance().getCommand("eye").setExecutor(new Eye());
|
||||||
|
pm.registerEvents(new EventListener(), Nemesis.getInstance());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getItemInMainHandHumanEntity(HumanEntity entity) {
|
||||||
|
return entity.getInventory().getItemInMainHand();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasItemMeta(ItemStack item) {
|
||||||
|
if (item.getItemMeta() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<World> getWorlds() {
|
||||||
|
return Bukkit.getWorlds();
|
||||||
|
}
|
||||||
|
|
||||||
|
@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())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasAnyEnchantment(ItemStack item) {
|
||||||
|
return !(item.getItemMeta().getEnchants().isEmpty());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue