Mirror von
https://github.com/Moulberry/AxiomPaperPlugin.git
synchronisiert 2024-11-17 05:40:06 +01:00
Update to 1.19.2
Dieser Commit ist enthalten in:
Ursprung
53f172bf03
Commit
8af375f4b7
@ -2,7 +2,7 @@ import net.minecrell.pluginyml.bukkit.BukkitPluginDescription
|
|||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
`java-library`
|
`java-library`
|
||||||
id("io.papermc.paperweight.userdev") version "1.3.7"
|
id("io.papermc.paperweight.userdev") version "1.3.8"
|
||||||
id("xyz.jpenilla.run-paper") version "1.0.6" // Adds runServer and runMojangMappedServer tasks for testing
|
id("xyz.jpenilla.run-paper") version "1.0.6" // Adds runServer and runMojangMappedServer tasks for testing
|
||||||
id("net.minecrell.plugin-yml.bukkit") version "0.5.2" // Generates plugin.yml
|
id("net.minecrell.plugin-yml.bukkit") version "0.5.2" // Generates plugin.yml
|
||||||
}
|
}
|
||||||
@ -17,12 +17,12 @@ java {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
paperDevBundle("1.19-R0.1-SNAPSHOT")
|
paperDevBundle("1.19.2-R0.1-SNAPSHOT")
|
||||||
// paperweightDevBundle("com.example.paperfork", "1.19-R0.1-SNAPSHOT")
|
// paperweightDevBundle("com.example.paperfork", "1.19.2-R0.1-SNAPSHOT")
|
||||||
|
|
||||||
// You will need to manually specify the full dependency if using the groovy gradle dsl
|
// You will need to manually specify the full dependency if using the groovy gradle dsl
|
||||||
// (paperDevBundle and paperweightDevBundle functions do not work in groovy)
|
// (paperDevBundle and paperweightDevBundle functions do not work in groovy)
|
||||||
// paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.19-R0.1-SNAPSHOT")
|
// paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.19.2-R0.1-SNAPSHOT")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
@ -58,6 +58,6 @@ tasks {
|
|||||||
bukkit {
|
bukkit {
|
||||||
load = BukkitPluginDescription.PluginLoadOrder.STARTUP
|
load = BukkitPluginDescription.PluginLoadOrder.STARTUP
|
||||||
main = "io.papermc.paperweight.testplugin.TestPlugin"
|
main = "io.papermc.paperweight.testplugin.TestPlugin"
|
||||||
apiVersion = "1.18"
|
apiVersion = "1.19"
|
||||||
authors = listOf("Author")
|
authors = listOf("Author")
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
package io.papermc.paperweight.testplugin;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.PluginIdentifiableCommand;
|
||||||
|
import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_19_R1.command.VanillaCommandWrapper;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
|
@DefaultQualifier(NonNull.class)
|
||||||
|
final class PluginBrigadierCommand extends Command implements PluginIdentifiableCommand {
|
||||||
|
private final Consumer<LiteralArgumentBuilder<CommandSourceStack>> command;
|
||||||
|
private final Plugin plugin;
|
||||||
|
|
||||||
|
PluginBrigadierCommand(
|
||||||
|
final Plugin plugin,
|
||||||
|
final String name,
|
||||||
|
final Consumer<LiteralArgumentBuilder<CommandSourceStack>> command
|
||||||
|
) {
|
||||||
|
super(name);
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.command = command;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(final CommandSender sender, final String commandLabel, final String[] args) {
|
||||||
|
final String joined = String.join(" ", args);
|
||||||
|
final String argsString = joined.isBlank() ? "" : " " + joined;
|
||||||
|
((CraftServer) Bukkit.getServer()).getServer().getCommands().performPrefixedCommand(
|
||||||
|
VanillaCommandWrapper.getListener(sender),
|
||||||
|
commandLabel + argsString,
|
||||||
|
commandLabel
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Plugin getPlugin() {
|
||||||
|
return this.plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
Consumer<LiteralArgumentBuilder<CommandSourceStack>> command() {
|
||||||
|
return this.command;
|
||||||
|
}
|
||||||
|
}
|
@ -1,27 +1,45 @@
|
|||||||
package io.papermc.paperweight.testplugin;
|
package io.papermc.paperweight.testplugin;
|
||||||
|
|
||||||
|
import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource;
|
||||||
|
import com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent;
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.Util;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.arguments.EntityArgument;
|
import net.minecraft.commands.arguments.EntityArgument;
|
||||||
import net.minecraft.network.chat.ClickEvent;
|
import net.minecraft.network.chat.ClickEvent;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
|
import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
import static net.kyori.adventure.text.format.NamedTextColor.BLUE;
|
||||||
import static net.minecraft.commands.Commands.argument;
|
import static net.minecraft.commands.Commands.argument;
|
||||||
import static net.minecraft.commands.Commands.literal;
|
import static net.minecraft.commands.Commands.literal;
|
||||||
import static net.minecraft.commands.arguments.EntityArgument.players;
|
import static net.minecraft.commands.arguments.EntityArgument.players;
|
||||||
|
|
||||||
|
@DefaultQualifier(NonNull.class)
|
||||||
public final class TestPlugin extends JavaPlugin implements Listener {
|
public final class TestPlugin extends JavaPlugin implements Listener {
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
this.getServer().getPluginManager().registerEvents(this, this);
|
this.getServer().getPluginManager().registerEvents(this, this);
|
||||||
((CraftServer) this.getServer()).getServer().vanillaCommandDispatcher.getDispatcher().register(
|
|
||||||
literal("paperweight")
|
this.registerPluginBrigadierCommand(
|
||||||
.requires(stack -> stack.hasPermission(stack.getServer().getOperatorUserPermissionLevel()))
|
"paperweight",
|
||||||
|
literal -> literal.requires(stack -> stack.getBukkitSender().hasPermission("paperweight"))
|
||||||
|
.then(literal("hello")
|
||||||
|
.executes(ctx -> {
|
||||||
|
ctx.getSource().getBukkitSender().sendMessage(text("Hello!", BLUE));
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}))
|
||||||
.then(argument("players", players())
|
.then(argument("players", players())
|
||||||
.executes(ctx -> {
|
.executes(ctx -> {
|
||||||
final Collection<ServerPlayer> players = EntityArgument.getPlayers(ctx, "players");
|
final Collection<ServerPlayer> players = EntityArgument.getPlayers(ctx, "players");
|
||||||
@ -36,4 +54,22 @@ public final class TestPlugin extends JavaPlugin implements Listener {
|
|||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PluginBrigadierCommand registerPluginBrigadierCommand(final String label, final Consumer<LiteralArgumentBuilder<CommandSourceStack>> command) {
|
||||||
|
final PluginBrigadierCommand pluginBrigadierCommand = new PluginBrigadierCommand(this, label, command);
|
||||||
|
this.getServer().getCommandMap().register(this.getName(), pluginBrigadierCommand);
|
||||||
|
((CraftServer) this.getServer()).syncCommands();
|
||||||
|
return pluginBrigadierCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
|
@EventHandler
|
||||||
|
public void onCommandRegistered(final CommandRegisteredEvent<BukkitBrigadierCommandSource> event) {
|
||||||
|
if (!(event.getCommand() instanceof PluginBrigadierCommand pluginBrigadierCommand)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final LiteralArgumentBuilder<CommandSourceStack> node = literal(event.getCommandLabel());
|
||||||
|
pluginBrigadierCommand.command().accept(node);
|
||||||
|
event.setLiteral((LiteralCommandNode) node.build());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren