Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 44 additions & 21 deletions src/main/java/pw/kaboom/extras/Main.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package pw.kaboom.extras;

import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
import io.papermc.paper.registry.keys.BlockTypeKeys;
import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.messaging.Messenger;
import pw.kaboom.extras.commands.BrigadierCommand;
import pw.kaboom.extras.commands.*;
import pw.kaboom.extras.modules.block.BlockCheck;
import pw.kaboom.extras.modules.block.BlockPhysics;
Expand All @@ -15,12 +20,14 @@
import pw.kaboom.extras.modules.entity.EntitySpawn;
import pw.kaboom.extras.modules.player.*;
import pw.kaboom.extras.modules.player.skin.SkinManager;
import pw.kaboom.extras.modules.player.username.UsernameManager;
import pw.kaboom.extras.modules.server.ServerCommand;
import pw.kaboom.extras.modules.server.ServerGameRule;
import pw.kaboom.extras.modules.server.ServerTabComplete;
import pw.kaboom.extras.util.FlatLayers;

import java.io.File;
import java.util.List;

public final class Main extends JavaPlugin {
public static Main PLUGIN;
Expand All @@ -46,27 +53,40 @@ public void onEnable() {
prefixConfig = YamlConfiguration.loadConfiguration(prefixConfigFile);

/* Commands */
this.getCommand("broadcastrainbow").setExecutor(new CommandBroadcastRainbow());
this.getCommand("broadcastminimessage").setExecutor(new CommandBroadcastMM());
this.getCommand("broadcastvanilla").setExecutor(new CommandBroadcastVanilla());
this.getCommand("clearchat").setExecutor(new CommandClearChat());
this.getCommand("console").setExecutor(new CommandConsole());
this.getCommand("destroyentities").setExecutor(new CommandDestroyEntities());
this.getCommand("enchantall").setExecutor(new CommandEnchantAll());
this.getCommand("getjson").setExecutor(new CommandGetJSON());
this.getCommand("getjsonmm").setExecutor(new CommandGetJSONMM());
this.getCommand("jumpscare").setExecutor(new CommandJumpscare());
this.getCommand("kaboom").setExecutor(new CommandKaboom());
this.getCommand("ping").setExecutor(new CommandPing());
this.getCommand("prefix").setExecutor(new CommandPrefix());
this.getCommand("pumpkin").setExecutor(new CommandPumpkin());
this.getCommand("serverinfo").setExecutor(new CommandServerInfo());
this.getCommand("skin").setExecutor(new CommandSkin());
this.getCommand("spawn").setExecutor(new CommandSpawn());
this.getCommand("spidey").setExecutor(new CommandSpidey());
this.getCommand("tellraw").setExecutor(new CommandTellraw());
this.getCommand("username").setExecutor(new CommandUsername());

this.getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS,event->{
final Commands registrar = event.registrar();
final List<BrigadierCommand> commands = List.of(
new CommandBroadcastMiniMessage(),
new CommandBroadcastRainbow(),
new CommandBroadcastRaw(),
new CommandBroadcastVanilla(),
new CommandClearChat(),
new CommandConsole(),
new CommandDestroyEntities(),
new CommandEnchantAll(),
new CommandGetJSON(),
new CommandGetJSONMiniMessage(),
new CommandJumpscare(),
new CommandKaboom(),
new CommandPing(),
new CommandPrefix(),
new CommandPumpkin(),
new CommandServerInfo(),
new CommandSkin(),
new CommandSpawn(),
new CommandSpidey(),
new CommandUsername()
);
for (final BrigadierCommand command : commands) {
final LiteralArgumentBuilder<CommandSourceStack> builder
= Commands.literal(command.getLabel());
command.build(builder);
registrar.register(
builder.build(),command.getDescription(),command.getAliases()
);
}
});

/* Block-related modules */
BlockPhysics.init(this);

Expand All @@ -92,6 +112,9 @@ public void onEnable() {
this.getServer().getPluginManager().registerEvents(skinManager, this);
skinManager.start();

final UsernameManager usernameManager = new UsernameManager();
this.getServer().getPluginManager().registerEvents(usernameManager, this);

/* Server-related modules */
ServerGameRule.init(this);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package pw.kaboom.extras.arguments;

import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.CustomArgumentType;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.EntitySelectorArgumentResolver;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import java.util.UUID;

public final class PlayerOrUUIDArgumentType implements
CustomArgumentType<Player, EntitySelectorArgumentResolver> {

// We lie to clients and tell them we're an entity selector so that UUIDs don't show up as red.
@Override
public ArgumentType<EntitySelectorArgumentResolver> getNativeType() {
return ArgumentTypes.entity();
}

@Override
public Player parse(final StringReader reader) {
throw new IllegalStateException("method should never be called as we implement override");
}

@Override
public <S> Player parse(final StringReader reader, final S source)
throws CommandSyntaxException {
if (!(source instanceof final CommandSourceStack stack))
throw new IllegalStateException("source was not a CommandSourceStack");

final int cursor = reader.getCursor();
final String string = reader.readString();

try {
final UUID uuid = UUID.fromString(string);
final Player player = Bukkit.getPlayer(uuid);

if (player != null) return player;
} catch (final IllegalArgumentException ignored) {
}

reader.setCursor(cursor);
return ArgumentTypes.player().parse(reader).resolve(stack).getFirst();
}

public static Player getPlayer(final CommandContext<CommandSourceStack> context,
final String name) {
return context.getArgument(name, Player.class);
}

public static PlayerOrUUIDArgumentType playerOrUUID() {
return new PlayerOrUUIDArgumentType();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package pw.kaboom.extras.arguments;

import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.CustomArgumentType;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.EntitySelectorArgumentResolver;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import java.util.List;
import java.util.UUID;

public final class PlayersOrUUIDArgumentType
implements CustomArgumentType<List<Player>, EntitySelectorArgumentResolver> {
@SuppressWarnings("unchecked")
public static List<Player> getPlayers(final CommandContext<CommandSourceStack> context,
final String name) {
return (List<Player>) context.getArgument(name, List.class);
}

public static PlayersOrUUIDArgumentType playersOrUUID() {
return new PlayersOrUUIDArgumentType();
}

// We lie to clients and tell them we're an entity selector so that UUIDs don't show up as red.
@Override
public ArgumentType<EntitySelectorArgumentResolver> getNativeType() {
return ArgumentTypes.entities();
}

@Override
public List<Player> parse(final StringReader reader) {
throw new IllegalStateException("method should never be called as we implement override");
}

@Override
public <S> List<Player> parse(final StringReader reader, final S source)
throws CommandSyntaxException {
if (!(source instanceof final CommandSourceStack stack))
throw new IllegalStateException("source was not a CommandSourceStack");

final int cursor = reader.getCursor();
final String string = reader.readString();

try {
final UUID uuid = UUID.fromString(string);
final Player player = Bukkit.getPlayer(uuid);

if (player != null) return List.of(player);
} catch (final IllegalArgumentException _) {
}

reader.setCursor(cursor);
return ArgumentTypes.players().parse(reader).resolve(stack);
}
}
4 changes: 4 additions & 0 deletions src/main/java/pw/kaboom/extras/arguments/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@NullMarked
package pw.kaboom.extras.arguments;

import org.jspecify.annotations.NullMarked;
18 changes: 18 additions & 0 deletions src/main/java/pw/kaboom/extras/commands/BrigadierCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package pw.kaboom.extras.commands;

import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import io.papermc.paper.command.brigadier.CommandSourceStack;

import java.util.List;

public interface BrigadierCommand {
String getLabel();

String getDescription();

default List<String> getAliases() {
return List.of();
}

void build(final LiteralArgumentBuilder<CommandSourceStack> builder);
}
34 changes: 0 additions & 34 deletions src/main/java/pw/kaboom/extras/commands/CommandBroadcastMM.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package pw.kaboom.extras.commands;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Bukkit;

import java.util.List;

import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
import static io.papermc.paper.command.brigadier.Commands.argument;

public final class CommandBroadcastMiniMessage implements BrigadierCommand {
private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage();

@Override
public String getLabel() {
return "broadcastminimessage";
}

@Override
public String getDescription() {
return "Broadcasts a deserialized MiniMessage component";
}

@Override
public List<String> getAliases() {
return List.of("broadcastmm", "bcmm");
}

@Override
public void build(final LiteralArgumentBuilder<CommandSourceStack> builder) {
builder
.requires(src -> src.getSender().hasPermission("extras.broadcastminimessage"))
.then(argument("message", greedyString())
.executes(ctx -> {
final String mm = StringArgumentType.getString(ctx, "message");
final Component component = MINI_MESSAGE.deserialize(mm);
Bukkit.broadcast(component);
return Command.SINGLE_SUCCESS;
})
);
}
}
Loading