aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/TimeCommand.cpp
diff options
context:
space:
mode:
authordaoge_cmd <3523206925@qq.com>2026-03-01 12:16:08 +0800
committerdaoge_cmd <3523206925@qq.com>2026-03-01 12:16:08 +0800
commitb691c43c44ff180d10e7d4a9afc83b98551ff586 (patch)
tree3e9849222cbc6ba49f2f1fc6e5fe7179632c7390 /Minecraft.World/TimeCommand.cpp
parentdef8cb415354ac390b7e89052a50605285f1aca9 (diff)
Initial commit
Diffstat (limited to 'Minecraft.World/TimeCommand.cpp')
-rw-r--r--Minecraft.World/TimeCommand.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/Minecraft.World/TimeCommand.cpp b/Minecraft.World/TimeCommand.cpp
new file mode 100644
index 00000000..e667a420
--- /dev/null
+++ b/Minecraft.World/TimeCommand.cpp
@@ -0,0 +1,80 @@
+#include "stdafx.h"
+#include "net.minecraft.commands.h"
+#include "..\Minecraft.Client\MinecraftServer.h"
+#include "..\Minecraft.Client\ServerLevel.h"
+#include "net.minecraft.network.packet.h"
+#include "TimeCommand.h"
+
+EGameCommand TimeCommand::getId()
+{
+ return eGameCommand_Time;
+}
+
+void TimeCommand::execute(shared_ptr<CommandSender> source, byteArray commandData)
+{
+ ByteArrayInputStream bais(commandData);
+ DataInputStream dis(&bais);
+
+ bool night = dis.readBoolean();
+
+ bais.reset();
+
+ int amount = 0;
+ if(night) amount = 12500;
+ doSetTime(source, amount);
+ //logAdminAction(source, "commands.time.set", amount);
+ logAdminAction(source, ChatPacket::e_ChatCustom, L"commands.time.set");
+
+ //if (args.length > 1) {
+ // if (args[0].equals("set")) {
+ // int amount;
+
+ // if (args[1].equals("day")) {
+ // amount = 0;
+ // } else if (args[1].equals("night")) {
+ // amount = 12500;
+ // } else {
+ // amount = convertArgToInt(source, args[1], 0);
+ // }
+
+ // doSetTime(source, amount);
+ // logAdminAction(source, "commands.time.set", amount);
+ // return;
+ // } else if (args[0].equals("add")) {
+ // int amount = convertArgToInt(source, args[1], 0);
+ // doAddTime(source, amount);
+
+ // logAdminAction(source, "commands.time.added", amount);
+ // return;
+ // }
+ //}
+
+ //throw new UsageException("commands.time.usage");
+}
+
+void TimeCommand::doSetTime(shared_ptr<CommandSender> source, int value)
+{
+ for (int i = 0; i < MinecraftServer::getInstance()->levels.length; i++)
+ {
+ MinecraftServer::getInstance()->levels[i]->setTimeAndAdjustTileTicks(value);
+ }
+}
+
+void TimeCommand::doAddTime(shared_ptr<CommandSender> source, int value)
+{
+ for (int i = 0; i < MinecraftServer::getInstance()->levels.length; i++)
+ {
+ ServerLevel *level = MinecraftServer::getInstance()->levels[i];
+ level->setTimeAndAdjustTileTicks(level->getTime() + value);
+ }
+}
+
+shared_ptr<GameCommandPacket> TimeCommand::preparePacket(bool night)
+{
+ ByteArrayOutputStream baos;
+ DataOutputStream dos(&baos);
+
+ dos.writeBoolean(night);
+
+ return shared_ptr<GameCommandPacket>( new GameCommandPacket(eGameCommand_Time, baos.toByteArray() ));
+} \ No newline at end of file