Skip to content

Commit 80ba992

Browse files
Merge pull request #443 from abola2/main
Griefprevention support (again 1.20)
2 parents d026f3b + b72338b commit 80ba992

File tree

5 files changed

+91
-2
lines changed

5 files changed

+91
-2
lines changed

src/main/java/com/volmit/adapt/Adapt.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ public void start() {
125125
if (getServer().getPluginManager().getPlugin("Factions") != null) {
126126
protectorRegistry.registerProtector(new FactionsClaimProtector());
127127
}
128-
129128
if (getServer().getPluginManager().getPlugin("ChestProtect") != null) {
130129
protectorRegistry.registerProtector(new ChestProtectProtector());
131130
}
@@ -135,6 +134,9 @@ public void start() {
135134
if (getServer().getPluginManager().getPlugin("GriefDefender") != null) {
136135
protectorRegistry.registerProtector(new GriefDefenderProtector());
137136
}
137+
if (getServer().getPluginManager().getPlugin("GriefPrevention") != null) {
138+
protectorRegistry.registerProtector(new GriefPreventionProtector());
139+
}
138140
glowingEntities = new GlowingEntities(this);
139141
parser.parse(new CommandAdapt());
140142
}

src/main/java/com/volmit/adapt/AdaptConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public static class Protector {
114114
private boolean factionsClaim = false;
115115
private boolean residence = true;
116116
private boolean chestProtect = true;
117+
private boolean griefprevention = true;
117118
}
118119

119120

src/main/java/com/volmit/adapt/api/protection/Protector.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import org.bukkit.Location;
2323
import org.bukkit.entity.Player;
2424

25+
import java.util.UUID;
26+
2527
public interface Protector {
2628

2729
default boolean canBlockBreak(Player player, Location blockLocation, Adaptation<?> adaptation) {
@@ -52,6 +54,7 @@ default boolean checkRegion(Player player, Location location, Adaptation<?> adap
5254
return true;
5355
}
5456

57+
5558
String getName();
5659

5760
boolean isEnabledByDefault();

src/main/java/com/volmit/adapt/content/protector/FactionsClaimProtector.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package com.volmit.adapt.content.protector;
2020

2121
import com.massivecraft.factions.*;
22-
import com.volmit.adapt.Adapt;
2322
import com.volmit.adapt.AdaptConfig;
2423
import com.volmit.adapt.api.adaptation.Adaptation;
2524
import com.volmit.adapt.api.protection.Protector;
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*------------------------------------------------------------------------------
2+
- Adapt is a Skill/Integration plugin for Minecraft Bukkit Servers
3+
- Copyright (c) 2022 Arcane Arts (Volmit Software)
4+
-
5+
- This program is free software: you can redistribute it and/or modify
6+
- it under the terms of the GNU General Public License as published by
7+
- the Free Software Foundation, either version 3 of the License, or
8+
- (at your option) any later version.
9+
-
10+
- This program is distributed in the hope that it will be useful,
11+
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
- GNU General Public License for more details.
14+
-
15+
- You should have received a copy of the GNU General Public License
16+
- along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
-----------------------------------------------------------------------------*/
18+
19+
package com.volmit.adapt.content.protector;
20+
21+
import com.volmit.adapt.AdaptConfig;
22+
import com.volmit.adapt.api.adaptation.Adaptation;
23+
import com.volmit.adapt.api.protection.Protector;
24+
import me.ryanhamshire.GriefPrevention.Claim;
25+
import me.ryanhamshire.GriefPrevention.ClaimPermission;
26+
import me.ryanhamshire.GriefPrevention.GriefPrevention;
27+
import me.ryanhamshire.GriefPrevention.PlayerData;
28+
import org.bukkit.Location;
29+
import org.bukkit.entity.Player;
30+
31+
import java.util.Objects;
32+
33+
public class GriefPreventionProtector implements Protector {
34+
35+
36+
@Override
37+
public boolean canBlockBreak(Player player, Location location, Adaptation<?> adaptation) {
38+
return canEditClaim(player, location);
39+
}
40+
41+
@Override
42+
public boolean canBlockPlace(Player player, Location location, Adaptation<?> adaptation) {
43+
return canEditClaim(player, location);
44+
}
45+
46+
@Override
47+
public String getName() {
48+
return "GriefPrevention";
49+
}
50+
51+
@Override
52+
public boolean isEnabledByDefault() {
53+
return AdaptConfig.get().getProtectorSupport().isGriefprevention();
54+
}
55+
56+
@Override
57+
public void unregister() {
58+
Protector.super.unregister();
59+
}
60+
61+
62+
63+
private boolean canEditClaim(Player player, Location location) {
64+
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(location, true, null);
65+
PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId());
66+
67+
if (claim == null) {
68+
return true;
69+
}
70+
//If doesn't check is adminclaim getting ownerid return null
71+
if (!claim.isAdminClaim() && Objects.equals(claim.getOwnerID(), player.getUniqueId())) {
72+
return true;
73+
}
74+
else if (claim.getPermission(player.getUniqueId().toString()) == ClaimPermission.Build) {
75+
return true;
76+
}
77+
78+
return playerData.ignoreClaims || claim.isAdminClaim() && player.hasPermission("griefprevention.adminclaims");
79+
80+
}
81+
82+
83+
}
84+

0 commit comments

Comments
 (0)