1.0.6-SNAPSHOT #1
45 changed files with 1010 additions and 269 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -2,4 +2,5 @@
|
||||||
build/
|
build/
|
||||||
out/
|
out/
|
||||||
.idea/
|
.idea/
|
||||||
libs/
|
libs/
|
||||||
|
run/
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,25 @@ tasks.register("buildAll") {
|
||||||
dependsOn(tasks.withType<Jar>())
|
dependsOn(tasks.withType<Jar>())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.register<Jar>("shadowJar") {
|
||||||
|
from(sourceSets["main"].output)
|
||||||
|
mcVersions.forEach { ver ->
|
||||||
|
from(sourceSets[ver].output)
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is kinda gross and, essentially, we shouldn't have it here...
|
||||||
|
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||||
|
|
||||||
|
archiveClassifier.set("all-implementations")
|
||||||
|
archiveVersion.set(project.version.toString())
|
||||||
|
|
||||||
|
manifest {
|
||||||
|
attributes(
|
||||||
|
"Implemented-Versions" to mcVersions.joinToString(",")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* ----------------------------------------- */
|
/* ----------------------------------------- */
|
||||||
/* JAVA SETTINGS */
|
/* JAVA SETTINGS */
|
||||||
/* ----------------------------------------- */
|
/* ----------------------------------------- */
|
||||||
|
|
@ -103,4 +122,18 @@ tasks.withType<JavaCompile> {
|
||||||
|
|
||||||
tasks.runServer {
|
tasks.runServer {
|
||||||
minecraftVersion("1.21")
|
minecraftVersion("1.21")
|
||||||
|
downloadPlugins {
|
||||||
|
modrinth("viaversion", "5.7.0")
|
||||||
|
modrinth("luckperms", "v5.5.17-bukkit")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.register("runServerClean") {
|
||||||
|
doFirst {
|
||||||
|
exec {
|
||||||
|
commandLine("rm", "run/plugins/Eye-of-Nemesis/settings.yml")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependsOn("runServer")
|
||||||
}
|
}
|
||||||
34
docs/Nodes.md
Normal file
34
docs/Nodes.md
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
# Nodes
|
||||||
|
Nodes narrow down even further if an action can be done or not. A node needs _properties_ to know what it should check against, for example, a HIT node needs a _list_ of blocks that it will check if the player is holding; while a USE_ENCHANTMENT node needs a mapping of enchantment to level. Some nodes like glyde don't need a value and will ignore if you provide one.
|
||||||
|
```yaml
|
||||||
|
nodes:
|
||||||
|
- [HIT]:
|
||||||
|
values:
|
||||||
|
- 'GOLD_SWORD'
|
||||||
|
- [USE_ENCHANTMENT]:
|
||||||
|
values:
|
||||||
|
- "UNBREAKING": "1"
|
||||||
|
- [GLYDE]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Available nodes
|
||||||
|
### INTERACT
|
||||||
|
Triggered on `InteractionEvent`, returns true when the provided `list` contains the material used to interact.
|
||||||
|
|
||||||
|
### HIT
|
||||||
|
Triggered on `EntityDamageByEntityEvent`, returns true when the provided `list` contains the material used to hit.
|
||||||
|
|
||||||
|
### PLACE
|
||||||
|
Triggered on `BlockPlaceEvent`, returns true when the provided `list` contains the material being placed.
|
||||||
|
|
||||||
|
### BREAK
|
||||||
|
Triggered on `BlockBreakEvent`, returns true when the provided `list` contains the material used to break.
|
||||||
|
|
||||||
|
### EQUIP
|
||||||
|
Triggered on `InventoryClickEvent` and `PlayerInteractEvent` (only if item is an armor), returns true when the provided `list` contains the material being equipped.
|
||||||
|
|
||||||
|
### GLYDE
|
||||||
|
Triggered on `PlayerMoveEvent`, returns true if player is gliding.
|
||||||
|
|
||||||
|
### USE_ENCHANTMENT
|
||||||
|
Triggered on `BlockBreakEvent` and `onEntityDamageByEntityEvent`, returns true the used item has an enchantment matching the provided mapping of enchantment-level.
|
||||||
89
docs/Policies.md
Normal file
89
docs/Policies.md
Normal file
|
|
@ -0,0 +1,89 @@
|
||||||
|
# Policies
|
||||||
|
Policies are a list of nodes with a specific condition to be met, they also determine what effect a node is going to have. Below is an example policy:
|
||||||
|
```yaml
|
||||||
|
- name: "Allow example"
|
||||||
|
type: "location"
|
||||||
|
effect: ALLOW
|
||||||
|
weight: 1
|
||||||
|
worlds: [world]
|
||||||
|
locations:
|
||||||
|
coordinates:
|
||||||
|
- corner1: { x: 2100, y: 256, z: 1400 }
|
||||||
|
corner2: { x: 1000, y: -64, z: 2200 }
|
||||||
|
nodes:
|
||||||
|
- [INTERACT, BREAK, HIT, PLACE]:
|
||||||
|
values:
|
||||||
|
- AIR
|
||||||
|
```
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
### `name`
|
||||||
|
Name of the policy, must not contain spaces or else commands that require you to type the policy name will not work.
|
||||||
|
|
||||||
|
Example: `name: "disable-axe-damage"`
|
||||||
|
|
||||||
|
### `type`
|
||||||
|
One of the policy [types](#Types).
|
||||||
|
|
||||||
|
Example: `type: location`
|
||||||
|
|
||||||
|
### `effect`
|
||||||
|
Can be `deny` to block the action if a node check returns true, `ALLOW` to revert `DENY` effects if the node check is true or `ALLOWONLY` to allow the action **only** if the node check returns true.
|
||||||
|
|
||||||
|
Example: `effect: DENY`
|
||||||
|
|
||||||
|
### `weight`
|
||||||
|
A policy with greater weight will override a conflicting policy of lower weight.
|
||||||
|
|
||||||
|
Example: `weight: 0`
|
||||||
|
|
||||||
|
### `nodes`
|
||||||
|
Must contain a list of node mappings to evaluate if the policy applies to a player.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```yaml
|
||||||
|
nodes:
|
||||||
|
- [HIT]:
|
||||||
|
values:
|
||||||
|
- '.*_AXE$'
|
||||||
|
```
|
||||||
|
|
||||||
|
### `locations`
|
||||||
|
Only used for `type: "location"`, is a list of mappings where corner1 and corner2 should map x, y and z to two corners of a rectangular area where the policy will take effect; `worlds` may be defined here.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
locations:
|
||||||
|
worlds: [world]
|
||||||
|
coordinates:
|
||||||
|
- corner1: { x: 2100, y: 256, z: 1400 }
|
||||||
|
corner2: { x: 1000, y: -64, z: 2200 }
|
||||||
|
```
|
||||||
|
|
||||||
|
### `permissions`
|
||||||
|
Only used for `type: "permission"`, is a list of permissions.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
permissions:
|
||||||
|
- "server.axehit"
|
||||||
|
```
|
||||||
|
|
||||||
|
### `names`
|
||||||
|
Only used for `type: "playerName"`, is a list of player names.
|
||||||
|
|
||||||
|
## Types
|
||||||
|
|
||||||
|
### `global`
|
||||||
|
Always matches.
|
||||||
|
|
||||||
|
### `location`
|
||||||
|
Matches if the player location is inside any rectangle defined in the `locations` property.
|
||||||
|
|
||||||
|
### `playerName`
|
||||||
|
Matches if the player name is in the `names` property.
|
||||||
|
|
||||||
|
### `permission`
|
||||||
|
Matches if the player has a permission in the `permissions` property.
|
||||||
|
|
@ -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,17 +0,0 @@
|
||||||
name: "Eye-of-Nemesis"
|
|
||||||
version: ${version}
|
|
||||||
main: io.github.adrianvic.nemesiseye.Nemesis
|
|
||||||
author: 'Adrian Victor'
|
|
||||||
description: "Change what players can do based in custom criteria."
|
|
||||||
commands:
|
|
||||||
eye:
|
|
||||||
description: "Run /eye help to see all available commands."
|
|
||||||
permissions:
|
|
||||||
nemesiseye.reload:
|
|
||||||
default: op
|
|
||||||
nemesiseye.policy.list.all:
|
|
||||||
default: op
|
|
||||||
nemesiseye.policy.list.self:
|
|
||||||
default: true
|
|
||||||
nemesiseye.help:
|
|
||||||
default: true
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
Policies:
|
|
||||||
# NO SPACES
|
|
||||||
- name: "Block-illegal-items"
|
|
||||||
type: global # global / location / permission / list of types
|
|
||||||
allowList: false # Will deny anything that's not allowed by the nodes if set to true
|
|
||||||
nodes:
|
|
||||||
- useItem:
|
|
||||||
value:
|
|
||||||
- SAND
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
impl.version=b1_7_3
|
|
||||||
|
|
@ -1,24 +1,28 @@
|
||||||
package io.github.adrianvic.nemesiseye;
|
package io.github.adrianvic.nemesiseye;
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.policy.Policy;
|
import io.github.adrianvic.nemesiseye.policy.Policy;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.policies.GlobalPolicy;
|
||||||
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
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 {
|
||||||
private static Config instance = new Config();
|
private static Config instance = new Config();
|
||||||
private final Glimmer glim = Nemesis.getInstance().getGlimmer();
|
private final Glimmer glim = Nemesis.getInstance().getGlimmer();
|
||||||
private File file;
|
private File file;
|
||||||
|
|
||||||
private List<Policy> policies = new ArrayList<>();
|
private List<Policy> policies = new ArrayList<>();
|
||||||
|
|
||||||
private Config() {}
|
private Config() {}
|
||||||
|
|
||||||
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
|
||||||
//
|
//
|
||||||
// public void save() {
|
// public void save() {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
package io.github.adrianvic.nemesiseye;
|
package io.github.adrianvic.nemesiseye;
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -44,38 +41,14 @@ public class DataShifter {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Glimmer.Box> configLocationParser(Object rawLocations) {
|
public static <T extends Enum<T>> T enumOrDefault(Class<T> type, String string, T def) {
|
||||||
Glimmer glim = Nemesis.getInstance().getGlimmer();
|
try {
|
||||||
|
return Enum.valueOf(type, string);
|
||||||
if (rawLocations == null) {
|
} catch (IllegalArgumentException e) {
|
||||||
return List.of();
|
return def;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parsing locations
|
|
||||||
List<?> groups = rawLocations instanceof List ? (List<?>) rawLocations : List.of();
|
|
||||||
|
|
||||||
ArrayList<Glimmer.Box> boxes = new ArrayList<>(groups.size());
|
|
||||||
|
|
||||||
// Now iterate over regions
|
|
||||||
for (Object rObj : groups) {
|
|
||||||
Map<?, ?> region = (Map<?, ?>) rObj;
|
|
||||||
Map<?, ?> c1 = (Map<?, ?>) region.get("corner1");
|
|
||||||
Map<?, ?> c2 = (Map<?, ?>) region.get("corner2");
|
|
||||||
|
|
||||||
double x1 = ((Number) c1.get("x")).doubleValue();
|
|
||||||
double y1 = ((Number) c1.get("y")).doubleValue();
|
|
||||||
double z1 = ((Number) c1.get("z")).doubleValue();
|
|
||||||
|
|
||||||
double x2 = ((Number) c2.get("x")).doubleValue();
|
|
||||||
double y2 = ((Number) c2.get("y")).doubleValue();
|
|
||||||
double z2 = ((Number) c2.get("z")).doubleValue();
|
|
||||||
|
|
||||||
Location loc1 = new Location(glim.getWorlds().getFirst(), x1, y1, z1);
|
|
||||||
Location loc2 = new Location(glim.getWorlds().getFirst(), x2, y2, z2);
|
|
||||||
|
|
||||||
boxes.add(Glimmer.Box.of(loc1, loc2));
|
|
||||||
}
|
|
||||||
|
|
||||||
return boxes;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,126 @@
|
||||||
package io.github.adrianvic.nemesiseye;
|
package io.github.adrianvic.nemesiseye;
|
||||||
|
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.Action;
|
||||||
|
import org.bukkit.Material;
|
||||||
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.inventory.ClickType;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
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.canBreak(event.getPlayer()));
|
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) {
|
ItemStack item = event.getItem();
|
||||||
event.setCancelled(!Validator.canInteract(event.getPlayer()));
|
|
||||||
|
if (item == null || item.getType().isAir()) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Right-click armor equipping
|
||||||
|
if (isArmor(item)
|
||||||
|
&& !Validator.can(event.getPlayer(), Action.EQUIP, event)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normal item interaction
|
||||||
|
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 player) {
|
||||||
event.setCancelled(!Validator.canHit((HumanEntity) event.getDamager()));
|
event.setCancelled(
|
||||||
|
!Validator.can(
|
||||||
|
player,
|
||||||
|
List.of(Action.HIT, Action.USE_ENCHANTMENT),
|
||||||
|
event
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public static void onPlayerMoveEvent(PlayerMoveEvent event) {
|
||||||
|
if (event.getPlayer().isGliding()
|
||||||
|
&& !Validator.can(
|
||||||
|
event.getPlayer(),
|
||||||
|
List.of(Action.GLYDE),
|
||||||
|
event
|
||||||
|
)) {
|
||||||
|
event.getPlayer().setGliding(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onInventoryClickEvent(InventoryClickEvent event) {
|
||||||
|
if (!isArmorEquipAttempt(event)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
HumanEntity entity = event.getWhoClicked();
|
||||||
|
|
||||||
|
if (!Validator.can(entity, Action.EQUIP, event)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isArmorEquipAttempt(InventoryClickEvent event) {
|
||||||
|
if (event.getSlotType() == InventoryType.SlotType.ARMOR) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.isShiftClick()) {
|
||||||
|
return isArmor(event.getCurrentItem());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.getClick() == ClickType.NUMBER_KEY
|
||||||
|
&& event.getSlotType() == InventoryType.SlotType.ARMOR
|
||||||
|
&& event.getWhoClicked() instanceof Player player) {
|
||||||
|
return isArmor(
|
||||||
|
player.getInventory().getItem(event.getHotbarButton())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isArmor(ItemStack item) {
|
||||||
|
if (item == null || item.getType().isAir()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Material type = item.getType();
|
||||||
|
String name = type.name();
|
||||||
|
|
||||||
|
return name.endsWith("_HELMET")
|
||||||
|
|| name.endsWith("_CHESTPLATE")
|
||||||
|
|| name.endsWith("_LEGGINGS")
|
||||||
|
|| name.endsWith("_BOOTS")
|
||||||
|
|| type == Material.ELYTRA;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,13 +1,10 @@
|
||||||
package io.github.adrianvic.nemesiseye;
|
package io.github.adrianvic.nemesiseye;
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
||||||
|
import io.github.adrianvic.nemesiseye.reflection.VersionMatcher;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
public final class Nemesis extends JavaPlugin {
|
public final class Nemesis extends JavaPlugin {
|
||||||
private Glimmer glim;
|
private Glimmer glim;
|
||||||
private static final String VERSION_PROP = "impl.version";
|
private static final String VERSION_PROP = "impl.version";
|
||||||
|
|
@ -16,44 +13,11 @@ public final class Nemesis extends JavaPlugin {
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
instance = this;
|
instance = this;
|
||||||
glim = loadGlim();
|
glim = new VersionMatcher().loadGlim();
|
||||||
glim.onLoad();
|
glim.onLoad();
|
||||||
Config.getInstance().load();
|
Config.getInstance().load();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String readImplVersion() {
|
|
||||||
Properties props = new Properties();
|
|
||||||
try (InputStream is = getClass().getClassLoader()
|
|
||||||
.getResourceAsStream("version.properties")) {
|
|
||||||
if (is == null) {
|
|
||||||
throw new IllegalStateException("version.properties not found on classpath.");
|
|
||||||
}
|
|
||||||
props.load(is);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new IllegalStateException("Failed to load version.properties", e);
|
|
||||||
}
|
|
||||||
String version = props.getProperty(VERSION_PROP);
|
|
||||||
if (version == null || version.isBlank()) {
|
|
||||||
throw new IllegalStateException(VERSION_PROP + " property missing in version.properties.");
|
|
||||||
}
|
|
||||||
return version.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Glimmer loadGlim() {
|
|
||||||
String implVersion = readImplVersion();
|
|
||||||
String className = "io.github.adrianvic.nemesiseye.impl." + implVersion;
|
|
||||||
|
|
||||||
try {
|
|
||||||
Class<?> clazz = Class.forName(className, true, getClass().getClassLoader());
|
|
||||||
if (!Glimmer.class.isAssignableFrom(clazz)) {
|
|
||||||
throw new IllegalStateException(className + " does not implement Glimmer.");
|
|
||||||
}
|
|
||||||
return (Glimmer) clazz.getDeclaredConstructor().newInstance();
|
|
||||||
} catch (ReflectiveOperationException e) {
|
|
||||||
throw new IllegalStateException("Failed to instantiate " + className, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
}
|
}
|
||||||
|
|
@ -61,4 +25,4 @@ public final class Nemesis extends JavaPlugin {
|
||||||
public static Nemesis getInstance() { return instance; }
|
public static Nemesis getInstance() { return instance; }
|
||||||
public Glimmer getGlimmer() { return glim; }
|
public Glimmer getGlimmer() { return glim; }
|
||||||
public PluginManager getPluginManager() { return this.getServer().getPluginManager(); }
|
public PluginManager getPluginManager() { return this.getServer().getPluginManager(); }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,56 +2,53 @@ 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.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 canInteract(HumanEntity entity) {
|
if (!can(entity, action, event)) {
|
||||||
return checkAgainstEntity(entity, Action.INTERACT);
|
return false;
|
||||||
}
|
}
|
||||||
public static boolean canBreak(HumanEntity entity) {
|
|
||||||
return checkAgainstEntity(entity, Action.BREAK);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean canHit(HumanEntity entity) {
|
|
||||||
return checkAgainstEntity(entity, Action.HIT);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean checkAgainstEntity(HumanEntity entity, Action action) {
|
|
||||||
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkAgainstNode(HumanEntity entity, PolicyNode node, Action action) {
|
public static boolean can(HumanEntity entity, Action action, Event event) {
|
||||||
return node.getHandler().allows(entity, node, action);
|
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 true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<PolicyNode> getNodesForPolicies(List<Policy> policies) {
|
|
||||||
List<PolicyNode> nodes = new ArrayList<>();
|
|
||||||
for (Policy p : policies) {
|
|
||||||
nodes.addAll(p.nodes());
|
|
||||||
}
|
|
||||||
return nodes;
|
|
||||||
}
|
|
||||||
|
|
||||||
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<>();
|
||||||
|
|
||||||
for (Policy policy : ps) {
|
for (Policy policy : ps) {
|
||||||
if (policy.applies(entity)) result.add(policy);
|
if (policy.applies(entity)) result.add(policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ public class EyeCore {
|
||||||
else if (commandSender.hasPermission(sub.permission())) {
|
else if (commandSender.hasPermission(sub.permission())) {
|
||||||
return sub.execute(commandSender, Arrays.copyOfRange(strings, 1, strings.length));
|
return sub.execute(commandSender, Arrays.copyOfRange(strings, 1, strings.length));
|
||||||
} else {
|
} else {
|
||||||
Nemesis.getInstance().getLogger().info("does not have %s".formatted(sub.permission()));
|
// Nemesis.getInstance().getLogger().info("does not have %s".formatted(sub.permission()));
|
||||||
Commands.sendNoPermissionError(commandSender);
|
Commands.sendNoPermissionError(commandSender);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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, "location", policy.nodes().size(), policy.allowlist() ? "Is allowlist" : "Is blacklist"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,9 @@ public enum Action {
|
||||||
INTERACT,
|
INTERACT,
|
||||||
BREAK,
|
BREAK,
|
||||||
HIT,
|
HIT,
|
||||||
CRAFT,
|
// TODO CRAFT,
|
||||||
EQUIP
|
EQUIP,
|
||||||
|
PLACE,
|
||||||
|
USE_ENCHANTMENT,
|
||||||
|
GLYDE
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
package io.github.adrianvic.nemesiseye.policy;
|
||||||
|
|
||||||
|
public enum Effect {
|
||||||
|
DENY,
|
||||||
|
ALLOW,
|
||||||
|
}
|
||||||
|
|
@ -1,7 +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 allows(HumanEntity entity, PolicyNode node, Action action);
|
boolean check(HumanEntity entity, PolicyNode node, Action action, Event event);
|
||||||
}
|
}
|
||||||
|
|
@ -1,22 +1,24 @@
|
||||||
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.*;
|
||||||
import io.github.adrianvic.nemesiseye.policy.handlers.useEnchantment;
|
|
||||||
import io.github.adrianvic.nemesiseye.policy.handlers.useItem;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class NodeHandlers {
|
public class NodeHandlers {
|
||||||
private static final Map<String, NodeHandler> handlers = new HashMap<>();
|
private static final Map<Action, NodeHandler> handlers = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
handlers.put("attackWithItemInHand", new attackWith());
|
handlers.put(Action.HIT, new useItem());
|
||||||
handlers.put("useItem", new useItem());
|
handlers.put(Action.PLACE, new bePlaced());
|
||||||
handlers.put("useEnchantment", new useEnchantment());
|
handlers.put(Action.INTERACT, new useItem());
|
||||||
|
handlers.put(Action.USE_ENCHANTMENT, new useEnchantment());
|
||||||
|
handlers.put(Action.GLYDE, new glyde());
|
||||||
|
handlers.put(Action.EQUIP, new equip());
|
||||||
|
handlers.put(Action.BREAK, new useItem()); // TODO: implement place handler
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NodeHandler get(String type) {
|
public static NodeHandler get(Action type) {
|
||||||
return handlers.get(type);
|
return handlers.get(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,34 @@
|
||||||
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 allowlist();
|
boolean policyAllowList();
|
||||||
boolean applies(HumanEntity entity);
|
boolean applies(HumanEntity entity);
|
||||||
|
Effect effect();
|
||||||
|
int weight();
|
||||||
|
List<String> worlds();
|
||||||
|
|
||||||
|
default void addNode(PolicyNode node) {
|
||||||
|
nodes().add(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
default boolean matches(HumanEntity entity, Action action, Event event) {
|
||||||
|
if (!worlds().contains(entity.getWorld().getName())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (PolicyNode node : nodes()) {
|
||||||
|
if (node.matches(entity, action, event)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,36 +1,72 @@
|
||||||
package io.github.adrianvic.nemesiseye.policy;
|
package io.github.adrianvic.nemesiseye.policy;
|
||||||
|
|
||||||
|
import io.github.adrianvic.nemesiseye.DataShifter;
|
||||||
|
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.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public record PolicyNode(String type, List<Object> values, boolean isWhitelist) {
|
public record PolicyNode(List<Action> actions, List<Object> values) {
|
||||||
public static List<PolicyNode> parseNodes(List<Map<String,Object>> raw, boolean isWhitelist) {
|
public static List<PolicyNode> parseNodes(List<Map<Object,Object>> raw, Effect effect) {
|
||||||
List<PolicyNode> nodes = new ArrayList<>();
|
List<PolicyNode> nodes = new ArrayList<>();
|
||||||
|
|
||||||
for (Map<String, Object> m : raw) {
|
for (Map<Object, Object> m : raw) {
|
||||||
for (Map.Entry<String, Object> entry : m.entrySet()) {
|
for (Map.Entry<Object, Object> rawNode : m.entrySet()) {
|
||||||
String type = entry.getKey();
|
List<Action> nodeActions = new ArrayList<>();
|
||||||
List<Object> values = new ArrayList<>();
|
List<Object> nodeValues = new ArrayList<>();
|
||||||
Object val = entry.getValue();
|
|
||||||
|
|
||||||
if (val instanceof Map<?,?> valMap) {
|
if (rawNode.getKey() instanceof List<?> rawTypes && rawNode.getValue() instanceof Map<?,?> rawNodeValues) {
|
||||||
if (valMap.get("values") instanceof String s) {
|
for (Object rawType : rawTypes) {
|
||||||
values.add(s);
|
if (rawType instanceof String rts && !rts.isEmpty() && !(rts == null) && DataShifter.enumOrDefault(Action.class, rts, null) != null) {
|
||||||
} else if (valMap.get("values") instanceof List<?> l) {
|
nodeActions.add(DataShifter.enumOrDefault(Action.class, rts, null));
|
||||||
values.addAll(l);
|
}
|
||||||
} else if (valMap.get("values") instanceof Map<?,?> map) {
|
}
|
||||||
values.add(map);
|
Map<String, Object> semiParsedNodeValue = new HashMap<>();
|
||||||
|
for (Map.Entry<?,?> rawNodeValueEntries : rawNodeValues.entrySet()) {
|
||||||
|
if (rawNodeValueEntries.getKey() instanceof String stringKey) {
|
||||||
|
semiParsedNodeValue.put(stringKey, rawNodeValueEntries.getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes.add(new PolicyNode(type, values, isWhitelist));
|
if (semiParsedNodeValue.get("values") instanceof List<?> l) {
|
||||||
|
for (Object v : l) {
|
||||||
|
nodeValues.add(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!nodeActions.isEmpty() && !nodeValues.isEmpty()) {
|
||||||
|
PolicyNode newNode = new PolicyNode(nodeActions, nodeValues);
|
||||||
|
nodes.add(newNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NodeHandler getHandler() {
|
public List<NodeHandler> getHandler() {
|
||||||
return NodeHandlers.get(type);
|
List<NodeHandler> handlers = new ArrayList<>();
|
||||||
|
for (Action a : actions) {
|
||||||
|
handlers.add(NodeHandlers.get(a));
|
||||||
|
}
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean matches(HumanEntity entity, Action action, Event event) {
|
||||||
|
if (!actions.contains(action)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeHandler handler = NodeHandlers.get(action);
|
||||||
|
|
||||||
|
if (handler == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean result = handler.check(entity, this, action, event);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,47 @@
|
||||||
package io.github.adrianvic.nemesiseye.policy;
|
package io.github.adrianvic.nemesiseye.policy;
|
||||||
|
|
||||||
|
import io.github.adrianvic.nemesiseye.DataShifter;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.policies.Core;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public interface PolicyParser {
|
public interface PolicyParser {
|
||||||
Policy parse(Map<?, ?> raw);
|
default Policy parse(Map<?, ?> raw) {
|
||||||
|
boolean policyAllowList = Boolean.TRUE.equals(raw.get("policyAllowList"));
|
||||||
|
boolean nodesAllowList = Boolean.TRUE.equals(raw.get("nodesAllowList"));
|
||||||
|
Effect effect = DataShifter.enumOrDefault(Effect.class, (String) raw.get("effect"), Effect.DENY);
|
||||||
|
String name = (String) raw.get("name");
|
||||||
|
Integer weightObj = (Integer) raw.get("weight");
|
||||||
|
int weight = weightObj != null ? weightObj : 0;
|
||||||
|
|
||||||
|
// Worlds
|
||||||
|
List<String> worlds = new ArrayList<>();
|
||||||
|
if (raw.get("worlds") instanceof List<?> list) {
|
||||||
|
for (Object object : list) {
|
||||||
|
if (object instanceof String result) {
|
||||||
|
worlds.add(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
worlds.add("world");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nodes
|
||||||
|
Object rawNodes = raw.get("nodes");
|
||||||
|
List<Map<Object, Object>> nodeList = new ArrayList<>();
|
||||||
|
|
||||||
|
if (rawNodes instanceof List<?> list) {
|
||||||
|
for (Object o : list) {
|
||||||
|
if (o instanceof Map<?, ?> map)
|
||||||
|
nodeList.add((Map<Object, Object>) map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<PolicyNode> nodes = PolicyNode.parseNodes(nodeList, effect);
|
||||||
|
return parse(new Core(name, worlds, nodes, nodesAllowList, policyAllowList, effect, weight), raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
Policy parse(Core corePolicy, Map<?, ?> raw);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package io.github.adrianvic.nemesiseye.policy;
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.policy.parser.GlobalPolicyParser;
|
import io.github.adrianvic.nemesiseye.policy.parser.GlobalPolicyParser;
|
||||||
import io.github.adrianvic.nemesiseye.policy.parser.LocationPolicyParser;
|
import io.github.adrianvic.nemesiseye.policy.parser.LocationPolicyParser;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.parser.PermissionPolicyParser;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.parser.PlayerNamePolicyParser;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -12,6 +14,8 @@ public class PolicyParsers {
|
||||||
static {
|
static {
|
||||||
handlers.put("location", new LocationPolicyParser());
|
handlers.put("location", new LocationPolicyParser());
|
||||||
handlers.put("global", new GlobalPolicyParser());
|
handlers.put("global", new GlobalPolicyParser());
|
||||||
|
handlers.put("playerName", new PlayerNamePolicyParser());
|
||||||
|
handlers.put("permission", new PermissionPolicyParser());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PolicyParser get(String type) {
|
public static PolicyParser get(String type) {
|
||||||
|
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
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;
|
|
||||||
|
|
||||||
public class attackWith implements NodeHandler {
|
|
||||||
|
|
||||||
private final static Glimmer glim = Nemesis.getInstance().getGlimmer();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean allows(HumanEntity entity, PolicyNode node, Action action) {
|
|
||||||
if (action == Action.HIT) {
|
|
||||||
for (String s : DataShifter.parseValueToStringList(node.values())) {
|
|
||||||
boolean matches = DataShifter.safeMatches(s, glim.getItemInMainHandHumanEntity(entity).getType().toString());
|
|
||||||
if (matches) return node.isWhitelist();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
package io.github.adrianvic.nemesiseye.policy.handlers;
|
||||||
|
|
||||||
|
import io.github.adrianvic.nemesiseye.DataShifter;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.Action;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.NodeHandler;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
|
|
||||||
|
public class bePlaced implements NodeHandler {
|
||||||
|
@Override
|
||||||
|
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())) {
|
||||||
|
if (DataShifter.safeMatches(s, type)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,84 @@
|
||||||
|
package io.github.adrianvic.nemesiseye.policy.handlers;
|
||||||
|
|
||||||
|
import com.destroystokyo.paper.event.player.PlayerArmorChangeEvent;
|
||||||
|
import io.github.adrianvic.nemesiseye.DataShifter;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.Action;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.NodeHandler;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class equip implements NodeHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean check(HumanEntity entity, PolicyNode node, Action action, Event event) {
|
||||||
|
ItemStack item = null;
|
||||||
|
|
||||||
|
if (event instanceof PlayerArmorChangeEvent e) {
|
||||||
|
// Right click equip, dispenser equip, etc...
|
||||||
|
item = e.getNewItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (event instanceof InventoryClickEvent e) {
|
||||||
|
InventoryType.SlotType slotType = e.getSlotType();
|
||||||
|
|
||||||
|
// Number key swap into armor slot
|
||||||
|
if (e.getClick() == ClickType.NUMBER_KEY
|
||||||
|
&& slotType == InventoryType.SlotType.ARMOR
|
||||||
|
&& entity instanceof Player player) {
|
||||||
|
item = player.getInventory().getItem(e.getHotbarButton());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Shift click armor from inventory
|
||||||
|
else if (e.isShiftClick()) {
|
||||||
|
ItemStack current = e.getCurrentItem();
|
||||||
|
|
||||||
|
if (isArmor(current)) {
|
||||||
|
item = current;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cursor click onto armor slot
|
||||||
|
else if (slotType == InventoryType.SlotType.ARMOR) {
|
||||||
|
ItemStack cursor = e.getCursor();
|
||||||
|
|
||||||
|
if (isArmor(cursor)) {
|
||||||
|
item = cursor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isArmor(item)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String type = item.getType().name();
|
||||||
|
|
||||||
|
for (String s : DataShifter.parseValueToStringList(node.values())) {
|
||||||
|
if (DataShifter.safeMatches(s, type)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isArmor(ItemStack item) {
|
||||||
|
if (item == null || item.getType().isAir()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String name = item.getType().name();
|
||||||
|
|
||||||
|
return name.endsWith("_HELMET")
|
||||||
|
|| name.endsWith("_CHESTPLATE")
|
||||||
|
|| name.endsWith("_LEGGINGS")
|
||||||
|
|| name.endsWith("_BOOTS")
|
||||||
|
|| item.getType() == org.bukkit.Material.ELYTRA;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package io.github.adrianvic.nemesiseye.policy.handlers;
|
||||||
|
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.Action;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.NodeHandler;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
|
public class glyde implements NodeHandler {
|
||||||
|
@Override
|
||||||
|
public boolean check(HumanEntity entity, PolicyNode node, Action action, Event event) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,21 +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;
|
||||||
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 allows(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()));
|
||||||
|
|
||||||
return matches ? node.isWhitelist() : !node.isWhitelist();
|
return matches;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 allows(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 node.isWhitelist();
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return !node.isWhitelist();
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,15 @@
|
||||||
package io.github.adrianvic.nemesiseye.policy.parser;
|
package io.github.adrianvic.nemesiseye.policy.parser;
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.policy.Policy;
|
import io.github.adrianvic.nemesiseye.policy.Policy;
|
||||||
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
|
||||||
import io.github.adrianvic.nemesiseye.policy.PolicyParser;
|
import io.github.adrianvic.nemesiseye.policy.PolicyParser;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.policies.Core;
|
||||||
import io.github.adrianvic.nemesiseye.policy.policies.GlobalPolicy;
|
import io.github.adrianvic.nemesiseye.policy.policies.GlobalPolicy;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class GlobalPolicyParser implements PolicyParser {
|
public class GlobalPolicyParser implements PolicyParser {
|
||||||
@Override
|
@Override
|
||||||
public Policy parse(Map<?, ?> raw) {
|
public Policy parse(Core corePolicy, Map<?, ?> raw) {
|
||||||
boolean allowlist = (boolean) raw.get("allowList");
|
return new GlobalPolicy(corePolicy.name(), corePolicy.worlds(), corePolicy.nodes(), corePolicy.policyAllowList(), corePolicy.effect(), corePolicy.weight());
|
||||||
String name = (String) raw.get("name");
|
|
||||||
|
|
||||||
// Nodes
|
|
||||||
Object rawNodes = raw.get("nodes");
|
|
||||||
List<Map<String, Object>> nodeList = new ArrayList<>();
|
|
||||||
if (rawNodes instanceof List<?> list) {
|
|
||||||
for (Object o : list) {
|
|
||||||
if (o instanceof Map<?, ?> map)
|
|
||||||
nodeList.add((Map<String, Object>) map);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<PolicyNode> nodes = PolicyNode.parseNodes(nodeList, allowlist);
|
|
||||||
|
|
||||||
return new GlobalPolicy(name, nodes, allowlist);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
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.Nemesis;
|
import io.github.adrianvic.nemesiseye.Nemesis;
|
||||||
import io.github.adrianvic.nemesiseye.policy.*;
|
import io.github.adrianvic.nemesiseye.policy.*;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.policies.Core;
|
||||||
import io.github.adrianvic.nemesiseye.policy.policies.LocationPolicy;
|
import io.github.adrianvic.nemesiseye.policy.policies.LocationPolicy;
|
||||||
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -13,24 +14,49 @@ import java.util.Map;
|
||||||
public class LocationPolicyParser implements PolicyParser {
|
public class LocationPolicyParser implements PolicyParser {
|
||||||
private Glimmer glim = Nemesis.getInstance().getGlimmer();
|
private Glimmer glim = Nemesis.getInstance().getGlimmer();
|
||||||
|
|
||||||
public Policy parse(Map<?, ?> raw) {
|
public Policy parse(Core corePolicy, Map<?, ?> raw) {
|
||||||
String name = (String) raw.get("name");
|
Object rawLocations = raw.get("locations");
|
||||||
boolean allowlist = Boolean.TRUE.equals(raw.get("allowList"));
|
Object rawCoordinates = null;
|
||||||
|
List<String> worlds = new ArrayList<>();
|
||||||
|
if (rawLocations instanceof Map<?,?> rawLocationMap) {
|
||||||
|
rawCoordinates = rawLocationMap.get("coordinates");
|
||||||
|
|
||||||
// Nodes
|
if (rawLocationMap.get("worlds") instanceof List<?> rawWorldsList) {
|
||||||
Object rawNodes = raw.get("nodes");
|
for (Object worldObject : rawWorldsList) {
|
||||||
List<Map<String, Object>> nodeList = new ArrayList<>();
|
if (worldObject instanceof String worldString) {
|
||||||
if (rawNodes instanceof List<?> list) {
|
worlds.add(worldString);
|
||||||
for (Object o : list) {
|
}
|
||||||
if (o instanceof Map<?, ?> map)
|
|
||||||
nodeList.add((Map<String, Object>) map);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
worlds.add("world");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
List<PolicyNode> nodes = PolicyNode.parseNodes(nodeList, allowlist);
|
List<Glimmer.Box> locations = new ArrayList<>();
|
||||||
|
|
||||||
List<Glimmer.Box> locations = DataShifter.configLocationParser(raw.get("locations"));
|
// Parsing locations
|
||||||
|
List<?> groups = rawCoordinates instanceof List ? (List<?>) rawCoordinates : List.of();
|
||||||
|
|
||||||
return new LocationPolicy(name, locations, nodes, allowlist);
|
// Now iterate over regions
|
||||||
|
for (Object rObj : groups) {
|
||||||
|
Map<?, ?> region = (Map<?, ?>) rObj;
|
||||||
|
Map<?, ?> c1 = (Map<?, ?>) region.get("corner1");
|
||||||
|
Map<?, ?> c2 = (Map<?, ?>) region.get("corner2");
|
||||||
|
|
||||||
|
double x1 = ((Number) c1.get("x")).doubleValue();
|
||||||
|
double y1 = ((Number) c1.get("y")).doubleValue();
|
||||||
|
double z1 = ((Number) c1.get("z")).doubleValue();
|
||||||
|
|
||||||
|
double x2 = ((Number) c2.get("x")).doubleValue();
|
||||||
|
double y2 = ((Number) c2.get("y")).doubleValue();
|
||||||
|
double z2 = ((Number) c2.get("z")).doubleValue();
|
||||||
|
|
||||||
|
Location loc1 = new Location(glim.getWorlds().getFirst(), x1, y1, z1);
|
||||||
|
Location loc2 = new Location(glim.getWorlds().getFirst(), x2, y2, z2);
|
||||||
|
|
||||||
|
locations.add(Glimmer.Box.of(loc1, loc2));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new LocationPolicy(corePolicy.name(), corePolicy.worlds(), locations, corePolicy.nodes(), corePolicy.nodeAllowlist(), corePolicy.policyAllowList(), corePolicy.effect(), corePolicy.weight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
package io.github.adrianvic.nemesiseye.policy.parser;
|
||||||
|
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.Policy;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.PolicyParser;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.policies.Core;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.policies.PermissionPolicy;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class PermissionPolicyParser implements PolicyParser {
|
||||||
|
@Override
|
||||||
|
public Policy parse(Core corePolicy, Map<?, ?> raw) {
|
||||||
|
Object rawPerms = raw.get("permissions");
|
||||||
|
List<String> permissions = new ArrayList<>();
|
||||||
|
|
||||||
|
if (rawPerms instanceof List<?> list) {
|
||||||
|
for (Object o : list) {
|
||||||
|
if (o instanceof String s) {
|
||||||
|
permissions.add(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PermissionPolicy(corePolicy.name(), corePolicy.worlds(), permissions, corePolicy.nodes(), corePolicy.policyAllowList(), corePolicy.effect(), corePolicy.weight());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
package io.github.adrianvic.nemesiseye.policy.parser;
|
||||||
|
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.Policy;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.PolicyParser;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.policies.Core;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.policies.PlayerNamePolicy;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class PlayerNamePolicyParser implements PolicyParser {
|
||||||
|
@Override
|
||||||
|
public Policy parse(Core corePolicy, Map<?, ?> raw) {
|
||||||
|
Object rawNames = raw.get("names");
|
||||||
|
List<String> names = new ArrayList<>();
|
||||||
|
|
||||||
|
if (rawNames instanceof List<?> list) {
|
||||||
|
for (Object o : list) {
|
||||||
|
if (o instanceof String s) {
|
||||||
|
names.add(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PlayerNamePolicy(corePolicy.name(), corePolicy.worlds(), names, corePolicy.nodes(), corePolicy.effect(), corePolicy.policyAllowList(), corePolicy.weight());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
package io.github.adrianvic.nemesiseye.policy.policies;
|
||||||
|
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.Effect;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.Policy;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public record Core(String name, List<String> worlds, List<PolicyNode> nodes, boolean nodeAllowlist, boolean policyAllowList, Effect effect, int weight) implements Policy {
|
||||||
|
@Override
|
||||||
|
public boolean applies(HumanEntity entity) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
package io.github.adrianvic.nemesiseye.policy.policies;
|
package io.github.adrianvic.nemesiseye.policy.policies;
|
||||||
|
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.Effect;
|
||||||
import io.github.adrianvic.nemesiseye.policy.Policy;
|
import io.github.adrianvic.nemesiseye.policy.Policy;
|
||||||
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public record GlobalPolicy(String name, List<PolicyNode> nodes, boolean allowlist) implements Policy {
|
public record GlobalPolicy(String name, List<String> worlds, 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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package io.github.adrianvic.nemesiseye.policy.policies;
|
package io.github.adrianvic.nemesiseye.policy.policies;
|
||||||
|
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.Effect;
|
||||||
import io.github.adrianvic.nemesiseye.policy.Policy;
|
import io.github.adrianvic.nemesiseye.policy.Policy;
|
||||||
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
||||||
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
||||||
|
|
@ -7,12 +8,14 @@ import org.bukkit.entity.HumanEntity;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public record LocationPolicy(String name, List<Glimmer.Box> locations, List<PolicyNode> nodes, boolean allowlist) implements Policy {
|
public record LocationPolicy(String name, List<String> worlds, List<Glimmer.Box> locations, List<PolicyNode> nodes, boolean nodeAllowlist, boolean policyAllowList, Effect effect, int weight) implements Policy {
|
||||||
@Override
|
@Override
|
||||||
public boolean applies(HumanEntity entity) {
|
public boolean applies(HumanEntity entity) {
|
||||||
for (Glimmer.Box box : locations) {
|
for (Glimmer.Box box : locations) {
|
||||||
if (box.contains(entity.getLocation().toVector())) return true;
|
if (box.contains(entity.getLocation().toVector(), entity.getWorld())) {
|
||||||
|
return !policyAllowList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return policyAllowList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,8 +1,22 @@
|
||||||
package io.github.adrianvic.nemesiseye.policy.policies;
|
package io.github.adrianvic.nemesiseye.policy.policies;
|
||||||
|
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.Effect;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.Policy;
|
||||||
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
||||||
import org.bukkit.permissions.Permission;
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.List;
|
||||||
|
|
||||||
public record PermissionPolicy(String name, ArrayList<Permission> permissions, PolicyNode nodes, boolean allowlist) {}
|
public record PermissionPolicy(String name, List<String> worlds, List<String> permissions, List<PolicyNode> nodes, boolean policyAllowList, Effect effect, int weight) implements Policy {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean applies(HumanEntity entity) {
|
||||||
|
for (String perm : permissions) {
|
||||||
|
if (entity.hasPermission(perm)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,20 @@
|
||||||
package io.github.adrianvic.nemesiseye.policy.policies;
|
package io.github.adrianvic.nemesiseye.policy.policies;
|
||||||
|
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.Effect;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.Policy;
|
||||||
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.List;
|
||||||
|
|
||||||
public record PlayerNamePolicy(String name, ArrayList<String> playerName, PolicyNode nodes, boolean allowlist) {}
|
public record PlayerNamePolicy(String name, List<String> worlds, List<String> playerName, List<PolicyNode> nodes, Effect effect, boolean policyAllowList, int weight) implements Policy {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean applies(HumanEntity entity) {
|
||||||
|
if (playerName.contains(entity.getName())) {
|
||||||
|
return !policyAllowList();
|
||||||
|
} else {
|
||||||
|
return policyAllowList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -11,6 +11,7 @@ import org.bukkit.util.Vector;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public interface Glimmer {
|
public interface Glimmer {
|
||||||
void onLoad();
|
void onLoad();
|
||||||
|
|
@ -32,14 +33,16 @@ public interface Glimmer {
|
||||||
|
|
||||||
class Box {
|
class Box {
|
||||||
public final double x1, y1, z1, x2, y2, z2;
|
public final double x1, y1, z1, x2, y2, z2;
|
||||||
|
public final String world;
|
||||||
|
|
||||||
public Box(double x1, double y1, double z1, double x2, double y2, double z2) {
|
public Box(String world, double x1, double y1, double z1, double x2, double y2, double z2) {
|
||||||
this.x1 = Math.min(x1, x2);
|
this.x1 = Math.min(x1, x2);
|
||||||
this.y1 = Math.min(y1, y2);
|
this.y1 = Math.min(y1, y2);
|
||||||
this.z1 = Math.min(z1, z2);
|
this.z1 = Math.min(z1, z2);
|
||||||
this.x2 = Math.max(x1, x2);
|
this.x2 = Math.max(x1, x2);
|
||||||
this.y2 = Math.max(y1, y2);
|
this.y2 = Math.max(y1, y2);
|
||||||
this.z2 = Math.max(z1, z2);
|
this.z2 = Math.max(z1, z2);
|
||||||
|
this.world = world;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean contains(double x, double y, double z) {
|
public boolean contains(double x, double y, double z) {
|
||||||
|
|
@ -47,13 +50,22 @@ public interface Glimmer {
|
||||||
&& y >= y1 && y <= y2
|
&& y >= y1 && y <= y2
|
||||||
&& z >= z1 && z <= z2;
|
&& z >= z1 && z <= z2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean contains(Vector v) {
|
public boolean contains(Vector v) {
|
||||||
return v.getX() >= x1 && v.getX() <= x2
|
return v.getX() >= x1 && v.getX() <= x2
|
||||||
&& v.getY() >= y1 && v.getY() <= y2
|
&& v.getY() >= y1 && v.getY() <= y2
|
||||||
&& v.getZ() >= z1 && v.getZ() <= z2;
|
&& 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()); }
|
public boolean contains(Vector v, String w) {
|
||||||
|
return (Objects.equals(w, world)) && contains(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(Vector v, World w) {
|
||||||
|
return contains(v, w.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Box of(Location loc1, Location loc2) { return new Box(loc1.getWorld().getName(), loc1.getX(), loc1.getY(), loc1.getZ(), loc2.getX(), loc2.getY(), loc2.getZ()); }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,158 @@
|
||||||
|
package io.github.adrianvic.nemesiseye.reflection;
|
||||||
|
|
||||||
|
import io.github.adrianvic.nemesiseye.DataShifter;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class VersionMatcher {
|
||||||
|
|
||||||
|
public VersionMatcher() {}
|
||||||
|
|
||||||
|
private record Entry(String pattern, String classSuffix) {}
|
||||||
|
|
||||||
|
public String getVersion(String type, String serverVersion) {
|
||||||
|
if (type == null || serverVersion == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, List<Entry>> map = populateMap();
|
||||||
|
List<Entry> entries = map.get(type.toLowerCase());
|
||||||
|
if (entries == null || entries.isEmpty()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Entry e : entries) {
|
||||||
|
if (DataShifter.safeMatches(e.pattern, serverVersion)) {
|
||||||
|
return e.pattern + "|" + e.classSuffix;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Entry> sorted = new ArrayList<>(entries);
|
||||||
|
Collections.sort(sorted, (a, b) -> compareVersions(a.pattern, b.pattern));
|
||||||
|
|
||||||
|
Entry oldest = sorted.get(0);
|
||||||
|
Entry newest = sorted.get(sorted.size() - 1);
|
||||||
|
|
||||||
|
int cmpOldest = compareVersions(serverVersion, oldest.pattern);
|
||||||
|
int cmpNewest = compareVersions(serverVersion, newest.pattern);
|
||||||
|
|
||||||
|
if (cmpOldest < 0) {
|
||||||
|
return oldest.pattern + "|" + oldest.classSuffix;
|
||||||
|
} else if (cmpNewest > 0) {
|
||||||
|
return newest.pattern + "|" + newest.classSuffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
// should not happen because we already tried all patterns
|
||||||
|
return newest.pattern + "|" + newest.classSuffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, List<Entry>> populateMap() {
|
||||||
|
Map<String, List<Entry>> map = new HashMap<>();
|
||||||
|
|
||||||
|
// RELEASE patterns, newest first (order does not matter for matching)
|
||||||
|
map.put("release", List.of(
|
||||||
|
new Entry("^1\\.21\\..*$", "r1_21")
|
||||||
|
));
|
||||||
|
|
||||||
|
// BETA patterns
|
||||||
|
map.put("beta", List.of(
|
||||||
|
new Entry("^1\\.7\\.3$", "b1_7_3")
|
||||||
|
));
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int compareVersions(String v1, String v2) {
|
||||||
|
String clean1 = v1.replaceAll("[^0-9.]", "");
|
||||||
|
String clean2 = v2.replaceAll("[^0-9.]", "");
|
||||||
|
|
||||||
|
String[] a1 = clean1.split("\\.");
|
||||||
|
String[] a2 = clean2.split("\\.");
|
||||||
|
|
||||||
|
int len = Math.max(a1.length, a2.length);
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
int n1 = i < a1.length ? parseInt(a1[i]) : 0;
|
||||||
|
int n2 = i < a2.length ? parseInt(a2[i]) : 0;
|
||||||
|
if (n1 != n2) {
|
||||||
|
return n1 - n2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int parseInt(String s) {
|
||||||
|
try {
|
||||||
|
return Integer.parseInt(s);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Glimmer loadGlim() {
|
||||||
|
String rawVersion;
|
||||||
|
try {
|
||||||
|
rawVersion = Bukkit.getMinecraftVersion(); // returns something like "1.21.10"
|
||||||
|
} catch (NoSuchMethodError e) {
|
||||||
|
return betaLoadGlim();
|
||||||
|
}
|
||||||
|
|
||||||
|
String matchInfo = getVersion("release", rawVersion);
|
||||||
|
if (matchInfo.isEmpty()) {
|
||||||
|
// TODO: Should change to something more robust, it's not beta since we have Bukkit.getMinecraftVersion()
|
||||||
|
return betaLoadGlim();
|
||||||
|
}
|
||||||
|
|
||||||
|
// split the returned string: "pattern|classSuffix"
|
||||||
|
String[] partsInfo = matchInfo.split("\\|");
|
||||||
|
String classSuffix = partsInfo[1]; // e.g. "r1_21"
|
||||||
|
|
||||||
|
String[] versionParts = rawVersion.split("\\.");
|
||||||
|
int major = parseInt(versionParts[0]);
|
||||||
|
int minor = parseInt(versionParts[1]);
|
||||||
|
int patch = versionParts.length > 2 ? parseInt(versionParts[2]) : 0;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
String className = "io.github.adrianvic.nemesiseye.impl." + classSuffix;
|
||||||
|
Glimmer glimmer = tryInstantiate(className);
|
||||||
|
if (glimmer != null) return glimmer;
|
||||||
|
|
||||||
|
if (patch > 0) {
|
||||||
|
patch--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (minor > 0) {
|
||||||
|
minor--;
|
||||||
|
patch = 20;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
className = "io.github.adrianvic.nemesiseye.impl.r" + major + "_" + minor;
|
||||||
|
glimmer = tryInstantiate(className);
|
||||||
|
if (glimmer != null) return glimmer;
|
||||||
|
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"No suitable implementation found for version " + rawVersion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Glimmer betaLoadGlim() {
|
||||||
|
// Bukkit.getVersion() // returns something like "1.1.10 (MC: 1.7.3)" WEIRD
|
||||||
|
return tryInstantiate("io.github.adrianvic.nemesiseye.impl.b1_7_3"); // only supported beta version for now
|
||||||
|
}
|
||||||
|
|
||||||
|
private Glimmer tryInstantiate(String className) {
|
||||||
|
try {
|
||||||
|
Class<?> clazz = Class.forName(className, true, getClass().getClassLoader());
|
||||||
|
if (!Glimmer.class.isAssignableFrom(clazz)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (Glimmer) clazz.getDeclaredConstructor().newInstance();
|
||||||
|
} catch (ReflectiveOperationException ignored) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
name: "Eye-of-Nemesis"
|
name: "Eye-of-Nemesis"
|
||||||
version: ${version}
|
version: ${version}
|
||||||
main: io.github.adrianvic.nemesiseye.Nemesis
|
main: io.github.adrianvic.nemesiseye.Nemesis
|
||||||
api-version: '1.21'
|
api-version: '1.13'
|
||||||
author: 'Adrian Victor'
|
author: 'Adrian Victor'
|
||||||
website: "https://github.io/adrianvic/NemesisEye"
|
website: "https://github.io/adrianvic/NemesisEye"
|
||||||
description: "Change what players can do based in custom criteria."
|
description: "Change what players can do based in custom criteria."
|
||||||
|
|
@ -1,13 +1,65 @@
|
||||||
|
# __ _______ __ ___________________ _______
|
||||||
|
# / / \ _ \ \ \ \_ _____/\_____ \ \ \
|
||||||
|
# / / / /_\ \ \ \ | __)_ / | \ / | \
|
||||||
|
# \ \ \ \_/ \ / / | \/ | \/ | \
|
||||||
|
# \_\ \_____ / /_/ /_______ /\_______ /\____|__ /
|
||||||
|
# \/ \/ \/ \/
|
||||||
|
# EYE OF NEMESIS - Example config file.
|
||||||
|
# Documentation in our wiki: https://github.com/adrianvic/NemesisEye
|
||||||
|
|
||||||
Policies:
|
Policies:
|
||||||
# NO SPACES
|
- name: "Bedrock-allow-admins"
|
||||||
- name: "Beta-1.7.3-items-only"
|
type: "permission"
|
||||||
type: "location"
|
worlds: [world]
|
||||||
allowList: true # Will deny anything that's not allowed by the nodes if set to true
|
effect: ALLOW
|
||||||
locations:
|
weight: 3
|
||||||
- corner1: { x: 2100, y: 256, z: 1400 }
|
permissions:
|
||||||
corner2: { x: 1000, y: -64, z: 2200 }
|
- "server.usebedrock"
|
||||||
nodes:
|
nodes:
|
||||||
- useItem:
|
- [BREAK, PLACE, HIT, INTERACT]:
|
||||||
|
values:
|
||||||
|
- BEDROCK
|
||||||
|
|
||||||
|
- name: "Bedrock-deny"
|
||||||
|
type: "global"
|
||||||
|
worlds: [world]
|
||||||
|
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: DENY # DENY | ALLOW (overrides deny) | ALLOWONLY (allow only if met)
|
||||||
|
worlds: [world]
|
||||||
|
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:
|
||||||
|
worlds: [world]
|
||||||
|
coordinates:
|
||||||
|
- corner1: { x: 2100, y: 256, z: 1400 }
|
||||||
|
corner2: { x: 1000, y: -64, z: 2200 }
|
||||||
|
nodes:
|
||||||
|
- [INTERACT, BREAK, HIT, PLACE]:
|
||||||
|
values:
|
||||||
|
- '.*'
|
||||||
|
- [USE_ENCHANTMENT]:
|
||||||
|
values:
|
||||||
|
- ".*": ".*"
|
||||||
|
|
||||||
|
- name: "Allow-beta-items"
|
||||||
|
type: "location"
|
||||||
|
effect: ALLOW
|
||||||
|
weight: 1
|
||||||
|
worlds: [world]
|
||||||
|
locations:
|
||||||
|
coordinates:
|
||||||
|
- 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
|
||||||
|
|
@ -25,7 +77,7 @@ Policies:
|
||||||
- COBWEB
|
- COBWEB
|
||||||
- PISTON
|
- PISTON
|
||||||
- STICKY_PISTON
|
- STICKY_PISTON
|
||||||
- GRASS
|
- GRASS_BLOCK
|
||||||
- DISPENSER
|
- DISPENSER
|
||||||
- NOTE_BLOCK
|
- NOTE_BLOCK
|
||||||
- SANDSTONE
|
- SANDSTONE
|
||||||
|
|
@ -37,7 +89,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
|
||||||
|
|
@ -106,7 +158,7 @@ Policies:
|
||||||
- FISHING_ROD
|
- FISHING_ROD
|
||||||
- CLOCK
|
- CLOCK
|
||||||
- GLOWSTONE_DUST
|
- GLOWSTONE_DUST
|
||||||
- INK_SACw
|
- INK_SAC
|
||||||
- BONE_MEAL
|
- BONE_MEAL
|
||||||
- SUGAR
|
- SUGAR
|
||||||
- COOKIE
|
- COOKIE
|
||||||
|
|
@ -116,6 +168,4 @@ Policies:
|
||||||
- MUSIC_DISK_CAT
|
- MUSIC_DISK_CAT
|
||||||
- MUSIC_DISK_13
|
- MUSIC_DISK_13
|
||||||
- DIRT
|
- DIRT
|
||||||
- BREAD
|
- BREAD
|
||||||
- useEnchantment:
|
|
||||||
"flying bananas": "0"
|
|
||||||
|
|
@ -2,10 +2,14 @@ package io.github.adrianvic.nemesiseye.impl;
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.Events;
|
import io.github.adrianvic.nemesiseye.Events;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
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.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
|
||||||
public class EventListener implements Listener {
|
public class EventListener implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
|
@ -22,4 +26,15 @@ 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerMoveEvent(PlayerMoveEvent event) { Events.onPlayerMoveEvent(event); }
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
|
public void onInventoryClickEvent(InventoryClickEvent event) { Events.onInventoryClickEvent(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;
|
||||||
|
|
@ -83,10 +84,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 +0,0 @@
|
||||||
impl.version=r1_21
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue