Skip to content

Commit

Permalink
[CORE] Introduce GriefDefender Protection - Fixes #81
Browse files Browse the repository at this point in the history
Signed-off-by: xMakeItRain94@gmail.com <ParamoreFan1994$>
  • Loading branch information
Wolfieheart authored and xMakeItRain94@gmail.com committed Jun 18, 2022
1 parent 63bed8a commit aeb231c
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 12 deletions.
31 changes: 21 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<!-- Towny -->
<!-- Towny + GriefDefender-->
<repository>
<id>glaremasters repo</id>
<url>https://repo.glaremasters.me/repository/towny/</url>
</repository>
<repository>
<id>glaremasters</id>
<url>https://repo.glaremasters.me/repository/bloodshot</url>
</repository>
<!--- Update Checker -->
<repository>
<id>jeff-media-public</id>
Expand Down Expand Up @@ -137,7 +141,13 @@
<version>1.10.0</version>
<scope>provided</scope>
</dependency>
<!--- CoreProtect TODO: 1.18-36/1.19? -->
<!--- GriefDefender -->
<dependency>
<groupId>com.griefdefender</groupId>
<artifactId>api</artifactId>
<version>2.1.0-20220608.043832-6</version>
<scope>provided</scope>
</dependency>
</dependencies>
<!--Java 8-->
<build>
Expand Down Expand Up @@ -167,6 +177,15 @@
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>${maven-release-plugin.version}</version>
<configuration>
<scmCommentPrefix>[ci skip] || [CI SKIP]</scmCommentPrefix>
<tagNameFormat>@{project.version}</tagNameFormat>
</configuration>
</plugin>
<plugin>

<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
Expand All @@ -177,14 +196,6 @@
</compilerArgs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>${maven-release-plugin.version}</version>
<configuration>
<scmCommentPrefix>[ci skip] || [CI SKIP]</scmCommentPrefix>
<tagNameFormat>@{project.version}</tagNameFormat>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import io.github.rypofalem.armorstandeditor.menu.ASEHolder;
import io.github.rypofalem.armorstandeditor.protections.*;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
Expand Down Expand Up @@ -60,6 +61,7 @@ public class PlayerEditorManager implements Listener {
private WorldGuardProtection worldGuardProtection;
private GriefPreventionProtection griefPreventionProtection;
private SkyblockProtection skyblockProtection;
private GriefDefenderProtection griefDefenderProtection;

PlayerEditorManager( ArmorStandEditorPlugin plugin) {
this.plugin = plugin;
Expand All @@ -77,6 +79,7 @@ public class PlayerEditorManager implements Listener {
worldGuardProtection = new WorldGuardProtection();
griefPreventionProtection = new GriefPreventionProtection();
skyblockProtection = new SkyblockProtection();
griefDefenderProtection = new GriefDefenderProtection();
}

@EventHandler(priority = EventPriority.LOWEST)
Expand Down Expand Up @@ -298,8 +301,9 @@ boolean canEdit( Player player, ArmorStand as) {
boolean protectWGActive = worldGuardProtection.checkPermission(block, player);
boolean protectGPActive = griefPreventionProtection.checkPermission(block, player);
boolean protectSkyActive = skyblockProtection.checkPermission(player);
boolean protectGDActive = griefDefenderProtection.checkPermission(block, player);

return protectTActive && protectPSActive && protectWGActive && protectGPActive && protectSkyActive;
return protectTActive && protectPSActive && protectWGActive && protectGPActive && protectSkyActive && protectGDActive;

}

Expand All @@ -314,8 +318,9 @@ boolean canEdit( Player player, ItemFrame itemf) {
boolean protectWGActive = worldGuardProtection.checkPermission(block, player);
boolean protectGPActive = griefPreventionProtection.checkPermission(block, player);
boolean protectSkyActive = skyblockProtection.checkPermission(player);
boolean protectGDActive = griefDefenderProtection.checkPermission(block, player);

return protectTActive && protectPSActive && protectWGActive && protectGPActive && protectSkyActive;
return protectTActive && protectPSActive && protectWGActive && protectGPActive && protectSkyActive && protectGDActive;
}

void applyLeftTool( Player player, ArmorStand as) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package io.github.rypofalem.armorstandeditor.protections;


import com.griefdefender.api.GriefDefender;
import com.griefdefender.api.claim.Claim;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

import static com.griefdefender.api.claim.TrustTypes.BUILDER;
import static com.griefdefender.api.claim.TrustTypes.RESIDENT;


public class GriefDefenderProtection {

private boolean gdEnabled;

public GriefDefenderProtection() {
gdEnabled = Bukkit.getPluginManager().isPluginEnabled("GriefDefender");
if (!gdEnabled) return;
}

public boolean checkPermission(Block block, Player player) {
if (!gdEnabled) return true;
if (player.isOp()) return true;
if (player.hasPermission("asedit.ignoreProtection.griefDefender")) return true;
if (player.hasPermission("griefdefender.admin.bypass.border-check")) return true;

Location blockLoc = block.getLocation();
if (GriefDefender.getCore().getClaimAt(blockLoc) != null) {
Claim landClaim = GriefDefender.getCore().getClaimAt(blockLoc);

if (landClaim == null || landClaim.isWilderness() || landClaim.isAdminClaim()) {
return true;
} else if (landClaim.isBasicClaim() &&
!landClaim.isUserTrusted(player.getUniqueId(), RESIDENT) &&
!landClaim.allowEdit(player.getUniqueId()) ||
landClaim.isBasicClaim() &&
!landClaim.isUserTrusted(player.getUniqueId(), BUILDER) &&
!landClaim.allowEdit(player.getUniqueId())) {
return false;
} else {
return true;
}
} else {
return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public PlotSquaredProtection(){

public boolean checkPermission(Block block, Player player){
if(!psEnabled) return true;
if(player.isOp()) return true;
if(player.hasPermission("asedit.ignoreProtection.plotSquared")) return true;

Location location = Location.at(block.getWorld().getName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public WorldGuardProtection(){

public boolean checkPermission(Block block, Player player){
if (!wgEnabled) return true;
if(player.isOp()) return true;
if (player.hasPermission("asedit.ignoreProtection.worldGuard")) return true;

LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
Expand Down

0 comments on commit aeb231c

Please sign in to comment.