2020-02-20 19:23:28 +01:00
|
|
|
#include "plugin.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
|
2020-02-22 09:08:07 +01:00
|
|
|
using namespace Plugin;
|
|
|
|
|
2020-02-20 19:23:28 +01:00
|
|
|
extern "C" {
|
|
|
|
|
2020-02-21 09:57:24 +01:00
|
|
|
class EventsPlugin : public CppPlugin {
|
2020-02-20 19:23:28 +01:00
|
|
|
public:
|
2020-11-12 14:21:19 +01:00
|
|
|
virtual void onLoad(JNIEnv*);
|
|
|
|
virtual void onEnable(JNIEnv*);
|
|
|
|
virtual void onDisable(JNIEnv*);
|
|
|
|
virtual std::map<std::string, eventfptr> getEvents();
|
2020-02-20 19:23:28 +01:00
|
|
|
};
|
|
|
|
|
2020-02-22 02:36:43 +01:00
|
|
|
void EventsPlugin::onLoad(JNIEnv*) {
|
2020-03-30 18:05:54 +02:00
|
|
|
log("Events::onLoad();");
|
2020-02-20 19:23:28 +01:00
|
|
|
}
|
|
|
|
|
2020-02-22 02:36:43 +01:00
|
|
|
void EventsPlugin::onEnable(JNIEnv*) {
|
2020-03-30 18:05:54 +02:00
|
|
|
log("Events::onEnable();");
|
2020-02-20 19:23:28 +01:00
|
|
|
}
|
|
|
|
|
2020-02-22 02:36:43 +01:00
|
|
|
void EventsPlugin::onDisable(JNIEnv*) {
|
2020-03-30 18:05:54 +02:00
|
|
|
log("Events::onDisable();");
|
2020-02-20 19:23:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CppPlugin* init() {
|
2020-11-12 14:21:19 +01:00
|
|
|
return new EventsPlugin();
|
2020-02-20 19:23:28 +01:00
|
|
|
}
|
|
|
|
|
2020-02-20 20:17:00 +01:00
|
|
|
void eventJoin(JNIEnv* env, CppPlugin* pl, Event* e) {
|
|
|
|
jstring msg = (jstring) e->getData(env, "joinMessage");
|
|
|
|
std::string jmsg(env->GetStringUTFChars(msg, 0));
|
2020-03-30 18:05:54 +02:00
|
|
|
pl->log("join " + e->getName() + " old join message: " + jmsg);
|
2020-11-12 14:21:19 +01:00
|
|
|
jstring newmsg = env->NewStringUTF((std::string("Ein ") + Plugin::DARK_BLUE + "Spieler " + Plugin::DARK_GREEN + "ist dem Spiel beigetreten!").c_str());
|
2020-02-20 20:17:00 +01:00
|
|
|
e->setData("joinMessage", newmsg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void eventQuit(JNIEnv* env, CppPlugin* pl, Event* e) {
|
2020-03-30 18:05:54 +02:00
|
|
|
pl->log("quit " + e->getName());
|
2020-02-20 20:17:00 +01:00
|
|
|
}
|
|
|
|
|
2020-02-21 09:57:24 +01:00
|
|
|
std::map<std::string, eventfptr> EventsPlugin::getEvents() {
|
2020-03-30 18:05:54 +02:00
|
|
|
log("EventsPlugin::getEvents");
|
2020-02-20 19:23:28 +01:00
|
|
|
std::map<std::string, eventfptr> out;
|
|
|
|
out.insert({"PlayerJoinEvent", eventJoin});
|
|
|
|
out.insert({"PlayerQuitEvent", eventQuit});
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
}//extern "C"
|