Redirect "player." commands to "entity."
This commit is contained in:
parent
5c264736de
commit
b7deac1389
@ -226,6 +226,7 @@ static std::string getEventsOfId(CircularQueue<T> events, CommandServer *command
|
||||
}
|
||||
|
||||
static const std::string fail = "Fail\n";
|
||||
static const std::string player_namespace = "player.";
|
||||
std::unordered_map<int, int> modern_entity_id_mapping = {
|
||||
{93, 10}, /* Chicken */
|
||||
{92, 11}, /* Cow */
|
||||
@ -254,6 +255,14 @@ std::string CommandServer_parse_injection(CommandServer_parse_t old, CommandServ
|
||||
if (cmd_end == std::string::npos) return fail;
|
||||
std::string args = command.substr(arg_start + 1, cmd_end - arg_start - 1);
|
||||
|
||||
// Redirect player commands to the entity command
|
||||
if (commandserver->minecraft->player != NULL) {
|
||||
if (cmd.starts_with(player_namespace) && cmd != "player.setting" && command != "player.getAbsPos" && command != "player.setAbsPos") {
|
||||
cmd = "entity." + cmd.substr(player_namespace.size());
|
||||
args = std::to_string(commandserver->minecraft->player->id) + "," + args;
|
||||
}
|
||||
}
|
||||
|
||||
// And now the big if-else chain
|
||||
if (cmd == "world.getBlocks") {
|
||||
int x0, y0, z0, x1, y1, z1;
|
||||
@ -331,17 +340,11 @@ std::string CommandServer_parse_injection(CommandServer_parse_t old, CommandServ
|
||||
}
|
||||
if (ret.size() > 1) ret.pop_back();
|
||||
return ret + "\n";
|
||||
} else if (cmd == "player.events.chat.posts") {
|
||||
if (commandserver->minecraft->player == NULL) return fail;
|
||||
return getEventsOfId(chatEvents, commandserver, commandserver->minecraft->player->id);
|
||||
} else if (cmd == "entity.events.chat.posts") {
|
||||
int id;
|
||||
int ret = sscanf(args.c_str(), "%d", &id);
|
||||
if (ret != 1) return fail;
|
||||
return getEventsOfId(chatEvents, commandserver, id);
|
||||
} else if (cmd == "player.events.block.hits") {
|
||||
if (commandserver->minecraft->player == NULL) return fail;
|
||||
return getBlockHits(commandserver, client, commandserver->minecraft->player->id);
|
||||
} else if (cmd == "entity.events.block.hits") {
|
||||
int id;
|
||||
int ret = sscanf(args.c_str(), "%d", &id);
|
||||
@ -356,20 +359,11 @@ std::string CommandServer_parse_injection(CommandServer_parse_t old, CommandServ
|
||||
}
|
||||
if (result.size() > 1) result.pop_back();
|
||||
return result + "\n";
|
||||
} else if (cmd == "player.events.projectile.hits") {
|
||||
if (commandserver->minecraft->player == NULL) return fail;
|
||||
return getEventsOfId(hitEvents, commandserver, commandserver->minecraft->player->id);
|
||||
} else if (cmd == "entity.events.projectile.hits") {
|
||||
int id;
|
||||
int ret = sscanf(args.c_str(), "%d", &id);
|
||||
if (ret != 1) return fail;
|
||||
return getEventsOfId(hitEvents, commandserver, id);
|
||||
} else if (cmd == "player.setDirection" && commandserver->minecraft->player) {
|
||||
if (commandserver->minecraft->player == NULL) return fail;
|
||||
float x, y, z;
|
||||
int ret = sscanf(args.c_str(), "%f,%f,%f", &x, &y, &z);
|
||||
if (ret != 3) return "";
|
||||
setDir((Entity *) commandserver->minecraft->player, x, y, z);
|
||||
} else if (cmd == "entity.setDirection") {
|
||||
int id;
|
||||
float x, y, z;
|
||||
@ -381,9 +375,6 @@ std::string CommandServer_parse_injection(CommandServer_parse_t old, CommandServ
|
||||
} else {
|
||||
setDir(entity, x, y, z);
|
||||
}
|
||||
} else if (cmd == "player.getDirection" && commandserver->minecraft->player) {
|
||||
Vec3 vec = getDir((Entity *) commandserver->minecraft->player);
|
||||
return std::to_string(vec.x) + "," + std::to_string(vec.y) + "," + std::to_string(vec.z) + "\n";
|
||||
} else if (cmd == "entity.getDirection") {
|
||||
int id;
|
||||
int ret = sscanf(args.c_str(), "%d", &id);
|
||||
@ -396,11 +387,6 @@ std::string CommandServer_parse_injection(CommandServer_parse_t old, CommandServ
|
||||
Vec3 vec = getDir(entity);
|
||||
return std::to_string(vec.x) + "," + std::to_string(vec.y) + "," + std::to_string(vec.z) + "\n";
|
||||
}
|
||||
} else if (cmd == "player.setRotation" && commandserver->minecraft->player) {
|
||||
float yaw;
|
||||
int ret = sscanf(args.c_str(), "%f", &yaw);
|
||||
if (ret != 1) return "";
|
||||
commandserver->minecraft->player->yaw = yaw;
|
||||
} else if (cmd == "entity.setRotation") {
|
||||
int id;
|
||||
float yaw;
|
||||
@ -412,11 +398,6 @@ std::string CommandServer_parse_injection(CommandServer_parse_t old, CommandServ
|
||||
} else {
|
||||
entity->yaw = yaw;
|
||||
}
|
||||
} else if (cmd == "player.setPitch" && commandserver->minecraft->player) {
|
||||
float pitch;
|
||||
int ret = sscanf(args.c_str(), "%f", &pitch);
|
||||
if (ret != 1) return "";
|
||||
commandserver->minecraft->player->pitch = pitch;
|
||||
} else if (cmd == "entity.setPitch") {
|
||||
int id;
|
||||
float pitch;
|
||||
@ -428,8 +409,6 @@ std::string CommandServer_parse_injection(CommandServer_parse_t old, CommandServ
|
||||
} else {
|
||||
entity->pitch = pitch;
|
||||
}
|
||||
} else if (cmd == "player.getRotation" && commandserver->minecraft->player) {
|
||||
return std::to_string(commandserver->minecraft->player->yaw) + "\n";
|
||||
} else if (cmd == "entity.getRotation") {
|
||||
int id;
|
||||
int ret = sscanf(args.c_str(), "%d", &id);
|
||||
@ -441,8 +420,6 @@ std::string CommandServer_parse_injection(CommandServer_parse_t old, CommandServ
|
||||
} else {
|
||||
return std::to_string(entity->yaw) + "\n";
|
||||
}
|
||||
} else if (cmd == "player.getPitch" && commandserver->minecraft->player) {
|
||||
return std::to_string(commandserver->minecraft->player->pitch) + "\n";
|
||||
} else if (cmd == "entity.getPitch") {
|
||||
int id;
|
||||
int ret = sscanf(args.c_str(), "%d", &id);
|
||||
@ -454,23 +431,17 @@ std::string CommandServer_parse_injection(CommandServer_parse_t old, CommandServ
|
||||
} else {
|
||||
return std::to_string(entity->pitch) + "\n";
|
||||
}
|
||||
} else if (cmd == "player.getEntities" || cmd == "entity.getEntities") {
|
||||
} else if (cmd == "entity.getEntities") {
|
||||
// Parse
|
||||
int dist, type;
|
||||
Entity *src = NULL;
|
||||
if (cmd == "player.getEntities") {
|
||||
int ret = sscanf(args.c_str(), "%d,%d", &dist, &type);
|
||||
if (ret != 2 || commandserver->minecraft->player == NULL) return "";
|
||||
src = (Entity *) commandserver->minecraft->player;
|
||||
} else {
|
||||
int id = 0;
|
||||
int ret = sscanf(args.c_str(), "%d,%d,%d", &id, &dist, &type);
|
||||
if (ret != 3) return "";
|
||||
src = commandserver->minecraft->level->getEntity(id);
|
||||
if (src == NULL) {
|
||||
WARN("Entity [%i] not found.", id);
|
||||
return fail;
|
||||
}
|
||||
int id = 0;
|
||||
int ret = sscanf(args.c_str(), "%d,%d,%d", &id, &dist, &type);
|
||||
if (ret != 3) return "";
|
||||
src = commandserver->minecraft->level->getEntity(id);
|
||||
if (src == NULL) {
|
||||
WARN("Entity [%i] not found.", id);
|
||||
return fail;
|
||||
}
|
||||
// Run
|
||||
std::string result = "";
|
||||
@ -481,23 +452,17 @@ std::string CommandServer_parse_injection(CommandServer_parse_t old, CommandServ
|
||||
}
|
||||
if (result.size() > 1) result.pop_back();
|
||||
return result + "\n";
|
||||
} else if (cmd == "player.removeEntities" || cmd == "entity.removeEntities") {
|
||||
} else if (cmd == "entity.removeEntities") {
|
||||
// Parse
|
||||
int dist, type;
|
||||
Entity *src = NULL;
|
||||
if (cmd == "player.removeEntities") {
|
||||
int ret = sscanf(args.c_str(), "%d,%d", &dist, &type);
|
||||
if (ret != 2 || commandserver->minecraft->player == NULL) return "";
|
||||
src = (Entity *) commandserver->minecraft->player;
|
||||
} else {
|
||||
int id = 0;
|
||||
int ret = sscanf(args.c_str(), "%d,%d,%d", &id, &dist, &type);
|
||||
if (ret != 3) return "";
|
||||
src = commandserver->minecraft->level->getEntity(id);
|
||||
if (src == NULL) {
|
||||
WARN("Entity [%i] not found.", id);
|
||||
return fail;
|
||||
}
|
||||
int id = 0;
|
||||
int ret = sscanf(args.c_str(), "%d,%d,%d", &id, &dist, &type);
|
||||
if (ret != 3) return "";
|
||||
src = commandserver->minecraft->level->getEntity(id);
|
||||
if (src == NULL) {
|
||||
WARN("Entity [%i] not found.", id);
|
||||
return fail;
|
||||
}
|
||||
// Run
|
||||
int removed = 0;
|
||||
@ -565,9 +530,6 @@ std::string CommandServer_parse_injection(CommandServer_parse_t old, CommandServ
|
||||
return std::to_string(commandserver->minecraft->player->x) + ","
|
||||
+ std::to_string(commandserver->minecraft->player->y) + ","
|
||||
+ std::to_string(commandserver->minecraft->player->z) + "\n";
|
||||
} else if (cmd == "player.events.clear") {
|
||||
if (commandserver->minecraft->player == NULL) return "";
|
||||
clearEvents(commandserver, commandserver->minecraft->player->id);
|
||||
} else if (cmd == "entity.events.clear") {
|
||||
int id;
|
||||
int ret = sscanf(args.c_str(), "%d", &id);
|
||||
|
Loading…
Reference in New Issue
Block a user