-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
# Conflicts: # .github/workflows/ci.yml # .gitignore # pom.xml # src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java # src/main/java/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java # src/main/java/me/ryanhamshire/GriefPrevention/RestoreNatureProcessingTask.java
- Loading branch information
Showing
27 changed files
with
937 additions
and
2,356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,80 @@ | ||
# Eclipse | ||
/.classpath | ||
/.project | ||
/.settings | ||
/*.jardesc | ||
*.class | ||
|
||
# IntelliJ | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# NetBeans | ||
/nbproject | ||
# Package Files # | ||
*.war | ||
*.ear | ||
|
||
# vim | ||
.*.sw[a-p] | ||
# ========================= | ||
# Ignore Eclipse Artifacts | ||
# ========================= | ||
.settings/ | ||
.classpath | ||
.project | ||
|
||
# Maven | ||
/build.xml | ||
/target | ||
/dependency-reduced-pom.xml | ||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
|
||
# various other potential build files | ||
/build | ||
/bin | ||
/dist | ||
/manifest.mf | ||
# ========================= | ||
# Operating System Files | ||
# ========================= | ||
|
||
# OSX | ||
# ========================= | ||
|
||
# Mac Filesystem Dust | ||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear on external disk | ||
.Spotlight-V100 | ||
.Trashes | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
# Windows | ||
# ========================= | ||
|
||
# Windows image file caches | ||
Thumbs.db | ||
ehthumbs.db | ||
|
||
# Folder config file | ||
Desktop.ini | ||
|
||
# Recycle Bin used on file shares | ||
$RECYCLE.BIN/ | ||
|
||
# Windows Installer files | ||
*.cab | ||
*.msi | ||
*.msm | ||
*.msp | ||
|
||
# Windows shortcuts | ||
*.lnk | ||
|
||
# IntelliJ | ||
workspace.xml | ||
tasks.xml | ||
.idea/libraries | ||
.idea/copyright | ||
out/ | ||
target/ | ||
*.MF | ||
*.name | ||
.idea | ||
*.iml | ||
|
||
# Windows Filesystem Dust | ||
Thumbs.db | ||
# VS Code | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
before_install: | ||
- sdk install java 17.0.1-open | ||
- sdk use java 17.0.1-open | ||
- sdk install java 21.0.3-tem | ||
- sdk use java 21.0.3-tem | ||
- mvn wrapper:wrapper -Dmaven=3.6.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/main/java/com/griefprevention/protection/ProtectionHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
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) | ||
{ | ||
ClaimsMode mode = GriefPrevention.instance.config_claims_worldModes.get(world); | ||
if (mode == ClaimsMode.Creative || mode == ClaimsMode.SurvivalRequiringClaims) | ||
{ | ||
// Allow placing chest if it would create an automatic claim. | ||
if (trigger instanceof BlockPlaceEvent placeEvent | ||
&& placeEvent.getBlock().getType() == Material.CHEST | ||
&& playerData.getClaims().isEmpty() | ||
&& GriefPrevention.instance.config_claims_automaticClaimsForNewPlayersRadius > -1) | ||
return null; | ||
|
||
// If claims are required, provide relevant information. | ||
return () -> | ||
{ | ||
String reason = GriefPrevention.instance.dataStore.getMessage(Messages.NoBuildOutsideClaims); | ||
if (player.hasPermission("griefprevention.ignoreclaims")) | ||
reason += " " + GriefPrevention.instance.dataStore.getMessage(Messages.IgnoreClaimsAdvertisement); | ||
reason += " " + GriefPrevention.instance.dataStore.getMessage(Messages.CreativeBasicsVideo2, DataStore.CREATIVE_VIDEO_URL); | ||
return reason; | ||
}; | ||
} | ||
|
||
// 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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.