From 7f9d40aafea66a7941dad67788196ad31e01c6bb Mon Sep 17 00:00:00 2001 From: YouHaveTrouble Date: Fri, 22 Mar 2024 15:05:28 +0100 Subject: [PATCH] Add FactionsUUID support to YardWatch Plugin The YardWatch Plugin now supports FactionsUUID. The plugin's functionality has been implemented and added to the list of dependencies in the pom.xml file. Also, FactionsUUID has been included in the soft dependencies category in the plugin.yml file and in the options for bug reports. --- .github/ISSUE_TEMPLATE/bug_report.yml | 1 + pom.xml | 10 +++ readme.md | 1 + .../youhavetrouble/yardwatch/YardWatch.java | 7 ++ .../hooks/FactionsUUIDProtection.java | 80 +++++++++++++++++++ src/main/resources/plugin.yml | 9 ++- 6 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 src/main/java/me/youhavetrouble/yardwatch/hooks/FactionsUUIDProtection.java diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 98212ae..50bed57 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -9,6 +9,7 @@ body: label: "Plugin name" multiple: false options: + - "FactionsUUID" - "GriefPrevention" - "WorldGuard" - "LWCX" diff --git a/pom.xml b/pom.xml index fe8e781..451102d 100644 --- a/pom.xml +++ b/pom.xml @@ -72,6 +72,10 @@ codemc-repo https://repo.codemc.io/repository/maven-public/ + + ender-zone + https://ci.ender.zone/plugin/repository/everything/ + @@ -111,5 +115,11 @@ 2.2.9-dev provided + + com.massivecraft + Factions + 1.6.9.5-U0.6.33 + provided + diff --git a/readme.md b/readme.md index cb46d4b..6bcae85 100644 --- a/readme.md +++ b/readme.md @@ -15,6 +15,7 @@ If you're a developer looking for information how to implement YardWatchAPI in y - GriefPrevention (v16+) - WorldGuard (7.0.0+) - LWCX +- FactionsUUID ## Plugin you're using is not implementing YardWatchAPI? Contact the plugin developer and send them [here](https://github.com/YouHaveTrouble/YardWatchAPI/blob/master/readme.md)! diff --git a/src/main/java/me/youhavetrouble/yardwatch/YardWatch.java b/src/main/java/me/youhavetrouble/yardwatch/YardWatch.java index 16cb89e..c76b258 100644 --- a/src/main/java/me/youhavetrouble/yardwatch/YardWatch.java +++ b/src/main/java/me/youhavetrouble/yardwatch/YardWatch.java @@ -1,5 +1,6 @@ package me.youhavetrouble.yardwatch; +import me.youhavetrouble.yardwatch.hooks.FactionsUUIDProtection; import me.youhavetrouble.yardwatch.hooks.GriefPreventionProtection; import me.youhavetrouble.yardwatch.hooks.LWCXProtection; import me.youhavetrouble.yardwatch.hooks.WorldGuardProtection; @@ -33,6 +34,12 @@ public final class YardWatch extends JavaPlugin { ); } + if (shouldRegisterService("Factions")) { + getServer().getServicesManager().register( + Protection.class, new FactionsUUIDProtection(this), this, ServicePriority.Normal + ); + } + } /** diff --git a/src/main/java/me/youhavetrouble/yardwatch/hooks/FactionsUUIDProtection.java b/src/main/java/me/youhavetrouble/yardwatch/hooks/FactionsUUIDProtection.java new file mode 100644 index 0000000..31e84a6 --- /dev/null +++ b/src/main/java/me/youhavetrouble/yardwatch/hooks/FactionsUUIDProtection.java @@ -0,0 +1,80 @@ +package me.youhavetrouble.yardwatch.hooks; + +import com.massivecraft.factions.Board; +import com.massivecraft.factions.FLocation; +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.FactionsPlugin; + +import com.massivecraft.factions.listeners.FactionsBlockListener; +import com.massivecraft.factions.listeners.FactionsEntityListener; +import com.massivecraft.factions.listeners.FactionsPlayerListener; +import com.massivecraft.factions.perms.PermissibleActions; +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; + +public class FactionsUUIDProtection implements Protection { + + private final YardWatch plugin; + + public FactionsUUIDProtection(YardWatch plugin) { + this.plugin = plugin; + } + + @Override + public boolean isEnabled() { + return plugin.getServer().getPluginManager().isPluginEnabled("Factions"); + } + + @Override + public boolean isProtected(Location location) { + if (!isEnabled()) return false; + if (!FactionsPlugin.getInstance().worldUtil().isEnabled(location.getWorld())) return false; + FLocation fLocation = new FLocation(location); + Faction faction = Board.getInstance().getFactionAt(fLocation); + return faction != null; + } + + @Override + public boolean canBreakBlock(Player player, BlockState blockState) { + if (!isEnabled()) return true; + return FactionsBlockListener.playerCanBuildDestroyBlock( + player, + blockState.getLocation(), + PermissibleActions.DESTROY, + true + ); + } + + @Override + public boolean canPlaceBlock(Player player, Location location) { + if (!isEnabled()) return true; + return FactionsBlockListener.playerCanBuildDestroyBlock( + player, + location, + PermissibleActions.BUILD, + true + ); + } + + @Override + public boolean canInteract(Player player, BlockState blockState) { + if (!isEnabled()) return true; + return FactionsPlayerListener.canInteractHere(player, blockState.getLocation()); + } + + @Override + public boolean canInteract(Player player, Entity target) { + if (!isEnabled()) return true; + return FactionsEntityListener.canInteractHere(player, target.getLocation()); + } + + @Override + public boolean canDamage(Entity damager, Entity target) { + if (!isEnabled()) return true; + return FactionsEntityListener.canDamage(damager, target, false); + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 801d50c..cff1352 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,11 +3,12 @@ version: '${project.version}' main: me.youhavetrouble.yardwatch.YardWatch api-version: '1.16' folia-supported: true -softdepend: - - "WorldGuard" - - "GriefPrevention" - - "Towny" authors: - "YouHaveTrouble" description: '${project.description}' website: '${project.url}' +softdepend: + - "WorldGuard" + - "GriefPrevention" + - "Towny" + - "Factions"