CppPlugins/src/main/cpp/inc/plugin.h

92 lines
2.0 KiB
C++

#pragma once
#include <jni.h>
#include <map>
#include <string>
#include <vector>
#include "event.h"
namespace Plugin {
//fwd declr
class CppPlugin;
//function pointer
typedef void (*eventfptr)(JNIEnv*, CppPlugin*, Event*); //event
typedef CppPlugin* (*initfptr)(); //init
// cmdsender cmd label args arglength
typedef bool (*cmdfptr)(JNIEnv*, CppPlugin*, jobject, jobject, std::string&, std::vector<std::string>&);
class CppPlugin {
public:
void* handle;
std::string name;
int id;
virtual void onLoad(JNIEnv*);
virtual void onEnable(JNIEnv*);
virtual void onDisable(JNIEnv*);
virtual std::map<std::string, eventfptr> getEvents();
virtual ~CppPlugin();
void printStacktrace();
};
bool registerCmd(JNIEnv* env, CppPlugin* plugin, std::string& cname, cmdfptr function);
inline bool registerCmd(JNIEnv* env, CppPlugin* plugin, const char* cname, cmdfptr function) {
std::string n(cname);
return registerCmd( env, plugin, n, function);
}
void send(JNIEnv* env, jobject sender, const char* text);
inline void send(JNIEnv* env, jobject sender, const std::string& text) {
send(env, sender, text.c_str());
}
enum Color : char {
BLACK = '0',
DARK_BLUE = '1',
DARK_GREEN = '2',
DARK_AQUA = '3',
DARK_RED = '4',
DARK_PURPLE = '5',
GOLD = '6',
GRAY = '7',
DARK_GRAY = '8',
BLUE = '9',
GREEN = 'a',
AQUA = 'b',
RED = 'c',
LIGHT_PURPLE = 'd',
YELLOW = 'e',
WHITE = 'f',
MAGIC = 'k',
BOLD = 'l',
STRIKETHROUGH = 'm',
UNDERLINE = 'n',
ITALIC = 'o',
RESET = 'r'
};
const char COLORCHAR = '\xA7'; // §
inline std::string operator+(const Color c, const std::string& r) {
std::string out(1, COLORCHAR);
return out + ((char) c) + r;
}
inline std::string operator+(const Color c, const char* r) {
std::string out(1, COLORCHAR);
return out + ((char) c) + r;
}
inline std::string operator+(const std::string& r, const Color c) {
return r + COLORCHAR + (char) c;
}
inline std::string operator+(const char* r, const Color c) {
return r + COLORCHAR + (char) c;
}
} //namespace Plugin