Minor refactoring in PlayerInteractListener and BlockExplodeListener

This commit is contained in:
Intelli 2021-07-22 18:06:24 -06:00
parent ae3768695f
commit 130614bfdd
3 changed files with 466 additions and 486 deletions

View File

@ -29,10 +29,10 @@ import net.coreprotect.model.BlockGroup;
public class BlockExplodeListener extends Queue implements Listener { public class BlockExplodeListener extends Queue implements Listener {
protected static void processBlockExplode(String user, World world, List<Block> b) { protected static void processBlockExplode(String user, World world, List<Block> blockList) {
HashMap<Location, Block> blockMap = new HashMap<>(); HashMap<Location, Block> blockMap = new HashMap<>();
for (Block block : b) { for (Block block : blockList) {
blockMap.put(block.getLocation(), block); blockMap.put(block.getLocation(), block);
} }
@ -46,11 +46,11 @@ public class BlockExplodeListener extends Queue implements Listener {
int z = block.getZ(); int z = block.getZ();
Location[] locationMap = new Location[5]; Location[] locationMap = new Location[5];
locationMap[0] = new Location(world, x + 1, y, z); locationMap[0] = new Location(world, (x + 1), y, z);
locationMap[1] = new Location(world, x - 1, y, z); locationMap[1] = new Location(world, (x - 1), y, z);
locationMap[2] = new Location(world, x, y, z + 1); locationMap[2] = new Location(world, x, y, (z + 1));
locationMap[3] = new Location(world, x, y, z - 1); locationMap[3] = new Location(world, x, y, (z - 1));
locationMap[4] = new Location(world, x, y + 1, z); locationMap[4] = new Location(world, x, (y + 1), z);
int scanMin = 0; int scanMin = 0;
int scanMax = 5; int scanMax = 5;
@ -114,22 +114,20 @@ public class BlockExplodeListener extends Queue implements Listener {
Block block = entry.getValue(); Block block = entry.getValue();
Material blockType = block.getType(); Material blockType = block.getType();
BlockState blockState = block.getState(); BlockState blockState = block.getState();
if (Tag.SIGNS.isTagged(blockType)) { if (Tag.SIGNS.isTagged(blockType) && Config.getConfig(world).SIGN_TEXT) {
if (Config.getConfig(world).SIGN_TEXT) { try {
try { Location location = blockState.getLocation();
Location location = blockState.getLocation(); Sign sign = (Sign) blockState;
Sign sign = (Sign) blockState; String line1 = sign.getLine(0);
String line1 = sign.getLine(0); String line2 = sign.getLine(1);
String line2 = sign.getLine(1); String line3 = sign.getLine(2);
String line3 = sign.getLine(2); String line4 = sign.getLine(3);
String line4 = sign.getLine(3); int color = sign.getColor().getColor().asRGB();
int color = sign.getColor().getColor().asRGB(); boolean isGlowing = BukkitAdapter.ADAPTER.isGlowing(sign);
boolean isGlowing = BukkitAdapter.ADAPTER.isGlowing(sign); Queue.queueSignText(user, location, 0, color, isGlowing, line1, line2, line3, line4, 5);
Queue.queueSignText(user, location, 0, color, isGlowing, line1, line2, line3, line4, 5); }
} catch (Exception e) {
catch (Exception e) { e.printStackTrace();
e.printStackTrace();
}
} }
} }

View File

@ -37,12 +37,12 @@ public final class FoodLevelChangeListener extends Queue implements Listener {
String coordinates = x + "." + y + "." + z + "." + worldId + "." + userUUID; String coordinates = x + "." + y + "." + z + "." + worldId + "." + userUUID;
Object[] data = CacheHandler.interactCache.get(coordinates); Object[] data = CacheHandler.interactCache.get(coordinates);
if (data != null) { if (data != null && data[1] == Material.CAKE) {
long newTime = System.currentTimeMillis(); long newTime = System.currentTimeMillis();
long oldTime = (long) data[0]; long oldTime = (long) data[0];
if ((newTime - oldTime) < 20) { // 50ms = 1 tick if ((newTime - oldTime) < 20) { // 50ms = 1 tick
final BlockState oldBlockState = (BlockState) data[1]; final BlockState oldBlockState = (BlockState) data[2];
Material oldType = oldBlockState.getType(); Material oldType = oldBlockState.getType();
if (oldType.name().endsWith(Material.CAKE.name())) { if (oldType.name().endsWith(Material.CAKE.name())) {