Added a command to manually reload the plugin and therefore solved issue

#4.
This commit is contained in:
Pascal Koenig
2011-09-02 00:36:02 +02:00
parent 6bb298e8ce
commit 674a5843b3
7 changed files with 103 additions and 14 deletions

View File

@@ -10,6 +10,14 @@ To install the plugin, simply place the compiled **XmlStats.jar** in your server
## Usage
### Game side
At this time of the development you are only able to reload the plugin without reloading the whole server:
/xmlstats reload
### Browser side
Afterwards you can access the following xml files:
For a list of all known players on your server:

View File

@@ -8,6 +8,7 @@
<property name="version" value="0.1" />
<property name="package" value="de/sockenklaus/XmlStats" />
<property name="resources" value="resources" />
<property name="author" value="sockenklaus" />
<path id="classpath">
<pathelement location="lib/" />
@@ -20,17 +21,18 @@
<!-- Build a jar file -->
<target name="jar" depends="compile">
<!-- this is some ugly plugin.yml-writing -->
<echo file="${src}/plugin.yml">name: ${name}
main: de.sockenklaus.XmlStats.XmlStats
version: ${version}-b${build.number}
author: sockenklaus</echo>
<copy file="${resources}/plugin.yml" tofile="${bin}/plugin.yml">
<filterchain>
<replacetokens>
<token key="VERSION" value="${version}-b${build.number}" />
<token key="NAME" value="${name}" />
<token key="AUTHOR" value="${author}" />
</replacetokens>
</filterchain>
</copy>
<jar jarfile="${dist}/${name}.jar">
<fileset dir="${bin}"/>
<fileset file="src/plugin.yml" />
</jar>
</target>

8
resources/plugin.yml Normal file
View File

@@ -0,0 +1,8 @@
name: @NAME@
main: de.@AUTHOR@.@NAME@.@NAME@
version: @VERSION@
author: @AUTHOR@
commands:
xmlstats:
description: The basic command.
usage: /<command> [reload]

View File

@@ -25,7 +25,6 @@ import de.sockenklaus.XmlStats.XmlWorkers.*;
/**
* The Class WebServer.
*/
@SuppressWarnings("restriction")
public class Webserver {
private InetSocketAddress address;

View File

@@ -17,6 +17,8 @@ package de.sockenklaus.XmlStats;
import java.util.logging.Level;
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;
@@ -45,6 +47,8 @@ public class XmlStats extends JavaPlugin {
if(this.enabled && webserverTemp.isRunning()){
this.enabled = false;
XmlStatsRegistry.flush();
webserverTemp.stop();
@@ -126,6 +130,11 @@ public class XmlStats extends JavaPlugin {
log.log(Level.WARNING, logprefix + " "+ Message);
}
/**
* Log debug.
*
* @param Message the message
*/
public static void LogDebug(String Message){
Settings settingsTemp = (Settings)XmlStatsRegistry.get("settings");
if(settingsTemp.getBoolean("options.verbose-enabled")){
@@ -133,6 +142,9 @@ public class XmlStats extends JavaPlugin {
}
}
/**
* Hook plugins.
*/
protected void hookPlugins(){
Plugin StatsTemp = getServer().getPluginManager().getPlugin("Stats");
Plugin iConomyTemp = getServer().getPluginManager().getPlugin("iConomy");
@@ -156,6 +168,12 @@ public class XmlStats extends JavaPlugin {
LogError("iConomy not found! Can't hook into it.");
}
}
/**
* Checks if is stats hooked.
*
* @return true, if is stats hooked
*/
public static boolean isStatsHooked(){
Stats StatsTemp = (Stats)XmlStatsRegistry.get("stats");
@@ -165,6 +183,11 @@ public class XmlStats extends JavaPlugin {
return false;
}
/**
* Checks if is i conomy hooked.
*
* @return true, if is i conomy hooked
*/
public static boolean isiConomyHooked(){
iConomy iConomyTemp = (iConomy)XmlStatsRegistry.get("iconomy");
@@ -174,10 +197,39 @@ public class XmlStats extends JavaPlugin {
return false;
}
/**
* Register events.
*/
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);
}
/* (non-Javadoc)
* @see org.bukkit.plugin.java.JavaPlugin#onCommand(org.bukkit.command.CommandSender, org.bukkit.command.Command, java.lang.String, java.lang.String[])
*/
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
if(commandLabel.equalsIgnoreCase("xmlstats")){
if(sender.isOp() && args.length == 1 && args[0].equalsIgnoreCase("reload")){
sender.sendMessage("Reloading the XmlStats plugin...");
LogInfo("Reloading the XmlStats plugin...");
this.reload();
return true;
}
}
return false;
}
/**
* Reload.
*/
private void reload() {
this.onDisable();
this.onEnable();
}
}

View File

@@ -5,18 +5,29 @@ package de.sockenklaus.XmlStats;
import java.util.HashMap;
// TODO: Auto-generated Javadoc
/**
* @author socrates
* The Class XmlStatsRegistry.
*
* @author socrates
*/
public class XmlStatsRegistry {
private HashMap<String, Object> register = null;
private static XmlStatsRegistry instance = null;
/**
* Instantiates a new xml stats registry.
*/
private XmlStatsRegistry(){
register = new HashMap<String, Object>();
}
/**
* Put.
*
* @param key the key
* @param value the value
*/
public static void put(String key, Object value){
if(instance == null){
instance = new XmlStatsRegistry();
@@ -24,10 +35,23 @@ public class XmlStatsRegistry {
instance.register.put(key, value);
}
/**
* Get.
*
* @param key the key
* @return the object
*/
static public Object get(String key){
if(instance == null){
instance = new XmlStatsRegistry();
}
return instance.register.get(key);
}
/**
* Flush.
*/
public static void flush(){
instance = null;
}
}

View File

@@ -1,4 +0,0 @@
name: XmlStats
main: de.sockenklaus.XmlStats.XmlStats
version: 0.1-b20
author: sockenklaus