Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
# 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
NahuLD committed Sep 24, 2024
2 parents b0d57b7 + 1e5f48a commit 775343d
Show file tree
Hide file tree
Showing 27 changed files with 937 additions and 2,356 deletions.
98 changes: 72 additions & 26 deletions .gitignore
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/
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ clone_depth: 10
environment:
matrix:
- appveyor_build_worker_image: Visual Studio 2022
JAVA_HOME: C:\Program Files\Java\jdk17
JAVA_HOME: C:\Program Files\Java\jdk21
branches:
only:
- master
Expand Down
5 changes: 3 additions & 2 deletions jitpack.yml
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
16 changes: 8 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>16</source>
<target>16</target>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
<!-- Append git commit hash to version -->
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>4.0.3</version>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
<version>9.0.1</version>
<executions>
<execution>
<id>get-the-git-infos</id>
Expand Down Expand Up @@ -162,9 +162,9 @@
<dependencies>
<!-- Bukkit API. Bukkit has never ever deployed a release version -->
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.20.4-R0.1-SNAPSHOT</version>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.21-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- Annotations for nullity and other behaviors -->
Expand Down
108 changes: 108 additions & 0 deletions src/main/java/com/griefprevention/protection/ProtectionHelper.java
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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

/**
* A representation of a system for displaying rectangular {@link Boundary Boundaries} to {@link Player Players}.
* This is used to display claim areas, visualize affected area during nature restoration, and more.
* This is used to display claim areas, conflicting claims, and more.
*/
public abstract class BoundaryVisualization
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public enum VisualizationType
/** Boundaries for a new claim area. */
INITIALIZE_ZONE,
/** Boundaries for a conflicting area. */
CONFLICT_ZONE,
/** Boundaries for area in which nature has been restored. */
NATURE_RESTORATION_ZONE
CONFLICT_ZONE

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public FakeBlockVisualization(@NotNull World world, @NotNull IntVector visualize
return addBlockElement(switch (boundary.type())
{
case SUBDIVISION -> Material.IRON_BLOCK.createBlockData();
case INITIALIZE_ZONE, NATURE_RESTORATION_ZONE -> Material.DIAMOND_BLOCK.createBlockData();
case INITIALIZE_ZONE -> Material.DIAMOND_BLOCK.createBlockData();
case CONFLICT_ZONE -> {
BlockData fakeData = Material.REDSTONE_ORE.createBlockData();
((Lightable) fakeData).setLit(true);
Expand All @@ -63,7 +63,7 @@ public FakeBlockVisualization(@NotNull World world, @NotNull IntVector visualize
{
case ADMIN_CLAIM -> Material.PUMPKIN.createBlockData();
case SUBDIVISION -> Material.WHITE_WOOL.createBlockData();
case INITIALIZE_ZONE, NATURE_RESTORATION_ZONE -> Material.DIAMOND_BLOCK.createBlockData();
case INITIALIZE_ZONE -> Material.DIAMOND_BLOCK.createBlockData();
case CONFLICT_ZONE -> Material.NETHERRACK.createBlockData();
default -> Material.GOLD_BLOCK.createBlockData();
});
Expand Down
Loading

0 comments on commit 775343d

Please sign in to comment.