mirror of
https://github.com/YouHaveTrouble/YardWatch.git
synced 2026-05-11 22:16:58 +00:00
Add plotsquared protection (#6)
* getState() is already true * add plotsquared protection * check if isProtected first * check if owned plot is not null * move isProtected up one * remove comments
This commit is contained in:
@@ -96,6 +96,18 @@
|
|||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.intellectualsites.bom</groupId>
|
||||||
|
<artifactId>bom-newest</artifactId>
|
||||||
|
<version>1.48</version>
|
||||||
|
<scope>import</scope>
|
||||||
|
<type>pom</type>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.destroystokyo.paper</groupId>
|
<groupId>com.destroystokyo.paper</groupId>
|
||||||
@@ -151,5 +163,11 @@
|
|||||||
<version>0.100.1.0</version>
|
<version>0.100.1.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.intellectualsites.plotsquared</groupId>
|
||||||
|
<artifactId>plotsquared-core</artifactId>
|
||||||
|
<version>7.3.8</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import me.youhavetrouble.yardwatch.commands.YardWatchCommand;
|
|||||||
import me.youhavetrouble.yardwatch.hooks.FactionsUUIDProtection;
|
import me.youhavetrouble.yardwatch.hooks.FactionsUUIDProtection;
|
||||||
import me.youhavetrouble.yardwatch.hooks.GriefPreventionProtection;
|
import me.youhavetrouble.yardwatch.hooks.GriefPreventionProtection;
|
||||||
import me.youhavetrouble.yardwatch.hooks.LWCXProtection;
|
import me.youhavetrouble.yardwatch.hooks.LWCXProtection;
|
||||||
|
import me.youhavetrouble.yardwatch.hooks.PlotSquaredProtection;
|
||||||
import me.youhavetrouble.yardwatch.hooks.SuperiorSkyBlockProtection;
|
import me.youhavetrouble.yardwatch.hooks.SuperiorSkyBlockProtection;
|
||||||
import me.youhavetrouble.yardwatch.hooks.TownyProtection;
|
import me.youhavetrouble.yardwatch.hooks.TownyProtection;
|
||||||
import me.youhavetrouble.yardwatch.hooks.WorldGuardProtection;
|
import me.youhavetrouble.yardwatch.hooks.WorldGuardProtection;
|
||||||
@@ -83,6 +84,13 @@ public final class YardWatch extends JavaPlugin {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (shouldRegisterService("PlotSquared")) {
|
||||||
|
getLogger().info("Registering PlotSquared service.");
|
||||||
|
getServer().getServicesManager().register(
|
||||||
|
Protection.class, new PlotSquaredProtection(this), this, ServicePriority.Normal
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
List<RegisteredServiceProvider<?>> registrations = getServer().getServicesManager().getRegistrations(this);
|
List<RegisteredServiceProvider<?>> registrations = getServer().getServicesManager().getRegistrations(this);
|
||||||
if (registrations.isEmpty()) {
|
if (registrations.isEmpty()) {
|
||||||
getLogger().info("Registered 0 services. This plugin can be safely removed.");
|
getLogger().info("Registered 0 services. This plugin can be safely removed.");
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
package me.youhavetrouble.yardwatch.hooks;
|
||||||
|
|
||||||
|
import com.plotsquared.core.plot.Plot;
|
||||||
|
import com.plotsquared.core.plot.flag.implementations.PvpFlag;
|
||||||
|
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 org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
|
public class PlotSquaredProtection implements Protection {
|
||||||
|
|
||||||
|
private final YardWatch plugin;
|
||||||
|
|
||||||
|
public PlotSquaredProtection(YardWatch plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return this.plugin.getServer().getPluginManager().isPluginEnabled("PlotSquared");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isProtected(final Location location) {
|
||||||
|
if (!isEnabled()) return false;
|
||||||
|
|
||||||
|
final com.plotsquared.core.location.Location arg1 = getLocation(location);
|
||||||
|
|
||||||
|
return arg1.isPlotArea() || arg1.isPlotRoad() || arg1.isUnownedPlotArea() || arg1.getOwnedPlot() != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canBreakBlock(final Player player, final BlockState blockState) {
|
||||||
|
if (!isEnabled()) return true;
|
||||||
|
|
||||||
|
final Location blockLocation = blockState.getLocation();
|
||||||
|
final com.plotsquared.core.location.@NonNull Location location = getLocation(blockLocation);
|
||||||
|
|
||||||
|
final Plot plot = location.getOwnedPlot();
|
||||||
|
|
||||||
|
if (plot == null) return isProtected(blockLocation);
|
||||||
|
|
||||||
|
return plot.isAdded(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canPlaceBlock(final Player player, final Location location) {
|
||||||
|
return canBreakBlock(player, location.getBlock().getState());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canInteract(final Player player, final BlockState blockState) {
|
||||||
|
if (!isEnabled()) return true;
|
||||||
|
|
||||||
|
final Location location = blockState.getLocation();
|
||||||
|
|
||||||
|
com.plotsquared.core.location.@NonNull Location plotLocation = getLocation(location);
|
||||||
|
|
||||||
|
final Plot plot = plotLocation.getOwnedPlot();
|
||||||
|
|
||||||
|
if (plot == null) return isProtected(location);
|
||||||
|
|
||||||
|
return plot.isAdded(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canInteract(final Player player, final Entity target) {
|
||||||
|
return canInteract(player, target.getLocation().getBlock().getState());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canDamage(final Entity damager, final Entity target) {
|
||||||
|
if (!isEnabled() || !(damager instanceof Player)) return true;
|
||||||
|
|
||||||
|
final Location location = target.getLocation();
|
||||||
|
|
||||||
|
com.plotsquared.core.location.@NonNull Location plotLocation = getLocation(location);
|
||||||
|
|
||||||
|
final Plot plot = plotLocation.getOwnedPlot();
|
||||||
|
|
||||||
|
if (plot == null) return isProtected(location);
|
||||||
|
|
||||||
|
return plot.getFlag(PvpFlag.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private com.plotsquared.core.location.@NonNull Location getLocation(final Location location) {
|
||||||
|
final String world = location.getWorld().getName();
|
||||||
|
final int x = (int) location.getX();
|
||||||
|
final int y = (int) location.getY();
|
||||||
|
final int z = (int) location.getZ();
|
||||||
|
|
||||||
|
return com.plotsquared.core.location.Location.at(world, x, y, z);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,6 @@ package me.youhavetrouble.yardwatch.hooks;
|
|||||||
import com.palmergames.bukkit.towny.TownyAPI;
|
import com.palmergames.bukkit.towny.TownyAPI;
|
||||||
import com.palmergames.bukkit.towny.object.Resident;
|
import com.palmergames.bukkit.towny.object.Resident;
|
||||||
import com.palmergames.bukkit.towny.object.TownBlock;
|
import com.palmergames.bukkit.towny.object.TownBlock;
|
||||||
import com.palmergames.bukkit.towny.object.TownyPermission;
|
|
||||||
import com.palmergames.bukkit.towny.utils.CombatUtil;
|
import com.palmergames.bukkit.towny.utils.CombatUtil;
|
||||||
import me.youhavetrouble.yardwatch.Protection;
|
import me.youhavetrouble.yardwatch.Protection;
|
||||||
import me.youhavetrouble.yardwatch.YardWatch;
|
import me.youhavetrouble.yardwatch.YardWatch;
|
||||||
@@ -45,7 +44,7 @@ public class TownyProtection implements Protection {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canPlaceBlock(Player player, Location location) {
|
public boolean canPlaceBlock(Player player, Location location) {
|
||||||
return canInteract(player, location.getBlock().getState(true));
|
return canInteract(player, location.getBlock().getState());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -63,7 +62,7 @@ public class TownyProtection implements Protection {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInteract(Player player, Entity target) {
|
public boolean canInteract(Player player, Entity target) {
|
||||||
return canInteract(player, target.getLocation().getBlock().getState(true));
|
return canInteract(player, target.getLocation().getBlock().getState());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user