CppPlugins/testplugins/02simpleEvents/src/plugin.cpp

55 lines
1.3 KiB
C++
Raw Normal View History

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*) {
log("Events::onLoad();");
2020-02-20 19:23:28 +01:00
}
2020-02-22 02:36:43 +01:00
void EventsPlugin::onEnable(JNIEnv*) {
log("Events::onEnable();");
2020-02-20 19:23:28 +01:00
}
2020-02-22 02:36:43 +01:00
void EventsPlugin::onDisable(JNIEnv*) {
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));
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) {
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() {
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"