mirror of
https://github.com/YouHaveTrouble/YardWatch.git
synced 2026-05-11 22:16:58 +00:00
Add support for GriefPrevention Protection
Refactored the YardWatch.java file to check if the GriefPrevention plugin is enabled. If enabled, GriefPrevention Protection is registered. Additionally, a new class GriefPreventionProtection.java was added which checks if a location is protected, if a player can break/place a block, interact with a block or entity, or damage an entity based on GriefPrevention's claims. Moreover, added a new dependency for GriefPrevention in pom.xml.
This commit is contained in:
@@ -95,6 +95,11 @@
|
||||
<version>2.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.GriefPrevention</groupId>
|
||||
<artifactId>GriefPrevention</artifactId>
|
||||
<version>16.18.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package me.youhavetrouble.yardwatch;
|
||||
|
||||
import me.youhavetrouble.yardwatch.hooks.GriefPreventionProtection;
|
||||
import me.youhavetrouble.yardwatch.hooks.WorldGuardProtection;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@@ -8,13 +10,19 @@ public final class YardWatch extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
PluginManager pluginManager = getServer().getPluginManager();
|
||||
|
||||
if (getServer().getPluginManager().isPluginEnabled("WorldGuard")) {
|
||||
getServer().getServicesManager().register(
|
||||
Protection.class, new WorldGuardProtection(this), this, ServicePriority.Normal
|
||||
);
|
||||
}
|
||||
if (pluginManager.isPluginEnabled("WorldGuard")) {
|
||||
getServer().getServicesManager().register(
|
||||
Protection.class, new WorldGuardProtection(this), this, ServicePriority.Normal
|
||||
);
|
||||
}
|
||||
|
||||
if (pluginManager.isPluginEnabled("GriefPrevention")) {
|
||||
getServer().getServicesManager().register(
|
||||
Protection.class, new GriefPreventionProtection(this), this, ServicePriority.Normal
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package me.youhavetrouble.yardwatch.hooks;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.Claim;
|
||||
import me.ryanhamshire.GriefPrevention.ClaimPermission;
|
||||
import me.ryanhamshire.GriefPrevention.GriefPrevention;
|
||||
import me.youhavetrouble.yardwatch.Protection;
|
||||
import me.youhavetrouble.yardwatch.YardWatch;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class GriefPreventionProtection implements Protection {
|
||||
|
||||
private final YardWatch plugin;
|
||||
|
||||
public GriefPreventionProtection(YardWatch plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return plugin.getServer().getPluginManager().isPluginEnabled("GriefPrevention");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProtected(Location location) {
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(location, true, null);
|
||||
if (claim == null) return false;
|
||||
return claim.checkPermission(UUID.fromString("00000000-0000-0000-0000-000000000000"), ClaimPermission.Build, null) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreakBlock(Player player, BlockState blockState) {
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(blockState.getLocation(), true, null);
|
||||
return claim == null || claim.hasExplicitPermission(player.getUniqueId(), ClaimPermission.Build) || claim.hasExplicitPermission(player.getUniqueId(), ClaimPermission.Edit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceBlock(Player player, Location location) {
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(location, true, null);
|
||||
return claim == null || claim.hasExplicitPermission(player.getUniqueId(), ClaimPermission.Build) || claim.hasExplicitPermission(player.getUniqueId(), ClaimPermission.Edit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteract(Player player, BlockState blockState) {
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(blockState.getLocation(), true, null);
|
||||
return claim == null || claim.hasExplicitPermission(player.getUniqueId(), ClaimPermission.Access);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteract(Player player, Entity target) {
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(target.getLocation(), true, null);
|
||||
return claim == null || claim.hasExplicitPermission(player.getUniqueId(), ClaimPermission.Access);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDamage(Entity damager, Entity target) {
|
||||
if (!(damager instanceof Player player)) return true;
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(target.getLocation(), true, null);
|
||||
return claim == null || claim.hasExplicitPermission(player.getUniqueId(), ClaimPermission.Access);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user