9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-19 15:09:24 +00:00

Worldguard support

This commit is contained in:
XiaoMoMi
2024-07-29 19:24:51 +08:00
parent 0b698a0e15
commit 8c68e9257d
6 changed files with 129 additions and 4 deletions

View File

@@ -32,4 +32,8 @@ public interface Action<T> {
* @param context the context
*/
void trigger(Context<T> context);
static Action<?> empty() {
return EmptyAction.INSTANCE;
}
}

View File

@@ -34,4 +34,8 @@ public interface Requirement<T> {
* @return true if the requirement is met, false otherwise
*/
boolean isSatisfied(Context<T> context);
static Requirement<?> empty() {
return EmptyRequirement.INSTANCE;
}
}

View File

@@ -1,5 +1,6 @@
repositories {
maven("https://jitpack.io/") // itemsadder
maven("https://maven.enginehub.org/repo/") // worldguard worldedit
maven("https://jitpack.io/") // itemsadder customcrops
maven("https://mvn.lumine.io/repository/maven-public/") // mythicmobs
maven("https://nexus.phoenixdevt.fr/repository/maven-public/") // mmoitems
maven("https://papermc.io/repo/repository/maven-public/")
@@ -9,12 +10,12 @@ repositories {
maven("https://repo.auxilor.io/repository/maven-public/") // eco
maven("https://nexus.betonquest.org/repository/betonquest/") // betonquest
maven("https://repo.dmulloy2.net/repository/public/") // betonquest needs packet wrapper?
maven("https://maven.enginehub.org/repo/") // worldguard
}
dependencies {
compileOnly(project(":common"))
compileOnly(project(":api"))
compileOnly("dev.dejvokep:boosted-yaml:${rootProject.properties["boosted_yaml_version"]}")
compileOnly("net.kyori:adventure-api:${rootProject.properties["adventure_bundle_version"]}") {
exclude(module = "adventure-bom")
exclude(module = "checker-qual")
@@ -58,6 +59,8 @@ dependencies {
compileOnly("com.willfp:EcoJobs:3.56.1")
compileOnly("com.willfp:EcoSkills:3.46.1")
compileOnly("com.willfp:libreforge:4.58.1")
// wg we
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.9")
}
java {

View File

@@ -0,0 +1,97 @@
/*
* Copyright (C) <2024> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.bukkit.integration.region;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
import net.momirealms.customfishing.api.mechanic.action.ActionManager;
import net.momirealms.customfishing.api.mechanic.context.ContextKeys;
import net.momirealms.customfishing.api.mechanic.requirement.EmptyRequirement;
import org.bukkit.Location;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
public class WorldGuardRegion {
public static void register() {
BukkitCustomFishingPlugin.getInstance().getRequirementManager().registerRequirement("region", (args, notSatisfiedActions, runActions) -> {
HashSet<String> regions = new HashSet<>();
boolean other;
int mode = 1;
if (args instanceof Section section) {
other = section.getString("position", "other").equalsIgnoreCase("other");
mode = section.getInt("mode", 1);
regions.addAll(section.getStringList("values"));
} else {
other = true;
if (args instanceof List<?> list) {
for (Object o : list) {
if (o instanceof String) {
regions.add((String) o);
}
}
} else {
BukkitCustomFishingPlugin.getInstance().getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at region requirement which is expected be `Section` or `StringList`");
return EmptyRequirement.INSTANCE;
}
}
int finalMode = mode;
return context -> {
Location location;
if (other) {
location = Optional.ofNullable(context.arg(ContextKeys.OTHER_LOCATION)).orElse(context.getHolder().getLocation());
} else {
location = context.getHolder().getLocation();
}
RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(location.getWorld()));
if (regionManager != null) {
ApplicableRegionSet set = regionManager.getApplicableRegions(BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
if (finalMode == 1) {
for (ProtectedRegion region : set) {
if (regions.contains(region.getId())) {
return true;
}
}
} else if (finalMode == 2) {
outer: {
Set<String> ids = set.getRegions().stream().map(ProtectedRegion::getId).collect(Collectors.toSet());
for (String region : regions) {
if (!ids.contains(region)) {
break outer;
}
}
return true;
}
}
}
if (runActions) ActionManager.trigger(context, notSatisfiedActions);
return false;
};
});
}
}

View File

@@ -35,6 +35,7 @@ import net.momirealms.customfishing.bukkit.integration.papi.StatisticsPapi;
import net.momirealms.customfishing.bukkit.integration.quest.BattlePassQuest;
import net.momirealms.customfishing.bukkit.integration.quest.BetonQuestQuest;
import net.momirealms.customfishing.bukkit.integration.quest.ClueScrollsQuest;
import net.momirealms.customfishing.bukkit.integration.region.WorldGuardRegion;
import net.momirealms.customfishing.bukkit.integration.season.AdvancedSeasonsProvider;
import net.momirealms.customfishing.bukkit.integration.season.CustomCropsSeasonProvider;
import net.momirealms.customfishing.bukkit.integration.season.RealisticSeasonsProvider;
@@ -42,6 +43,7 @@ import net.momirealms.customfishing.bukkit.item.BukkitItemManager;
import net.momirealms.customfishing.common.util.Pair;
import org.bukkit.Bukkit;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -78,7 +80,7 @@ public class BukkitIntegrationManager implements IntegrationManager {
if (isHooked("MMOItems")) {
registerItemProvider(new MMOItemsItemProvider());
}
if (isHooked("Oraxen")) {
if (isHooked("Oraxen", "1")) {
registerItemProvider(new OraxenItemProvider());
registerBlockProvider(new OraxenBlockProvider());
}
@@ -139,9 +141,12 @@ public class BukkitIntegrationManager implements IntegrationManager {
ClueScrollsQuest clueScrollsQuest = new ClueScrollsQuest();
clueScrollsQuest.register();
}
if (isHooked("BetonQuest")) {
if (isHooked("BetonQuest", "2")) {
BetonQuestQuest.register();
}
if (isHooked("WorldGuard", "7")) {
WorldGuardRegion.register();
}
if (isHooked("PlaceholderAPI")) {
new CustomFishingPapi(plugin).load();
new CompetitionPapi(plugin).load();
@@ -157,6 +162,17 @@ public class BukkitIntegrationManager implements IntegrationManager {
return false;
}
private boolean isHooked(String hooked, String versionPrefix) {
Plugin p = Bukkit.getPluginManager().getPlugin(hooked);
if (p != null) {
if (p.getDescription().getVersion().startsWith(versionPrefix)) {
plugin.getPluginLogger().info(hooked + " hooked!");
return true;
}
}
return false;
}
@Override
public boolean registerLevelerProvider(@NotNull LevelerProvider leveler) {
if (levelerProviders.containsKey(leveler.identifier())) return false;

View File

@@ -24,6 +24,7 @@ softdepend:
- AdvancedEnchantments
- EcoJobs
- Zaphkiel
- WorldGuard
permissions:
fishingbag.user:
default: true