Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/lectern #579

Merged
merged 13 commits into from
Aug 10, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
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;
Expand Down Expand Up @@ -232,6 +233,22 @@ public void onBlockPlace(BlockPlaceEvent placeEvent)
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.allowContainers(player) != null)
ShaneBeee marked this conversation as resolved.
Show resolved Hide resolved
{
placeEvent.setCancelled(true);
GriefPrevention.sendMessage(player, TextMode.Err, claim.allowContainers(player));
ShaneBeee marked this conversation as resolved.
Show resolved Hide resolved
return;
}
else
{
return;
}
}
GriefPrevention.sendMessage(player, TextMode.Err, noBuildReason);
placeEvent.setCancelled(true);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_lecternreading; //reading lecterns requires access trust
ShaneBeee marked this conversation as resolved.
Show resolved Hide resolved

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
Expand Down Expand Up @@ -588,6 +590,7 @@ else if(world.getEnvironment() == Environment.NORMAL)

this.config_claims_firespreads = config.getBoolean("GriefPrevention.Claims.FireSpreadsInClaims", false);
this.config_claims_firedamages = config.getBoolean("GriefPrevention.Claims.FireDamagesInClaims", false);
this.config_claims_lecternreading = 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);
Expand Down Expand Up @@ -840,6 +843,7 @@ else if(world.getEnvironment() == Environment.NORMAL)

outConfig.set("GriefPrevention.Claims.FireSpreadsInClaims", config_claims_firespreads);
outConfig.set("GriefPrevention.Claims.FireDamagesInClaims", config_claims_firedamages);
outConfig.set("GriefPrevention.Claims.LecternReadingRequiresAccessTrust", config_claims_lecternreading);

outConfig.set("GriefPrevention.Spam.Enabled", this.config_spam_enabled);
outConfig.set("GriefPrevention.Spam.LoginCooldownSeconds", this.config_spam_loginCooldownSeconds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
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;
Expand Down Expand Up @@ -1658,7 +1659,22 @@ void onPlayerInteract(PlayerInteractEvent event)
if(claim != null)
{
playerData.lastClaim = claim;


if(clickedBlock.getType() == Material.LECTERN)
{
String noAccessReason = claim.allowAccess(player);
if(noAccessReason != null && instance.config_claims_lecternreading)
{
event.setCancelled(true);
GriefPrevention.sendMessage(player, TextMode.Err, noAccessReason);
return;
}
else
{
return;
}
}
ShaneBeee marked this conversation as resolved.
Show resolved Hide resolved

String noContainersReason = claim.allowContainers(player);
if(noContainersReason != null)
{
Expand Down Expand Up @@ -2620,6 +2636,21 @@ else if(playerData.shovelMode == ShovelMode.Subdivide)
}
}
}

// 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.allowContainers(player) != null)
ShaneBeee marked this conversation as resolved.
Show resolved Hide resolved
{
event.setCancelled(true);
player.closeInventory();
GriefPrevention.sendMessage(player, TextMode.Err, claim.allowContainers(player));
}
}

//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>();
Expand Down