56 lines
3.8 KiB
Java
56 lines
3.8 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* com.mojang.brigadier.CommandDispatcher
|
|
* com.mojang.brigadier.arguments.IntegerArgumentType
|
|
* com.mojang.brigadier.builder.LiteralArgumentBuilder
|
|
* com.mojang.brigadier.context.CommandContext
|
|
*/
|
|
package net.minecraft.server.commands;
|
|
|
|
import com.mojang.brigadier.CommandDispatcher;
|
|
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
|
import com.mojang.brigadier.context.CommandContext;
|
|
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;
|
|
|
|
public class TimeCommand {
|
|
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
|
dispatcher.register((LiteralArgumentBuilder)((LiteralArgumentBuilder)((LiteralArgumentBuilder)((LiteralArgumentBuilder)Commands.literal("time").requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS))).then(((LiteralArgumentBuilder)((LiteralArgumentBuilder)((LiteralArgumentBuilder)((LiteralArgumentBuilder)Commands.literal("set").then(Commands.literal("day").executes(c -> TimeCommand.setTime((CommandSourceStack)c.getSource(), 1000)))).then(Commands.literal("noon").executes(c -> TimeCommand.setTime((CommandSourceStack)c.getSource(), 6000)))).then(Commands.literal("night").executes(c -> TimeCommand.setTime((CommandSourceStack)c.getSource(), 13000)))).then(Commands.literal("midnight").executes(c -> TimeCommand.setTime((CommandSourceStack)c.getSource(), 18000)))).then(Commands.argument("time", TimeArgument.time()).executes(c -> TimeCommand.setTime((CommandSourceStack)c.getSource(), IntegerArgumentType.getInteger((CommandContext)c, (String)"time")))))).then(Commands.literal("add").then(Commands.argument("time", TimeArgument.time()).executes(c -> TimeCommand.addTime((CommandSourceStack)c.getSource(), IntegerArgumentType.getInteger((CommandContext)c, (String)"time")))))).then(((LiteralArgumentBuilder)((LiteralArgumentBuilder)Commands.literal("query").then(Commands.literal("daytime").executes(c -> TimeCommand.queryTime((CommandSourceStack)c.getSource(), TimeCommand.getDayTime(((CommandSourceStack)c.getSource()).getLevel()))))).then(Commands.literal("gametime").executes(c -> TimeCommand.queryTime((CommandSourceStack)c.getSource(), (int)(((CommandSourceStack)c.getSource()).getLevel().getGameTime() % Integer.MAX_VALUE))))).then(Commands.literal("day").executes(c -> TimeCommand.queryTime((CommandSourceStack)c.getSource(), (int)(((CommandSourceStack)c.getSource()).getLevel().getDayCount() % Integer.MAX_VALUE))))));
|
|
}
|
|
|
|
private static int getDayTime(ServerLevel level) {
|
|
return (int)(level.getDayTime() % 24000L);
|
|
}
|
|
|
|
private static int queryTime(CommandSourceStack source, int time) {
|
|
source.sendSuccess(() -> Component.translatable("commands.time.query", time), false);
|
|
return time;
|
|
}
|
|
|
|
public static int setTime(CommandSourceStack source, int time) {
|
|
for (ServerLevel level : source.getServer().getAllLevels()) {
|
|
level.setDayTime(time);
|
|
}
|
|
source.getServer().forceTimeSynchronization();
|
|
source.sendSuccess(() -> Component.translatable("commands.time.set", time), true);
|
|
return TimeCommand.getDayTime(source.getLevel());
|
|
}
|
|
|
|
public static int addTime(CommandSourceStack source, int time) {
|
|
for (ServerLevel level : source.getServer().getAllLevels()) {
|
|
level.setDayTime(level.getDayTime() + (long)time);
|
|
}
|
|
source.getServer().forceTimeSynchronization();
|
|
int newTime = TimeCommand.getDayTime(source.getLevel());
|
|
source.sendSuccess(() -> Component.translatable("commands.time.set", newTime), true);
|
|
return newTime;
|
|
}
|
|
}
|
|
|