--- a/net/minecraft/server/commands/TimeCommand.java +++ b/net/minecraft/server/commands/TimeCommand.java @@ -8,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,12 +53,18 @@ } public static int setTime(CommandSourceStack source, int time) { - Iterator iterator = source.getServer().getAllLevels().iterator(); + 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(); - worldserver.setDayTime((long) time); + // 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.getServer().forceTimeSynchronization(); @@ -65,12 +75,18 @@ } public static int addTime(CommandSourceStack source, int time) { - Iterator iterator = source.getServer().getAllLevels().iterator(); + 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(); - worldserver.setDayTime(worldserver.getDayTime() + (long) time); + // CraftBukkit start + TimeSkipEvent event = new TimeSkipEvent(worldserver.getWorld(), TimeSkipEvent.SkipReason.COMMAND, time); + Bukkit.getPluginManager().callEvent(event); + if (!event.isCancelled()) { + worldserver.setDayTime(worldserver.getDayTime() + event.getSkipAmount()); + } + // CraftBukkit end } source.getServer().forceTimeSynchronization();