diff options
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/server/commands/TimeCommand.java.patch')
-rw-r--r-- | patch-remap/mache-vineflower/net/minecraft/server/commands/TimeCommand.java.patch | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/server/commands/TimeCommand.java.patch b/patch-remap/mache-vineflower/net/minecraft/server/commands/TimeCommand.java.patch new file mode 100644 index 0000000000..21d1052b9d --- /dev/null +++ b/patch-remap/mache-vineflower/net/minecraft/server/commands/TimeCommand.java.patch @@ -0,0 +1,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; + } + } |