CommandManager class
Пакет: com.hypixel.hytale.server.core.command.system
Файл: com/hypixel/hytale/server/core/command/system/CommandManager.java
implements: CommandOwner
Поля (31)
| Модификаторы | Тип | Имя |
|---|---|---|
final |
HytaleLogger |
LOGGER |
|
|
instance |
|
|
return |
|
|
return |
|
|
return |
|
|
return |
|
Map |
var1 |
|
List |
var10 |
|
ParserContext |
var11 |
|
AbstractOptionalArg |
var12 |
|
ArgCacheInvalidation |
var2 |
|
String |
var2 |
|
AbstractCommand |
var2 |
|
AbstractCommand |
var2 |
|
String |
var3 |
|
CompletableFuture |
var3 |
|
String |
var4 |
|
|
var4 |
|
ArgumentType |
var4 |
|
Thread |
var4 |
|
ArgumentType |
var5 |
|
String |
var5 |
|
ParseResult |
var5 |
|
Set |
var6 |
|
String |
var6 |
|
int |
var6 |
|
List |
var7 |
|
String |
var7 |
|
Message |
var7 |
|
AbstractCommand |
var8 |
|
CompletableFuture |
var8 |
Методы (21)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
abstract |
throw new |
IllegalArgumentExceptionthrow new IllegalArgumentException("Registered commands must define a name") |
public |
void |
broadcastArgCacheInvalidationvoid broadcastArgCacheInvalidation(@Nonnull String... var1) |
public |
Map<String, Set<String>> |
createVirtualPermissionGroupsMap<String, Set<String>> createVirtualPermissionGroups() |
|
|
for for(AbstractCommand.SuggestionOverrideEntry var13 : var7) |
static |
CommandManager |
getCommandManager get() |
|
|
if if(var7 instanceof GeneralCommandException var5) |
|
|
if if(var6 != null) |
|
|
if if(var2 != null) |
|
|
if if(var7 != null) |
|
|
if if(var2 != null) |
|
|
if if(var8 != null) |
|
|
if if(var8 != null) |
|
|
if if(var4x != null) |
|
|
if if(var9 instanceof CommandException var6) |
|
|
if if(var0 instanceof CommandException) |
static |
boolean |
isInternalExceptionboolean isInternalException(@Nonnull Throwable var0) |
private |
void |
registerArgTypesvoid registerArgTypes(@Nonnull AbstractCommand var1) |
public |
void |
registerCommandsvoid registerCommands() |
public |
void |
registerSystemCommandvoid registerSystemCommand(@Nonnull AbstractCommand var1) |
private |
void |
runCommandvoid runCommand(@Nonnull CommandSender var1, @Nonnull String var2, @Nonnull AbstractCommand var3, @Nonnull CompletableFuture<Void> var4) |
public |
void |
shutdownvoid shutdown() |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.command.system;
class="kw">import com.hypixel.hytale.common.util.CompletableFutureUtil;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
class="kw">import com.hypixel.hytale.logger.sentry.SkipSentryException;
class="kw">import com.hypixel.hytale.protocol.packets.interface_.ArgCacheInvalidation;
class="kw">import com.hypixel.hytale.protocol.packets.interface_.CommandTreeSync;
class="kw">import com.hypixel.hytale.server.core.Message;
class="kw">import com.hypixel.hytale.server.core.asset.type.particle.commands.ParticleCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.debug.AssetsCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.debug.DebugPlayerPositionCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.debug.HitDetectionCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.debug.HudManagerTestCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.debug.LogCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.debug.MessageTranslationTestCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.debug.PIDCheckCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.debug.PacketStatsCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.debug.PingCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.debug.ShowBuilderToolsHudCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.debug.StopNetworkChunkSendingCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.debug.TagPatternCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.debug.VersionCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.debug.component.hitboxcollision.HitboxCollisionCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.debug.component.knockback.KnockbackCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.debug.component.repulsion.RepulsionCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.debug.packs.PacksCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.debug.server.ServerCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.player.DamageCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.player.GameModeCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.player.HideCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.player.KillCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.player.PlayerCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.player.ReferCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.player.SpectateCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.player.SudoCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.player.ToggleBlockPlacementOverrideCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.player.WhereAmICommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.player.WhoAmICommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.player.inventory.GiveCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.player.inventory.InventoryCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.player.inventory.ItemStateCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.server.KickCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.server.MaxPlayersCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.server.MaxViewRadiusCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.server.StopCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.server.WhoCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.server.auth.AuthCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.utility.BackupCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.utility.ConvertPrefabsCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.utility.EventTitleCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.utility.NotifyCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.utility.StashCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.utility.UIGalleryCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.utility.ValidateCPBCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.utility.help.HelpCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.utility.lighting.LightingCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.utility.metacommands.CommandsCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.utility.net.NetworkCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.utility.sleep.SleepCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.utility.sound.SoundCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.utility.worldmap.WorldMapCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.world.SpawnBlockCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.world.chunk.ChunkCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.world.entity.EntityCommand;
class="kw">import com.hypixel.hytale.server.core.command.commands.world.worldgen.WorldGenCommand;
class="kw">import com.hypixel.hytale.server.core.command.system.arguments.system.AbstractOptionalArg;
class="kw">import com.hypixel.hytale.server.core.command.system.arguments.system.Argument;
class="kw">import com.hypixel.hytale.server.core.command.system.arguments.system.FlagArg;
class="kw">import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
class="kw">import com.hypixel.hytale.server.core.command.system.arguments.types.ArgumentType;
class="kw">import com.hypixel.hytale.server.core.command.system.exceptions.CommandException;
class="kw">import com.hypixel.hytale.server.core.command.system.exceptions.GeneralCommandException;
class="kw">import com.hypixel.hytale.server.core.universe.Universe;
class="kw">import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
class="kw">import java.util.Deque;
class="kw">import java.util.HashSet;
class="kw">import java.util.List;
class="kw">import java.util.Locale;
class="kw">import java.util.Map;
class="kw">import java.util.Objects;
class="kw">import java.util.Set;
class="kw">import java.util.Map.Entry;
class="kw">import java.util.concurrent.CompletableFuture;
class="kw">import java.util.concurrent.CompletionException;
class="kw">import java.util.concurrent.ForkJoinPool;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">public class CommandManager class="kw">implements CommandOwner {
class="kw">private class="kw">static class="kw">final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass();
class="kw">private class="kw">static CommandManager instance;
class="kw">private class="kw">final Map<String, AbstractCommand> commandRegistration = new Object2ObjectOpenHashMap();
class="kw">private class="kw">final Map<String, String> aliases = new Object2ObjectOpenHashMap();
class="kw">private class="kw">final Map<String, ArgumentType<?>> argTypeRegistry = new Object2ObjectOpenHashMap();
class="kw">private class="kw">final CommandTreeBuilder commandTreeBuilder = new CommandTreeBuilder();
class="kw">public class="kw">static CommandManager get() {
class="kw">return instance;
}
class="kw">public CommandManager() {
instance = this;
}
class="kw">public void shutdown() {
this.aliases.clear();
}
@Nullable
class="kw">public ArgumentType<?> getArgTypeById(@Nonnull String var1) {
class="kw">return this.argTypeRegistry.get(var1);
}
class="kw">public void broadcastArgCacheInvalidation(@Nonnull String... var1) {
ArgCacheInvalidation var2 = new ArgCacheInvalidation();
var2.argTypeIds = var1;
Universe.get().broadcastPacket(var2);
}
@Nonnull
class="kw">public Map<String, AbstractCommand> getCommandRegistration() {
class="kw">return this.commandRegistration;
}
class="kw">public void registerCommands() {
this.registerSystemCommand(new ChunkCommand());
this.registerSystemCommand(new LogCommand());
this.registerSystemCommand(new PIDCheckCommand());
this.registerSystemCommand(new PingCommand());
this.registerSystemCommand(new WorldGenCommand());
this.registerSystemCommand(new HitDetectionCommand());
this.registerSystemCommand(new PacketStatsCommand());
this.registerSystemCommand(new AssetsCommand());
this.registerSystemCommand(new PacksCommand());
this.registerSystemCommand(new ServerCommand());
this.registerSystemCommand(new HitboxCollisionCommand());
this.registerSystemCommand(new DebugPlayerPositionCommand());
this.registerSystemCommand(new MessageTranslationTestCommand());
this.registerSystemCommand(new HudManagerTestCommand());
this.registerSystemCommand(new RepulsionCommand());
this.registerSystemCommand(new KnockbackCommand());
this.registerSystemCommand(new StopNetworkChunkSendingCommand());
this.registerSystemCommand(new ShowBuilderToolsHudCommand());
this.registerSystemCommand(new VersionCommand());
this.registerSystemCommand(new ParticleCommand());
this.registerSystemCommand(new TagPatternCommand());
this.registerSystemCommand(new GameModeCommand());
this.registerSystemCommand(new HideCommand());
this.registerSystemCommand(new SpectateCommand());
this.registerSystemCommand(new KillCommand());
this.registerSystemCommand(new DamageCommand());
this.registerSystemCommand(new SudoCommand());
this.registerSystemCommand(new WhereAmICommand());
this.registerSystemCommand(new WhoAmICommand());
this.registerSystemCommand(new ReferCommand());
this.registerSystemCommand(new ToggleBlockPlacementOverrideCommand());
this.registerSystemCommand(new GiveCommand());
this.registerSystemCommand(new InventoryCommand());
this.registerSystemCommand(new ItemStateCommand());
this.registerSystemCommand(new AuthCommand());
this.registerSystemCommand(new KickCommand());
this.registerSystemCommand(new MaxPlayersCommand());
this.registerSystemCommand(new MaxViewRadiusCommand());
this.registerSystemCommand(new StopCommand());
this.registerSystemCommand(new WhoCommand());
this.registerSystemCommand(new BackupCommand());
this.registerSystemCommand(new ConvertPrefabsCommand());
this.registerSystemCommand(new HelpCommand());
this.registerSystemCommand(new NotifyCommand());
this.registerSystemCommand(new EventTitleCommand());
this.registerSystemCommand(new ValidateCPBCommand());
this.registerSystemCommand(new WorldMapCommand());
this.registerSystemCommand(new SoundCommand());
this.registerSystemCommand(new StashCommand());
this.registerSystemCommand(new SpawnBlockCommand());
this.registerSystemCommand(new EntityCommand());
this.registerSystemCommand(new PlayerCommand());
this.registerSystemCommand(new LightingCommand());
this.registerSystemCommand(new SleepCommand());
this.registerSystemCommand(new NetworkCommand());
this.registerSystemCommand(new CommandsCommand());
this.registerSystemCommand(new UIGalleryCommand());
}
class="kw">public Map<String, Set<String>> createVirtualPermissionGroups() {
Map var1 = new Object2ObjectOpenHashMap();
for (AbstractCommand var3 : this.commandRegistration.values()) {
for (Entry var5 : var3.getPermissionGroupsRecursive().entrySet()) {
Set var6 = var1.computeIfAbsent(var5.getKey(), var0 -> new HashSet<>());
var6.addAll(var5.getValue());
}
}
class="kw">return var1;
}
class="kw">public void registerSystemCommand(@Nonnull AbstractCommand var1) {
var1.setOwner(this);
this.register(var1);
}
@Nullable
class="kw">public CommandRegistration register(@Nonnull AbstractCommand var1) {
String var2 = var1.getName();
if (var2 != null && !var2.isEmpty()) {
this.commandRegistration.put(var1.getName(), var1);
try {
var1.completeRegistration();
} catch (Exception var7) {
String var4 = var7.getMessage();
if (var7 class="kw">instanceof GeneralCommandException var5) {
String var6 = var5.getMessageText();
if (var6 != null) {
var4 = var6;
}
}
((HytaleLogger.Api)HytaleLogger.getLogger().at(Level.SEVERE).withCause(var7))
.log("Failed to register command: %s%s", var1.getName(), var4 != null ? " - " + var4 : "");
this.commandRegistration.remove(var2, var1);
class="kw">return null;
}
for (String var8 : var1.getAliases()) {
this.aliases.put(var8, var2);
}
this.registerArgTypes(var1);
class="kw">return new CommandRegistration(var1, () -> true, () -> {
AbstractCommand var2 = this.commandRegistration.remove(var2);
if (var2 != null) {
for (String var4 : var2.getAliases()) {
this.aliases.remove(var4);
}
}
});
} else {
throw new IllegalArgumentException("Registered commands must define a name");
}
}
class="kw">private void registerArgTypes(@Nonnull AbstractCommand var1) {
for (RequiredArg var3 : var1.getRequiredArguments()) {
ArgumentType var4 = var3.getArgumentType();
this.argTypeRegistry.putIfAbsent(var4.getSuggestionTypeId(), var4);
}
for (Entry var8 : var1.getOptionalArguments().entrySet()) {
AbstractOptionalArg var12 = (AbstractOptionalArg<? class="kw">extends Argument<?, ?>, ?>)var8.getValue();
if (!(var12 class="kw">instanceof FlagArg)) {
ArgumentType var5 = var12.getArgumentType();
this.argTypeRegistry.putIfAbsent(var5.getSuggestionTypeId(), var5);
}
}
List var7 = var1.getSuggestionOverrides();
if (var7 != null) {
for (AbstractCommand.SuggestionOverrideEntry var13 : var7) {
this.argTypeRegistry.putIfAbsent(var13.argTypeId(), var13.overrideType());
}
}
for (AbstractCommand var14 : var1.getVariantCommands()) {
this.registerArgTypes(var14);
}
for (AbstractCommand var15 : var1.getSubCommands().values()) {
this.registerArgTypes(var15);
}
}
@Nonnull
class="kw">public CommandTreeSync buildCommandTree(@Nonnull CommandSender var1) {
class="kw">return this.commandTreeBuilder.build(var1, this.commandRegistration.values());
}
@Nullable
class="kw">public AbstractCommand resolveCommand(@Nonnull String var1) {
AbstractCommand var2 = this.commandRegistration.get(var1);
if (var2 != null) {
class="kw">return var2;
}
String var3 = this.aliases.get(var1);
class="kw">return var3 != null ? this.commandRegistration.get(var3) : null;
}
@Nonnull
class="kw">public List<String> suggestCompletions(@Nonnull CommandSender var1, @Nonnull List<String> var2, int var3) {
class="kw">return CommandCompletion.suggest(var1, this.commandRegistration.values(), this::resolveCommand, var2, var3);
}
@Nonnull
class="kw">public CompletableFuture<Void> handleCommand(@Nonnull CommandSender var1, @Nonnull String var2) {
Objects.requireNonNull(var1, "Command sender must not be null!");
Objects.requireNonNull(var2, "Command must not be null!");
CompletableFuture var3 = new CompletableFuture<>();
ForkJoinPool.commonPool().execute(() -> {
Thread var4 = Thread.currentThread();
String var5 = var4.getName();
var4.setName(var5 + " -- Running: " + var2);
try {
LOGGER.at(Level.FINE).log("%s sent command: %s", var1.getUsername(), var2);
int var6 = var2.indexOf(32);
String var7 = (var6 < 0 ? var2 : var2.substring(0, var6)).toLowerCase(Locale.ROOT);
AbstractCommand var8 = this.resolveCommand(var7);
if (var8 != null) {
this.runCommand(var1, var2, var8, var3);
class="kw">return;
}
var1.sendMessage(Message.translation("server.modules.command.notFound").param("cmd", var2));
var3.complete(null);
} class="kw">finally {
var4.setName(var5);
}
});
class="kw">return var3;
}
class="kw">private void runCommand(@Nonnull CommandSender var1, @Nonnull String var2, @Nonnull AbstractCommand var3, @Nonnull CompletableFuture<Void> var4) {
try {
LOGGER.at(Level.INFO).log("%s executed command: %s", var1.getUsername(), var2);
ParseResult var5 = new ParseResult();
List var10 = Tokenizer.parseArguments(var2, var5);
if (var5.failed()) {
var5.sendMessages(var1);
var4.complete(null);
class="kw">return;
}
ParserContext var11 = ParserContext.of(var10, var2, var5);
if (var5.failed()) {
var5.sendMessages(var1);
var4.complete(null);
class="kw">return;
}
CompletableFuture var8 = var3.acceptCall(var1, var11, var5);
if (var5.failed()) {
var5.sendMessages(var1);
var4.complete(null);
class="kw">return;
}
if (var8 != null) {
var8.whenComplete(
(var3x, var4x) -> {
if (var4x != null) {
if (!CompletableFutureUtil.isCanceled(var4x) && !isInternalException(var4x)) {
((HytaleLogger.Api)LOGGER.at(Level.SEVERE).withCause(new SkipSentryException(var4x)))
.log("Failed to execute command %s for %s", var2, var1.getUsername());
var1.sendMessage(Message.translation("server.modules.command.error").param("cmd", var2).param("msg", var4x.getMessage()));
}
var4.completeExceptionally(var4x);
} else {
var4.complete(null);
}
}
);
} else {
var4.complete(null);
}
} catch (Throwable var9) {
if (var9 class="kw">instanceof CommandException var6) {
var6.sendTranslatedMessage(var1);
} else {
((HytaleLogger.Api)LOGGER.at(Level.SEVERE).withCause(var9)).log("Failed to execute command %s for %s", var2, var1.getUsername());
Message var7 = var9.getMessage() == null
? Message.translation("server.modules.command.noProvidedExceptionMessage")
: Message.raw(var9.getMessage());
var1.sendMessage(Message.translation("server.modules.command.error").param("cmd", var2).param("msg", var7));
}
var4.completeExceptionally(var9);
}
}
class="kw">private class="kw">static boolean isInternalException(@Nonnull Throwable var0) {
if (var0 class="kw">instanceof CommandException) {
class="kw">return true;
} else {
class="kw">return var0 class="kw">instanceof CompletionException && var0.getCause() != null && var0.getCause() != var0 ? isInternalException(var0.getCause()) : false;
}
}
@Nonnull
class="kw">public CompletableFuture<Void> handleCommands(@Nonnull CommandSender var1, @Nonnull Deque<String> var2) {
class="kw">return this.handleCommands0(var1, var2);
}
@Nonnull
class="kw">private CompletableFuture<Void> handleCommands0(@Nonnull CommandSender var1, @Nonnull Deque<String> var2) {
class="kw">return var2.isEmpty()
? CompletableFuture.completedFuture(null)
: this.handleCommand(var1, var2.poll()).thenCompose(var3 -> this.handleCommands0(var1, var2));
}
@Nonnull
@Override
class="kw">public String getName() {
class="kw">return "HytaleServer";
}
}