regionmanager: basic lands plugin integration
This commit is contained in:
parent
669fab22cd
commit
d247953546
11
pom.xml
11
pom.xml
@ -46,6 +46,12 @@
|
||||
<version>2.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.angeschossen</groupId>
|
||||
<artifactId>LandsAPI</artifactId>
|
||||
<version>6.15.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
@ -171,7 +177,10 @@
|
||||
<id>papermc</id>
|
||||
<url>http://papermc.io/repo/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository><id>pl3x-repo</id><url>http://repo.pl3x.net/</url></repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
<repository><id>dynmap-repo</id><url>http://repo.mikeprimm.com/</url></repository>
|
||||
<repository><id>imagej</id><url>http://maven.imagej.net/content/repositories/public/</url></repository>
|
||||
</repositories>
|
||||
|
@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ main: us.camin.regions.Plugin
|
||||
author: Torrie Fischer <tdfischer@hackerbots.net>
|
||||
website: http://hackerbots.net/
|
||||
version: ${version}
|
||||
api-version: 1.16
|
||||
softdepend: [dynmap, ProtocolLib, Pl3xMap]
|
||||
api-version: 1.19
|
||||
softdepend: [dynmap, ProtocolLib, Lands]
|
||||
commands:
|
||||
regions:
|
||||
description: "List available regions."
|
||||
@ -21,6 +21,7 @@ permissions:
|
||||
description: Allows use of all regions permissions
|
||||
children:
|
||||
regions.create: true
|
||||
regions.create.bypass: true
|
||||
regions.commands.*: true
|
||||
regions.regen.*: true
|
||||
regions.bypass.*: true
|
||||
@ -37,6 +38,9 @@ permissions:
|
||||
regions.create:
|
||||
default: true
|
||||
description: Create a region with a region item
|
||||
regions.create.bypass:
|
||||
default: op
|
||||
description: Bypass anything preventing creation of a new region
|
||||
regions.setbanner:
|
||||
default: true
|
||||
description: Allows setting a region post banner
|
||||
|
Loading…
Reference in New Issue
Block a user