use of com.sk89q.worldguard.bukkit.BukkitWorldConfiguration in project MyPet by xXKeyleXx.
the class WorldGuardHook method fixMissingEntityType.
public void fixMissingEntityType(World world, boolean apply) {
if (is7) {
try {
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
com.sk89q.worldedit.world.World w = BukkitAdapter.adapt(world);
BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) cfg.get(w);
if (apply) {
if (missingEntityTypeFixValue.containsKey(world.getName())) {
fixMissingEntityType(world, false);
}
missingEntityTypeFixValue.put(world.getName(), wcfg.blockPluginSpawning);
wcfg.blockPluginSpawning = false;
} else if (missingEntityTypeFixValue.containsKey(world.getName())) {
wcfg.blockPluginSpawning = missingEntityTypeFixValue.get(world.getName());
missingEntityTypeFixValue.remove(world.getName());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of com.sk89q.worldguard.bukkit.BukkitWorldConfiguration in project WorldGuard by EngineHub.
the class WorldGuardBlockListener method onBlockBurn.
/*
* Called when a block is destroyed from burning.
*/
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockBurn(BlockBurnEvent event) {
ConfigurationManager cfg = getConfig();
if (cfg.activityHaltToggle) {
event.setCancelled(true);
return;
}
BukkitWorldConfiguration wcfg = getWorldConfig(event.getBlock().getWorld());
if (wcfg.disableFireSpread) {
event.setCancelled(true);
return;
}
if (wcfg.fireSpreadDisableToggle) {
Block block = event.getBlock();
event.setCancelled(true);
checkAndDestroyFireAround(block.getWorld(), block.getX(), block.getY(), block.getZ());
return;
}
if (!wcfg.disableFireSpreadBlocks.isEmpty()) {
Block block = event.getBlock();
if (wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(block.getType()).getId())) {
event.setCancelled(true);
checkAndDestroyFireAround(block.getWorld(), block.getX(), block.getY(), block.getZ());
return;
}
}
if (wcfg.isChestProtected(BukkitAdapter.adapt(event.getBlock().getLocation()))) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions) {
Block block = event.getBlock();
int x = block.getX();
int y = block.getY();
int z = block.getZ();
ApplicableRegionSet set = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation()));
if (!set.testState(null, Flags.FIRE_SPREAD)) {
checkAndDestroyFireAround(block.getWorld(), x, y, z);
event.setCancelled(true);
}
}
}
use of com.sk89q.worldguard.bukkit.BukkitWorldConfiguration in project WorldGuard by EngineHub.
the class WorldGuardEntityListener method onEntityExplode.
/*
* Called on entity explode.
*/
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityExplode(EntityExplodeEvent event) {
ConfigurationManager cfg = getConfig();
Entity ent = event.getEntity();
if (cfg.activityHaltToggle) {
ent.remove();
event.setCancelled(true);
return;
}
BukkitWorldConfiguration wcfg = getWorldConfig(event.getLocation().getWorld());
if (ent instanceof Creeper) {
if (wcfg.blockCreeperExplosions) {
event.setCancelled(true);
return;
}
if (wcfg.blockCreeperBlockDamage) {
event.blockList().clear();
return;
}
} else if (ent instanceof EnderDragon) {
if (wcfg.blockEnderDragonBlockDamage) {
event.blockList().clear();
return;
}
} else if (ent instanceof TNTPrimed || ent instanceof ExplosiveMinecart) {
if (wcfg.blockTNTExplosions) {
event.setCancelled(true);
return;
}
if (wcfg.blockTNTBlockDamage) {
event.blockList().clear();
return;
}
} else if (ent instanceof Fireball) {
if (ent instanceof WitherSkull) {
if (wcfg.blockWitherSkullExplosions) {
event.setCancelled(true);
return;
}
if (wcfg.blockWitherSkullBlockDamage) {
event.blockList().clear();
return;
}
} else {
if (wcfg.blockFireballExplosions) {
event.setCancelled(true);
return;
}
if (wcfg.blockFireballBlockDamage) {
event.blockList().clear();
return;
}
}
// allow wither skull blocking since there is no dedicated flag atm
if (wcfg.useRegions) {
for (Block block : event.blockList()) {
if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation())).testState(null, Flags.GHAST_FIREBALL)) {
event.blockList().clear();
if (wcfg.explosionFlagCancellation)
event.setCancelled(true);
return;
}
}
}
} else if (ent instanceof Wither) {
if (wcfg.blockWitherExplosions) {
event.setCancelled(true);
return;
}
if (wcfg.blockWitherBlockDamage) {
event.blockList().clear();
return;
}
if (wcfg.useRegions) {
for (Block block : event.blockList()) {
if (!StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(block.getLocation()), (RegionAssociable) null, Flags.WITHER_DAMAGE))) {
event.blockList().clear();
event.setCancelled(true);
return;
}
}
}
} else {
// unhandled entity
if (wcfg.blockOtherExplosions) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions) {
for (Block block : event.blockList()) {
if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation())).testState(null, Flags.OTHER_EXPLOSION)) {
event.blockList().clear();
if (wcfg.explosionFlagCancellation)
event.setCancelled(true);
return;
}
}
}
}
if (wcfg.signChestProtection) {
for (Block block : event.blockList()) {
if (wcfg.isChestProtected(BukkitAdapter.adapt(block.getLocation()))) {
event.blockList().clear();
return;
}
}
}
}
use of com.sk89q.worldguard.bukkit.BukkitWorldConfiguration in project WorldGuard by EngineHub.
the class BlockedPotionsListener method onProjectile.
@EventHandler
public void onProjectile(DamageEntityEvent event) {
if (event.getOriginalEvent() instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent originalEvent = (EntityDamageByEntityEvent) event.getOriginalEvent();
if (Entities.isPotionArrow(originalEvent.getDamager())) {
// should take care of backcompat
BukkitWorldConfiguration wcfg = getWorldConfig(event.getWorld());
PotionEffectType blockedEffect = null;
if (originalEvent.getDamager() instanceof SpectralArrow) {
if (wcfg.blockPotions.contains(PotionEffectType.GLOWING)) {
blockedEffect = PotionEffectType.GLOWING;
}
} else if (originalEvent.getDamager() instanceof Arrow) {
Arrow tippedArrow = (Arrow) originalEvent.getDamager();
PotionEffectType baseEffect = tippedArrow.getBasePotionData().getType().getEffectType();
if (wcfg.blockPotions.contains(baseEffect)) {
blockedEffect = baseEffect;
} else {
for (PotionEffect potionEffect : tippedArrow.getCustomEffects()) {
if (wcfg.blockPotions.contains(potionEffect.getType())) {
blockedEffect = potionEffect.getType();
break;
}
}
}
}
if (blockedEffect != null) {
Player player = event.getCause().getFirstPlayer();
if (player != null) {
if (getPlugin().hasPermission(player, "worldguard.override.potions")) {
return;
}
player.sendMessage(ChatColor.RED + "Sorry, arrows with " + blockedEffect.getName() + " are presently disabled.");
}
event.setCancelled(true);
}
}
}
}
use of com.sk89q.worldguard.bukkit.BukkitWorldConfiguration in project WorldGuard by EngineHub.
the class ChestProtectionListener method onPlaceBlock.
@EventHandler(ignoreCancelled = true)
public void onPlaceBlock(final PlaceBlockEvent event) {
final Player player = event.getCause().getFirstPlayer();
if (player != null) {
final BukkitWorldConfiguration wcfg = getWorldConfig(event.getWorld());
// Early guard
if (!wcfg.signChestProtection) {
return;
}
event.filter(target -> {
if (wcfg.getChestProtection().isChest(BukkitAdapter.asBlockType(event.getEffectiveMaterial())) && wcfg.isChestProtected(BukkitAdapter.adapt(target.getBlock().getLocation()), WorldGuardPlugin.inst().wrapPlayer(player))) {
sendMessage(event, player, ChatColor.DARK_RED + "This spot is for a chest that you don't have permission for.");
return false;
}
return true;
}, true);
}
}
Aggregations