Fixes some weird cases for lectern protection
This commit is contained in:
parent
9c0ed3e46a
commit
45782ec94d
@ -16,6 +16,7 @@ import com.massivecraft.massivecore.util.MUtil;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.block.data.type.Lectern;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -154,12 +155,31 @@ public class EnginePermBuild extends Engine {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void takeBook(PlayerTakeLecternBookEvent event) {
|
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)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void build(BlockPlaceEvent event) {
|
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 <p>The event to check</p>
|
||||||
|
* @return <p>True if the event is causing a book to be updated</p>
|
||||||
|
*/
|
||||||
|
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)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
|
@ -17,7 +17,7 @@ public enum ProtectCase {
|
|||||||
USE_ITEM,
|
USE_ITEM,
|
||||||
USE_ENTITY,
|
USE_ENTITY,
|
||||||
|
|
||||||
TAKE_BOOK,
|
CHANGE_BOOK,
|
||||||
|
|
||||||
// END OF LIST
|
// END OF LIST
|
||||||
;
|
;
|
||||||
@ -29,7 +29,7 @@ public enum ProtectCase {
|
|||||||
public MPerm getPerm(Object object) {
|
public MPerm getPerm(Object object) {
|
||||||
switch (this) {
|
switch (this) {
|
||||||
case BUILD:
|
case BUILD:
|
||||||
case TAKE_BOOK:
|
case CHANGE_BOOK:
|
||||||
return MPerm.getPermBuild();
|
return MPerm.getPermBuild();
|
||||||
|
|
||||||
case USE_ITEM:
|
case USE_ITEM:
|
||||||
|
Loading…
Reference in New Issue
Block a user