Skip to content
This repository has been archived by the owner on Jan 20, 2025. It is now read-only.

Commit

Permalink
fixed #9
Browse files Browse the repository at this point in the history
  • Loading branch information
engsr6982 committed Jun 3, 2024
1 parent 23d2c2e commit a97417d
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 62 deletions.
6 changes: 3 additions & 3 deletions src/Command/Command.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Command.h"
#include "Utils/Utils.h"
#include "mc/network/packet/RemoveActorPacket.h"

namespace tls::command {

Expand Down Expand Up @@ -88,9 +89,8 @@ void registerCommand() {
auto item = param.player.results(origin).data;
for (Player* target : *item) {
if (target) {
string name = target->getRealName();
LevelChunkPacket pkt = LevelChunkPacket();
pkt.mCacheEnabled = true;
string name = target->getRealName();
RemoveActorPacket pkt = RemoveActorPacket(target->getAgentID());
target->sendNetworkPacket(pkt);
tls::utils::sendMsg(player, "try crash player: {}"_tr(name));
}
Expand Down
6 changes: 3 additions & 3 deletions src/Command/GamemodeCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using ll::command::CommandRegistrar;

void registerGamemodeCommand() {
#define Gm_String_Full_CallBack \
[&](CommandOrigin const& origin, CommandOutput& output, GameMode_String_Full const& param) { \
[](CommandOrigin const& origin, CommandOutput& output, GameMode_String_Full const& param) { \
CHECK_COMMAND_TYPE(output, origin.getOriginType(), CommandOriginType::Player); \
if (!checkPlayerPermission(origin, output, tls::perms::ChangeGameMode)) { \
output.error("You don't have permission to use this command!"_tr()); \
Expand All @@ -30,7 +30,7 @@ void registerGamemodeCommand() {
}

#define Gm_String_Brief_CallBack \
[&](CommandOrigin const& origin, CommandOutput& output, GameMode_String_Brief const& param) { \
[](CommandOrigin const& origin, CommandOutput& output, GameMode_String_Brief const& param) { \
CHECK_COMMAND_TYPE(output, origin.getOriginType(), CommandOriginType::Player); \
if (!checkPlayerPermission(origin, output, tls::perms::ChangeGameMode)) { \
output.error("You don't have permission to use this command!"_tr()); \
Expand All @@ -52,7 +52,7 @@ void registerGamemodeCommand() {
}

#define Gm_Int_CallBack \
[&](CommandOrigin const& origin, CommandOutput& output, GameMode_Int const& param) { \
[](CommandOrigin const& origin, CommandOutput& output, GameMode_Int const& param) { \
CHECK_COMMAND_TYPE(output, origin.getOriginType(), CommandOriginType::Player); \
if (!checkPlayerPermission(origin, output, tls::perms::ChangeGameMode)) { \
output.error("You don't have permission to use this command!"_tr()); \
Expand Down
14 changes: 0 additions & 14 deletions src/Entry/Entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "Command/Command.h"
#include "Entry.h"
#include "File/Config.h"
#include "Form/Mapping.h"
#include "Motd/Motd.h"
#include "Permission/Permission.h"
#include "PluginInfo.h"
Expand All @@ -37,15 +36,6 @@ bool entry::load() {

// print plugin info
logger.info("Autor: {}"_tr(PLUGIN_AUTHOR));
logger.info("Support Bedrock Dedicated Server Protocol {}"_tr(PLUGIN_TARGET_BDS_PROTOCOL_VERSION));
// check server protocol version
if (ll::getServerProtocolVersion() != PLUGIN_TARGET_BDS_PROTOCOL_VERSION) {
logger.warn("The bedrock server protocol version does not match, which can lead to unexpected errors. "_tr());
logger.warn("Current protocol version {} Adaptation protocol version {}"_tr(
ll::getServerProtocolVersion(),
PLUGIN_TARGET_BDS_PROTOCOL_VERSION
));
}
return true;
}

Expand All @@ -56,7 +46,6 @@ bool entry::enable() {
tls::command::registerChunkCommand();
tls::command::registerGamemodeCommand();
tls::command::registerTeleportCommand();
tls::form::initMapping();
tls::perms::initPermission();
tls::motd::initMotd();

Expand All @@ -66,9 +55,6 @@ bool entry::enable() {
bool entry::disable() {
getSelf().getLogger().info("Disabling...");

// TODO: 销毁注册的权限
// TODO: 销毁PermissionCore

return true;
}

Expand Down
6 changes: 2 additions & 4 deletions src/Entry/PluginInfo.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
#define PLUGIN_NAME "LeviOPTools" // 插件名
#define PLUGIN_AUTHOR "engsr6982" // 作者

#define PLUGIN_TARGET_BDS_PROTOCOL_VERSION 662 // BDS协议版本
#define PLUGIN_NAME "LeviOPTools"
#define PLUGIN_AUTHOR "engsr6982"
29 changes: 0 additions & 29 deletions src/Form/Mapping.cpp

This file was deleted.

17 changes: 15 additions & 2 deletions src/Form/Mapping.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "function/include_all.h"
#include "mc/world/actor/player/Player.h"
#include <functional>
#include <string>
Expand All @@ -6,7 +7,19 @@

namespace tls::form {

extern std::unordered_map<std::string, std::function<void(Player&)>> mapping;
bool initMapping();
inline static std::unordered_map<std::string, std::function<void(Player&)>> mapping = {
{"kickPlayer", kickPlayer },
{"killPlayer", killPlayer },
{"changeWeather", changeWeather },
{"changeTime", changeTime },
{"changeGameRule", changeGameRule },
{"terminal", terminal },
{"crashPlayerClient", crashPlayerClient },
{"broadCastMessage", broadCastMessage },
{"usePlayerIdentitySay", usePlayerIdentitySay },
{"usePlayerIdentityExecute", usePlayerIdentityExecute},
{"motdManagement", motdManagement },
{"getBlockOrItem", getBlockOrItem }
};

} // namespace tls::form
9 changes: 4 additions & 5 deletions src/Form/function/CrashClient.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "include_all.h"
#include "mc/network/packet/RemoveActorPacket.h"

namespace tls::form {

Expand Down Expand Up @@ -26,14 +27,12 @@ void crashPlayerClient(Player& player) {
DebugFormCallBack(dt);

for (auto const& [name, value] : *dt) {
if (std::holds_alternative<uint64_t>(value)) {
auto isTrue = std::get<uint64_t>(value);
if (std::holds_alternative<uint64>(value)) {
auto isTrue = std::get<uint64>(value);
if (isTrue) {
Player* playerPtr = ll::service::getLevel()->getPlayer(name);
if (playerPtr) {
string name = playerPtr->getRealName();
LevelChunkPacket pkt = LevelChunkPacket();
pkt.mCacheEnabled = true;
RemoveActorPacket pkt = RemoveActorPacket(playerPtr->getAgentID());
playerPtr->sendNetworkPacket(pkt);
} else {
sendMsg(pl, "Failed to get player {} pointer"_tr(name));
Expand Down
3 changes: 2 additions & 1 deletion src/Form/function/include_all.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "mc/network/packet/BossEventPacket.h"
#include "mc/network/packet/LevelChunkPacket.h"
#include "mc/network/packet/ModalFormRequestPacket.h"
#include "mc/network/packet/RemoveActorPacket.h"
#include "mc/network/packet/RemoveObjectivePacket.h"
#include "mc/network/packet/ScorePacketInfo.h"
#include "mc/network/packet/SetDisplayObjectivePacket.h"
Expand Down Expand Up @@ -122,7 +123,7 @@ void getBlockOrItem(Player& player);

#define AutoCheckPermission(player, permission) \
{ \
if (pmc::PermissionManager::getInstance() \
if (pmc::PermissionManager::getInstance() \
.getPermissionCore(PLUGIN_NAME) \
->checkUserPermission(player.getUuid().asString().c_str(), permission) \
== false) \
Expand Down
1 change: 1 addition & 0 deletions src/Utils/Utils.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once
#include "Entry/PluginInfo.h"
#include "mc/world/actor/player/Player.h"
#include <iostream>
Expand Down
2 changes: 1 addition & 1 deletion xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ add_repositories("liteldev-repo https://github.com/LiteLDev/xmake-repo.git")
-- add_requires("levilamina develop") to use develop version
-- please note that you should add bdslibrary yourself if using dev version
add_requires(
"levilamina 0.12.1",
"levilamina 0.12.3",
"PermissionCore"
)

Expand Down

0 comments on commit a97417d

Please sign in to comment.