From 3cb9b90ef08b33ecc985720f7d411824b77f3b8c Mon Sep 17 00:00:00 2001 From: Wizjany Date: Sun, 3 Apr 2011 05:48:32 -0400 Subject: [PATCH 1/3] Added config to disable damage from falling into the void. --- config_world.yml | 4 ++- .../worldguard/bukkit/WorldConfiguration.java | 25 +++++++++++-------- .../bukkit/WorldGuardEntityListener.java | 25 +++++++++++++------ 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/config_world.yml b/config_world.yml index d7d91914..1e0e25ca 100644 --- a/config_world.yml +++ b/config_world.yml @@ -67,6 +67,8 @@ player-damage: disable-suffocation-damage: off disable-contact-damage: off teleport-on-suffocation: off + disable-void-damage: off + teleport-on-void-falling: off regions: enable: on @@ -96,4 +98,4 @@ blacklist: file: enable: on path: worldguard/logs/%w-%Y-%m-%d.log - open-files: 10 \ No newline at end of file + open-files: 10 diff --git a/src/com/sk89q/worldguard/bukkit/WorldConfiguration.java b/src/com/sk89q/worldguard/bukkit/WorldConfiguration.java index cfdfbeaf..80861490 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldConfiguration.java +++ b/src/com/sk89q/worldguard/bukkit/WorldConfiguration.java @@ -36,7 +36,7 @@ /** * Holds the configuration for individual worlds. - * + * * @author sk89q * @author Michael */ @@ -86,6 +86,8 @@ public class WorldConfiguration { public boolean disableDrowningDamage; public boolean disableSuffocationDamage; public boolean teleportOnSuffocation; + public boolean disableVoidDamage; + public boolean teleportOnVoid; public boolean useRegions; public boolean highFreqFlags; public int regionWand = 287; @@ -102,18 +104,18 @@ public class WorldConfiguration { /** * Construct the object. - * - * @param plugin - * @param worldName + * + * @param plugin + * @param worldName */ public WorldConfiguration(WorldGuardPlugin plugin, String worldName) { File baseFolder = new File(plugin.getDataFolder(), "worlds/" + worldName); configFile = new File(baseFolder, "config.yml"); blacklistFile = new File(baseFolder, "blacklist.txt"); - + this.plugin = plugin; this.worldName = worldName; - + WorldGuardPlugin.createDefaultConfiguration(configFile, "config_world.yml"); WorldGuardPlugin.createDefaultConfiguration(blacklistFile, "blacklist.txt"); @@ -128,7 +130,7 @@ public WorldConfiguration(WorldGuardPlugin plugin, String worldName) { private void loadConfiguration() { Configuration config = new Configuration(this.configFile); config.load(); - + enforceOneSession = config.getBoolean("protection.enforce-single-session", true); itemDurability = config.getBoolean("protection.item-durability", true); @@ -136,7 +138,7 @@ private void loadConfiguration() { simulateSponge = config.getBoolean("simulation.sponge.enable", true); spongeRadius = Math.max(1, config.getInt("simulation.sponge.radius", 3)) - 1; redstoneSponges = config.getBoolean("simulation.sponge.redstone", false); - + pumpkinScuba = config.getBoolean("pumpkin-scuba", false); noPhysicsGravel = config.getBoolean("physics.no-physics-gravel", false); @@ -169,6 +171,9 @@ private void loadConfiguration() { disableSuffocationDamage = config.getBoolean("player-damage.disable-suffocation-damage", false); disableContactDamage = config.getBoolean("player-damage.disable-contact-damage", false); teleportOnSuffocation = config.getBoolean("player-damage.teleport-on-suffocation", false); + disableVoidDamage = config.getBoolean("player-damage.disable-void-damage", false); + //this is pretty useless since presumably there won't be much above them if they fall into a big hole + teleportOnVoid = config.getBoolean("player-damage.teleport-on-void-falling", false); useRegions = config.getBoolean("regions.enable", true); highFreqFlags = config.getBoolean("regions.high-frequency-flags", false); @@ -184,7 +189,7 @@ private void loadConfiguration() { blockCreatureSpawn = new HashSet(); for (String creatureName : config.getStringList("mobs.block-creature-spawn", null)) { CreatureType creature = CreatureType.fromName(creatureName); - + if (creature == null) { logger.warning("WorldGuard: Unknown mob type '" + creatureName + "'"); } else { @@ -265,7 +270,7 @@ private void loadConfiguration() { logger.log(Level.INFO, preventLavaFire ? "WorldGuard: (" + worldName + ") Lava fire is blocked." : "WorldGuard: (" + worldName + ") Lava fire is PERMITTED."); - + if (disableFireSpread) { logger.log(Level.INFO, "WorldGuard: (" + worldName + ") All fire spread is disabled."); } else { diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java b/src/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java index 009a1b33..00e566ad 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java @@ -92,7 +92,18 @@ public void onEntityDamageByBlock(EntityDamageByBlockEvent event) { event.setCancelled(true); return; } - + + if (wcfg.teleportOnVoid && type == DamageCause.VOID) { + findFreePosition(player); + event.setCancelled(true); + return; + } + + if (wcfg.disableVoidDamage && type == DamageCause.VOID) { + event.setCancelled(true); + return; + } + } } @@ -226,18 +237,18 @@ public void onEntityDamage(EntityDamageEvent event) { } } else if (defender instanceof Player) { Player player = (Player) defender; - + if (cfg.hasGodMode(player)) { event.setCancelled(true); return; } - + if (type == DamageCause.DROWNING && cfg.hasAmphibiousMode(player)) { player.setRemainingAir(player.getMaximumAir()); event.setCancelled(true); return; } - + if (type == DamageCause.DROWNING && wcfg.pumpkinScuba && (player.getInventory().getHelmet().getType() == Material.PUMPKIN || player.getInventory().getHelmet().getType() == Material.JACK_O_LANTERN)) { @@ -263,7 +274,7 @@ public void onEntityDamage(EntityDamageEvent event) { return; } - if (wcfg.teleportOnSuffocation && type == DamageCause.SUFFOCATION) { + if (wcfg.teleportOnSuffocation && type == DamageCause.SUFFOCATION) { findFreePosition(player); event.setCancelled(true); return; @@ -334,9 +345,9 @@ public void onCreatureSpawn(CreatureSpawnEvent event) { ConfigurationManager cfg = plugin.getGlobalConfiguration(); WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld()); - + //CreatureType creaType = (CreatureType) CreatureType.valueOf(event.getMobType().toString()); - CreatureType creaType = event.getCreatureType(); + CreatureType creaType = event.getCreatureType(); Boolean cancelEvent = false; if (wcfg.blockCreatureSpawn.contains(creaType)) { From 355c89ecab28316e90a80749db232cbb339099b1 Mon Sep 17 00:00:00 2001 From: Wizjany Date: Sun, 3 Apr 2011 11:25:04 -0400 Subject: [PATCH 2/3] Added missing default global config option to file. --- config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/config.yml b/config.yml index e2cd2eba..96113580 100644 --- a/config.yml +++ b/config.yml @@ -18,6 +18,7 @@ # Remember to check the compatibility spreadsheet for WorldGuard to see # if any features are currently broken in your version of Bukkit. # +suppress-tick-sync-warnings: false # For permissions, see http://wiki.sk89q.com/wiki/WorldGuard/Permissions/Bukkit permissions: From 104b7c2cf283b3e143300108e75b282d3c3cc178 Mon Sep 17 00:00:00 2001 From: Wizjany Date: Mon, 4 Apr 2011 01:36:52 -0400 Subject: [PATCH 3/3] Fixed falling into void and wolves still taking damage. Requires Craftbukkit 638+ --- .../worldguard/bukkit/WorldConfiguration.java | 1 - .../bukkit/WorldGuardEntityListener.java | 32 +++++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/com/sk89q/worldguard/bukkit/WorldConfiguration.java b/src/com/sk89q/worldguard/bukkit/WorldConfiguration.java index 80861490..42212342 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldConfiguration.java +++ b/src/com/sk89q/worldguard/bukkit/WorldConfiguration.java @@ -172,7 +172,6 @@ private void loadConfiguration() { disableContactDamage = config.getBoolean("player-damage.disable-contact-damage", false); teleportOnSuffocation = config.getBoolean("player-damage.teleport-on-suffocation", false); disableVoidDamage = config.getBoolean("player-damage.disable-void-damage", false); - //this is pretty useless since presumably there won't be much above them if they fall into a big hole teleportOnVoid = config.getBoolean("player-damage.teleport-on-void-falling", false); useRegions = config.getBoolean("regions.enable", true); diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java b/src/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java index 00e566ad..21394971 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java @@ -18,16 +18,15 @@ */ package com.sk89q.worldguard.bukkit; -import com.sk89q.worldguard.protection.flags.DefaultFlag; -import com.sk89q.worldguard.protection.managers.RegionManager; import org.bukkit.event.Event.Priority; import org.bukkit.event.Event; import org.bukkit.plugin.PluginManager; -import com.sk89q.worldguard.protection.ApplicableRegionSet; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.entity.CreatureType; import org.bukkit.entity.Creeper; import org.bukkit.entity.Skeleton; @@ -37,10 +36,16 @@ import org.bukkit.entity.Wolf; import org.bukkit.event.entity.*; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; + import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BlockType; + import static com.sk89q.worldguard.bukkit.BukkitUtil.*; +import com.sk89q.worldguard.protection.flags.DefaultFlag; +import com.sk89q.worldguard.protection.managers.RegionManager; +import com.sk89q.worldguard.protection.ApplicableRegionSet; + public class WorldGuardEntityListener extends EntityListener { /** @@ -72,12 +77,17 @@ public void onEntityDamageByBlock(EntityDamageByBlockEvent event) { Entity defender = event.getEntity(); DamageCause type = event.getCause(); - if (defender instanceof Player) { + ConfigurationManager cfg = plugin.getGlobalConfiguration(); + WorldConfiguration wcfg = cfg.get(defender.getWorld()); + + if (defender instanceof Wolf) { + if (wcfg.antiWolfDumbness && !(type == DamageCause.VOID)) { + event.setCancelled(true); + return; + } + } else if (defender instanceof Player) { Player player = (Player) defender; - ConfigurationManager cfg = plugin.getGlobalConfiguration(); - WorldConfiguration wcfg = cfg.get(player.getWorld()); - if (cfg.hasGodMode(player)) { event.setCancelled(true); return; @@ -402,13 +412,17 @@ public void findFreePosition(Player player) { } if (free == 2) { - if (y - 1 != origY) { + if (y - 1 != origY || y == 1) { loc.setX(x + 0.5); loc.setY(y); loc.setZ(z + 0.5); + if (y <= 2 && world.getBlockAt(x,0,z).getType() == Material.AIR) { + world.getBlockAt(x,0,z).setTypeId(20); + loc.setY(2); + } + player.setFallDistance(0F); player.teleport(loc); } - return; }