Re-enabled the ServerListener to catch plugins that are starting after
XmlStats. Solved issue #13.
This commit is contained in:
@@ -14,7 +14,7 @@
|
|||||||
<pathelement location="lib/Achievements.jar" />
|
<pathelement location="lib/Achievements.jar" />
|
||||||
<pathelement location="lib/Stats.jar" />
|
<pathelement location="lib/Stats.jar" />
|
||||||
<pathelement location="lib/iConomy.jar" />
|
<pathelement location="lib/iConomy.jar" />
|
||||||
<pathelement location="bukkit-0.0.1-SNAPSHOT.jar" />
|
<pathelement location="lib/bukkit-0.0.1-SNAPSHOT.jar" />
|
||||||
</path>
|
</path>
|
||||||
|
|
||||||
<buildnumber file=".build.number" />
|
<buildnumber file=".build.number" />
|
||||||
|
|||||||
@@ -77,29 +77,38 @@ public class Webserver {
|
|||||||
|
|
||||||
this.server.createContext("/users.xml", new XmlWorkerUsers());
|
this.server.createContext("/users.xml", new XmlWorkerUsers());
|
||||||
|
|
||||||
if(XmlStats.checkStats()){
|
|
||||||
server.createContext("/userstats.xml", new XmlWorkerUserstats());
|
|
||||||
XmlStats.LogInfo("Stats seems to be loaded correctly. Enabling /userstats.xml");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
XmlStats.LogWarn("Stats not loaded correctly. Disabling /userstats.xml");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (XmlStats.checkiConomy()){
|
|
||||||
|
this.server.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void startiConomy(){
|
||||||
|
if (this.isRunning() && XmlStats.checkiConomy()){
|
||||||
server.createContext("/money.xml", new XmlWorkerMoney());
|
server.createContext("/money.xml", new XmlWorkerMoney());
|
||||||
XmlStats.LogInfo("iConomy seems to be loaded correctly. Enabling /money.xml.");
|
XmlStats.LogInfo("iConomy seems to be loaded correctly. Enabling /money.xml.");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
XmlStats.LogWarn("iConomy not loaded correctly. Disabling /money.xml");
|
XmlStats.LogWarn("iConomy or webserver not loaded correctly. Disabling /money.xml");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(XmlStats.checkAchievements()){
|
|
||||||
|
protected void startAchievements(){
|
||||||
|
if(this.isRunning() && XmlStats.checkAchievements()){
|
||||||
server.createContext("/achievements.xml", new XmlWorkerAchievements());
|
server.createContext("/achievements.xml", new XmlWorkerAchievements());
|
||||||
|
XmlStats.LogInfo("Achievements seems to be loaded correctly. Enabling /achievements.xml");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
XmlStats.LogWarn("Achievements not loaded correctly. Disabling /achievements.xml");
|
XmlStats.LogWarn("Achievements or webserver not loaded correctly. Disabling /achievements.xml");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void startStats(){
|
||||||
|
if(this.isRunning() && XmlStats.checkStats()){
|
||||||
|
server.createContext("/userstats.xml", new XmlWorkerUserstats());
|
||||||
|
XmlStats.LogInfo("Stats seems to be loaded correctly. Enabling /userstats.xml");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
XmlStats.LogWarn("Stats or webserver not loaded correctly. Disabling /userstats.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.server.start();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.event.Event.Priority;
|
||||||
|
import org.bukkit.event.Event.Type;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
@@ -76,14 +78,15 @@ public class XmlStats extends JavaPlugin {
|
|||||||
LogDebug("options.webserver-port: "+settingsTemp.getInt("options.webserver-port"));
|
LogDebug("options.webserver-port: "+settingsTemp.getInt("options.webserver-port"));
|
||||||
LogDebug("options.verbose-enabled: "+settingsTemp.getBoolean("options.verbose-enabled"));
|
LogDebug("options.verbose-enabled: "+settingsTemp.getBoolean("options.verbose-enabled"));
|
||||||
|
|
||||||
this.hookPlugins();
|
|
||||||
|
|
||||||
if (settingsTemp.getBoolean("options.webserver-enabled")){
|
if (settingsTemp.getBoolean("options.webserver-enabled")){
|
||||||
try {
|
try {
|
||||||
XmlStatsRegistry.put("webserver", new Webserver());
|
XmlStatsRegistry.put("webserver", new Webserver());
|
||||||
|
|
||||||
this.enabled = true;
|
this.enabled = true;
|
||||||
LogInfo("XmStats "+this.version+" enabled");
|
LogInfo("XmStats "+this.version+" enabled");
|
||||||
|
this.hookPlugins();
|
||||||
|
|
||||||
|
this.registerEvents();
|
||||||
}
|
}
|
||||||
catch (Exception ex){
|
catch (Exception ex){
|
||||||
LogError("Fehler beim Erstellen des Webservers:");
|
LogError("Fehler beim Erstellen des Webservers:");
|
||||||
@@ -141,40 +144,53 @@ public class XmlStats extends JavaPlugin {
|
|||||||
* Hook plugins.
|
* Hook plugins.
|
||||||
*/
|
*/
|
||||||
protected void hookPlugins(){
|
protected void hookPlugins(){
|
||||||
Plugin StatsTemp = getServer().getPluginManager().getPlugin("Stats");
|
this.hookAchievements();
|
||||||
Plugin iConomyTemp = getServer().getPluginManager().getPlugin("iConomy");
|
this.hookiConomy();
|
||||||
Plugin AchievementsTemp = getServer().getPluginManager().getPlugin("Achievements");
|
this.hookStats();
|
||||||
|
|
||||||
if(StatsTemp != null){
|
}
|
||||||
if(StatsTemp.isEnabled() && StatsTemp.getClass().getName().equals("com.nidefawl.Stats.Stats")){
|
|
||||||
XmlStatsRegistry.put("stats", (Stats)StatsTemp);
|
protected void hookiConomy(){
|
||||||
LogInfo("Hooked into Stats!");
|
Plugin iConomyTemp = getServer().getPluginManager().getPlugin("iConomy");
|
||||||
}
|
Webserver webserver = (Webserver)XmlStatsRegistry.get("webserver");
|
||||||
}
|
|
||||||
else {
|
if (iConomyTemp != null && iConomyTemp.isEnabled() && iConomyTemp.getClass().getName().equals("com.iConomy.iConomy")) {
|
||||||
LogWarn("Stats not found! Can't hook into it.");
|
XmlStatsRegistry.put("iconomy", (iConomy)iConomyTemp);
|
||||||
}
|
LogInfo("Hooked into iConomy");
|
||||||
|
webserver.startiConomy();
|
||||||
if(AchievementsTemp != null){
|
|
||||||
if(AchievementsTemp.isEnabled() && AchievementsTemp.getClass().getName().equals("com.nidefawl.Achievements.Achievements")){
|
|
||||||
XmlStatsRegistry.put("achievements", (Achievements)AchievementsTemp);
|
|
||||||
LogInfo("Hooked into Achievements!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
LogWarn("Achievements not found! Can't hook into it.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (iConomyTemp != null) {
|
|
||||||
if (iConomyTemp.isEnabled() && iConomyTemp.getClass().getName().equals("com.iConomy.iConomy")) {
|
|
||||||
XmlStatsRegistry.put("iconomy", (iConomy)iConomyTemp);
|
|
||||||
LogInfo("Hooked into iConomy");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LogWarn("iConomy not found! Can't hook into it.");
|
LogWarn("iConomy not found! Can't hook into it.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void hookAchievements(){
|
||||||
|
Plugin AchievementsTemp = getServer().getPluginManager().getPlugin("Achievements");
|
||||||
|
Webserver webserver = (Webserver)XmlStatsRegistry.get("webserver");
|
||||||
|
|
||||||
|
if(AchievementsTemp != null && AchievementsTemp.isEnabled() && AchievementsTemp.getClass().getName().equals("com.nidefawl.Achievements.Achievements")){
|
||||||
|
XmlStatsRegistry.put("achievements", (Achievements)AchievementsTemp);
|
||||||
|
LogInfo("Hooked into Achievements!");
|
||||||
|
webserver.startAchievements();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogWarn("Achievements not found! Can't hook into it.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void hookStats(){
|
||||||
|
Plugin StatsTemp = getServer().getPluginManager().getPlugin("Stats");
|
||||||
|
Webserver webserver = (Webserver)XmlStatsRegistry.get("webserver");
|
||||||
|
|
||||||
|
if(StatsTemp != null && StatsTemp.isEnabled() && StatsTemp.getClass().getName().equals("com.nidefawl.Stats.Stats")){
|
||||||
|
XmlStatsRegistry.put("stats", (Stats)StatsTemp);
|
||||||
|
LogInfo("Hooked into Stats!");
|
||||||
|
webserver.startStats();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogWarn("Stats not found! Can't hook into it.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if is stats hooked.
|
* Checks if is stats hooked.
|
||||||
@@ -184,9 +200,7 @@ public class XmlStats extends JavaPlugin {
|
|||||||
public static boolean checkStats(){
|
public static boolean checkStats(){
|
||||||
Stats StatsTemp = (Stats)XmlStatsRegistry.get("stats");
|
Stats StatsTemp = (Stats)XmlStatsRegistry.get("stats");
|
||||||
|
|
||||||
if (StatsTemp != null){
|
if(StatsTemp != null && StatsTemp.getClass().getName().equals("com.nidefawl.Stats.Stats") && StatsTemp.isEnabled()) return true;
|
||||||
if(StatsTemp.getClass().getName().equals("com.nidefawl.Stats.Stats") && StatsTemp.isEnabled()) return true;
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,9 +212,7 @@ public class XmlStats extends JavaPlugin {
|
|||||||
public static boolean checkiConomy(){
|
public static boolean checkiConomy(){
|
||||||
iConomy iConomyTemp = (iConomy)XmlStatsRegistry.get("iconomy");
|
iConomy iConomyTemp = (iConomy)XmlStatsRegistry.get("iconomy");
|
||||||
|
|
||||||
if (iConomyTemp != null){
|
if (iConomyTemp != null && iConomyTemp.getClass().getName().equals("com.iConomy.iConomy") && iConomyTemp.isEnabled()) return true;
|
||||||
if (iConomyTemp.getClass().getName().equals("com.iConomy.iConomy") && iConomyTemp.isEnabled()) return true;
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,9 +224,7 @@ public class XmlStats extends JavaPlugin {
|
|||||||
public static boolean checkAchievements(){
|
public static boolean checkAchievements(){
|
||||||
Achievements AchievementsTemp = (Achievements)XmlStatsRegistry.get("achievements");
|
Achievements AchievementsTemp = (Achievements)XmlStatsRegistry.get("achievements");
|
||||||
|
|
||||||
if (AchievementsTemp != null){
|
if(AchievementsTemp != null && AchievementsTemp.getClass().getName().equals("com.nidefawl.Achievements.Achievements") && AchievementsTemp.isEnabled()) return true;
|
||||||
if(AchievementsTemp.getClass().getName().equals("com.nidefawl.Achievements.Achievements") && AchievementsTemp.isEnabled()) return true;
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,4 +258,10 @@ public class XmlStats extends JavaPlugin {
|
|||||||
this.onEnable();
|
this.onEnable();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
private void registerEvents(){
|
||||||
|
XmlStatsServerListener listener = new XmlStatsServerListener(this);
|
||||||
|
|
||||||
|
getServer().getPluginManager().registerEvent(Type.PLUGIN_ENABLE, listener, Priority.Monitor, this);
|
||||||
|
//getServer().getPluginManager().registerEvent(Type.PLUGIN_DISABLE, listener, Priority.Monitor, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
62
src/de/sockenklaus/XmlStats/XmlStatsServerListener.java
Normal file
62
src/de/sockenklaus/XmlStats/XmlStatsServerListener.java
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.sockenklaus.XmlStats;
|
||||||
|
|
||||||
|
import org.bukkit.event.server.PluginDisableEvent;
|
||||||
|
import org.bukkit.event.server.PluginEnableEvent;
|
||||||
|
import org.bukkit.event.server.ServerListener;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import com.iConomy.iConomy;
|
||||||
|
import com.nidefawl.Stats.Stats;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author socrates
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class XmlStatsServerListener extends ServerListener {
|
||||||
|
private XmlStats plugin;
|
||||||
|
|
||||||
|
public XmlStatsServerListener(XmlStats plugin){
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPluginDisable(PluginDisableEvent event){
|
||||||
|
/*
|
||||||
|
* TODO
|
||||||
|
* Not implemented yet!
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*Plugin iConomy = (Plugin)XmlStatsRegistry.get("iconomy");
|
||||||
|
Plugin Stats = (Plugin)XmlStatsRegistry.get("stats");
|
||||||
|
Plugin Achievements = (Plugin)XmlStatsRegistry.get("achievements");
|
||||||
|
|
||||||
|
if (!XmlStats.checkAchievements()){
|
||||||
|
|
||||||
|
}
|
||||||
|
if(!XmlStats.checkiConomy()){
|
||||||
|
|
||||||
|
}
|
||||||
|
if(!XmlStats.checkStats()){
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPluginEnable(PluginEnableEvent event){
|
||||||
|
if(this.identifyPlugin(event, "stats")){
|
||||||
|
this.plugin.hookStats();
|
||||||
|
}
|
||||||
|
if(this.identifyPlugin(event, "achievements")){
|
||||||
|
this.plugin.hookAchievements();
|
||||||
|
}
|
||||||
|
if(this.identifyPlugin(event, "iconomy")){
|
||||||
|
this.plugin.hookiConomy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean identifyPlugin(PluginEnableEvent event, String name){
|
||||||
|
return event.getPlugin().getDescription().getName().equalsIgnoreCase(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user