aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-spigotflower/net/minecraft/server/commands/TimeCommand.java.patch
blob: b1383ee7718b3256ece26cb75f9b2562f331dad1 (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
--- a/net/minecraft/server/commands/TimeCommand.java
+++ b/net/minecraft/server/commands/TimeCommand.java
@@ -5,77 +5,92 @@
 import com.mojang.brigadier.builder.LiteralArgumentBuilder;
 import java.util.Iterator;
 import net.minecraft.commands.CommandSourceStack;
-import net.minecraft.commands.Commands;
 import net.minecraft.commands.arguments.TimeArgument;
 import net.minecraft.network.chat.Component;
 import net.minecraft.server.level.ServerLevel;
+// CraftBukkit start
+import org.bukkit.Bukkit;
+import org.bukkit.event.world.TimeSkipEvent;
+// CraftBukkit end
 
 public class TimeCommand {
 
     public TimeCommand() {}
 
-    public static void register(CommandDispatcher<CommandSourceStack> commanddispatcher) {
-        commanddispatcher.register((LiteralArgumentBuilder) ((LiteralArgumentBuilder) ((LiteralArgumentBuilder) ((LiteralArgumentBuilder) Commands.literal("time").requires((commandsourcestack) -> {
-            return commandsourcestack.hasPermission(2);
-        })).then(((LiteralArgumentBuilder) ((LiteralArgumentBuilder) ((LiteralArgumentBuilder) ((LiteralArgumentBuilder) Commands.literal("set").then(Commands.literal("day").executes((commandcontext) -> {
+    public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
+        dispatcher.register((LiteralArgumentBuilder) ((LiteralArgumentBuilder) ((LiteralArgumentBuilder) ((LiteralArgumentBuilder) net.minecraft.commands.Commands.literal("time").requires((commandlistenerwrapper) -> {
+            return commandlistenerwrapper.hasPermission(2);
+        })).then(((LiteralArgumentBuilder) ((LiteralArgumentBuilder) ((LiteralArgumentBuilder) ((LiteralArgumentBuilder) net.minecraft.commands.Commands.literal("set").then(net.minecraft.commands.Commands.literal("day").executes((commandcontext) -> {
             return setTime((CommandSourceStack) commandcontext.getSource(), 1000);
-        }))).then(Commands.literal("noon").executes((commandcontext) -> {
+        }))).then(net.minecraft.commands.Commands.literal("noon").executes((commandcontext) -> {
             return setTime((CommandSourceStack) commandcontext.getSource(), 6000);
-        }))).then(Commands.literal("night").executes((commandcontext) -> {
+        }))).then(net.minecraft.commands.Commands.literal("night").executes((commandcontext) -> {
             return setTime((CommandSourceStack) commandcontext.getSource(), 13000);
-        }))).then(Commands.literal("midnight").executes((commandcontext) -> {
+        }))).then(net.minecraft.commands.Commands.literal("midnight").executes((commandcontext) -> {
             return setTime((CommandSourceStack) commandcontext.getSource(), 18000);
-        }))).then(Commands.argument("time", TimeArgument.time()).executes((commandcontext) -> {
+        }))).then(net.minecraft.commands.Commands.argument("time", TimeArgument.time()).executes((commandcontext) -> {
             return setTime((CommandSourceStack) commandcontext.getSource(), IntegerArgumentType.getInteger(commandcontext, "time"));
-        })))).then(Commands.literal("add").then(Commands.argument("time", TimeArgument.time()).executes((commandcontext) -> {
+        })))).then(net.minecraft.commands.Commands.literal("add").then(net.minecraft.commands.Commands.argument("time", TimeArgument.time()).executes((commandcontext) -> {
             return addTime((CommandSourceStack) commandcontext.getSource(), IntegerArgumentType.getInteger(commandcontext, "time"));
-        })))).then(((LiteralArgumentBuilder) ((LiteralArgumentBuilder) Commands.literal("query").then(Commands.literal("daytime").executes((commandcontext) -> {
+        })))).then(((LiteralArgumentBuilder) ((LiteralArgumentBuilder) net.minecraft.commands.Commands.literal("query").then(net.minecraft.commands.Commands.literal("daytime").executes((commandcontext) -> {
             return queryTime((CommandSourceStack) commandcontext.getSource(), getDayTime(((CommandSourceStack) commandcontext.getSource()).getLevel()));
-        }))).then(Commands.literal("gametime").executes((commandcontext) -> {
+        }))).then(net.minecraft.commands.Commands.literal("gametime").executes((commandcontext) -> {
             return queryTime((CommandSourceStack) commandcontext.getSource(), (int) (((CommandSourceStack) commandcontext.getSource()).getLevel().getGameTime() % 2147483647L));
-        }))).then(Commands.literal("day").executes((commandcontext) -> {
+        }))).then(net.minecraft.commands.Commands.literal("day").executes((commandcontext) -> {
             return queryTime((CommandSourceStack) commandcontext.getSource(), (int) (((CommandSourceStack) commandcontext.getSource()).getLevel().getDayTime() / 24000L % 2147483647L));
         }))));
     }
 
-    private static int getDayTime(ServerLevel serverlevel) {
-        return (int) (serverlevel.getDayTime() % 24000L);
+    private static int getDayTime(ServerLevel level) {
+        return (int) (level.getDayTime() % 24000L);
     }
 
-    private static int queryTime(CommandSourceStack commandsourcestack, int i) {
-        commandsourcestack.sendSuccess(() -> {
-            return Component.translatable("commands.time.query", i);
+    private static int queryTime(CommandSourceStack source, int time) {
+        source.sendSuccess(() -> {
+            return Component.translatable("commands.time.query", time);
         }, false);
-        return i;
+        return time;
     }
 
-    public static int setTime(CommandSourceStack commandsourcestack, int i) {
-        Iterator iterator = commandsourcestack.getServer().getAllLevels().iterator();
+    public static int setTime(CommandSourceStack source, int time) {
+        Iterator iterator = com.google.common.collect.Iterators.singletonIterator(source.getLevel()); // CraftBukkit - SPIGOT-6496: Only set the time for the world the command originates in
 
         while (iterator.hasNext()) {
-            ServerLevel serverlevel = (ServerLevel) iterator.next();
+            ServerLevel worldserver = (ServerLevel) iterator.next();
 
-            serverlevel.setDayTime((long) i);
+            // CraftBukkit start
+            TimeSkipEvent event = new TimeSkipEvent(worldserver.getWorld(), TimeSkipEvent.SkipReason.COMMAND, time - worldserver.getDayTime());
+            Bukkit.getPluginManager().callEvent(event);
+            if (!event.isCancelled()) {
+                worldserver.setDayTime((long) worldserver.getDayTime() + event.getSkipAmount());
+            }
+            // CraftBukkit end
         }
 
-        commandsourcestack.sendSuccess(() -> {
-            return Component.translatable("commands.time.set", i);
+        source.sendSuccess(() -> {
+            return Component.translatable("commands.time.set", time);
         }, true);
-        return getDayTime(commandsourcestack.getLevel());
+        return getDayTime(source.getLevel());
     }
 
-    public static int addTime(CommandSourceStack commandsourcestack, int i) {
-        Iterator iterator = commandsourcestack.getServer().getAllLevels().iterator();
+    public static int addTime(CommandSourceStack source, int amount) {
+        Iterator iterator = com.google.common.collect.Iterators.singletonIterator(source.getLevel()); // CraftBukkit - SPIGOT-6496: Only set the time for the world the command originates in
 
         while (iterator.hasNext()) {
-            ServerLevel serverlevel = (ServerLevel) iterator.next();
+            ServerLevel worldserver = (ServerLevel) iterator.next();
 
-            serverlevel.setDayTime(serverlevel.getDayTime() + (long) i);
+            // CraftBukkit start
+            TimeSkipEvent event = new TimeSkipEvent(worldserver.getWorld(), TimeSkipEvent.SkipReason.COMMAND, amount);
+            Bukkit.getPluginManager().callEvent(event);
+            if (!event.isCancelled()) {
+                worldserver.setDayTime(worldserver.getDayTime() + event.getSkipAmount());
+            }
+            // CraftBukkit end
         }
 
-        int j = getDayTime(commandsourcestack.getLevel());
+        int j = getDayTime(source.getLevel());
 
-        commandsourcestack.sendSuccess(() -> {
+        source.sendSuccess(() -> {
             return Component.translatable("commands.time.set", j);
         }, true);
         return j;