regionmanager: basic lands plugin integration
This commit is contained in:
@@ -37,13 +37,72 @@ import us.camin.regions.events.RegionRemoveEvent;
|
||||
import us.camin.regions.geometry.RegionSet;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import me.angeschossen.lands.api.land.Land;
|
||||
import me.angeschossen.lands.api.land.Area;
|
||||
import me.angeschossen.lands.api.flags.Flags;
|
||||
import me.angeschossen.lands.api.integration.LandsIntegration;
|
||||
|
||||
public class RegionManager {
|
||||
|
||||
private final LandsIntegration m_lands;
|
||||
|
||||
public enum ValidationResult {
|
||||
VALID,
|
||||
UNKNOWN,
|
||||
NO_PERMISSION,
|
||||
TOO_CLOSE,
|
||||
BAD_NAME,
|
||||
}
|
||||
|
||||
public String validateRegionName(String name, Location location) {
|
||||
Land thisLand = m_lands.getLand(location);
|
||||
if (thisLand == null) {
|
||||
return name;
|
||||
} else {
|
||||
return thisLand.getName();
|
||||
}
|
||||
}
|
||||
|
||||
public ValidationResult validateAnchorPoint(Player player, Location location, String proposedName) {
|
||||
// Require basic permission
|
||||
if (!player.hasPermission("regions.create")) {
|
||||
return ValidationResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
// Allow admins to create regions in unclaimed land
|
||||
Area thisArea = m_lands.getAreaByLoc(location);
|
||||
if (thisArea == null) {
|
||||
if (proposedName == null) {
|
||||
return ValidationResult.BAD_NAME;
|
||||
} else if (player.hasPermission("regions.create.bypass")) {
|
||||
return ValidationResult.VALID;
|
||||
} else {
|
||||
return ValidationResult.NO_PERMISSION;
|
||||
}
|
||||
}
|
||||
|
||||
// For claimed land, require claiming perms to place post
|
||||
if (!thisArea.hasFlag(player, Flags.LAND_CLAIM, false)) {
|
||||
return ValidationResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
// Ensure this is the only region post for this region
|
||||
for (Region region : regionsForWorld(location.getWorld())) {
|
||||
Land thatLand = m_lands.getLand(region.interactLocation());
|
||||
if (thatLand != null && thatLand.getId() == thisArea.getLand().getId()) {
|
||||
return ValidationResult.TOO_CLOSE;
|
||||
}
|
||||
}
|
||||
|
||||
return ValidationResult.VALID;
|
||||
}
|
||||
|
||||
Logger log = Logger.getLogger("Regions.RegionManager");
|
||||
private Map<String, RegionSet> m_regions;
|
||||
private Server m_server;
|
||||
public RegionManager(Plugin plugin, Server server) {
|
||||
m_server = server;
|
||||
m_lands = new LandsIntegration(plugin);
|
||||
log.setLevel(Level.ALL);
|
||||
clear();
|
||||
}
|
||||
|
@@ -185,28 +185,32 @@ public class RegionPostItemWatcher implements Listener {
|
||||
ItemStack compassItem = createCompass(nearest);
|
||||
player.setItemInHand(compassItem);
|
||||
player.sendMessage("Now tracking " + nearest.name());
|
||||
} else if (!event.isCancelled() && isRegionCreateItem(handStack, player) && event.getAction() == Action.RIGHT_CLICK_BLOCK && !event.getClickedBlock().getType().isInteractable() && player.hasPermission("regions.create")) {
|
||||
} else if (!event.isCancelled() && isRegionCreateItem(handStack, player) && event.getAction() == Action.RIGHT_CLICK_BLOCK && !event.getClickedBlock().getType().isInteractable()) {
|
||||
event.setUseItemInHand(Event.Result.DENY);
|
||||
event.setCancelled(true);
|
||||
if (meta.getDisplayName().equals("") || meta.getDisplayName().equals("Region Post Anchor")) {
|
||||
player.sendMessage("You must first give this item a name!");
|
||||
String postName = meta.getDisplayName();
|
||||
if (postName.equals("") || postName.equals("Region Post Anchor")) {
|
||||
postName = null;
|
||||
}
|
||||
postName = m_manager.validateRegionName(postName, event.getClickedBlock().getLocation());
|
||||
RegionManager.ValidationResult result = m_manager.validateAnchorPoint(player, event.getClickedBlock().getLocation(), postName);
|
||||
if (result == RegionManager.ValidationResult.VALID) {
|
||||
Region r = new Region(postName, event.getClickedBlock().getRelative(event.getBlockFace()).getLocation());
|
||||
m_plugin.getServer().getScheduler().runTask(m_plugin, () -> {
|
||||
RegionPostBuilder builder = new RegionPostBuilder(r, m_plugin);
|
||||
builder.build();
|
||||
});
|
||||
handStack.setAmount(handStack.getAmount()-1);
|
||||
player.setItemInHand(handStack);
|
||||
m_plugin.regionManager().addRegion(r);
|
||||
m_plugin.saveRegions();
|
||||
player.sendMessage("You established the region "+r.coloredName());
|
||||
} else if (result == RegionManager.ValidationResult.TOO_CLOSE) {
|
||||
player.sendMessage("You are too close to another region post!");
|
||||
} else if (result == RegionManager.ValidationResult.BAD_NAME) {
|
||||
player.sendMessage("You must first give this item a better name.");
|
||||
} else {
|
||||
Region nearest = m_manager.nearestRegion(event.getClickedBlock().getLocation());
|
||||
if (nearest != null && event.getClickedBlock().getLocation().distance(nearest.interactLocation()) < 500) {
|
||||
int distance = 500 - (int)event.getClickedBlock().getLocation().distance(nearest.interactLocation());
|
||||
player.sendMessage("You are " + distance + " blocks too close to the region post for " + nearest.name() + ".");
|
||||
} else {
|
||||
Region r = new Region(meta.getDisplayName(), event.getClickedBlock().getRelative(event.getBlockFace()).getLocation());
|
||||
m_plugin.getServer().getScheduler().runTask(m_plugin, () -> {
|
||||
RegionPostBuilder builder = new RegionPostBuilder(r, m_plugin);
|
||||
builder.build();
|
||||
});
|
||||
handStack.setAmount(handStack.getAmount()-1);
|
||||
player.setItemInHand(handStack);
|
||||
m_plugin.regionManager().addRegion(r);
|
||||
m_plugin.saveRegions();
|
||||
player.sendMessage("You established the region "+r.coloredName());
|
||||
}
|
||||
player.sendMessage("You aren't allowed to create a region here.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user