Skip to content
This repository has been archived by the owner on Nov 21, 2022. It is now read-only.

Commit

Permalink
First release(1.0.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
KoshakMineDEV committed Sep 5, 2022
1 parent 81e79a1 commit 8bf2cea
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 12 deletions.
93 changes: 85 additions & 8 deletions src/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,93 @@
* @file Plugin.cpp
* @brief The main file of the plugin
*/

#include <fstream>
#include <LoggerAPI.h>
#include <LLAPI.h>
#include <regCommandAPI.h>
#include <EventAPI.h>
#include <MC/SynchedActorData.hpp>
#include <third-party\Nlohmann\json.hpp>
#include <MC/SynchedActorDataComponent.hpp>

Logger logger;
using json = nlohmann::json;


class SizeCMD : public Command {
float size;
public:
void execute(CommandOrigin const& ori, CommandOutput& outp) const {

std::ifstream conf("plugins\\kps\\config.json");
json parsed;
conf >> parsed;
float minSize = parsed["minSize"];
float maxSize = parsed["maxSize"];
if (size >= minSize && size <= maxSize) {
ori.getPlayer()->getEntityData().set(ActorDataKeys::SCALE, size);
}
else {
std::ostringstream sssize;
sssize << size;
std::string strsize(sssize.str());

std::ostringstream ssminsize;
ssminsize << minSize;
std::string strminsize(ssminsize.str());

std::ostringstream ssmaxsize;
ssmaxsize << maxSize;
std::string strmaxsize(ssmaxsize.str());
ori.getPlayer()->sendText("You set the size higher or lower than allowed(" + strsize + "). Maximum size: " + strmaxsize + ", minimum size : " + strminsize);
}
}

static void setup(CommandRegistry* registry)
{
using RegisterCommandHelper::makeMandatory;
registry->registerCommand(
"size",
"Change your size",
CommandPermissionLevel::Any,
{ (CommandFlagValue)0 },
{ (CommandFlagValue)0x80 });
registry->registerOverload<SizeCMD>(
"Size",
makeMandatory(&SizeCMD::size, "size"));
}
};

void CommandEvent() {
Event::RegCmdEvent::subscribe([](Event::RegCmdEvent ev) {
SizeCMD::setup(ev.mCommandRegistry);
return true;
});
}


inline bool configExists(const std::string& name) {
if (FILE* file = fopen(name.c_str(), "r")) {
fclose(file);
return true;
}
else {
return false;
}
}

/**
* @brief The entrypoint of the plugin. DO NOT remove or rename this function.
*
*/
void PluginInit()
{
// Your code here
Logger logger;
logger.info("Hello, world!");

CommandEvent();
if (!configExists("plugins\\kps\\config.json")) {
logger.warn("[KPS] Config file not found, creating one...");
std::ofstream file;
std::filesystem::create_directory("plugins\\kps");
file.open("plugins\\kps\\config.json");
file << "{\n\"minSize\": 0.5,\n\"maxSize\": 2\n}";
logger.warn("[KPS] Created!");
file.close();

}
}
4 changes: 4 additions & 0 deletions src/Plugin.vcxproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
Binary file added src/Resource.aps
Binary file not shown.
7 changes: 3 additions & 4 deletions src/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@

// Please fill up the content here before developing your plugin!

static_assert(false, "Please modify your plugin information below and delete this line!");

#define PLUGIN_NAME "Plugin Name"
#define PLUGIN_NAME "KPS"

#define PLUGIN_INTRODUCTION "Plugin Introduction"
#define PLUGIN_INTRODUCTION "Koshak's Player Size is Minecraft:BE Plugin, that allows players change their size using command."

#define PLUGIN_AUTHOR "Plugin Author Name"
#define PLUGIN_AUTHOR "Koshak_Mine"

// The version of your plugin. If you do not know how to set it, please refer
// to https://semver.org/ .
Expand Down

0 comments on commit 8bf2cea

Please sign in to comment.