Skip to content

Commit

Permalink
Merge pull request #217 from InsightsPlugin/mc1.21
Browse files Browse the repository at this point in the history
MC 1.21
  • Loading branch information
FrankHeijden authored Jun 23, 2024
2 parents 953055b + b4cff54 commit 02249b8
Show file tree
Hide file tree
Showing 30 changed files with 376 additions and 575 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: Java CI with Gradle
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
publish:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
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
109 changes: 49 additions & 60 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,33 +31,37 @@
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;
import java.nio.file.Files;
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 {

Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -199,10 +190,6 @@ public InsightsNMS getNMS() {
return nms;
}

public Optional<EntityTrackerTask> getEntityTracker() {
return Optional.ofNullable(entityTrackerTask);
}

@Override
public void reloadSettings() {
File file = new File(getDataFolder(), SETTINGS_FILE_NAME);
Expand Down Expand Up @@ -268,62 +255,64 @@ 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,
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));
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
Loading

0 comments on commit 02249b8

Please sign in to comment.