Handle falling Blocks (Sand/Gravel)

This commit is contained in:
Jascha Starke 2013-09-26 10:02:29 +02:00
parent 49b528e352
commit 23525692e1
2 changed files with 34 additions and 8 deletions

View file

@ -5,6 +5,7 @@ import org.bukkit.event.Listener;
import de.jaschastarke.bukkit.lib.CoreModule;
import de.jaschastarke.bukkit.lib.commands.AliasHelpedCommand;
import de.jaschastarke.bukkit.lib.modules.AdditionalBlockBreaks;
import de.jaschastarke.bukkit.lib.modules.BlockFall;
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockListener;
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateCommand;
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateConfig;
@ -47,6 +48,7 @@ public class ModBlockStates extends CoreModule<LimitedCreative> {
if (plugin.getModule(AdditionalBlockBreaks.class) == null) {
plugin.addModule(new AdditionalBlockBreaks(plugin));
}
addModule(new BlockFall(plugin));
listeners.addListener(new BlockListener(this));
listeners.addListener(new HangingListener(this));

View file

@ -8,6 +8,8 @@ import java.util.Map;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.FallingBlock;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -15,17 +17,23 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
import de.jaschastarke.bukkit.lib.events.BlockDestroyedEvent;
import de.jaschastarke.bukkit.lib.events.BlockMovedEvent;
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.DBTransaction;
public class BlockListener implements Listener {
private ModBlockStates mod;
private MetadataValue blockAlreadExtended;
public BlockListener(ModBlockStates mod) {
this.mod = mod;
blockAlreadExtended = new FixedMetadataValue(mod.getPlugin(), new Boolean(true));
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@ -34,11 +42,9 @@ public class BlockListener implements Listener {
return;
if (mod.getModel().isRestricted(event.getBlock())) {
if (mod.isDebug())
mod.getLog().debug("Breaking bad, err.. block: " + event.getBlock().getLocation().toString());
mod.getLog().debug("Breaking bad, err.. block: " + event.getBlock().getLocation().toString() + " was placed by creative. Drop prevented");
if (event.getPlayer().getGameMode() != GameMode.CREATIVE) {
if (mod.isDebug())
mod.getLog().debug("... was placed by creative. Drop prevented");
mod.getBlockSpawn().block(event.getBlock(), event.getPlayer());
event.setExpToDrop(0);
}
@ -52,14 +58,32 @@ public class BlockListener implements Listener {
return;
if (mod.getModel().isRestricted(event.getBlock())) {
if (mod.isDebug())
mod.getLog().debug("Breaking attached block: " + event.getBlock().getLocation().toString());
mod.getLog().debug("Breaking attached block: " + event.getBlock().getLocation().toString() + " was placed by creative. Drop prevented");
if (mod.isDebug())
mod.getLog().debug("... was placed by creative. Drop prevented");
mod.getBlockSpawn().block(event.getBlock());
}
mod.getModel().removeState(event.getBlock());
}
@EventHandler
public void onBlockMoved(BlockMovedEvent event) {
if (mod.getConfig().getIgnoredWorlds().contains(event.getBlock().getWorld().getName()))
return;
mod.getModel().moveState(event.getSource(), event.getBlock());
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityChangeBlock(final EntityChangeBlockEvent event) {
if (event.getEntityType() == EntityType.FALLING_BLOCK) {
if (event.getTo() == Material.AIR) {
if (mod.getModel().isRestricted(event.getBlock())) {
if (mod.isDebug())
mod.getLog().debug("Falling block: " + event.getBlock().getLocation().toString() + " was placed by creative (drop prevented)");
FallingBlock fe = (FallingBlock) event.getEntity();
fe.setDropItem(false);
}
}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlocksBreakByExplosion(EntityExplodeEvent event) {
@ -69,7 +93,7 @@ public class BlockListener implements Listener {
DBTransaction update = mod.getModel().groupUpdate();
for (Block block : event.blockList()) {
if (mod.isDebug())
mod.getLog().debug("Breaking bad, err.. block: " + block.getLocation().toString());
mod.getLog().debug("Breaking bad, err.. block by explosion: " + block.getLocation().toString());
if (states.get(block)) {
if (mod.isDebug())
@ -102,7 +126,7 @@ public class BlockListener implements Listener {
return;
if (event.getBlock().getMetadata("LCBS_pistonIsAlreadyExtended").size() > 0) // Fixes long known Bukkit issue
return;
event.getBlock().setMetadata("LCBS_pistonIsAlreadyExtended", new FixedMetadataValue(mod.getPlugin(), new Boolean(true)));
event.getBlock().setMetadata("LCBS_pistonIsAlreadyExtended", blockAlreadExtended);
Block source = event.getBlock().getRelative(event.getDirection());
/*if (mod.isDebug())