Updates for 1.19.3: Log hanging signs and add some missing materials

This commit is contained in:
Brokkonaut
2023-02-07 04:30:24 +01:00
parent b3e829d1be
commit d347a25a02
5 changed files with 236 additions and 216 deletions

View File

@ -36,8 +36,6 @@ import org.bukkit.World;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Waterlogged;
import org.bukkit.block.data.type.Sign;
import org.bukkit.block.data.type.WallSign;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
@ -346,7 +344,7 @@ public class Consumer extends Thread {
* The four lines on the sign.
*/
public void queueSignChange(Actor actor, Location loc, BlockData type, String[] lines) {
if ((!(type instanceof Sign) && !(type instanceof WallSign)) || lines == null || lines.length != 4) {
if (!BukkitUtils.getAllSignMaterials().contains(type.getMaterial())) {
return;
}
queueBlock(actor, loc, type, type, null, BlockStateCodecSign.serialize(lines), null);

View File

@ -13,7 +13,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
public class BlockStateCodecSign implements BlockStateCodec {
@Override
public Material[] getApplicableMaterials() {
return BukkitUtils.getAllSignsArray();
return BukkitUtils.getAllSignMaterials().toArray(new Material[BukkitUtils.getAllSignMaterials().size()]);
}
@Override
@ -54,7 +54,9 @@ public class BlockStateCodecSign implements BlockStateCodec {
*/
public static YamlConfiguration serialize(String[] lines) {
YamlConfiguration conf = new YamlConfiguration();
if (lines != null) {
conf.set("lines", Arrays.asList(lines));
}
return conf;
}

View File

@ -66,29 +66,64 @@ public class InteractLogging extends LoggingListener {
lastInteractionBlockData = blockData;
lastInteractionLocation = loc;
switch (type) {
case OAK_FENCE_GATE:
case SPRUCE_FENCE_GATE:
case BIRCH_FENCE_GATE:
case JUNGLE_FENCE_GATE:
case ACACIA_FENCE_GATE:
case DARK_OAK_FENCE_GATE:
case WARPED_FENCE_GATE:
case CRIMSON_FENCE_GATE:
case OAK_TRAPDOOR:
case SPRUCE_TRAPDOOR:
case BIRCH_TRAPDOOR:
case JUNGLE_TRAPDOOR:
case ACACIA_TRAPDOOR:
case DARK_OAK_TRAPDOOR:
case WARPED_TRAPDOOR:
case CRIMSON_TRAPDOOR:
if (BukkitUtils.isFenceGate(type) || BukkitUtils.isWoodenTrapdoor(type)) {
if (wcfg.isLogging(Logging.DOORINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Openable newBlockData = (Openable) blockData.clone();
newBlockData.setOpen(!newBlockData.isOpen());
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
}
break;
} else if (BukkitUtils.isPressurePlate(type)) {
if (wcfg.isLogging(Logging.PRESUREPLATEINTERACT) && event.getAction() == Action.PHYSICAL) {
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, blockData);
}
} else if (BukkitUtils.isWoodenDoor(type)) {
if (wcfg.isLogging(Logging.DOORINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Door newBlockData = (Door) blockData.clone();
newBlockData.setOpen(!newBlockData.isOpen());
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
}
} else if (BukkitUtils.isButton(type) || type == Material.LEVER) {
if (wcfg.isLogging(Logging.SWITCHINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Switch newBlockData = (Switch) blockData.clone();
if (!newBlockData.isPowered() || type == Material.LEVER) {
newBlockData.setPowered(!newBlockData.isPowered());
}
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
}
} else if (BukkitUtils.isSign(type)) {
if (wcfg.isLogging(Logging.SIGNTEXT) && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getItem() != null) {
Material itemType = event.getItem().getType();
if (BukkitUtils.isDye(itemType) || itemType == Material.GLOW_INK_SAC || itemType == Material.INK_SAC) {
final BlockState before = event.getClickedBlock().getState();
if (before instanceof Sign) {
if (itemType == Material.GLOW_INK_SAC) {
Sign signBefore = (Sign) before;
if (!signBefore.isGlowingText()) {
final Sign signAfter = (Sign) event.getClickedBlock().getState();
signAfter.setGlowingText(true);
consumer.queueBlockReplace(Actor.actorFromEntity(player), signBefore, signAfter);
}
} else if (itemType == Material.INK_SAC) {
Sign signBefore = (Sign) before;
if (signBefore.isGlowingText()) {
final Sign signAfter = (Sign) event.getClickedBlock().getState();
signAfter.setGlowingText(false);
consumer.queueBlockReplace(Actor.actorFromEntity(player), signBefore, signAfter);
}
} else {
DyeColor newColor = BukkitUtils.dyeToDyeColor(itemType);
Sign signBefore = (Sign) before;
if (newColor != null && signBefore.getColor() != newColor) {
final Sign signAfter = (Sign) event.getClickedBlock().getState();
signAfter.setColor(newColor);
consumer.queueBlockReplace(Actor.actorFromEntity(player), signBefore, signAfter);
}
}
}
}
}
} else {
switch (type) {
case CAKE:
if (event.hasItem() && BukkitUtils.isCandle(event.getItem().getType()) && event.useItemInHand() != Result.DENY) {
BlockData newBlockData = Material.valueOf(event.getItem().getType().name() + "_CAKE").createBlockData();
@ -135,21 +170,6 @@ public class InteractLogging extends LoggingListener {
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
}
break;
case OAK_PRESSURE_PLATE:
case SPRUCE_PRESSURE_PLATE:
case BIRCH_PRESSURE_PLATE:
case JUNGLE_PRESSURE_PLATE:
case ACACIA_PRESSURE_PLATE:
case DARK_OAK_PRESSURE_PLATE:
case WARPED_PRESSURE_PLATE:
case CRIMSON_PRESSURE_PLATE:
case STONE_PRESSURE_PLATE:
case HEAVY_WEIGHTED_PRESSURE_PLATE:
case LIGHT_WEIGHTED_PRESSURE_PLATE:
if (wcfg.isLogging(Logging.PRESUREPLATEINTERACT) && event.getAction() == Action.PHYSICAL) {
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, blockData);
}
break;
case TRIPWIRE:
if (wcfg.isLogging(Logging.TRIPWIREINTERACT) && event.getAction() == Action.PHYSICAL) {
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, blockData);
@ -203,90 +223,11 @@ public class InteractLogging extends LoggingListener {
}
}
break;
case OAK_DOOR:
case SPRUCE_DOOR:
case BIRCH_DOOR:
case JUNGLE_DOOR:
case ACACIA_DOOR:
case DARK_OAK_DOOR:
case WARPED_DOOR:
case CRIMSON_DOOR:
if (wcfg.isLogging(Logging.DOORINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Door newBlockData = (Door) blockData.clone();
newBlockData.setOpen(!newBlockData.isOpen());
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
}
break;
case STONE_BUTTON:
case OAK_BUTTON:
case SPRUCE_BUTTON:
case BIRCH_BUTTON:
case JUNGLE_BUTTON:
case ACACIA_BUTTON:
case DARK_OAK_BUTTON:
case WARPED_BUTTON:
case CRIMSON_BUTTON:
case LEVER:
if (wcfg.isLogging(Logging.SWITCHINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Switch newBlockData = (Switch) blockData.clone();
if (!newBlockData.isPowered() || type == Material.LEVER) {
newBlockData.setPowered(!newBlockData.isPowered());
}
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
}
break;
case OAK_SIGN:
case SPRUCE_SIGN:
case BIRCH_SIGN:
case JUNGLE_SIGN:
case ACACIA_SIGN:
case DARK_OAK_SIGN:
case WARPED_SIGN:
case CRIMSON_SIGN:
case OAK_WALL_SIGN:
case SPRUCE_WALL_SIGN:
case BIRCH_WALL_SIGN:
case JUNGLE_WALL_SIGN:
case ACACIA_WALL_SIGN:
case DARK_OAK_WALL_SIGN:
case WARPED_WALL_SIGN:
case CRIMSON_WALL_SIGN:
if (wcfg.isLogging(Logging.SIGNTEXT) && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getItem() != null) {
Material itemType = event.getItem().getType();
if (BukkitUtils.isDye(itemType) || itemType == Material.GLOW_INK_SAC || itemType == Material.INK_SAC) {
final BlockState before = event.getClickedBlock().getState();
if (before instanceof Sign) {
if (itemType == Material.GLOW_INK_SAC) {
Sign signBefore = (Sign) before;
if (!signBefore.isGlowingText()) {
final Sign signAfter = (Sign) event.getClickedBlock().getState();
signAfter.setGlowingText(true);
consumer.queueBlockReplace(Actor.actorFromEntity(player), signBefore, signAfter);
}
} else if (itemType == Material.INK_SAC) {
Sign signBefore = (Sign) before;
if (signBefore.isGlowingText()) {
final Sign signAfter = (Sign) event.getClickedBlock().getState();
signAfter.setGlowingText(false);
consumer.queueBlockReplace(Actor.actorFromEntity(player), signBefore, signAfter);
}
} else {
DyeColor newColor = BukkitUtils.dyeToDyeColor(itemType);
Sign signBefore = (Sign) before;
if (newColor != null && signBefore.getColor() != newColor) {
final Sign signAfter = (Sign) event.getClickedBlock().getState();
signAfter.setColor(newColor);
consumer.queueBlockReplace(Actor.actorFromEntity(player), signBefore, signAfter);
}
}
}
}
}
break;
default:
}
}
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onGenericGameEvent(GenericGameEvent event) {

View File

@ -7,6 +7,7 @@ import java.io.File;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.HashMap;
@ -70,7 +71,10 @@ public class BukkitUtils {
private static final Map<EntityType, Material> projectileItems;
private static final EnumSet<Material> signs;
private static final EnumSet<Material> wallSigns;
private static final EnumSet<Material> hangingSigns;
private static final EnumSet<Material> hangingWallSigns;
private static final EnumSet<Material> allSigns;
private static final Set<Material> unmodifiableSigns;
private static final EnumSet<Material> buttons;
private static final EnumSet<Material> pressurePlates;
private static final EnumSet<Material> woodenDoors;
@ -80,8 +84,34 @@ public class BukkitUtils {
private static final EnumSet<Material> alwaysWaterlogged;
private static final EnumSet<Material> candles;
private static final EnumSet<Material> candleCakes;
private static final EnumSet<Material> fenceGates;
private static final EnumSet<Material> woodenTrapdoors;
static {
fenceGates = EnumSet.noneOf(Material.class);
fenceGates.add(Material.OAK_FENCE_GATE);
fenceGates.add(Material.SPRUCE_FENCE_GATE);
fenceGates.add(Material.BIRCH_FENCE_GATE);
fenceGates.add(Material.JUNGLE_FENCE_GATE);
fenceGates.add(Material.ACACIA_FENCE_GATE);
fenceGates.add(Material.DARK_OAK_FENCE_GATE);
fenceGates.add(Material.WARPED_FENCE_GATE);
fenceGates.add(Material.CRIMSON_FENCE_GATE);
fenceGates.add(Material.MANGROVE_FENCE_GATE);
fenceGates.add(Material.BAMBOO_FENCE_GATE);
woodenTrapdoors = EnumSet.noneOf(Material.class);
woodenTrapdoors.add(Material.OAK_TRAPDOOR);
woodenTrapdoors.add(Material.SPRUCE_TRAPDOOR);
woodenTrapdoors.add(Material.BIRCH_TRAPDOOR);
woodenTrapdoors.add(Material.JUNGLE_TRAPDOOR);
woodenTrapdoors.add(Material.ACACIA_TRAPDOOR);
woodenTrapdoors.add(Material.DARK_OAK_TRAPDOOR);
woodenTrapdoors.add(Material.WARPED_TRAPDOOR);
woodenTrapdoors.add(Material.CRIMSON_TRAPDOOR);
woodenTrapdoors.add(Material.MANGROVE_TRAPDOOR);
woodenTrapdoors.add(Material.BAMBOO_TRAPDOOR);
pressurePlates = EnumSet.noneOf(Material.class);
pressurePlates.add(Material.OAK_PRESSURE_PLATE);
pressurePlates.add(Material.SPRUCE_PRESSURE_PLATE);
@ -207,9 +237,36 @@ public class BukkitUtils {
wallSigns.add(Material.MANGROVE_WALL_SIGN);
wallSigns.add(Material.BAMBOO_WALL_SIGN);
hangingSigns = EnumSet.noneOf(Material.class);
hangingSigns.add(Material.OAK_HANGING_SIGN);
hangingSigns.add(Material.SPRUCE_HANGING_SIGN);
hangingSigns.add(Material.BIRCH_HANGING_SIGN);
hangingSigns.add(Material.JUNGLE_HANGING_SIGN);
hangingSigns.add(Material.DARK_OAK_HANGING_SIGN);
hangingSigns.add(Material.ACACIA_HANGING_SIGN);
hangingSigns.add(Material.WARPED_HANGING_SIGN);
hangingSigns.add(Material.CRIMSON_HANGING_SIGN);
hangingSigns.add(Material.MANGROVE_HANGING_SIGN);
hangingSigns.add(Material.BAMBOO_HANGING_SIGN);
hangingWallSigns = EnumSet.noneOf(Material.class);
hangingWallSigns.add(Material.OAK_WALL_HANGING_SIGN);
hangingWallSigns.add(Material.SPRUCE_WALL_HANGING_SIGN);
hangingWallSigns.add(Material.BIRCH_WALL_HANGING_SIGN);
hangingWallSigns.add(Material.JUNGLE_WALL_HANGING_SIGN);
hangingWallSigns.add(Material.DARK_OAK_WALL_HANGING_SIGN);
hangingWallSigns.add(Material.ACACIA_WALL_HANGING_SIGN);
hangingWallSigns.add(Material.WARPED_WALL_HANGING_SIGN);
hangingWallSigns.add(Material.CRIMSON_WALL_HANGING_SIGN);
hangingWallSigns.add(Material.MANGROVE_WALL_HANGING_SIGN);
hangingWallSigns.add(Material.BAMBOO_WALL_HANGING_SIGN);
allSigns = EnumSet.noneOf(Material.class);
allSigns.addAll(signs);
allSigns.addAll(wallSigns);
allSigns.addAll(hangingSigns);
allSigns.addAll(hangingWallSigns);
unmodifiableSigns = Collections.unmodifiableSet(allSigns);
singleBlockPlants = EnumSet.noneOf(Material.class);
singleBlockPlants.add(Material.GRASS);
@ -1131,8 +1188,8 @@ public class BukkitUtils {
return false;
}
public static Material[] getAllSignsArray() {
return allSigns.toArray(new Material[allSigns.size()]);
public static Set<Material> getAllSignMaterials() {
return unmodifiableSigns;
}
public static boolean isAlwaysWaterlogged(Material m) {
@ -1146,4 +1203,24 @@ public class BukkitUtils {
public static boolean isCandleCake(Material m) {
return candleCakes.contains(m);
}
public static boolean isHangingSign(Material m) {
return hangingSigns.contains(m);
}
public static boolean isFenceGate(Material m) {
return fenceGates.contains(m);
}
public static boolean isWoodenTrapdoor(Material m) {
return woodenTrapdoors.contains(m);
}
public static boolean isPressurePlate(Material m) {
return pressurePlates.contains(m);
}
public static boolean isSign(Material m) {
return allSigns.contains(m);
}
}

View File

@ -228,6 +228,8 @@ public class LoggingUtil {
if (lantern.isHanging()) {
consumer.queueBlockBreak(actor, checkBlock.getState());
}
} else if (BukkitUtils.isHangingSign(typeBelow)) {
consumer.queueBlockBreak(actor, checkBlock.getState());
} else if (typeBelow == Material.BELL) {
Bell bell = (Bell) checkBlock.getBlockData();
if (bell.getAttachment() == Attachment.CEILING) {