- [FEAT] New APIs for Maintenance Mode and rewrite commands system
- [FEAT] Improved config system to fix old loading bugs and support JSON - [FEAT] LuckPerms support for commands
This commit is contained in:
@@ -16,6 +16,10 @@ public class BridgedCommandSourceStack {
|
||||
internal.sendSuccess(() -> ChatUtils.adventureToMojang(supplier.get()), bl);
|
||||
}
|
||||
|
||||
public void sendFailure(Component text) {
|
||||
internal.sendFailure(ChatUtils.adventureToMojang(text));
|
||||
}
|
||||
|
||||
public CommandSourceStack toMojang() {
|
||||
return internal;
|
||||
}
|
||||
|
@@ -1,85 +0,0 @@
|
||||
package com.hypherionmc.craterlib.nojang.commands;
|
||||
|
||||
import com.hypherionmc.craterlib.api.commands.CraterCommand;
|
||||
import com.hypherionmc.craterlib.nojang.authlib.BridgedGameProfile;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import com.hypherionmc.craterlib.utils.TriConsumer;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.arguments.GameProfileArgument;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class CommandsRegistry {
|
||||
|
||||
public static final CommandsRegistry INSTANCE = new CommandsRegistry();
|
||||
|
||||
private final List<CraterCommand> commands = new ArrayList<>();
|
||||
|
||||
public void registerCommand(CraterCommand cmd) {
|
||||
commands.add(cmd);
|
||||
}
|
||||
|
||||
public void registerCommands(CommandDispatcher<CommandSourceStack> stack) {
|
||||
commands.forEach(cmd -> {
|
||||
if (cmd.hasArguments()) {
|
||||
CommandWithArguments.register(cmd, stack);
|
||||
} else {
|
||||
CommandWithoutArguments.register(cmd, stack);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static class CommandWithoutArguments {
|
||||
|
||||
public static void register(CraterCommand cmd, CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||
LiteralArgumentBuilder<CommandSourceStack> command = Commands.literal(cmd.getCommandName())
|
||||
.requires(source -> source.hasPermission(cmd.getPermissionLevel()))
|
||||
.executes(context -> {
|
||||
cmd.getExecutor().accept(BridgedCommandSourceStack.of(context.getSource()));
|
||||
return 1;
|
||||
});
|
||||
|
||||
dispatcher.register(command);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static class CommandWithArguments {
|
||||
|
||||
public static void register(CraterCommand cmd, CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||
LiteralArgumentBuilder<CommandSourceStack> command = Commands.literal(cmd.getCommandName())
|
||||
.requires(source -> source.hasPermission(cmd.getPermissionLevel()));
|
||||
|
||||
cmd.getArguments().forEach((key, pair) -> command.then(Commands.argument(key, pair.getLeft()).executes(context -> {
|
||||
|
||||
// This is FUCKING UGLY.... Need to improve this in the future
|
||||
if (pair.getLeft() instanceof GameProfileArgument) {
|
||||
Collection<GameProfile> profiles = GameProfileArgument.getGameProfiles(context, key);
|
||||
List<BridgedGameProfile> bridgedGameProfiles = new ArrayList<>();
|
||||
|
||||
profiles.forEach(p -> bridgedGameProfiles.add(BridgedGameProfile.of(p)));
|
||||
|
||||
((TriConsumer<BridgedPlayer, List<BridgedGameProfile>, BridgedCommandSourceStack>) pair.getRight())
|
||||
.accept(BridgedPlayer.of(context.getSource().getPlayer()), bridgedGameProfiles, BridgedCommandSourceStack.of(context.getSource()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
})));
|
||||
|
||||
dispatcher.register(command);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package com.hypherionmc.craterlib.nojang.network.protocol.status;
|
||||
|
||||
import net.minecraft.network.protocol.status.ServerStatus;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
public final class WrappedServerStatus {
|
||||
|
||||
public static final class WrappedFavicon {
|
||||
|
||||
private final ServerStatus.Favicon internal;
|
||||
|
||||
public WrappedFavicon(byte[] iconBytes) {
|
||||
internal = new ServerStatus.Favicon(iconBytes);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public WrappedFavicon(ServerStatus.Favicon internal) {
|
||||
this.internal = internal;
|
||||
}
|
||||
|
||||
public byte[] iconBytes() {
|
||||
return internal.iconBytes();
|
||||
}
|
||||
|
||||
public ServerStatus.Favicon toMojang() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -57,6 +57,11 @@ public class BridgedPlayer {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void disconnect(Component message) {
|
||||
if (isServerPlayer())
|
||||
toMojangServerPlayer().connection.disconnect(ChatUtils.adventureToMojang(message));
|
||||
}
|
||||
|
||||
public ServerPlayer toMojangServerPlayer() {
|
||||
return (ServerPlayer) internal;
|
||||
}
|
||||
|
Reference in New Issue
Block a user