157 lines
12 KiB
Java
157 lines
12 KiB
Java
package net.minecraft.server.commands;
|
|
|
|
import com.mojang.brigadier.Message;
|
|
import net.minecraft.commands.SharedSuggestionProvider;
|
|
import java.util.concurrent.CompletableFuture;
|
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
|
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
|
import com.mojang.brigadier.context.CommandContext;
|
|
import net.minecraft.world.level.timers.FunctionCallback;
|
|
import net.minecraft.resources.ResourceLocation;
|
|
import net.minecraft.world.level.timers.TimerCallback;
|
|
import net.minecraft.world.level.timers.FunctionTagCallback;
|
|
import net.minecraft.world.level.timers.TimerQueue;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.network.chat.TranslatableComponent;
|
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
|
import net.minecraft.tags.Tag;
|
|
import net.minecraft.commands.CommandFunction;
|
|
import com.mojang.datafixers.util.Either;
|
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
|
import net.minecraft.commands.arguments.TimeArgument;
|
|
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
|
import com.mojang.brigadier.arguments.ArgumentType;
|
|
import net.minecraft.commands.arguments.item.FunctionArgument;
|
|
import net.minecraft.commands.Commands;
|
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
|
import com.mojang.brigadier.CommandDispatcher;
|
|
import net.minecraft.commands.CommandSourceStack;
|
|
import com.mojang.brigadier.suggestion.SuggestionProvider;
|
|
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
|
|
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
|
|
|
public class ScheduleCommand {
|
|
private static final SimpleCommandExceptionType ERROR_SAME_TICK;
|
|
private static final DynamicCommandExceptionType ERROR_CANT_REMOVE;
|
|
private static final SuggestionProvider<CommandSourceStack> SUGGEST_SCHEDULE;
|
|
|
|
public static void register(final CommandDispatcher<CommandSourceStack> commandDispatcher) {
|
|
commandDispatcher.register((LiteralArgumentBuilder)((LiteralArgumentBuilder)((LiteralArgumentBuilder)Commands.literal("schedule").requires(cq -> cq.hasPermission(2))).then(Commands.literal("function").then(Commands.argument("function", (com.mojang.brigadier.arguments.ArgumentType<Object>)FunctionArgument.functions()).suggests((SuggestionProvider)FunctionCommand.SUGGEST_FUNCTION).then(((RequiredArgumentBuilder)((RequiredArgumentBuilder)Commands.argument("time", (com.mojang.brigadier.arguments.ArgumentType<Object>)TimeArgument.time()).executes(commandContext -> schedule((CommandSourceStack)commandContext.getSource(), FunctionArgument.getFunctionOrTag((CommandContext<CommandSourceStack>)commandContext, "function"), IntegerArgumentType.getInteger(commandContext, "time"), true))).then(Commands.literal("append").executes(commandContext -> schedule((CommandSourceStack)commandContext.getSource(), FunctionArgument.getFunctionOrTag((CommandContext<CommandSourceStack>)commandContext, "function"), IntegerArgumentType.getInteger(commandContext, "time"), false)))).then(Commands.literal("replace").executes(commandContext -> schedule((CommandSourceStack)commandContext.getSource(), FunctionArgument.getFunctionOrTag((CommandContext<CommandSourceStack>)commandContext, "function"), IntegerArgumentType.getInteger(commandContext, "time"), true))))))).then(Commands.literal("clear").then(Commands.argument("function", (com.mojang.brigadier.arguments.ArgumentType<Object>)StringArgumentType.greedyString()).suggests((SuggestionProvider)ScheduleCommand.SUGGEST_SCHEDULE).executes(commandContext -> remove((CommandSourceStack)commandContext.getSource(), StringArgumentType.getString(commandContext, "function"))))));
|
|
}
|
|
|
|
private static int schedule(final CommandSourceStack cq, final Either<CommandFunction, Tag<CommandFunction>> either, final int integer, final boolean boolean4) throws CommandSyntaxException {
|
|
//
|
|
// This method could not be decompiled.
|
|
//
|
|
// Original Bytecode:
|
|
//
|
|
// 1: ifne 11
|
|
// 4: getstatic net/minecraft/server/commands/ScheduleCommand.ERROR_SAME_TICK:Lcom/mojang/brigadier/exceptions/SimpleCommandExceptionType;
|
|
// 7: invokevirtual com/mojang/brigadier/exceptions/SimpleCommandExceptionType.create:()Lcom/mojang/brigadier/exceptions/CommandSyntaxException;
|
|
// 10: athrow
|
|
// 11: aload_0 /* cq */
|
|
// 12: invokevirtual net/minecraft/commands/CommandSourceStack.getLevel:()Lnet/minecraft/server/level/ServerLevel;
|
|
// 15: invokevirtual net/minecraft/server/level/ServerLevel.getGameTime:()J
|
|
// 18: iload_2 /* integer */
|
|
// 19: i2l
|
|
// 20: ladd
|
|
// 21: lstore long5
|
|
// 23: aload_0 /* cq */
|
|
// 24: invokevirtual net/minecraft/commands/CommandSourceStack.getLevel:()Lnet/minecraft/server/level/ServerLevel;
|
|
// 27: invokevirtual net/minecraft/server/level/ServerLevel.getLevelData:()Lnet/minecraft/world/level/storage/LevelData;
|
|
// 30: invokevirtual net/minecraft/world/level/storage/LevelData.getScheduledEvents:()Lnet/minecraft/world/level/timers/TimerQueue;
|
|
// 33: astore cuz7
|
|
// 35: aload_1 /* either */
|
|
// 36: iload_3 /* boolean4 */
|
|
// 37: aload cuz7
|
|
// 39: lload long5
|
|
// 41: aload_0 /* cq */
|
|
// 42: iload_2 /* integer */
|
|
// 43: invokedynamic BootstrapMethod #5, accept:(ZLnet/minecraft/world/level/timers/TimerQueue;JLnet/minecraft/commands/CommandSourceStack;I)Ljava/util/function/Consumer;
|
|
// 48: invokevirtual com/mojang/datafixers/util/Either.ifLeft:(Ljava/util/function/Consumer;)Lcom/mojang/datafixers/util/Either;
|
|
// 51: iload_3 /* boolean4 */
|
|
// 52: aload cuz7
|
|
// 54: lload long5
|
|
// 56: aload_0 /* cq */
|
|
// 57: iload_2 /* integer */
|
|
// 58: invokedynamic BootstrapMethod #6, accept:(ZLnet/minecraft/world/level/timers/TimerQueue;JLnet/minecraft/commands/CommandSourceStack;I)Ljava/util/function/Consumer;
|
|
// 63: invokevirtual com/mojang/datafixers/util/Either.ifRight:(Ljava/util/function/Consumer;)Lcom/mojang/datafixers/util/Either;
|
|
// 66: pop
|
|
// 67: lload long5
|
|
// 69: ldc2_w 2147483647
|
|
// 72: invokestatic java/lang/Math.floorMod:(JJ)J
|
|
// 75: l2i
|
|
// 76: ireturn
|
|
// Exceptions:
|
|
// throws com.mojang.brigadier.exceptions.CommandSyntaxException
|
|
// Signature:
|
|
// (Lnet/minecraft/commands/CommandSourceStack;Lcom/mojang/datafixers/util/Either<Lnet/minecraft/commands/CommandFunction;Lnet/minecraft/tags/Tag<Lnet/minecraft/commands/CommandFunction;>;>;IZ)I
|
|
// MethodParameters:
|
|
// Name Flags
|
|
// -------- -----
|
|
// cq
|
|
// either
|
|
// integer
|
|
// boolean4
|
|
// StackMapTable: 00 01 0B
|
|
//
|
|
// The error that occurred was:
|
|
//
|
|
// java.lang.IllegalStateException: Could not infer any expression.
|
|
// at com.strobel.decompiler.ast.TypeAnalysis.runInference(TypeAnalysis.java:374)
|
|
// at com.strobel.decompiler.ast.TypeAnalysis.run(TypeAnalysis.java:96)
|
|
// at com.strobel.decompiler.ast.AstOptimizer.optimize(AstOptimizer.java:344)
|
|
// at com.strobel.decompiler.ast.AstOptimizer.optimize(AstOptimizer.java:42)
|
|
// at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.createMethodBody(AstMethodBodyBuilder.java:214)
|
|
// at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.createMethodBody(AstMethodBodyBuilder.java:99)
|
|
// at com.strobel.decompiler.languages.java.ast.AstBuilder.createMethodBody(AstBuilder.java:782)
|
|
// at com.strobel.decompiler.languages.java.ast.AstBuilder.createMethod(AstBuilder.java:675)
|
|
// at com.strobel.decompiler.languages.java.ast.AstBuilder.addTypeMembers(AstBuilder.java:552)
|
|
// at com.strobel.decompiler.languages.java.ast.AstBuilder.createTypeCore(AstBuilder.java:519)
|
|
// at com.strobel.decompiler.languages.java.ast.AstBuilder.createTypeNoCache(AstBuilder.java:161)
|
|
// at com.strobel.decompiler.languages.java.ast.AstBuilder.createType(AstBuilder.java:150)
|
|
// at com.strobel.decompiler.languages.java.ast.AstBuilder.addType(AstBuilder.java:125)
|
|
// at cuchaz.enigma.SourceProvider.getSources(SourceProvider.java:85)
|
|
// at cuchaz.enigma.EnigmaProject$JarExport.decompileClass(EnigmaProject.java:241)
|
|
// at cuchaz.enigma.EnigmaProject$JarExport.lambda$decompile$1(EnigmaProject.java:230)
|
|
// at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
|
|
// at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1654)
|
|
// at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
|
|
// at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
|
|
// at java.base/java.util.stream.ReduceOps$ReduceTask.doLeaf(ReduceOps.java:952)
|
|
// at java.base/java.util.stream.ReduceOps$ReduceTask.doLeaf(ReduceOps.java:926)
|
|
// at java.base/java.util.stream.AbstractTask.compute(AbstractTask.java:327)
|
|
// at java.base/java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:746)
|
|
// at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
|
|
// at java.base/java.util.concurrent.ForkJoinTask.doInvoke(ForkJoinTask.java:408)
|
|
// at java.base/java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:736)
|
|
// at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateParallel(ReduceOps.java:919)
|
|
// at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233)
|
|
// at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
|
|
// at cuchaz.enigma.EnigmaProject$JarExport.decompile(EnigmaProject.java:233)
|
|
// at cuchaz.enigma.command.DecompileCommand.run(DecompileCommand.java:35)
|
|
// at cuchaz.enigma.CommandMain.main(CommandMain.java:43)
|
|
//
|
|
throw new IllegalStateException("An error occurred while decompiling this method.");
|
|
}
|
|
|
|
private static int remove(final CommandSourceStack cq, final String string) throws CommandSyntaxException {
|
|
final int integer3 = cq.getLevel().getLevelData().getScheduledEvents().remove(string);
|
|
if (integer3 == 0) {
|
|
throw ScheduleCommand.ERROR_CANT_REMOVE.create(string);
|
|
}
|
|
cq.sendSuccess(new TranslatableComponent("commands.schedule.cleared.success", new Object[] { integer3, string }), true);
|
|
return integer3;
|
|
}
|
|
|
|
static {
|
|
ERROR_SAME_TICK = new SimpleCommandExceptionType((Message)new TranslatableComponent("commands.schedule.same_tick", new Object[0]));
|
|
final TranslatableComponent translatableComponent;
|
|
ERROR_CANT_REMOVE = new DynamicCommandExceptionType(object -> {
|
|
new TranslatableComponent("commands.schedule.cleared.failure", new Object[] { object });
|
|
return translatableComponent;
|
|
});
|
|
SUGGEST_SCHEDULE = ((commandContext, suggestionsBuilder) -> SharedSuggestionProvider.suggest(((CommandSourceStack)commandContext.getSource()).getLevel().getLevelData().getScheduledEvents().getEventsIds(), suggestionsBuilder));
|
|
}
|
|
}
|