Started interfacing of NodeHandler.
This commit is contained in:
parent
c0bd8a9509
commit
add3c34fad
14 changed files with 80 additions and 31 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
1
.idea/.name
generated
Normal file
1
.idea/.name
generated
Normal file
|
|
@ -0,0 +1 @@
|
|||
regions
|
||||
8
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
8
.idea/inspectionProfiles/Project_Default.xml
generated
Normal 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
9
.idea/mcregions.iml
generated
Normal 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
8
.idea/modules.xml
generated
|
|
@ -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>
|
||||
|
|
@ -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