mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-08-20 09:57:09 +00:00
ChatCommands Testing
This commit is contained in:
parent
5e3f188689
commit
23bf01fc27
|
|
@ -633,10 +633,76 @@ void PlayerConnection::handleChat(shared_ptr<ChatPacket> packet)
|
||||||
|
|
||||||
void PlayerConnection::handleCommand(const wstring& message)
|
void PlayerConnection::handleCommand(const wstring& message)
|
||||||
{
|
{
|
||||||
// 4J - TODO
|
wstring commandStr = message;
|
||||||
#if 0
|
stripWhitespaceForHtml(commandStr, true);
|
||||||
server.getCommandDispatcher().performCommand(player, message);
|
|
||||||
#endif
|
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)
|
void PlayerConnection::handleAnimate(shared_ptr<AnimatePacket> packet)
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,7 @@ int CommandDispatcher::performCommand(shared_ptr<CommandSender> sender, EGameCom
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifndef _CONTENT_PACKAGE
|
sender->sendMessage(L"You do not have permission to use this command.");
|
||||||
sender->sendMessage(L"\u00A7cYou do not have permission to use this command.");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "net.minecraft.commands.h"
|
#include "net.minecraft.commands.h"
|
||||||
|
#include "../Minecraft.Client/ServerPlayer.h"
|
||||||
|
#include "LevelSettings.h"
|
||||||
#include "GameModeCommand.h"
|
#include "GameModeCommand.h"
|
||||||
|
|
||||||
EGameCommand GameModeCommand::getId()
|
EGameCommand GameModeCommand::getId()
|
||||||
|
|
@ -12,39 +14,54 @@ int GameModeCommand::getPermissionLevel()
|
||||||
return LEVEL_GAMEMASTERS;
|
return LEVEL_GAMEMASTERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameModeCommand::execute(shared_ptr<CommandSender> source, byteArray commandData)
|
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);
|
|
||||||
|
|
||||||
// player.setGameMode(newMode);
|
ByteArrayInputStream bais(commandData);
|
||||||
// player.fallDistance = 0; // reset falldistance so flying people do not die :P
|
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) {
|
if (player != source)
|
||||||
// logAdminAction(source, AdminLogCommand.LOGTYPE_DONT_SHOW_TO_SELF, "commands.gamemode.success.other", player.getAName(), mode);
|
{
|
||||||
// } else {
|
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.self", mode);
|
//logAdminAction(source, AdminLogCommand::LOGTYPE_DONT_SHOW_TO_SELF, "commands.gamemode.success.other", player->getAName(), mode);
|
||||||
// }
|
}
|
||||||
|
else
|
||||||
// return;
|
{
|
||||||
//}
|
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);
|
||||||
//throw new UsageException("commands.gamemode.usage");
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GameType *GameModeCommand::getModeForString(shared_ptr<CommandSender> source, const wstring &name)
|
GameType *GameModeCommand::getModeForString(shared_ptr<CommandSender> source, const wstring &name)
|
||||||
{
|
{
|
||||||
return NULL;
|
if (equalsIgnoreCase(name, GameType::SURVIVAL->getName()) || equalsIgnoreCase(name, L"s"))
|
||||||
//if (name.equalsIgnoreCase(GameType.SURVIVAL.getName()) || name.equalsIgnoreCase("s")) {
|
{
|
||||||
// return GameType.SURVIVAL;
|
return GameType::SURVIVAL;
|
||||||
//} else if (name.equalsIgnoreCase(GameType.CREATIVE.getName()) || name.equalsIgnoreCase("c")) {
|
}
|
||||||
// return GameType.CREATIVE;
|
else if (equalsIgnoreCase(name, GameType::CREATIVE->getName()) || equalsIgnoreCase(name, L"c"))
|
||||||
//} else if (name.equalsIgnoreCase(GameType.ADVENTURE.getName()) || name.equalsIgnoreCase("a")) {
|
{
|
||||||
// return GameType.ADVENTURE;
|
return GameType::CREATIVE;
|
||||||
//} else {
|
}
|
||||||
// return LevelSettings.validateGameType(convertArgToInt(source, name, 0, GameType.values().length - 2));
|
else if (equalsIgnoreCase(name, GameType::ADVENTURE->getName()) || equalsIgnoreCase(name, L"a"))
|
||||||
//}
|
{
|
||||||
|
return GameType::ADVENTURE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue