mirror of
https://gitea.sffempire.ru/Kolyah35/minecraft-pe-0.6.1.git
synced 2026-04-04 14:33:36 +00:00
FEAT: Server operators
This commit is contained in:
35
src/commands/CommandOp.cpp
Normal file
35
src/commands/CommandOp.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "CommandOp.hpp"
|
||||
#include "commands/Command.hpp"
|
||||
#include "network/RakNetInstance.h"
|
||||
#include "raknet/RakPeer.h"
|
||||
#include "world/level/Level.h"
|
||||
#include <algorithm>
|
||||
#include <client/Minecraft.h>
|
||||
|
||||
|
||||
CommandOp::CommandOp() : Command("op") {}
|
||||
|
||||
void CommandOp::execute(Minecraft& mc, Player& player, const std::vector<std::string>& args) {
|
||||
if (!isPlayerOp(mc, player)) {
|
||||
return mc.addMessage("You aren't enough priveleged to run this command");
|
||||
}
|
||||
|
||||
if (args.empty()) {
|
||||
return printHelp(mc);
|
||||
}
|
||||
|
||||
auto it = std::find_if(mc.level->players.begin(), mc.level->players.end(), [args] (auto& it) -> bool {
|
||||
return it->name == args[0];
|
||||
});
|
||||
|
||||
if (mc.level->ops.find(args[0]) != mc.level->ops.end()) {
|
||||
return mc.addMessage("op: player " + args[0] + " already opped");
|
||||
}
|
||||
|
||||
mc.level->ops.emplace((*it)->name);
|
||||
mc.addMessage("op: successfully opped player " + args[0]);
|
||||
}
|
||||
|
||||
void CommandOp::printHelp(Minecraft& mc) {
|
||||
mc.addMessage("Usage: /op <player>");
|
||||
}
|
||||
Reference in New Issue
Block a user