Modify lectern permissions (#579)
- /accesstrust for viewing (with a config to disable permission requirement) - /containertrust for modifying Closes #537 Co-authored-by: Zedadias Wick <zedwick@gmail.com>
This commit is contained in:
parent
c58dea357a
commit
7c7e98e5e6
|
|
@ -33,6 +33,7 @@ import org.bukkit.block.Block;
|
|||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Hopper;
|
||||
import org.bukkit.block.Lectern;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.minecart.HopperMinecart;
|
||||
|
|
@ -232,6 +233,23 @@ public class BlockEventHandler implements Listener
|
|||
String noBuildReason = GriefPrevention.instance.allowBuild(player, block.getLocation(), block.getType());
|
||||
if(noBuildReason != null)
|
||||
{
|
||||
// Allow players with container trust to place books in lecterns
|
||||
PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
|
||||
Claim claim = this.dataStore.getClaimAt(block.getLocation(), true, playerData.lastClaim);
|
||||
if (block.getType() == Material.LECTERN && placeEvent.getBlockReplacedState() instanceof Lectern)
|
||||
{
|
||||
if (claim != null)
|
||||
{
|
||||
playerData.lastClaim = claim;
|
||||
String noContainerReason = claim.allowContainers(player);
|
||||
if (noContainerReason == null)
|
||||
return;
|
||||
|
||||
placeEvent.setCancelled(true);
|
||||
GriefPrevention.sendMessage(player, TextMode.Err, noContainerReason);
|
||||
return;
|
||||
}
|
||||
}
|
||||
GriefPrevention.sendMessage(player, TextMode.Err, noBuildReason);
|
||||
placeEvent.setCancelled(true);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -135,6 +135,8 @@ public class GriefPrevention extends JavaPlugin
|
|||
|
||||
public boolean config_claims_firespreads; //whether fire will spread in claims
|
||||
public boolean config_claims_firedamages; //whether fire will damage in claims
|
||||
|
||||
public boolean config_claims_lecternReadingRequiresAccessTrust; //reading lecterns requires access trust
|
||||
|
||||
public ArrayList<World> config_siege_enabledWorlds; //whether or not /siege is enabled on this server
|
||||
public ArrayList<Material> config_siege_blocks; //which blocks will be breakable in siege mode
|
||||
|
|
@ -588,6 +590,7 @@ public class GriefPrevention extends JavaPlugin
|
|||
|
||||
this.config_claims_firespreads = config.getBoolean("GriefPrevention.Claims.FireSpreadsInClaims", false);
|
||||
this.config_claims_firedamages = config.getBoolean("GriefPrevention.Claims.FireDamagesInClaims", false);
|
||||
this.config_claims_lecternReadingRequiresAccessTrust = config.getBoolean("GriefPrevention.Claims.LecternReadingRequiresAccessTrust", true);
|
||||
|
||||
this.config_spam_enabled = config.getBoolean("GriefPrevention.Spam.Enabled", true);
|
||||
this.config_spam_loginCooldownSeconds = config.getInt("GriefPrevention.Spam.LoginCooldownSeconds", 60);
|
||||
|
|
@ -840,6 +843,7 @@ public class GriefPrevention extends JavaPlugin
|
|||
|
||||
outConfig.set("GriefPrevention.Claims.FireSpreadsInClaims", config_claims_firespreads);
|
||||
outConfig.set("GriefPrevention.Claims.FireDamagesInClaims", config_claims_firedamages);
|
||||
outConfig.set("GriefPrevention.Claims.LecternReadingRequiresAccessTrust", config_claims_lecternReadingRequiresAccessTrust);
|
||||
|
||||
outConfig.set("GriefPrevention.Spam.Enabled", this.config_spam_enabled);
|
||||
outConfig.set("GriefPrevention.Spam.LoginCooldownSeconds", this.config_spam_loginCooldownSeconds);
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ import org.bukkit.event.player.PlayerPickupItemEvent;
|
|||
import org.bukkit.event.player.PlayerPortalEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerTakeLecternBookEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
|
|
@ -1626,7 +1627,7 @@ class PlayerEventHandler implements Listener
|
|||
//apply rules for containers and crafting blocks
|
||||
if( clickedBlock != null && instance.config_claims_preventTheft && (
|
||||
event.getAction() == Action.RIGHT_CLICK_BLOCK && (
|
||||
this.isInventoryHolder(clickedBlock) ||
|
||||
(this.isInventoryHolder(clickedBlock) && clickedBlock.getType() != Material.LECTERN) ||
|
||||
clickedBlockType == Material.CAULDRON ||
|
||||
clickedBlockType == Material.JUKEBOX ||
|
||||
clickedBlockType == Material.ANVIL ||
|
||||
|
|
@ -1658,7 +1659,7 @@ class PlayerEventHandler implements Listener
|
|||
if(claim != null)
|
||||
{
|
||||
playerData.lastClaim = claim;
|
||||
|
||||
|
||||
String noContainersReason = claim.allowContainers(player);
|
||||
if(noContainersReason != null)
|
||||
{
|
||||
|
|
@ -1719,7 +1720,8 @@ class PlayerEventHandler implements Listener
|
|||
clickedBlockType == Material.BIRCH_FENCE_GATE ||
|
||||
clickedBlockType == Material.JUNGLE_FENCE_GATE ||
|
||||
clickedBlockType == Material.SPRUCE_FENCE_GATE ||
|
||||
clickedBlockType == Material.DARK_OAK_FENCE_GATE)))
|
||||
clickedBlockType == Material.DARK_OAK_FENCE_GATE)) ||
|
||||
(instance.config_claims_lecternReadingRequiresAccessTrust && clickedBlockType == Material.LECTERN))
|
||||
{
|
||||
if(playerData == null) playerData = this.dataStore.getPlayerData(player.getUniqueId());
|
||||
Claim claim = this.dataStore.getClaimAt(clickedBlock.getLocation(), false, playerData.lastClaim);
|
||||
|
|
@ -2620,6 +2622,26 @@ class PlayerEventHandler implements Listener
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Stops an untrusted player from removing a book from a lectern
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
void onTakeBook(PlayerTakeLecternBookEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
|
||||
Claim claim = this.dataStore.getClaimAt(event.getLectern().getLocation(), false, playerData.lastClaim);
|
||||
if (claim != null)
|
||||
{
|
||||
playerData.lastClaim = claim;
|
||||
String noContainerReason = claim.allowContainers(player);
|
||||
if (noContainerReason != null)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
player.closeInventory();
|
||||
GriefPrevention.sendMessage(player, TextMode.Err, noContainerReason);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//determines whether a block type is an inventory holder. uses a caching strategy to save cpu time
|
||||
private ConcurrentHashMap<Material, Boolean> inventoryHolderCache = new ConcurrentHashMap<Material, Boolean>();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user