ChatCommands Testing

This commit is contained in:
KKNecmi 2026-03-08 02:26:28 +03:00
parent 5e3f188689
commit 23bf01fc27
3 changed files with 117 additions and 36 deletions

View file

@ -633,10 +633,76 @@ void PlayerConnection::handleChat(shared_ptr<ChatPacket> packet)
void PlayerConnection::handleCommand(const wstring& message)
{
// 4J - TODO
#if 0
server.getCommandDispatcher().performCommand(player, message);
#endif
wstring commandStr = message;
stripWhitespaceForHtml(commandStr, true);
vector<wstring> args;
if (message.find(' ') >= 0)
{
args = stringSplit(commandStr, ' ');
commandStr = args[0];
args.erase(args.begin());
}
if (commandStr == L"/kill")
{
server->getCommandDispatcher()->performCommand(player, eGameCommand_Kill, byteArray());
}
else if (commandStr == L"/gamemode")
{
ByteArrayOutputStream baos(2);
DataOutputStream dos(&baos);
if (args.size() == 0)
{
player->sendMessage(L"Incorrect command usage!");
return;
}
dos.writeUTF(args[0]);
if (args.size() >= 2)
{
// Player was specified in the command arguments
shared_ptr<ServerPlayer> serverPlayer = server->getPlayers()->getPlayer(args[1]);
string playerName = wstringtochararray(args[1]);
if (!serverPlayer)
{
// Player not found
player->sendMessage(L"Player '" + args[1] + L"' not found!");
return;
}
PlayerUID uid = serverPlayer->getXuid();
dos.writePlayerUID(uid);
}
else
{
// Set own gamemode
dos.writePlayerUID(player->getXuid());
}
server->getCommandDispatcher()->performCommand(player, eGameCommand_GameMode, baos.toByteArray());
}
else if (commandStr == L"/teleport" || commandStr == L"/tp")
{
if (args.size() == 0)
{
player->sendMessage(L"Incorrect command usage!");
return;
}
if (args.size() >= 4)
{
app.DebugPrintf("size much");
}
app.DebugPrintf("Teleported");
}
else
{
player->sendMessage(L"Unknown command!");
}
}
void PlayerConnection::handleAnimate(shared_ptr<AnimatePacket> packet)

View file

@ -15,9 +15,7 @@ int CommandDispatcher::performCommand(shared_ptr<CommandSender> sender, EGameCom
}
else
{
#ifndef _CONTENT_PACKAGE
sender->sendMessage(L"\u00A7cYou do not have permission to use this command.");
#endif
sender->sendMessage(L"You do not have permission to use this command.");
}
}
else

View file

@ -1,5 +1,7 @@
#include "stdafx.h"
#include "net.minecraft.commands.h"
#include "../Minecraft.Client/ServerPlayer.h"
#include "LevelSettings.h"
#include "GameModeCommand.h"
EGameCommand GameModeCommand::getId()
@ -12,39 +14,54 @@ int GameModeCommand::getPermissionLevel()
return LEVEL_GAMEMASTERS;
}
void GameModeCommand::execute(shared_ptr<CommandSender> source, byteArray commandData)
{
//if (args.length > 0) {
// GameType newMode = getModeForString(source, args[0]);
// Player player = args.length >= 2 ? convertToPlayer(source, args[1]) : convertSourceToPlayer(source);
void GameModeCommand::execute(shared_ptr<CommandSender> source, byteArray commandData)
{
// player.setGameMode(newMode);
// player.fallDistance = 0; // reset falldistance so flying people do not die :P
ByteArrayInputStream bais(commandData);
DataInputStream dis(&bais);
wstring gamemodeStr = dis.readUTF();
PlayerUID uid = dis.readPlayerUID();
// ChatMessageComponent mode = ChatMessageComponent.forTranslation("gameMode." + newMode.getName());
GameType *gamemode = getModeForString(source, gamemodeStr);
shared_ptr<ServerPlayer> player = getPlayer(uid);
if (gamemode != NULL)
{
player->setGameMode(gamemode);
player->fallDistance = 0;
//ChatMessageComponent mode = ChatMessageComponent.forTranslation("gameMode." newMode.getName());
// if (player != source) {
// logAdminAction(source, AdminLogCommand.LOGTYPE_DONT_SHOW_TO_SELF, "commands.gamemode.success.other", player.getAName(), mode);
// } else {
// logAdminAction(source, AdminLogCommand.LOGTYPE_DONT_SHOW_TO_SELF, "commands.gamemode.success.self", mode);
// }
// return;
//}
//throw new UsageException("commands.gamemode.usage");
}
if (player != source)
{
logAdminAction(source, ChatPacket::e_ChatCustom, L"Set game mode of " + player->getName() + L" to " + gamemode->getName(), gamemode->getId(), player->getAName());
//logAdminAction(source, AdminLogCommand::LOGTYPE_DONT_SHOW_TO_SELF, "commands.gamemode.success.other", player->getAName(), mode);
}
else
{
logAdminAction(source, ChatPacket::e_ChatCustom, L"Set own game mode to " + gamemode->getName(), gamemode->getId(), player->getAName());
//logAdminAction(source, AdminLogCommand::LOGTYPE_DONT_SHOW_TO_SELF, "commands.gamemode.success.self", mode);
}
}
}
GameType *GameModeCommand::getModeForString(shared_ptr<CommandSender> source, const wstring &name)
{
return NULL;
//if (name.equalsIgnoreCase(GameType.SURVIVAL.getName()) || name.equalsIgnoreCase("s")) {
// return GameType.SURVIVAL;
//} else if (name.equalsIgnoreCase(GameType.CREATIVE.getName()) || name.equalsIgnoreCase("c")) {
// return GameType.CREATIVE;
//} else if (name.equalsIgnoreCase(GameType.ADVENTURE.getName()) || name.equalsIgnoreCase("a")) {
// return GameType.ADVENTURE;
//} else {
// return LevelSettings.validateGameType(convertArgToInt(source, name, 0, GameType.values().length - 2));
//}
if (equalsIgnoreCase(name, GameType::SURVIVAL->getName()) || equalsIgnoreCase(name, L"s"))
{
return GameType::SURVIVAL;
}
else if (equalsIgnoreCase(name, GameType::CREATIVE->getName()) || equalsIgnoreCase(name, L"c"))
{
return GameType::CREATIVE;
}
else if (equalsIgnoreCase(name, GameType::ADVENTURE->getName()) || equalsIgnoreCase(name, L"a"))
{
return GameType::ADVENTURE;
}
else
{
return NULL;
}
}