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
|
--- a/net/minecraft/server/commands/TimeCommand.java
+++ b/net/minecraft/server/commands/TimeCommand.java
@@ -2,76 +2,97 @@
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
-import com.mojang.brigadier.context.CommandContext;
+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> dispatcher) {
- dispatcher.register(
- Commands.literal("time")
- .requires(source -> source.hasPermission(2))
- .then(
- Commands.literal("set")
- .then(Commands.literal("day").executes(context -> setTime(context.getSource(), 1000)))
- .then(Commands.literal("noon").executes(context -> setTime(context.getSource(), 6000)))
- .then(Commands.literal("night").executes(context -> setTime(context.getSource(), 13000)))
- .then(Commands.literal("midnight").executes(context -> setTime(context.getSource(), 18000)))
- .then(
- Commands.argument("time", TimeArgument.time())
- .executes(context -> setTime(context.getSource(), IntegerArgumentType.getInteger(context, "time")))
- )
- )
- .then(
- Commands.literal("add")
- .then(
- Commands.argument("time", TimeArgument.time())
- .executes(context -> addTime(context.getSource(), IntegerArgumentType.getInteger(context, "time")))
- )
- )
- .then(
- Commands.literal("query")
- .then(Commands.literal("daytime").executes(context -> queryTime(context.getSource(), getDayTime(context.getSource().getLevel()))))
- .then(
- Commands.literal("gametime")
- .executes(context -> queryTime(context.getSource(), (int)(context.getSource().getLevel().getGameTime() % 2147483647L)))
- )
- .then(
- Commands.literal("day")
- .executes(context -> queryTime(context.getSource(), (int)(context.getSource().getLevel().getDayTime() / 24000L % 2147483647L)))
- )
- )
- );
+ 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(net.minecraft.commands.Commands.literal("noon").executes((commandcontext) -> {
+ return setTime((CommandSourceStack) commandcontext.getSource(), 6000);
+ }))).then(net.minecraft.commands.Commands.literal("night").executes((commandcontext) -> {
+ return setTime((CommandSourceStack) commandcontext.getSource(), 13000);
+ }))).then(net.minecraft.commands.Commands.literal("midnight").executes((commandcontext) -> {
+ return setTime((CommandSourceStack) commandcontext.getSource(), 18000);
+ }))).then(net.minecraft.commands.Commands.argument("time", TimeArgument.time()).executes((commandcontext) -> {
+ return setTime((CommandSourceStack) commandcontext.getSource(), IntegerArgumentType.getInteger(commandcontext, "time"));
+ })))).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) 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(net.minecraft.commands.Commands.literal("gametime").executes((commandcontext) -> {
+ return queryTime((CommandSourceStack) commandcontext.getSource(), (int) (((CommandSourceStack) commandcontext.getSource()).getLevel().getGameTime() % 2147483647L));
+ }))).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 level) {
- return (int)(level.getDayTime() % 24000L);
+ return (int) (level.getDayTime() % 24000L);
}
private static int queryTime(CommandSourceStack source, int time) {
- source.sendSuccess(() -> Component.translatable("commands.time.query", time), false);
+ source.sendSuccess(() -> {
+ return Component.translatable("commands.time.query", time);
+ }, false);
return time;
}
public static int setTime(CommandSourceStack source, int time) {
- for (ServerLevel serverLevel : source.getServer().getAllLevels()) {
- serverLevel.setDayTime((long)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 worldserver = (ServerLevel) iterator.next();
+
+ // 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
}
- source.sendSuccess(() -> Component.translatable("commands.time.set", time), true);
+ source.sendSuccess(() -> {
+ return Component.translatable("commands.time.set", time);
+ }, true);
return getDayTime(source.getLevel());
}
public static int addTime(CommandSourceStack source, int amount) {
- for (ServerLevel serverLevel : source.getServer().getAllLevels()) {
- serverLevel.setDayTime(serverLevel.getDayTime() + (long)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 worldserver = (ServerLevel) iterator.next();
+
+ // 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 dayTime = getDayTime(source.getLevel());
- source.sendSuccess(() -> Component.translatable("commands.time.set", dayTime), true);
- return dayTime;
+ int j = getDayTime(source.getLevel());
+
+ source.sendSuccess(() -> {
+ return Component.translatable("commands.time.set", j);
+ }, true);
+ return j;
}
}
|