forked from LogBlock/LogBlock
Log signs broken by relative block breaks
This commit is contained in:
@@ -2,6 +2,8 @@ package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
|
||||
import static de.diddiz.LogBlock.config.Config.isLogging;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@@ -10,6 +12,7 @@ import org.bukkit.event.player.PlayerBucketFillEvent;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import de.diddiz.LogBlock.config.WorldConfig;
|
||||
import de.diddiz.util.BukkitUtils;
|
||||
|
||||
public class BlockBreakLogging extends LoggingListener
|
||||
{
|
||||
@@ -28,8 +31,18 @@ public class BlockBreakLogging extends LoggingListener
|
||||
consumer.queueContainerBreak(event.getPlayer().getName(), event.getBlock().getState());
|
||||
else if (type == 79)
|
||||
consumer.queueBlockReplace(event.getPlayer().getName(), event.getBlock().getState(), 9, (byte)0);
|
||||
else
|
||||
else {
|
||||
consumer.queueBlockBreak(event.getPlayer().getName(), event.getBlock().getState());
|
||||
List<Location> nearbySigns = BukkitUtils.getBlocksNearby(event.getBlock(), BukkitUtils.getRelativeBreakables());
|
||||
if(nearbySigns.size() != 0) {
|
||||
for(Location location : nearbySigns) {
|
||||
int blockType = location.getBlock().getTypeId();
|
||||
if (wcfg.isLogging(Logging.SIGNTEXT) && (blockType == 63 || type == 68))
|
||||
consumer.queueSignBreak(event.getPlayer().getName(), (Sign) location.getBlock().getState());
|
||||
consumer.queueBlockBreak(event.getPlayer().getName(), location.getBlock().getState());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -7,11 +7,13 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.DoubleChest;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -24,6 +26,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
public class BukkitUtils
|
||||
{
|
||||
private static final Set<Set<Integer>> blockEquivalents;
|
||||
private static final Set<Integer> relativeBreakable;
|
||||
|
||||
static {
|
||||
blockEquivalents = new HashSet<Set<Integer>>(7);
|
||||
@@ -34,6 +37,34 @@ public class BukkitUtils
|
||||
blockEquivalents.add(new HashSet<Integer>(Arrays.asList(73, 74)));
|
||||
blockEquivalents.add(new HashSet<Integer>(Arrays.asList(75, 76)));
|
||||
blockEquivalents.add(new HashSet<Integer>(Arrays.asList(93, 94)));
|
||||
|
||||
relativeBreakable = new HashSet<Integer>(2);
|
||||
relativeBreakable.add(63); // Sign
|
||||
relativeBreakable.add(68); // Sign
|
||||
relativeBreakable.add(65); // Ladder
|
||||
relativeBreakable.add(77); // Button
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of block locations around the block that are of the type specified by the integer list parameter
|
||||
*
|
||||
* @param block
|
||||
* @param type
|
||||
* @return List of block locations around the block that are of the type specified by the integer list parameter
|
||||
*/
|
||||
public static List<Location> getBlocksNearby(org.bukkit.block.Block block, Set<Integer> type) {
|
||||
ArrayList<Location> blocks = new ArrayList<Location>();
|
||||
if(type.contains(block.getRelative(BlockFace.EAST).getTypeId()))
|
||||
blocks.add(block.getRelative(BlockFace.EAST).getLocation());
|
||||
if(type.contains(block.getRelative(BlockFace.WEST).getTypeId()))
|
||||
blocks.add(block.getRelative(BlockFace.WEST).getLocation());
|
||||
if(type.contains(block.getRelative(BlockFace.NORTH).getTypeId()))
|
||||
blocks.add(block.getRelative(BlockFace.NORTH).getLocation());
|
||||
if(type.contains(block.getRelative(BlockFace.SOUTH).getTypeId()))
|
||||
blocks.add(block.getRelative(BlockFace.SOUTH).getLocation());
|
||||
if(type.contains(block.getRelative(BlockFace.UP).getTypeId()))
|
||||
blocks.add(block.getRelative(BlockFace.UP).getLocation());
|
||||
return blocks;
|
||||
}
|
||||
|
||||
public static int getInventoryHolderType(InventoryHolder holder) {
|
||||
@@ -131,6 +162,10 @@ public class BukkitUtils
|
||||
return blockEquivalents;
|
||||
}
|
||||
|
||||
public static Set<Integer> getRelativeBreakables() {
|
||||
return relativeBreakable;
|
||||
}
|
||||
|
||||
public static String entityName(Entity entity) {
|
||||
if (entity instanceof Player)
|
||||
return ((Player)entity).getName();
|
||||
|
Reference in New Issue
Block a user