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

Stop people creating nether portals in claimed land #1842

Merged
merged 2 commits into from May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -64,6 +64,7 @@
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.world.PortalCreateEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -1077,4 +1078,45 @@ public void onItemFrameBrokenByBoat(final HangingBreakEvent event)
event.setCancelled(true);
}
}


@EventHandler(ignoreCancelled = true)
public void onNetherPortalCreate(final PortalCreateEvent event)
{
if (event.getReason() != PortalCreateEvent.CreateReason.NETHER_PAIR)
{
return;
}

// Ignore this event if preventNonPlayerCreatedPortals config option is disabled, and we don't know the entity.
if (!(event.getEntity() instanceof Player) && !GriefPrevention.instance.config_claims_preventNonPlayerCreatedPortals)
{
return;
}

for (BlockState blockState : event.getBlocks())
{
Claim claim = this.dataStore.getClaimAt(blockState.getLocation(), false, null);
if (claim != null)
{
if (event.getEntity() instanceof Player player)
{
Supplier<String> noPortalReason = claim.checkPermission(player, ClaimPermission.Build, event);

if (noPortalReason != null)
{
event.setCancelled(true);
GriefPrevention.sendMessage(player, TextMode.Err, noPortalReason.get());
return;
}
}
else
{
// Cancels the event if in a claim, as we can not efficiently retrieve the person/entity who created the portal.
event.setCancelled(true);
return;
}
}
}
}
}
Expand Up @@ -108,6 +108,7 @@ public class GriefPrevention extends JavaPlugin
public boolean config_claims_lockWoodenDoors; //whether wooden doors should be locked by default (require /accesstrust)
public boolean config_claims_lockTrapDoors; //whether trap doors should be locked by default (require /accesstrust)
public boolean config_claims_lockFenceGates; //whether fence gates should be locked by default (require /accesstrust)
public boolean config_claims_preventNonPlayerCreatedPortals; // whether portals where we cannot determine the creating player should be prevented from creation in claims
public boolean config_claims_enderPearlsRequireAccessTrust; //whether teleporting into a claim with a pearl requires access trust
public boolean config_claims_raidTriggersRequireBuildTrust; //whether raids are triggered by a player that doesn't have build permission in that claim
public int config_claims_maxClaimsPerPlayer; //maximum number of claims per player
Expand Down Expand Up @@ -541,6 +542,7 @@ else if (world.getEnvironment() == Environment.NORMAL)
this.config_claims_lockWoodenDoors = config.getBoolean("GriefPrevention.Claims.LockWoodenDoors", false);
this.config_claims_lockTrapDoors = config.getBoolean("GriefPrevention.Claims.LockTrapDoors", false);
this.config_claims_lockFenceGates = config.getBoolean("GriefPrevention.Claims.LockFenceGates", true);
this.config_claims_preventNonPlayerCreatedPortals = config.getBoolean("GriefPrevention.Claims.PreventNonPlayerCreatedPortals", false);
this.config_claims_enderPearlsRequireAccessTrust = config.getBoolean("GriefPrevention.Claims.EnderPearlsRequireAccessTrust", true);
this.config_claims_raidTriggersRequireBuildTrust = config.getBoolean("GriefPrevention.Claims.RaidTriggersRequireBuildTrust", true);
this.config_claims_initialBlocks = config.getInt("GriefPrevention.Claims.InitialBlocks", 100);
Expand Down