forked from LogBlock/LogBlock
Added player and creature crop trample logging
This commit is contained in:
@@ -149,8 +149,11 @@ public class LogBlock extends JavaPlugin
|
|||||||
if (isLogging(Logging.CHESTACCESS)) {
|
if (isLogging(Logging.CHESTACCESS)) {
|
||||||
pm.registerEvents(new ChestAccessLogging(this), this);
|
pm.registerEvents(new ChestAccessLogging(this), this);
|
||||||
}
|
}
|
||||||
if (isLogging(Logging.SWITCHINTERACT) || isLogging(Logging.DOORINTERACT) || isLogging(Logging.CAKEEAT) || isLogging(Logging.DIODEINTERACT) || isLogging(Logging.COMPARATORINTERACT) || isLogging(Logging.NOTEBLOCKINTERACT) || isLogging(Logging.PRESUREPLATEINTERACT) || isLogging(Logging.TRIPWIREINTERACT))
|
if (isLogging(Logging.SWITCHINTERACT) || isLogging(Logging.DOORINTERACT) || isLogging(Logging.CAKEEAT) || isLogging(Logging.DIODEINTERACT) || isLogging(Logging.COMPARATORINTERACT) || isLogging(Logging.NOTEBLOCKINTERACT) || isLogging(Logging.PRESUREPLATEINTERACT) || isLogging(Logging.TRIPWIREINTERACT) || isLogging(Logging.CROPTRAMPLE))
|
||||||
pm.registerEvents(new InteractLogging(this), this);
|
pm.registerEvents(new InteractLogging(this), this);
|
||||||
|
if (isLogging(Logging.CREATURECROPTRAMPLE)) {
|
||||||
|
pm.registerEvents(new CreatureInteractLogging(this), this);
|
||||||
|
}
|
||||||
if (isLogging(Logging.KILL))
|
if (isLogging(Logging.KILL))
|
||||||
pm.registerEvents(new KillLogging(this), this);
|
pm.registerEvents(new KillLogging(this), this);
|
||||||
if (isLogging(Logging.CHAT))
|
if (isLogging(Logging.CHAT))
|
||||||
|
@@ -6,8 +6,10 @@ public enum Logging
|
|||||||
GHASTFIREBALLEXPLOSION(true), ENDERDRAGON(true), MISCEXPLOSION, FIRE(true), LEAVESDECAY,
|
GHASTFIREBALLEXPLOSION(true), ENDERDRAGON(true), MISCEXPLOSION, FIRE(true), LEAVESDECAY,
|
||||||
LAVAFLOW, WATERFLOW, CHESTACCESS, KILL, CHAT, SNOWFORM, SNOWFADE, DOORINTERACT,
|
LAVAFLOW, WATERFLOW, CHESTACCESS, KILL, CHAT, SNOWFORM, SNOWFADE, DOORINTERACT,
|
||||||
SWITCHINTERACT, CAKEEAT, ENDERMEN, NOTEBLOCKINTERACT, DIODEINTERACT, COMPARATORINTERACT,
|
SWITCHINTERACT, CAKEEAT, ENDERMEN, NOTEBLOCKINTERACT, DIODEINTERACT, COMPARATORINTERACT,
|
||||||
PRESUREPLATEINTERACT, TRIPWIREINTERACT, NATURALSTRUCTUREGROW, WITHER(true), WITHER_SKULL(true),
|
PRESUREPLATEINTERACT, TRIPWIREINTERACT, CREATURECROPTRAMPLE, CROPTRAMPLE,
|
||||||
BONEMEALSTRUCTUREGROW, WORLDEDIT, TNTMINECARTEXPLOSION(true);
|
NATURALSTRUCTUREGROW, WITHER(true), WITHER_SKULL(true),BONEMEALSTRUCTUREGROW,
|
||||||
|
WORLDEDIT, TNTMINECARTEXPLOSION(true);
|
||||||
|
|
||||||
public static final int length = Logging.values().length;
|
public static final int length = Logging.values().length;
|
||||||
private final boolean defaultEnabled;
|
private final boolean defaultEnabled;
|
||||||
|
|
||||||
|
@@ -0,0 +1,57 @@
|
|||||||
|
package de.diddiz.LogBlock.listeners;
|
||||||
|
|
||||||
|
import de.diddiz.LogBlock.LogBlock;
|
||||||
|
import de.diddiz.LogBlock.Logging;
|
||||||
|
import de.diddiz.LogBlock.config.WorldConfig;
|
||||||
|
import de.diddiz.util.BukkitUtils;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.entity.EntityInteractEvent;
|
||||||
|
|
||||||
|
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
|
||||||
|
|
||||||
|
public class CreatureInteractLogging extends LoggingListener
|
||||||
|
{
|
||||||
|
public CreatureInteractLogging(LogBlock lb) {
|
||||||
|
super(lb);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
public void onEntityInteract(EntityInteractEvent event) {
|
||||||
|
final WorldConfig wcfg = getWorldConfig(event.getEntity().getWorld());
|
||||||
|
|
||||||
|
final EntityType entityType = event.getEntityType();
|
||||||
|
|
||||||
|
// Mobs only
|
||||||
|
if (event.getEntity() instanceof Player || entityType == null) return;
|
||||||
|
|
||||||
|
if (wcfg != null) {
|
||||||
|
final Block clicked = event.getBlock();
|
||||||
|
final Material type = clicked.getType();
|
||||||
|
final int typeId = type.getId();
|
||||||
|
final byte blockData = clicked.getData();
|
||||||
|
final Location loc = clicked.getLocation();
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case SOIL:
|
||||||
|
if (wcfg.isLogging(Logging.CREATURECROPTRAMPLE)) {
|
||||||
|
// 3 = Dirt ID
|
||||||
|
consumer.queueBlock(entityType.getName(), loc, typeId, 3, blockData);
|
||||||
|
// Log the crop on top as being broken
|
||||||
|
Block trampledCrop = clicked.getRelative(BlockFace.UP);
|
||||||
|
if (BukkitUtils.getCropBlocks().contains(trampledCrop.getType())) {
|
||||||
|
consumer.queueBlockBreak("CreatureTrample", trampledCrop.getState());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@@ -1,8 +1,12 @@
|
|||||||
package de.diddiz.LogBlock.listeners;
|
package de.diddiz.LogBlock.listeners;
|
||||||
|
|
||||||
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
|
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
|
||||||
|
|
||||||
|
import de.diddiz.util.BukkitUtils;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@@ -22,11 +26,12 @@ public class InteractLogging extends LoggingListener
|
|||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
final WorldConfig wcfg = getWorldConfig(event.getPlayer().getWorld());
|
final WorldConfig wcfg = getWorldConfig(event.getPlayer().getWorld());
|
||||||
if (wcfg != null) {
|
if (wcfg != null) {
|
||||||
final Material type = event.getClickedBlock().getType();
|
final Block clicked = event.getClickedBlock();
|
||||||
|
final Material type = clicked.getType();
|
||||||
final int typeId = type.getId();
|
final int typeId = type.getId();
|
||||||
final byte blockData = event.getClickedBlock().getData();
|
final byte blockData = clicked.getData();
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
final Location loc = event.getClickedBlock().getLocation();
|
final Location loc = clicked.getLocation();
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case LEVER:
|
case LEVER:
|
||||||
@@ -73,6 +78,17 @@ public class InteractLogging extends LoggingListener
|
|||||||
consumer.queueBlock(player.getName(), loc, typeId, typeId, blockData);
|
consumer.queueBlock(player.getName(), loc, typeId, typeId, blockData);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case SOIL:
|
||||||
|
if (wcfg.isLogging(Logging.CROPTRAMPLE) && event.getAction() == Action.PHYSICAL) {
|
||||||
|
// 3 = Dirt ID
|
||||||
|
consumer.queueBlock(player.getName(), loc, typeId, 3, blockData);
|
||||||
|
// Log the crop on top as being broken
|
||||||
|
Block trampledCrop = clicked.getRelative(BlockFace.UP);
|
||||||
|
if (BukkitUtils.getCropBlocks().contains(trampledCrop.getType())) {
|
||||||
|
consumer.queueBlockBreak(player.getName(), trampledCrop.getState());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -32,6 +32,8 @@ public class BukkitUtils
|
|||||||
private static final Set<Material> relativeTopFallables;
|
private static final Set<Material> relativeTopFallables;
|
||||||
private static final Set<Material> fallingEntityKillers;
|
private static final Set<Material> fallingEntityKillers;
|
||||||
|
|
||||||
|
private static final Set<Material> cropBlocks;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
blockEquivalents = new HashSet<Set<Integer>>(7);
|
blockEquivalents = new HashSet<Set<Integer>>(7);
|
||||||
blockEquivalents.add(new HashSet<Integer>(Arrays.asList(2, 3, 60)));
|
blockEquivalents.add(new HashSet<Integer>(Arrays.asList(2, 3, 60)));
|
||||||
@@ -130,6 +132,14 @@ public class BukkitUtils
|
|||||||
fallingEntityKillers.add(Material.REDSTONE_COMPARATOR_ON);
|
fallingEntityKillers.add(Material.REDSTONE_COMPARATOR_ON);
|
||||||
fallingEntityKillers.add(Material.REDSTONE_COMPARATOR_OFF);
|
fallingEntityKillers.add(Material.REDSTONE_COMPARATOR_OFF);
|
||||||
fallingEntityKillers.add(Material.DAYLIGHT_DETECTOR);
|
fallingEntityKillers.add(Material.DAYLIGHT_DETECTOR);
|
||||||
|
|
||||||
|
// Crop Blocks
|
||||||
|
cropBlocks = new HashSet<Material>(5);
|
||||||
|
cropBlocks.add(Material.CROPS);
|
||||||
|
cropBlocks.add(Material.MELON_STEM);
|
||||||
|
cropBlocks.add(Material.PUMPKIN_STEM);
|
||||||
|
cropBlocks.add(Material.CARROT);
|
||||||
|
cropBlocks.add(Material.POTATO);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final BlockFace[] relativeBlockFaces = new BlockFace[] {
|
private static final BlockFace[] relativeBlockFaces = new BlockFace[] {
|
||||||
@@ -264,6 +274,10 @@ public class BukkitUtils
|
|||||||
return fallingEntityKillers;
|
return fallingEntityKillers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Set<Material> getCropBlocks() {
|
||||||
|
return cropBlocks;
|
||||||
|
}
|
||||||
|
|
||||||
public static String entityName(Entity entity) {
|
public static String entityName(Entity entity) {
|
||||||
if (entity instanceof Player)
|
if (entity instanceof Player)
|
||||||
return ((Player)entity).getName();
|
return ((Player)entity).getName();
|
||||||
|
Reference in New Issue
Block a user