Skip to content

Commit

Permalink
partial mc 1.21 impl
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankHeijden committed Jun 22, 2024
1 parent 953055b commit 33aa270
Show file tree
Hide file tree
Showing 26 changed files with 352 additions and 513 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public abstract class InsightsNMS {
@SuppressWarnings("unchecked")
public static <T extends InsightsNMS> 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);
Expand Down
3 changes: 3 additions & 0 deletions Insights-NMS/Current/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies {
paperweight.paperDevBundle("1.21-R0.1-SNAPSHOT")
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 0 additions & 3 deletions Insights-NMS/MojangMappings/build.gradle.kts

This file was deleted.

2 changes: 1 addition & 1 deletion Insights/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dependencies {
tasks.withType<ShadowJar> {
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")
}
Expand Down
77 changes: 28 additions & 49 deletions Insights/src/main/java/dev/frankheijden/insights/Insights.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -37,11 +31,10 @@
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;
Expand All @@ -50,11 +43,15 @@
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 org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
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;
Expand All @@ -63,7 +60,6 @@
import java.util.Arrays;
import java.util.Locale;
import java.util.Optional;
import java.util.function.Function;

public class Insights extends InsightsPlugin {

Expand Down Expand Up @@ -160,7 +156,7 @@ public void onEnable() {
}

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;
}

Expand Down Expand Up @@ -268,62 +264,45 @@ public void reloadLimits() {
}

private void loadCommands() {
PaperCommandManager<CommandSender> commandManager;
try {
commandManager = new PaperCommandManager<>(
this,
AsynchronousCommandExecutionCoordinator.<CommandSender>newBuilder().build(),
Function.identity(),
Function.identity()
);
} catch (Exception ex) {
ex.printStackTrace();
return;
}
PaperCommandManager<CommandSourceStack> commandManager = PaperCommandManager.builder()
.executionCoordinator(ExecutionCoordinator.asyncCoordinator())
.buildOnEnable(this);

// Register parsers
ParserRegistry<CommandSender> parserRegistry = commandManager.parserRegistry();
ParserRegistry<CommandSourceStack> parserRegistry = commandManager.parserRegistry();
parserRegistry.registerParserSupplier(
TypeToken.get(new TypeToken<Limit>() {
}.getType()),
options -> new LimitArgument.LimitParser()
LimitParser::new
);
parserRegistry.registerParserSupplier(
TypeToken.get(new TypeToken<ScanObject<?>[]>() {
}.getType()),
options -> new ScanObjectArrayArgument.ScanObjectArrayParser()
ScanObjectArrayParser::new
);
parserRegistry.registerParserSupplier(
TypeToken.get(new TypeToken<CommandScanHistory.Page>() {
}.getType()),
options -> new ScanHistoryPageArgument.ScanHistoryPageParser()
ScanHistoryPageParser::new
);
parserRegistry.registerParserSupplier(
TypeToken.get(new TypeToken<World>() {
}.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<CommandSender, ?> 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<ScanObjectArrayParser<CommandSourceStack>>() {},
builder -> {
builder.to(argument -> StringArgumentType.greedyString());
builder.cloudSuggestions();
}
);
}

// Create Annotation Parser
AnnotationParser<CommandSender> annotationParser = new AnnotationParser<>(
commandManager,
CommandSender.class,
parameters -> SimpleCommandMeta.empty()
);
var annotationParser = new AnnotationParser(commandManager, CommandSourceStack.class);

// Parse commands
annotationParser.parse(new CommandInsights(this));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
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 {

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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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=----------------",
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 <radius>")
@Command("scan <radius>")
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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -66,8 +66,8 @@ private void handleAllScan(
handleScan(player, radius, null, ScanOptions.scanOnly(), false, groupByChunk);
}

@CommandMethod("custom <items>")
@CommandPermission("insights.scan.custom")
@Command("custom <items>")
@Permission("insights.scan.custom")
private void handleCustomScan(
Player player,
@Argument("radius") @Range(min = "0", max = "256") int radius,
Expand All @@ -92,8 +92,8 @@ private void handleCustomScan(
handleScan(player, radius, new HashSet<>(scanObjects), options, true, groupByChunk);
}

@CommandMethod("limit <limit>")
@CommandPermission("insights.scan.limit")
@Command("limit <limit>")
@Permission("insights.scan.limit")
private void handleLimitScan(
Player player,
@Argument("radius") @Range(min = "0", max = "256") int radius,
Expand Down
Loading

0 comments on commit 33aa270

Please sign in to comment.