mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-15 23:26:16 +01:00
Add worldguard region support to wander waypoint provider
This commit is contained in:
parent
bc9f74965f
commit
4c33fa4f86
11
main/pom.xml
11
main/pom.xml
@ -16,6 +16,7 @@
|
||||
<craftbukkit.version>1.16.4-R0.1-SNAPSHOT</craftbukkit.version>
|
||||
<citizensapi.version>${project.version}</citizensapi.version>
|
||||
<powermock.version>1.4.12</powermock.version>
|
||||
<worldguard.version>7.0.4</worldguard.version>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
@ -31,6 +32,10 @@
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sk89q-repo</id>
|
||||
<url>https://maven.enginehub.org/repo/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
@ -72,6 +77,12 @@
|
||||
<version>${powermock.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
<artifactId>worldguard-bukkit</artifactId>
|
||||
<version>${worldguard.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<url>http://www.citizensnpcs.co</url>
|
||||
|
@ -21,6 +21,9 @@ import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ForwardingList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
|
||||
import ch.ethz.globis.phtree.PhTreeSolid;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
@ -45,11 +48,14 @@ public class WanderWaypointProvider
|
||||
@Persist
|
||||
public int delay = -1;
|
||||
private NPC npc;
|
||||
private volatile boolean paused;
|
||||
private boolean paused;
|
||||
@Persist
|
||||
private final List<Location> regionCentres = Lists.newArrayList();
|
||||
private PhTreeSolid<Boolean> tree = PhTreeSolid.create(3);
|
||||
@Persist
|
||||
private String worldguardRegion;
|
||||
private Object worldguardRegionCache;
|
||||
@Persist
|
||||
public int xrange = DEFAULT_XRANGE;
|
||||
@Persist
|
||||
public int yrange = DEFAULT_YRANGE;
|
||||
@ -195,6 +201,31 @@ public class WanderWaypointProvider
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (message.startsWith("worldguardregion")) {
|
||||
event.setCancelled(true);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Object region = null;
|
||||
String regionId = message.replace("worldguardregion ", "");
|
||||
try {
|
||||
RegionManager manager = WorldGuard.getInstance().getPlatform().getRegionContainer()
|
||||
.get(BukkitAdapter.adapt(npc.getStoredLocation().getWorld()));
|
||||
region = manager.getRegion(regionId);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (region == null) {
|
||||
Messaging.sendErrorTr(sender, Messages.WANDER_WAYPOINTS_WORLDGUARD_REGION_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
WanderWaypointProvider.this.worldguardRegion = regionId;
|
||||
if (currentGoal != null) {
|
||||
currentGoal.setWorldGuardRegion(region);
|
||||
}
|
||||
Messaging.sendErrorTr(sender, Messages.WANDER_WAYPOINTS_WORLDGUARD_REGION_SET, regionId);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -246,6 +277,23 @@ public class WanderWaypointProvider
|
||||
return new RecalculateList();
|
||||
}
|
||||
|
||||
public Object getWorldGuardRegion() {
|
||||
if (worldguardRegion == null) {
|
||||
return null;
|
||||
}
|
||||
if (worldguardRegionCache != null) {
|
||||
return worldguardRegionCache;
|
||||
}
|
||||
try {
|
||||
RegionManager manager = WorldGuard.getInstance().getPlatform().getRegionContainer()
|
||||
.get(BukkitAdapter.adapt(npc.getStoredLocation().getWorld()));
|
||||
return worldguardRegionCache = manager.getRegion(worldguardRegion);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPaused() {
|
||||
return paused;
|
||||
@ -265,8 +313,8 @@ public class WanderWaypointProvider
|
||||
public void onSpawn(NPC npc) {
|
||||
this.npc = npc;
|
||||
if (currentGoal == null) {
|
||||
currentGoal = WanderGoal.createWithNPCAndRangeAndTreeAndFallback(npc, xrange, yrange,
|
||||
WanderWaypointProvider.this, WanderWaypointProvider.this);
|
||||
currentGoal = WanderGoal.createWithNPCAndRangeAndTreeAndFallbackAndRegion(npc, xrange, yrange,
|
||||
WanderWaypointProvider.this, WanderWaypointProvider.this, getWorldGuardRegion());
|
||||
currentGoal.setDelay(delay);
|
||||
}
|
||||
Iterator<GoalEntry> itr = npc.getDefaultGoalController().iterator();
|
||||
|
@ -384,6 +384,8 @@ public class Messages {
|
||||
public static final String WANDER_WAYPOINTS_RANGE_SET = "citizens.editors.waypoints.wander.range-set";
|
||||
public static final String WANDER_WAYPOINTS_REGION_EDITING_START = "citizens.editors.waypoints.wander.editing-regions";
|
||||
public static final String WANDER_WAYPOINTS_REMOVED_REGION = "citizens.editors.waypoints.wander.removed-region";
|
||||
public static final String WANDER_WAYPOINTS_WORLDGUARD_REGION_NOT_FOUND = "citizens.editors.waypoints.wander.worldguard-region-not-found";
|
||||
public static final String WANDER_WAYPOINTS_WORLDGUARD_REGION_SET = "citizens.editors.waypoints.wander.worldguard-region-set";
|
||||
public static final String WAYPOINT_ADDED = "citizens.commands.waypoints.add.waypoint-added";
|
||||
public static final String WAYPOINT_PROVIDER_SET = "citizens.waypoints.set-provider";
|
||||
public static final String WAYPOINT_TELEPORTING_DISABLED = "citizens.commands.waypoints.disableteleporting.disabled";
|
||||
|
@ -320,8 +320,10 @@ citizens.editors.text.remove-prompt=Enter the index of the entry you wish to rem
|
||||
citizens.editors.text.removed-entry=[[Removed]] entry at index [[{0}]].
|
||||
citizens.editors.text.start-prompt=Type [[add]] to add an entry, [[edit]] to edit entries, [[remove]] to remove entries, [[close]] to toggle the NPC to send messages when players get close, [[item]] to set the talk item in hand pattern (set to [[default]] to clear), [[range]] to set the talking range, [[delay]] to set the talking delay in seconds and [[random]] to toggle the NPC as a random talker. Type [[help]] to show this again.
|
||||
citizens.editors.text.talk-item-set=[[Talk item pattern]] set to [[{0}]].
|
||||
citizens.editors.waypoints.wander.worldguard-region-not-found=WorldGuard region not found.
|
||||
citizens.editors.waypoints.wander.worldguard-region-set=WorldGuard region set to [[{0}]].
|
||||
citizens.editors.waypoints.wander.range-set=Wander range set to xrange [[{0}]] and yrange [[{1}]].
|
||||
citizens.editors.waypoints.wander.begin=<b>Entered the wander waypoint editor.<br> Type [[xrange <number>]] or [[yrange <number>]] to modify the random wander range. Type [[regions]] to enter the region editor.<br>Type [[delay <ticks>]] to delay the NPC between wanders.
|
||||
citizens.editors.waypoints.wander.begin=<b>Entered the wander waypoint editor.<br> Type [[xrange <number>]] or [[yrange <number>]] to modify the random wander range. Type [[regions]] to enter the region editor.<br>Type [[delay <ticks>]] to delay the NPC between wanders. Type [[worldguardregion <regionId>]] to restrict movement to a WorldGuard region.
|
||||
citizens.editors.waypoints.wander.end=Exited the wander waypoint editor.
|
||||
citizens.editors.waypoints.wander.delay-set=Delay between wanders set to [[{0}]] ticks.
|
||||
citizens.editors.waypoints.wander.invalid-delay=Invalid delay specified.
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: Citizens
|
||||
authors: [fullwall]
|
||||
softdepend: [Vault, PlaceholderAPI]
|
||||
softdepend: [Vault, PlaceholderAPI, WorldGuard]
|
||||
version: ${project.version} (build ${BUILD_NUMBER})
|
||||
main: net.citizensnpcs.Citizens
|
||||
website: http://www.citizensnpcs.co
|
||||
|
Loading…
Reference in New Issue
Block a user