diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index cd01d76f..c426de07 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -2,8 +2,6 @@ name: Java CI with Gradle on: push: branches: [ master ] - pull_request: - branches: [ master ] jobs: publish: runs-on: ubuntu-latest diff --git a/CHANGELOG.md b/CHANGELOG.md index 4af84ef5..768b7624 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,3 @@ # Changelog -- Added support for >= 1.20.6 -- Dropped support for <= 1.20.5 +- Added support for 1.21 +- Dropped support for 1.20.X diff --git a/Insights-NMS/Core/src/main/java/dev/frankheijden/insights/nms/core/InsightsNMS.java b/Insights-NMS/Core/src/main/java/dev/frankheijden/insights/nms/core/InsightsNMS.java index f675d293..c3f595a0 100644 --- a/Insights-NMS/Core/src/main/java/dev/frankheijden/insights/nms/core/InsightsNMS.java +++ b/Insights-NMS/Core/src/main/java/dev/frankheijden/insights/nms/core/InsightsNMS.java @@ -19,7 +19,7 @@ public abstract class InsightsNMS { @SuppressWarnings("unchecked") public static T get() { try { - Class clazz = Class.forName("dev.frankheijden.insights.nms.mojangmappings.InsightsNMSImpl"); + Class clazz = Class.forName("dev.frankheijden.insights.nms.current.InsightsNMSImpl"); return (T) clazz.getDeclaredConstructor().newInstance(); } catch (ReflectiveOperationException e) { logger.log(Level.SEVERE, "Unable to get InsightsNMSImpl", e); diff --git a/Insights-NMS/Current/build.gradle.kts b/Insights-NMS/Current/build.gradle.kts new file mode 100644 index 00000000..629ba5af --- /dev/null +++ b/Insights-NMS/Current/build.gradle.kts @@ -0,0 +1,3 @@ +dependencies { + paperweight.paperDevBundle("1.21-R0.1-SNAPSHOT") +} diff --git a/Insights-NMS/MojangMappings/src/main/java/dev/frankheijden/insights/nms/impl/InsightsNMSImpl.java b/Insights-NMS/Current/src/main/java/dev/frankheijden/insights/nms/impl/InsightsNMSImpl.java similarity index 99% rename from Insights-NMS/MojangMappings/src/main/java/dev/frankheijden/insights/nms/impl/InsightsNMSImpl.java rename to Insights-NMS/Current/src/main/java/dev/frankheijden/insights/nms/impl/InsightsNMSImpl.java index 7670a4b5..bdb8e698 100644 --- a/Insights-NMS/MojangMappings/src/main/java/dev/frankheijden/insights/nms/impl/InsightsNMSImpl.java +++ b/Insights-NMS/Current/src/main/java/dev/frankheijden/insights/nms/impl/InsightsNMSImpl.java @@ -1,12 +1,12 @@ package dev.frankheijden.insights.nms.impl; import ca.spottedleaf.concurrentutil.executor.standard.PrioritisedExecutor; +import ca.spottedleaf.moonrise.patches.chunk_system.io.RegionFileIOThread; import com.mojang.serialization.Codec; import com.mojang.serialization.DataResult; import dev.frankheijden.insights.nms.core.ChunkEntity; import dev.frankheijden.insights.nms.core.ChunkSection; import dev.frankheijden.insights.nms.core.InsightsNMS; -import io.papermc.paper.chunk.system.io.RegionFileIOThread; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.NbtOps; diff --git a/Insights-NMS/MojangMappings/build.gradle.kts b/Insights-NMS/MojangMappings/build.gradle.kts deleted file mode 100644 index 94b60ca8..00000000 --- a/Insights-NMS/MojangMappings/build.gradle.kts +++ /dev/null @@ -1,3 +0,0 @@ -dependencies { - paperweight.paperDevBundle("1.20.6-R0.1-SNAPSHOT") -} diff --git a/Insights/build.gradle.kts b/Insights/build.gradle.kts index 4e061597..4383c308 100644 --- a/Insights/build.gradle.kts +++ b/Insights/build.gradle.kts @@ -24,7 +24,7 @@ dependencies { tasks.withType { exclude("com/mojang/**") relocate("com.github.zafarkhaja.semver", "$dependencyDir.semver") - relocate("cloud.commandframework", "$dependencyDir.cloud") + relocate("org.incendo.cloud", "$dependencyDir.cloud") relocate("io.leangen.geantyref", "$dependencyDir.typetoken") relocate("me.lucko.commodore", "$dependencyDir.commodore") } diff --git a/Insights/src/main/java/dev/frankheijden/insights/Insights.java b/Insights/src/main/java/dev/frankheijden/insights/Insights.java index b4cce3a2..261ca675 100644 --- a/Insights/src/main/java/dev/frankheijden/insights/Insights.java +++ b/Insights/src/main/java/dev/frankheijden/insights/Insights.java @@ -1,13 +1,7 @@ package dev.frankheijden.insights; -import cloud.commandframework.annotations.AnnotationParser; -import cloud.commandframework.arguments.parser.ParserRegistry; -import cloud.commandframework.brigadier.CloudBrigadierManager; -import cloud.commandframework.bukkit.CloudBukkitCapabilities; -import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator; -import cloud.commandframework.meta.SimpleCommandMeta; -import cloud.commandframework.paper.PaperCommandManager; import com.github.zafarkhaja.semver.Version; +import com.mojang.brigadier.arguments.StringArgumentType; import dev.frankheijden.insights.api.InsightsPlugin; import dev.frankheijden.insights.api.addons.AddonManager; import dev.frankheijden.insights.api.concurrent.ChunkContainerExecutor; @@ -37,24 +31,30 @@ import dev.frankheijden.insights.commands.CommandScanRegion; import dev.frankheijden.insights.commands.CommandScanWorld; import dev.frankheijden.insights.commands.CommandTeleportChunk; -import dev.frankheijden.insights.commands.brigadier.BrigadierHandler; -import dev.frankheijden.insights.commands.parser.LimitArgument; -import dev.frankheijden.insights.commands.parser.ScanHistoryPageArgument; -import dev.frankheijden.insights.commands.parser.ScanObjectArrayArgument; -import dev.frankheijden.insights.commands.parser.WorldArgument; +import dev.frankheijden.insights.commands.parser.LimitParser; +import dev.frankheijden.insights.commands.parser.ScanHistoryPageParser; +import dev.frankheijden.insights.commands.parser.ScanObjectArrayParser; +import dev.frankheijden.insights.commands.parser.WorldParser; import dev.frankheijden.insights.concurrent.ContainerExecutorService; import dev.frankheijden.insights.listeners.manager.ListenerManager; import dev.frankheijden.insights.nms.core.InsightsNMS; import dev.frankheijden.insights.placeholders.InsightsPlaceholderExpansion; -import dev.frankheijden.insights.tasks.EntityTrackerTask; import dev.frankheijden.insights.tasks.PlayerTrackerTask; import io.leangen.geantyref.TypeToken; import io.papermc.lib.PaperLib; +import io.papermc.paper.command.brigadier.CommandSourceStack; import net.kyori.adventure.platform.bukkit.BukkitAudiences; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; +import org.incendo.cloud.annotations.AnnotationParser; +import org.incendo.cloud.execution.ExecutionCoordinator; +import org.incendo.cloud.paper.PaperCommandManager; +import org.incendo.cloud.parser.ParserRegistry; import java.io.File; import java.io.IOException; import java.nio.file.DirectoryStream; @@ -62,8 +62,6 @@ import java.nio.file.Path; import java.util.Arrays; import java.util.Locale; -import java.util.Optional; -import java.util.function.Function; public class Insights extends InsightsPlugin { @@ -85,7 +83,6 @@ public class Insights extends InsightsPlugin { private AddonStorage addonStorage; private WorldChunkScanTracker worldChunkScanTracker; private AddonScanTracker addonScanTracker; - private EntityTrackerTask entityTrackerTask; private MetricsManager metricsManager; private ScanHistory scanHistory; private ListenerManager listenerManager; @@ -150,17 +147,11 @@ public void onEnable() { loadCommands(); - if (!PaperLib.isPaper()) { - entityTrackerTask = new EntityTrackerTask(this); - var interval = settings.SPIGOT_ENTITY_TRACKER_INTERVAL_TICKS; - Bukkit.getScheduler().runTaskTimer(this, entityTrackerTask, 0, interval); - } - reload(); } private static boolean isIncompatible() { - var minecraftVersion = Version.parse(Bukkit.getServer().getMinecraftVersion(), true); + var minecraftVersion = Version.parse(Bukkit.getServer().getMinecraftVersion(), false); return !PaperLib.isPaper() || minecraftVersion.compareTo(minimumCompatibleVersion) < 0; } @@ -199,10 +190,6 @@ public InsightsNMS getNMS() { return nms; } - public Optional getEntityTracker() { - return Optional.ofNullable(entityTrackerTask); - } - @Override public void reloadSettings() { File file = new File(getDataFolder(), SETTINGS_FILE_NAME); @@ -268,62 +255,64 @@ public void reloadLimits() { } private void loadCommands() { - PaperCommandManager commandManager; - try { - commandManager = new PaperCommandManager<>( - this, - AsynchronousCommandExecutionCoordinator.newBuilder().build(), - Function.identity(), - Function.identity() - ); - } catch (Exception ex) { - ex.printStackTrace(); - return; - } + PaperCommandManager commandManager = PaperCommandManager.builder() + .executionCoordinator(ExecutionCoordinator.asyncCoordinator()) + .buildOnEnable(this); // Register parsers - ParserRegistry parserRegistry = commandManager.parserRegistry(); + ParserRegistry parserRegistry = commandManager.parserRegistry(); parserRegistry.registerParserSupplier( TypeToken.get(new TypeToken() { }.getType()), - options -> new LimitArgument.LimitParser() + LimitParser::new ); parserRegistry.registerParserSupplier( TypeToken.get(new TypeToken[]>() { }.getType()), - options -> new ScanObjectArrayArgument.ScanObjectArrayParser() + ScanObjectArrayParser::new ); parserRegistry.registerParserSupplier( TypeToken.get(new TypeToken() { }.getType()), - options -> new ScanHistoryPageArgument.ScanHistoryPageParser() + ScanHistoryPageParser::new ); parserRegistry.registerParserSupplier( TypeToken.get(new TypeToken() { }.getType()), - options -> new WorldArgument.WorldParser() + WorldParser::new ); - // Register capabilities if allowed - boolean hasBrigadier = commandManager.hasCapability(CloudBukkitCapabilities.BRIGADIER); - boolean hasNativeBrigadier = commandManager.hasCapability(CloudBukkitCapabilities.NATIVE_BRIGADIER); - boolean hasCommodoreBrigadier = commandManager.hasCapability(CloudBukkitCapabilities.COMMODORE_BRIGADIER); - if (hasBrigadier && (hasNativeBrigadier || hasCommodoreBrigadier)) { - commandManager.registerBrigadier(); - CloudBrigadierManager brigadierManager = commandManager.brigadierManager(); - var handler = new BrigadierHandler(brigadierManager); - handler.registerTypes(); - } - if (commandManager.hasCapability(CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION)) { - commandManager.registerAsynchronousCompletions(); + if (commandManager.hasBrigadierManager()) { + commandManager.brigadierManager().registerMapping( + new TypeToken>() {}, + builder -> { + builder.to(argument -> StringArgumentType.greedyString()); + builder.cloudSuggestions(); + } + ); } - // Create Annotation Parser - AnnotationParser annotationParser = new AnnotationParser<>( - commandManager, + commandManager.parameterInjectorRegistry().registerInjector( CommandSender.class, - parameters -> SimpleCommandMeta.empty() + (context, annotationAccessor) -> context.sender().getSender() ); + commandManager.parameterInjectorRegistry().registerInjector( + Player.class, + (context, annotationAccessor) -> { + var sender = context.sender().getSender(); + if (sender instanceof Player player) { + return player; + } + + audiences.sender(sender).sendMessage( + Component.text("This command can only be sent as a player", NamedTextColor.RED) + ); + return null; + } + ); + + // Create Annotation Parser + var annotationParser = new AnnotationParser(commandManager, CommandSourceStack.class); // Parse commands annotationParser.parse(new CommandInsights(this)); diff --git a/Insights/src/main/java/dev/frankheijden/insights/commands/CommandCancelScan.java b/Insights/src/main/java/dev/frankheijden/insights/commands/CommandCancelScan.java index e18ed982..46c6b617 100644 --- a/Insights/src/main/java/dev/frankheijden/insights/commands/CommandCancelScan.java +++ b/Insights/src/main/java/dev/frankheijden/insights/commands/CommandCancelScan.java @@ -1,12 +1,12 @@ package dev.frankheijden.insights.commands; -import cloud.commandframework.annotations.CommandMethod; -import cloud.commandframework.annotations.CommandPermission; import dev.frankheijden.insights.api.InsightsPlugin; import dev.frankheijden.insights.api.commands.InsightsCommand; import dev.frankheijden.insights.api.config.Messages; import dev.frankheijden.insights.api.tasks.ScanTask; import org.bukkit.entity.Player; +import org.incendo.cloud.annotations.Command; +import org.incendo.cloud.annotations.Permission; public class CommandCancelScan extends InsightsCommand { @@ -14,8 +14,8 @@ public CommandCancelScan(InsightsPlugin plugin) { super(plugin); } - @CommandMethod("cancelscan") - @CommandPermission("insights.cancelscan") + @Command("cancelscan") + @Permission("insights.cancelscan") private void handleCancelScan(Player player) { if (ScanTask.cancelScan(player.getUniqueId())) { // Player will be notified of the results, no need to send verification. diff --git a/Insights/src/main/java/dev/frankheijden/insights/commands/CommandInsights.java b/Insights/src/main/java/dev/frankheijden/insights/commands/CommandInsights.java index ef1dc229..1dfc820f 100644 --- a/Insights/src/main/java/dev/frankheijden/insights/commands/CommandInsights.java +++ b/Insights/src/main/java/dev/frankheijden/insights/commands/CommandInsights.java @@ -1,7 +1,5 @@ package dev.frankheijden.insights.commands; -import cloud.commandframework.annotations.CommandMethod; -import cloud.commandframework.annotations.CommandPermission; import dev.frankheijden.insights.Insights; import dev.frankheijden.insights.api.InsightsPlugin; import dev.frankheijden.insights.api.commands.InsightsCommand; @@ -10,16 +8,18 @@ import dev.frankheijden.insights.api.utils.StringUtils; import dev.frankheijden.insights.concurrent.ContainerExecutorService; import org.bukkit.command.CommandSender; +import org.incendo.cloud.annotations.Command; +import org.incendo.cloud.annotations.Permission; -@CommandMethod("insights|in") +@Command("insights|in") public class CommandInsights extends InsightsCommand { public CommandInsights(InsightsPlugin plugin) { super(plugin); } - @CommandMethod("") - @CommandPermission("insights.info") + @Command("") + @Permission("insights.info") private void showBase(CommandSender sender) { sender.sendMessage(ColorUtils.colorize( "&8&l&m---------------=&r&8[ &b&lInsights&8 ]&l&m=----------------", @@ -31,16 +31,16 @@ private void showBase(CommandSender sender) { )); } - @CommandMethod("reload") - @CommandPermission("insights.reload") + @Command("reload") + @Permission("insights.reload") private void reloadConfigurations(CommandSender sender) { plugin.reloadConfigs(); plugin.reload(); plugin.getMessages().getMessage(Messages.Key.CONFIGS_RELOADED).sendTo(sender); } - @CommandMethod("stats") - @CommandPermission("insights.stats") + @Command("stats") + @Permission("insights.stats") private void displayStatistics(CommandSender sender) { ContainerExecutorService executor = ((Insights) plugin).getExecutor(); plugin.getMessages().getMessage(Messages.Key.STATS).addTemplates( diff --git a/Insights/src/main/java/dev/frankheijden/insights/commands/CommandScan.java b/Insights/src/main/java/dev/frankheijden/insights/commands/CommandScan.java index adc15c44..ea1ad925 100644 --- a/Insights/src/main/java/dev/frankheijden/insights/commands/CommandScan.java +++ b/Insights/src/main/java/dev/frankheijden/insights/commands/CommandScan.java @@ -1,10 +1,5 @@ package dev.frankheijden.insights.commands; -import cloud.commandframework.annotations.Argument; -import cloud.commandframework.annotations.CommandMethod; -import cloud.commandframework.annotations.CommandPermission; -import cloud.commandframework.annotations.Flag; -import cloud.commandframework.annotations.specifier.Range; import dev.frankheijden.insights.api.InsightsPlugin; import dev.frankheijden.insights.api.commands.InsightsCommand; import dev.frankheijden.insights.api.concurrent.ScanOptions; @@ -17,20 +12,25 @@ import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.entity.Player; +import org.incendo.cloud.annotation.specifier.Range; +import org.incendo.cloud.annotations.Argument; +import org.incendo.cloud.annotations.Command; +import org.incendo.cloud.annotations.Flag; +import org.incendo.cloud.annotations.Permission; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; -@CommandMethod("scan ") +@Command("scan ") public class CommandScan extends InsightsCommand { public CommandScan(InsightsPlugin plugin) { super(plugin); } - @CommandMethod("tile") - @CommandPermission("insights.scan.tile") + @Command("tile") + @Permission("insights.scan.tile") private void handleTileScan( Player player, @Argument("radius") @Range(min = "0", max = "256") int radius, @@ -46,8 +46,8 @@ private void handleTileScan( ); } - @CommandMethod("entity") - @CommandPermission("insights.scan.entity") + @Command("entity") + @Permission("insights.scan.entity") private void handleEntityScan( Player player, @Argument("radius") @Range(min = "0", max = "256") int radius, @@ -56,8 +56,8 @@ private void handleEntityScan( handleScan(player, radius, Constants.SCAN_ENTITIES, ScanOptions.entitiesOnly(), false, groupByChunk); } - @CommandMethod("all") - @CommandPermission("insights.scan.all") + @Command("all") + @Permission("insights.scan.all") private void handleAllScan( Player player, @Argument("radius") @Range(min = "0", max = "256") int radius, @@ -66,8 +66,8 @@ private void handleAllScan( handleScan(player, radius, null, ScanOptions.scanOnly(), false, groupByChunk); } - @CommandMethod("custom ") - @CommandPermission("insights.scan.custom") + @Command("custom ") + @Permission("insights.scan.custom") private void handleCustomScan( Player player, @Argument("radius") @Range(min = "0", max = "256") int radius, @@ -92,8 +92,8 @@ private void handleCustomScan( handleScan(player, radius, new HashSet<>(scanObjects), options, true, groupByChunk); } - @CommandMethod("limit ") - @CommandPermission("insights.scan.limit") + @Command("limit ") + @Permission("insights.scan.limit") private void handleLimitScan( Player player, @Argument("radius") @Range(min = "0", max = "256") int radius, diff --git a/Insights/src/main/java/dev/frankheijden/insights/commands/CommandScanCache.java b/Insights/src/main/java/dev/frankheijden/insights/commands/CommandScanCache.java index 5c4aa4dd..69a047ea 100644 --- a/Insights/src/main/java/dev/frankheijden/insights/commands/CommandScanCache.java +++ b/Insights/src/main/java/dev/frankheijden/insights/commands/CommandScanCache.java @@ -1,8 +1,5 @@ package dev.frankheijden.insights.commands; -import cloud.commandframework.annotations.Argument; -import cloud.commandframework.annotations.CommandMethod; -import cloud.commandframework.annotations.CommandPermission; import dev.frankheijden.insights.api.InsightsPlugin; import dev.frankheijden.insights.api.addons.Region; import dev.frankheijden.insights.api.commands.InsightsCommand; @@ -17,51 +14,54 @@ import net.kyori.adventure.text.Component; import org.bukkit.Location; import org.bukkit.entity.Player; +import org.incendo.cloud.annotations.Argument; +import org.incendo.cloud.annotations.Command; +import org.incendo.cloud.annotations.Permission; import java.util.Arrays; import java.util.Comparator; import java.util.HashSet; import java.util.Optional; import java.util.Set; -@CommandMethod("scancache") +@Command("scancache") public class CommandScanCache extends InsightsCommand { public CommandScanCache(InsightsPlugin plugin) { super(plugin); } - @CommandMethod("tile") - @CommandPermission("insights.scancache.tile") + @Command("tile") + @Permission("insights.scancache.tile") private void handleTileScan(Player player) { handleScan(player, RTileEntityTypes.getTileEntities(), false); } - @CommandMethod("entity") - @CommandPermission("insights.scancache.entity") + @Command("entity") + @Permission("insights.scancache.entity") private void handleEntityScan(Player player) { handleScan(player, Constants.SCAN_ENTITIES, false); } - @CommandMethod("all") - @CommandPermission("insights.scancache.all") + @Command("all") + @Permission("insights.scancache.all") private void handleAllScan(Player player) { handleScan(player, null, false); } - @CommandMethod("custom ") - @CommandPermission("insights.scancache.custom") + @Command("custom ") + @Permission("insights.scancache.custom") private void handleCustomScan(Player player, @Argument("items") ScanObject[] items) { handleScan(player, new HashSet<>(Arrays.asList(items)), true); } - @CommandMethod("limit ") - @CommandPermission("insights.scancache.limit") + @Command("limit ") + @Permission("insights.scancache.limit") private void handleLimitScan(Player player, @Argument("limit") Limit limit) { handleScan(player, limit.getScanObjects(), false); } - @CommandMethod("clear") - @CommandPermission("insights.scancache.clear") + @Command("clear") + @Permission("insights.scancache.clear") private void handleCacheClear(Player player) { Location loc = player.getLocation(); Optional optionalRegion = plugin.getAddonManager().getRegion(loc); diff --git a/Insights/src/main/java/dev/frankheijden/insights/commands/CommandScanHistory.java b/Insights/src/main/java/dev/frankheijden/insights/commands/CommandScanHistory.java index 62395b48..92f6a864 100644 --- a/Insights/src/main/java/dev/frankheijden/insights/commands/CommandScanHistory.java +++ b/Insights/src/main/java/dev/frankheijden/insights/commands/CommandScanHistory.java @@ -1,13 +1,13 @@ package dev.frankheijden.insights.commands; -import cloud.commandframework.annotations.Argument; -import cloud.commandframework.annotations.CommandMethod; import dev.frankheijden.insights.api.InsightsPlugin; import dev.frankheijden.insights.api.commands.InsightsCommand; import dev.frankheijden.insights.api.config.Messages; import java.util.Optional; import java.util.UUID; import org.bukkit.entity.Player; +import org.incendo.cloud.annotations.Argument; +import org.incendo.cloud.annotations.Command; public class CommandScanHistory extends InsightsCommand { @@ -15,7 +15,7 @@ public CommandScanHistory(InsightsPlugin plugin) { super(plugin); } - @CommandMethod("scanhistory ") + @Command("scanhistory ") private void handleScanHistory( Player player, @Argument("page") Page page diff --git a/Insights/src/main/java/dev/frankheijden/insights/commands/CommandScanRegion.java b/Insights/src/main/java/dev/frankheijden/insights/commands/CommandScanRegion.java index af8f5f7f..1d6de60b 100644 --- a/Insights/src/main/java/dev/frankheijden/insights/commands/CommandScanRegion.java +++ b/Insights/src/main/java/dev/frankheijden/insights/commands/CommandScanRegion.java @@ -1,9 +1,5 @@ package dev.frankheijden.insights.commands; -import cloud.commandframework.annotations.Argument; -import cloud.commandframework.annotations.CommandMethod; -import cloud.commandframework.annotations.CommandPermission; -import cloud.commandframework.annotations.Flag; import dev.frankheijden.insights.api.InsightsPlugin; import dev.frankheijden.insights.api.addons.Region; import dev.frankheijden.insights.api.commands.InsightsCommand; @@ -16,21 +12,25 @@ import dev.frankheijden.insights.api.tasks.ScanTask; import dev.frankheijden.insights.api.utils.Constants; import org.bukkit.entity.Player; +import org.incendo.cloud.annotations.Argument; +import org.incendo.cloud.annotations.Command; +import org.incendo.cloud.annotations.Flag; +import org.incendo.cloud.annotations.Permission; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Optional; import java.util.Set; -@CommandMethod("scanregion") +@Command("scanregion") public class CommandScanRegion extends InsightsCommand { public CommandScanRegion(InsightsPlugin plugin) { super(plugin); } - @CommandMethod("tile") - @CommandPermission("insights.scanregion.tile") + @Command("tile") + @Permission("insights.scanregion.tile") private void handleTileScan( Player player, @Flag(value = "group-by-chunk", aliases = { "c" }) boolean groupByChunk @@ -38,8 +38,8 @@ private void handleTileScan( handleScan(player, RTileEntityTypes.getTileEntities(), ScanOptions.materialsOnly(), false, groupByChunk); } - @CommandMethod("entity") - @CommandPermission("insights.scanregion.entity") + @Command("entity") + @Permission("insights.scanregion.entity") private void handleEntityScan( Player player, @Flag(value = "group-by-chunk", aliases = { "c" }) boolean groupByChunk @@ -47,8 +47,8 @@ private void handleEntityScan( handleScan(player, Constants.SCAN_ENTITIES, ScanOptions.entitiesOnly(), false, groupByChunk); } - @CommandMethod("all") - @CommandPermission("insights.scanregion.all") + @Command("all") + @Permission("insights.scanregion.all") private void handleAllScan( Player player, @Flag(value = "group-by-chunk", aliases = { "c" }) boolean groupByChunk @@ -56,8 +56,8 @@ private void handleAllScan( handleScan(player, null, ScanOptions.scanOnly(), false, groupByChunk); } - @CommandMethod("custom ") - @CommandPermission("insights.scanregion.custom") + @Command("custom ") + @Permission("insights.scanregion.custom") private void handleCustomScan( Player player, @Flag(value = "group-by-chunk", aliases = { "c" }) boolean groupByChunk, @@ -66,8 +66,8 @@ private void handleCustomScan( handleScan(player, new HashSet<>(Arrays.asList(items)), ScanOptions.scanOnly(), true, groupByChunk); } - @CommandMethod("limit ") - @CommandPermission("insights.scanregion.limit") + @Command("limit ") + @Permission("insights.scanregion.limit") private void handleLimitScan( Player player, @Flag(value = "group-by-chunk", aliases = { "c" }) boolean groupByChunk, diff --git a/Insights/src/main/java/dev/frankheijden/insights/commands/CommandScanWorld.java b/Insights/src/main/java/dev/frankheijden/insights/commands/CommandScanWorld.java index 3a3cc386..f257f38d 100644 --- a/Insights/src/main/java/dev/frankheijden/insights/commands/CommandScanWorld.java +++ b/Insights/src/main/java/dev/frankheijden/insights/commands/CommandScanWorld.java @@ -1,9 +1,5 @@ package dev.frankheijden.insights.commands; -import cloud.commandframework.annotations.Argument; -import cloud.commandframework.annotations.CommandMethod; -import cloud.commandframework.annotations.CommandPermission; -import cloud.commandframework.annotations.Flag; import dev.frankheijden.insights.api.InsightsPlugin; import dev.frankheijden.insights.api.commands.InsightsCommand; import dev.frankheijden.insights.api.concurrent.ScanOptions; @@ -17,21 +13,25 @@ import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.entity.Player; +import org.incendo.cloud.annotations.Argument; +import org.incendo.cloud.annotations.Command; +import org.incendo.cloud.annotations.Flag; +import org.incendo.cloud.annotations.Permission; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; -@CommandMethod("scanworld") +@Command("scanworld") public class CommandScanWorld extends InsightsCommand { public CommandScanWorld(InsightsPlugin plugin) { super(plugin); } - @CommandMethod("tile") - @CommandPermission("insights.scanworld.tile") + @Command("tile") + @Permission("insights.scanworld.tile") private void handleTileScan( Player player, @Flag(value = "group-by-chunk", aliases = { "c" }) boolean groupByChunk @@ -39,8 +39,8 @@ private void handleTileScan( handleScan(player, RTileEntityTypes.getTileEntities(), ScanOptions.materialsOnly(), false, groupByChunk); } - @CommandMethod("entity") - @CommandPermission("insights.scanworld.entity") + @Command("entity") + @Permission("insights.scanworld.entity") private void handleEntityScan( Player player, @Flag(value = "group-by-chunk", aliases = { "c" }) boolean groupByChunk @@ -48,8 +48,8 @@ private void handleEntityScan( handleScan(player, Constants.SCAN_ENTITIES, ScanOptions.entitiesOnly(), false, groupByChunk); } - @CommandMethod("all") - @CommandPermission("insights.scanworld.all") + @Command("all") + @Permission("insights.scanworld.all") private void handleAllScan( Player player, @Flag(value = "group-by-chunk", aliases = { "c" }) boolean groupByChunk @@ -57,8 +57,8 @@ private void handleAllScan( handleScan(player, null, ScanOptions.scanOnly(), false, groupByChunk); } - @CommandMethod("custom ") - @CommandPermission("insights.scanworld.custom") + @Command("custom ") + @Permission("insights.scanworld.custom") private void handleCustomScan( Player player, @Flag(value = "group-by-chunk", aliases = { "c" }) boolean groupByChunk, @@ -67,8 +67,8 @@ private void handleCustomScan( handleScan(player, new HashSet<>(Arrays.asList(items)), ScanOptions.scanOnly(), true, groupByChunk); } - @CommandMethod("limit ") - @CommandPermission("insights.scanworld.limit") + @Command("limit ") + @Permission("insights.scanworld.limit") private void handleLimitScan( Player player, @Flag(value = "group-by-chunk", aliases = { "c" }) boolean groupByChunk, diff --git a/Insights/src/main/java/dev/frankheijden/insights/commands/CommandTeleportChunk.java b/Insights/src/main/java/dev/frankheijden/insights/commands/CommandTeleportChunk.java index 376555f0..1d32d979 100644 --- a/Insights/src/main/java/dev/frankheijden/insights/commands/CommandTeleportChunk.java +++ b/Insights/src/main/java/dev/frankheijden/insights/commands/CommandTeleportChunk.java @@ -1,14 +1,14 @@ package dev.frankheijden.insights.commands; -import cloud.commandframework.annotations.Argument; -import cloud.commandframework.annotations.CommandMethod; -import cloud.commandframework.annotations.CommandPermission; -import cloud.commandframework.annotations.Flag; import dev.frankheijden.insights.api.InsightsPlugin; import dev.frankheijden.insights.api.commands.InsightsCommand; import dev.frankheijden.insights.api.config.Messages; import org.bukkit.World; import org.bukkit.entity.Player; +import org.incendo.cloud.annotations.Argument; +import org.incendo.cloud.annotations.Command; +import org.incendo.cloud.annotations.Flag; +import org.incendo.cloud.annotations.Permission; public class CommandTeleportChunk extends InsightsCommand { @@ -16,8 +16,8 @@ public CommandTeleportChunk(InsightsPlugin plugin) { super(plugin); } - @CommandMethod("teleportchunk|tpchunk ") - @CommandPermission("insights.teleportchunk") + @Command("teleportchunk|tpchunk ") + @Permission("insights.teleportchunk") private void handleTeleportChunk( Player player, @Argument("world") World world, diff --git a/Insights/src/main/java/dev/frankheijden/insights/commands/brigadier/BrigadierHandler.java b/Insights/src/main/java/dev/frankheijden/insights/commands/brigadier/BrigadierHandler.java deleted file mode 100644 index da67ba63..00000000 --- a/Insights/src/main/java/dev/frankheijden/insights/commands/brigadier/BrigadierHandler.java +++ /dev/null @@ -1,28 +0,0 @@ -package dev.frankheijden.insights.commands.brigadier; - -import cloud.commandframework.brigadier.CloudBrigadierManager; -import com.mojang.brigadier.arguments.StringArgumentType; -import dev.frankheijden.insights.commands.parser.ScanObjectArrayArgument; -import io.leangen.geantyref.TypeToken; -import org.bukkit.command.CommandSender; - -public class BrigadierHandler { - - private final CloudBrigadierManager brigadierManager; - - public BrigadierHandler(CloudBrigadierManager brigadierManager) { - this.brigadierManager = brigadierManager; - } - - /** - * Registers brigadier types. - */ - public void registerTypes() { - brigadierManager.registerMapping(new TypeToken() { - // - }, builder -> { - builder.to(argument -> StringArgumentType.greedyString()); - builder.cloudSuggestions(); - }); - } -} diff --git a/Insights/src/main/java/dev/frankheijden/insights/commands/parser/LimitArgument.java b/Insights/src/main/java/dev/frankheijden/insights/commands/parser/LimitArgument.java deleted file mode 100644 index b8ca8a68..00000000 --- a/Insights/src/main/java/dev/frankheijden/insights/commands/parser/LimitArgument.java +++ /dev/null @@ -1,76 +0,0 @@ -package dev.frankheijden.insights.commands.parser; - -import cloud.commandframework.ArgumentDescription; -import cloud.commandframework.arguments.CommandArgument; -import cloud.commandframework.arguments.parser.ArgumentParseResult; -import cloud.commandframework.arguments.parser.ArgumentParser; -import cloud.commandframework.context.CommandContext; -import cloud.commandframework.exceptions.parsing.NoInputProvidedException; -import dev.frankheijden.insights.api.InsightsPlugin; -import dev.frankheijden.insights.api.config.limits.Limit; -import io.leangen.geantyref.TypeToken; -import org.bukkit.command.CommandSender; -import java.util.ArrayList; -import java.util.List; -import java.util.Queue; -import java.util.function.BiFunction; - -public class LimitArgument extends CommandArgument { - - /** - * Constructs a Limit argument. - */ - public LimitArgument( - boolean required, - String name, - BiFunction, String, List> suggestionsProvider, - ArgumentDescription defaultDescription - ) { - super( - required, - name, - new LimitParser(), - "", - new TypeToken() {}, - suggestionsProvider, - defaultDescription - ); - } - - public static final class LimitParser implements ArgumentParser { - - @Override - public ArgumentParseResult parse( - CommandContext cxt, - Queue inputQueue - ) { - if (inputQueue.isEmpty()) { - return ArgumentParseResult.failure(new NoInputProvidedException( - LimitParser.class, - cxt - )); - } - - var fileName = inputQueue.peek(); - var limit = InsightsPlugin.getInstance().getLimits().getLimitByFileName(fileName); - if (limit.isEmpty()) { - return ArgumentParseResult.failure(new IllegalArgumentException( - "Invalid limit file name '" + fileName + "'" - )); - } - - inputQueue.poll(); - return ArgumentParseResult.success(limit.get()); - } - - @Override - public boolean isContextFree() { - return true; - } - - @Override - public List suggestions(CommandContext context, String input) { - return new ArrayList<>(InsightsPlugin.getInstance().getLimits().getLimitFileNames()); - } - } -} diff --git a/Insights/src/main/java/dev/frankheijden/insights/commands/parser/LimitParser.java b/Insights/src/main/java/dev/frankheijden/insights/commands/parser/LimitParser.java new file mode 100644 index 00000000..a8453361 --- /dev/null +++ b/Insights/src/main/java/dev/frankheijden/insights/commands/parser/LimitParser.java @@ -0,0 +1,49 @@ +package dev.frankheijden.insights.commands.parser; + +import dev.frankheijden.insights.api.InsightsPlugin; +import dev.frankheijden.insights.api.config.limits.Limit; +import java.util.concurrent.CompletableFuture; +import org.incendo.cloud.context.CommandContext; +import org.incendo.cloud.context.CommandInput; +import org.incendo.cloud.parser.ArgumentParseResult; +import org.incendo.cloud.parser.ArgumentParser; +import org.incendo.cloud.parser.ParserParameters; +import org.incendo.cloud.suggestion.Suggestion; +import org.incendo.cloud.suggestion.SuggestionProvider; + +public class LimitParser implements ArgumentParser, SuggestionProvider { + + public LimitParser(ParserParameters options) { + // + } + + @Override + public ArgumentParseResult parse(CommandContext ctx, CommandInput input) { + var fileName = input.peekString(); + var limit = InsightsPlugin.getInstance().getLimits().getLimitByFileName(fileName); + if (limit.isEmpty()) { + return ArgumentParseResult.failure(new IllegalArgumentException( + "Invalid limit file name '" + fileName + "'" + )); + } + + input.readString(); + return ArgumentParseResult.success(limit.get()); + } + + + @Override + public CompletableFuture> suggestionsFuture( + CommandContext ctx, + CommandInput input + ) { + return CompletableFuture.completedFuture( + InsightsPlugin.getInstance() + .getLimits() + .getLimitFileNames() + .stream() + .map(Suggestion::suggestion) + .toList() + ); + } +} diff --git a/Insights/src/main/java/dev/frankheijden/insights/commands/parser/ScanHistoryPageArgument.java b/Insights/src/main/java/dev/frankheijden/insights/commands/parser/ScanHistoryPageArgument.java deleted file mode 100644 index 7148e87f..00000000 --- a/Insights/src/main/java/dev/frankheijden/insights/commands/parser/ScanHistoryPageArgument.java +++ /dev/null @@ -1,95 +0,0 @@ -package dev.frankheijden.insights.commands.parser; - -import cloud.commandframework.ArgumentDescription; -import cloud.commandframework.arguments.CommandArgument; -import cloud.commandframework.arguments.parser.ArgumentParseResult; -import cloud.commandframework.arguments.parser.ArgumentParser; -import cloud.commandframework.context.CommandContext; -import cloud.commandframework.exceptions.parsing.NoInputProvidedException; -import dev.frankheijden.insights.api.InsightsPlugin; -import dev.frankheijden.insights.api.config.Messages; -import dev.frankheijden.insights.api.utils.StringUtils; -import dev.frankheijden.insights.commands.CommandScanHistory; -import io.leangen.geantyref.TypeToken; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Queue; -import java.util.function.BiFunction; - -public class ScanHistoryPageArgument extends CommandArgument { - - /** - * Constructs a CommandScanHistory.Page argument. - */ - public ScanHistoryPageArgument( - boolean required, - String name, - BiFunction, String, List> suggestionsProvider, - ArgumentDescription defaultDescription - ) { - super( - required, - name, - new ScanHistoryPageParser(), - "", - new TypeToken() {}, - suggestionsProvider, - defaultDescription - ); - } - - public static final class ScanHistoryPageParser implements ArgumentParser { - - @Override - public ArgumentParseResult parse( - CommandContext cxt, - Queue inputQueue - ) { - if (inputQueue.isEmpty()) { - return ArgumentParseResult.failure(new NoInputProvidedException( - ScanHistoryPageArgument.ScanHistoryPageParser.class, - cxt - )); - } - - try { - var pageNumber = Integer.parseInt(inputQueue.peek()); - if (pageNumber <= 0) throw new NumberFormatException(); - - inputQueue.poll(); - return ArgumentParseResult.success(new CommandScanHistory.Page(pageNumber - 1)); - } catch (NumberFormatException ex) { - return ArgumentParseResult.failure(new IllegalArgumentException( - "Invalid Page '" + inputQueue.peek() + "'" - )); - } - } - - @Override - public boolean isContextFree() { - return true; - } - - @Override - public List suggestions(CommandContext context, String input) { - if (context.getSender() instanceof Player) { - var scanHistory = InsightsPlugin.getInstance().getScanHistory(); - int pages = scanHistory.getHistory(((Player) context.getSender()).getUniqueId()) - .map(Messages.PaginatedMessage::getPageAmount) - .orElse(0); - - List suggestions = new ArrayList<>(pages); - for (var i = 1; i <= pages; i++) { - suggestions.add(String.valueOf(i)); - } - - return StringUtils.findThatStartsWith(suggestions, input); - } - - return Collections.emptyList(); - } - } -} diff --git a/Insights/src/main/java/dev/frankheijden/insights/commands/parser/ScanHistoryPageParser.java b/Insights/src/main/java/dev/frankheijden/insights/commands/parser/ScanHistoryPageParser.java new file mode 100644 index 00000000..ca18818c --- /dev/null +++ b/Insights/src/main/java/dev/frankheijden/insights/commands/parser/ScanHistoryPageParser.java @@ -0,0 +1,68 @@ +package dev.frankheijden.insights.commands.parser; + +import dev.frankheijden.insights.api.InsightsPlugin; +import dev.frankheijden.insights.api.config.Messages; +import dev.frankheijden.insights.api.utils.StringUtils; +import dev.frankheijden.insights.commands.CommandScanHistory; +import io.papermc.paper.command.brigadier.CommandSourceStack; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import org.bukkit.entity.Player; +import org.incendo.cloud.context.CommandContext; +import org.incendo.cloud.context.CommandInput; +import org.incendo.cloud.parser.ArgumentParseResult; +import org.incendo.cloud.parser.ArgumentParser; +import org.incendo.cloud.parser.ParserParameters; +import org.incendo.cloud.suggestion.Suggestion; +import org.incendo.cloud.suggestion.SuggestionProvider; + +public class ScanHistoryPageParser implements ArgumentParser, SuggestionProvider { + + public ScanHistoryPageParser(ParserParameters options) { + // + } + + @Override + public ArgumentParseResult parse(CommandContext ctx, CommandInput input) { + try { + var pageNumber = Integer.parseInt(input.peekString()); + if (pageNumber <= 0) throw new NumberFormatException(); + + input.readString(); + return ArgumentParseResult.success(new CommandScanHistory.Page(pageNumber - 1)); + } catch (NumberFormatException ex) { + return ArgumentParseResult.failure(new IllegalArgumentException( + "Invalid Page '" + input.peekString() + "'" + )); + } + } + + @Override + public CompletableFuture> suggestionsFuture( + CommandContext ctx, + CommandInput input + ) { + return CompletableFuture.supplyAsync(() -> { + if (ctx.sender() instanceof CommandSourceStack sourceStack + && sourceStack.getSender() instanceof Player player) { + var scanHistory = InsightsPlugin.getInstance().getScanHistory(); + int pages = scanHistory.getHistory(player.getUniqueId()) + .map(Messages.PaginatedMessage::getPageAmount) + .orElse(0); + + List suggestions = new ArrayList<>(pages); + for (var i = 1; i <= pages; i++) { + suggestions.add(String.valueOf(i)); + } + + return StringUtils.findThatStartsWith(suggestions, input.peekString()).stream() + .map(Suggestion::suggestion) + .toList(); + } + + return Collections.emptyList(); + }); + } +} diff --git a/Insights/src/main/java/dev/frankheijden/insights/commands/parser/ScanObjectArrayArgument.java b/Insights/src/main/java/dev/frankheijden/insights/commands/parser/ScanObjectArrayArgument.java deleted file mode 100644 index cf1cbbce..00000000 --- a/Insights/src/main/java/dev/frankheijden/insights/commands/parser/ScanObjectArrayArgument.java +++ /dev/null @@ -1,89 +0,0 @@ -package dev.frankheijden.insights.commands.parser; - -import cloud.commandframework.ArgumentDescription; -import cloud.commandframework.arguments.CommandArgument; -import cloud.commandframework.arguments.parser.ArgumentParseResult; -import cloud.commandframework.arguments.parser.ArgumentParser; -import cloud.commandframework.context.CommandContext; -import cloud.commandframework.exceptions.parsing.NoInputProvidedException; -import dev.frankheijden.insights.api.objects.wrappers.ScanObject; -import dev.frankheijden.insights.api.utils.Constants; -import dev.frankheijden.insights.api.utils.StringUtils; -import io.leangen.geantyref.TypeToken; -import org.bukkit.command.CommandSender; -import java.util.ArrayList; -import java.util.List; -import java.util.Queue; -import java.util.Set; -import java.util.function.BiFunction; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class ScanObjectArrayArgument extends CommandArgument[]> { - - protected static final Set SUGGESTIONS = Stream.>concat( - Constants.BLOCKS.stream(), - Constants.ENTITIES.stream() - ).map(Enum::name).map(String::toLowerCase).collect(Collectors.toSet()); - - /** - * Constructs a ScanObject[] argument. - */ - public ScanObjectArrayArgument( - boolean required, - String name, - BiFunction, String, List> suggestionsProvider, - ArgumentDescription defaultDescription - ) { - super( - required, - name, - new ScanObjectArrayParser(), - "", - new TypeToken[]>() {}, - suggestionsProvider, - defaultDescription - ); - } - - public static final class ScanObjectArrayParser implements ArgumentParser[]> { - - @Override - public ArgumentParseResult[]> parse(CommandContext cxt, Queue inputQueue) { - if (inputQueue.isEmpty()) { - return ArgumentParseResult.failure(new NoInputProvidedException(ScanObjectArrayParser.class, cxt)); - } - - try { - int queueSize = inputQueue.size(); - List> items = new ArrayList<>(queueSize); - for (var i = 0; i < (queueSize - 1); i++) { - items.add(ScanObject.parse(inputQueue.peek())); - inputQueue.remove(); - } - - String last = inputQueue.peek(); - if (!last.equalsIgnoreCase("-c") && !last.equalsIgnoreCase("--group-by-chunk")) { - items.add(ScanObject.parse(last)); - inputQueue.remove(); - } - - return ArgumentParseResult.success(items.toArray(ScanObject[]::new)); - } catch (IllegalArgumentException ex) { - return ArgumentParseResult.failure(new IllegalArgumentException( - "Invalid Material '" + inputQueue.peek() + "'" - )); - } - } - - @Override - public boolean isContextFree() { - return true; - } - - @Override - public List suggestions(CommandContext context, String input) { - return StringUtils.findThatStartsWith(SUGGESTIONS, input); - } - } -} diff --git a/Insights/src/main/java/dev/frankheijden/insights/commands/parser/ScanObjectArrayParser.java b/Insights/src/main/java/dev/frankheijden/insights/commands/parser/ScanObjectArrayParser.java new file mode 100644 index 00000000..9f2dbb24 --- /dev/null +++ b/Insights/src/main/java/dev/frankheijden/insights/commands/parser/ScanObjectArrayParser.java @@ -0,0 +1,65 @@ +package dev.frankheijden.insights.commands.parser; + +import dev.frankheijden.insights.api.objects.wrappers.ScanObject; +import dev.frankheijden.insights.api.utils.Constants; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import dev.frankheijden.insights.api.utils.StringUtils; +import org.incendo.cloud.context.CommandContext; +import org.incendo.cloud.context.CommandInput; +import org.incendo.cloud.parser.ArgumentParseResult; +import org.incendo.cloud.parser.ArgumentParser; +import org.incendo.cloud.parser.ParserParameters; +import org.incendo.cloud.suggestion.Suggestion; +import org.incendo.cloud.suggestion.SuggestionProvider; + +public class ScanObjectArrayParser implements ArgumentParser[]>, SuggestionProvider { + protected static final Set SUGGESTIONS = Stream.>concat( + Constants.BLOCKS.stream(), + Constants.ENTITIES.stream() + ).map(Enum::name).map(String::toLowerCase).collect(Collectors.toSet()); + + public ScanObjectArrayParser(ParserParameters options) { + // + } + + @Override + public ArgumentParseResult[]> parse(CommandContext ctx, CommandInput input) { + try { + int queueSize = input.length(); + List> items = new ArrayList<>(queueSize); + for (var i = 0; i < (queueSize - 1); i++) { + items.add(ScanObject.parse(input.peekString())); + input.readString(); + } + + String last = input.peekString(); + if (!last.equalsIgnoreCase("-c") && !last.equalsIgnoreCase("--group-by-chunk")) { + items.add(ScanObject.parse(last)); + input.readString(); + } + + return ArgumentParseResult.success(items.toArray(ScanObject[]::new)); + } catch (IllegalArgumentException ex) { + return ArgumentParseResult.failure(new IllegalArgumentException( + "Invalid Material '" + input.peekString() + "'" + )); + } + } + + @Override + public CompletableFuture> suggestionsFuture( + CommandContext ctx, + CommandInput input + ) { + return CompletableFuture.completedFuture( + StringUtils.findThatStartsWith(SUGGESTIONS, input.peekString()).stream() + .map(Suggestion::suggestion) + .toList() + ); + } +} diff --git a/Insights/src/main/java/dev/frankheijden/insights/commands/parser/WorldArgument.java b/Insights/src/main/java/dev/frankheijden/insights/commands/parser/WorldArgument.java deleted file mode 100644 index 3c81b932..00000000 --- a/Insights/src/main/java/dev/frankheijden/insights/commands/parser/WorldArgument.java +++ /dev/null @@ -1,80 +0,0 @@ -package dev.frankheijden.insights.commands.parser; - -import cloud.commandframework.ArgumentDescription; -import cloud.commandframework.arguments.CommandArgument; -import cloud.commandframework.arguments.parser.ArgumentParseResult; -import cloud.commandframework.arguments.parser.ArgumentParser; -import cloud.commandframework.context.CommandContext; -import cloud.commandframework.exceptions.parsing.NoInputProvidedException; -import io.leangen.geantyref.TypeToken; -import java.util.ArrayList; -import java.util.List; -import java.util.Queue; -import java.util.function.BiFunction; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.World; - -public class WorldArgument extends CommandArgument { - - /** - * Constructs a {@link World} argument. - */ - public WorldArgument( - boolean required, - String name, - BiFunction, String, List> suggestionsProvider, - ArgumentDescription defaultDescription - ) { - super( - required, - name, - new WorldParser(), - "", - new TypeToken() {}, - suggestionsProvider, - defaultDescription - ); - } - - public static final class WorldParser implements ArgumentParser { - - @Override - public ArgumentParseResult parse( - CommandContext cxt, - Queue inputQueue - ) { - if (inputQueue.isEmpty()) { - return ArgumentParseResult.failure(new NoInputProvidedException( - WorldParser.class, - cxt - )); - } - - var world = Bukkit.getWorld(inputQueue.peek()); - if (world == null) { - return ArgumentParseResult.failure(new IllegalArgumentException( - "Invalid World '" + inputQueue.peek() + "'" - )); - } - - inputQueue.poll(); - return ArgumentParseResult.success(world); - } - - @Override - public boolean isContextFree() { - return true; - } - - @Override - public List suggestions(CommandContext context, String input) { - List worlds = Bukkit.getWorlds(); - List worldNames = new ArrayList<>(worlds.size()); - for (World world : worlds) { - worldNames.add(world.getName()); - } - return worldNames; - } - } -} diff --git a/Insights/src/main/java/dev/frankheijden/insights/commands/parser/WorldParser.java b/Insights/src/main/java/dev/frankheijden/insights/commands/parser/WorldParser.java new file mode 100644 index 00000000..fbc34d8e --- /dev/null +++ b/Insights/src/main/java/dev/frankheijden/insights/commands/parser/WorldParser.java @@ -0,0 +1,44 @@ +package dev.frankheijden.insights.commands.parser; + +import java.util.concurrent.CompletableFuture; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.incendo.cloud.context.CommandContext; +import org.incendo.cloud.context.CommandInput; +import org.incendo.cloud.parser.ArgumentParseResult; +import org.incendo.cloud.parser.ArgumentParser; +import org.incendo.cloud.parser.ParserParameters; +import org.incendo.cloud.suggestion.Suggestion; +import org.incendo.cloud.suggestion.SuggestionProvider; + +public class WorldParser implements ArgumentParser, SuggestionProvider { + public WorldParser(ParserParameters options) { + // + } + + @Override + public ArgumentParseResult parse(CommandContext ctx, CommandInput input) { + var world = Bukkit.getWorld(input.peekString()); + if (world == null) { + return ArgumentParseResult.failure(new IllegalArgumentException( + "Invalid World '" + input.peekString() + "'" + )); + } + + input.readString(); + return ArgumentParseResult.success(world); + } + + @Override + public CompletableFuture> suggestionsFuture( + CommandContext ctx, + CommandInput input + ) { + return CompletableFuture.completedFuture( + Bukkit.getWorlds() + .stream() + .map(world -> Suggestion.suggestion(world.getName())) + .toList() + ); + } +} diff --git a/Insights/src/main/java/dev/frankheijden/insights/listeners/EntityListener.java b/Insights/src/main/java/dev/frankheijden/insights/listeners/EntityListener.java index 97e41942..793cfd84 100644 --- a/Insights/src/main/java/dev/frankheijden/insights/listeners/EntityListener.java +++ b/Insights/src/main/java/dev/frankheijden/insights/listeners/EntityListener.java @@ -36,7 +36,7 @@ public class EntityListener extends InsightsListener { protected static final Set LIMITED_ENTITIES = EnumSet.of( EntityType.ARMOR_STAND, - EntityType.ENDER_CRYSTAL, + EntityType.END_CRYSTAL, EntityType.ITEM_FRAME, EntityType.GLOW_ITEM_FRAME, EntityType.PAINTING diff --git a/Insights/src/main/java/dev/frankheijden/insights/tasks/EntityTrackerTask.java b/Insights/src/main/java/dev/frankheijden/insights/tasks/EntityTrackerTask.java deleted file mode 100644 index f93baad7..00000000 --- a/Insights/src/main/java/dev/frankheijden/insights/tasks/EntityTrackerTask.java +++ /dev/null @@ -1,46 +0,0 @@ -package dev.frankheijden.insights.tasks; - -import dev.frankheijden.insights.api.InsightsPlugin; -import dev.frankheijden.insights.api.events.EntityRemoveFromWorldEvent; -import dev.frankheijden.insights.api.tasks.InsightsTask; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.entity.Entity; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -public class EntityTrackerTask extends InsightsTask { - - private Map trackedEntities; - - public EntityTrackerTask(InsightsPlugin plugin) { - super(plugin); - this.trackedEntities = new HashMap<>(); - } - - @Override - public void run() { - // Find entities that are alive - Map entities = new HashMap<>(); - for (World world : Bukkit.getWorlds()) { - for (Entity entity : world.getEntities()) { - entities.put(entity.getUniqueId(), entity); - } - } - - // Remove all alive entities from the tracked map - // TrackedEntities now contains the "removed" entities - trackedEntities.keySet().removeAll(entities.keySet()); - - for (Entity entity : trackedEntities.values()) { - if (entity.isDead()) { - Bukkit.getPluginManager().callEvent(new EntityRemoveFromWorldEvent(entity)); - } - } - - // Update the tracked entities with the scanned entities. - trackedEntities.clear(); - trackedEntities = entities; - } -} diff --git a/build.gradle.kts b/build.gradle.kts index c1de5f5e..ee4c3b2b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,7 +12,7 @@ plugins { val name = "Insights" group = "dev.frankheijden.insights" val dependencyDir = "$group.dependencies" -version = "6.18.0" +version = "6.19.0" subprojects { apply(plugin = "java") diff --git a/config/checkstyle/suppressions.xml b/config/checkstyle/suppressions.xml index 8c030622..bcb7dec2 100644 --- a/config/checkstyle/suppressions.xml +++ b/config/checkstyle/suppressions.xml @@ -5,4 +5,5 @@ - \ No newline at end of file + + diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0a4e86af..a6cb0ba6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,7 +1,7 @@ [versions] # libraries semver = "0.10.2" -minecraft = "1.20.2-R0.1-SNAPSHOT" +minecraft = "1.21-R0.1-SNAPSHOT" paperLib = "1.0.8" bStats = "3.0.0" adventure = "4.17.0" @@ -12,7 +12,8 @@ jupiter = "5.9.1" brigadier = "1.0.18" placeholderapi = "2.11.4" commodore = "2.2" -cloud = "1.8.4" +cloudPaper = "2.0.0-beta.9" +cloud = "2.0.0-rc.2" # plugins shadow = "8.1.1" @@ -35,8 +36,8 @@ jupiterEngine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", ve brigadier = { group = "com.mojang", name = "brigadier", version.ref = "brigadier" } placeholderapi = { group = "me.clip", name = "placeholderapi", version.ref = "placeholderapi" } commodore = { group = "me.lucko", name = "commodore", version.ref = "commodore" } -cloudPaper = { group = "cloud.commandframework", name = "cloud-paper", version.ref = "cloud" } -cloudAnnotations = { group = "cloud.commandframework", name = "cloud-annotations", version.ref = "cloud" } +cloudPaper = { group = "org.incendo", name = "cloud-paper", version.ref = "cloudPaper" } +cloudAnnotations = { group = "org.incendo", name = "cloud-annotations", version.ref = "cloud" } [plugins] shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }