2020-02-20 12:21:43 +01:00
|
|
|
#pragma once
|
|
|
|
#include <jni.h>
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2020-02-22 02:37:07 +01:00
|
|
|
#include <vector>
|
2020-02-20 12:21:43 +01:00
|
|
|
|
2020-02-20 19:23:28 +01:00
|
|
|
#include "event.h"
|
2020-02-20 12:21:43 +01:00
|
|
|
|
2020-02-22 09:08:07 +01:00
|
|
|
namespace Plugin {
|
|
|
|
|
2020-02-20 19:23:28 +01:00
|
|
|
//fwd declr
|
|
|
|
class CppPlugin;
|
2020-02-20 12:21:43 +01:00
|
|
|
|
|
|
|
//function pointer
|
2020-02-22 02:37:07 +01:00
|
|
|
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>&);
|
|
|
|
|
2020-02-20 12:21:43 +01:00
|
|
|
|
2020-02-20 19:23:28 +01:00
|
|
|
class CppPlugin {
|
|
|
|
public:
|
|
|
|
void* handle;
|
2020-02-21 09:57:24 +01:00
|
|
|
std::string name;
|
2020-02-22 02:37:07 +01:00
|
|
|
int id;
|
|
|
|
virtual void onLoad(JNIEnv*);
|
|
|
|
virtual void onEnable(JNIEnv*);
|
|
|
|
virtual void onDisable(JNIEnv*);
|
2020-02-20 19:23:28 +01:00
|
|
|
virtual std::map<std::string, eventfptr> getEvents();
|
|
|
|
virtual ~CppPlugin();
|
2020-03-30 16:59:26 +02:00
|
|
|
void printStacktrace();
|
2020-02-20 19:23:28 +01:00
|
|
|
};
|
|
|
|
|
2020-02-22 02:37:07 +01:00
|
|
|
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);
|
2020-02-22 08:54:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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'
|
|
|
|
};
|
2020-02-22 09:08:07 +01:00
|
|
|
const char COLORCHAR = '\xA7'; // §
|
2020-02-22 08:54:09 +01:00
|
|
|
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;
|
|
|
|
}
|
2020-02-22 09:08:07 +01:00
|
|
|
|
|
|
|
} //namespace Plugin
|
|
|
|
|