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/Stats.jar" />
|
||||
<pathelement location="lib/iConomy.jar" />
|
||||
<pathelement location="bukkit-0.0.1-SNAPSHOT.jar" />
|
||||
<pathelement location="lib/bukkit-0.0.1-SNAPSHOT.jar" />
|
||||
</path>
|
||||
|
||||
<buildnumber file=".build.number" />
|
||||
|
||||
@@ -77,29 +77,38 @@ public class Webserver {
|
||||
|
||||
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());
|
||||
XmlStats.LogInfo("iConomy seems to be loaded correctly. Enabling /money.xml.");
|
||||
}
|
||||
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());
|
||||
XmlStats.LogInfo("Achievements seems to be loaded correctly. Enabling /achievements.xml");
|
||||
}
|
||||
else {
|
||||
XmlStats.LogWarn("Achievements not loaded correctly. Disabling /achievements.xml");
|
||||
XmlStats.LogWarn("Achievements or webserver not loaded correctly. Disabling /achievements.xml");
|
||||
}
|
||||
}
|
||||
|
||||
this.server.start();
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
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.java.JavaPlugin;
|
||||
|
||||
@@ -76,14 +78,15 @@ public class XmlStats extends JavaPlugin {
|
||||
LogDebug("options.webserver-port: "+settingsTemp.getInt("options.webserver-port"));
|
||||
LogDebug("options.verbose-enabled: "+settingsTemp.getBoolean("options.verbose-enabled"));
|
||||
|
||||
this.hookPlugins();
|
||||
|
||||
if (settingsTemp.getBoolean("options.webserver-enabled")){
|
||||
try {
|
||||
XmlStatsRegistry.put("webserver", new Webserver());
|
||||
|
||||
this.enabled = true;
|
||||
LogInfo("XmStats "+this.version+" enabled");
|
||||
this.hookPlugins();
|
||||
|
||||
this.registerEvents();
|
||||
}
|
||||
catch (Exception ex){
|
||||
LogError("Fehler beim Erstellen des Webservers:");
|
||||
@@ -141,38 +144,51 @@ public class XmlStats extends JavaPlugin {
|
||||
* Hook plugins.
|
||||
*/
|
||||
protected void hookPlugins(){
|
||||
Plugin StatsTemp = getServer().getPluginManager().getPlugin("Stats");
|
||||
Plugin iConomyTemp = getServer().getPluginManager().getPlugin("iConomy");
|
||||
Plugin AchievementsTemp = getServer().getPluginManager().getPlugin("Achievements");
|
||||
this.hookAchievements();
|
||||
this.hookiConomy();
|
||||
this.hookStats();
|
||||
|
||||
if(StatsTemp != null){
|
||||
if(StatsTemp.isEnabled() && StatsTemp.getClass().getName().equals("com.nidefawl.Stats.Stats")){
|
||||
XmlStatsRegistry.put("stats", (Stats)StatsTemp);
|
||||
LogInfo("Hooked into Stats!");
|
||||
}
|
||||
}
|
||||
|
||||
protected void hookiConomy(){
|
||||
Plugin iConomyTemp = getServer().getPluginManager().getPlugin("iConomy");
|
||||
Webserver webserver = (Webserver)XmlStatsRegistry.get("webserver");
|
||||
|
||||
if (iConomyTemp != null && iConomyTemp.isEnabled() && iConomyTemp.getClass().getName().equals("com.iConomy.iConomy")) {
|
||||
XmlStatsRegistry.put("iconomy", (iConomy)iConomyTemp);
|
||||
LogInfo("Hooked into iConomy");
|
||||
webserver.startiConomy();
|
||||
}
|
||||
else {
|
||||
LogWarn("Stats not found! Can't hook into it.");
|
||||
LogWarn("iConomy not found! Can't hook into it.");
|
||||
}
|
||||
}
|
||||
|
||||
if(AchievementsTemp != null){
|
||||
if(AchievementsTemp.isEnabled() && AchievementsTemp.getClass().getName().equals("com.nidefawl.Achievements.Achievements")){
|
||||
XmlStatsRegistry.put("achievements", (Achievements)AchievementsTemp);
|
||||
LogInfo("Hooked into Achievements!");
|
||||
}
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
if (iConomyTemp != null) {
|
||||
if (iConomyTemp.isEnabled() && iConomyTemp.getClass().getName().equals("com.iConomy.iConomy")) {
|
||||
XmlStatsRegistry.put("iconomy", (iConomy)iConomyTemp);
|
||||
LogInfo("Hooked into iConomy");
|
||||
}
|
||||
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("iConomy not found! Can't hook into it.");
|
||||
LogWarn("Stats not found! Can't hook into it.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,9 +200,7 @@ public class XmlStats extends JavaPlugin {
|
||||
public static boolean checkStats(){
|
||||
Stats StatsTemp = (Stats)XmlStatsRegistry.get("stats");
|
||||
|
||||
if (StatsTemp != null){
|
||||
if(StatsTemp.getClass().getName().equals("com.nidefawl.Stats.Stats") && StatsTemp.isEnabled()) return true;
|
||||
}
|
||||
if(StatsTemp != null && StatsTemp.getClass().getName().equals("com.nidefawl.Stats.Stats") && StatsTemp.isEnabled()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -198,9 +212,7 @@ public class XmlStats extends JavaPlugin {
|
||||
public static boolean checkiConomy(){
|
||||
iConomy iConomyTemp = (iConomy)XmlStatsRegistry.get("iconomy");
|
||||
|
||||
if (iConomyTemp != null){
|
||||
if (iConomyTemp.getClass().getName().equals("com.iConomy.iConomy") && iConomyTemp.isEnabled()) return true;
|
||||
}
|
||||
if (iConomyTemp != null && iConomyTemp.getClass().getName().equals("com.iConomy.iConomy") && iConomyTemp.isEnabled()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -212,9 +224,7 @@ public class XmlStats extends JavaPlugin {
|
||||
public static boolean checkAchievements(){
|
||||
Achievements AchievementsTemp = (Achievements)XmlStatsRegistry.get("achievements");
|
||||
|
||||
if (AchievementsTemp != null){
|
||||
if(AchievementsTemp.getClass().getName().equals("com.nidefawl.Achievements.Achievements") && AchievementsTemp.isEnabled()) return true;
|
||||
}
|
||||
if(AchievementsTemp != null && AchievementsTemp.getClass().getName().equals("com.nidefawl.Achievements.Achievements") && AchievementsTemp.isEnabled()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -248,4 +258,10 @@ public class XmlStats extends JavaPlugin {
|
||||
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