Clean up docs / code for utility classes.

This commit is contained in:
sk89q 2014-08-11 17:54:32 -07:00
parent 05369b69b6
commit 110aa2e56b
3 changed files with 40 additions and 14 deletions

View File

@ -27,11 +27,21 @@
import java.util.Collections;
import java.util.List;
/**
* Utility methods to deal with blocks.
*/
public final class Blocks {
private Blocks() {
}
/**
* Get a list of connected blocks to the given block, not including
* the given block.
*
* @param block the block
* @return a list of connected blocks, not including the given block
*/
public static List<Block> getConnected(Block block) {
MaterialData data = block.getState().getData();

View File

@ -23,26 +23,49 @@
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
public final class DamageCauses {
/**
* Utility methods to deal with event-related enums in Bukkit.
*/
public final class EventEnums {
private DamageCauses() {
private EventEnums() {
}
public static boolean isFire(DamageCause cause) {
/**
* Return whether the given damage cause is fire-reltaed.
*
* @param cause the cause
* @return true if fire related
*/
public static boolean isFireCause(DamageCause cause) {
return cause == DamageCause.FIRE || cause == DamageCause.FIRE_TICK;
}
public static boolean isExplosion(DamageCause cause) {
/**
* Return whether the given cause is an explosion.
*
* @param cause the cause
* @return true if it is an explosion cuase
*/
public static boolean isExplosionCause(DamageCause cause) {
return cause == DamageCause.BLOCK_EXPLOSION || cause == DamageCause.ENTITY_EXPLOSION;
}
/**
* Restore the statistic associated with the given cause. For example,
* for the {@link DamageCause#DROWNING} cause, the entity would have its
* air level set to its maximum.
*
* @param entity the entity
* @param cause the cuase
*/
public static void restoreStatistic(Entity entity, DamageCause cause) {
if (cause == DamageCause.DROWNING && entity instanceof LivingEntity) {
LivingEntity living = (LivingEntity) entity;
living.setRemainingAir(living.getMaximumAir());
}
if (isFire(cause)) {
if (isFireCause(cause)) {
entity.setFireTicks(0);
}

View File

@ -29,7 +29,6 @@
import com.sk89q.worldguard.protection.managers.RegionManager;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import javax.annotation.Nullable;
@ -38,23 +37,17 @@
public class RegionQuery {
private final WorldGuardPlugin plugin;
private final ConfigurationManager config;
private final GlobalRegionManager globalManager;
@Nullable
private final LocalPlayer localPlayer;
public RegionQuery(WorldGuardPlugin plugin, @Nullable Player player) {
this.plugin = plugin;
this.config = plugin.getGlobalStateManager();
this.globalManager = plugin.getGlobalRegionManager();
this.localPlayer = player != null ? plugin.wrapPlayer(player) : null;
}
public boolean canBuild(Block block) {
return canBuild(block.getLocation());
}
public boolean canBuild(Location location) {
World world = location.getWorld();
WorldConfiguration worldConfig = config.get(world);
@ -63,7 +56,7 @@ public boolean canBuild(Location location) {
return true;
}
if (globalManager.hasBypass(localPlayer, world)) {
if (localPlayer != null && globalManager.hasBypass(localPlayer, world)) {
return true;
} else {
RegionManager manager = globalManager.get(location.getWorld());
@ -79,7 +72,7 @@ public boolean canConstruct(Location location) {
return true;
}
if (globalManager.hasBypass(localPlayer, world)) {
if (localPlayer != null && globalManager.hasBypass(localPlayer, world)) {
return true;
} else {
RegionManager manager = globalManager.get(location.getWorld());