aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-spigotflower-stripped/net/minecraft/server/commands/TimeCommand.java.patch
blob: ad1b09041f281684a5b1c840489e0f4759279080 (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
--- a/net/minecraft/server/commands/TimeCommand.java
+++ b/net/minecraft/server/commands/TimeCommand.java
@@ -9,6 +8,10 @@
 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 {
 
@@ -49,13 +52,19 @@
         return i;
     }
 
-    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.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(() -> {
@@ -64,13 +73,19 @@
         return getDayTime(commandsourcestack.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.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());