forked from LogBlock/LogBlock
Log lectern book change
This commit is contained in:
@ -13,6 +13,7 @@ import org.bukkit.block.data.Openable;
|
|||||||
import org.bukkit.block.data.Powerable;
|
import org.bukkit.block.data.Powerable;
|
||||||
import org.bukkit.block.data.type.Comparator;
|
import org.bukkit.block.data.type.Comparator;
|
||||||
import org.bukkit.block.data.type.DaylightDetector;
|
import org.bukkit.block.data.type.DaylightDetector;
|
||||||
|
import org.bukkit.block.data.type.Lectern;
|
||||||
import org.bukkit.block.data.type.NoteBlock;
|
import org.bukkit.block.data.type.NoteBlock;
|
||||||
import org.bukkit.block.data.type.Repeater;
|
import org.bukkit.block.data.type.Repeater;
|
||||||
import org.bukkit.block.data.type.Sign;
|
import org.bukkit.block.data.type.Sign;
|
||||||
@ -141,6 +142,8 @@ public class BlockChange implements LookupCacheElement {
|
|||||||
msg.append("set ").append(type.getMaterial().name()).append(" to ").append(((Comparator) type).getMode());
|
msg.append("set ").append(type.getMaterial().name()).append(" to ").append(((Comparator) type).getMode());
|
||||||
} else if (type.getMaterial() == Material.DAYLIGHT_DETECTOR) {
|
} else if (type.getMaterial() == Material.DAYLIGHT_DETECTOR) {
|
||||||
msg.append("set ").append(type.getMaterial().name()).append(" to ").append(((DaylightDetector) type).isInverted() ? "inverted" : "normal");
|
msg.append("set ").append(type.getMaterial().name()).append(" to ").append(((DaylightDetector) type).isInverted() ? "inverted" : "normal");
|
||||||
|
} else if (type instanceof Lectern) {
|
||||||
|
msg.append("changed the book on a ").append(type.getMaterial().name()).append(" to").append(replacedDetails.length() == 0 ? "empty" : replacedDetails);
|
||||||
} else if (type instanceof Powerable) {
|
} else if (type instanceof Powerable) {
|
||||||
msg.append("stepped on ").append(type.getMaterial().name());
|
msg.append("stepped on ").append(type.getMaterial().name());
|
||||||
} else if (type.getMaterial() == Material.TRIPWIRE) {
|
} else if (type.getMaterial() == Material.TRIPWIRE) {
|
||||||
|
@ -189,6 +189,9 @@ public class LogBlock extends JavaPlugin {
|
|||||||
if (isLogging(Logging.DRAGONEGGTELEPORT)) {
|
if (isLogging(Logging.DRAGONEGGTELEPORT)) {
|
||||||
pm.registerEvents(new DragonEggLogging(this), this);
|
pm.registerEvents(new DragonEggLogging(this), this);
|
||||||
}
|
}
|
||||||
|
if (isLogging(Logging.LECTERNBOOKCHANGE)) {
|
||||||
|
pm.registerEvents(new LecternLogging(this), this);
|
||||||
|
}
|
||||||
if (Config.isLoggingAnyEntities()) {
|
if (Config.isLoggingAnyEntities()) {
|
||||||
if (!WorldEditHelper.hasFullWorldEdit()) {
|
if (!WorldEditHelper.hasFullWorldEdit()) {
|
||||||
getLogger().severe("No compatible WorldEdit found, entity logging will not work!");
|
getLogger().severe("No compatible WorldEdit found, entity logging will not work!");
|
||||||
|
@ -8,7 +8,8 @@ public enum Logging {
|
|||||||
PRESUREPLATEINTERACT, TRIPWIREINTERACT, CREATURECROPTRAMPLE, CROPTRAMPLE,
|
PRESUREPLATEINTERACT, TRIPWIREINTERACT, CREATURECROPTRAMPLE, CROPTRAMPLE,
|
||||||
NATURALSTRUCTUREGROW, GRASSGROWTH, MYCELIUMSPREAD, VINEGROWTH, MUSHROOMSPREAD,
|
NATURALSTRUCTUREGROW, GRASSGROWTH, MYCELIUMSPREAD, VINEGROWTH, MUSHROOMSPREAD,
|
||||||
WITHER(true), WITHER_SKULL(true), BONEMEALSTRUCTUREGROW, WORLDEDIT, TNTMINECARTEXPLOSION(true),
|
WITHER(true), WITHER_SKULL(true), BONEMEALSTRUCTUREGROW, WORLDEDIT, TNTMINECARTEXPLOSION(true),
|
||||||
ENDERCRYSTALEXPLOSION(true), BEDEXPLOSION(true), DRAGONEGGTELEPORT(true), DAYLIGHTDETECTORINTERACT;
|
ENDERCRYSTALEXPLOSION(true), BEDEXPLOSION(true), DRAGONEGGTELEPORT(true), DAYLIGHTDETECTORINTERACT,
|
||||||
|
LECTERNBOOKCHANGE(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,50 @@
|
|||||||
|
package de.diddiz.LogBlock.blockstate;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.block.Lectern;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class BlockStateCodecLectern implements BlockStateCodec {
|
||||||
|
@Override
|
||||||
|
public Material[] getApplicableMaterials() {
|
||||||
|
return new Material[] { Material.LECTERN };
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public YamlConfiguration serialize(BlockState state) {
|
||||||
|
if (state instanceof Lectern) {
|
||||||
|
Lectern lectern = (Lectern) state;
|
||||||
|
ItemStack book = lectern.getSnapshotInventory().getItem(0);
|
||||||
|
if (book != null && book.getType() != Material.AIR) {
|
||||||
|
YamlConfiguration conf = new YamlConfiguration();
|
||||||
|
conf.set("book", book);
|
||||||
|
return conf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deserialize(BlockState state, YamlConfiguration conf) {
|
||||||
|
if (state instanceof Lectern) {
|
||||||
|
Lectern lectern = (Lectern) state;
|
||||||
|
ItemStack book = null;
|
||||||
|
if (conf != null) {
|
||||||
|
book = conf.getItemStack("book");
|
||||||
|
}
|
||||||
|
lectern.getSnapshotInventory().setItem(0, book);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(YamlConfiguration conf) {
|
||||||
|
if (conf != null) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("[").append("book").append("]");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -25,6 +25,7 @@ public class BlockStateCodecs {
|
|||||||
registerCodec(new BlockStateCodecSkull());
|
registerCodec(new BlockStateCodecSkull());
|
||||||
registerCodec(new BlockStateCodecBanner());
|
registerCodec(new BlockStateCodecBanner());
|
||||||
registerCodec(new BlockStateCodecSpawner());
|
registerCodec(new BlockStateCodecSpawner());
|
||||||
|
registerCodec(new BlockStateCodecLectern());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasCodec(Material material) {
|
public static boolean hasCodec(Material material) {
|
||||||
|
@ -29,7 +29,9 @@ public class BlockPlaceLogging extends LoggingListener {
|
|||||||
final BlockState before = event.getBlockReplacedState();
|
final BlockState before = event.getBlockReplacedState();
|
||||||
final BlockState after = event.getBlockPlaced().getState();
|
final BlockState after = event.getBlockPlaced().getState();
|
||||||
final Actor actor = Actor.actorFromEntity(event.getPlayer());
|
final Actor actor = Actor.actorFromEntity(event.getPlayer());
|
||||||
|
if (before.getType() == Material.LECTERN && after.getType() == Material.LECTERN && !Config.isLogging(event.getBlock().getWorld(), Logging.LECTERNBOOKCHANGE)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
LoggingUtil.smartLogBlockPlace(consumer, actor, before, after);
|
LoggingUtil.smartLogBlockPlace(consumer, actor, before, after);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
package de.diddiz.LogBlock.listeners;
|
||||||
|
|
||||||
|
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
|
||||||
|
|
||||||
|
import de.diddiz.LogBlock.Actor;
|
||||||
|
import de.diddiz.LogBlock.LogBlock;
|
||||||
|
import de.diddiz.LogBlock.Logging;
|
||||||
|
import de.diddiz.LogBlock.config.WorldConfig;
|
||||||
|
import org.bukkit.block.Lectern;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.player.PlayerTakeLecternBookEvent;
|
||||||
|
|
||||||
|
public class LecternLogging extends LoggingListener {
|
||||||
|
public LecternLogging(LogBlock lb) {
|
||||||
|
super(lb);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
public void onPlayerTakeLecternBook(PlayerTakeLecternBookEvent event) {
|
||||||
|
final WorldConfig wcfg = getWorldConfig(event.getPlayer().getWorld());
|
||||||
|
if (wcfg != null && wcfg.isLogging(Logging.LECTERNBOOKCHANGE)) {
|
||||||
|
Lectern oldState = event.getLectern();
|
||||||
|
Lectern newState = (Lectern) oldState.getBlock().getState();
|
||||||
|
newState.getSnapshotInventory().setItem(0, null);
|
||||||
|
|
||||||
|
consumer.queueBlockReplace(Actor.actorFromEntity(event.getPlayer()), oldState, newState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user