mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-28 05:25:20 +01:00
Added config to stop players from trampling crops. Animals don't work yet (blame CraftBukkit)
This commit is contained in:
parent
1e8c91e92f
commit
215b2b5f75
@ -88,6 +88,10 @@ iconomy:
|
||||
chest-protection:
|
||||
enable: off
|
||||
|
||||
crops:
|
||||
disable-creature-trampling: off
|
||||
disable-player-trampling: off
|
||||
|
||||
blacklist:
|
||||
use-as-whitelist: off
|
||||
logging:
|
||||
|
@ -104,6 +104,8 @@ public class WorldConfiguration {
|
||||
public boolean antiWolfDumbness;
|
||||
public boolean signChestProtection;
|
||||
public boolean removeInfiniteStacks;
|
||||
public boolean disableCreatureCropTrampling;
|
||||
public boolean disablePlayerCropTrampling;
|
||||
|
||||
/* Configuration data end */
|
||||
|
||||
@ -182,6 +184,9 @@ private void loadConfiguration() {
|
||||
|
||||
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);
|
||||
highFreqFlags = config.getBoolean("regions.high-frequency-flags", false);
|
||||
regionWand = config.getInt("regions.wand", 287);
|
||||
|
@ -28,13 +28,7 @@
|
||||
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;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Wolf;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.entity.*;
|
||||
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_EXPLODE, 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) {
|
||||
|
||||
|
@ -91,11 +91,13 @@ public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
handleBlockRightClick(event);
|
||||
} else if (event.getAction() == Action.RIGHT_CLICK_AIR) {
|
||||
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
|
||||
*/
|
||||
@ -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
|
||||
*/
|
||||
@ -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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user