Added config to stop players from trampling crops. Animals don't work yet (blame CraftBukkit)

This commit is contained in:
Wizjany 2011-04-15 12:20:15 +08:00 committed by
parent 1e8c91e92f
commit 215b2b5f75
4 changed files with 48 additions and 9 deletions

View File

@ -88,6 +88,10 @@ iconomy:
chest-protection: chest-protection:
enable: off enable: off
crops:
disable-creature-trampling: off
disable-player-trampling: off
blacklist: blacklist:
use-as-whitelist: off use-as-whitelist: off
logging: logging:

View File

@ -104,6 +104,8 @@ public class WorldConfiguration {
public boolean antiWolfDumbness; public boolean antiWolfDumbness;
public boolean signChestProtection; public boolean signChestProtection;
public boolean removeInfiniteStacks; public boolean removeInfiniteStacks;
public boolean disableCreatureCropTrampling;
public boolean disablePlayerCropTrampling;
/* Configuration data end */ /* Configuration data end */
@ -182,6 +184,9 @@ private void loadConfiguration() {
signChestProtection = config.getBoolean("chest-protection.enable", false); signChestProtection = config.getBoolean("chest-protection.enable", false);
disableCreatureCropTrampling = config.getBoolean("crops.disable-creature-trampling", false);
disablePlayerCropTrampling = config.getBoolean("crops.disable-player-trampling", false);
useRegions = config.getBoolean("regions.enable", true); useRegions = config.getBoolean("regions.enable", true);
highFreqFlags = config.getBoolean("regions.high-frequency-flags", false); highFreqFlags = config.getBoolean("regions.high-frequency-flags", false);
regionWand = config.getInt("regions.wand", 287); regionWand = config.getInt("regions.wand", 287);

View File

@ -28,13 +28,7 @@
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.CreatureType; import org.bukkit.entity.*;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Wolf;
import org.bukkit.event.entity.*; import org.bukkit.event.entity.*;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
@ -70,8 +64,24 @@ public void registerEvents() {
pm.registerEvent(Event.Type.ENTITY_DAMAGE, this, Priority.High, plugin); pm.registerEvent(Event.Type.ENTITY_DAMAGE, this, Priority.High, plugin);
pm.registerEvent(Event.Type.ENTITY_EXPLODE, this, Priority.High, plugin); pm.registerEvent(Event.Type.ENTITY_EXPLODE, this, Priority.High, plugin);
pm.registerEvent(Event.Type.CREATURE_SPAWN, this, Priority.High, plugin); pm.registerEvent(Event.Type.CREATURE_SPAWN, this, Priority.High, plugin);
pm.registerEvent(Event.Type.ENTITY_INTERACT, this, Priority.High, plugin);
} }
@Override
public void onEntityInteract(EntityInteractEvent event) {
//bukkit doesn't actually throw this event yet, someone add a ticket to leaky
Entity entity = event.getEntity();
Block block = event.getBlock();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(entity.getWorld());
if (block.getType() == Material.SOIL) {
if (entity instanceof Creature && wcfg.disableCreatureCropTrampling) {
event.setCancelled(true);
}
}
}
public void onEntityDamageByBlock(EntityDamageByBlockEvent event) { public void onEntityDamageByBlock(EntityDamageByBlockEvent event) {

View File

@ -91,11 +91,13 @@ public void onPlayerInteract(PlayerInteractEvent event) {
handleBlockRightClick(event); handleBlockRightClick(event);
} else if (event.getAction() == Action.RIGHT_CLICK_AIR) { } else if (event.getAction() == Action.RIGHT_CLICK_AIR) {
handleAirRightClick(event); handleAirRightClick(event);
} else if (event.getAction() == Action.PHYSICAL) {
handlePhysicalInteract(event);
} }
} }
/** /**
* Called when a block is damaged. * Called when a player right clicks air.
* *
* @param event * @param event
*/ */
@ -123,7 +125,7 @@ public void handleAirRightClick(PlayerInteractEvent event) {
} }
/** /**
* Called when a block is damaged. * Called when a player right clicks a block.
* *
* @param event * @param event
*/ */
@ -314,6 +316,24 @@ public void handleBlockRightClick(PlayerInteractEvent event) {
}*/ }*/
} }
/**
* Called when a player steps on a pressure plate or tramples crops.
*
* @param event
*/
public void handlePhysicalInteract(PlayerInteractEvent event) {
if (event.isCancelled() == true) return;
Player player = event.getPlayer();
Block block = event.getClickedBlock(); //not actually clicked but whatever
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(player.getWorld());
if (block.getType() == Material.SOIL && wcfg.disablePlayerCropTrampling) {
event.setCancelled(true);
}
}
/** /**
* Called when a player joins a server * Called when a player joins a server
* *