From a5498de65c9e0277841703e23a48d34005922de9 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Sun, 26 Jan 2025 10:03:10 +0800 Subject: [PATCH 1/2] add [Dominion](https://github.com/ColdeZhang/Dominion) Protection module. --- dough-api/pom.xml | 8 ++ dough-protection/pom.xml | 14 +++ .../dough/protection/ProtectionManager.java | 20 +--- .../modules/DominionProtectionModule.java | 96 +++++++++++++++++++ 4 files changed, 120 insertions(+), 18 deletions(-) create mode 100644 dough-protection/src/main/java/io/github/bakedlibs/dough/protection/modules/DominionProtectionModule.java diff --git a/dough-api/pom.xml b/dough-api/pom.xml index 4bb28d00..d8b160ae 100644 --- a/dough-api/pom.xml +++ b/dough-api/pom.xml @@ -443,6 +443,14 @@ 1.0.580 provided + + + + cn.lunadeer + DominionAPI + 3.5 + provided + diff --git a/dough-protection/pom.xml b/dough-protection/pom.xml index d12c8315..41ce84d6 100644 --- a/dough-protection/pom.xml +++ b/dough-protection/pom.xml @@ -439,6 +439,20 @@ + + + + cn.lunadeer + DominionAPI + 3.5 + provided + + + bukkit + * + + + diff --git a/dough-protection/src/main/java/io/github/bakedlibs/dough/protection/ProtectionManager.java b/dough-protection/src/main/java/io/github/bakedlibs/dough/protection/ProtectionManager.java index bebd5b33..881887b5 100644 --- a/dough-protection/src/main/java/io/github/bakedlibs/dough/protection/ProtectionManager.java +++ b/dough-protection/src/main/java/io/github/bakedlibs/dough/protection/ProtectionManager.java @@ -9,6 +9,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; +import io.github.bakedlibs.dough.protection.modules.*; import org.bukkit.Location; import org.bukkit.OfflinePlayer; import org.bukkit.block.Block; @@ -18,24 +19,6 @@ import io.github.bakedlibs.dough.common.DoughLogger; import io.github.bakedlibs.dough.protection.loggers.CoreProtectLogger; import io.github.bakedlibs.dough.protection.loggers.LogBlockLogger; -import io.github.bakedlibs.dough.protection.modules.BentoBoxProtectionModule; -import io.github.bakedlibs.dough.protection.modules.BlockLockerProtectionModule; -import io.github.bakedlibs.dough.protection.modules.BoltProtectionModule; -import io.github.bakedlibs.dough.protection.modules.ChestProtectProtectionModule; -import io.github.bakedlibs.dough.protection.modules.FactionsUUIDProtectionModule; -import io.github.bakedlibs.dough.protection.modules.FunnyGuildsProtectionModule; -import io.github.bakedlibs.dough.protection.modules.GriefPreventionProtectionModule; -import io.github.bakedlibs.dough.protection.modules.HuskTownsProtectionModule; -import io.github.bakedlibs.dough.protection.modules.HuskClaimsProtectionModule; -import io.github.bakedlibs.dough.protection.modules.LWCProtectionModule; -import io.github.bakedlibs.dough.protection.modules.LandsProtectionModule; -import io.github.bakedlibs.dough.protection.modules.LocketteProtectionModule; -import io.github.bakedlibs.dough.protection.modules.PlotSquaredProtectionModule; -import io.github.bakedlibs.dough.protection.modules.PreciousStonesProtectionModule; -import io.github.bakedlibs.dough.protection.modules.RedProtectProtectionModule; -import io.github.bakedlibs.dough.protection.modules.ShopChestProtectionModule; -import io.github.bakedlibs.dough.protection.modules.TownyProtectionModule; -import io.github.bakedlibs.dough.protection.modules.WorldGuardProtectionModule; /** * This Class provides a nifty API for plugins to query popular protection plugins. @@ -97,6 +80,7 @@ private void loadModuleImplementations(Plugin plugin) { registerModule(pm, "ShopChest", shopChest -> new ShopChestProtectionModule(shopChest)); registerModule(pm, "HuskClaims", huskClaims -> new HuskClaimsProtectionModule(huskClaims)); registerModule(pm, "Bolt", bolt -> new BoltProtectionModule(bolt)); + registerModule(pm, "Dominion", dominion -> new DominionProtectionModule(dominion)); /* * The following Plugins work by utilising one of the above listed diff --git a/dough-protection/src/main/java/io/github/bakedlibs/dough/protection/modules/DominionProtectionModule.java b/dough-protection/src/main/java/io/github/bakedlibs/dough/protection/modules/DominionProtectionModule.java new file mode 100644 index 00000000..da43ebfb --- /dev/null +++ b/dough-protection/src/main/java/io/github/bakedlibs/dough/protection/modules/DominionProtectionModule.java @@ -0,0 +1,96 @@ +package io.github.bakedlibs.dough.protection.modules; + +import cn.lunadeer.dominion.api.DominionAPI; +import cn.lunadeer.dominion.api.dtos.DominionDTO; +import cn.lunadeer.dominion.api.dtos.flag.EnvFlag; +import cn.lunadeer.dominion.api.dtos.flag.Flag; +import cn.lunadeer.dominion.api.dtos.flag.Flags; +import cn.lunadeer.dominion.api.dtos.flag.PreFlag; +import io.github.bakedlibs.dough.protection.Interaction; +import io.github.bakedlibs.dough.protection.ProtectionModule; +import org.bukkit.Location; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.Nullable; + +import javax.annotation.Nonnull; + +public class DominionProtectionModule implements ProtectionModule { + + private final Plugin plugin; + private DominionAPI api; + + public DominionProtectionModule(Plugin plugin) { + this.plugin = plugin; + } + + /** + * Use this method to load instances of your API or other utilites you need + */ + @Override + public void load() { + try { + api = DominionAPI.getInstance(); + } catch (Exception e) { + plugin.getLogger().warning("Failed to load Dominion API. Disabling Dominion Protection Module."); + } + } + + /** + * This returns the {@link Plugin} for this {@link ProtectionModule}. + * + * @return The associated {@link Plugin} + */ + @Override + public Plugin getPlugin() { + return plugin; + } + + /** + * This method implements the functionality of this module. + * Use it to allow or deny an Action based on the rules of your Protection {@link Plugin} + * + * @param p The Player that is being queried, can be offline + * @param l The {@link Location} of the event that is happening + * @param action The {@link Interaction} that is taking place. + * @return Whether the action was allowed by your {@link Plugin} + */ + @Override + public boolean hasPermission(OfflinePlayer p, Location l, Interaction action) { + if (!p.isOnline()) { + return false; + } + Player player = p.getPlayer(); + if (player == null) { + return true; + } + Flag flag = getDominionFlagFromInteraction(action); + if (flag == null) { + return true; + } + DominionDTO dominion = api.getDominionByLoc(l); + if (flag instanceof PreFlag) { + PreFlag preFlag = (PreFlag) flag; + return api.checkPrivilegeFlag(dominion, preFlag, player); + } else { + EnvFlag envFlag = (EnvFlag) flag; + return api.checkEnvironmentFlag(dominion, envFlag); + } + } + + private @Nullable Flag getDominionFlagFromInteraction(@Nonnull Interaction action) { + switch (action) { + case BREAK_BLOCK: + return Flags.BREAK_BLOCK; + case PLACE_BLOCK: + return Flags.PLACE; + case INTERACT_BLOCK: + return Flags.CONTAINER; + case ATTACK_PLAYER: + return Flags.PLAYER_DAMAGE; + default: + return null; + } + } +} From fc8e609dd5b32b0fdcb372fcc47765b913b692ba Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Tue, 18 Mar 2025 10:01:06 +0800 Subject: [PATCH 2/2] update dominion api version --- dough-api/pom.xml | 2 +- dough-protection/pom.xml | 2 +- .../protection/modules/DominionProtectionModule.java | 11 +++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/dough-api/pom.xml b/dough-api/pom.xml index d8b160ae..e56160ab 100644 --- a/dough-api/pom.xml +++ b/dough-api/pom.xml @@ -448,7 +448,7 @@ cn.lunadeer DominionAPI - 3.5 + 4.2 provided diff --git a/dough-protection/pom.xml b/dough-protection/pom.xml index 41ce84d6..992f8948 100644 --- a/dough-protection/pom.xml +++ b/dough-protection/pom.xml @@ -444,7 +444,7 @@ cn.lunadeer DominionAPI - 3.5 + 4.2 provided diff --git a/dough-protection/src/main/java/io/github/bakedlibs/dough/protection/modules/DominionProtectionModule.java b/dough-protection/src/main/java/io/github/bakedlibs/dough/protection/modules/DominionProtectionModule.java index da43ebfb..0732a0f4 100644 --- a/dough-protection/src/main/java/io/github/bakedlibs/dough/protection/modules/DominionProtectionModule.java +++ b/dough-protection/src/main/java/io/github/bakedlibs/dough/protection/modules/DominionProtectionModule.java @@ -5,7 +5,7 @@ import cn.lunadeer.dominion.api.dtos.flag.EnvFlag; import cn.lunadeer.dominion.api.dtos.flag.Flag; import cn.lunadeer.dominion.api.dtos.flag.Flags; -import cn.lunadeer.dominion.api.dtos.flag.PreFlag; +import cn.lunadeer.dominion.api.dtos.flag.PriFlag; import io.github.bakedlibs.dough.protection.Interaction; import io.github.bakedlibs.dough.protection.ProtectionModule; import org.bukkit.Location; @@ -69,9 +69,12 @@ public boolean hasPermission(OfflinePlayer p, Location l, Interaction action) { if (flag == null) { return true; } - DominionDTO dominion = api.getDominionByLoc(l); - if (flag instanceof PreFlag) { - PreFlag preFlag = (PreFlag) flag; + DominionDTO dominion = api.getDominion(l); + if (dominion == null) { + return true; + } + if (flag instanceof PriFlag) { + PriFlag preFlag = (PriFlag) flag; return api.checkPrivilegeFlag(dominion, preFlag, player); } else { EnvFlag envFlag = (EnvFlag) flag;