Compare commits

...

10 Commits

Author SHA1 Message Date
Len e03851246e Add Jenkinsfile 2024-08-04 23:15:12 +02:00
Len 9a687ec099 Add abandonpet command. 2024-08-03 14:32:34 +02:00
Len 98a0a06081 Add abandonsublevelclaim command. 2024-08-03 14:24:39 +02:00
Len 88f9c27194 Cherry pick: * Extract GriefPrevention#allowBuild/GriefPrevention#allowBreak to a helper method
* These methods have been hacky since the introduction of the `ClaimPermissionCheckEvent`, and as we saw with damage events, Spigot is serious about event constructors not being API. Moving away from constructing events is a good idea in general.
2024-07-20 17:54:40 +02:00
Len 0acbfa316f Cherry pick: * Use Tag.REPLACEABLE instead of manual material listing 2024-07-20 17:09:21 +02:00
Len 40152b5dd9 Cherry pick: * Move to more maintainable PotionEffectTypeCategory for potion handling 2024-07-20 17:08:31 +02:00
Len 6f2a02d610 remove FEATURE: limit fire placement, to prevent PvP-by-fire 2024-07-20 17:04:23 +02:00
Len 49e1dadf94 Update and changes for 1.21 2024-07-20 16:54:10 +02:00
Len 01dbc159de Fix /kfc 2024-06-08 09:49:15 +02:00
Len 034124341c Update kick from claim and send players to spawn.
This prevents players from building traps at the locations.
2024-06-01 12:00:10 +02:00
14 changed files with 388 additions and 224 deletions

20
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,20 @@
pipeline {
agent any
stages {
stage('Gradle') {
steps {
sh './gradlew build'
}
}
stage('Archive') {
steps {
archiveArtifacts artifacts: 'build/libs/', followSymlinks: false
}
}
stage('discord') {
steps {
discordSend description: "Build: ${BUILD_NUMBER}", showChangeset: true, result: currentBuild.currentResult, title: currentBuild.fullProjectName, webhookURL: env.discordwebhook
}
}
}
}

View File

