diff --git a/src/main/java/com/massivecraft/factions/engine/EnginePermBuild.java b/src/main/java/com/massivecraft/factions/engine/EnginePermBuild.java index c829f82f..078c69af 100644 --- a/src/main/java/com/massivecraft/factions/engine/EnginePermBuild.java +++ b/src/main/java/com/massivecraft/factions/engine/EnginePermBuild.java @@ -16,6 +16,7 @@ import com.massivecraft.massivecore.util.MUtil; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.data.type.Lectern; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -154,12 +155,31 @@ public class EnginePermBuild extends Engine { @EventHandler(priority = EventPriority.NORMAL) public void takeBook(PlayerTakeLecternBookEvent event) { - protect(ProtectCase.TAKE_BOOK, true, event.getPlayer(), PS.valueOf(event.getLectern().getBlock()), Material.LECTERN, event); + protect(ProtectCase.CHANGE_BOOK, true, event.getPlayer(), PS.valueOf(event.getLectern().getBlock()), + Material.LECTERN, event); } @EventHandler(priority = EventPriority.NORMAL) public void build(BlockPlaceEvent event) { - build(event.getPlayer(), event.getBlock(), event); + if (isUpdatingBook(event)) { + protect(ProtectCase.CHANGE_BOOK, true, event.getPlayer(), PS.valueOf(event.getBlock()), + Material.LECTERN, event); + } else { + build(event.getPlayer(), event.getBlock(), event); + } + } + + /** + * Checks whether the given block place event is a book being updated + * + * @param event
The event to check
+ * @returnTrue if the event is causing a book to be updated
+ */ + private boolean isUpdatingBook(BlockPlaceEvent event) { + return event.getBlockPlaced().getType().equals(Material.LECTERN) && + event.getBlockPlaced().getState() instanceof Lectern && + (event.getItemInHand().getType().equals(Material.WRITTEN_BOOK) || + event.getItemInHand().getType().equals(Material.WRITABLE_BOOK)); } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) diff --git a/src/main/java/com/massivecraft/factions/engine/ProtectCase.java b/src/main/java/com/massivecraft/factions/engine/ProtectCase.java index c92077bb..00a316b8 100644 --- a/src/main/java/com/massivecraft/factions/engine/ProtectCase.java +++ b/src/main/java/com/massivecraft/factions/engine/ProtectCase.java @@ -17,7 +17,7 @@ public enum ProtectCase { USE_ITEM, USE_ENTITY, - TAKE_BOOK, + CHANGE_BOOK, // END OF LIST ; @@ -29,7 +29,7 @@ public enum ProtectCase { public MPerm getPerm(Object object) { switch (this) { case BUILD: - case TAKE_BOOK: + case CHANGE_BOOK: return MPerm.getPermBuild(); case USE_ITEM: