aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower/net/minecraft/server/commands/ScheduleCommand.java.patch
blob: e63f3cfbfafc57cce9f121213ca4a30ffb6a3ae6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
--- a/net/minecraft/server/commands/ScheduleCommand.java
+++ b/net/minecraft/server/commands/ScheduleCommand.java
@@ -3,21 +3,19 @@
 import com.mojang.brigadier.CommandDispatcher;
 import com.mojang.brigadier.arguments.IntegerArgumentType;
 import com.mojang.brigadier.arguments.StringArgumentType;
-import com.mojang.brigadier.context.CommandContext;
+import com.mojang.brigadier.builder.LiteralArgumentBuilder;
+import com.mojang.brigadier.builder.RequiredArgumentBuilder;
 import com.mojang.brigadier.exceptions.CommandSyntaxException;
 import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
 import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
 import com.mojang.brigadier.suggestion.SuggestionProvider;
-import com.mojang.brigadier.suggestion.SuggestionsBuilder;
 import com.mojang.datafixers.util.Either;
 import com.mojang.datafixers.util.Pair;
 import java.util.Collection;
 import net.minecraft.commands.CommandSourceStack;
-import net.minecraft.commands.Commands;
 import net.minecraft.commands.SharedSuggestionProvider;
 import net.minecraft.commands.arguments.TimeArgument;
 import net.minecraft.commands.arguments.item.FunctionArgument;
-import net.minecraft.commands.functions.CommandFunction;
 import net.minecraft.network.chat.Component;
 import net.minecraft.resources.ResourceLocation;
 import net.minecraft.server.MinecraftServer;
@@ -26,114 +24,75 @@
 import net.minecraft.world.level.timers.TimerQueue;
 
 public class ScheduleCommand {
+
     private static final SimpleCommandExceptionType ERROR_SAME_TICK = new SimpleCommandExceptionType(Component.translatable("commands.schedule.same_tick"));
-    private static final DynamicCommandExceptionType ERROR_CANT_REMOVE = new DynamicCommandExceptionType(
-        functionName -> Component.translatableEscape("commands.schedule.cleared.failure", functionName)
-    );
-    private static final SuggestionProvider<CommandSourceStack> SUGGEST_SCHEDULE = (context, builder) -> SharedSuggestionProvider.suggest(
-            context.getSource().getServer().getWorldData().overworldData().getScheduledEvents().getEventsIds(), builder
-        );
+    private static final DynamicCommandExceptionType ERROR_CANT_REMOVE = new DynamicCommandExceptionType((object) -> {
+        return Component.translatableEscape("commands.schedule.cleared.failure", object);
+    });
+    private static final SuggestionProvider<CommandSourceStack> SUGGEST_SCHEDULE = (commandcontext, suggestionsbuilder) -> {
+        return SharedSuggestionProvider.suggest((Iterable) ((CommandSourceStack) commandcontext.getSource()).getServer().getWorldData().overworldData().getScheduledEvents().getEventsIds(), suggestionsbuilder);
+    };
 
+    public ScheduleCommand() {}
+
     public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
-        dispatcher.register(
-            Commands.literal("schedule")
-                .requires(source -> source.hasPermission(2))
-                .then(
-                    Commands.literal("function")
-                        .then(
-                            Commands.argument("function", FunctionArgument.functions())
-                                .suggests(FunctionCommand.SUGGEST_FUNCTION)
-                                .then(
-                                    Commands.argument("time", TimeArgument.time())
-                                        .executes(
-                                            context -> schedule(
-                                                    context.getSource(),
-                                                    FunctionArgument.getFunctionOrTag(context, "function"),
-                                                    IntegerArgumentType.getInteger(context, "time"),
-                                                    true
-                                                )
-                                        )
-                                        .then(
-                                            Commands.literal("append")
-                                                .executes(
-                                                    context -> schedule(
-                                                            context.getSource(),
-                                                            FunctionArgument.getFunctionOrTag(context, "function"),
-                                                            IntegerArgumentType.getInteger(context, "time"),
-                                                            false
-                                                        )
-                                                )
-                                        )
-                                        .then(
-                                            Commands.literal("replace")
-                                                .executes(
-                                                    context -> schedule(
-                                                            context.getSource(),
-                                                            FunctionArgument.getFunctionOrTag(context, "function"),
-                                                            IntegerArgumentType.getInteger(context, "time"),
-                                                            true
-                                                        )
-                                                )
-                                        )
-                                )
-                        )
-                )
-                .then(
-                    Commands.literal("clear")
-                        .then(
-                            Commands.argument("function", StringArgumentType.greedyString())
-                                .suggests(SUGGEST_SCHEDULE)
-                                .executes(context -> remove(context.getSource(), StringArgumentType.getString(context, "function")))
-                        )
-                )
-        );
+        dispatcher.register((LiteralArgumentBuilder) ((LiteralArgumentBuilder) ((LiteralArgumentBuilder) net.minecraft.commands.Commands.literal("schedule").requires((commandlistenerwrapper) -> {
+            return commandlistenerwrapper.hasPermission(2);
+        })).then(net.minecraft.commands.Commands.literal("function").then(net.minecraft.commands.Commands.argument("function", FunctionArgument.functions()).suggests(FunctionCommand.SUGGEST_FUNCTION).then(((RequiredArgumentBuilder) ((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("time", TimeArgument.time()).executes((commandcontext) -> {
+            return schedule((CommandSourceStack) commandcontext.getSource(), FunctionArgument.getFunctionOrTag(commandcontext, "function"), IntegerArgumentType.getInteger(commandcontext, "time"), true);
+        })).then(net.minecraft.commands.Commands.literal("append").executes((commandcontext) -> {
+            return schedule((CommandSourceStack) commandcontext.getSource(), FunctionArgument.getFunctionOrTag(commandcontext, "function"), IntegerArgumentType.getInteger(commandcontext, "time"), false);
+        }))).then(net.minecraft.commands.Commands.literal("replace").executes((commandcontext) -> {
+            return schedule((CommandSourceStack) commandcontext.getSource(), FunctionArgument.getFunctionOrTag(commandcontext, "function"), IntegerArgumentType.getInteger(commandcontext, "time"), true);
+        })))))).then(net.minecraft.commands.Commands.literal("clear").then(net.minecraft.commands.Commands.argument("function", StringArgumentType.greedyString()).suggests(ScheduleCommand.SUGGEST_SCHEDULE).executes((commandcontext) -> {
+            return remove((CommandSourceStack) commandcontext.getSource(), StringArgumentType.getString(commandcontext, "function"));
+        }))));
     }
 
-    private static int schedule(
-        CommandSourceStack source,
-        Pair<ResourceLocation, Either<CommandFunction<CommandSourceStack>, Collection<CommandFunction<CommandSourceStack>>>> function,
-        int time,
-        boolean append
-    ) throws CommandSyntaxException {
+    private static int schedule(CommandSourceStack source, Pair<ResourceLocation, Either<net.minecraft.commands.functions.CommandFunction<CommandSourceStack>, Collection<net.minecraft.commands.functions.CommandFunction<CommandSourceStack>>>> function, int time, boolean append) throws CommandSyntaxException {
         if (time == 0) {
-            throw ERROR_SAME_TICK.create();
+            throw ScheduleCommand.ERROR_SAME_TICK.create();
         } else {
-            long l = source.getLevel().getGameTime() + (long)time;
-            ResourceLocation resourceLocation = function.getFirst();
-            TimerQueue<MinecraftServer> scheduledEvents = source.getServer().getWorldData().overworldData().getScheduledEvents();
-            function.getSecond()
-                .ifLeft(
-                    commandFunction -> {
-                        String string = resourceLocation.toString();
-                        if (append) {
-                            scheduledEvents.remove(string);
-                        }
-        
-                        scheduledEvents.schedule(string, l, new FunctionCallback(resourceLocation));
-                        source.sendSuccess(
-                            () -> Component.translatable("commands.schedule.created.function", Component.translationArg(resourceLocation), time, l), true
-                        );
-                    }
-                )
-                .ifRight(functions -> {
-                    String string = "#" + resourceLocation;
-                    if (append) {
-                        scheduledEvents.remove(string);
-                    }
-    
-                    scheduledEvents.schedule(string, l, new FunctionTagCallback(resourceLocation));
-                    source.sendSuccess(() -> Component.translatable("commands.schedule.created.tag", Component.translationArg(resourceLocation), time, l), true);
-                });
-            return Math.floorMod(l, Integer.MAX_VALUE);
+            long j = source.getLevel().getGameTime() + (long) time;
+            ResourceLocation minecraftkey = (ResourceLocation) function.getFirst();
+            TimerQueue<MinecraftServer> customfunctioncallbacktimerqueue = source.getLevel().serverLevelData.overworldData().getScheduledEvents(); // CraftBukkit - SPIGOT-6667: Use world specific function timer
+
+            ((Either) function.getSecond()).ifLeft((net_minecraft_commands_functions_commandfunction) -> {
+                String s = minecraftkey.toString();
+
+                if (append) {
+                    customfunctioncallbacktimerqueue.remove(s);
+                }
+
+                customfunctioncallbacktimerqueue.schedule(s, j, new FunctionCallback(minecraftkey));
+                source.sendSuccess(() -> {
+                    return Component.translatable("commands.schedule.created.function", Component.translationArg(minecraftkey), time, j);
+                }, true);
+            }).ifRight((collection) -> {
+                String s = "#" + minecraftkey;
+
+                if (append) {
+                    customfunctioncallbacktimerqueue.remove(s);
+                }
+
+                customfunctioncallbacktimerqueue.schedule(s, j, new FunctionTagCallback(minecraftkey));
+                source.sendSuccess(() -> {
+                    return Component.translatable("commands.schedule.created.tag", Component.translationArg(minecraftkey), time, j);
+                }, true);
+            });
+            return Math.floorMod(j, Integer.MAX_VALUE);
         }
     }
 
     private static int remove(CommandSourceStack source, String function) throws CommandSyntaxException {
         int i = source.getServer().getWorldData().overworldData().getScheduledEvents().remove(function);
+
         if (i == 0) {
-            throw ERROR_CANT_REMOVE.create(function);
+            throw ScheduleCommand.ERROR_CANT_REMOVE.create(function);
         } else {
-            source.sendSuccess(() -> Component.translatable("commands.schedule.cleared.success", i, function), true);
+            source.sendSuccess(() -> {
+                return Component.translatable("commands.schedule.cleared.success", i, function);
+            }, true);
             return i;
         }
     }