Started interfacing of NodeHandler.
This commit is contained in:
parent
c0bd8a9509
commit
add3c34fad
14 changed files with 80 additions and 31 deletions
|
|
@ -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() {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<>();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
package io.github.adrianvic.regions.policy;
|
||||
|
||||
public enum Action {
|
||||
INTERACT,
|
||||
BREAK,
|
||||
HIT
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue