Skip to content

Commit

Permalink
test-plugin: Update cloud to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Mar 15, 2024
1 parent 57d90c0 commit 046b4d2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 33 deletions.
7 changes: 4 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine" }
checker-qual = "org.checkerframework:checker-qual:3.40.0"
mapping-io = { group = "net.fabricmc", name = "mapping-io", version = "0.5.0" }

cloud-bom = { group = "cloud.commandframework", name = "cloud-bom", version = "1.8.4" }
cloud-paper = { module = "cloud.commandframework:cloud-paper" }
cloud-minecraft-extras = { module = "cloud.commandframework:cloud-minecraft-extras" }
cloud-bom = { group = "org.incendo", name = "cloud-bom", version = "2.0.0-beta.4" }
cloud-minecraft-bom = { group = "org.incendo", name = "cloud-minecraft-bom", version = "2.0.0-beta.5" }
cloud-paper = { module = "org.incendo:cloud-paper" }
cloud-minecraft-extras = { module = "org.incendo:cloud-minecraft-extras" }

[bundles]
3 changes: 2 additions & 1 deletion test-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies {
implementation(projects.reflectionRemapper)

implementation(platform(libs.cloud.bom))
implementation(platform(libs.cloud.minecraft.bom))
implementation(libs.cloud.paper)
implementation(libs.cloud.minecraft.extras) {
isTransitive = false // Paper provides adventure
Expand All @@ -30,7 +31,7 @@ tasks {
shadowJar {
fun reloc(pkg: String) = relocate(pkg, "xyz.jpenilla.reflectionremapper.testplugin.dependency.$pkg")
reloc("net.fabricmc.mappingio")
reloc("cloud.commandframework")
reloc("org.incendo.cloud")
reloc("io.leangen.geantyref")
}
processResources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@
*/
package xyz.jpenilla.reflectionremapper.testplugin;

import cloud.commandframework.Command;
import cloud.commandframework.brigadier.CloudBrigadierManager;
import cloud.commandframework.context.CommandContext;
import cloud.commandframework.execution.CommandExecutionCoordinator;
import cloud.commandframework.minecraft.extras.AudienceProvider;
import cloud.commandframework.minecraft.extras.MinecraftExceptionHandler;
import cloud.commandframework.paper.PaperCommandManager;
import io.papermc.paper.util.MCUtil;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
Expand All @@ -33,8 +26,12 @@
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier;
import org.incendo.cloud.Command;
import org.incendo.cloud.context.CommandContext;
import org.incendo.cloud.execution.ExecutionCoordinator;
import org.incendo.cloud.minecraft.extras.MinecraftExceptionHandler;
import org.incendo.cloud.paper.PaperCommandManager;
import xyz.jpenilla.reflectionremapper.ReflectionRemapper;
import xyz.jpenilla.reflectionremapper.proxy.ReflectionProxyFactory;
import xyz.jpenilla.reflectionremapper.proxy.annotation.Proxies;
Expand All @@ -50,26 +47,26 @@ public void onEnable() {
}

private void registerCommands(final PaperCommandManager<CommandSender> manager) {
final Command.Builder<CommandSender> createEndPlatform = manager.commandBuilder("create_end_platform")
final Command.Builder<Player> createEndPlatform = manager.commandBuilder("create_end_platform")
.senderType(Player.class)
.handler(this::executeCreateEndPlatform);
manager.command(createEndPlatform);

final Command.Builder<CommandSender> strikeLightning = manager.commandBuilder("strike_lightning")
final Command.Builder<Player> strikeLightning = manager.commandBuilder("strike_lightning")
.senderType(Player.class)
.handler(this::executeStrikeLightning);
manager.command(strikeLightning);
}

private void executeCreateEndPlatform(final CommandContext<CommandSender> ctx) {
final ServerPlayer serverPlayer = ((CraftPlayer) ctx.getSender()).getHandle();
private void executeCreateEndPlatform(final CommandContext<Player> ctx) {
final ServerPlayer serverPlayer = ((CraftPlayer) ctx.sender()).getHandle();
Reflection.SERVER_PLAYER.createEndPlatform(serverPlayer, (ServerLevel) serverPlayer.level(), serverPlayer.blockPosition());
}

private void executeStrikeLightning(final CommandContext<CommandSender> ctx) {
final ServerPlayer serverPlayer = ((CraftPlayer) ctx.getSender()).getHandle();
private void executeStrikeLightning(final CommandContext<Player> ctx) {
final ServerPlayer serverPlayer = ((CraftPlayer) ctx.sender()).getHandle();
final BlockPos lightningTarget = Reflection.SERVER_LEVEL.findLightningTargetAround((ServerLevel) serverPlayer.level(), serverPlayer.blockPosition());
((Player) ctx.getSender()).getWorld().strikeLightning(MCUtil.toLocation(serverPlayer.level(), lightningTarget));
ctx.sender().getWorld().strikeLightning(MCUtil.toLocation(serverPlayer.level(), lightningTarget));
}

public static final class Reflection {
Expand Down Expand Up @@ -99,21 +96,11 @@ private interface ServerPlayerProxy {
}

private static PaperCommandManager<CommandSender> createCommandManager(final JavaPlugin plugin) {
final PaperCommandManager<CommandSender> manager;
try {
manager = PaperCommandManager.createNative(plugin, CommandExecutionCoordinator.simpleCoordinator());
} catch (final Exception e) {
throw new RuntimeException(e);
}
final PaperCommandManager<CommandSender> manager = PaperCommandManager.createNative(plugin, ExecutionCoordinator.simpleCoordinator());
manager.registerBrigadier();
manager.registerAsynchronousCompletions();
final @Nullable CloudBrigadierManager<CommandSender, ?> brigMgr = manager.brigadierManager();
if (brigMgr != null) {
brigMgr.setNativeNumberSuggestions(false);
}
new MinecraftExceptionHandler<CommandSender>()
.withDefaultHandlers()
.apply(manager, AudienceProvider.nativeAudience());
MinecraftExceptionHandler.<CommandSender>createNative()
.defaultHandlers()
.registerTo(manager);
return manager;
}
}

0 comments on commit 046b4d2

Please sign in to comment.