regionmanager: basic lands plugin integration

This commit is contained in:
Torrie Fischer 2022-09-18 14:11:43 +02:00
parent 669fab22cd
commit d247953546
4 changed files with 98 additions and 22 deletions

11
pom.xml
View File

@ -46,6 +46,12 @@
<version>2.0</version> <version>2.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.github.angeschossen</groupId>
<artifactId>LandsAPI</artifactId>
<version>6.15.0</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>commons-codec</groupId> <groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId> <artifactId>commons-codec</artifactId>
@ -171,7 +177,10 @@
<id>papermc</id> <id>papermc</id>
<url>http://papermc.io/repo/repository/maven-public/</url> <url>http://papermc.io/repo/repository/maven-public/</url>
</repository> </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>dynmap-repo</id><url>http://repo.mikeprimm.com/</url></repository>
<repository><id>imagej</id><url>http://maven.imagej.net/content/repositories/public/</url></repository> <repository><id>imagej</id><url>http://maven.imagej.net/content/repositories/public/</url></repository>
</repositories> </repositories>

View File

@ -37,13 +37,72 @@ import us.camin.regions.events.RegionRemoveEvent;
import us.camin.regions.geometry.RegionSet; import us.camin.regions.geometry.RegionSet;
import java.util.logging.Level; 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 { 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"); Logger log = Logger.getLogger("Regions.RegionManager");
private Map<String, RegionSet> m_regions; private Map<String, RegionSet> m_regions;
private Server m_server; private Server m_server;
public RegionManager(Plugin plugin, Server server) { public RegionManager(Plugin plugin, Server server) {
m_server = server; m_server = server;
m_lands = new LandsIntegration(plugin);
log.setLevel(Level.ALL); log.setLevel(Level.ALL);
clear(); clear();
} }

View File

@ -185,18 +185,17 @@ public class RegionPostItemWatcher implements Listener {
ItemStack compassItem = createCompass(nearest); ItemStack compassItem = createCompass(nearest);
player.setItemInHand(compassItem); player.setItemInHand(compassItem);
player.sendMessage("Now tracking " + nearest.name()); 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.setUseItemInHand(Event.Result.DENY);
event.setCancelled(true); event.setCancelled(true);
if (meta.getDisplayName().equals("") || meta.getDisplayName().equals("Region Post Anchor")) { String postName = meta.getDisplayName();
player.sendMessage("You must first give this item a name!"); if (postName.equals("") || postName.equals("Region Post Anchor")) {
} else { postName = null;
Region nearest = m_manager.nearestRegion(event.getClickedBlock().getLocation()); }
if (nearest != null && event.getClickedBlock().getLocation().distance(nearest.interactLocation()) < 500) { postName = m_manager.validateRegionName(postName, event.getClickedBlock().getLocation());
int distance = 500 - (int)event.getClickedBlock().getLocation().distance(nearest.interactLocation()); RegionManager.ValidationResult result = m_manager.validateAnchorPoint(player, event.getClickedBlock().getLocation(), postName);
player.sendMessage("You are " + distance + " blocks too close to the region post for " + nearest.name() + "."); if (result == RegionManager.ValidationResult.VALID) {
} else { Region r = new Region(postName, event.getClickedBlock().getRelative(event.getBlockFace()).getLocation());
Region r = new Region(meta.getDisplayName(), event.getClickedBlock().getRelative(event.getBlockFace()).getLocation());
m_plugin.getServer().getScheduler().runTask(m_plugin, () -> { m_plugin.getServer().getScheduler().runTask(m_plugin, () -> {
RegionPostBuilder builder = new RegionPostBuilder(r, m_plugin); RegionPostBuilder builder = new RegionPostBuilder(r, m_plugin);
builder.build(); builder.build();
@ -206,7 +205,12 @@ public class RegionPostItemWatcher implements Listener {
m_plugin.regionManager().addRegion(r); m_plugin.regionManager().addRegion(r);
m_plugin.saveRegions(); m_plugin.saveRegions();
player.sendMessage("You established the region "+r.coloredName()); 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 {
player.sendMessage("You aren't allowed to create a region here.");
} }
} }
} }

View File

@ -3,8 +3,8 @@ main: us.camin.regions.Plugin
author: Torrie Fischer <tdfischer@hackerbots.net> author: Torrie Fischer <tdfischer@hackerbots.net>
website: http://hackerbots.net/ website: http://hackerbots.net/
version: ${version} version: ${version}
api-version: 1.16 api-version: 1.19
softdepend: [dynmap, ProtocolLib, Pl3xMap] softdepend: [dynmap, ProtocolLib, Lands]
commands: commands:
regions: regions:
description: "List available regions." description: "List available regions."
@ -21,6 +21,7 @@ permissions:
description: Allows use of all regions permissions description: Allows use of all regions permissions
children: children:
regions.create: true regions.create: true
regions.create.bypass: true
regions.commands.*: true regions.commands.*: true
regions.regen.*: true regions.regen.*: true
regions.bypass.*: true regions.bypass.*: true
@ -37,6 +38,9 @@ permissions:
regions.create: regions.create:
default: true default: true
description: Create a region with a region item description: Create a region with a region item
regions.create.bypass:
default: op
description: Bypass anything preventing creation of a new region
regions.setbanner: regions.setbanner:
default: true default: true
description: Allows setting a region post banner description: Allows setting a region post banner