9
0
mirror of https://gitlab.com/SamB440/rpgregions-2.git synced 2025-12-21 07:49:16 +00:00

feat: Cloud commands & Folia support

This commit is contained in:
SamB440
2023-03-31 14:45:42 +01:00
parent 48bc0f6a43
commit 7a2a06a74d
34 changed files with 936 additions and 357 deletions

View File

@@ -9,6 +9,7 @@ dependencies {
testImplementation("com.github.seeseemelk:MockBukkit-v1.17:1.13.0")
testImplementation("org.reflections:reflections:0.10.2")
compileOnly("org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT")
compileOnly("io.papermc:paperlib:1.0.4") // we include paperlib and relocate elsewhere
compileOnly("com.github.MilkBowl:VaultAPI:1.7") // vault
compileOnly("me.clip:placeholderapi:2.10.4") // PAPI

View File

@@ -2,6 +2,7 @@ package net.islandearth.rpgregions.api;
import com.convallyria.languagy.api.language.Translator;
import com.google.gson.Gson;
import net.islandearth.rpgregions.api.schedule.PlatformScheduler;
import net.islandearth.rpgregions.managers.IRPGRegionsManagers;
import org.bukkit.configuration.Configuration;
@@ -29,4 +30,10 @@ public interface IRPGRegionsAPI {
void debug(String debug);
boolean hasHeadDatabase();
/**
* Gets the scheduler used for the current platform.
* @return the scheduler for this server platform
*/
PlatformScheduler<? extends IRPGRegionsAPI> getScheduler();
}

View File

@@ -0,0 +1,30 @@
package net.islandearth.rpgregions.api.schedule;
import net.islandearth.rpgregions.api.IRPGRegionsAPI;
import org.bukkit.entity.Entity;
public abstract class PlatformScheduler<T extends IRPGRegionsAPI> {
protected final T api;
public PlatformScheduler(T api) {
this.api = api;
}
public abstract void executeOnMain(Runnable runnable);
public abstract void executeOnEntity(Entity entity, Runnable runnable);
public abstract RPGRegionsTask executeRepeating(Runnable runnable, long delay, long period);
public abstract void executeDelayed(Runnable runnable, long delay);
public abstract void executeAsync(Runnable runnable);
public abstract void registerInitTask(Runnable runnable);
@FunctionalInterface
public interface RPGRegionsTask {
void cancel();
}
}

View File

@@ -1,11 +1,8 @@
plugins {
id("com.github.johnrengelman.shadow") version("7.1.2")
id("com.github.johnrengelman.shadow") version("8.1.1")
id("java")
}
java.sourceCompatibility = JavaVersion.VERSION_16
java.targetCompatibility = JavaVersion.VERSION_16
dependencies {
testImplementation("junit:junit:4.13.2")
implementation(project(":rpgregions", "shadow"))
@@ -31,6 +28,10 @@ allprojects {
apply(plugin = "com.github.johnrengelman.shadow")
apply(plugin = "java")
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}
repositories {
mavenCentral()
mavenLocal()
@@ -66,8 +67,7 @@ allprojects {
}
dependencies {
implementation("com.convallyria.languagy:api:3.0.1")
compileOnly("org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT")
implementation("com.convallyria.languagy:api:3.0.2")
}
tasks {
@@ -99,6 +99,12 @@ allprojects {
dependsOn(shadowJar)
}
compileJava {
// Set the release flag. This configures what version bytecode the compiler will emit, as well as what JDK APIs are usable.
// See https://openjdk.java.net/jeps/247 for more information.
options.release.set(16)
}
processResources {
filesMatching("plugin.yml") {
expand("version" to project.version)

16
folia/build.gradle.kts Normal file
View File

@@ -0,0 +1,16 @@
java {
disableAutoTargetJvm()
}
repositories {
maven {
name = "papermc"
url = uri("https://repo.papermc.io/repository/maven-public/")
}
}
dependencies {
compileOnly(project(":api"))
compileOnly("dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT")
}

View File

@@ -0,0 +1,79 @@
package net.islandearth.rpgregions.folia.schedule;
import io.papermc.paper.threadedregions.RegionizedServerInitEvent;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import net.islandearth.rpgregions.api.IRPGRegionsAPI;
import net.islandearth.rpgregions.api.schedule.PlatformScheduler;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import java.util.ArrayList;
import java.util.List;
public class FoliaScheduler extends PlatformScheduler<IRPGRegionsAPI> implements Listener {
public static final boolean RUNNING_FOLIA;
static {
boolean found;
try {
Class.forName("io.papermc.paper.threadedregions.RegionizedServerInitEvent");
found = true;
} catch (final ReflectiveOperationException e) {
found = false;
}
RUNNING_FOLIA = found;
}
private List<Runnable> initTasks = new ArrayList<>();
public FoliaScheduler(IRPGRegionsAPI api) {
super(api);
Bukkit.getPluginManager().registerEvents(this, (Plugin) api);
}
@EventHandler
public void onServerInit(RegionizedServerInitEvent event) {
for (final Runnable tasks : initTasks) {
tasks.run();
}
initTasks = null;
}
@Override
public void executeOnMain(Runnable runnable) {
Bukkit.getGlobalRegionScheduler().execute((Plugin) api, runnable);
}
@Override
public void executeOnEntity(Entity entity, Runnable runnable) {
entity.getScheduler().run((Plugin) api, (s) -> runnable.run(), () -> {});
}
@Override
public RPGRegionsTask executeRepeating(Runnable runnable, long delay, long period) {
final ScheduledTask task = Bukkit.getGlobalRegionScheduler().runAtFixedRate((Plugin) api, (s) -> runnable.run(), delay, period);
return task::cancel;
}
@Override
public void executeDelayed(Runnable runnable, long delay) {
Bukkit.getGlobalRegionScheduler().runDelayed((Plugin) api, (s) -> runnable.run(), delay);
}
@Override
public void executeAsync(Runnable runnable) {
Bukkit.getAsyncScheduler().runNow((Plugin) api, (s) -> runnable.run());
}
@Override
public void registerInitTask(Runnable runnable) {
if (initTasks == null) {
throw new IllegalStateException("Server already initialised!");
}
initTasks.add(runnable);
}
}

View File

@@ -2,3 +2,6 @@ pluginGroup=net.islandearth
pluginVersion=1.4.5
# Set to false if you don't have access to the UltraRegions API jar to make the plugin compilable. The purchased plugin has support for it.
ultraRegionsSupport=true
# Dependency management
cloud_version = 1.8.3

Binary file not shown.

View File

@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

18
gradlew vendored
View File

@@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -80,10 +80,10 @@ do
esac
done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
@@ -143,12 +143,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
@@ -205,6 +209,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.

15
gradlew.bat vendored
View File

@@ -14,7 +14,7 @@
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@@ -25,7 +25,8 @@
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal

View File

@@ -12,6 +12,7 @@ dependencies {
testImplementation("junit:junit:4.13.2")
compileOnly("org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT")
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.4-SNAPSHOT") {
exclude("com.destroystokyo.paper")
exclude("org.spigotmc")

View File

@@ -4,19 +4,31 @@ repositories {
dependencies {
implementation(project(":api"))
implementation(project(":folia"))
testImplementation("junit:junit:4.13.2")
testImplementation("com.github.seeseemelk:MockBukkit-v1.17:1.13.0")
testImplementation("org.reflections:reflections:0.10.2")
implementation("cloud.commandframework:cloud-paper:${properties["cloud_version"]}") {
exclude("org.checkerframework")
}
implementation("cloud.commandframework:cloud-annotations:${properties["cloud_version"]}") {
exclude("org.checkerframework")
}
implementation("cloud.commandframework:cloud-minecraft-extras:${properties["cloud_version"]}") {
exclude("org.checkerframework")
exclude("net.kyori")
}
implementation("net.kyori:adventure-platform-bukkit:4.3.0")
implementation("org.apache.commons:commons-lang3:3.12.0")
implementation("net.wesjd:anvilgui:1.6.3-SNAPSHOT") // anvilgui
implementation("com.github.stefvanschie.inventoryframework:IF:0.10.9") // inventory framework
implementation("co.aikar:acf-paper:0.5.1-SNAPSHOT") // commands
implementation("co.aikar:idb-core:1.0.0-SNAPSHOT") // database
implementation("org.bstats:bstats-bukkit:3.0.1") // plugin stats
implementation("io.papermc:paperlib:1.0.7") // paperlib - async teleport on Paper
compileOnly("org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT")
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.4-SNAPSHOT") {
exclude("com.destroystokyo.paper")
exclude("org.spigotmc")
@@ -60,8 +72,9 @@ tasks {
}
shadowJar {
relocate("co.aikar.commands", "net.islandearth.rpgregions.libs.acf")
relocate("co.aikar.locales", "net.islandearth.rpgregions.libs.acf.locales")
relocate("net.kyori.adventure", "net.islandearth.rpgregions.libs.adventure")
relocate("cloud.commandframework", "net.islandearth.rpgregions.libs.commandframework")
relocate("io.leangen.geantyref", "net.islandearth.rpgregions.libs.typetoken")
relocate("co.aikar.idb", "net.islandearth.rpgregions.libs.idb")
relocate("com.github.stefvanschie.inventoryframework", "net.islandearth.rpgregions.libs.inventoryframework")
relocate("org.bstats", "net.islandearth.rpgregions.libs.bstats")

View File

@@ -1,27 +1,23 @@
package net.islandearth.rpgregions;
import co.aikar.commands.InvalidCommandArgument;
import co.aikar.commands.PaperCommandManager;
import co.aikar.idb.DB;
import com.convallyria.languagy.api.language.Language;
import com.convallyria.languagy.api.language.Translator;
import com.google.common.collect.ImmutableList;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.islandearth.rpgregions.api.IRPGRegionsAPI;
import net.islandearth.rpgregions.api.RPGRegionsAPI;
import net.islandearth.rpgregions.api.integrations.rpgregions.RPGRegionsIntegration;
import net.islandearth.rpgregions.api.integrations.rpgregions.region.RPGRegionsRegion;
import net.islandearth.rpgregions.commands.DiscoveriesCommand;
import net.islandearth.rpgregions.commands.RPGRegionsCommand;
import net.islandearth.rpgregions.commands.RPGRegionsDebugCommand;
import net.islandearth.rpgregions.commands.RPGRegionsExportCommand;
import net.islandearth.rpgregions.api.schedule.PlatformScheduler;
import net.islandearth.rpgregions.commands.Commands;
import net.islandearth.rpgregions.effects.FogEffect;
import net.islandearth.rpgregions.effects.PotionRegionEffect;
import net.islandearth.rpgregions.effects.RegionEffect;
import net.islandearth.rpgregions.effects.RegionEffectRegistry;
import net.islandearth.rpgregions.effects.VanishEffect;
import net.islandearth.rpgregions.exception.CouldNotStartException;
import net.islandearth.rpgregions.folia.schedule.FoliaScheduler;
import net.islandearth.rpgregions.gson.AbstractAdapter;
import net.islandearth.rpgregions.gson.ItemStackAdapter;
import net.islandearth.rpgregions.gson.LocationAdapter;
@@ -32,7 +28,6 @@ import net.islandearth.rpgregions.listener.RegionListener;
import net.islandearth.rpgregions.listener.ServerReloadListener;
import net.islandearth.rpgregions.listener.external.CustomStructuresListener;
import net.islandearth.rpgregions.managers.RPGRegionsManagers;
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
import net.islandearth.rpgregions.managers.registry.IRPGRegionsRegistry;
import net.islandearth.rpgregions.requirements.AlonsoLevelRequirement;
import net.islandearth.rpgregions.requirements.DependencyRequirement;
@@ -59,37 +54,39 @@ import net.islandearth.rpgregions.rewards.QuestReward;
import net.islandearth.rpgregions.rewards.RegionDiscoverReward;
import net.islandearth.rpgregions.rewards.RegionRewardRegistry;
import net.islandearth.rpgregions.rewards.TeleportReward;
import net.islandearth.rpgregions.schedule.BukkitScheduler;
import net.islandearth.rpgregions.tasks.DynmapTask;
import net.islandearth.rpgregions.translation.Translations;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.milkbowl.vault.economy.Economy;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
import org.bstats.charts.SingleLineChart;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
public final class RPGRegions extends JavaPlugin implements IRPGRegionsAPI {
private BukkitAudiences adventure;
private PlatformScheduler<? extends IRPGRegionsAPI> scheduler;
private RPGRegionsManagers managers;
private PaperCommandManager commandManager;
private Economy ecoProvider;
public PaperCommandManager getCommandManager() {
return commandManager;
public @NonNull BukkitAudiences adventure() {
if (this.adventure == null) {
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
}
return this.adventure;
}
@Override
@@ -101,10 +98,11 @@ public final class RPGRegions extends JavaPlugin implements IRPGRegionsAPI {
@Override
public void onEnable() {
this.adventure = BukkitAudiences.create(this);
this.scheduler = FoliaScheduler.RUNNING_FOLIA ? new FoliaScheduler(this) : new BukkitScheduler(this);
RPGRegionsAPI.setAPI(this);
this.createConfig();
this.generateLang();
this.commandManager = new PaperCommandManager(this);
try {
this.managers = new RPGRegionsManagers(this);
} catch (ReflectiveOperationException | IOException | CouldNotStartException e) {
@@ -112,12 +110,12 @@ public final class RPGRegions extends JavaPlugin implements IRPGRegionsAPI {
Bukkit.getPluginManager().disablePlugin(this);
return;
}
this.registerCommands();
this.registerRewards();
this.registerRequirements();
this.registerEffects();
this.registerListeners();
this.registerCommands();
this.translator = Translator.of(this, "lang", Language.ENGLISH, debug());
this.translator = Translator.of(this, "lang", Language.BRITISH_ENGLISH, debug());
this.registerTasks();
this.registerMetrics();
this.setupEconomy();
@@ -155,6 +153,11 @@ public final class RPGRegions extends JavaPlugin implements IRPGRegionsAPI {
managers.getRegionsCache().getConfiguredRegions().forEach((id, region) -> region.save(this));
}
if (this.adventure != null) {
this.adventure.close();
this.adventure = null;
}
RPGRegionsAPI.setAPI(null);
DB.close();
}
@@ -186,55 +189,7 @@ public final class RPGRegions extends JavaPlugin implements IRPGRegionsAPI {
}
private void registerCommands() {
final PaperCommandManager manager = commandManager;
manager.enableUnstableAPI("help");
manager.getCommandCompletions().registerAsyncCompletion("regions", context -> ImmutableList.copyOf(getManagers().getRegionsCache().getConfiguredRegions().keySet()));
manager.getCommandCompletions().registerAsyncCompletion("integration-regions", context -> ImmutableList.copyOf(this.getManagers().getIntegrationManager().getAllRegionNames(context.getPlayer().getWorld())));
manager.getCommandCompletions().registerAsyncCompletion("async", context -> ImmutableList.of("--async"));
manager.getCommandCompletions().registerAsyncCompletion("region-types", context -> ImmutableList.of("Cuboid", "Poly"));
manager.getCommandCompletions().registerAsyncCompletion("offline-players", context -> {
List<String> players = new ArrayList<>();
if (!getConfig().getBoolean("settings.server.tabcomplete.search-offline-players")) {
for (Player player : Bukkit.getOnlinePlayers()) {
players.add(player.getName());
}
return ImmutableList.copyOf(players);
}
for (OfflinePlayer offlinePlayer : Bukkit.getOfflinePlayers()) {
players.add(offlinePlayer.getName());
}
return ImmutableList.copyOf(players);
});
manager.getCommandCompletions().registerAsyncCompletion("schematics", context -> {
File schematicFolder = new File("plugins/WorldEdit/schematics/");
List<String> files = new ArrayList<>();
for (File file : schematicFolder.listFiles()) {
files.add(file.getName());
}
return files;
});
manager.getCommandCompletions().registerAsyncCompletion("templates", context -> {
File templates = new File(this.getDataFolder() + File.separator + "templates");
List<String> files = new ArrayList<>();
for (File file : templates.listFiles()) {
files.add(file.getName());
}
return files;
});
manager.getCommandContexts().registerContext(ConfiguredRegion.class, context -> {
String id = context.popFirstArg();
for (ConfiguredRegion region : managers.getRegionsCache().getConfiguredRegions().values()) {
if (region.getId().equals(id)) {
return region;
}
}
throw new InvalidCommandArgument("Could not find a region with that id.");
});
manager.registerCommand(new RPGRegionsCommand(this));
manager.registerCommand(new DiscoveriesCommand(this));
manager.registerCommand(new RPGRegionsDebugCommand(this));
manager.registerCommand(new RPGRegionsExportCommand(this));
new Commands(this);
}
private void registerRewards() {
@@ -305,6 +260,11 @@ public final class RPGRegions extends JavaPlugin implements IRPGRegionsAPI {
return Bukkit.getPluginManager().getPlugin("HeadDatabase") != null;
}
@Override
public PlatformScheduler<? extends IRPGRegionsAPI> getScheduler() {
return scheduler;
}
private void setupEconomy() {
if (getServer().getPluginManager().getPlugin("Vault") == null) {
return;
@@ -323,7 +283,7 @@ public final class RPGRegions extends JavaPlugin implements IRPGRegionsAPI {
private void registerTasks() {
if (Bukkit.getPluginManager().getPlugin("Dynmap") != null
&& getConfig().getBoolean("settings.external.dynmap")) {
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new DynmapTask(this), 0L, 20L);
getScheduler().executeRepeating(new DynmapTask(this), 0L, 20L);
getLogger().info("Registered support for Dynmap.");
}
}

View File

@@ -1,13 +1,10 @@
package net.islandearth.rpgregions.api.integrations.rpgregions;
import co.aikar.commands.InvalidCommandArgument;
import com.google.gson.Gson;
import net.islandearth.rpgregions.RPGRegions;
import net.islandearth.rpgregions.api.IRPGRegionsAPI;
import net.islandearth.rpgregions.api.events.RegionsEnterEvent;
import net.islandearth.rpgregions.api.integrations.IntegrationManager;
import net.islandearth.rpgregions.api.integrations.rpgregions.region.RPGRegionsRegion;
import net.islandearth.rpgregions.commands.RPGRegionsIntegrationCommand;
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@@ -39,20 +36,6 @@ public class RPGRegionsIntegration implements IntegrationManager {
public RPGRegionsIntegration(IRPGRegionsAPI plugin) {
this.plugin = plugin;
this.regions = new HashMap<>();
// Register command completions and command, it's here because we only want it to enable if enabled.
if (plugin instanceof RPGRegions rpgRegions) {
rpgRegions.getCommandManager().getCommandContexts().registerContext(RPGRegionsRegion.class, context -> {
String id = context.popFirstArg();
if (rpgRegions.getManagers().getIntegrationManager() instanceof RPGRegionsIntegration rpgRegionsIntegration) {
Optional<RPGRegionsRegion> region = rpgRegionsIntegration.getRegion(id);
if (region.isPresent()) {
return region.get();
}
}
throw new InvalidCommandArgument("Could not find a region with that id.");
});
rpgRegions.getCommandManager().registerCommand(new RPGRegionsIntegrationCommand(rpgRegions));
}
plugin.getLogger().info("RPGRegions region integration has been enabled.");
}

View File

@@ -0,0 +1,146 @@
package net.islandearth.rpgregions.commands;
import cloud.commandframework.annotations.AnnotationParser;
import cloud.commandframework.arguments.parser.ParserParameters;
import cloud.commandframework.arguments.parser.ParserRegistry;
import cloud.commandframework.arguments.parser.StandardParameters;
import cloud.commandframework.bukkit.CloudBukkitCapabilities;
import cloud.commandframework.execution.CommandExecutionCoordinator;
import cloud.commandframework.extra.confirmation.CommandConfirmationManager;
import cloud.commandframework.meta.CommandMeta;
import cloud.commandframework.minecraft.extras.MinecraftExceptionHandler;
import cloud.commandframework.paper.PaperCommandManager;
import com.google.common.collect.ImmutableList;
import io.leangen.geantyref.TypeToken;
import net.islandearth.rpgregions.RPGRegions;
import net.islandearth.rpgregions.api.integrations.rpgregions.RPGRegionsIntegration;
import net.islandearth.rpgregions.api.integrations.rpgregions.region.RPGRegionsRegion;
import net.islandearth.rpgregions.commands.caption.RPGRegionsCaptionRegistry;
import net.islandearth.rpgregions.commands.caption.RPGRegionsCaptionRegistryFactory;
import net.islandearth.rpgregions.commands.parser.ConfiguredRegionArgument;
import net.islandearth.rpgregions.commands.parser.IntegrationRegionArgument;
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
public class Commands {
public Commands(RPGRegions plugin) {
// This function maps the command sender type of our choice to the bukkit command sender.
final Function<CommandSender, CommandSender> mapperFunction = Function.identity();
final PaperCommandManager<CommandSender> manager;
try {
manager = new PaperCommandManager<>(
plugin,
CommandExecutionCoordinator.simpleCoordinator(),
mapperFunction,
mapperFunction
);
} catch (Exception e) {
plugin.getLogger().severe("Failed to initialize the command manager");
e.printStackTrace();
return;
}
// Register Brigadier mappings
if (manager.hasCapability(CloudBukkitCapabilities.BRIGADIER)) {
manager.registerBrigadier();
}
// Register asynchronous completions
if (manager.hasCapability(CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION)) {
manager.registerAsynchronousCompletions();
}
/*
* Create the confirmation manager. This allows us to require certain commands to be
* confirmed before they can be executed
*/
final CommandConfirmationManager<CommandSender> confirmationManager = new CommandConfirmationManager<>(30L, TimeUnit.SECONDS,
/* Action when confirmation is required */
context -> {
final String name = context.getCommand().getArguments().get(0).getName();
context.getCommandContext().getSender().sendMessage(
ChatColor.RED + "Confirmation required. Confirm using " + ChatColor.YELLOW + "/" + name + " confirm" + ChatColor.RED + ".");
},
/* Action when no confirmation is pending */ sender -> sender.sendMessage(
ChatColor.RED + "You don't have any pending commands.")
);
// Register the confirmation processor. This will enable confirmations for commands that require it
confirmationManager.registerConfirmationProcessor(manager);
// This will allow you to decorate commands with descriptions
final Function<ParserParameters, CommandMeta> commandMetaFunction = parserParameters ->
CommandMeta.simple()
.with(CommandMeta.DESCRIPTION, parserParameters.get(StandardParameters.DESCRIPTION, "No description"))
.build();
// Override the default exception handlers
// todo: change some stuff lmao
new MinecraftExceptionHandler<CommandSender>()
.withInvalidSyntaxHandler()
.withInvalidSenderHandler()
.withNoPermissionHandler()
.withArgumentParsingHandler()
.apply(manager, player -> plugin.adventure().sender(player));
// Register our custom caption registry so we can define exception messages for parsers
final RPGRegionsCaptionRegistry<CommandSender> captionRegistry = new RPGRegionsCaptionRegistryFactory<CommandSender>().create();
manager.captionRegistry(captionRegistry);
// Register custom parsers
final ParserRegistry<CommandSender> parserRegistry = manager.parserRegistry();
parserRegistry.registerParserSupplier(TypeToken.get(ConfiguredRegion.class), parserParameters ->
new ConfiguredRegionArgument.ConfiguredRegionParser<>());
parserRegistry.registerParserSupplier(TypeToken.get(RPGRegionsRegion.class), parserParameters ->
new IntegrationRegionArgument.IntegrationRegionParser<>());
parserRegistry.registerSuggestionProvider("region-types", (context, arg) -> ImmutableList.of("Cuboid", "Poly"));
parserRegistry.registerSuggestionProvider("integration-regions", (context, arg) -> {
if (context.getSender() instanceof Player player) {
return ImmutableList.copyOf(plugin.getManagers().getIntegrationManager().getAllRegionNames(player.getWorld()));
}
return new ArrayList<>();
});
parserRegistry.registerSuggestionProvider("templates", (context, arg) -> {
File templates = new File(plugin.getDataFolder() + File.separator + "templates");
List<String> files = new ArrayList<>();
for (File file : templates.listFiles()) {
files.add(file.getName());
}
return files;
});
parserRegistry.registerSuggestionProvider("schematics", (context, arg) -> {
File schematicFolder = new File("plugins/WorldEdit/schematics/");
List<String> files = new ArrayList<>();
for (File file : schematicFolder.listFiles()) {
files.add(file.getName());
}
return files;
});
parserRegistry.registerSuggestionProvider("async", (context, arg) -> List.of("--async"));
final AnnotationParser<CommandSender> annotationParser = new AnnotationParser<>(manager, CommandSender.class, commandMetaFunction);
annotationParser.parse(new DiscoveriesCommand(plugin));
annotationParser.parse(new RPGRegionsCommand(plugin, manager));
annotationParser.parse(new RPGRegionsDebugCommand(plugin));
annotationParser.parse(new RPGRegionsExportCommand(plugin, manager));
if (plugin.getManagers().getIntegrationManager() instanceof RPGRegionsIntegration) {
annotationParser.parse(new RPGRegionsIntegrationCommand(plugin, manager));
}
}
}

View File

@@ -1,11 +1,9 @@
package net.islandearth.rpgregions.commands;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandCompletion;
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Default;
import co.aikar.commands.annotation.Subcommand;
import cloud.commandframework.annotations.Argument;
import cloud.commandframework.annotations.CommandDescription;
import cloud.commandframework.annotations.CommandMethod;
import cloud.commandframework.annotations.CommandPermission;
import net.islandearth.rpgregions.RPGRegions;
import net.islandearth.rpgregions.api.events.RegionDiscoverEvent;
import net.islandearth.rpgregions.gui.DiscoveryGUI;
@@ -20,8 +18,7 @@ import org.bukkit.entity.Player;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@CommandAlias("discoveries|discovery")
public class DiscoveriesCommand extends BaseCommand {
public class DiscoveriesCommand {
private final RPGRegions plugin;
@@ -29,16 +26,19 @@ public class DiscoveriesCommand extends BaseCommand {
this.plugin = plugin;
}
@Default
@CommandDescription("Opens the discovery GUI")
@CommandPermission("rpgregions.list")
@CommandMethod("discoveries|discovery")
public void onDefault(Player player) {
new DiscoveryGUI(plugin, player).open();
}
@Subcommand("discover")
@CommandDescription("Discovers a region for a player")
@CommandPermission("rpgregions.discover")
@CommandCompletion("@regions @offline-players")
public void onDiscover(CommandSender sender, ConfiguredRegion configuredRegion, OfflinePlayer target) {
@CommandMethod("discoveries|discovery discover <region> <player>")
public void onDiscover(CommandSender sender,
@Argument("region") ConfiguredRegion configuredRegion,
@Argument("player") OfflinePlayer target) {
plugin.getManagers().getStorageManager().getAccount(target.getUniqueId()).thenAccept(account -> {
LocalDateTime date = LocalDateTime.now();
DateTimeFormatter format = DateTimeFormatter.ofPattern(plugin.getConfig().getString("settings.server.discoveries.date.format"));

View File

@@ -1,13 +1,12 @@
package net.islandearth.rpgregions.commands;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.CommandHelp;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandCompletion;
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Default;
import co.aikar.commands.annotation.HelpCommand;
import co.aikar.commands.annotation.Subcommand;
import cloud.commandframework.annotations.Argument;
import cloud.commandframework.annotations.CommandDescription;
import cloud.commandframework.annotations.CommandMethod;
import cloud.commandframework.annotations.CommandPermission;
import cloud.commandframework.annotations.specifier.Greedy;
import cloud.commandframework.minecraft.extras.MinecraftHelp;
import cloud.commandframework.paper.PaperCommandManager;
import net.islandearth.rpgregions.RPGRegions;
import net.islandearth.rpgregions.api.RPGRegionsAPI;
import net.islandearth.rpgregions.api.events.RPGRegionsReloadEvent;
@@ -27,6 +26,7 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -34,25 +34,30 @@ import java.io.File;
import java.io.FileReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@CommandAlias("rpgregions|rpgr")
public class RPGRegionsCommand extends BaseCommand {
public class RPGRegionsCommand {
private final RPGRegions plugin;
private final MinecraftHelp<CommandSender> help;
private final List<UUID> regenerateConfirm = new ArrayList<>();
private static final String WARNING_MESSAGE = ChatColor.RED + "" + ChatColor.ITALIC + "" + ChatColor.BOLD
+ "The regenerate configuration is very dangerous and can delete world sections if used wrongly.";
public RPGRegionsCommand(RPGRegions plugin) {
public RPGRegionsCommand(RPGRegions plugin, PaperCommandManager<CommandSender> manager) {
this.plugin = plugin;
this.help = new MinecraftHelp<>(
"/rpgregions help",
player -> plugin.adventure().sender(player),
manager
);
}
@Default
@CommandDescription("The default RPGRegions command")
@CommandMethod("rpgregions|rpgr")
public void onDefault(CommandSender sender) {
if (sender.hasPermission("rpgregions.noview") && !sender.isOp()) return;
@@ -68,13 +73,13 @@ public class RPGRegionsCommand extends BaseCommand {
+ " regions are loaded with " + rewards + " rewards.");
}
@HelpCommand
@Subcommand("help")
public void onHelp(final CommandHelp commandHelp) {
commandHelp.showHelp();
@CommandMethod("rpgregions|rpgr help [query]")
public void onHelp(final CommandSender sender, @Argument("query") @Greedy @Nullable String query) {
help.queryCommands(query == null ? "" : query, sender);
}
@Subcommand("about")
@CommandDescription("Debug information about the plugin")
@CommandMethod("rpgregions|rpgr about")
public void onAbout(CommandSender sender) {
sender.sendMessage(StringUtils.colour("&eRPGRegions v" + plugin.getDescription().getVersion() + "."));
sender.sendMessage(StringUtils.colour("&eOwner: https://www.spigotmc.org/members/%%__USER__%%/"));
@@ -82,10 +87,13 @@ public class RPGRegionsCommand extends BaseCommand {
sender.sendMessage(StringUtils.colour("&eIntegration: " + plugin.getManagers().getIntegrationManager().getClass().getName()));
}
@Subcommand("add")
@CommandDescription("Creates a configured region from a region created in your integration")
@CommandPermission("rpgregions.add")
@CommandCompletion("@integration-regions")
public void onAdd(CommandSender sender, String region, @co.aikar.commands.annotation.Optional @Nullable String worldName) {
@CommandMethod("rpgregions|rpgr add <region> [world]")
public void onAdd(CommandSender sender,
@Argument(value = "region", suggestions = "integration-regions") String region,
@Argument("world") @Nullable World world) {
if (plugin.getManagers().getRegionsCache().getConfiguredRegion(region).isPresent()) {
sender.sendMessage(StringUtils.colour("&cThat region is already configured."));
return;
@@ -96,7 +104,6 @@ public class RPGRegionsCommand extends BaseCommand {
location = player.getLocation();
}
final World world = worldName == null ? null : Bukkit.getWorld(worldName);
if (world != null) {
if (location == null) location = new Location(world, 0, 100, 0);
else location.setWorld(world);
@@ -127,59 +134,58 @@ public class RPGRegionsCommand extends BaseCommand {
plugin.getManagers().getRegionsCache().addConfiguredRegion(configuredRegion);
}
@Subcommand("setname")
@CommandDescription("Sets the display name of a region")
@CommandPermission("rpgregions.setname")
@CommandCompletion("@regions")
public void onSetName(CommandSender sender, String region, String regionName) {
Optional<ConfiguredRegion> configuredRegion = plugin.getManagers().getRegionsCache().getConfiguredRegion(region);
if (configuredRegion.isEmpty()) {
sender.sendMessage(StringUtils.colour("&cRegion '" + region + "' does not exist yet, create it first."));
return;
}
configuredRegion.get().setCustomName(regionName);
sender.sendMessage(StringUtils.colour("&aSet name of region '" + region + "' to: " + regionName));
@CommandMethod("rpgregions|rpgr setname <region> <name>")
public void onSetName(CommandSender sender,
@Argument("region") ConfiguredRegion region,
@Argument("name") String name) {
region.setCustomName(name);
sender.sendMessage(StringUtils.colour("&aSet name of region '" + region + "' to: " + name));
}
@Subcommand("remove")
@CommandDescription("Removes a configured region. Does not delete it from your integration.")
@CommandPermission("rpgregions.remove")
@CommandCompletion("@regions")
public void onRemove(CommandSender sender, ConfiguredRegion configuredRegion) {
if (configuredRegion != null) {
configuredRegion.delete(plugin);
plugin.getManagers().getRegionsCache().removeConfiguredRegion(configuredRegion.getId());
sender.sendMessage(StringUtils.colour("&cRemoved configured region " + configuredRegion.getId() + "!"));
@CommandMethod("rpgregions|rpgr remove <region>")
public void onRemove(CommandSender sender, @Argument("region") ConfiguredRegion region) {
if (region != null) {
region.delete(plugin);
plugin.getManagers().getRegionsCache().removeConfiguredRegion(region.getId());
sender.sendMessage(StringUtils.colour("&cRemoved configured region " + region.getId() + "!"));
} else {
sender.sendMessage(StringUtils.colour("&cA region by that name is not yet configured."));
}
}
@Subcommand("edit")
@CommandDescription("Opens the editor GUI for a region")
@CommandPermission("rpgregions.edit")
@CommandCompletion("@regions")
public void onEdit(Player player, ConfiguredRegion configuredRegion) {
new RegionCreateGUI(plugin, player, configuredRegion).open();
@CommandMethod("rpgregions|rpgr edit <region>")
public void onEdit(Player player, @Argument("region") ConfiguredRegion region) {
new RegionCreateGUI(plugin, player, region).open();
}
@Subcommand("list|discoveries")
@CommandDescription("Opens the /discovery GUI")
@CommandPermission("rpgregions.list")
@CommandMethod("rpgregions|rpgr list|discoveries")
public void onList(Player player) {
new DiscoveryGUI(plugin, player).open();
}
@Subcommand("additem")
@CommandDescription("Adds an item reward to a region (util command)")
@CommandPermission("rpgregions.additem")
@CommandCompletion("@regions")
public void onAddItem(Player player, ConfiguredRegion configuredRegion) {
if (configuredRegion != null) {
configuredRegion.getRewards().add(new ItemReward(plugin, player.getInventory().getItemInMainHand()));
@CommandMethod("rpgregions|rpgr additem <region>")
public void onAddItem(Player player, @Argument("region") ConfiguredRegion region) {
if (region != null) {
region.getRewards().add(new ItemReward(plugin, player.getInventory().getItemInMainHand()));
player.sendMessage(ChatColor.GREEN + "Item added to configuration!");
} else {
player.sendMessage(ChatColor.RED + "No region exists by that name.");
}
}
@Subcommand("reload")
@CommandDescription("Reloads configured regions from the `/plugins/RPGRegions/regions` folder.")
@CommandPermission("rpgregions.reload")
@CommandMethod("rpgregions|rpgr reload")
public void onReload(CommandSender sender) {
sender.sendMessage(ChatColor.GREEN + "Reloading region files...");
long startTime = System.currentTimeMillis();
@@ -208,11 +214,11 @@ public class RPGRegionsCommand extends BaseCommand {
sender.sendMessage(ChatColor.GREEN + "Done! (" + totalTime + "ms)");
}
@Subcommand("save")
@CommandDescription("Saves configured regions to the `/plugins/RPGRegions/regions` folder. Also saves user data.")
@CommandPermission("rpgregions.save")
@CommandCompletion("@async")
public void onSave(CommandSender sender, @co.aikar.commands.annotation.Optional String[] args) {
boolean async = Arrays.asList(args).contains("--async");
@CommandMethod("rpgregions|rpgr save [async]")
public void onSave(CommandSender sender, @Argument(value = "async", suggestions = "async") String asyncArg) {
boolean async = asyncArg.equals("--async");
sender.sendMessage(ChatColor.GREEN + "Saving data..." + (async ? ChatColor.GOLD + " (async)" : ""));
long startTime = System.currentTimeMillis();
@@ -236,68 +242,55 @@ public class RPGRegionsCommand extends BaseCommand {
});
}
@Subcommand("reset")
@CommandDescription("Resets the data of a player")
@CommandPermission("rpgregions.reset")
@CommandCompletion("@players @regions")
public void onReset(CommandSender sender, String[] args) {
@SuppressWarnings({"deprecation"}) // We know what we're doing.
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
if (!player.hasPlayedBefore()) {
sender.sendMessage(ChatColor.RED + "That player cannot be found.");
return;
}
switch (args.length) {
case 1 -> {
plugin.getManagers().getStorageManager().clearDiscoveries(player.getUniqueId());
@CommandMethod("rpgregions|rpgr reset <player> [region]")
public void onReset(CommandSender sender,
@Argument("player") @NonNull OfflinePlayer player,
@Argument("region") @Nullable ConfiguredRegion region) {
if (region == null) {
plugin.getManagers().getStorageManager().clearDiscoveries(player.getUniqueId());
if (!player.isOnline())
plugin.getManagers().getStorageManager().removeCachedAccount(player.getUniqueId());
sender.sendMessage(ChatColor.GREEN + "Players discoveries has been cleared.");
} else {
if (plugin.getManagers().getRegionsCache().getConfiguredRegions().containsKey(region.getId())) {
plugin.getManagers().getStorageManager().clearDiscovery(player.getUniqueId(), region.getId());
if (!player.isOnline())
plugin.getManagers().getStorageManager().removeCachedAccount(player.getUniqueId());
sender.sendMessage(ChatColor.GREEN + "Players discoveries has been cleared.");
sender.sendMessage(ChatColor.GREEN + "Discovery cleared.");
} else {
sender.sendMessage(ChatColor.RED + "Region does not exist or is not configured.");
}
case 2 -> {
String regionId = args[1];
if (plugin.getManagers().getRegionsCache().getConfiguredRegions().containsKey(regionId)) {
plugin.getManagers().getStorageManager().clearDiscovery(player.getUniqueId(), regionId);
if (!player.isOnline())
plugin.getManagers().getStorageManager().removeCachedAccount(player.getUniqueId());
sender.sendMessage(ChatColor.GREEN + "Discovery cleared.");
} else {
sender.sendMessage(ChatColor.RED + "Region does not exist or is not configured.");
}
}
default -> sender.sendMessage(ChatColor.RED + "Usage: /rpgregions reset <player> [region_id]");
}
}
@Subcommand("delete")
@CommandDescription("Deletes user accounts from the database")
@CommandPermission("rpgregions.delete")
@CommandCompletion("@players")
public void onDelete(CommandSender sender, Player player) {
if (player != null) {
plugin.getManagers().getStorageManager().deleteAccount(player.getUniqueId());
sender.sendMessage(ChatColor.GREEN + "Deleted account of player.");
} else {
sender.sendMessage(ChatColor.RED + "That player cannot be found.");
}
@CommandMethod("rpgregions|rpgr delete <player>")
public void onDelete(CommandSender sender,
@Argument("player") @NotNull OfflinePlayer player) {
plugin.getManagers().getStorageManager().deleteAccount(player.getUniqueId());
sender.sendMessage(ChatColor.GREEN + "Deleted account of player.");
}
@Subcommand("setlocation")
@CommandDescription("Sets the teleport location of a region")
@CommandPermission("rpgregions.setlocation")
@CommandCompletion("@regions")
public void onSetLocation(Player player, ConfiguredRegion configuredRegion) {
if (configuredRegion != null) {
Location location = player.getLocation();
configuredRegion.setLocation(location);
player.sendMessage(ChatColor.GREEN + "Location has been updated.");
} else {
player.sendMessage(StringUtils.colour("&cA region by that name is not yet configured."));
}
@CommandMethod("rpgregions|rpgr setlocation <region>")
public void onSetLocation(Player player,
@Argument("region") ConfiguredRegion region) {
Location location = player.getLocation();
region.setLocation(location);
player.sendMessage(ChatColor.GREEN + "Location has been updated.");
}
@Subcommand("regenerate|regen")
//TODO: use confirmation api
@CommandDescription("If configured, regenerates a region to the set schematic")
@CommandPermission("rpgregions.regenerate")
@CommandCompletion("@regions")
public void onRegenerate(Player player, ConfiguredRegion configuredRegion) {
@CommandMethod("rpgregions|rpgr regenerate <region>")
public void onRegenerate(Player player,
@Argument("region") ConfiguredRegion region) {
IntegrationType integrationType = IntegrationType.valueOf(plugin.getConfig().getString("settings.integration.name").toUpperCase());
if (integrationType != IntegrationType.WORLDGUARD) {
player.sendMessage(ChatColor.RED + "Regeneration only supports WorldGuard integrations.");
@@ -306,13 +299,13 @@ public class RPGRegionsCommand extends BaseCommand {
if (!regenerateConfirm.contains(player.getUniqueId())) {
regenerateConfirm.add(player.getUniqueId());
player.sendMessage(ChatColor.YELLOW + "Run /rpgregions regenerate " + configuredRegion.getId() + " again to confirm. Only use if you know what you are doing!");
player.sendMessage(ChatColor.YELLOW + "Run /rpgregions regenerate " + region.getId() + " again to confirm. Only use if you know what you are doing!");
player.sendMessage(WARNING_MESSAGE);
} else {
regenerateConfirm.remove(player.getUniqueId());
player.sendMessage(ChatColor.GREEN + "Regenerating region...");
long startTime = System.currentTimeMillis();
boolean done = RegenUtils.regenerate(configuredRegion);
boolean done = RegenUtils.regenerate(region);
if (!done) {
player.sendMessage(ChatColor.RED + "Unable to regenerate region. Check console for details.");
}
@@ -322,28 +315,30 @@ public class RPGRegionsCommand extends BaseCommand {
}
}
@Subcommand("setschematic")
@CommandDescription("Sets the regeneration schematic for a region")
@CommandPermission("rpgregions.setschematic")
@CommandCompletion("@regions @schematics @nothing")
public void onAddSchematic(Player player, ConfiguredRegion configuredRegion, String schematicName) {
@CommandMethod("rpgregions|rpgr setschematic <region> <schematicName>")
public void onAddSchematic(Player player,
@Argument("region") ConfiguredRegion region,
@Argument("schematicName") String schematicName) {
IntegrationType integrationType = IntegrationType.valueOf(plugin.getConfig().getString("settings.integration.name").toUpperCase());
if (integrationType != IntegrationType.WORLDGUARD) {
player.sendMessage(ChatColor.RED + "Regeneration only supports WorldGuard integrations.");
return;
}
if (configuredRegion != null) {
if (region != null) {
if (!regenerateConfirm.contains(player.getUniqueId())) {
regenerateConfirm.add(player.getUniqueId());
player.sendMessage(ChatColor.YELLOW + "Run /rpgregions addschematic " + schematicName + " again to confirm. Only use if you know what you are doing!");
player.sendMessage(ChatColor.RED + "MAKE SURE YOU ARE STANDING WHERE YOU CREATED THE SCHEMATIC ORIGINALLY (//copy, //schematic save), OTHERWISE IT WILL NOT PASTE CORRECTLY.");
} else {
regenerateConfirm.remove(player.getUniqueId());
Regenerate regenerate = configuredRegion.getRegenerate();
Regenerate regenerate = region.getRegenerate();
if (regenerate == null) regenerate = new Regenerate(Integer.MAX_VALUE, false, new ArrayList<>());
regenerate.setSchematicName(schematicName);
regenerate.setOrigin(player.getLocation());
configuredRegion.setRegenerate(regenerate);
region.setRegenerate(regenerate);
player.sendMessage(ChatColor.GREEN + "This region has had a regenerate section added, and schematicName set to " + schematicName + " and origin set to " + player.getLocation() + ".");
player.sendMessage(ChatColor.YELLOW + "Run /rpgregions save and " + ChatColor.BOLD + "CONFIGURE BEFORE RELOADING OR RESTARTING THE SERVER.");
}
@@ -351,8 +346,9 @@ public class RPGRegionsCommand extends BaseCommand {
}
}
@Subcommand("forceupdateicons")
@CommandDescription("Resets the icons of all configured regions to the config default")
@CommandPermission("rpgregions.forceupdate")
@CommandMethod("rpgregions|rpgr forceupdateicons")
public void onForceUpdateIcons(Player player) {
Optional<Material> defaultIcon = Optional.of(Material.valueOf(RPGRegionsAPI.getAPI().getConfig().getString("settings.server.gui.default_region_icon")));
defaultIcon.ifPresent(xMaterial -> {

View File

@@ -1,10 +1,8 @@
package net.islandearth.rpgregions.commands;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Default;
import co.aikar.commands.annotation.Subcommand;
import cloud.commandframework.annotations.Argument;
import cloud.commandframework.annotations.CommandMethod;
import cloud.commandframework.annotations.CommandPermission;
import co.aikar.idb.DB;
import co.aikar.idb.Database;
import net.islandearth.rpgregions.RPGRegions;
@@ -15,14 +13,14 @@ import net.islandearth.rpgregions.rewards.DiscoveryReward;
import net.islandearth.rpgregions.thread.Blocking;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import java.sql.Connection;
import java.sql.SQLException;
@CommandAlias("rpgregionsdebug|rpgrd")
@CommandPermission("rpgregions.debug")
public class RPGRegionsDebugCommand extends BaseCommand {
public class RPGRegionsDebugCommand {
private final RPGRegions plugin;
@@ -30,7 +28,7 @@ public class RPGRegionsDebugCommand extends BaseCommand {
this.plugin = plugin;
}
@Default
@CommandMethod("rpgregionsdebug|rpgrd")
public void onDefault(CommandSender sender) throws SQLException {
IStorageManager storageManager = plugin.getManagers().getStorageManager();
sender.sendMessage(ChatColor.GOLD + "Database status:");
@@ -67,8 +65,7 @@ public class RPGRegionsDebugCommand extends BaseCommand {
});
}
@Subcommand("enable|disable")
@CommandMethod("rpgregionsdebug|rpgrd enable|disable|toggle")
public void onEnable(CommandSender sender) {
final boolean newValue = !plugin.debug();
plugin.getConfig().set("settings.dev.debug", newValue);
@@ -76,7 +73,7 @@ public class RPGRegionsDebugCommand extends BaseCommand {
else sender.sendMessage(ChatColor.RED + "Debug disabled.");
}
@Subcommand("cache")
@CommandMethod("rpgregionsdebug|rpgrd cache")
public void onCache(CommandSender sender) {
IStorageManager storageManager = plugin.getManagers().getStorageManager();
sender.sendMessage(ChatColor.GOLD + "Database cache:");
@@ -84,4 +81,13 @@ public class RPGRegionsDebugCommand extends BaseCommand {
sender.sendMessage(ChatColor.GRAY + " - " + uuid.toString());
});
}
@CommandMethod("rpgregionsdebug|rpgrd removecached <player>")
public void onRemoveCached(CommandSender sender, @Argument("player") OfflinePlayer player) {
IStorageManager storageManager = plugin.getManagers().getStorageManager();
sender.sendMessage(ChatColor.GREEN + "Removing from cache...");
storageManager.removeCachedAccount(player.getUniqueId()).thenAccept((a) -> {
sender.sendMessage(ChatColor.GREEN + "Successfully removed and saved " + player.getName() + "'s account from the cache.");
});
}
}

View File

@@ -1,13 +1,11 @@
package net.islandearth.rpgregions.commands;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.CommandHelp;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandCompletion;
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Default;
import co.aikar.commands.annotation.HelpCommand;
import co.aikar.commands.annotation.Subcommand;
import cloud.commandframework.annotations.Argument;
import cloud.commandframework.annotations.CommandDescription;
import cloud.commandframework.annotations.CommandMethod;
import cloud.commandframework.annotations.specifier.Greedy;
import cloud.commandframework.minecraft.extras.MinecraftHelp;
import cloud.commandframework.paper.PaperCommandManager;
import net.islandearth.rpgregions.RPGRegions;
import net.islandearth.rpgregions.effects.RegionEffect;
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
@@ -15,36 +13,42 @@ import net.islandearth.rpgregions.requirements.RegionRequirement;
import net.islandearth.rpgregions.rewards.DiscoveryReward;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.FileReader;
import java.io.Reader;
import java.util.logging.Level;
@CommandAlias("rpgre")
@CommandPermission("rpgregions.export")
public class RPGRegionsExportCommand extends BaseCommand {
public class RPGRegionsExportCommand {
private final RPGRegions plugin;
private final MinecraftHelp<CommandSender> help;
public RPGRegionsExportCommand(RPGRegions plugin) {
public RPGRegionsExportCommand(RPGRegions plugin, PaperCommandManager<CommandSender> manager) {
this.plugin = plugin;
this.help = new MinecraftHelp<>(
"/rpgre help",
player -> plugin.adventure().sender(player),
manager
);
}
@Default
@CommandDescription("The default RPGRegions export command.")
@CommandMethod("rpgre")
public void onDefault(CommandSender sender) {
sender.sendMessage(ChatColor.GREEN + "Use this command to export/import a region template.");
}
@HelpCommand
@Subcommand("help")
public void onHelp(final CommandHelp commandHelp) {
commandHelp.showHelp();
@CommandMethod("rpgre help [query]")
public void onHelp(final CommandSender sender, @Argument("query") @Greedy @Nullable String query) {
help.queryCommands(query == null ? "" : query, sender);
}
@Subcommand("export")
@CommandCompletion("@regions")
public void onExport(CommandSender sender, ConfiguredRegion region) {
@CommandDescription("Exports a region to a template file (`plugins/RPGRegions/templates`).")
@CommandMethod("rpgre export <region>")
public void onExport(CommandSender sender,
@Argument("region") ConfiguredRegion region) {
File templates = new File(plugin.getDataFolder() + File.separator + "templates");
File target = new File(templates + File.separator + region.getId() + "_template.json");
region.save(plugin, target);
@@ -53,9 +57,13 @@ public class RPGRegionsExportCommand extends BaseCommand {
sender.sendMessage(ChatColor.YELLOW + "You may use /rpgre import " + region.getId() + " <target> to import the requirements, rewards, etc. of this template to the target region.");
}
@Subcommand("import")
@CommandCompletion("@templates @regions")
public void onImport(CommandSender sender, String template, ConfiguredRegion region) {
@CommandDescription("Imports a template region into an existing configured region")
@CommandMethod("rpgre import <template> <region>")
public void onImport(CommandSender sender,
@Argument(value = "template",
suggestions = "templates",
description = "The name of the template file") String template,
@Argument("region") ConfiguredRegion region) {
File templateFile = new File(plugin.getDataFolder() + File.separator + "templates" + File.separator + template);
if (!templateFile.exists()) {
sender.sendMessage(ChatColor.RED + "That template does not exist.");

View File

@@ -1,13 +1,12 @@
package net.islandearth.rpgregions.commands;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.CommandHelp;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandCompletion;
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Default;
import co.aikar.commands.annotation.HelpCommand;
import co.aikar.commands.annotation.Subcommand;
import cloud.commandframework.annotations.Argument;
import cloud.commandframework.annotations.CommandDescription;
import cloud.commandframework.annotations.CommandMethod;
import cloud.commandframework.annotations.CommandPermission;
import cloud.commandframework.annotations.specifier.Greedy;
import cloud.commandframework.minecraft.extras.MinecraftHelp;
import cloud.commandframework.paper.PaperCommandManager;
import net.islandearth.rpgregions.RPGRegions;
import net.islandearth.rpgregions.api.integrations.rpgregions.RPGRegionsIntegration;
import net.islandearth.rpgregions.api.integrations.rpgregions.region.CuboidRegion;
@@ -24,63 +23,66 @@ import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
@CommandAlias("rpgri|rpgrintegration")
@CommandPermission("rpgregions.integration")
public class RPGRegionsIntegrationCommand extends BaseCommand {
public class RPGRegionsIntegrationCommand {
private final RPGRegions plugin;
private final MinecraftHelp<CommandSender> help;
public RPGRegionsIntegrationCommand(final RPGRegions plugin) {
public RPGRegionsIntegrationCommand(final RPGRegions plugin, PaperCommandManager<CommandSender> manager) {
this.plugin = plugin;
this.help = new MinecraftHelp<>(
"/rpgri help",
player -> plugin.adventure().sender(player),
manager
);
}
@Default
@CommandDescription("The default RPGRegions integration command.")
@CommandMethod("rpgri|rpgrintegration")
public void onDefault(CommandSender sender) {
sender.sendMessage(ChatColor.GREEN + "RPGRegions region integration is enabled. Type /rpgri help for help.");
}
@HelpCommand
@Subcommand("help")
public void onHelp(final CommandHelp commandHelp) {
commandHelp.showHelp();
@CommandMethod("rpgri|rpgrintegration help [query]")
public void onHelp(final CommandSender sender, @Argument("query") @Greedy @Nullable String query) {
help.queryCommands(query == null ? "" : query, sender);
}
@Subcommand("list")
@CommandDescription("Lists all existing regions in the integration")
@CommandMethod("rpgri|rpgrintegration list")
public void onList(final CommandSender sender) {
RPGRegionsIntegration integration = (RPGRegionsIntegration) plugin.getManagers().getIntegrationManager();
integration.getAllRegionNames(null).forEach(name -> sender.sendMessage(ChatColor.GREEN + "- " + name));
}
@Subcommand("info")
@CommandCompletion("@integration-regions")
public void onInfo(final CommandSender sender, final String name) {
RPGRegionsIntegration integration = (RPGRegionsIntegration) plugin.getManagers().getIntegrationManager();
Optional<RPGRegionsRegion> region = integration.getRegion(name);
if (region.isPresent()) {
sender.sendMessage(ChatColor.GREEN + "Name: " + ChatColor.WHITE + region.get().getName());
sender.sendMessage(ChatColor.GREEN + "Priority: " + ChatColor.WHITE + region.get().getPriority());
sender.sendMessage(ChatColor.GREEN + "Points for " + region.get().getName() + ":");
region.get().getPoints().forEach(point -> sender.sendMessage(" " + point.toString()));
return;
}
sender.sendMessage(ChatColor.RED + "Region " + name + " does not exist!");
@CommandDescription("Shows information about a region")
@CommandMethod("rpgri|rpgrintegration info <region>")
public void onInfo(final CommandSender sender,
@Argument(value = "region") final RPGRegionsRegion region) {
sender.sendMessage(ChatColor.GREEN + "Name: " + ChatColor.WHITE + region.getName());
sender.sendMessage(ChatColor.GREEN + "Priority: " + ChatColor.WHITE + region.getPriority());
sender.sendMessage(ChatColor.GREEN + "Points for " + region.getName() + ":");
region.getPoints().forEach(point -> sender.sendMessage(" " + point.toString()));
}
@Subcommand("save")
@CommandDescription("Saves all regions")
@CommandMethod("rpgri|rpgrintegration save")
public void onSave(final CommandSender sender) {
RPGRegionsIntegration integration = (RPGRegionsIntegration) plugin.getManagers().getIntegrationManager();
integration.save();
sender.sendMessage(ChatColor.GREEN + "Regions saved.");
}
@Subcommand("create")
@CommandCompletion("@integration-regions @region-types @worlds")
public void onCreate(final CommandSender sender, final String name, final String regionType,
@co.aikar.commands.annotation.Optional @Nullable String worldName) {
@CommandDescription("Creates a region of the specified name, type, and optionally the world it is in.")
@CommandMethod("rpgri|rpgrintegration create <name> <type> <world>")
public void onCreate(final CommandSender sender,
@Argument("name") final String name,
@Argument(value = "type", suggestions = "region-types") final String regionType,
@Argument("world") @Nullable World argWorld) {
// If worldName is null, try to get from sender if they are a player, else overworld, else worldName world
World world = worldName == null ? sender instanceof Player player ? player.getWorld() : Bukkit.getWorlds().get(0) : Bukkit.getWorld(worldName);
World world = argWorld == null ? sender instanceof Player player ? player.getWorld() : Bukkit.getWorlds().get(0) : argWorld;
RPGRegionsRegion region = switch (regionType.toLowerCase(Locale.ENGLISH)) {
case "cuboid" -> new CuboidRegion(name, world);
case "poly" -> new PolyRegion(name, world);
@@ -92,7 +94,7 @@ public class RPGRegionsIntegrationCommand extends BaseCommand {
return;
}
if (worldName == null && !(sender instanceof Player)) {
if (argWorld == null && !(sender instanceof Player)) {
sender.sendMessage(ChatColor.YELLOW + "WARNING: World name was not provided and you are not a player. Defaulted to '" + world.getName() + "'.");
}
@@ -101,66 +103,63 @@ public class RPGRegionsIntegrationCommand extends BaseCommand {
sender.sendMessage(ChatColor.GREEN + "Created region " + name + ".");
}
@Subcommand("delete")
@CommandCompletion("@integration-regions")
public void onDelete(final CommandSender sender, final RPGRegionsRegion region) {
@CommandDescription("Deletes a region.")
@CommandMethod("rpgri|rpgrintegration delete <region>")
public void onDelete(final CommandSender sender,
@Argument("region") final RPGRegionsRegion region) {
RPGRegionsIntegration integration = (RPGRegionsIntegration) plugin.getManagers().getIntegrationManager();
integration.removeRegion(region);
sender.sendMessage(ChatColor.GREEN + "Region " + region.getName() + " has been removed.");
}
@Subcommand("addpos")
@CommandCompletion("@integration-regions")
public void onAddPos(final CommandSender sender, final RPGRegionsRegion region,
@co.aikar.commands.annotation.Optional World world,
@co.aikar.commands.annotation.Optional Double x,
@co.aikar.commands.annotation.Optional Double y,
@co.aikar.commands.annotation.Optional Double z) {
System.out.println("world: " + world + ", x:" + x + ", y:" + y + ", z:" + z);
if (sender instanceof Player player && x == null && y == null && z == null) {
@CommandDescription("Adds a position to a region. Cuboid regions require 2 points to form a cuboid. Poly regions may have any number.")
@CommandMethod("rpgri|rpgrintegration addpos <region> [location]")
public void onAddPos(final CommandSender sender,
@Argument("region") final RPGRegionsRegion region,
@Argument("location") @Nullable Location location) {
if (sender instanceof Player player && location == null) {
if (!region.addPoint(player.getLocation())) {
player.sendMessage(ChatColor.RED + "Could not add a point to that region because it exceeds the size for its type.");
} else {
player.sendMessage(ChatColor.GREEN + "Added point to " + region.getName() + ".");
}
} else {
if (world == null || x == null || y == null || z == null) {
if (location == null) {
sender.sendMessage(ChatColor.RED + "You need to specify the world, x, y, z of the point.");
return;
}
Location location = new Location(world, x, y, z);
region.addPoint(location);
sender.sendMessage(ChatColor.GREEN + "Added point to " + region.getName() + ".");
}
}
@Subcommand("setpriority")
@CommandCompletion("@integration-regions @range:20")
public void onSetPriority(final Player player, final RPGRegionsRegion region, final int priority) {
@CommandDescription("Sets the priority of a region. Higher priority regions override lower priority ones in the same location.")
@CommandMethod("rpgri|rpgrintegration setpriority <region> <priority>")
public void onSetPriority(final Player player,
@Argument("region") final RPGRegionsRegion region,
@Argument("priority") final int priority) {
region.setPriority(priority);
player.sendMessage(ChatColor.GREEN + "Set priority of " + region.getName() + " to " + priority + ".");
}
@Subcommand("setworld")
@CommandCompletion("@integration-regions @worlds")
public void onSetWorld(final CommandSender sender, final RPGRegionsRegion region, final String worldName) {
final World world = Bukkit.getWorld(worldName);
if (world == null) {
sender.sendMessage(ChatColor.RED + "That world could not be found.");
return;
}
@CommandDescription("Sets the world a region is in.")
@CommandMethod("rpgri|rpgrintegration setworld <region> <world>")
public void onSetWorld(final CommandSender sender,
@Argument("region") final RPGRegionsRegion region,
@Argument("world") final World world) {
region.setWorld(world.getUID());
sender.sendMessage(ChatColor.GREEN + "Set region '" + region.getName() + "' world to '" + world.getName() + "'.");
}
@Subcommand("visualise")
@CommandCompletion("@integration-regions")
public void onVisualise(final Player sender, final RPGRegionsRegion region) {
@CommandDescription("Visualises the boundaries of a region.")
@CommandMethod("rpgri|rpgrintegration visualise <region>")
public void onVisualise(final Player sender, @Argument("region") final RPGRegionsRegion region) {
region.visualise(sender);
}
@Subcommand("whereami")
@CommandDescription("Tells you what region you are in.")
@CommandMethod("rpgri|rpgrintegration whereami")
public void onWhereAmI(final Player sender) {
final RPGRegionsIntegration manager = (RPGRegionsIntegration) plugin.getManagers().getIntegrationManager();
List<RPGRegionsRegion> regions = new ArrayList<>();
@@ -180,20 +179,15 @@ public class RPGRegionsIntegrationCommand extends BaseCommand {
}
}
@Subcommand("migrate")
@CommandCompletion("@worlds")
public void onMigrate(final CommandSender sender, final String worldName) {
final World world = Bukkit.getWorld(worldName);
if (world == null) {
sender.sendMessage(ChatColor.RED + "That world could not be found.");
return;
}
@CommandDescription("Migrates all regions to a world.")
@CommandMethod("rpgri|rpgrintegration migrate <world>")
public void onMigrate(final CommandSender sender,
@Argument("world") final World world) {
RPGRegionsIntegration integration = (RPGRegionsIntegration) plugin.getManagers().getIntegrationManager();
for (RPGRegionsRegion region : integration.getRegions()) {
region.setWorld(world.getUID());
}
sender.sendMessage(ChatColor.GREEN + "Set all regions to world '" + worldName + "'.");
sender.sendMessage(ChatColor.GREEN + "Set all regions to world '" + world.getName() + "'.");
}
}

View File

@@ -0,0 +1,32 @@
package net.islandearth.rpgregions.commands.caption;
import cloud.commandframework.captions.Caption;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
public class RPGRegionsCaptionKeys {
private static final Collection<Caption> RECOGNIZED_CAPTIONS = new LinkedList<>();
public static final Caption ARGUMENT_PARSE_FAILURE_REGION_NOT_FOUND = of("argument.parse.failure.region_not_found");
private RPGRegionsCaptionKeys() { }
private static @NonNull Caption of(final @NonNull String key) {
final Caption caption = Caption.of(key);
RECOGNIZED_CAPTIONS.add(caption);
return caption;
}
/**
* Get an immutable collection containing all standard caption keys
*
* @return Immutable collection of keys
*/
public static @NonNull Collection<@NonNull Caption> getStandardCaptionKeys() {
return Collections.unmodifiableCollection(RECOGNIZED_CAPTIONS);
}
}

View File

@@ -0,0 +1,24 @@
package net.islandearth.rpgregions.commands.caption;
import cloud.commandframework.bukkit.BukkitCaptionRegistry;
/**
* Caption registry that uses bi-functions to produce messages
*
* @param <C> Command sender type
*/
public class RPGRegionsCaptionRegistry<C> extends BukkitCaptionRegistry<C> {
/**
* Default caption for {@link RPGRegionsCaptionKeys#ARGUMENT_PARSE_FAILURE_REGION_NOT_FOUND}.
*/
public static final String ARGUMENT_PARSE_FAILURE_REGION_NOT_FOUND = "Could not find region '{input}'";
protected RPGRegionsCaptionRegistry() {
super();
this.registerMessageFactory(
RPGRegionsCaptionKeys.ARGUMENT_PARSE_FAILURE_REGION_NOT_FOUND,
(caption, sender) -> ARGUMENT_PARSE_FAILURE_REGION_NOT_FOUND
);
}
}

View File

@@ -0,0 +1,16 @@
package net.islandearth.rpgregions.commands.caption;
import org.checkerframework.checker.nullness.qual.NonNull;
public final class RPGRegionsCaptionRegistryFactory<C> {
/**
* Create a new RPGRegions caption registry instance
*
* @return Created instance
*/
public @NonNull RPGRegionsCaptionRegistry<C> create() {
return new RPGRegionsCaptionRegistry<>();
}
}

View File

@@ -0,0 +1,94 @@
package net.islandearth.rpgregions.commands.parser;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.arguments.parser.ArgumentParseResult;
import cloud.commandframework.arguments.parser.ArgumentParser;
import cloud.commandframework.captions.CaptionVariable;
import cloud.commandframework.context.CommandContext;
import cloud.commandframework.exceptions.parsing.NoInputProvidedException;
import cloud.commandframework.exceptions.parsing.ParserException;
import com.google.common.collect.ImmutableList;
import net.islandearth.rpgregions.api.RPGRegionsAPI;
import net.islandearth.rpgregions.commands.caption.RPGRegionsCaptionKeys;
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
import java.util.Optional;
import java.util.Queue;
import java.util.function.BiFunction;
public final class ConfiguredRegionArgument<C> extends CommandArgument<C, ConfiguredRegion> {
public ConfiguredRegionArgument(
final boolean required,
final @NonNull String name,
final @NonNull String defaultValue,
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String, @NonNull List<@NonNull String>> suggestionsProvider) {
super(required, name, new ConfiguredRegionArgument.ConfiguredRegionParser<>(), defaultValue, ConfiguredRegion.class, suggestionsProvider);
}
public static <C> ConfiguredRegionArgument.Builder<C> newBuilder(final @NonNull String name) {
return new ConfiguredRegionArgument.Builder<>(name);
}
public static final class Builder<C> extends CommandArgument.Builder<C, ConfiguredRegion> {
private Builder(final @NonNull String name) {
super(ConfiguredRegion.class, name);
}
@Override
public @NonNull CommandArgument<C, ConfiguredRegion> build() {
return new ConfiguredRegionArgument<>(
this.isRequired(),
this.getName(),
this.getDefaultValue(),
this.getSuggestionsProvider()
);
}
}
public static final class ConfiguredRegionParser<C> implements ArgumentParser<C, ConfiguredRegion> {
@Override
public @NonNull ArgumentParseResult<ConfiguredRegion> parse(
@NonNull CommandContext<@NonNull C> commandContext,
@NonNull Queue<@NonNull String> inputQueue) {
final String input = inputQueue.peek();
if (input == null) {
return ArgumentParseResult.failure(new NoInputProvidedException(
ConfiguredRegionArgument.class,
commandContext
));
}
final Optional<ConfiguredRegion> configuredRegion = RPGRegionsAPI.getAPI().getManagers().getRegionsCache().getConfiguredRegion(input);
if (configuredRegion.isPresent()) {
inputQueue.remove();
return ArgumentParseResult.success(configuredRegion.get());
}
return ArgumentParseResult.failure(new ConfiguredRegionParserException(input, commandContext));
}
@Override
public @NonNull List<@NonNull String> suggestions(@NonNull CommandContext<C> commandContext, @NonNull String input) {
return ImmutableList.copyOf(RPGRegionsAPI.getAPI().getManagers().getRegionsCache().getConfiguredRegions().keySet());
}
}
public static final class ConfiguredRegionParserException extends ParserException {
public ConfiguredRegionParserException(
final @NonNull String input,
final @NonNull CommandContext<?> context
) {
super(
ConfiguredRegionParser.class,
context,
RPGRegionsCaptionKeys.ARGUMENT_PARSE_FAILURE_REGION_NOT_FOUND,
CaptionVariable.of("input", input)
);
}
}
}

View File

@@ -0,0 +1,103 @@
package net.islandearth.rpgregions.commands.parser;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.arguments.parser.ArgumentParseResult;
import cloud.commandframework.arguments.parser.ArgumentParser;
import cloud.commandframework.captions.CaptionVariable;
import cloud.commandframework.context.CommandContext;
import cloud.commandframework.exceptions.parsing.NoInputProvidedException;
import cloud.commandframework.exceptions.parsing.ParserException;
import com.google.common.collect.ImmutableList;
import net.islandearth.rpgregions.api.RPGRegionsAPI;
import net.islandearth.rpgregions.api.integrations.rpgregions.RPGRegionsIntegration;
import net.islandearth.rpgregions.api.integrations.rpgregions.region.RPGRegionsRegion;
import net.islandearth.rpgregions.commands.caption.RPGRegionsCaptionKeys;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Queue;
import java.util.function.BiFunction;
public final class IntegrationRegionArgument<C> extends CommandArgument<C, RPGRegionsRegion> {
public IntegrationRegionArgument(
final boolean required,
final @NonNull String name,
final @NonNull String defaultValue,
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String, @NonNull List<@NonNull String>> suggestionsProvider) {
super(required, name, new IntegrationRegionArgument.IntegrationRegionParser<>(), defaultValue, RPGRegionsRegion.class, suggestionsProvider);
}
public static <C> IntegrationRegionArgument.Builder<C> newBuilder(final @NonNull String name) {
return new IntegrationRegionArgument.Builder<>(name);
}
public static final class Builder<C> extends CommandArgument.Builder<C, RPGRegionsRegion> {
private Builder(final @NonNull String name) {
super(RPGRegionsRegion.class, name);
}
@Override
public @NonNull CommandArgument<C, RPGRegionsRegion> build() {
return new IntegrationRegionArgument<>(
this.isRequired(),
this.getName(),
this.getDefaultValue(),
this.getSuggestionsProvider()
);
}
}
public static final class IntegrationRegionParser<C> implements ArgumentParser<C, RPGRegionsRegion> {
@Override
public @NonNull ArgumentParseResult<RPGRegionsRegion> parse(
@NonNull CommandContext<@NonNull C> commandContext,
@NonNull Queue<@NonNull String> inputQueue) {
final String input = inputQueue.peek();
if (input == null) {
return ArgumentParseResult.failure(new NoInputProvidedException(
IntegrationRegionArgument.class,
commandContext
));
}
if (RPGRegionsAPI.getAPI().getManagers().getIntegrationManager() instanceof RPGRegionsIntegration rpgRegionsIntegration) {
Optional<RPGRegionsRegion> region = rpgRegionsIntegration.getRegion(input);
if (region.isPresent()) {
inputQueue.remove();
return ArgumentParseResult.success(region.get());
}
}
return ArgumentParseResult.failure(new IntegrationRegionParserException(input, commandContext));
}
@Override
public @NonNull List<@NonNull String> suggestions(@NonNull CommandContext<C> commandContext, @NonNull String input) {
if (commandContext.getSender() instanceof Player player) {
return ImmutableList.copyOf(RPGRegionsAPI.getAPI().getManagers().getIntegrationManager().getAllRegionNames(player.getWorld()));
}
return new ArrayList<>();
}
}
public static final class IntegrationRegionParserException extends ParserException {
public IntegrationRegionParserException(
final @NonNull String input,
final @NonNull CommandContext<?> context
) {
super(
RPGRegionsRegion.class,
context,
RPGRegionsCaptionKeys.ARGUMENT_PARSE_FAILURE_REGION_NOT_FOUND,
CaptionVariable.of("input", input)
);
}
}
}

View File

@@ -19,7 +19,6 @@ import net.islandearth.rpgregions.translation.Translations;
import net.islandearth.rpgregions.utils.ItemStackBuilder;
import net.islandearth.rpgregions.utils.StringUtils;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@@ -272,8 +271,9 @@ public class DiscoveryGUI extends RPGRegionsGUI {
} else player.sendMessage(ChatColor.RED + "Unable to find teleport location.");
if (configuredRegion.getTeleportCooldown() != 0) {
account.getCooldowns().add(RPGRegionsAccount.AccountCooldown.TELEPORT);
Bukkit.getScheduler().runTaskLater(plugin,
() -> account.getCooldowns().remove(RPGRegionsAccount.AccountCooldown.TELEPORT), configuredRegion.getTeleportCooldown());
plugin.getScheduler().executeDelayed(() -> {
account.getCooldowns().remove(RPGRegionsAccount.AccountCooldown.TELEPORT);
}, configuredRegion.getTeleportCooldown());
}
}
} else {
@@ -299,7 +299,9 @@ public class DiscoveryGUI extends RPGRegionsGUI {
if (iconCommand.getCooldown() != 0) {
account.getCooldowns().add(RPGRegionsAccount.AccountCooldown.ICON_COMMAND);
Bukkit.getScheduler().runTaskLater(plugin, () -> account.getCooldowns().remove(RPGRegionsAccount.AccountCooldown.ICON_COMMAND), iconCommand.getCooldown());
plugin.getScheduler().executeDelayed(() -> {
account.getCooldowns().remove(RPGRegionsAccount.AccountCooldown.ICON_COMMAND);
}, iconCommand.getCooldown());
}
});
}

View File

@@ -15,7 +15,6 @@ import net.islandearth.rpgregions.translation.Translations;
import net.islandearth.rpgregions.utils.ItemStackBuilder;
import net.islandearth.rpgregions.utils.ReflectionUtils;
import net.wesjd.anvilgui.AnvilGUI;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
@@ -142,7 +141,7 @@ public class EditGuiElementGUI extends RPGRegionsGUI {
items.add(guiItem);
}
Bukkit.getScheduler().runTask(plugin, () -> { // GUI updates must be sync.
plugin.getScheduler().executeOnMain(() -> { // GUI updates must be sync.
pane.populateWithGuiItems(items);
gui.setTitle(region.getId());
gui.update();

View File

@@ -76,7 +76,7 @@ public class RegionListener implements Listener {
plugin.debug("Has the player discovered this region? " + has);
plugin.debug("Is this the prioritised region? " + prioritised);
Bukkit.getScheduler().runTask(plugin, () -> this.checkEffects(configuredRegion, player));
plugin.getScheduler().executeOnEntity(player, () -> this.checkEffects(configuredRegion, player));
if (configuredRegion.alwaysShowTitles() && event.hasChanged() && has && prioritised) {
this.sendTitles(player, configuredRegion, false);
@@ -170,10 +170,10 @@ public class RegionListener implements Listener {
plugin.debug("Added to title cooldown");
titleCooldown.add(player.getUniqueId());
Bukkit.getScheduler().runTaskLater(plugin, () -> {
plugin.getScheduler().executeDelayed(() -> {
plugin.debug("Removed from title cooldown");
titleCooldown.remove(player.getUniqueId());
}, plugin.getConfig().getInt("settings.server.discoveries.discovered.title.cooldown"));
}, plugin.getConfig().getLong("settings.server.discoveries.discovered.title.cooldown"));
if (!discovered) {
List<String> discoveredTitle = configuredRegion.getDiscoveredTitle(player);
List<String> discoveredSubtitle = configuredRegion.getDiscoveredSubtitle(player);

View File

@@ -2,7 +2,6 @@ package net.islandearth.rpgregions.managers.data;
import net.islandearth.rpgregions.RPGRegions;
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
import org.bukkit.Bukkit;
import java.util.Map;
import java.util.Optional;
@@ -47,7 +46,7 @@ public class RPGRegionsCache implements IRPGRegionsCache {
public CompletableFuture<Boolean> saveAll(boolean async) {
CompletableFuture<Boolean> future = new CompletableFuture<>();
if (async) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
plugin.getScheduler().executeAsync(() -> {
configuredRegions.forEach((id, region) -> region.save(plugin));
future.complete(true);
});

View File

@@ -1,11 +1,11 @@
package net.islandearth.rpgregions.managers.regeneration;
import net.islandearth.rpgregions.RPGRegions;
import net.islandearth.rpgregions.api.schedule.PlatformScheduler;
import net.islandearth.rpgregions.managers.IRegenerationManager;
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
import net.islandearth.rpgregions.regenerate.Regenerate;
import net.islandearth.rpgregions.tasks.RegenerationTask;
import org.bukkit.Bukkit;
import java.util.ArrayList;
import java.util.List;
@@ -13,7 +13,7 @@ import java.util.List;
public class RegenerationManager implements IRegenerationManager {
private final RPGRegions plugin;
private final List<Integer> tasks;
private final List<PlatformScheduler.RPGRegionsTask> tasks;
public RegenerationManager(RPGRegions plugin) {
this.plugin = plugin;
@@ -22,14 +22,14 @@ public class RegenerationManager implements IRegenerationManager {
@Override
public void reload() {
tasks.forEach(task -> Bukkit.getScheduler().cancelTask(task));
tasks.forEach(PlatformScheduler.RPGRegionsTask::cancel);
tasks.clear();
for (ConfiguredRegion configuredRegion1 : plugin.getManagers().getRegionsCache().getConfiguredRegions().values()) {
if (configuredRegion1.getRegenerate() != null) {
Regenerate regenerate = configuredRegion1.getRegenerate();
if (regenerate.isOnDiscover()) continue;
if (regenerate.getRegenerateInterval() < 5000) plugin.getLogger().warning("Region " + configuredRegion1.getId() + " has a very low regenerate interval! This may lag your server.");
tasks.add(Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new RegenerationTask(plugin, configuredRegion1), 0L, regenerate.getRegenerateInterval()));
tasks.add(plugin.getScheduler().executeRepeating(new RegenerationTask(plugin, configuredRegion1), 0L, regenerate.getRegenerateInterval()));
}
}
}

View File

@@ -0,0 +1,45 @@
package net.islandearth.rpgregions.schedule;
import net.islandearth.rpgregions.RPGRegions;
import net.islandearth.rpgregions.api.schedule.PlatformScheduler;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.scheduler.BukkitTask;
public class BukkitScheduler extends PlatformScheduler<RPGRegions> {
public BukkitScheduler(RPGRegions api) {
super(api);
}
@Override
public void executeOnMain(Runnable runnable) {
Bukkit.getScheduler().runTask(api, runnable);
}
@Override
public void executeOnEntity(Entity entity, Runnable runnable) {
executeOnMain(runnable);
}
@Override
public RPGRegionsTask executeRepeating(Runnable runnable, long delay, long period) {
final BukkitTask task = Bukkit.getScheduler().runTaskTimer(api, runnable, delay, period);
return task::cancel;
}
@Override
public void executeDelayed(Runnable runnable, long delay) {
Bukkit.getScheduler().runTaskLater(api, runnable, delay);
}
@Override
public void executeAsync(Runnable runnable) {
Bukkit.getScheduler().runTaskAsynchronously(api, runnable);
}
@Override
public void registerInitTask(Runnable runnable) {
executeOnMain(runnable);
}
}

View File

@@ -7,4 +7,5 @@ libraries:
softdepend: [Hyperverse, Multiverse, UltraRegions, WorldGuard, PlaceholderAPI, HeadDatabase, Residence, Plan, GriefPrevention, GriefDefender, Vault, MythicMobs, AlonsoLevels, Dynmap, ProtocolLib, Quests, BetonQuest, Lands, MMOCore, CustomStructures]
authors: [SamB440]
description: Discoverable regions
website: https://fortitude.islandearth.net
website: https://fortitude.islandearth.net
folia-supported: true

View File

@@ -1,3 +1,4 @@
include("rpgregions")
include("modern")
include("api")
include("api")
include("folia")