forked from LogBlock/LogBlock
Log sign base color change
This commit is contained in:
@@ -3,7 +3,7 @@ package de.diddiz.LogBlock.blockstate;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.bukkit.DyeColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
@@ -27,9 +27,18 @@ public class BlockStateCodecSign implements BlockStateCodec {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hasText) {
|
DyeColor signColor = sign.getColor();
|
||||||
|
if (signColor == null) {
|
||||||
|
signColor = DyeColor.BLACK;
|
||||||
|
}
|
||||||
|
if (hasText || signColor != DyeColor.BLACK) {
|
||||||
YamlConfiguration conf = new YamlConfiguration();
|
YamlConfiguration conf = new YamlConfiguration();
|
||||||
conf.set("lines", Arrays.asList(lines));
|
if (hasText) {
|
||||||
|
conf.set("lines", Arrays.asList(lines));
|
||||||
|
}
|
||||||
|
if (signColor != DyeColor.BLACK) {
|
||||||
|
conf.set("color", signColor.name());
|
||||||
|
}
|
||||||
return conf;
|
return conf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,14 +58,25 @@ public class BlockStateCodecSign implements BlockStateCodec {
|
|||||||
public void deserialize(BlockState state, YamlConfiguration conf) {
|
public void deserialize(BlockState state, YamlConfiguration conf) {
|
||||||
if (state instanceof Sign) {
|
if (state instanceof Sign) {
|
||||||
Sign sign = (Sign) state;
|
Sign sign = (Sign) state;
|
||||||
|
DyeColor signColor = DyeColor.BLACK;
|
||||||
List<String> lines = Collections.emptyList();
|
List<String> lines = Collections.emptyList();
|
||||||
if (conf != null) {
|
if (conf != null) {
|
||||||
lines = conf.getStringList("lines");
|
if (conf.contains("lines")) {
|
||||||
|
lines = conf.getStringList("lines");
|
||||||
|
}
|
||||||
|
if (conf.contains("color")) {
|
||||||
|
try {
|
||||||
|
signColor = DyeColor.valueOf(conf.getString("color"));
|
||||||
|
} catch (IllegalArgumentException | NullPointerException e) {
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
String line = lines.size() > i && lines.get(i) != null ? lines.get(i) : "";
|
String line = lines.size() > i && lines.get(i) != null ? lines.get(i) : "";
|
||||||
sign.setLine(i, line);
|
sign.setLine(i, line);
|
||||||
}
|
}
|
||||||
|
sign.setColor(signColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,12 +5,15 @@ import de.diddiz.LogBlock.LogBlock;
|
|||||||
import de.diddiz.LogBlock.Logging;
|
import de.diddiz.LogBlock.Logging;
|
||||||
import de.diddiz.LogBlock.config.WorldConfig;
|
import de.diddiz.LogBlock.config.WorldConfig;
|
||||||
import de.diddiz.util.BukkitUtils;
|
import de.diddiz.util.BukkitUtils;
|
||||||
|
import org.bukkit.DyeColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Note;
|
import org.bukkit.Note;
|
||||||
import org.bukkit.Note.Tone;
|
import org.bukkit.Note.Tone;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.block.data.Directional;
|
import org.bukkit.block.data.Directional;
|
||||||
import org.bukkit.block.data.Openable;
|
import org.bukkit.block.data.Openable;
|
||||||
@@ -178,23 +181,60 @@ public class InteractLogging extends LoggingListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
case OAK_DOOR:
|
||||||
if (BukkitUtils.isButton(type) || type == Material.LEVER) {
|
case SPRUCE_DOOR:
|
||||||
if (wcfg.isLogging(Logging.SWITCHINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
case BIRCH_DOOR:
|
||||||
Switch newBlockData = (Switch) blockData.clone();
|
case JUNGLE_DOOR:
|
||||||
if (!newBlockData.isPowered() || type == Material.LEVER) {
|
case ACACIA_DOOR:
|
||||||
newBlockData.setPowered(!newBlockData.isPowered());
|
case DARK_OAK_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 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 OAK_WALL_SIGN:
|
||||||
|
case SPRUCE_WALL_SIGN:
|
||||||
|
case BIRCH_WALL_SIGN:
|
||||||
|
case JUNGLE_WALL_SIGN:
|
||||||
|
case ACACIA_WALL_SIGN:
|
||||||
|
case DARK_OAK_WALL_SIGN:
|
||||||
|
ItemStack stack = event.getItem();
|
||||||
|
if (stack != null && BukkitUtils.isDye(stack.getType())) {
|
||||||
|
final BlockState before = event.getClickedBlock().getState();
|
||||||
|
if (before instanceof Sign) {
|
||||||
|
DyeColor newColor = BukkitUtils.dyeToDyeColor(stack.getType());
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -50,6 +50,7 @@ public class BukkitUtils {
|
|||||||
private static final EnumSet<Material> woodenDoors;
|
private static final EnumSet<Material> woodenDoors;
|
||||||
private static final EnumSet<Material> slabs;
|
private static final EnumSet<Material> slabs;
|
||||||
private static final EnumSet<Material> concreteBlocks;
|
private static final EnumSet<Material> concreteBlocks;
|
||||||
|
private static final EnumMap<Material, DyeColor> dyes;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
pressurePlates = EnumSet.noneOf(Material.class);
|
pressurePlates = EnumSet.noneOf(Material.class);
|
||||||
@@ -393,6 +394,24 @@ public class BukkitUtils {
|
|||||||
concreteBlocks.add(Material.RED_CONCRETE);
|
concreteBlocks.add(Material.RED_CONCRETE);
|
||||||
concreteBlocks.add(Material.WHITE_CONCRETE);
|
concreteBlocks.add(Material.WHITE_CONCRETE);
|
||||||
concreteBlocks.add(Material.YELLOW_CONCRETE);
|
concreteBlocks.add(Material.YELLOW_CONCRETE);
|
||||||
|
|
||||||
|
dyes = new EnumMap<>(Material.class);
|
||||||
|
dyes.put(Material.BLACK_DYE, DyeColor.BLACK);
|
||||||
|
dyes.put(Material.BLUE_DYE, DyeColor.BLUE);
|
||||||
|
dyes.put(Material.LIGHT_GRAY_DYE, DyeColor.LIGHT_GRAY);
|
||||||
|
dyes.put(Material.BROWN_DYE, DyeColor.BROWN);
|
||||||
|
dyes.put(Material.CYAN_DYE, DyeColor.CYAN);
|
||||||
|
dyes.put(Material.GRAY_DYE, DyeColor.GRAY);
|
||||||
|
dyes.put(Material.GREEN_DYE, DyeColor.GREEN);
|
||||||
|
dyes.put(Material.LIGHT_BLUE_DYE, DyeColor.LIGHT_BLUE);
|
||||||
|
dyes.put(Material.MAGENTA_DYE, DyeColor.MAGENTA);
|
||||||
|
dyes.put(Material.LIME_DYE, DyeColor.LIME);
|
||||||
|
dyes.put(Material.ORANGE_DYE, DyeColor.ORANGE);
|
||||||
|
dyes.put(Material.PINK_DYE, DyeColor.PINK);
|
||||||
|
dyes.put(Material.PURPLE_DYE, DyeColor.PURPLE);
|
||||||
|
dyes.put(Material.RED_DYE, DyeColor.RED);
|
||||||
|
dyes.put(Material.WHITE_DYE, DyeColor.WHITE);
|
||||||
|
dyes.put(Material.YELLOW_DYE, DyeColor.YELLOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final BlockFace[] relativeBlockFaces = new BlockFace[]{
|
private static final BlockFace[] relativeBlockFaces = new BlockFace[]{
|
||||||
@@ -727,6 +746,14 @@ public class BukkitUtils {
|
|||||||
return bedBlocks.contains(type);
|
return bedBlocks.contains(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isDye(Material type) {
|
||||||
|
return dyes.containsKey(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DyeColor dyeToDyeColor(Material type) {
|
||||||
|
return dyes.get(type);
|
||||||
|
}
|
||||||
|
|
||||||
public static Block getConnectedChest(Block chestBlock) {
|
public static Block getConnectedChest(Block chestBlock) {
|
||||||
// is this a chest?
|
// is this a chest?
|
||||||
BlockData blockData = chestBlock.getBlockData();
|
BlockData blockData = chestBlock.getBlockData();
|
||||||
|
Reference in New Issue
Block a user