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:
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user