mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-27 21:15:57 +01:00
Clean up docs / code for utility classes.
This commit is contained in:
parent
05369b69b6
commit
110aa2e56b
@ -27,11 +27,21 @@
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility methods to deal with blocks.
|
||||||
|
*/
|
||||||
public final class Blocks {
|
public final class Blocks {
|
||||||
|
|
||||||
private 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) {
|
public static List<Block> getConnected(Block block) {
|
||||||
MaterialData data = block.getState().getData();
|
MaterialData data = block.getState().getData();
|
||||||
|
|
||||||
|
@ -23,26 +23,49 @@
|
|||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
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;
|
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;
|
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) {
|
public static void restoreStatistic(Entity entity, DamageCause cause) {
|
||||||
if (cause == DamageCause.DROWNING && entity instanceof LivingEntity) {
|
if (cause == DamageCause.DROWNING && entity instanceof LivingEntity) {
|
||||||
LivingEntity living = (LivingEntity) entity;
|
LivingEntity living = (LivingEntity) entity;
|
||||||
living.setRemainingAir(living.getMaximumAir());
|
living.setRemainingAir(living.getMaximumAir());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFire(cause)) {
|
if (isFireCause(cause)) {
|
||||||
entity.setFireTicks(0);
|
entity.setFireTicks(0);
|
||||||
}
|
}
|
||||||
|
|
@ -29,7 +29,6 @@
|
|||||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -38,23 +37,17 @@
|
|||||||
|
|
||||||
public class RegionQuery {
|
public class RegionQuery {
|
||||||
|
|
||||||
private final WorldGuardPlugin plugin;
|
|
||||||
private final ConfigurationManager config;
|
private final ConfigurationManager config;
|
||||||
private final GlobalRegionManager globalManager;
|
private final GlobalRegionManager globalManager;
|
||||||
@Nullable
|
@Nullable
|
||||||
private final LocalPlayer localPlayer;
|
private final LocalPlayer localPlayer;
|
||||||
|
|
||||||
public RegionQuery(WorldGuardPlugin plugin, @Nullable Player player) {
|
public RegionQuery(WorldGuardPlugin plugin, @Nullable Player player) {
|
||||||
this.plugin = plugin;
|
|
||||||
this.config = plugin.getGlobalStateManager();
|
this.config = plugin.getGlobalStateManager();
|
||||||
this.globalManager = plugin.getGlobalRegionManager();
|
this.globalManager = plugin.getGlobalRegionManager();
|
||||||
this.localPlayer = player != null ? plugin.wrapPlayer(player) : null;
|
this.localPlayer = player != null ? plugin.wrapPlayer(player) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canBuild(Block block) {
|
|
||||||
return canBuild(block.getLocation());
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canBuild(Location location) {
|
public boolean canBuild(Location location) {
|
||||||
World world = location.getWorld();
|
World world = location.getWorld();
|
||||||
WorldConfiguration worldConfig = config.get(world);
|
WorldConfiguration worldConfig = config.get(world);
|
||||||
@ -63,7 +56,7 @@ public boolean canBuild(Location location) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (globalManager.hasBypass(localPlayer, world)) {
|
if (localPlayer != null && globalManager.hasBypass(localPlayer, world)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
RegionManager manager = globalManager.get(location.getWorld());
|
RegionManager manager = globalManager.get(location.getWorld());
|
||||||
@ -79,7 +72,7 @@ public boolean canConstruct(Location location) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (globalManager.hasBypass(localPlayer, world)) {
|
if (localPlayer != null && globalManager.hasBypass(localPlayer, world)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
RegionManager manager = globalManager.get(location.getWorld());
|
RegionManager manager = globalManager.get(location.getWorld());
|
||||||
|
Loading…
Reference in New Issue
Block a user