Started interfacing of NodeHandler.

This commit is contained in:
天クマ 2025-12-04 22:19:21 -03:00
commit add3c34fad
14 changed files with 80 additions and 31 deletions

Binary file not shown.

1
.idea/.name generated Normal file
View file

@ -0,0 +1 @@
regions

View file

@ -0,0 +1,8 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="CommentedOutCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="minLines" value="3" />
</inspection_tool>
</profile>
</component>

9
.idea/mcregions.iml generated Normal file
View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

8
.idea/modules.xml generated
View file

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/modules/regions.main.iml" filepath="$PROJECT_DIR$/.idea/modules/regions.main.iml" />
</modules>
</component>
</project>

View file

@ -1,4 +1,4 @@
# Regions
Regions is a Minecraft Paper plugin that allows server admins to write *policies* that will deny or allow (black/whitelist) players to do specific things.
You can create policies based on player location, hence the name **Regions**, but other types of policies are available, like permission and player-name policy.
You can create policies based on player location, hence the name **Regions**, but other types of policies are available, like permission and player-name policy.

View file

@ -14,8 +14,8 @@ public class Config {
private YamlConfiguration config;
private List<LocationPolicy> locationPolicies;
private List<PermissionPolicy> permissionPolicies;
private List<PlayerNamePolicy> playerNamePolicies;
// private List<PermissionPolicy> permissionPolicies;
// private List<PlayerNamePolicy> playerNamePolicies;
private Config() {
}

View file

@ -1,38 +1,28 @@
package io.github.adrianvic.regions;
import io.github.adrianvic.regions.policy.PolicyNode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class Validator {
ArrayList<Material> blacklistedItems = new ArrayList<Material>();
public Validator() {
blacklistedItems.add(Material.COPPER_SWORD);
blacklistedItems.add(Material.COPPER_AXE);
blacklistedItems.add(Material.COPPER_HOE);
blacklistedItems.add(Material.ROTTEN_FLESH);
public static boolean canInteract(HumanEntity entity) {
return true;
}
public boolean isHumanoidAbleToHit(HumanEntity damager) {
return isItemValid(damager.getInventory().getItemInMainHand().getType());
public static boolean canBreak(HumanEntity entity) {
return true;
}
public boolean isHumanoidAbleToHarvest(HumanEntity harvester) {
return isItemValid(harvester.getInventory().getItemInMainHand().getType());
public static boolean canHit(HumanEntity entity) {
return true;
}
public boolean isItemValid(Material item) {
return !blacklistedItems.contains(item);
}
public void warnPlayer(Player player) {
Location loc = player.getLocation();
loc.getWorld().strikeLightningEffect(loc);
player.sendMessage("Please note that you are not allowed to do this here!");
public static List<PolicyNode> getPoliciesFor(HumanEntity entity) {
return new ArrayList<>();
}
}

View file

@ -0,0 +1,7 @@
package io.github.adrianvic.regions.policy;
public enum Action {
INTERACT,
BREAK,
HIT
}

View file

@ -0,0 +1,7 @@
package io.github.adrianvic.regions.policy;
import org.bukkit.entity.HumanEntity;
public interface NodeHandler {
boolean allows(HumanEntity entity, PolicyNode node, Action action);
}

View file

@ -0,0 +1,18 @@
package io.github.adrianvic.regions.policy;
import io.github.adrianvic.regions.policy.handlers.attackWith;
import java.util.HashMap;
import java.util.Map;
public class NodeHandlers {
private static final Map<String, NodeHandler> handlers = new HashMap<>();
static {
handlers.put("attackWithItemInHand", new attackWith());
}
public static NodeHandler get(String type) {
return handlers.get(type);
}
}

View file

@ -0,0 +1,17 @@
package io.github.adrianvic.regions.policy.handlers;
import io.github.adrianvic.regions.policy.Action;
import io.github.adrianvic.regions.policy.NodeHandler;
import io.github.adrianvic.regions.policy.PolicyNode;
import org.bukkit.entity.HumanEntity;
public class attackWith implements NodeHandler {
@Override
public boolean allows(HumanEntity entity, PolicyNode node, Action action) {
if (action == Action.HIT) {
if (node.values().contains(entity.getMainHand() )) return false; // nope
}
return true;
}
}