diff --git a/api/build.gradle.kts b/api/build.gradle.kts index f3095d0..4ae8a61 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("maven-publish") + id("buildlogic.java-publish-conventions") } dependencies { @@ -32,31 +32,3 @@ dependencies { exclude("com.google") } } - -java { - withSourcesJar() - withJavadocJar() -} - -publishing { - repositories { - // See Gradle docs for how to provide credentials to PasswordCredentials - // https://docs.gradle.org/current/samples/sample_publishing_credentials.html - maven { - name = "convallyriaSnapshots" - url = uri("https://repo.convallyria.com/snapshots/") - credentials(PasswordCredentials::class) - } - maven { - name = "convallyriaReleases" - url = uri("https://repo.convallyria.com/releases/") - credentials(PasswordCredentials::class) - } - } -} - -configure { - publications.create("maven") { - from(components["java"]) - } -} \ No newline at end of file diff --git a/api/src/main/java/net/islandearth/rpgregions/api/IRPGRegionsAPI.java b/api/src/main/java/net/islandearth/rpgregions/api/IRPGRegionsAPI.java index 09bb54e..e4f12db 100644 --- a/api/src/main/java/net/islandearth/rpgregions/api/IRPGRegionsAPI.java +++ b/api/src/main/java/net/islandearth/rpgregions/api/IRPGRegionsAPI.java @@ -28,7 +28,7 @@ public interface IRPGRegionsAPI { IRPGRegionsManagers getManagers(); boolean debug(); - + void debug(String debug); boolean hasHeadDatabase(); diff --git a/api/src/main/java/net/islandearth/rpgregions/api/events/FaunaDiscoverEvent.java b/api/src/main/java/net/islandearth/rpgregions/api/events/FaunaDiscoverEvent.java index e054f5f..9d49093 100644 --- a/api/src/main/java/net/islandearth/rpgregions/api/events/FaunaDiscoverEvent.java +++ b/api/src/main/java/net/islandearth/rpgregions/api/events/FaunaDiscoverEvent.java @@ -52,4 +52,4 @@ public class FaunaDiscoverEvent extends Event { return HANDLER_LIST; } -} \ No newline at end of file +} diff --git a/api/src/main/java/net/islandearth/rpgregions/api/events/RPGRegionsReloadEvent.java b/api/src/main/java/net/islandearth/rpgregions/api/events/RPGRegionsReloadEvent.java index dfdfc9a..80026ff 100644 --- a/api/src/main/java/net/islandearth/rpgregions/api/events/RPGRegionsReloadEvent.java +++ b/api/src/main/java/net/islandearth/rpgregions/api/events/RPGRegionsReloadEvent.java @@ -16,4 +16,4 @@ public class RPGRegionsReloadEvent extends Event { return HANDLER_LIST; } -} \ No newline at end of file +} diff --git a/api/src/main/java/net/islandearth/rpgregions/api/events/RegionDiscoverEvent.java b/api/src/main/java/net/islandearth/rpgregions/api/events/RegionDiscoverEvent.java index 77f4493..0390272 100644 --- a/api/src/main/java/net/islandearth/rpgregions/api/events/RegionDiscoverEvent.java +++ b/api/src/main/java/net/islandearth/rpgregions/api/events/RegionDiscoverEvent.java @@ -14,7 +14,7 @@ public class RegionDiscoverEvent extends Event { private final RPGRegionsAccount account; private final ConfiguredRegion region; private final Discovery discovery; - + public RegionDiscoverEvent(Player player, RPGRegionsAccount account, ConfiguredRegion region, Discovery discovery) { this.player = player; this.account = account; @@ -63,4 +63,4 @@ public class RegionDiscoverEvent extends Event { return HANDLER_LIST; } -} \ No newline at end of file +} diff --git a/api/src/main/java/net/islandearth/rpgregions/api/events/RegionsEnterEvent.java b/api/src/main/java/net/islandearth/rpgregions/api/events/RegionsEnterEvent.java index 08b18b4..74474b3 100644 --- a/api/src/main/java/net/islandearth/rpgregions/api/events/RegionsEnterEvent.java +++ b/api/src/main/java/net/islandearth/rpgregions/api/events/RegionsEnterEvent.java @@ -63,4 +63,4 @@ public class RegionsEnterEvent extends Event { public static HandlerList getHandlerList() { return HANDLER_LIST; } -} \ No newline at end of file +} diff --git a/api/src/main/java/net/islandearth/rpgregions/api/integrations/IntegrationManager.java b/api/src/main/java/net/islandearth/rpgregions/api/integrations/IntegrationManager.java index 7e7da27..6ff3029 100644 --- a/api/src/main/java/net/islandearth/rpgregions/api/integrations/IntegrationManager.java +++ b/api/src/main/java/net/islandearth/rpgregions/api/integrations/IntegrationManager.java @@ -101,6 +101,5 @@ public interface IntegrationManager { return true; } - @NotNull - List getBoundingBoxPoints(@NotNull ConfiguredRegion region); + @NotNull List getBoundingBoxPoints(@NotNull ConfiguredRegion region); } diff --git a/api/src/main/java/net/islandearth/rpgregions/editor/ClassEditor.java b/api/src/main/java/net/islandearth/rpgregions/editor/ClassEditor.java index c20c6b7..8c1c3eb 100644 --- a/api/src/main/java/net/islandearth/rpgregions/editor/ClassEditor.java +++ b/api/src/main/java/net/islandearth/rpgregions/editor/ClassEditor.java @@ -13,7 +13,7 @@ import java.util.List; */ @Deprecated public class ClassEditor { - + private final List editable = new ArrayList<>(); public ClassEditor(ConfiguredRegion clazz) { diff --git a/api/src/main/java/net/islandearth/rpgregions/effects/RegionEffect.java b/api/src/main/java/net/islandearth/rpgregions/effects/RegionEffect.java index 8a6582d..c0ee19b 100644 --- a/api/src/main/java/net/islandearth/rpgregions/effects/RegionEffect.java +++ b/api/src/main/java/net/islandearth/rpgregions/effects/RegionEffect.java @@ -10,7 +10,7 @@ import java.util.ArrayList; import java.util.List; public abstract class RegionEffect implements IGuiEditable { - + private final boolean wearingRequired; private final List ignoreItems; private final boolean ignorePerm; @@ -41,8 +41,7 @@ public abstract class RegionEffect implements IGuiEditable { * Gets the required Minecraft version for this effect to function. * @return minecraft version */ - @Nullable - public String getRequiredVersion() { + @Nullable public String getRequiredVersion() { return null; } @@ -70,7 +69,7 @@ public abstract class RegionEffect implements IGuiEditable { public boolean shouldIgnore(ItemStack item) { return ignoreItems.contains(item); } - + /** * Gets the permission for this effect to apply. * @return permission the player requires @@ -78,7 +77,7 @@ public abstract class RegionEffect implements IGuiEditable { public String getPermission() { return "rpgregions.effect." + getName(); } - + /** * Whether the permission should be ignored or not. * @return true if permission is ignored diff --git a/api/src/main/java/net/islandearth/rpgregions/managers/data/account/RPGRegionsAccount.java b/api/src/main/java/net/islandearth/rpgregions/managers/data/account/RPGRegionsAccount.java index 6bed022..3f37646 100644 --- a/api/src/main/java/net/islandearth/rpgregions/managers/data/account/RPGRegionsAccount.java +++ b/api/src/main/java/net/islandearth/rpgregions/managers/data/account/RPGRegionsAccount.java @@ -77,4 +77,4 @@ public class RPGRegionsAccount { ICON_COMMAND, TELEPORT } -} \ No newline at end of file +} diff --git a/api/src/main/java/net/islandearth/rpgregions/managers/data/region/ConfiguredRegion.java b/api/src/main/java/net/islandearth/rpgregions/managers/data/region/ConfiguredRegion.java index 985d889..30f067e 100644 --- a/api/src/main/java/net/islandearth/rpgregions/managers/data/region/ConfiguredRegion.java +++ b/api/src/main/java/net/islandearth/rpgregions/managers/data/region/ConfiguredRegion.java @@ -148,8 +148,7 @@ public class ConfiguredRegion { this.sound = sound; } - @Nullable - public ItemStack getIcon() { + @Nullable public ItemStack getIcon() { if (icon == null) return new ItemStack(Material.TOTEM_OF_UNDYING); if (icon.startsWith("hdb-") && RPGRegionsAPI.getAPI().hasHeadDatabase()) return new ItemStackBuilder(new HeadDatabaseAPI().getItemHead(icon.replace("hdb-", ""))).withModel(iconModel).build(); return new ItemStackBuilder(Material.valueOf(icon)).withModel(iconModel).build(); @@ -167,8 +166,7 @@ public class ConfiguredRegion { this.iconModel = iconModel; } - @Nullable - public ItemStack getUndiscoveredIcon() { + @Nullable public ItemStack getUndiscoveredIcon() { if (undiscoveredIcon == null) return new ItemStack(Material.TOTEM_OF_UNDYING); if (undiscoveredIcon.startsWith("hdb-") && RPGRegionsAPI.getAPI().hasHeadDatabase()) return new ItemStackBuilder(new HeadDatabaseAPI().getItemHead(undiscoveredIcon.replace("hdb-", ""))).withModel(undiscoveredIconModel).build(); return new ItemStackBuilder(Material.valueOf(undiscoveredIcon)).withModel(undiscoveredIconModel).build(); @@ -186,8 +184,7 @@ public class ConfiguredRegion { this.undiscoveredIconModel = undiscoveredIconModel; } - @NotNull - public List getIconCommand() { + @NotNull public List getIconCommand() { return iconCommand == null ? new ArrayList<>() : iconCommand; } @@ -207,8 +204,7 @@ public class ConfiguredRegion { this.showCoords = showCoords; } - @Nullable - public List getHints() { + @Nullable public List getHints() { return hints; } @@ -228,8 +224,7 @@ public class ConfiguredRegion { this.teleportable = teleportable; } - @Nullable - public World getWorld() { + @Nullable public World getWorld() { return Bukkit.getWorld(world); } @@ -254,18 +249,15 @@ public class ConfiguredRegion { this.hidden = hidden; } - @Nullable - public List getEffects() { + @Nullable public List getEffects() { return effects; } - @Nullable - public List getRequirements() { + @Nullable public List getRequirements() { return requirements; } - @Nullable - public List getDiscoveredLore() { + @Nullable public List getDiscoveredLore() { return discoveredLore; } @@ -278,8 +270,7 @@ public class ConfiguredRegion { * @param player the player * @return A string list of title */ - @NotNull - public List getTitle(Player player) { + @NotNull public List getTitle(Player player) { if (title == null) { return Translations.DISCOVERED_TITLE.get(player, customName); } @@ -294,8 +285,7 @@ public class ConfiguredRegion { * @param player the player * @return A string list of subtitles */ - @NotNull - public List getSubtitle(Player player) { + @NotNull public List getSubtitle(Player player) { if (subtitle == null) { return Translations.DISCOVERED_SUBTITLE.get(player, customName); } @@ -310,8 +300,7 @@ public class ConfiguredRegion { * @param player the player * @return A string list of title */ - @NotNull - public List getDiscoveredTitle(Player player) { + @NotNull public List getDiscoveredTitle(Player player) { if (discoveredTitle == null) { return Translations.ALREADY_DISCOVERED_TITLE.get(player, customName); } @@ -326,8 +315,7 @@ public class ConfiguredRegion { * @param player the player * @return A string list of subtitles */ - @NotNull - public List getDiscoveredSubtitle(Player player) { + @NotNull public List getDiscoveredSubtitle(Player player) { if (discoveredSubtitle == null) { return Translations.ALREADY_DISCOVERED_SUBTITLE.get(player, customName); } @@ -337,8 +325,7 @@ public class ConfiguredRegion { return translatedSubtitle; } - @Nullable - public Regenerate getRegenerate() { + @Nullable public Regenerate getRegenerate() { return regenerate; } @@ -381,8 +368,7 @@ public class ConfiguredRegion { this.showActionbar = showActionbar; } - @Nullable - public List getBoundingBox() { + @Nullable public List getBoundingBox() { return RPGRegionsAPI.getAPI().getManagers().getIntegrationManager().getBoundingBoxPoints(this); } @@ -474,8 +460,7 @@ public class ConfiguredRegion { return false; } - @Nullable - private File findFile(IRPGRegionsAPI plugin) throws IOException { + @Nullable private File findFile(IRPGRegionsAPI plugin) throws IOException { File folder = new File(plugin.getDataFolder() + "/regions/"); Stream files = Files.walk(Paths.get(folder.getPath())); List valid = files.filter(path -> Files.isRegularFile(path) && path.toFile().getName().equals(this.id + ".json")).toList(); diff --git a/api/src/main/java/net/islandearth/rpgregions/managers/data/region/WorldDiscovery.java b/api/src/main/java/net/islandearth/rpgregions/managers/data/region/WorldDiscovery.java index 8b9c246..d28d933 100644 --- a/api/src/main/java/net/islandearth/rpgregions/managers/data/region/WorldDiscovery.java +++ b/api/src/main/java/net/islandearth/rpgregions/managers/data/region/WorldDiscovery.java @@ -1,6 +1,5 @@ package net.islandearth.rpgregions.managers.data.region; -import java.time.LocalDate; import java.time.LocalDateTime; public record WorldDiscovery(LocalDateTime date, String region) implements Discovery { diff --git a/api/src/main/java/net/islandearth/rpgregions/managers/registry/IRPGRegionsRegistry.java b/api/src/main/java/net/islandearth/rpgregions/managers/registry/IRPGRegionsRegistry.java index 6e972c3..07ed785 100644 --- a/api/src/main/java/net/islandearth/rpgregions/managers/registry/IRPGRegionsRegistry.java +++ b/api/src/main/java/net/islandearth/rpgregions/managers/registry/IRPGRegionsRegistry.java @@ -10,8 +10,7 @@ import java.util.List; public interface IRPGRegionsRegistry { - @NotNull - ImmutableMap> get(); + @NotNull ImmutableMap> get(); /** * Attempts to register a class. @@ -20,11 +19,9 @@ public interface IRPGRegionsRegistry { */ void register(Class clazz); - @Nullable - T getNew(String name, IRPGRegionsAPI plugin, Object... data); + @Nullable T getNew(String name, IRPGRegionsAPI plugin, Object... data); - @Nullable - T getNew(Class clazz, IRPGRegionsAPI plugin, Object... data); + @Nullable T getNew(Class clazz, IRPGRegionsAPI plugin, Object... data); String getRegistryName(); diff --git a/api/src/main/java/net/islandearth/rpgregions/managers/registry/RPGRegionsRegistry.java b/api/src/main/java/net/islandearth/rpgregions/managers/registry/RPGRegionsRegistry.java index 3f5cbb4..3b8f5eb 100644 --- a/api/src/main/java/net/islandearth/rpgregions/managers/registry/RPGRegionsRegistry.java +++ b/api/src/main/java/net/islandearth/rpgregions/managers/registry/RPGRegionsRegistry.java @@ -18,13 +18,11 @@ public abstract class RPGRegionsRegistry implements IRPGRegionsRegistry { this.registeredClasses = new ConcurrentHashMap<>(); } - @NotNull - protected Map> getRegisteredClasses() { + @NotNull protected Map> getRegisteredClasses() { return registeredClasses; } - @NotNull - @Override + @NotNull @Override public ImmutableMap> get() { return ImmutableMap.copyOf(registeredClasses); } @@ -36,14 +34,12 @@ public abstract class RPGRegionsRegistry implements IRPGRegionsRegistry { registeredClasses.put(clazz.getSimpleName(), clazz); } - @Nullable - @Override + @Nullable @Override public T getNew(String name, IRPGRegionsAPI plugin, Object... data) { return getNew(registeredClasses.get(name), plugin, data); } - @Nullable - @Override + @Nullable @Override public abstract T getNew(Class clazz, IRPGRegionsAPI plugin, Object... data); @Override diff --git a/api/src/main/java/net/islandearth/rpgregions/requirements/DependencyRequirement.java b/api/src/main/java/net/islandearth/rpgregions/requirements/DependencyRequirement.java index 90180d5..adb26b3 100644 --- a/api/src/main/java/net/islandearth/rpgregions/requirements/DependencyRequirement.java +++ b/api/src/main/java/net/islandearth/rpgregions/requirements/DependencyRequirement.java @@ -24,7 +24,7 @@ public class DependencyRequirement extends RegionRequirement { super(api); this.requiredRegions = requiredRegions; } - + /** * Returns an immutable list of required regions by their ID. * @return immutable list of required regions @@ -32,22 +32,22 @@ public class DependencyRequirement extends RegionRequirement { public ImmutableList getRequiredRegions() { return ImmutableList.copyOf(requiredRegions); } - + public boolean meetsRequirements(List discoveries) { return new HashSet<>(discoveries).containsAll(requiredRegions); } - + @Override @Deprecated public boolean meetsRequirements(Player player) { return meetsRequirements(Collections.emptyList()); } - + @Override public String getName() { return "Dependency"; } - + @Override public String getText(Player player) { List convertedIds = new ArrayList<>(); diff --git a/api/src/main/java/net/islandearth/rpgregions/requirements/RegionRequirement.java b/api/src/main/java/net/islandearth/rpgregions/requirements/RegionRequirement.java index 57e4fa8..50977e3 100644 --- a/api/src/main/java/net/islandearth/rpgregions/requirements/RegionRequirement.java +++ b/api/src/main/java/net/islandearth/rpgregions/requirements/RegionRequirement.java @@ -57,8 +57,7 @@ public abstract class RegionRequirement implements IGuiEditable, ICustomGuiFeedb return null; } - @Nullable - public String getPreventMessage() { + @Nullable public String getPreventMessage() { return preventMessage; } diff --git a/api/src/main/java/net/islandearth/rpgregions/translation/Translations.java b/api/src/main/java/net/islandearth/rpgregions/translation/Translations.java index b885a4a..410e822 100644 --- a/api/src/main/java/net/islandearth/rpgregions/translation/Translations.java +++ b/api/src/main/java/net/islandearth/rpgregions/translation/Translations.java @@ -93,11 +93,14 @@ public enum Translations { File lang = new File(plugin.getDataFolder() + "/lang/"); lang.mkdirs(); + int validLanguages = 0; for (Language language : Language.values()) { final LanguageKey languageKey = language.getKey(); + try { plugin.saveResource("lang/" + languageKey.getCode() + ".yml", false); - plugin.getLogger().info("Generated " + languageKey.getCode() + ".yml"); + validLanguages++; + } catch (IllegalArgumentException ignored) { } File file = new File(plugin.getDataFolder() + "/lang/" + languageKey.getCode() + ".yml"); @@ -106,15 +109,17 @@ public enum Translations { for (Translations key : values()) { if (config.get(key.toString().toLowerCase()) == null) { plugin.getLogger().warning("No value in translation file for key " - + key + " was found. Please regenerate or edit your language files with new values!"); + + key + " was found. Please regenerate or edit your language files with new values!" + + " Check https://fortitude.islandearth.net/rpgregions/configuration/#default-language-file-en_gb for defaults."); } } } } + + plugin.getLogger().info("Generated " + validLanguages + " valid language(s)."); } - @NotNull - private String setPapi(Player player, String message) { + @NotNull private String setPapi(Player player, String message) { if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { return PlaceholderAPI.setPlaceholders(player, message); } diff --git a/api/src/main/java/net/islandearth/rpgregions/utils/ItemStackBuilder.java b/api/src/main/java/net/islandearth/rpgregions/utils/ItemStackBuilder.java index c5f1343..6fd216b 100644 --- a/api/src/main/java/net/islandearth/rpgregions/utils/ItemStackBuilder.java +++ b/api/src/main/java/net/islandearth/rpgregions/utils/ItemStackBuilder.java @@ -1,7 +1,7 @@ package net.islandearth.rpgregions.utils; +import net.kyori.adventure.platform.bukkit.BukkitComponentSerializer; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Color; @@ -48,7 +48,7 @@ public class ItemStackBuilder { } public ItemStackBuilder withName(Component name) { - return withName(LegacyComponentSerializer.legacyAmpersand().serialize(name)); + return withName(BukkitComponentSerializer.legacy().serialize(name)); } public ItemStackBuilder withLore(String name) { @@ -65,7 +65,7 @@ public class ItemStackBuilder { } public ItemStackBuilder withLore(Component name) { - return withLore(LegacyComponentSerializer.legacyAmpersand().serialize(name)); + return withLore(BukkitComponentSerializer.legacy().serialize(name)); } public ItemStackBuilder withLore(@Nullable List name) { @@ -86,7 +86,7 @@ public class ItemStackBuilder { if (name == null) return this; List legacy = new ArrayList<>(); for (Component component : name) { - legacy.add(ChatColor.translateAlternateColorCodes('&', LegacyComponentSerializer.legacyAmpersand().serialize(component))); + legacy.add(BukkitComponentSerializer.legacy().serialize(component)); } return withLore(legacy); } diff --git a/api/src/main/java/net/islandearth/rpgregions/utils/MessageUtils.java b/api/src/main/java/net/islandearth/rpgregions/utils/MessageUtils.java index a6b7251..03af4e0 100644 --- a/api/src/main/java/net/islandearth/rpgregions/utils/MessageUtils.java +++ b/api/src/main/java/net/islandearth/rpgregions/utils/MessageUtils.java @@ -7,8 +7,7 @@ import org.jetbrains.annotations.NotNull; public class MessageUtils { - @NotNull - public static String replaceVariables(String message, String... values) { + @NotNull public static String replaceVariables(String message, String... values) { String modifiedMessage = message; for (int i = 0; i < 10; i++) { if (values.length > i) modifiedMessage = modifiedMessage.replaceAll("%" + i, values[i]); @@ -18,8 +17,7 @@ public class MessageUtils { return modifiedMessage; } - @NotNull - public static String setPapi(Player player, String message) { + @NotNull public static String setPapi(Player player, String message) { if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { return PlaceholderAPI.setPlaceholders(player, message); } diff --git a/api/src/test/java/net/islandearth/rpgregions/translation/TranslationsTest.java b/api/src/test/java/net/islandearth/rpgregions/translation/TranslationsTest.java index 40442cf..ecb5c59 100644 --- a/api/src/test/java/net/islandearth/rpgregions/translation/TranslationsTest.java +++ b/api/src/test/java/net/islandearth/rpgregions/translation/TranslationsTest.java @@ -13,7 +13,7 @@ import java.util.Set; import java.util.regex.Pattern; public class TranslationsTest { - + @Test public void translationTest() { Reflections reflections = new Reflections("lang/", new ResourcesScanner()); diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts new file mode 100644 index 0000000..2a74932 --- /dev/null +++ b/build-logic/build.gradle.kts @@ -0,0 +1,23 @@ +/* + * This file was generated by the Gradle 'init' task. + * + * This project uses @Incubating APIs which are subject to change. + */ + +plugins { + // Support convention plugins written in Kotlin. Convention plugins are build scripts in 'src/main' that automatically become available as plugins in the main build. + `kotlin-dsl` +} + +repositories { + // Use the plugin portal to apply community plugins in convention plugins. + gradlePluginPortal() + mavenCentral() +} + +dependencies { + implementation("io.github.goooler.shadow:io.github.goooler.shadow.gradle.plugin:8.1.7") + implementation("com.diffplug.spotless:spotless-plugin-gradle:6.25.0") +// implementation("net.kyori:indra-licenser-spotless:3.1.3") + implementation("net.kyori:blossom:2.1.0") +} diff --git a/build-logic/settings.gradle.kts b/build-logic/settings.gradle.kts new file mode 100644 index 0000000..5be38e8 --- /dev/null +++ b/build-logic/settings.gradle.kts @@ -0,0 +1,15 @@ +/* + * This file was generated by the Gradle 'init' task. + * + * This settings file is used to specify which projects to include in your build-logic build. + * This project uses @Incubating APIs which are subject to change. + */ + +dependencyResolutionManagement { + // Reuse version catalog from the main build. + versionCatalogs { + create("libs", { from(files("../gradle/libs.versions.toml")) }) + } +} + +rootProject.name = "build-logic" diff --git a/build-logic/src/main/kotlin/buildlogic.java-common-conventions.gradle.kts b/build-logic/src/main/kotlin/buildlogic.java-common-conventions.gradle.kts new file mode 100644 index 0000000..30815f7 --- /dev/null +++ b/build-logic/src/main/kotlin/buildlogic.java-common-conventions.gradle.kts @@ -0,0 +1,135 @@ +plugins { + // Apply the java Plugin to add support for Java. + java + id("io.github.goooler.shadow") + id("com.diffplug.spotless") +// id("net.kyori.indra.licenser.spotless") +} + +spotless { + java { + toggleOffOn("@formatter:off", "@formatter:on") + trimTrailingWhitespace() + formatAnnotations() + removeUnusedImports() + endWithNewline() + toggleOffOn() + } + + kotlinGradle { + endWithNewline() + indentWithSpaces(4) + trimTrailingWhitespace() + } +} + +repositories { + mavenCentral() + mavenLocal() + + maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") + maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") + maven("https://repo.codemc.io/repository/maven-snapshots/") + maven("https://jitpack.io") + maven("https://repo.convallyria.com/releases") + maven("https://repo.convallyria.com/snapshots") + maven("https://papermc.io/repo/repository/maven-public/") + maven("https://oss.sonatype.org/content/groups/public/") + maven("https://repo.aikar.co/content/groups/aikar/") + + // worldguard + maven("https://maven.enginehub.org/repo/") + + // PAPI + maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") + + // MythicMobs + maven("https://mvn.lumine.io/repository/maven-public/") + + // Dynmap + maven("https://repo.mikeprimm.com") + + // GriefDefender + maven("https://repo.glaremasters.me/repository/bloodshot") + + // Crunch + maven("https://redempt.dev") + + flatDir { dir("../libraries") } +} + +project.group = "net.islandearth.rpgregions" +project.version = "1.4.7-SNAPSHOT" + +group = project.group +version = project.version + +dependencies { + constraints { + // Define dependency versions as constraints + compileOnly("net.kyori:adventure-api:4.17.0") + implementation("net.kyori:adventure-api:4.17.0") + testImplementation("net.kyori:adventure-api:4.17.0") + } + + implementation("com.convallyria.languagy:api:3.0.3-SNAPSHOT") + implementation("com.google.code.gson:gson:2.10.1") + + implementation("net.kyori:adventure-api:4.17.0") + implementation("net.kyori:adventure-text-serializer-plain:4.17.0") + implementation("net.kyori:adventure-platform-bukkit:4.3.3-SNAPSHOT") // IMPLEMENTED VIA LIBRARIES +// implementation("net.kyori:adventure-platform-api:4.3.3-SNAPSHOT") + implementation("net.kyori:adventure-text-minimessage:4.17.0") // IMPLEMENTED VIA LIBRARIES +} + +testing { + suites { + // Configure the built-in test suite + val test by getting(JvmTestSuite::class) { + // Use JUnit Jupiter test framework + useJUnitJupiter("5.10.1") + } + } +} + +// Apply a specific Java toolchain to ease working on different environments. +java { + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } + disableAutoTargetJvm() +} + +tasks { + processResources { + filesMatching("plugin.yml") { + expand("version" to project.version) + } + } + + compileJava { + options.encoding = Charsets.UTF_8.name() + options.release.set(16) + } + + build { + dependsOn(shadowJar) + } + + shadowJar { + archiveBaseName.set("rpgregions-2-${project.name}") + archiveClassifier.set("") + relocate("net.kyori", "rpgregions-libs.adventure") + relocate("com.google.gson", "rpgregions-libs.gson") + relocate("org.incendo.cloud", "rpgregions-libs.commandframework") + relocate("io.leangen.geantyref", "rpgregions-libs.typetoken") + relocate("com.convallyria.languagy", "rpgregions-libs.languagy") + relocate("io.papermc.lib", "rpgregions-libs.paperlib") + relocate("redempt.crunch", "rpgregions-libs.crunch") + relocate("co.aikar.idb", "rpgregions-libs.idb") + relocate("com.github.stefvanschie.inventoryframework", "rpgregions-libs.inventoryframework") + relocate("org.bstats", "rpgregions-libs.bstats") + relocate("me.lucko.helper", "rpgregions-libs.helper") + relocate("net.wesjd", "rpgregions-libs.anvilgui") + } +} \ No newline at end of file diff --git a/build-logic/src/main/kotlin/buildlogic.java-library-conventions.gradle.kts b/build-logic/src/main/kotlin/buildlogic.java-library-conventions.gradle.kts new file mode 100644 index 0000000..daf53e7 --- /dev/null +++ b/build-logic/src/main/kotlin/buildlogic.java-library-conventions.gradle.kts @@ -0,0 +1,13 @@ +/* + * This file was generated by the Gradle 'init' task. + * + * This project uses @Incubating APIs which are subject to change. + */ + +plugins { + // Apply the common convention plugin for shared build configuration between library and application projects. + id("buildlogic.java-common-conventions") + + // Apply the java-library plugin for API and implementation separation. + `java-library` +} diff --git a/build-logic/src/main/kotlin/buildlogic.java-publish-conventions.gradle.kts b/build-logic/src/main/kotlin/buildlogic.java-publish-conventions.gradle.kts new file mode 100644 index 0000000..eb4a2e2 --- /dev/null +++ b/build-logic/src/main/kotlin/buildlogic.java-publish-conventions.gradle.kts @@ -0,0 +1,52 @@ +/* + * This file was generated by the Gradle 'init' task. + * + * This project uses @Incubating APIs which are subject to change. + */ + +plugins { + // Apply the common convention plugin for shared build configuration between library and application projects. + id("buildlogic.java-library-conventions") + `maven-publish` +} + +java { + withSourcesJar() + withJavadocJar() +} + +publishing { + publications { + create("maven") { + groupId = "net.islandearth.rpgregions" + artifactId = project.name + version = project.version.toString() + from(components["java"]) + + // skip shadow jar from publishing. Workaround for https://github.com/johnrengelman/shadow/issues/651 + val javaComponent = components["java"] as AdhocComponentWithVariants + javaComponent.withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) { skip() } + } + } + + repositories { + // See Gradle docs for how to provide credentials to PasswordCredentials + // https://docs.gradle.org/current/samples/sample_publishing_credentials.html + maven { + val snapshotUrl = "https://repo.convallyria.com/snapshots/" + val releaseUrl = "https://repo.convallyria.com/releases/" + + // Check which URL should be used + url = if (project.version.toString().endsWith("SNAPSHOT")) { + uri(snapshotUrl) + } else { + uri(releaseUrl) + } + + name = "convallyria" + credentials { + credentials(PasswordCredentials::class) + } + } + } +} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts deleted file mode 100644 index a187e69..0000000 --- a/build.gradle.kts +++ /dev/null @@ -1,122 +0,0 @@ -plugins { - id("com.github.johnrengelman.shadow") version("8.1.1") - id("java") -} - -dependencies { - testImplementation("junit:junit:4.13.2") - implementation(project(":rpgregions", "shadow")) - implementation(project(":modern", "shadow")) -} - -allprojects { - group = "net.islandearth.rpgregions" - version = "1.4.6" - - //tasks.withType(JavaCompile).configureEach { - // ensure that the encoding is set to UTF-8, no matter what the system default is - // this fixes some edge cases with special characters not displaying correctly - // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html - // If Javadoc is generated, this must be specified in that task too. - //it.options.encoding = "UTF-8" - - // Force warnings - //options.compilerArgs << '-Xlint:all' - //options.deprecation = true - //} - - apply(plugin = "com.github.johnrengelman.shadow") - apply(plugin = "java") - - java { - toolchain.languageVersion.set(JavaLanguageVersion.of(17)) - disableAutoTargetJvm() - } - - repositories { - mavenCentral() - mavenLocal() - - maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") - maven("https://repo.codemc.io/repository/maven-snapshots/") - maven("https://jitpack.io") - maven("https://repo.convallyria.com/releases") - maven("https://repo.convallyria.com/snapshots") - maven("https://papermc.io/repo/repository/maven-public/") - maven("https://oss.sonatype.org/content/groups/public/") - maven("https://repo.aikar.co/content/groups/aikar/") - - // worldguard - maven("https://maven.enginehub.org/repo/") - - // PAPI - maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") - - // MythicMobs - maven("https://mvn.lumine.io/repository/maven-public/") - - // Dynmap - maven("https://repo.mikeprimm.com") - - // GriefDefender - maven("https://repo.glaremasters.me/repository/bloodshot") - - // Crunch - maven("https://redempt.dev") - - flatDir { dir("../libraries") } - } - - dependencies { - implementation("com.convallyria.languagy:api:3.0.3-SNAPSHOT") - implementation("com.google.code.gson:gson:2.10.1") - - compileOnly("net.kyori:adventure-api:4.14.0") - compileOnly("net.kyori:adventure-platform-bukkit:4.3.2") // IMPLEMENTED VIA LIBRARIES - compileOnly("net.kyori:adventure-text-minimessage:4.14.0") // IMPLEMENTED VIA LIBRARIES - } - - tasks { - test { - useJUnitPlatform() - - testLogging { - events("passed", "skipped", "failed") - } - } - - shadowJar { - archiveClassifier.set("") - - relocate("com.google.gson", "net.islandearth.rpgregions.libs.gson") - relocate("cloud.commandframework", "net.islandearth.rpgregions.libs.commandframework") - relocate("io.leangen.geantyref", "net.islandearth.rpgregions.libs.typetoken") - relocate("com.convallyria.languagy", "net.islandearth.rpgregions.libs.languagy") - relocate("io.papermc.lib", "net.islandearth.rpgregions.libs.paperlib") - relocate("redempt.crunch", "net.islandearth.rpgregions.libs.crunch") - 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") - relocate("me.lucko.helper", "net.islandearth.rpgregions.libs.helper") - relocate("net.wesjd", "net.islandearth.rpgregions.libs.anvilgui") - } - - build { - dependsOn(shadowJar) - } - - compileJava { - options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything - - // 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) - } - } - } -} \ No newline at end of file diff --git a/folia/build.gradle.kts b/folia/build.gradle.kts index f4c5423..638b155 100644 --- a/folia/build.gradle.kts +++ b/folia/build.gradle.kts @@ -1,12 +1,9 @@ -java { - disableAutoTargetJvm() +plugins { + id("buildlogic.java-common-conventions") } -repositories { - maven { - name = "papermc" - url = uri("https://repo.papermc.io/repository/maven-public/") - } +java { + disableAutoTargetJvm() } dependencies { diff --git a/gradle.properties b/gradle.properties index 342c6e7..2aaab9f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,11 +1,11 @@ pluginGroup=net.islandearth -pluginVersion=1.4.5 +pluginVersion=1.4.7 # 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 -spigot_version = 1.20.4-R0.1-SNAPSHOT +spigot_version = 1.20.6-R0.1-SNAPSHOT folia_version = 1.20.4-R0.1-SNAPSHOT worldguard_version = 7.0.9 worldedit_version = 7.2.18-SNAPSHOT -cloud_version = 1.8.3 +cloud_version = 2.0.0-beta.7 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..4ac3234 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,2 @@ +# This file was generated by the Gradle 'init' task. +# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index c1962a7..e644113 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 37aef8d..b82aa23 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index aeb74cb..1aa94a4 100644 --- a/gradlew +++ b/gradlew @@ -83,7 +83,8 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -130,10 +131,13 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. @@ -141,7 +145,7 @@ 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 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -149,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -198,11 +202,11 @@ fi # 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"' -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/gradlew.bat b/gradlew.bat index 93e3f59..25da30d 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/license_header.txt b/license_header.txt new file mode 100644 index 0000000..f592b3c --- /dev/null +++ b/license_header.txt @@ -0,0 +1,17 @@ +This file is part of RPGRegions, licensed under the GNU GPL v3 License. + +Copyright (C) $YEAR Convallyria +Copyright (C) contributors + +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 +(at your option) 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 . \ No newline at end of file diff --git a/modern/build.gradle.kts b/modern/build.gradle.kts index ce88f64..991db20 100644 --- a/modern/build.gradle.kts +++ b/modern/build.gradle.kts @@ -1,3 +1,7 @@ +plugins { + id("buildlogic.java-common-conventions") +} + val ultraRegionsSupport = (properties.getValue("ultraRegionsSupport") as String).toBoolean() tasks.compileJava { @@ -8,9 +12,6 @@ tasks.compileJava { dependencies { implementation(project(":api")) - implementation(project(":rpgregions")) - - testImplementation("junit:junit:4.13.2") compileOnly("org.spigotmc:spigot-api:${properties["spigot_version"]}") compileOnly("com.sk89q.worldguard:worldguard-bukkit:${properties["worldguard_version"]}") { @@ -23,4 +24,4 @@ dependencies { compileOnly("com.griefdefender:api:2.1.0-SNAPSHOT") // GriefDefender if (ultraRegionsSupport) compileOnly(":UltraRegions") // ultraregions compileOnly("org.empirewar.orbis:paper-api:1.0.0-SNAPSHOT") -} \ No newline at end of file +} diff --git a/modern/src/main/java/net/islandearth/rpgregions/api/integrations/orbis/OrbisIntegration.java b/modern/src/main/java/net/islandearth/rpgregions/api/integrations/orbis/OrbisIntegration.java index e8e131f..961d28e 100644 --- a/modern/src/main/java/net/islandearth/rpgregions/api/integrations/orbis/OrbisIntegration.java +++ b/modern/src/main/java/net/islandearth/rpgregions/api/integrations/orbis/OrbisIntegration.java @@ -4,6 +4,7 @@ import net.islandearth.rpgregions.api.IRPGRegionsAPI; import net.islandearth.rpgregions.api.events.RegionsEnterEvent; import net.islandearth.rpgregions.api.integrations.IntegrationManager; import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion; +import net.kyori.adventure.key.Key; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; @@ -15,7 +16,7 @@ import org.empirewar.orbis.query.RegionQuery; import org.empirewar.orbis.region.Region; import org.empirewar.orbis.world.RegionisedWorld; import org.jetbrains.annotations.NotNull; -import org.joml.Vector3i; +import org.joml.Vector3ic; import java.util.ArrayList; import java.util.List; @@ -91,32 +92,35 @@ public class OrbisIntegration implements IntegrationManager { @Override public boolean exists(World world, String region) { - final RegionisedWorld regionisedWorld = OrbisAPI.get().getRegionisedWorld(world.getUID()); + final RegionisedWorld regionisedWorld = OrbisAPI.get().getRegionisedWorld(worldToKey(world)); return regionisedWorld.getByName(region).isPresent(); } @Override public Set getAllRegionNames(World world) { - final RegionisedWorld regionisedWorld = OrbisAPI.get().getRegionisedWorld(world.getUID()); + final RegionisedWorld regionisedWorld = OrbisAPI.get().getRegionisedWorld(worldToKey(world)); return regionisedWorld.regions().stream().map(Region::name).collect(Collectors.toSet()); } @Override - @NonNull - public List getBoundingBoxPoints(@NotNull ConfiguredRegion region) { + @NonNull public List getBoundingBoxPoints(@NotNull ConfiguredRegion region) { List points = new ArrayList<>(); - final RegionisedWorld world = OrbisAPI.get().getRegionisedWorld(region.getWorld().getUID()); + final RegionisedWorld world = OrbisAPI.get().getRegionisedWorld(worldToKey(region.getWorld())); final Region protectedRegion = world.getByName(region.getId()).orElseThrow(); - for (Vector3i point : protectedRegion.area().points()) { + for (Vector3ic point : protectedRegion.area().points()) { points.add(new Location(region.getWorld(), point.x(), region.getLocation().getY(), point.z())); } return points; } private Set getRegions(Location location) { - final RegionisedWorld world = OrbisAPI.get().getRegionisedWorld(location.getWorld().getUID()); + final RegionisedWorld world = OrbisAPI.get().getRegionisedWorld(worldToKey(location.getWorld())); return world.query(RegionQuery.Position.builder() .position(location.getX(), location.getY(), location.getZ()).build()) .result(); } + + private Key worldToKey(World world) { + return Key.key(world.getKey().toString()); + } } diff --git a/modern/src/main/java/net/islandearth/rpgregions/api/integrations/worldguard/WorldGuardIntegration.java b/modern/src/main/java/net/islandearth/rpgregions/api/integrations/worldguard/WorldGuardIntegration.java index 7c6670d..d29130c 100644 --- a/modern/src/main/java/net/islandearth/rpgregions/api/integrations/worldguard/WorldGuardIntegration.java +++ b/modern/src/main/java/net/islandearth/rpgregions/api/integrations/worldguard/WorldGuardIntegration.java @@ -107,8 +107,7 @@ public class WorldGuardIntegration implements IntegrationManager { } @Override - @NonNull - public List getBoundingBoxPoints(@NotNull ConfiguredRegion region) { + @NonNull public List getBoundingBoxPoints(@NotNull ConfiguredRegion region) { List points = new ArrayList<>(); final Map regions = WorldGuard.getInstance() .getPlatform() diff --git a/rpgregions/build.gradle.kts b/rpgregions/build.gradle.kts index 524fea4..d1bb4a4 100644 --- a/rpgregions/build.gradle.kts +++ b/rpgregions/build.gradle.kts @@ -1,3 +1,7 @@ +plugins { + id("buildlogic.java-common-conventions") +} + repositories { maven("https://nexus.betonquest.org/repository/betonquest/") maven("https://repo.codemc.io/repository/maven-public/") @@ -7,23 +11,28 @@ repositories { dependencies { implementation(project(":api")) implementation(project(":folia")) + implementation(project(":modern")) - testImplementation("junit:junit:4.13.2") testImplementation("com.github.seeseemelk:MockBukkit-v1.20:3.9.0") testImplementation("org.reflections:reflections:0.10.2") - implementation("cloud.commandframework:cloud-paper:${properties["cloud_version"]}") { + implementation("org.incendo:cloud-paper:${properties["cloud_version"]}") { + exclude("org.checkerframework") + exclude("net.kyori") + } + implementation("org.incendo:cloud-annotations:2.0.0-rc.1") { exclude("org.checkerframework") } - implementation("cloud.commandframework:cloud-annotations:${properties["cloud_version"]}") { + implementation("org.incendo:cloud-minecraft-extras:${properties["cloud_version"]}") { exclude("org.checkerframework") + exclude("net.kyori") } - implementation("cloud.commandframework:cloud-minecraft-extras:${properties["cloud_version"]}") { + implementation("org.incendo:cloud-processors-confirmation:1.0.0-SNAPSHOT") { exclude("org.checkerframework") exclude("net.kyori") } - implementation("net.wesjd:anvilgui:1.9.3-SNAPSHOT") // anvilgui + implementation("net.wesjd:anvilgui:1.9.4-SNAPSHOT") // anvilgui implementation("com.github.stefvanschie.inventoryframework:IF:0.10.13") // inventory framework implementation("co.aikar:idb-core:1.0.0-SNAPSHOT") // database implementation("org.bstats:bstats-bukkit:3.0.2") // plugin stats @@ -43,8 +52,8 @@ dependencies { exclude("org.bukkit") exclude("org.spigotmc") } - compileOnly("org.flywaydb:flyway-core:9.16.2") // IMPLEMENTED VIA LIBRARIES - db migration - compileOnly("org.flywaydb:flyway-mysql:9.16.3") // IMPLEMENTED VIA LIBRARIES + compileOnly("org.flywaydb:flyway-core:10.12.0") // IMPLEMENTED VIA LIBRARIES - db migration + compileOnly("org.flywaydb:flyway-mysql:10.12.0") // IMPLEMENTED VIA LIBRARIES //compileOnly 'com.zaxxer:HikariCP:2.4.1' // IMPLEMENTED VIA LIBRARIES - database compileOnly("me.clip:placeholderapi:2.11.3") // PAPI compileOnly("com.github.MilkBowl:VaultAPI:1.7") { // vault @@ -90,6 +99,9 @@ tasks { } shadowJar { - minimize() + archiveBaseName.set("rpgregions-2") + minimize { + exclude(project(":modern")) + } } -} \ No newline at end of file +} diff --git a/rpgregions/src/main/java/me/lucko/helper/gson/GsonSerializable.java b/rpgregions/src/main/java/me/lucko/helper/gson/GsonSerializable.java index e8301d3..658c494 100644 --- a/rpgregions/src/main/java/me/lucko/helper/gson/GsonSerializable.java +++ b/rpgregions/src/main/java/me/lucko/helper/gson/GsonSerializable.java @@ -85,8 +85,7 @@ public interface GsonSerializable { * @param clazz the class * @return the deserialization method, if the class has one */ - @Nullable - static Method getDeserializeMethod(@Nonnull Class clazz) { + @Nullable static Method getDeserializeMethod(@Nonnull Class clazz) { if (!GsonSerializable.class.isAssignableFrom(clazz)) { return null; } diff --git a/rpgregions/src/main/java/net/islandearth/rpgregions/RPGRegions.java b/rpgregions/src/main/java/net/islandearth/rpgregions/RPGRegions.java index 6b6b4a1..a7585b7 100644 --- a/rpgregions/src/main/java/net/islandearth/rpgregions/RPGRegions.java +++ b/rpgregions/src/main/java/net/islandearth/rpgregions/RPGRegions.java @@ -77,9 +77,11 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.potion.PotionEffect; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.time.format.DateTimeFormatter; import java.util.concurrent.CompletableFuture; import java.util.logging.Level; @@ -359,6 +361,23 @@ public final class RPGRegions extends JavaPlugin implements IRPGRegionsAPI { this.formatter = null; } + @Override + public void saveResource(@NotNull String resourcePath, boolean replace) { + // Override to avoid "could not save resource" warning if already exists. + if (!resourcePath.isEmpty()) { + resourcePath = resourcePath.replace('\\', '/'); + InputStream in = this.getResource(resourcePath); + if (in == null) { + // Let super error this + super.saveResource(resourcePath, replace); + return; + } + File outFile = new File(this.getDataFolder(), resourcePath); + if (outFile.exists()) return; + } + super.saveResource(resourcePath, replace); + } + @Override public boolean debug() { // This part of the code is called very often, caching the boolean gives a big performance boost at high player counts diff --git a/rpgregions/src/main/java/net/islandearth/rpgregions/api/integrations/hooks/PlaceholderRegionHook.java b/rpgregions/src/main/java/net/islandearth/rpgregions/api/integrations/hooks/PlaceholderRegionHook.java index 8c84ea2..4a01dc9 100644 --- a/rpgregions/src/main/java/net/islandearth/rpgregions/api/integrations/hooks/PlaceholderRegionHook.java +++ b/rpgregions/src/main/java/net/islandearth/rpgregions/api/integrations/hooks/PlaceholderRegionHook.java @@ -7,7 +7,7 @@ import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion; import net.islandearth.rpgregions.thread.Blocking; import net.islandearth.rpgregions.translation.Translations; import net.islandearth.rpgregions.utils.TimeEntry; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import net.kyori.adventure.platform.bukkit.BukkitComponentSerializer; import org.bukkit.entity.Player; import java.util.Optional; @@ -70,7 +70,7 @@ public class PlaceholderRegionHook extends PlaceholderExpansion implements Block if (plugin.getManagers().getIntegrationManager().getPrioritisedRegion(player.getLocation()).isPresent()) return plugin.getManagers().getIntegrationManager().getPrioritisedRegion(player.getLocation()).get().getCustomName(); else - return LegacyComponentSerializer.legacyAmpersand().serialize(Translations.UNKNOWN_REGION.get(player).get(0)); + return BukkitComponentSerializer.legacy().serialize(Translations.UNKNOWN_REGION.get(player).get(0)); case "discovered_count": // We have to do a blocking operation :( try { @@ -93,7 +93,7 @@ public class PlaceholderRegionHook extends PlaceholderExpansion implements Block case "region_timed": { final Optional region = plugin.getManagers().getIntegrationManager().getPrioritisedRegion(player.getLocation()); if (region.isEmpty()) { - return LegacyComponentSerializer.legacyAmpersand().serialize(Translations.UNKNOWN_REGION.get(player).get(0)); + return BukkitComponentSerializer.legacy().serialize(Translations.UNKNOWN_REGION.get(player).get(0)); } final ConfiguredRegion configuredRegion = region.get(); @@ -113,7 +113,7 @@ public class PlaceholderRegionHook extends PlaceholderExpansion implements Block final double time = TimeUnit.MILLISECONDS.toSeconds((long) (timeEntry.get().getLatestEntry() - entry)); final double secondsInsideToDiscover = configuredRegion.getSecondsInsideToDiscover(); final double percent = (time / secondsInsideToDiscover) * 100; - return LegacyComponentSerializer.legacyAmpersand().serialize(Translations.DISCOVERING_AREA_PLACEHOLDER.get(player, (int) percent, region.get().getId()).get(0)); + return BukkitComponentSerializer.legacy().serialize(Translations.DISCOVERING_AREA_PLACEHOLDER.get(player, (int) percent, region.get().getId()).get(0)); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } diff --git a/rpgregions/src/main/java/net/islandearth/rpgregions/api/integrations/rpgregions/region/CuboidRegion.java b/rpgregions/src/main/java/net/islandearth/rpgregions/api/integrations/rpgregions/region/CuboidRegion.java index f4b9d07..d411bc1 100644 --- a/rpgregions/src/main/java/net/islandearth/rpgregions/api/integrations/rpgregions/region/CuboidRegion.java +++ b/rpgregions/src/main/java/net/islandearth/rpgregions/api/integrations/rpgregions/region/CuboidRegion.java @@ -17,13 +17,11 @@ public class CuboidRegion extends RPGRegionsRegion { super(name, world); } - @Nullable - public Location getFirstCorner() { + @Nullable public Location getFirstCorner() { return getPoints().isEmpty() ? null : getPoints().get(0); } - @Nullable - public Location getSecondCorner() { + @Nullable public Location getSecondCorner() { return getPoints().size() < 2 ? null : getPoints().get(1); } diff --git a/rpgregions/src/main/java/net/islandearth/rpgregions/chat/RPGRegionsConversationPrefix.java b/rpgregions/src/main/java/net/islandearth/rpgregions/chat/RPGRegionsConversationPrefix.java index 4988f8f..d76d6f9 100644 --- a/rpgregions/src/main/java/net/islandearth/rpgregions/chat/RPGRegionsConversationPrefix.java +++ b/rpgregions/src/main/java/net/islandearth/rpgregions/chat/RPGRegionsConversationPrefix.java @@ -7,8 +7,7 @@ import org.jetbrains.annotations.NotNull; public class RPGRegionsConversationPrefix implements ConversationPrefix { - @NotNull - @Override + @NotNull @Override public String getPrefix(@NotNull ConversationContext context) { return ChatColor.GOLD + "RPGRegions > " + ChatColor.AQUA; } diff --git a/rpgregions/src/main/java/net/islandearth/rpgregions/chat/RPGRegionsStringPrompt.java b/rpgregions/src/main/java/net/islandearth/rpgregions/chat/RPGRegionsStringPrompt.java index e2e8c75..419d7d6 100644 --- a/rpgregions/src/main/java/net/islandearth/rpgregions/chat/RPGRegionsStringPrompt.java +++ b/rpgregions/src/main/java/net/islandearth/rpgregions/chat/RPGRegionsStringPrompt.java @@ -14,14 +14,12 @@ public class RPGRegionsStringPrompt extends StringPrompt { this.promptText = promptText; } - @NotNull - @Override + @NotNull @Override public String getPromptText(@NotNull ConversationContext context) { return promptText; } - @Nullable - @Override + @Nullable @Override public Prompt acceptInput(@NotNull ConversationContext context, @Nullable String input) { context.setSessionData("input", input); return Prompt.END_OF_CONVERSATION; diff --git a/rpgregions/src/main/java/net/islandearth/rpgregions/commands/Commands.java b/rpgregions/src/main/java/net/islandearth/rpgregions/commands/Commands.java index 7663615..e12346f 100644 --- a/rpgregions/src/main/java/net/islandearth/rpgregions/commands/Commands.java +++ b/rpgregions/src/main/java/net/islandearth/rpgregions/commands/Commands.java @@ -1,52 +1,54 @@ 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 com.github.benmanes.caffeine.cache.Caffeine; import io.leangen.geantyref.TypeFactory; 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.caption.RPGRegionsCaptionProvider; import net.islandearth.rpgregions.commands.parser.ConfiguredRegionArgument; import net.islandearth.rpgregions.commands.parser.FaunaArgument; import net.islandearth.rpgregions.commands.parser.IntegrationRegionArgument; import net.islandearth.rpgregions.fauna.FaunaInstance; import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion; -import org.bukkit.ChatColor; +import net.islandearth.rpgregions.utils.Colors; +import net.kyori.adventure.audience.Audience; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.incendo.cloud.SenderMapper; +import org.incendo.cloud.annotations.AnnotationParser; +import org.incendo.cloud.bukkit.CloudBukkitCapabilities; +import org.incendo.cloud.execution.ExecutionCoordinator; +import org.incendo.cloud.minecraft.extras.MinecraftExceptionHandler; +import org.incendo.cloud.paper.PaperCommandManager; +import org.incendo.cloud.parser.ParserRegistry; +import org.incendo.cloud.processors.cache.CaffeineCache; +import org.incendo.cloud.processors.confirmation.ConfirmationConfiguration; +import org.incendo.cloud.processors.confirmation.ConfirmationManager; +import org.incendo.cloud.suggestion.Suggestion; import java.io.File; +import java.time.Duration; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.TimeUnit; -import java.util.function.Function; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Stream; + +import static net.kyori.adventure.text.Component.text; public class Commands { - public Commands(RPGRegions plugin) { + private ConfirmationManager confirmationManager; - // This function maps the command sender type of our choice to the bukkit command sender. - final Function mapperFunction = Function.identity(); + public Commands(RPGRegions plugin) { final PaperCommandManager manager; try { manager = new PaperCommandManager<>( plugin, - CommandExecutionCoordinator.simpleCoordinator(), - mapperFunction, - mapperFunction + ExecutionCoordinator.asyncCoordinator(), + SenderMapper.identity() ); } catch (Exception e) { plugin.getLogger().severe("Failed to initialize the command manager"); @@ -54,13 +56,10 @@ public class Commands { return; } - // Register Brigadier mappings + // Register Brigadier mappings or asynchronous completions if (manager.hasCapability(CloudBukkitCapabilities.NATIVE_BRIGADIER)) { manager.registerBrigadier(); - } - - // Register asynchronous completions - if (manager.hasCapability(CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION)) { + } else if (manager.hasCapability(CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION)) { manager.registerAsynchronousCompletions(); } @@ -68,78 +67,82 @@ public class Commands { * Create the confirmation manager. This allows us to require certain commands to be * confirmed before they can be executed */ - final CommandConfirmationManager 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.") + ConfirmationConfiguration confirmationConfig = ConfirmationConfiguration.builder() + .cache(CaffeineCache.of(Caffeine.newBuilder().expireAfterWrite(Duration.ofSeconds(30)).build())) + .noPendingCommandNotifier(sender -> { + final Audience audience = plugin.adventure().sender(sender); + audience.sendMessage(text("You don't have any pending confirmations.", Colors.BRIGHT_RED)); + }) + .confirmationRequiredNotifier((sender, context) -> { + final Audience audience = plugin.adventure().sender(sender); + audience.sendMessage(text("Confirmation required. Confirm using", Colors.BRIGHT_RED).append(text(" /rpgregions confirm", Colors.HONEY_YELLOW).append(text(".", Colors.BRIGHT_RED)))); + }) + .build(); + + confirmationManager = ConfirmationManager.confirmationManager(confirmationConfig); + + // Register the confirmation command. + manager.command( + manager.commandBuilder("rpgregions") + .literal("confirm") + .handler(confirmationManager.createExecutionHandler()) ); // 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 commandMetaFunction = parserParameters -> - CommandMeta.simple() - .with(CommandMeta.DESCRIPTION, parserParameters.get(StandardParameters.DESCRIPTION, "No description")) - .build(); + manager.registerCommandPostProcessor(confirmationManager.createPostprocessor()); // Override the default exception handlers // todo: change some stuff lmao - new MinecraftExceptionHandler() - .withInvalidSyntaxHandler() - .withInvalidSenderHandler() - .withNoPermissionHandler() - .withArgumentParsingHandler() - .apply(manager, player -> plugin.adventure().sender(player)); + MinecraftExceptionHandler.create(sender -> plugin.adventure().sender(sender)) + .defaultInvalidSyntaxHandler() + .defaultInvalidSenderHandler() + .defaultNoPermissionHandler() + .defaultArgumentParsingHandler() + .defaultCommandExecutionHandler() + .registerTo(manager); // Register our custom caption registry so we can define exception messages for parsers - final RPGRegionsCaptionRegistry captionRegistry = new RPGRegionsCaptionRegistryFactory().create(); - manager.captionRegistry(captionRegistry); + manager.captionRegistry().registerProvider(new RPGRegionsCaptionProvider<>()); // Register custom parsers final ParserRegistry parserRegistry = manager.parserRegistry(); - parserRegistry.registerParserSupplier(TypeToken.get(ConfiguredRegion.class), parserParameters -> - new ConfiguredRegionArgument.ConfiguredRegionParser<>()); + parserRegistry.registerParserSupplier(TypeToken.get(ConfiguredRegion.class), parserParameters -> new ConfiguredRegionArgument<>()); parserRegistry.registerParserSupplier(TypeToken.get(TypeFactory.parameterizedClass(FaunaInstance.class, TypeFactory.unboundWildcard())), parserParameters -> - new FaunaArgument.FaunaParser<>()); + new FaunaArgument<>()); parserRegistry.registerParserSupplier(TypeToken.get(RPGRegionsRegion.class), parserParameters -> - new IntegrationRegionArgument.IntegrationRegionParser<>()); + new IntegrationRegionArgument<>()); - parserRegistry.registerSuggestionProvider("region-types", (context, arg) -> ImmutableList.of("Cuboid", "Poly")); + parserRegistry.registerSuggestionProvider("region-types", (context, arg) -> CompletableFuture.completedFuture(Stream.of("Cuboid", "Poly").map(Suggestion::suggestion).toList())); parserRegistry.registerSuggestionProvider("integration-regions", (context, arg) -> { - if (context.getSender() instanceof Player player) { - return ImmutableList.copyOf(plugin.getManagers().getIntegrationManager().getAllRegionNames(player.getWorld())); + if (context.sender() instanceof Player player) { + return CompletableFuture.completedFuture(plugin.getManagers().getIntegrationManager() + .getAllRegionNames(player.getWorld()).stream().map(Suggestion::suggestion).toList()); } - return new ArrayList<>(); + return CompletableFuture.completedFuture(List.of()); }); parserRegistry.registerSuggestionProvider("templates", (context, arg) -> { File templates = new File(plugin.getDataFolder() + File.separator + "templates"); - List files = new ArrayList<>(); + List files = new ArrayList<>(); for (File file : templates.listFiles()) { - files.add(file.getName()); + files.add(Suggestion.suggestion(file.getName())); } - return files; + return CompletableFuture.completedFuture(files); }); parserRegistry.registerSuggestionProvider("schematics", (context, arg) -> { File schematicFolder = new File("plugins/WorldEdit/schematics/"); - List files = new ArrayList<>(); + List files = new ArrayList<>(); for (File file : schematicFolder.listFiles()) { - files.add(file.getName()); + files.add(Suggestion.suggestion(file.getName())); } - return files; + return CompletableFuture.completedFuture(files); }); - parserRegistry.registerSuggestionProvider("async", (context, arg) -> List.of("--async")); + parserRegistry.registerSuggestionProvider("async", (context, arg) -> CompletableFuture.completedFuture(List.of(Suggestion.suggestion("--async")))); - final AnnotationParser annotationParser = new AnnotationParser<>(manager, CommandSender.class, commandMetaFunction); + final AnnotationParser annotationParser = new AnnotationParser<>(manager, CommandSender.class); annotationParser.parse(new DiscoveriesCommand(plugin)); annotationParser.parse(new RPGRegionsCommand(plugin, manager)); annotationParser.parse(new RPGRegionsDebugCommand(plugin)); diff --git a/rpgregions/src/main/java/net/islandearth/rpgregions/commands/DiscoveriesCommand.java b/rpgregions/src/main/java/net/islandearth/rpgregions/commands/DiscoveriesCommand.java index 3648f0e..8608c57 100644 --- a/rpgregions/src/main/java/net/islandearth/rpgregions/commands/DiscoveriesCommand.java +++ b/rpgregions/src/main/java/net/islandearth/rpgregions/commands/DiscoveriesCommand.java @@ -1,9 +1,5 @@ package net.islandearth.rpgregions.commands; -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.IRPGRegionsAPI; import net.islandearth.rpgregions.api.RPGRegionsAPI; @@ -30,6 +26,10 @@ import org.bukkit.OfflinePlayer; import org.bukkit.Sound; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.incendo.cloud.annotations.Argument; +import org.incendo.cloud.annotations.Command; +import org.incendo.cloud.annotations.CommandDescription; +import org.incendo.cloud.annotations.Permission; import java.time.LocalDateTime; import java.util.ArrayList; @@ -44,24 +44,24 @@ public class DiscoveriesCommand { } @CommandDescription("Opens the discovery GUI") - @CommandPermission("rpgregions.list") - @CommandMethod("discoveries|discovery") + @Permission("rpgregions.list") + @Command("discoveries|discovery") public void onDefault(Player player) { - new DiscoveryGUI(plugin, player).open(); + plugin.getScheduler().executeOnMain(() -> new DiscoveryGUI(plugin, player).open()); } @CommandDescription("Opens the bestiary book") - @CommandPermission("rpgregions.bestiary") - @CommandMethod("bestiary|flora|fauna") + @Permission("rpgregions.bestiary") + @Command("bestiary|flora|fauna") public void onBestiary(Player player) { openBestiary(player); } @CommandDescription("Shows a specific bestiary entry") - @CommandPermission("rpgregions.bestiary") - @CommandMethod("bestiary|flora|fauna show ") + @Permission("rpgregions.bestiary") + @Command("bestiary|flora|fauna show ") public void onBestiaryShow(Player player, - @Argument(value = "fauna") FaunaInstance fauna) { + @Argument(value = "fauna") FaunaInstance fauna) { fauna.openDescription(player); } @@ -109,8 +109,8 @@ public class DiscoveriesCommand { } @CommandDescription("Discovers a region for a player") - @CommandPermission("rpgregions.discover") - @CommandMethod("discoveries|discovery discover region ") + @Permission("rpgregions.discover") + @Command("discoveries|discovery discover region ") public void onDiscover(CommandSender sender, @Argument("region") ConfiguredRegion configuredRegion, @Argument("player") OfflinePlayer target) { @@ -130,8 +130,8 @@ public class DiscoveriesCommand { } @CommandDescription("Discovers fauna for a player") - @CommandPermission("rpgregions.discover") - @CommandMethod("discoveries|discovery discover fauna ") + @Permission("rpgregions.discover") + @Command("discoveries|discovery discover fauna ") public void onDiscover(CommandSender sender, @Argument("fauna") FaunaInstance fauna, @Argument("player") OfflinePlayer target) { diff --git a/rpgregions/src/main/java/net/islandearth/rpgregions/commands/RPGRegionsCommand.java b/rpgregions/src/main/java/net/islandearth/rpgregions/commands/RPGRegionsCommand.java index 7e013c9..8000b0c 100644 --- a/rpgregions/src/main/java/net/islandearth/rpgregions/commands/RPGRegionsCommand.java +++ b/rpgregions/src/main/java/net/islandearth/rpgregions/commands/RPGRegionsCommand.java @@ -1,15 +1,5 @@ package net.islandearth.rpgregions.commands; -import cloud.commandframework.annotations.Argument; -import cloud.commandframework.annotations.CommandDescription; -import cloud.commandframework.annotations.CommandMethod; -import cloud.commandframework.annotations.CommandPermission; -import cloud.commandframework.annotations.Hidden; -import cloud.commandframework.annotations.specifier.Greedy; -import cloud.commandframework.annotations.suggestions.Suggestions; -import cloud.commandframework.context.CommandContext; -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; @@ -35,6 +25,15 @@ import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.checkerframework.checker.nullness.qual.NonNull; +import org.incendo.cloud.annotation.specifier.Greedy; +import org.incendo.cloud.annotations.Argument; +import org.incendo.cloud.annotations.Command; +import org.incendo.cloud.annotations.CommandDescription; +import org.incendo.cloud.annotations.Permission; +import org.incendo.cloud.annotations.suggestion.Suggestions; +import org.incendo.cloud.context.CommandContext; +import org.incendo.cloud.minecraft.extras.MinecraftHelp; +import org.incendo.cloud.paper.PaperCommandManager; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -59,15 +58,11 @@ public class RPGRegionsCommand { public RPGRegionsCommand(RPGRegions plugin, PaperCommandManager manager) { this.plugin = plugin; - this.help = new MinecraftHelp<>( - "/rpgregions help", - player -> plugin.adventure().sender(player), - manager - ); + this.help = MinecraftHelp.create("/rpgregions help", manager, sender -> plugin.adventure().sender(sender)); } @CommandDescription("The default RPGRegions command") - @CommandMethod("rpgregions|rpgr") + @Command("rpgregions|rpgr") public void onDefault(CommandSender sender) { if (sender.hasPermission("rpgregions.noview") && !sender.isOp()) return; @@ -91,14 +86,13 @@ public class RPGRegionsCommand { "" + plugin.getManagers().getFaunaCache().getFauna().size() + " fauna is loaded.")); } - @CommandMethod("rpgregions|rpgr help [query]") + @Command("rpgregions|rpgr help [query]") public void onHelp(final CommandSender sender, @Argument("query") @Greedy @Nullable String query) { help.queryCommands(query == null ? "" : query, sender); } @CommandDescription("Debug information about the plugin") - @CommandMethod("rpgregions|rpgr about") - @Hidden + @Command("rpgregions|rpgr about") public void onAbout(CommandSender sender) { sender.sendMessage(Colors.colour("&eRPGRegions v" + plugin.getDescription().getVersion() + ".")); sender.sendMessage(Colors.colour("&eOwner: https://www.spigotmc.org/members/%%__USER__%%/")); @@ -107,8 +101,8 @@ public class RPGRegionsCommand { } @CommandDescription("Creates a configured region from a region created in your integration") - @CommandPermission("rpgregions.add") - @CommandMethod("rpgregions|rpgr add [world]") + @Permission("rpgregions.add") + @Command("rpgregions|rpgr add [world]") public void onAdd(CommandSender sender, @Argument(value = "region", suggestions = "integration-regions") String region, @Argument("world") @Nullable World world) { @@ -153,8 +147,8 @@ public class RPGRegionsCommand { } @CommandDescription("Sets the display name of a region") - @CommandPermission("rpgregions.setname") - @CommandMethod("rpgregions|rpgr setname ") + @Permission("rpgregions.setname") + @Command("rpgregions|rpgr setname ") public void onSetName(CommandSender sender, @Argument("region") ConfiguredRegion region, @Argument("name") @Greedy String name) { @@ -163,8 +157,8 @@ public class RPGRegionsCommand { } @CommandDescription("Removes a configured region. Does not delete it from your integration.") - @CommandPermission("rpgregions.remove") - @CommandMethod("rpgregions|rpgr remove ") + @Permission("rpgregions.remove") + @Command("rpgregions|rpgr remove ") public void onRemove(CommandSender sender, @Argument("region") ConfiguredRegion region) { region.delete(plugin); plugin.getManagers().getRegionsCache().removeConfiguredRegion(region.getId()); @@ -172,30 +166,30 @@ public class RPGRegionsCommand { } @CommandDescription("Opens the editor GUI for a region") - @CommandPermission("rpgregions.edit") - @CommandMethod("rpgregions|rpgr edit ") + @Permission("rpgregions.edit") + @Command("rpgregions|rpgr edit ") public void onEdit(Player player, @Argument("region") ConfiguredRegion region) { - new RegionCreateGUI(plugin, player, region).open(); + plugin.getScheduler().executeOnMain(() -> new RegionCreateGUI(plugin, player, region).open()); } @CommandDescription("Opens the /discovery GUI") - @CommandPermission("rpgregions.list") - @CommandMethod("rpgregions|rpgr list|discoveries") + @Permission("rpgregions.list") + @Command("rpgregions|rpgr list|discoveries") public void onList(Player player) { - new DiscoveryGUI(plugin, player).open(); + plugin.getScheduler().executeOnMain(() -> new DiscoveryGUI(plugin, player).open()); } @CommandDescription("Adds an item reward to a region (util command)") - @CommandPermission("rpgregions.additem") - @CommandMethod("rpgregions|rpgr additem ") + @Permission("rpgregions.additem") + @Command("rpgregions|rpgr additem ") public void onAddItem(Player player, @Argument("region") ConfiguredRegion region) { region.getRewards().add(new ItemReward(plugin, player.getInventory().getItemInMainHand())); Colors.sendColourful(player, Component.text("Item added to configuration!", Colors.EREBOR_GREEN)); } @CommandDescription("Reloads configured regions from the `/plugins/RPGRegions/regions` folder.") - @CommandPermission("rpgregions.reload") - @CommandMethod("rpgregions|rpgr reload") + @Permission("rpgregions.reload") + @Command("rpgregions|rpgr reload") public void onReload(CommandSender sender) { sender.sendMessage(ChatColor.GREEN + "Reloading region files..."); long startTime = System.currentTimeMillis(); @@ -226,8 +220,8 @@ public class RPGRegionsCommand { } @CommandDescription("Saves configured regions to the `/plugins/RPGRegions/regions` folder. Also saves user data.") - @CommandPermission("rpgregions.save") - @CommandMethod("rpgregions|rpgr save [async]") + @Permission("rpgregions.save") + @Command("rpgregions|rpgr save [async]") public void onSave(CommandSender sender, @Argument(value = "async", suggestions = "async") @Nullable String asyncArg) { boolean async = asyncArg != null && asyncArg.equals("--async"); @@ -255,8 +249,8 @@ public class RPGRegionsCommand { } @CommandDescription("Resets the data of a player") - @CommandPermission("rpgregions.reset") - @CommandMethod("rpgregions|rpgr reset [region]") + @Permission("rpgregions.reset") + @Command("rpgregions|rpgr reset [region]") public void onReset(CommandSender sender, @Argument("player") @NonNull OfflinePlayer player, @Argument("region") @Nullable ConfiguredRegion region) { @@ -279,8 +273,8 @@ public class RPGRegionsCommand { @CommandDescription("Deletes user accounts from the database") - @CommandPermission("rpgregions.delete") - @CommandMethod("rpgregions|rpgr delete ") + @Permission("rpgregions.delete") + @Command("rpgregions|rpgr delete ") public void onDelete(CommandSender sender, @Argument("player") @NotNull OfflinePlayer player) { plugin.getManagers().getStorageManager().deleteAccount(player.getUniqueId()); @@ -288,8 +282,8 @@ public class RPGRegionsCommand { } @CommandDescription("Sets the teleport location of a region") - @CommandPermission("rpgregions.setlocation") - @CommandMethod("rpgregions|rpgr setlocation ") + @Permission("rpgregions.setlocation") + @Command("rpgregions|rpgr setlocation ") public void onSetLocation(Player player, @Argument("region") ConfiguredRegion region) { Location location = player.getLocation(); @@ -298,8 +292,8 @@ public class RPGRegionsCommand { } @CommandDescription("Sets or removes the sound of a region when it is discovered") - @CommandPermission("rpgregions.edit") - @CommandMethod("rpgregions|rpgr setsound [sound]") + @Permission("rpgregions.edit") + @Command("rpgregions|rpgr setsound [sound]") public void onSetSound(CommandSender sender, @Argument("region") ConfiguredRegion region, @Argument(value = "sound", suggestions = "sound_names") @Nullable String soundName) { @@ -314,8 +308,8 @@ public class RPGRegionsCommand { //TODO: use confirmation api @CommandDescription("If configured, regenerates a region to the set schematic") - @CommandPermission("rpgregions.regenerate") - @CommandMethod("rpgregions|rpgr regenerate ") + @Permission("rpgregions.regenerate") + @Command("rpgregions|rpgr regenerate ") public void onRegenerate(Player player, @Argument("region") ConfiguredRegion region) { IntegrationType integrationType = IntegrationType.valueOf(plugin.getConfig().getString("settings.integration.name").toUpperCase()); @@ -343,8 +337,8 @@ public class RPGRegionsCommand { } @CommandDescription("Sets the regeneration schematic for a region") - @CommandPermission("rpgregions.setschematic") - @CommandMethod("rpgregions|rpgr setschematic ") + @Permission("rpgregions.setschematic") + @Command("rpgregions|rpgr setschematic ") public void onAddSchematic(Player player, @Argument("region") ConfiguredRegion region, @Argument("schematicName") @Greedy String schematicName) { @@ -374,8 +368,8 @@ public class RPGRegionsCommand { } @CommandDescription("Resets the icons of all configured regions to the config default") - @CommandPermission("rpgregions.forceupdate") - @CommandMethod("rpgregions|rpgr forceupdateicons") + @Permission("rpgregions.forceupdate") + @Command("rpgregions|rpgr forceupdateicons") public void onForceUpdateIcons(Player player) { Optional defaultIcon = Optional.of(Material.valueOf(RPGRegionsAPI.getAPI().getConfig().getString("settings.server.gui.default_region_icon"))); defaultIcon.ifPresent(xMaterial -> { diff --git a/rpgregions/src/main/java/net/islandearth/rpgregions/commands/RPGRegionsDebugCommand.java b/rpgregions/src/main/java/net/islandearth/rpgregions/commands/RPGRegionsDebugCommand.java index 84cd208..b472b86 100644 --- a/rpgregions/src/main/java/net/islandearth/rpgregions/commands/RPGRegionsDebugCommand.java +++ b/rpgregions/src/main/java/net/islandearth/rpgregions/commands/RPGRegionsDebugCommand.java @@ -1,8 +1,5 @@ package net.islandearth.rpgregions.commands; -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; @@ -11,16 +8,19 @@ import net.islandearth.rpgregions.managers.data.IStorageManager; import net.islandearth.rpgregions.requirements.RegionRequirement; 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.World; import org.bukkit.command.CommandSender; +import org.incendo.cloud.annotations.Argument; +import org.incendo.cloud.annotations.Command; +import org.incendo.cloud.annotations.Permission; import java.sql.Connection; import java.sql.SQLException; +import java.util.List; -@CommandPermission("rpgregions.debug") +@Permission("rpgregions.debug") public class RPGRegionsDebugCommand { private final RPGRegions plugin; @@ -29,15 +29,16 @@ public class RPGRegionsDebugCommand { this.plugin = plugin; } - @CommandMethod("rpgregionsdebug|rpgrd") + @Command("rpgregionsdebug|rpgrd") public void onDefault(CommandSender sender) throws SQLException { IStorageManager storageManager = plugin.getManagers().getStorageManager(); sender.sendMessage(ChatColor.GOLD + "Database status:"); sender.sendMessage(ChatColor.GRAY + "Storage implementation " + storageManager.getClass().getSimpleName() + "."); sender.sendMessage(ChatColor.GRAY + "" + storageManager.getCachedAccounts().synchronous().asMap().size() + " cached players."); + final List timings = storageManager.getTimings(); sender.sendMessage(ChatColor.GRAY + "Performance (" + storageManager.getTimingsAverage() + " avg. ms)" + - " (last 3 retrievals): " + StringUtils.join(storageManager.getTimings(), "ms, ") + "ms"); + " (last 3 retrievals): " + timings.get(0) + " ms, " + timings.get(1) + " ms, " + timings.get(2) + " ms"); Database database = DB.getGlobalDatabase(); if (database != null) { Connection connection = database.getConnection(); @@ -67,7 +68,7 @@ public class RPGRegionsDebugCommand { }); } - @CommandMethod("rpgregionsdebug|rpgrd enable|disable|toggle") + @Command("rpgregionsdebug|rpgrd enable|disable|toggle") public void onEnable(CommandSender sender) { final boolean newValue = !plugin.debug(); plugin.getConfig().set("settings.dev.debug", newValue); @@ -76,7 +77,7 @@ public class RPGRegionsDebugCommand { else sender.sendMessage(ChatColor.RED + "Debug disabled."); } - @CommandMethod("rpgregionsdebug|rpgrd cache") + @Command("rpgregionsdebug|rpgrd cache") public void onCache(CommandSender sender) { IStorageManager storageManager = plugin.getManagers().getStorageManager(); sender.sendMessage(ChatColor.GOLD + "Database cache:"); @@ -85,7 +86,7 @@ public class RPGRegionsDebugCommand { }); } - @CommandMethod("rpgregionsdebug|rpgrd removecached ") + @Command("rpgregionsdebug|rpgrd removecached ") public void onRemoveCached(CommandSender sender, @Argument("player") OfflinePlayer player) { IStorageManager storageManager = plugin.getManagers().getStorageManager(); sender.sendMessage(ChatColor.GREEN + "Removing from cache..."); @@ -94,7 +95,7 @@ public class RPGRegionsDebugCommand { }); } - @CommandMethod("rpgregionsdebug|rpgrd worldid ") + @Command("rpgregionsdebug|rpgrd worldid ") public void onGetWorldId(CommandSender sender, @Argument("world") World world) { sender.sendMessage(ChatColor.GREEN + String.valueOf(world.getUID())); } diff --git a/rpgregions/src/main/java/net/islandearth/rpgregions/commands/RPGRegionsExportCommand.java b/rpgregions/src/main/java/net/islandearth/rpgregions/commands/RPGRegionsExportCommand.java index ab3b192..2587334 100644 --- a/rpgregions/src/main/java/net/islandearth/rpgregions/commands/RPGRegionsExportCommand.java +++ b/rpgregions/src/main/java/net/islandearth/rpgregions/commands/RPGRegionsExportCommand.java @@ -1,11 +1,5 @@ package net.islandearth.rpgregions.commands; -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; @@ -13,6 +7,12 @@ import net.islandearth.rpgregions.requirements.RegionRequirement; import net.islandearth.rpgregions.rewards.DiscoveryReward; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; +import org.incendo.cloud.annotation.specifier.Greedy; +import org.incendo.cloud.annotations.Argument; +import org.incendo.cloud.annotations.Command; +import org.incendo.cloud.annotations.CommandDescription; +import org.incendo.cloud.minecraft.extras.MinecraftHelp; +import org.incendo.cloud.paper.PaperCommandManager; import org.jetbrains.annotations.Nullable; import java.io.File; @@ -27,26 +27,22 @@ public class RPGRegionsExportCommand { public RPGRegionsExportCommand(RPGRegions plugin, PaperCommandManager manager) { this.plugin = plugin; - this.help = new MinecraftHelp<>( - "/rpgre help", - player -> plugin.adventure().sender(player), - manager - ); + this.help = MinecraftHelp.create("/rpgre help", manager, sender -> plugin.adventure().sender(sender)); } @CommandDescription("The default RPGRegions export command.") - @CommandMethod("rpgre") + @Command("rpgre") public void onDefault(CommandSender sender) { sender.sendMessage(ChatColor.GREEN + "Use this command to export/import a region template."); } - @CommandMethod("rpgre help [query]") + @Command("rpgre help [query]") public void onHelp(final CommandSender sender, @Argument("query") @Greedy @Nullable String query) { help.queryCommands(query == null ? "" : query, sender); } @CommandDescription("Exports a region to a template file (`plugins/RPGRegions/templates`).") - @CommandMethod("rpgre export ") + @Command("rpgre export ") public void onExport(CommandSender sender, @Argument("region") ConfiguredRegion region) { File templates = new File(plugin.getDataFolder() + File.separator + "templates"); @@ -58,7 +54,7 @@ public class RPGRegionsExportCommand { } @CommandDescription("Imports a template region into an existing configured region") - @CommandMethod("rpgre import