@ -39,7 +39,7 @@ repositories {
}
dependencies {
compileOnly("com.alttd:Galaxy-API:1.20.4-R0.1-SNAPSHOT")
compileOnly("com.alttd:Galaxy-API:1.21-R0.1-SNAPSHOT")
compileOnly("de.keyle:mypet:3.11-SNAPSHOT")
compileOnly("com.github.NeumimTo:Pl3xMap:1.18-2")
testImplementation("org.junit.jupiter:junit-jupiter:5.7.0")
@ -51,7 +51,7 @@ dependencies {
group = "com.griefprevention"
version = "16.18-RC2-SNAPSHOT"
description = "GriefPrevention"
java.sourceCompatibility = JavaVersion.VERSION_17
java.sourceCompatibility = JavaVersion.VERSION_21
publishing {
publications.create<MavenPublication>("maven") {

View File

@ -1,38 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>GriefPrevention Chatroom</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="IRC webclient to the #GriefPrevention channel on irc.spi.gt">
<style>
.iframe-container
{
overflow: hidden;
height: 70vh;
position: relative;
}
.iframe-container iframe
{
border: 0;
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
}
</style>
</head>
<body>
<center>
<h1>GriefPrevention Chat</h1>
<h3>Before proceeding, try searching the <a href="https://docs.griefprevention.com">Docs</a> or <a href="https://github.com/TechFortress/GriefPrevention/discussions" target="_blank">Discussions</a> for your question.</h3>
No need to wait for a response before asking; simply state your question and then wait patiently for a response. This is an idle chatroom - think of this like email instead of a phone conversation.<br />
<div class="iframe-container"><iframe loading="lazy" src="https://kiwiirc.com/client/irc.spi.gt/#GriefPrevention"></iframe></div>
<b><a href="https://r.griefprevention.com/irc" target="_blank">Chat window not appearing? Click here to open in a separate tab.</a></b><br />
Or join with your own IRC client. Server: irc.spi.gt Channel: #GriefPrevention<br />
<br/>
Want chat history? Consider using <a href="https://www.irccloud.com/" target="_blank">IRCCloud</a> or a free bouncer service. Chat logs are also available, see the channel topic.<br />
Yes, GriefPrevention has an official <a href="https://r.griefprevention.com/dumcord">discord channel.</a>
</center>
</body>
</html>

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -0,0 +1,87 @@
package com.griefprevention.protection;
import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.ClaimPermission;
import me.ryanhamshire.GriefPrevention.ClaimsMode;
import me.ryanhamshire.GriefPrevention.DataStore;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import me.ryanhamshire.GriefPrevention.Messages;
import me.ryanhamshire.GriefPrevention.PlayerData;
import me.ryanhamshire.GriefPrevention.events.PreventBlockBreakEvent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.function.Supplier;
/**
* A utility used to simplify various protection-related checks.
*/
public final class ProtectionHelper
{
private ProtectionHelper() {}
/**
* Check the {@link ClaimPermission} state for a {@link Player} at a particular {@link Location}.
*
* <p>This respects ignoring claims, wilderness rules, etc.</p>
*
* @param player the person performing the action
* @param location the affected {@link Location}
* @param permission the required permission
* @param trigger the triggering {@link Event}, if any
* @return the denial message supplier, or {@code null} if the action is not denied
*/
public static @Nullable Supplier<String> checkPermission(
@NotNull Player player,
@NotNull Location location,
@NotNull ClaimPermission permission,
@Nullable Event trigger)
{
World world = location.getWorld();
if (world == null || !GriefPrevention.instance.claimsEnabledForWorld(world)) return null;
PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId());
// Administrators ignoring claims always have permission.
if (playerData.ignoreClaims) return null;
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(location, false, playerData.lastClaim);
// If there is no claim here, use wilderness rules.
if (claim == null)
{
// If claims are not required, then the player has permission.
return null;
}
// Update cached claim.
playerData.lastClaim = claim;
// Apply claim rules.
Supplier<String> cancel = claim.checkPermission(player, permission, trigger);
// Apply additional specific rules.
if (cancel != null && trigger instanceof BlockBreakEvent breakEvent)
{
PreventBlockBreakEvent preventionEvent = new PreventBlockBreakEvent(breakEvent);
Bukkit.getPluginManager().callEvent(preventionEvent);
if (preventionEvent.isCancelled())
{
cancel = null;
}
}
return cancel;
}
}

View File

@ -18,6 +18,7 @@
package me.ryanhamshire.GriefPrevention;
import com.griefprevention.protection.ProtectionHelper;
import me.ryanhamshire.GriefPrevention.util.BoundingBox;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
@ -118,10 +119,10 @@ public class BlockEventHandler implements Listener
Block block = breakEvent.getBlock();
//make sure the player is allowed to break at the location
String noBuildReason = GriefPrevention.instance.allowBreak(player, block, block.getLocation(), breakEvent);
Supplier<String> noBuildReason = ProtectionHelper.checkPermission(player, block.getLocation(), ClaimPermission.Build, breakEvent);
if (noBuildReason != null)
{
GriefPrevention.sendMessage(player, TextMode.Err, noBuildReason);
GriefPrevention.sendMessage(player, TextMode.Err, noBuildReason.get());
breakEvent.setCancelled(true);
return;
}
@ -136,10 +137,10 @@ public class BlockEventHandler implements Listener
if (player == null || sign == null) return;
String noBuildReason = GriefPrevention.instance.allowBuild(player, sign.getLocation(), sign.getType());
Supplier<String> noBuildReason = ProtectionHelper.checkPermission(player, sign.getLocation(), ClaimPermission.Build, event);
if (noBuildReason != null)
{
GriefPrevention.sendMessage(player, TextMode.Err, noBuildReason);
GriefPrevention.sendMessage(player, TextMode.Err, noBuildReason.get());
event.setCancelled(true);
return;
}
@ -205,10 +206,10 @@ public class BlockEventHandler implements Listener
//make sure the player is allowed to build at the location
for (BlockState block : placeEvent.getReplacedBlockStates())
{
String noBuildReason = GriefPrevention.instance.allowBuild(player, block.getLocation(), block.getType());
Supplier<String> noBuildReason = ProtectionHelper.checkPermission(player, block.getLocation(), ClaimPermission.Build, placeEvent);
if (noBuildReason != null)
{
GriefPrevention.sendMessage(player, TextMode.Err, noBuildReason);
GriefPrevention.sendMessage(player, TextMode.Err, noBuildReason.get());
placeEvent.setCancelled(true);
return;
}
@ -235,35 +236,11 @@ public class BlockEventHandler implements Listener
Player player = placeEvent.getPlayer();
Block block = placeEvent.getBlock();
//FEATURE: limit fire placement, to prevent PvP-by-fire
//if placed block is fire and pvp is off, apply rules for proximity to other players
if (block.getType() == Material.FIRE && !doesAllowFireProximityInWorld(block.getWorld()))
{
List<Player> players = block.getWorld().getPlayers();
for (Player otherPlayer : players)
{
// Ignore players in creative or spectator mode to avoid users from checking if someone is spectating near them
if (otherPlayer.getGameMode() == GameMode.CREATIVE || otherPlayer.getGameMode() == GameMode.SPECTATOR)
{
continue;
}
Location location = otherPlayer.getLocation();
if (!otherPlayer.equals(player) && location.distanceSquared(block.getLocation()) < 9 && player.canSee(otherPlayer))
{
GriefPrevention.sendMessage(player, TextMode.Err, Messages.PlayerTooCloseForFire2);
placeEvent.setCancelled(true);
return;
}
}
}
//don't track in worlds where claims are not enabled
if (!GriefPrevention.instance.claimsEnabledForWorld(placeEvent.getBlock().getWorld())) return;
//make sure the player is allowed to build at the location
String noBuildReason = GriefPrevention.instance.allowBuild(player, block.getLocation(), block.getType());
Supplier<String> noBuildReason = ProtectionHelper.checkPermission(player, block.getLocation(), ClaimPermission.Build, placeEvent);
if (noBuildReason != null)
{
// Allow players with container trust to place books in lecterns
@ -283,7 +260,7 @@ public class BlockEventHandler implements Listener
return;
}
}
GriefPrevention.sendMessage(player, TextMode.Err, noBuildReason);
GriefPrevention.sendMessage(player, TextMode.Err, noBuildReason.get());
placeEvent.setCancelled(true);
return;
}

View File

@ -1529,8 +1529,11 @@ public abstract class DataStore
this.addDefault(defaults, Messages.AdvertiseACB, "You may use /ACB to give yourself more claim blocks.", null);
this.addDefault(defaults, Messages.NotYourPet, "That belongs to {0} until it's given to you with /GivePet.", "0: owner name");
this.addDefault(defaults, Messages.PetGiveawayConfirmation, "Pet transferred.", null);
this.addDefault(defaults, Messages.PetAbandonConfirmation, "Pet abandoned.", null);
this.addDefault(defaults, Messages.PetTransferCancellation, "Pet giveaway cancelled.", null);
this.addDefault(defaults, Messages.PetAbandonCancellation, "Pet giveaway cancelled.", null);
this.addDefault(defaults, Messages.ReadyToTransferPet, "Ready to transfer! Right-click the pet you'd like to give away, or cancel with /GivePet cancel.", null);
this.addDefault(defaults, Messages.ReadyToAbandonPet, "Ready to abandon! Right-click the pet you'd like to abandon.", null);
this.addDefault(defaults, Messages.AvoidGriefClaimLand, "Prevent grief! If you claim your land, you will be grief-proof.", null);
this.addDefault(defaults, Messages.BecomeMayor, "Subdivide your land claim and become a mayor!", null);
this.addDefault(defaults, Messages.ClaimCreationFailedOverClaimCountLimit, "You've reached your limit on land claims. Use /AbandonClaim to remove one before creating another.", null);
@ -1588,6 +1591,8 @@ public abstract class DataStore
this.addDefault(defaults, Messages.SubclaimUnrestricted, "This subclaim's permissions will now inherit from the parent claim", null);
this.addDefault(defaults, Messages.NetherPortalTrapDetectionMessage, "It seems you might be stuck inside a nether portal. We will rescue you in a few seconds if that is the case!", "Sent to player on join, if they left while inside a nether portal.");
this.addDefault(defaults, Messages.NoSubDivisions, "This claim has no subdivisions.", null);
this.addDefault(defaults, Messages.SubDivisionsRemoved, "This claim has all subdivisions removed.", null);
//load the config file
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(messagesFilePath));

View File

@ -18,10 +18,12 @@
package me.ryanhamshire.GriefPrevention;
import com.griefprevention.protection.ProtectionHelper;
import de.Keyle.MyPet.api.entity.MyPetBukkitEntity;
import me.ryanhamshire.GriefPrevention.events.PreventPvPEvent;
import me.ryanhamshire.GriefPrevention.events.ProtectDeathDropsEvent;
import org.bukkit.Bukkit;
import org.bukkit.ExplosionResult;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
@ -58,6 +60,7 @@ import org.bukkit.entity.WaterMob;
import org.bukkit.entity.Wolf;
import org.bukkit.entity.Zombie;
import org.bukkit.entity.minecart.ExplosiveMinecart;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -96,9 +99,12 @@ import org.bukkit.metadata.MetadataValue;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionEffectTypeCategory;
import org.bukkit.projectiles.BlockProjectileSource;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
@ -128,16 +134,12 @@ public class EntityEventHandler implements Listener
public void onEntityFormBlock(EntityBlockFormEvent event)
{
Entity entity = event.getEntity();
if (entity.getType() == EntityType.PLAYER)
{
Player player = (Player) event.getEntity();
String noBuildReason = GriefPrevention.instance.allowBuild(player, event.getBlock().getLocation(), event.getNewState().getType());
if (noBuildReason != null)
if (entity instanceof Player player
&& ProtectionHelper.checkPermission(player, event.getBlock().getLocation(), ClaimPermission.Build, event) != null)
{
event.setCancelled(true);
}
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onEntityChangeBLock(EntityChangeBlockEvent event)
@ -182,15 +184,14 @@ public class EntityEventHandler implements Listener
//don't allow crops to be trampled, except by a player with build permission
else if (event.getTo() == Material.DIRT && event.getBlock().getType() == Material.FARMLAND)
{
if (event.getEntityType() != EntityType.PLAYER)
if (!(event.getEntity() instanceof Player player))
{
event.setCancelled(true);
}
else
{
Player player = (Player) event.getEntity();
Block block = event.getBlock();
if (GriefPrevention.instance.allowBreak(player, block, block.getLocation()) != null)
if (ProtectionHelper.checkPermission(player, block.getLocation(), ClaimPermission.Build, event) != null)
{
event.setCancelled(true);
}
@ -201,10 +202,10 @@ public class EntityEventHandler implements Listener
else if (event.getEntity() instanceof Vehicle && !event.getEntity().getPassengers().isEmpty())
{
Entity driver = event.getEntity().getPassengers().get(0);
if (driver instanceof Player)
if (driver instanceof Player player)
{
Block block = event.getBlock();
if (GriefPrevention.instance.allowBreak((Player) driver, block, block.getLocation()) != null)
if (ProtectionHelper.checkPermission(player, block.getLocation(), ClaimPermission.Build, event) != null)
{
event.setCancelled(true);
}
@ -336,7 +337,7 @@ public class EntityEventHandler implements Listener
@EventHandler(ignoreCancelled = true)
void onTNTExitPortal(EntityPortalExitEvent event)
{
if (event.getEntityType() != EntityType.PRIMED_TNT)
if (event.getEntityType() != EntityType.TNT)
return;
if (event.getTo().getWorld().getEnvironment() != Environment.THE_END)
return;
@ -376,23 +377,99 @@ public class EntityEventHandler implements Listener
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onEntityExplode(EntityExplodeEvent explodeEvent)
{
this.handleExplosion(explodeEvent.getLocation(), explodeEvent.getEntity(), explodeEvent.blockList());
// If there aren't any affected blocks, there's nothing to do. Vanilla mob griefing rule causes this.
if (explodeEvent.blockList().isEmpty()) return;
// Explosion causes interactable blocks (levers, buttons, etc.) to change state.
if (explodeEvent.getExplosionResult() == ExplosionResult.TRIGGER_BLOCK)
{
handleExplodeInteract(explodeEvent.getLocation(), explodeEvent.getEntity(), explodeEvent.blockList(), explodeEvent);
}
// Explosion damages world.
else
{
handleExplosion(explodeEvent.getLocation(), explodeEvent.getEntity(), explodeEvent.blockList());
}
}
//when a block explodes...
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onBlockExplode(BlockExplodeEvent explodeEvent)
{
this.handleExplosion(explodeEvent.getBlock().getLocation(), null, explodeEvent.blockList());
// If there aren't any affected blocks, there's nothing to do. Vanilla mob griefing rule causes this.
if (explodeEvent.blockList().isEmpty()) return;
// Explosion causes interactable blocks (levers, buttons, etc.) to change state.
if (explodeEvent.getExplosionResult() == ExplosionResult.TRIGGER_BLOCK)
{
handleExplodeInteract(explodeEvent.getBlock().getLocation(), null, explodeEvent.blockList(), explodeEvent);
}
// Explosion damages world.
else
{
handleExplosion(explodeEvent.getBlock().getLocation(), null, explodeEvent.blockList());
}
}
void handleExplodeInteract(@NotNull Location location, @Nullable Entity entity, @NotNull List<Block> blocks, @NotNull Event event)
{
World world = location.getWorld();
void handleExplosion(Location location, Entity entity, List<Block> blocks)
if (world == null || !GriefPrevention.instance.claimsEnabledForWorld(world)) return;
Player player = null;
PlayerData playerData = null;
ProjectileSource source = null;
if (entity instanceof Projectile projectile)
{
source = projectile.getShooter();
if (source instanceof Player)
{
player = (Player) source;
playerData = dataStore.getPlayerData(player.getUniqueId());
}
}
List<Block> removed = new ArrayList<>();
Claim cachedClaim = playerData != null ? playerData.lastClaim : null;
for (Block block : blocks)
{
// Always ignore air blocks.
if (block.getType().isAir()) continue;
Claim claim = this.dataStore.getClaimAt(block.getLocation(), false, cachedClaim);
// Is it in a land claim?
if (claim == null) continue;
cachedClaim = claim;
if (player == null)
{
// If the source is not part of the claim, prevent interaction.
if (!isBlockSourceInClaim(source, claim))
removed.add(block);
continue;
}
// If the player is not allowed to interact with blocks, prevent interaction.
if (claim.checkPermission(player, ClaimPermission.Access, event) != null)
removed.add(block);
}
if (playerData != null && cachedClaim != null)
playerData.lastClaim = cachedClaim;
blocks.removeAll(removed);
}
void handleExplosion(@NotNull Location location, @Nullable Entity entity, @NotNull List<Block> blocks)
{
//only applies to claims-enabled worlds
World world = location.getWorld();
if (!GriefPrevention.instance.claimsEnabledForWorld(world)) return;
if (world == null || !GriefPrevention.instance.claimsEnabledForWorld(world)) return;
//FEATURE: explosions don't destroy surface blocks by default
boolean isCreeper = (entity != null && entity.getType() == EntityType.CREEPER);
@ -405,7 +482,7 @@ public class EntityEventHandler implements Listener
for (Block block : blocks)
{
//always ignore air blocks
if (block.getType() == Material.AIR) continue;
if (block.getType().isAir()) continue;
//is it in a land claim?
Claim claim = this.dataStore.getClaimAt(block.getLocation(), false, cachedClaim);
@ -588,19 +665,18 @@ public class EntityEventHandler implements Listener
Entity remover = entityEvent.getRemover();
//again, making sure the breaker is a player
if (remover.getType() != EntityType.PLAYER)
if (!(remover instanceof Player playerRemover))
{
event.setCancelled(true);
return;
}
//if the player doesn't have build permission, don't allow the breakage
Player playerRemover = (Player) entityEvent.getRemover();
String noBuildReason = GriefPrevention.instance.allowBuild(playerRemover, event.getEntity().getLocation(), Material.AIR);
Supplier<String> noBuildReason = ProtectionHelper.checkPermission(playerRemover, event.getEntity().getLocation(), ClaimPermission.Build, event);
if (noBuildReason != null)
{
event.setCancelled(true);
GriefPrevention.sendMessage(playerRemover, TextMode.Err, noBuildReason);
GriefPrevention.sendMessage(playerRemover, TextMode.Err, noBuildReason.get());
}
}
@ -610,15 +686,16 @@ public class EntityEventHandler implements Listener
{
//don't track in worlds where claims are not enabled
if (!GriefPrevention.instance.claimsEnabledForWorld(event.getBlock().getWorld())) return;
if (event.getPlayer() == null) return;
//FEATURE: similar to above, placing a painting requires build permission in the claim
//if the player doesn't have permission, don't allow the placement
String noBuildReason = GriefPrevention.instance.allowBuild(event.getPlayer(), event.getEntity().getLocation(), Material.PAINTING);
Supplier<String> noBuildReason = ProtectionHelper.checkPermission(event.getPlayer(), event.getEntity().getLocation(), ClaimPermission.Build, event);
if (noBuildReason != null)
{
event.setCancelled(true);
GriefPrevention.sendMessage(event.getPlayer(), TextMode.Err, noBuildReason);
GriefPrevention.sendMessage(event.getPlayer(), TextMode.Err, noBuildReason.get());
return;
}
@ -694,7 +771,7 @@ public class EntityEventHandler implements Listener
if (event.getEntity() instanceof Mule && !GriefPrevention.instance.config_claims_protectDonkeys) return;
if (event.getEntity() instanceof Llama && !GriefPrevention.instance.config_claims_protectLlamas) return;
//protected death loot can't be destroyed, only picked up or despawned due to expiration
if (event.getEntityType() == EntityType.DROPPED_ITEM)
if (event.getEntityType() == EntityType.ITEM)
{
if (event.getEntity().hasMetadata("GP_ITEMOWNER"))
{
@ -943,7 +1020,7 @@ public class EntityEventHandler implements Listener
|| subEvent.getEntityType() == EntityType.GLOW_ITEM_FRAME
|| subEvent.getEntityType() == EntityType.ARMOR_STAND
|| subEvent.getEntityType() == EntityType.VILLAGER
|| subEvent.getEntityType() == EntityType.ENDER_CRYSTAL)
|| subEvent.getEntityType() == EntityType.END_CRYSTAL)
{
//allow for disabling villager protections in the config
if (subEvent.getEntityType() == EntityType.VILLAGER && !GriefPrevention.instance.config_claims_protectCreatures)
@ -1071,7 +1148,7 @@ public class EntityEventHandler implements Listener
&& damageSource != null
&& damageSource.getType() != EntityType.CREEPER
&& damageSource.getType() != EntityType.WITHER
&& damageSource.getType() != EntityType.ENDER_CRYSTAL
&& damageSource.getType() != EntityType.END_CRYSTAL
&& damageSource.getType() != EntityType.AREA_EFFECT_CLOUD
&& damageSource.getType() != EntityType.WITCH
&& !(damageSource instanceof Projectile)
@ -1136,7 +1213,7 @@ public class EntityEventHandler implements Listener
//kill the arrow to avoid infinite bounce between crowded together animals //RoboMWM: except for tridents
if (arrow != null && arrow.getType() != EntityType.TRIDENT) arrow.remove();
if (damageSource != null && damageSource.getType() == EntityType.FIREWORK && event.getEntity().getType() != EntityType.PLAYER)
if (damageSource != null && damageSource.getType() == EntityType.FIREWORK_ROCKET && event.getEntity().getType() != EntityType.PLAYER)
return;
try {
@ -1317,7 +1394,7 @@ public class EntityEventHandler implements Listener
}
//if not a player and not an explosion, always allow
if (attacker == null && damageSourceType != EntityType.CREEPER && damageSourceType != EntityType.WITHER && damageSourceType != EntityType.PRIMED_TNT)
if (attacker == null && damageSourceType != EntityType.CREEPER && damageSourceType != EntityType.WITHER && damageSourceType != EntityType.TNT)
{
return;
}
@ -1405,9 +1482,9 @@ public class EntityEventHandler implements Listener
// Restrict some potions on claimed villagers and animals.
// Griefers could use potions to kill entities or steal them over fences.
if (PotionEffectType.HARM.equals(effectType)
if (PotionEffectType.INSTANT_DAMAGE.equals(effectType)
|| PotionEffectType.POISON.equals(effectType)
|| PotionEffectType.JUMP.equals(effectType)
|| PotionEffectType.JUMP_BOOST.equals(effectType)
|| PotionEffectType.WITHER.equals(effectType))
{
Claim cachedClaim = null;
@ -1456,7 +1533,7 @@ public class EntityEventHandler implements Listener
if (thrower == null) return;
//otherwise, no restrictions for positive effects
if (positiveEffects.contains(effectType)) continue;
if (effectType.getCategory() == PotionEffectTypeCategory.BENEFICIAL) continue;
for (LivingEntity effected : event.getAffectedEntities())
{
@ -1528,9 +1605,9 @@ public class EntityEventHandler implements Listener
// Restrict some potions on claimed villagers and animals.
// Griefers could use potions to kill entities or steal them over fences.
if (PotionEffectType.HARM.equals(effectType)
if (PotionEffectType.INSTANT_DAMAGE.equals(effectType)
|| PotionEffectType.POISON.equals(effectType)
|| PotionEffectType.JUMP.equals(effectType)
|| PotionEffectType.JUMP_BOOST.equals(effectType)
|| PotionEffectType.WITHER.equals(effectType))
{
Claim cachedClaim = null;
@ -1577,22 +1654,4 @@ public class EntityEventHandler implements Listener
}
}
public static final HashSet<PotionEffectType> positiveEffects = new HashSet<>(Arrays.asList
(
PotionEffectType.ABSORPTION,
PotionEffectType.DAMAGE_RESISTANCE,
PotionEffectType.FAST_DIGGING,
PotionEffectType.FIRE_RESISTANCE,
PotionEffectType.HEAL,
PotionEffectType.HEALTH_BOOST,
PotionEffectType.INCREASE_DAMAGE,
PotionEffectType.INVISIBILITY,
PotionEffectType.JUMP,
PotionEffectType.NIGHT_VISION,
PotionEffectType.REGENERATION,
PotionEffectType.SATURATION,
PotionEffectType.SPEED,
PotionEffectType.WATER_BREATHING
));
}

View File

@ -18,6 +18,7 @@
package me.ryanhamshire.GriefPrevention;
import com.griefprevention.protection.ProtectionHelper;
import me.ryanhamshire.GriefPrevention.DataStore.NoTransferException;
import me.ryanhamshire.GriefPrevention.alttd.config.Config;
import me.ryanhamshire.GriefPrevention.alttd.database.DatabaseConnection;
@ -1117,6 +1118,12 @@ public class GriefPrevention extends JavaPlugin
return this.abandonClaimHandler(player, true);
}
//abandonsublevelclaim
if (cmd.getName().equalsIgnoreCase("abandonsublevelclaim") && player != null)
{
return this.abandonSubLevelClaimHandler(player);
}
//forceabandonclaim
if (cmd.getName().equalsIgnoreCase("forceabandonclaim") && player != null)
{
@ -2452,6 +2459,28 @@ public class GriefPrevention extends JavaPlugin
return true;
}
//abandonpet
else if (cmd.getName().equalsIgnoreCase("abandonpet") && player != null)
{
PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
//special case: cancellation
if (args.length > 0 && args[0].equalsIgnoreCase("cancel"))
{
playerData.petAbandonment = false;
GriefPrevention.sendMessage(player, TextMode.Success, Messages.PetTransferCancellation);
return true;
}
playerData.petAbandonment = true;
//send instructions
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.ReadyToAbandonPet);
return true;
}
//gpblockinfo
else if (cmd.getName().equalsIgnoreCase("gpblockinfo") && player != null)
{
@ -2501,13 +2530,13 @@ public class GriefPrevention extends JavaPlugin
return true;
}
zone.testForSafeSpot();
Location safe = zone.getSafeArea();
Location safe = Bukkit.getWorlds().get(0).getSpawnLocation();
if (safe == null) {
player.sendMiniMessage(Config.NoSafeLocation, null); // todo placeholders.
} else {
if (target.isInsideVehicle()) target.leaveVehicle();
target.teleport(safe);
Bukkit.getPluginManager().callEvent(new PlayerTeleportEvent(target, safe, safe));
Bukkit.getPluginManager().callEvent(new PlayerTeleportEvent(target, safe, zone.getSafeArea()));
player.sendMiniMessage(Config.KickSuccess, placeholders); // todo placeholders.
target.sendMiniMessage(Config.KickedFromClaim, placeholders); // todo placeholders.
}
@ -2541,6 +2570,40 @@ public class GriefPrevention extends JavaPlugin
return location.getWorld().getName() + ": x" + location.getBlockX() + ", z" + location.getBlockZ() + " to x" + location2.getBlockX() + ", z" + location2.getBlockZ();
}
private boolean abandonSubLevelClaimHandler(Player player)
{
//which claim is being abandoned?
Claim claim = this.dataStore.getClaimAt(player.getLocation(), true /*ignore height*/, null);
if (claim == null)
{
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.AbandonClaimMissing);
}
//verify ownership
else if (claim.checkPermission(player, ClaimPermission.Edit, null) != null)
{
GriefPrevention.sendMessage(player, TextMode.Err, Messages.NotYourClaim);
}
else if (claim.children.isEmpty())
{
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.NoSubDivisions);
return true;
}
else
{
//delete it
for (Claim subClaim : claim.children)
{
GriefPrevention.instance.dataStore.deleteClaim(subClaim, false, true);
}
//revert any current visualization
Visualization.Revert(player);
}
return true;
}
private boolean abandonClaimHandler(Player player, boolean deleteTopLevelClaim)
{
PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
@ -3050,89 +3113,68 @@ public class GriefPrevention extends JavaPlugin
return mode != null && mode != ClaimsMode.Disabled;
}
/**
* @deprecated use {@link ProtectionHelper#checkPermission(Player, Location, ClaimPermission, org.bukkit.event.Event)}
*/
@Deprecated(forRemoval = true, since = "17.0.0")
public String allowBuild(Player player, Location location)
{
// TODO check all derivatives and rework API
return this.allowBuild(player, location, location.getBlock().getType());
}
/**
* @deprecated use {@link ProtectionHelper#checkPermission(Player, Location, ClaimPermission, org.bukkit.event.Event)}
*/
@Deprecated(forRemoval = true, since = "17.0.0")
public String allowBuild(Player player, Location location, Material material)
{
if (!GriefPrevention.instance.claimsEnabledForWorld(location.getWorld())) return null;
PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
Claim claim = this.dataStore.getClaimAt(location, false, playerData.lastClaim);
//exception: administrators in ignore claims mode
if (playerData.ignoreClaims) return null;
//wilderness rules
if (claim == null)
ItemStack placed;
if (material.isItem())
{
return null;
placed = new ItemStack(material);
}
//if not in the wilderness, then apply claim rules (permissions, etc)
else
{
//cache the claim for later reference
playerData.lastClaim = claim;
var blockType = material.asBlockType();
if (blockType != null && blockType.hasItemType())
placed = blockType.getItemType().createItemStack();
else
placed = new ItemStack(Material.DIRT);
}
Block block = location.getBlock();
Supplier<String> supplier = claim.checkPermission(player, ClaimPermission.Build, new BlockPlaceEvent(block, block.getState(), block, new ItemStack(material), player, true, EquipmentSlot.HAND));
if (supplier == null) return null;
return supplier.get();
}
Supplier<String> result = ProtectionHelper.checkPermission(player, location, ClaimPermission.Build, new BlockPlaceEvent(block, block.getState(), block, placed, player, true, EquipmentSlot.HAND));
return result == null ? null : result.get();
}
/**
* @deprecated use {@link ProtectionHelper#checkPermission(Player, Location, ClaimPermission, org.bukkit.event.Event)}
*/
@Deprecated(forRemoval = true, since = "17.0.0")
public String allowBreak(Player player, Block block, Location location)
{
return this.allowBreak(player, block, location, new BlockBreakEvent(block, player));
}
/**
* @deprecated use {@link ProtectionHelper#checkPermission(Player, Location, ClaimPermission, org.bukkit.event.Event)}
*/
@Deprecated(forRemoval = true, since = "17.0.0")
public String allowBreak(Player player, Material material, Location location, BlockBreakEvent breakEvent)
{
return this.allowBreak(player, location.getBlock(), location, breakEvent);
}
/**
* @deprecated use {@link ProtectionHelper#checkPermission(Player, Location, ClaimPermission, org.bukkit.event.Event)}
*/
@Deprecated(forRemoval = true, since = "17.0.0")
public String allowBreak(Player player, Block block, Location location, BlockBreakEvent breakEvent)
{
if (!GriefPrevention.instance.claimsEnabledForWorld(location.getWorld())) return null;
PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
Claim claim = this.dataStore.getClaimAt(location, false, playerData.lastClaim);
//exception: administrators in ignore claims mode
if (playerData.ignoreClaims) return null;
//wilderness rules
if (claim == null)
{
return null;
}
else
{
//cache the claim for later reference
playerData.lastClaim = claim;
//if not in the wilderness, then apply claim rules (permissions, etc)
Supplier<String> cancel = claim.checkPermission(player, ClaimPermission.Build, breakEvent);
if (cancel != null && breakEvent != null)
{
PreventBlockBreakEvent preventionEvent = new PreventBlockBreakEvent(breakEvent);
Bukkit.getPluginManager().callEvent(preventionEvent);
if (preventionEvent.isCancelled())
{
cancel = null;
}
}
if (cancel == null) return null;
return cancel.get();
}
Supplier<String> result = ProtectionHelper.checkPermission(player, location, ClaimPermission.Build, breakEvent);
return result == null ? null : result.get();
}
public void restoreChunk(Chunk chunk, int miny, boolean aggressiveMode, long delayInTicks, Player playerReceivingVisualization)

View File

@ -196,8 +196,11 @@ public enum Messages
AdvertiseACB,
NotYourPet,
PetGiveawayConfirmation,
PetAbandonConfirmation,
PetTransferCancellation,
PetAbandonCancellation,
ReadyToTransferPet,
ReadyToAbandonPet,
AvoidGriefClaimLand,
BecomeMayor,
ClaimCreationFailedOverClaimCountLimit,
@ -255,5 +258,7 @@ public enum Messages
SubclaimRestricted,
SubclaimUnrestricted,
NetherPortalTrapDetectionMessage,
NoClaimTrust
NoClaimTrust,
NoSubDivisions,
SubDivisionsRemoved
}

View File

@ -112,6 +112,7 @@ public class PlayerData
//player which a pet will be given to when it's right-clicked
OfflinePlayer petGiveawayRecipient = null;
boolean petAbandonment = false;
//timestamp for last "you're building outside your land claims" message
Long buildWarningTimestamp = null;

View File

@ -19,9 +19,9 @@
package me.ryanhamshire.GriefPrevention;
import com.destroystokyo.paper.loottable.LootableBlockInventory;
import com.griefprevention.protection.ProtectionHelper;
import me.ryanhamshire.GriefPrevention.events.ClaimInspectionEvent;
import me.ryanhamshire.GriefPrevention.events.VisualizationEvent;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
@ -38,7 +38,6 @@ import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Levelled;
import org.bukkit.block.data.Waterlogged;
import org.bukkit.command.Command;
import org.bukkit.entity.AbstractHorse;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Creature;
@ -47,7 +46,6 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Fish;
import org.bukkit.entity.Hanging;
import org.bukkit.entity.Item;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Llama;
import org.bukkit.entity.Mule;
@ -63,8 +61,6 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.CauldronLevelChangeEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
@ -89,10 +85,7 @@ import org.bukkit.event.raid.RaidTriggerEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.loot.Lootable;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.BlockIterator;
@ -585,6 +578,15 @@ class PlayerEventHandler implements Listener
//if the player interacting is the owner or an admin in ignore claims mode, always allow
if (player.getUniqueId().equals(ownerID) || playerData.ignoreClaims)
{
//if abandoning a pet, do that instead
if (playerData.petAbandonment)
{
tameable.setOwner(null);
playerData.petAbandonment = false;
GriefPrevention.sendMessage(player, TextMode.Success, Messages.PetGiveawayConfirmation);
event.setCancelled(true);
}
//if giving away pet, do that instead
if (playerData.petGiveawayRecipient != null)
{
@ -626,10 +628,10 @@ class PlayerEventHandler implements Listener
//don't allow interaction with item frames or armor stands in claimed areas without build permission
if (entity.getType() == EntityType.ARMOR_STAND || entity instanceof Hanging && !(entity instanceof ItemFrame))
{
String noBuildReason = instance.allowBuild(player, entity.getLocation(), Material.ITEM_FRAME);
Supplier<String> noBuildReason = ProtectionHelper.checkPermission(player, entity.getLocation(), ClaimPermission.Build, event);
if (noBuildReason != null)
{
GriefPrevention.sendMessage(player, TextMode.Err, noBuildReason);
GriefPrevention.sendMessage(player, TextMode.Err, noBuildReason.get());
event.setCancelled(true);
return;
}
@ -886,10 +888,10 @@ class PlayerEventHandler implements Listener
}
//make sure the player is allowed to build at the location
String noBuildReason = instance.allowBuild(player, block.getLocation(), Material.WATER);
Supplier<String> noBuildReason = ProtectionHelper.checkPermission(player, block.getLocation(), ClaimPermission.Build, bucketEvent);
if (noBuildReason != null)
{
GriefPrevention.sendMessage(player, TextMode.Err, noBuildReason);
GriefPrevention.sendMessage(player, TextMode.Err, noBuildReason.get());
bucketEvent.setCancelled(true);
return;
}
@ -972,10 +974,6 @@ class PlayerEventHandler implements Listener
if (!instance.claimsEnabledForWorld(block.getWorld())) return;
//make sure the player is allowed to build at the location
String noBuildReason = instance.allowBuild(player, block.getLocation(), Material.AIR);
if (noBuildReason != null)
{
//exemption for cow milking (permissions will be handled by player interact with entity event instead)
Material blockType = block.getType();
if (blockType == Material.AIR)
@ -985,13 +983,17 @@ class PlayerEventHandler implements Listener
BlockData blockData = block.getBlockData();
if (!(blockData instanceof Waterlogged) || !((Waterlogged) blockData).isWaterlogged())
return;
}
GriefPrevention.sendMessage(player, TextMode.Err, noBuildReason);
//make sure the player is allowed to build at the location
Supplier<String> noBuildReason = ProtectionHelper.checkPermission(player, block.getLocation(), ClaimPermission.Build, bucketEvent);
if (noBuildReason != null)
{
GriefPrevention.sendMessage(player, TextMode.Err, noBuildReason.get());
bucketEvent.setCancelled(true);
return;
}
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerBucketatCauldron(CauldronLevelChangeEvent event)
@ -1305,15 +1307,13 @@ class PlayerEventHandler implements Listener
|| materialInHand == Material.FLINT_AND_STEEL
|| materialInHand == Material.INK_SAC
|| materialInHand == Material.GLOW_INK_SAC
|| materialInHand == Material.HONEYCOMB
|| dyes.contains(materialInHand)))
{
String noBuildReason = instance
.allowBuild(player, clickedBlock
.getLocation(),
clickedBlockType);
Supplier<String> noBuildReason = ProtectionHelper.checkPermission(player, event.getClickedBlock().getLocation(), ClaimPermission.Build, event);
if (noBuildReason != null)
{
GriefPrevention.sendMessage(player, TextMode.Err, noBuildReason);
GriefPrevention.sendMessage(player, TextMode.Err, noBuildReason.get());
event.setCancelled(true);
}
@ -2066,10 +2066,7 @@ class PlayerEventHandler implements Listener
{
result = iterator.next();
Material type = result.getType();
if (type != Material.AIR &&
(!passThroughWater || type != Material.WATER) &&
type != Material.SHORT_GRASS &&
type != Material.SNOW) return result;
if (!Tag.REPLACEABLE.isTagged(type) || (!passThroughWater && type == Material.WATER)) return result;
}
return result;

View File

@ -7,9 +7,10 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.jetbrains.annotations.NotNull;
/**
* An {@link Event} called when GriefPrevention prevents a {@link BlockBreakEvent}.
* If cancelled, GriefPrevention will allow the event to complete normally.
* @deprecated Listen to {@link ClaimPermissionCheckEvent} and check if
* {@link ClaimPermissionCheckEvent#getTriggeringEvent()} {@code instanceof} {@link BlockBreakEvent}.
*/
@Deprecated(forRemoval = true, since = "17.0.0")
public class PreventBlockBreakEvent extends Event implements Cancellable
{
private final @NotNull BlockBreakEvent innerEvent;

View File

@ -4,7 +4,7 @@ softdepend: [Vault, Multiverse-Core, My_Worlds, MystCraft, Transporter, TheUnder
dev-url: https://dev.bukkit.org/projects/grief-prevention
loadbefore: [TheUnderground]
version: '${git.commit.id.describe}'
api-version: '1.17'
api-version: '1.21'
commands:
abandonclaim:
description: Deletes a claim.
@ -15,6 +15,10 @@ commands:
description: Deletes a claim and all its subdivisions.
usage: /AbandonTopLevelClaim
permission: griefprevention.claims
abandonsublevelclaim:
description: Deletes all subdivisions in a claim.
usage: /abandonsublevelclaim
permission: griefprevention.claims
abandonallclaims:
description: Deletes ALL your claims.
usage: /AbandonAllClaims
@ -189,6 +193,10 @@ commands:
description: Allows a player to give away a pet he or she tamed.
usage: /GivePet <player>
permission: griefprevention.givepet
abandonpet:
description: Allows a player to abandon a pet he or she tamed.
usage: /Abandonpet <player>
permission: griefprevention.abandonpet
gpblockinfo:
description: Allows an administrator to get technical information about blocks in the world and items in hand.
usage: /GPBlockInfo