-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Worldguard NPC properties for Wander Provider (#419)
* Adds Worldguard NPC properties for Wander Provider * Switch modern tag format * Props -> Extension
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...ava/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardNPCExtensions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.denizenscript.depenizen.bukkit.properties.worldguard; | ||
|
||
import com.denizenscript.denizen.objects.NPCTag; | ||
import com.denizenscript.denizencore.objects.core.ElementTag; | ||
import com.denizenscript.depenizen.bukkit.objects.worldguard.WorldGuardRegionTag; | ||
import net.citizensnpcs.trait.waypoint.WanderWaypointProvider; | ||
import net.citizensnpcs.trait.waypoint.Waypoints; | ||
import com.sk89q.worldguard.protection.regions.ProtectedRegion; | ||
|
||
public class WorldGuardNPCExtensions { | ||
|
||
public static void register() { | ||
|
||
// <--[tag] | ||
// @attribute <NPCTag.worldguard_wanderregion> | ||
// @returns WorldGuardRegionTag | ||
// @plugin Depenizen, WorldGuard | ||
// @description | ||
// Returns the worldguardRegion for the NPC's wander Waypoint Provider, if that provider is in use. | ||
// --> | ||
NPCTag.tagProcessor.registerTag(WorldGuardRegionTag.class, "worldguard_wanderregion", (attribute, object) -> { | ||
Waypoints waypoints = object.npc.getOrAddTrait(Waypoints.class); | ||
if (waypoints.getCurrentProvider() instanceof WanderWaypointProvider wanderWaypointProvider) { | ||
Object worldGuardRegion = wanderWaypointProvider.getWorldGuardRegion(); | ||
org.bukkit.World world = object.getWorld(); | ||
if ((worldGuardRegion != null) && (world != null)) { | ||
return new WorldGuardRegionTag((ProtectedRegion) worldGuardRegion, world); | ||
} | ||
} | ||
return null; | ||
}); | ||
|
||
// <--[mechanism] | ||
// @object NPCTag | ||
// @name wander_worldguardregion | ||
// @input ElementTag | ||
// @plugin Depenizen, WorldGuard | ||
// @description | ||
// Sets the worldguardRegion for an NPC's wander Waypoints Provider, if that provider is in use. | ||
// @tags | ||
// <NPCTag.wander_worldguardregion> | ||
// --> | ||
NPCTag.tagProcessor.registerMechanism("wander_worldguardregion", false, ElementTag.class, (object, mechanism, input) -> { | ||
Waypoints waypoints = object.npc.getOrAddTrait(Waypoints.class); | ||
if (waypoints.getCurrentProvider() instanceof WanderWaypointProvider wanderWaypointProvider) { | ||
wanderWaypointProvider.setWorldGuardRegion(input.asString()); | ||
} | ||
}); | ||
} | ||
} |