Skip to content

Commit

Permalink
Replace <player.region[name]> with <player.location.region[name]>.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcernat committed Jun 26, 2013
1 parent d873c27 commit 3c8fc19
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 31 deletions.
Expand Up @@ -130,7 +130,7 @@ public void listenBreak(BlockBreakEvent event) {
if (event.getPlayer() == player) {

if (region != null)
if (!WorldGuardUtilities.checkPlayerWGRegion(player.getPlayerEntity(), region)) return;
if (!WorldGuardUtilities.checkWGRegion(player.getPlayerEntity().getLocation(), region)) return;

if (blocks.contains(event.getBlock().getType().toString())
|| blocks.contains(String.valueOf(event.getBlock().getTypeId()))) {
Expand All @@ -155,7 +155,7 @@ public void listenCollect(PlayerPickupItemEvent event) {
if (event.getPlayer() == player) {

if (region != null)
if (!WorldGuardUtilities.checkPlayerWGRegion(player.getPlayerEntity(), region)) return;
if (!WorldGuardUtilities.checkWGRegion(player.getPlayerEntity().getLocation(), region)) return;

if (blocks.contains(event.getItem().getItemStack().getType().toString())
|| blocks.contains(String.valueOf(event.getItem().getItemStack().getTypeId()))) {
Expand All @@ -179,7 +179,7 @@ public void listenBucket(PlayerBucketFillEvent event) {
if (event.getPlayer() == player) {

if (region != null)
if (!WorldGuardUtilities.checkPlayerWGRegion(player.getPlayerEntity(), region)) return;
if (!WorldGuardUtilities.checkWGRegion(player.getPlayerEntity().getLocation(), region)) return;

if (blocks.contains(event.getBucket().name().toUpperCase())
|| blocks.contains(String.valueOf(event.getBucket().name().toUpperCase()))) {
Expand All @@ -198,7 +198,7 @@ public void listenPlace(BlockPlaceEvent event) {
if (event.getPlayer() == player) {

if (region != null)
if (!WorldGuardUtilities.checkPlayerWGRegion(player.getPlayerEntity(), region)) return;
if (!WorldGuardUtilities.checkWGRegion(player.getPlayerEntity().getLocation(), region)) return;

if (blocks.contains(event.getBlock().getType().toString())
|| blocks.contains(String.valueOf(event.getBlock().getTypeId()))) {
Expand Down
Expand Up @@ -200,7 +200,7 @@ public void mobKilled(EntityDeathEvent event) {
}
dB.echoDebug("...within range");
if (region != null) {
if (!WorldGuardUtilities.checkPlayerWGRegion(player.getPlayerEntity(), region)) return;
if (!WorldGuardUtilities.checkWGRegion(player.getPlayerEntity().getLocation(), region)) return;
}
dB.echoDebug("...within region");

Expand All @@ -227,7 +227,7 @@ public void blockMined(BlockBreakEvent event) {
}
dB.echoDebug("...within range");
if (region != null) {
if (!WorldGuardUtilities.checkPlayerWGRegion(player.getPlayerEntity(), region)) return;
if (!WorldGuardUtilities.checkWGRegion(player.getPlayerEntity().getLocation(), region)) return;
}
dB.echoDebug("...within region");

Expand All @@ -252,7 +252,7 @@ public void blockPlaced(BlockPlaceEvent event) {
}
dB.echoDebug("...within range");
if (region != null) {
if (!WorldGuardUtilities.checkPlayerWGRegion(player.getPlayerEntity(), region)) return;
if (!WorldGuardUtilities.checkWGRegion(player.getPlayerEntity().getLocation(), region)) return;
}
dB.echoDebug("...within region");

Expand Down
Expand Up @@ -93,7 +93,7 @@ public void listenItem(InventoryClickEvent event)
|| (type == ItemType.SMELT && inventoryType == "FURNACE")) {

if (region != null)
if (!WorldGuardUtilities.checkPlayerWGRegion(player.getPlayerEntity(), region)) return;
if (!WorldGuardUtilities.checkWGRegion(player.getPlayerEntity().getLocation(), region)) return;

// Get the item in the result slot as an ItemStack
final ItemStack item = new ItemStack(event.getCurrentItem());
Expand Down Expand Up @@ -152,7 +152,7 @@ public void listenFish(PlayerFishEvent event)
{

if (region != null)
if (!WorldGuardUtilities.checkPlayerWGRegion(player.getPlayerEntity(), region)) return;
if (!WorldGuardUtilities.checkWGRegion(player.getPlayerEntity().getLocation(), region)) return;

if (event.getState().toString() == "CAUGHT_FISH")
{
Expand Down
Expand Up @@ -158,7 +158,7 @@ public void listen(EntityDeathEvent event) {

// If REGION argument specified, check. If not in region, don't count kill!
if (region != null)
if (!WorldGuardUtilities.checkPlayerWGRegion(player.getPlayerEntity(), region)) return;
if (!WorldGuardUtilities.checkWGRegion(player.getPlayerEntity().getLocation(), region)) return;

// Check type!
if (type == KillType.ENTITY) {
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dLocation.java
Expand Up @@ -4,6 +4,9 @@
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.Utilities;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.depends.Depends;
import net.aufdemrand.denizen.utilities.depends.WorldGuardUtilities;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
Expand Down Expand Up @@ -378,6 +381,18 @@ else return new Element(String.valueOf(this.distance(toLocation)))
if (attribute.startsWith("power"))
return new Element(String.valueOf(getBlock().getBlockPower()))
.getAttribute(attribute.fulfill(1));

if (attribute.startsWith("region")) {
if (Depends.worldGuard == null) {
dB.echoError("Cannot check region! WorldGuard is not loaded!");
return null;
}

String region = attribute.getContext(1);

return new Element(String.valueOf(WorldGuardUtilities.checkWGRegion(this, region)))
.getAttribute(attribute.fulfill(1));
}



Expand Down
12 changes: 0 additions & 12 deletions src/main/java/net/aufdemrand/denizen/objects/dPlayer.java
Expand Up @@ -339,18 +339,6 @@ else if ((float) getPlayerEntity().getFoodLevel() / maxHunger < 1)
return new Element(String.valueOf(Depends.permissions.playerInGroup(getPlayerEntity(), group)))
.getAttribute(attribute.fulfill(1));
}

if (attribute.startsWith("region")) {
if (Depends.worldGuard == null) {
dB.echoError("Cannot check region! WorldGuard is not loaded!");
return null;
}

String region = attribute.getContext(1);

return new Element(String.valueOf(WorldGuardUtilities.checkPlayerWGRegion(getPlayerEntity(), region)))
.getAttribute(attribute.fulfill(1));
}

if (attribute.startsWith("is_flying"))
return new Element(String.valueOf(getPlayerEntity().isFlying()))
Expand Down
Expand Up @@ -56,7 +56,7 @@ public boolean check(RequirementsContext context, List<String> args) throws Requ
/*
* Check if player is in the given region.
*/
outcome = WorldGuardUtilities.checkPlayerWGRegion(context.getPlayer().getPlayerEntity(), region);
outcome = WorldGuardUtilities.checkWGRegion(context.getPlayer().getPlayerEntity().getLocation(), region);

/*
* Display proper debug output
Expand Down
Expand Up @@ -2,7 +2,7 @@

import net.aufdemrand.denizen.utilities.debugging.dB;

import org.bukkit.entity.Player;
import org.bukkit.Location;

import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
Expand All @@ -14,22 +14,25 @@ public class WorldGuardUtilities {
* This method is used to determine if the player is in
* a specified WorldGuard region.
*
* @param thePlayer The player to check
* @param location The location to check
* @param region The WorldGuard region to check
*
* @return returns a boolean value
*/
public static boolean checkPlayerWGRegion(Player thePlayer, String region) {
public static boolean checkWGRegion(Location location, String region) {
if (Depends.worldGuard == null) return false;
boolean inRegion = false;
ApplicableRegionSet currentRegions = Depends.worldGuard.getRegionManager(thePlayer.getWorld()).getApplicableRegions(thePlayer.getLocation());

ApplicableRegionSet currentRegions = Depends.worldGuard.getRegionManager
(location.getWorld()).getApplicableRegions(location);

for(ProtectedRegion thisRegion: currentRegions){
dB.echoDebug("...checking current player region: " + thisRegion.getId());
dB.echoDebug("...checking current region: " + thisRegion.getId());
if (thisRegion.getId().equalsIgnoreCase(region)) {
inRegion = true;

dB.echoDebug("...matched region");
return true;
}
}
return inRegion;
return false;
}
}

0 comments on commit 3c8fc19

Please sign in to comment.