Add sendCommand() on Glimmer because beta does not break line on sendMessage() line break.

Subcommands are now mapped in the class Commands.

Add usage() and description() to Subcommand.

Add help command.
This commit is contained in:
天クマ 2025-12-15 02:09:09 -03:00
commit 0b04c0553a
12 changed files with 154 additions and 44 deletions

View file

@ -3,13 +3,12 @@
[![Build status badge](https://github.com/adrianvic/NemesisEye/actions/workflows/build.yml/badge.svg)](https://github.com/adrianvic/NemesisEye/actions/workflows/build.yml) [![Build status badge](https://github.com/adrianvic/NemesisEye/actions/workflows/build.yml/badge.svg)](https://github.com/adrianvic/NemesisEye/actions/workflows/build.yml)
![Modrinth link](https://img.shields.io/badge/Modrinth-Black?style=social&logo=Modrinth&logoColor=green&link=https%3A%2F%2Fmodrinth.com%2Fplugin%2Feye-of-nemesis%2F) ![Modrinth link](https://img.shields.io/badge/Modrinth-Black?style=social&logo=Modrinth&logoColor=green&link=https%3A%2F%2Fmodrinth.com%2Fplugin%2Feye-of-nemesis%2F)
> [!IMPORTANT]
> This project is in a early stage, please report any bug you find.
# Eye of Nemesis # Eye of Nemesis
Eye of Nemesis is a plugin that allows server admins to write policies that will deny or allow (black/whitelist) players to do specific things based on the value of nodes. Eye of Nemesis is a plugin that allows server admins to write policies that will deny or allow (black/whitelist) players to do specific things based on the value of nodes.
## Warnings
- This plugin is in a very early stage.
- Even though running `/eye` will tell you to run `/eye help` to list all available commands, this is not implemented yet, however all commands are available as tab-complete of `/eye`.
## Motivations ## Motivations
I made this plugin as an effort to preserve a village from my private server. Originally from beta 1.7.3 Betalands server, then transferred to RetroMC, and then finally we downloaded the chunks to merge into our server, I was afraid it would not have the same feeling after all the updates, so I had the idea to make a plugin that can block the newer features. I made this plugin as an effort to preserve a village from my private server. Originally from beta 1.7.3 Betalands server, then transferred to RetroMC, and then finally we downloaded the chunks to merge into our server, I was afraid it would not have the same feeling after all the updates, so I had the idea to make a plugin that can block the newer features.

View file

@ -7,6 +7,7 @@ import io.github.adrianvic.nemesiseye.policy.PolicyParsers;
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 org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -89,6 +90,14 @@ public class b1_7_3 implements Glimmer {
return entity.getItemInHand(); return entity.getItemInHand();
} }
@Override
public void sendMessage(CommandSender commandSender, String text) {
String[] lines = text.split("\\r?\\n");
for (String line : lines) {
commandSender.sendMessage(line);
}
}
@Override @Override
public boolean hasItemMeta(ItemStack item) { public boolean hasItemMeta(ItemStack item) {
return false; return false;

View file

@ -0,0 +1,26 @@
package io.github.adrianvic.nemesiseye.commands;
import io.github.adrianvic.nemesiseye.commands.sub.*;
import java.util.HashMap;
import java.util.Map;
public class Commands {
private static final Map<String, Subcommand> commands = new HashMap<>();
static {
commands.put("help", new Help());
commands.put("listpolicies", new ListPolicies());
commands.put("currentpolicies", new CurrentPolicies());
commands.put("policyinfo", new PolicyInfo());
commands.put("reload", new Reload());
}
public static Map<String, Subcommand> getAll() {
return commands;
}
public static Subcommand get(String type) {
return commands.get(type);
}
}

View file

@ -2,33 +2,26 @@ 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 io.github.adrianvic.nemesiseye.reflection.Glimmer;
import io.github.adrianvic.nemesiseye.commands.Commands;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import java.util.*; import java.util.*;
public class EyeCore { public class EyeCore {
public final Map<String, Subcommand> subs = new HashMap<>(); private final Glimmer glim = Nemesis.getInstance().getGlimmer();
public EyeCore() { public EyeCore() {}
register(new Reload());
register(new ListPolicies());
register(new PolicyInfo());
register(new CurrentPolicies());
}
private void register(Subcommand sub) {
subs.put(sub.name(), sub);
}
public boolean onCommand(CommandSender commandSender, Command command, String s, String [] strings) { public boolean onCommand(CommandSender commandSender, Command command, String s, String [] strings) {
if (strings.length == 0) { if (strings.length == 0) {
commandSender.sendMessage(""" glim.sendMessage(commandSender, """
Eye of Nemesis 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(Nemesis.getInstance().getDescription().getVersion())); """.formatted(Nemesis.getInstance().getDescription().getVersion()));
} else { } else {
Subcommand sub = subs.get(strings[0].toLowerCase()); Subcommand sub = Commands.get(strings[0].toLowerCase());
if (sub == null) { if (sub == null) {
commandSender.sendMessage("Unknown command, try '/eye help' to list available commands."); commandSender.sendMessage("Unknown command, try '/eye help' to list available commands.");
return true; return true;
@ -40,14 +33,12 @@ public class EyeCore {
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String [] strings) { public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String [] strings) {
if (strings.length == 1) { if (strings.length == 1) {
return new ArrayList<>(subs.keySet()); return new ArrayList<>(Commands.getAll().keySet());
} }
Subcommand sub = subs.get(strings[0].toLowerCase()); Subcommand sub = Commands.get(strings[0].toLowerCase());
if (sub != null) { if (sub != null) {
return sub.onTabComplete(commandSender, Arrays.copyOfRange(strings, 1, strings.length)); return sub.onTabComplete(commandSender, Arrays.copyOfRange(strings, 1, strings.length));
} }
return List.of(); return List.of();
} }
public Map<String, Subcommand> getSubs() { return subs; }
} }

View file

@ -9,11 +9,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class CurrentPolicies implements Subcommand { public class CurrentPolicies implements Subcommand {
@Override
public String name() {
return "currentpolicies";
}
@Override @Override
public boolean execute(CommandSender commandSender, String[] args) { public boolean execute(CommandSender commandSender, String[] args) {
List<Policy> policies = Validator.getPoliciesForEntity((HumanEntity) commandSender); List<Policy> policies = Validator.getPoliciesForEntity((HumanEntity) commandSender);
@ -34,4 +29,14 @@ public class CurrentPolicies implements Subcommand {
public List<String> onTabComplete(CommandSender sender, String[] args) { public List<String> onTabComplete(CommandSender sender, String[] args) {
return List.of(); return List.of();
} }
@Override
public String description() {
return "Lists policies appliying to you.";
}
@Override
public String usage() {
return "";
}
} }

View file

@ -0,0 +1,47 @@
package io.github.adrianvic.nemesiseye.commands.sub;
import io.github.adrianvic.nemesiseye.Nemesis;
import io.github.adrianvic.nemesiseye.commands.Commands;
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class Help implements Subcommand {
private final Glimmer glim = Nemesis.getInstance().getGlimmer();
@Override
public boolean execute(CommandSender commandSender, String[] strings) {
List<String> rstr = new ArrayList<>();
Map<String, Subcommand> allSubcommands = Commands.getAll();
if (allSubcommands.isEmpty()) {
rstr.add("No commands found.");
}
for (Map.Entry<String, Subcommand> e : allSubcommands.entrySet()) {
rstr.add("""
%s - %s
Usage: /eye %s %s
""".formatted(e.getKey(), e.getValue().description(), e.getKey(), e.getValue()));
}
glim.sendMessage(commandSender, String.join("\n", rstr));
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, String[] strings) {
return List.of();
}
@Override
public String description() {
return "Lists all commands.";
}
@Override
public String usage() {
return "";
}
}

View file

@ -8,12 +8,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class ListPolicies implements Subcommand { public class ListPolicies implements Subcommand {
@Override
public String name() {
return "listpolicies";
}
@Override @Override
public boolean execute(CommandSender commandSender, String[] args) { public boolean execute(CommandSender commandSender, String[] args) {
List<String> rstr = new ArrayList<>(); List<String> rstr = new ArrayList<>();
@ -28,4 +22,14 @@ public class ListPolicies implements Subcommand {
public List<String> onTabComplete(CommandSender sender, String[] args) { public List<String> onTabComplete(CommandSender sender, String[] args) {
return List.of(); return List.of();
} }
@Override
public String description() {
return "Lists all loaded policies.";
}
@Override
public String usage() {
return "";
}
} }

View file

@ -1,24 +1,23 @@
package io.github.adrianvic.nemesiseye.commands.sub; package io.github.adrianvic.nemesiseye.commands.sub;
import io.github.adrianvic.nemesiseye.Config; import io.github.adrianvic.nemesiseye.Config;
import io.github.adrianvic.nemesiseye.Nemesis;
import io.github.adrianvic.nemesiseye.policy.Policy; import io.github.adrianvic.nemesiseye.policy.Policy;
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class PolicyInfo implements Subcommand { public class PolicyInfo implements Subcommand {
@Override private final Glimmer glim = Nemesis.getInstance().getGlimmer();
public String name() {
return "policyinfo";
}
@Override @Override
public boolean execute(CommandSender commandSender, String[] strings) { public boolean execute(CommandSender commandSender, String[] strings) {
List<Policy> policies = Config.getInstance().getPolicies(); List<Policy> policies = Config.getInstance().getPolicies();
for (Policy policy : policies) { for (Policy policy : policies) {
if (policy.name().equals(strings[0])) { if (policy.name().equals(strings[0])) {
commandSender.sendMessage(String.format(""" glim.sendMessage(commandSender, String.format("""
Showing info for policy "%s": Showing info for policy "%s":
Type: %s Type: %s
Nodes: %s Nodes: %s
@ -37,4 +36,14 @@ public class PolicyInfo implements Subcommand {
} }
return rstr; return rstr;
} }
@Override
public String description() {
return "Shows info for a specified policy.";
}
@Override
public String usage() {
return "<policy>";
}
} }

View file

@ -6,7 +6,6 @@ import org.bukkit.command.CommandSender;
import java.util.List; import java.util.List;
public class Reload implements Subcommand { public class Reload implements Subcommand {
@Override @Override
public boolean execute(CommandSender commandSender, String [] strings) { public boolean execute(CommandSender commandSender, String [] strings) {
Config.getInstance().load(); Config.getInstance().load();
@ -20,7 +19,12 @@ public class Reload implements Subcommand {
} }
@Override @Override
public String name() { public String description() {
return "reload"; return "Reloads the plugin configuration file.";
}
@Override
public String usage() {
return "";
} }
} }

View file

@ -5,7 +5,8 @@ import org.bukkit.command.CommandSender;
import java.util.List; import java.util.List;
public interface Subcommand { public interface Subcommand {
String name(); String description();
String usage();
@SuppressWarnings("SameReturnValue") @SuppressWarnings("SameReturnValue")
boolean execute(CommandSender commandSender, String[] strings); boolean execute(CommandSender commandSender, String[] strings);
List<String> onTabComplete(CommandSender sender, String[] strings); List<String> onTabComplete(CommandSender sender, String[] strings);

View file

@ -3,6 +3,7 @@ package io.github.adrianvic.nemesiseye.reflection;
import io.github.adrianvic.nemesiseye.policy.Policy; import io.github.adrianvic.nemesiseye.policy.Policy;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@ -12,15 +13,23 @@ import java.util.List;
import java.util.Map; import java.util.Map;
public interface Glimmer { public interface Glimmer {
void onLoad();
List<World> getWorlds();
// Configuration
File loadConfigFile(); File loadConfigFile();
List<Policy> loadPoliciesFromFile(File file); List<Policy> loadPoliciesFromFile(File file);
List<Policy> getApplyingPoliciesForEntity(HumanEntity entity, List<Policy> policies); List<Policy> getApplyingPoliciesForEntity(HumanEntity entity, List<Policy> policies);
void onLoad();
ItemStack getItemInMainHandHumanEntity(HumanEntity entity); // Items
boolean hasItemMeta(ItemStack item); boolean hasItemMeta(ItemStack item);
List<World> getWorlds();
boolean hasEnchantment(ItemStack item, Map<String, String> valuesmap); boolean hasEnchantment(ItemStack item, Map<String, String> valuesmap);
boolean hasAnyEnchantment(ItemStack itemStack); boolean hasAnyEnchantment(ItemStack itemStack);
ItemStack getItemInMainHandHumanEntity(HumanEntity entity);
// Commands
void sendMessage(CommandSender commandSender, String text);
class Box { class Box {
public final double x1, y1, z1, x2, y2, z2; public final double x1, y1, z1, x2, y2, z2;

View file

@ -8,6 +8,7 @@ import io.github.adrianvic.nemesiseye.policy.policies.LocationPolicy;
import io.github.adrianvic.nemesiseye.reflection.Glimmer; import io.github.adrianvic.nemesiseye.reflection.Glimmer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
@ -84,6 +85,11 @@ public class r1_21 implements Glimmer {
return entity.getInventory().getItemInMainHand(); return entity.getInventory().getItemInMainHand();
} }
@Override
public void sendMessage(CommandSender commandSender, String text) {
commandSender.sendMessage(text);
}
@Override @Override
public boolean hasItemMeta(ItemStack item) { public boolean hasItemMeta(ItemStack item) {
return item.getItemMeta() != null; return item.getItemMeta() != null;