forked from Kolyah35/minecraft-pe-0.6.1
FIX: grass color | small improvements
This commit is contained in:
@@ -2,18 +2,12 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
enum CommandFlags {
|
||||
COMMAND_FLAG_SINGLEPLAYER_ONLY = (1 << 1),
|
||||
COMMAND_FLAG_NO_ARGS = (1 << 2),
|
||||
};
|
||||
|
||||
class Minecraft;
|
||||
class Player;
|
||||
|
||||
class Command {
|
||||
public:
|
||||
const std::string& getName() { return m_name; }
|
||||
const CommandFlags getFlags() { return m_flags; }
|
||||
|
||||
bool isPlayerOp(Minecraft& mc, Player& player);
|
||||
|
||||
@@ -21,8 +15,7 @@ public:
|
||||
virtual std::string help(Minecraft& mc) = 0;
|
||||
|
||||
protected:
|
||||
Command(const std::string& name, CommandFlags flags = (CommandFlags)0) : m_name(name), m_flags(flags) {}
|
||||
Command(const std::string& name) : m_name(name) {}
|
||||
|
||||
const std::string m_name;
|
||||
const CommandFlags m_flags;
|
||||
};
|
||||
33
src/commands/CommandGimmieItems.cpp
Normal file
33
src/commands/CommandGimmieItems.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "CommandGimmieItems.hpp"
|
||||
#include <client/Minecraft.h>
|
||||
#include <world/level/Level.h>
|
||||
#include <world/item/DyePowderItem.h>
|
||||
|
||||
CommandGimmieItems::CommandGimmieItems() : Command("gimmieitems") {}
|
||||
|
||||
std::string CommandGimmieItems::execute(Minecraft& mc, Player& player, const std::vector<std::string>& args) {
|
||||
if (mc.level != nullptr) {
|
||||
if (mc.level->getLevelData()->getAllowCheats()) {
|
||||
player.inventory->add(new ItemInstance(Item::ironIngot, 64));
|
||||
player.inventory->add(new ItemInstance(Item::ironIngot, 34));
|
||||
player.inventory->add(new ItemInstance(Tile::stonecutterBench));
|
||||
player.inventory->add(new ItemInstance(Tile::workBench));
|
||||
player.inventory->add(new ItemInstance(Tile::furnace));
|
||||
player.inventory->add(new ItemInstance(Tile::wood, 54));
|
||||
player.inventory->add(new ItemInstance(Item::stick, 14));
|
||||
player.inventory->add(new ItemInstance(Item::coal, 31));
|
||||
player.inventory->add(new ItemInstance(Tile::sand, 6));
|
||||
player.inventory->add(new ItemInstance(Item::dye_powder, 23, DyePowderItem::PURPLE));
|
||||
|
||||
return "Grant debug items. Have fun!";
|
||||
} else {
|
||||
return "Cheats are not allowed!";
|
||||
}
|
||||
}
|
||||
|
||||
return "World not loaded";
|
||||
}
|
||||
|
||||
std::string CommandGimmieItems::help(Minecraft& mc) {
|
||||
return "Usage: /gimmieitems";
|
||||
}
|
||||
9
src/commands/CommandGimmieItems.hpp
Normal file
9
src/commands/CommandGimmieItems.hpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "Command.hpp"
|
||||
|
||||
class CommandGimmieItems : public Command {
|
||||
public:
|
||||
CommandGimmieItems();
|
||||
|
||||
std::string execute(Minecraft& mc, Player& player, const std::vector<std::string>& args);
|
||||
std::string help(Minecraft& mc);
|
||||
};
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "commands/CommandKick.hpp"
|
||||
#include "commands/CommandOp.hpp"
|
||||
#include "commands/CommandBan.hpp"
|
||||
#include "commands/CommandGimmieItems.hpp"
|
||||
#include "network/packet/ChatPacket.h"
|
||||
#include "network/RakNetInstance.h"
|
||||
#include "world/level/Level.h"
|
||||
@@ -21,6 +22,7 @@ void CommandManager::registerAllCommands() {
|
||||
m_commands.push_back(new CommandKick());
|
||||
m_commands.push_back(new CommandOp());
|
||||
m_commands.push_back(new CommandBan());
|
||||
m_commands.push_back(new CommandGimmieItems());
|
||||
}
|
||||
|
||||
std::vector<std::string> CommandManager::getListAllCommands() {
|
||||
@@ -34,32 +36,32 @@ std::vector<std::string> CommandManager::getListAllCommands() {
|
||||
}
|
||||
|
||||
std::string CommandManager::execute(Minecraft& mc, Player& player, const std::string& input) {
|
||||
std::istringstream ss(input);
|
||||
std::string cmd;
|
||||
if (!mc.level->isClientSide) {
|
||||
std::istringstream ss(input);
|
||||
std::string cmd;
|
||||
|
||||
ss >> cmd;
|
||||
ss >> cmd;
|
||||
|
||||
auto it = std::find_if(m_commands.begin(), m_commands.end(), [cmd](auto& it) -> bool {
|
||||
return it->getName() == cmd;
|
||||
});
|
||||
auto it = std::find_if(m_commands.begin(), m_commands.end(), [cmd](auto& it) -> bool {
|
||||
return it->getName() == cmd;
|
||||
});
|
||||
|
||||
if (it == m_commands.end()) {
|
||||
return "Command /" + cmd + " not found";
|
||||
}
|
||||
if (it == m_commands.end()) {
|
||||
return "Command /" + cmd + " not found";
|
||||
}
|
||||
|
||||
std::vector<std::string> args;
|
||||
std::vector<std::string> args;
|
||||
|
||||
std::string tok;
|
||||
while (ss >> tok) args.push_back(tok);
|
||||
|
||||
std::string tok;
|
||||
while (ss >> tok) args.push_back(tok);
|
||||
|
||||
if (!mc.level->isClientSide || (*it)->getFlags() & CommandFlags::COMMAND_FLAG_SINGLEPLAYER_ONLY) {
|
||||
return (*it)->execute(mc, player, args);
|
||||
} else {
|
||||
ChatPacket packet("/" + input);
|
||||
mc.raknetInstance->send(packet);
|
||||
}
|
||||
|
||||
return "";
|
||||
return std::string();
|
||||
}
|
||||
|
||||
Command* CommandManager::getCommand(const std::string& name) {
|
||||
|
||||
Reference in New Issue
Block a user