Added basic iConomy support to show the users holdings.
This commit is contained in:
@@ -8,5 +8,6 @@
|
|||||||
<attribute name="javadoc_location" value="http://jd.bukkit.org/apidocs/"/>
|
<attribute name="javadoc_location" value="http://jd.bukkit.org/apidocs/"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
|
<classpathentry kind="lib" path="lib/iConomy.jar"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|||||||
@@ -24,9 +24,6 @@ To fetch the stats of the given user:
|
|||||||
|
|
||||||
http://server:port/userstats.xml?player=username
|
http://server:port/userstats.xml?player=username
|
||||||
|
|
||||||
The following commands are planned but not implemented yet:
|
To get data provided by the iConomy plugin:
|
||||||
|
|
||||||
to get data provided by the iConomy plugin:
|
|
||||||
|
|
||||||
http://server:port/money.xml
|
http://server:port/money.xml
|
||||||
http://server:port/money.xml?player=username
|
|
||||||
BIN
lib/iConomy.jar
Normal file
BIN
lib/iConomy.jar
Normal file
Binary file not shown.
@@ -14,9 +14,58 @@
|
|||||||
*/
|
*/
|
||||||
package de.sockenklaus.XmlStats.Datasource;
|
package de.sockenklaus.XmlStats.Datasource;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import com.iConomy.iConomy;
|
||||||
|
import com.iConomy.system.Account;
|
||||||
|
import com.iConomy.system.Holdings;
|
||||||
|
|
||||||
|
import de.sockenklaus.XmlStats.XmlStats;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class MoneyDS.
|
* The Class MoneyDS.
|
||||||
*/
|
*/
|
||||||
public class MoneyDS extends Datasource {
|
public class MoneyDS extends Datasource {
|
||||||
|
|
||||||
|
private iConomy iConomy;
|
||||||
|
private ArrayList<String> allPlayers;
|
||||||
|
|
||||||
|
public MoneyDS(){
|
||||||
|
this.iConomy = XmlStats.getiConomyPlugin();
|
||||||
|
this.allPlayers = fetchAllPlayers();
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, Double> getBalances(){
|
||||||
|
HashMap<String, Double> result = new HashMap<String, Double>();
|
||||||
|
|
||||||
|
for (String playerName : allPlayers){
|
||||||
|
result.put(playerName, getBalance(playerName));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("static-access")
|
||||||
|
private Double getBalance(String playerName){
|
||||||
|
Double result = 0.0;
|
||||||
|
|
||||||
|
if (XmlStats.isiConomyHooked()){
|
||||||
|
if(this.iConomy.hasAccount(playerName)){
|
||||||
|
Account account = this.iConomy.getAccount(playerName);
|
||||||
|
|
||||||
|
if (account != null){
|
||||||
|
Holdings balance = account.getHoldings();
|
||||||
|
result = balance.balance();
|
||||||
|
}
|
||||||
|
else XmlStats.LogError("The player has an account but it isn't valid. Bad data will return.");
|
||||||
|
}
|
||||||
|
else XmlStats.LogError("This player doesn't have a bank account and this action will return bad data");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
XmlStats.LogError("Something went wrong! /money.xml shouldn't be enabled but it's datasource was called! This will return bad results.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import de.sockenklaus.XmlStats.XmlStats;
|
|||||||
/**
|
/**
|
||||||
* The Class StatsDS.
|
* The Class StatsDS.
|
||||||
*/
|
*/
|
||||||
public class StatsDS extends Datasource {
|
public class UserstatsDS extends Datasource {
|
||||||
|
|
||||||
private Stats statsPlugin;
|
private Stats statsPlugin;
|
||||||
private ArrayList<String> allPlayerNames;
|
private ArrayList<String> allPlayerNames;
|
||||||
@@ -38,7 +38,7 @@ public class StatsDS extends Datasource {
|
|||||||
/**
|
/**
|
||||||
* Instantiates a new stats ds.
|
* Instantiates a new stats ds.
|
||||||
*/
|
*/
|
||||||
public StatsDS() {
|
public UserstatsDS() {
|
||||||
this.statsPlugin = XmlStats.getStatsPlugin();
|
this.statsPlugin = XmlStats.getStatsPlugin();
|
||||||
this.allPlayerNames = fetchAllPlayers();
|
this.allPlayerNames = fetchAllPlayers();
|
||||||
this.stats = fetchPlayerStats(allPlayerNames);
|
this.stats = fetchPlayerStats(allPlayerNames);
|
||||||
@@ -129,4 +129,8 @@ public class StatsDS extends Datasource {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sortStats(){
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -42,10 +42,6 @@ public class Settings {
|
|||||||
else {
|
else {
|
||||||
conf.setProperty("options.webserver-enabled", false);
|
conf.setProperty("options.webserver-enabled", false);
|
||||||
conf.setProperty("options.webserver-port", 9123);
|
conf.setProperty("options.webserver-port", 9123);
|
||||||
conf.setProperty("plugins.stats", true);
|
|
||||||
conf.setProperty("plugins.users", true);
|
|
||||||
conf.setProperty("plugins.achievements", false);
|
|
||||||
conf.setProperty("plugins.economy", false);
|
|
||||||
conf.save();
|
conf.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,14 @@ public class WebServer {
|
|||||||
|
|
||||||
server.createContext("/users.xml", new XmlWorkerUsers());
|
server.createContext("/users.xml", new XmlWorkerUsers());
|
||||||
server.createContext("/userstats.xml", new XmlWorkerUserstats());
|
server.createContext("/userstats.xml", new XmlWorkerUserstats());
|
||||||
|
|
||||||
|
if (XmlStats.isiConomyHooked()){
|
||||||
server.createContext("/money.xml", new XmlWorkerMoney());
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
this.server.start();
|
this.server.start();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,8 +18,14 @@ import java.util.logging.Level;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.event.Event.Priority;
|
||||||
|
import org.bukkit.event.Event.Type;
|
||||||
|
import org.bukkit.event.server.PluginDisableEvent;
|
||||||
|
import org.bukkit.event.server.PluginEnableEvent;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import com.iConomy.iConomy;
|
||||||
import com.nidefawl.Stats.Stats;
|
import com.nidefawl.Stats.Stats;
|
||||||
|
|
||||||
// TODO: Auto-generated Javadoc
|
// TODO: Auto-generated Javadoc
|
||||||
@@ -32,9 +38,10 @@ public class XmlStats extends JavaPlugin {
|
|||||||
private final static double version = 0.01;
|
private final static double version = 0.01;
|
||||||
private final static String logprefix = "[XmlStats]";
|
private final static String logprefix = "[XmlStats]";
|
||||||
private boolean enabled = false;
|
private boolean enabled = false;
|
||||||
private static Stats statsPlugin;
|
private static Stats Stats = null;
|
||||||
|
private static iConomy iConomy = null;
|
||||||
private static Server serverRef;
|
private static Server serverRef;
|
||||||
private WebServer xmlQueryServer;
|
private WebServer webServer;
|
||||||
private Settings settings;
|
private Settings settings;
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@@ -42,10 +49,13 @@ public class XmlStats extends JavaPlugin {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
if(enabled && xmlQueryServer.isRunning()){
|
if(this.enabled && this.webServer.isRunning()){
|
||||||
enabled = false;
|
this.enabled = false;
|
||||||
|
|
||||||
xmlQueryServer.stopServer();
|
iConomy = null;
|
||||||
|
Stats = null;
|
||||||
|
|
||||||
|
this.webServer.stopServer();
|
||||||
|
|
||||||
getServer().getScheduler().cancelTasks(this);
|
getServer().getScheduler().cancelTasks(this);
|
||||||
|
|
||||||
@@ -60,27 +70,23 @@ public class XmlStats extends JavaPlugin {
|
|||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
|
||||||
getDataFolder().mkdirs();
|
getDataFolder().mkdirs();
|
||||||
statsPlugin = (Stats)getServer().getPluginManager().getPlugin("Stats");
|
|
||||||
serverRef = getServer();
|
serverRef = getServer();
|
||||||
|
this.settings = new Settings(this);
|
||||||
|
|
||||||
settings = new Settings(this);
|
this.hookPlugins();
|
||||||
|
|
||||||
if (settings.getBoolean("options.webserver-enabled")){
|
if (this.settings.getBoolean("options.webserver-enabled")){
|
||||||
if (getServer().getPluginManager().isPluginEnabled("Stats")){
|
|
||||||
try {
|
try {
|
||||||
xmlQueryServer = new WebServer(settings.getInt("options.webserver-port"));
|
this.webServer = new WebServer(settings.getInt("options.webserver-port"));
|
||||||
|
|
||||||
enabled = true;
|
this.enabled = true;
|
||||||
LogInfo("Plugin Enabled");
|
LogInfo("Plugin Enabled");
|
||||||
}
|
}
|
||||||
catch (Exception ex){
|
catch (Exception ex){
|
||||||
LogError("Fehler beim Erstellen des Webservers:");
|
LogError("Fehler beim Erstellen des Webservers:");
|
||||||
LogError(ex.getMessage());
|
LogError(ex.getMessage());
|
||||||
}
|
ex.printStackTrace();
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
LogError("Stats-Plugin laeuft nicht... Breche ab...");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -123,7 +129,7 @@ public class XmlStats extends JavaPlugin {
|
|||||||
* @return the stats plugin
|
* @return the stats plugin
|
||||||
*/
|
*/
|
||||||
public static Stats getStatsPlugin(){
|
public static Stats getStatsPlugin(){
|
||||||
return statsPlugin;
|
return Stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -135,4 +141,65 @@ public class XmlStats extends JavaPlugin {
|
|||||||
return serverRef;
|
return serverRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static iConomy getiConomyPlugin(){
|
||||||
|
return iConomy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPluginDisable(PluginDisableEvent event){
|
||||||
|
if(iConomy != null){
|
||||||
|
if(event.getPlugin().getDescription().getName().equals("iConomy")){
|
||||||
|
iConomy = null;
|
||||||
|
LogInfo("iConomy is disabled now. Unhooking.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(Stats != null){
|
||||||
|
if(event.getPlugin().getDescription().getName().equals("Stats")){
|
||||||
|
Stats = null;
|
||||||
|
LogInfo("Stats is disabled now. Unhooking.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPluginEnable(PluginEnableEvent event){
|
||||||
|
this.hookPlugins();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void hookPlugins(){
|
||||||
|
Plugin StatsTemp = getServer().getPluginManager().getPlugin("Stats");
|
||||||
|
Plugin iConomyTemp = getServer().getPluginManager().getPlugin("iConomy");
|
||||||
|
|
||||||
|
if(StatsTemp != null){
|
||||||
|
if(StatsTemp.isEnabled() && StatsTemp.getClass().getName().equals("com.nidefawl.Stats.Stats")){
|
||||||
|
Stats = (Stats)StatsTemp;
|
||||||
|
LogInfo("Hooked into Stats!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogError("Stats not found! Can't hook into it.");
|
||||||
|
}
|
||||||
|
if (iConomyTemp != null) {
|
||||||
|
if (iConomyTemp.isEnabled() && iConomyTemp.getClass().getName().equals("com.iConomy.iConomy")) {
|
||||||
|
iConomy = (iConomy)iConomyTemp;
|
||||||
|
LogInfo("Hooked into iConomy");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogError("iConomy not found! Can't hook into it.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isStatsHooked(){
|
||||||
|
if (Stats != null){
|
||||||
|
if(Stats.getClass().getName().equals("com.nidefawl.Stats.Stats") && Stats.isEnabled()) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isiConomyHooked(){
|
||||||
|
if (iConomy != null){
|
||||||
|
if (iConomy.getClass().getName().equals("com.iConomy.iConomy") && iConomy.isEnabled()) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,25 @@
|
|||||||
*/
|
*/
|
||||||
package de.sockenklaus.XmlStats.XmlWorkers;
|
package de.sockenklaus.XmlStats.XmlWorkers;
|
||||||
|
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.transform.Transformer;
|
||||||
|
import javax.xml.transform.TransformerFactory;
|
||||||
|
import javax.xml.transform.dom.DOMSource;
|
||||||
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
import com.nidefawl.Stats.Stats;
|
||||||
|
|
||||||
|
import de.sockenklaus.XmlStats.Datasource.MoneyDS;
|
||||||
|
|
||||||
// TODO: Auto-generated Javadoc
|
// TODO: Auto-generated Javadoc
|
||||||
/**
|
/**
|
||||||
@@ -23,12 +40,57 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class XmlWorkerMoney extends XmlWorker {
|
public class XmlWorkerMoney extends XmlWorker {
|
||||||
|
|
||||||
|
private MoneyDS moneyDS;
|
||||||
|
|
||||||
|
public XmlWorkerMoney(){
|
||||||
|
this.moneyDS = new MoneyDS();
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getXML(java.util.Map)
|
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getXML(java.util.Map)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getXML(Map<String, List<String>> parameters) {
|
public String getXML(Map<String, List<String>> parameters) {
|
||||||
// TODO Auto-generated method stub
|
try {
|
||||||
return null;
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
|
Document doc = builder.newDocument();
|
||||||
|
DOMSource source = new DOMSource(doc);
|
||||||
|
StringWriter writer = new StringWriter();
|
||||||
|
StreamResult result = new StreamResult(writer);
|
||||||
|
TransformerFactory tf = TransformerFactory.newInstance();
|
||||||
|
Transformer transformer = tf.newTransformer();
|
||||||
|
|
||||||
|
HashMap<String, Double> balances = moneyDS.getBalances();
|
||||||
|
|
||||||
|
Element root = doc.createElement("money");
|
||||||
|
doc.appendChild(root);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Hier wird das XML aufgebaut
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (String playerName : balances.keySet()){
|
||||||
|
Element elem_player = doc.createElement("player");
|
||||||
|
elem_player.setAttribute("name", playerName);
|
||||||
|
elem_player.setAttribute("balance", String.valueOf(balances.get(playerName)));
|
||||||
|
|
||||||
|
root.appendChild(elem_player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Hier endet der XML-Aufbau
|
||||||
|
*/
|
||||||
|
|
||||||
|
transformer.transform(source, result);
|
||||||
|
return writer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
catch (Exception e){
|
||||||
|
Stats.log.log(Level.SEVERE, "Something went terribly wrong!");
|
||||||
|
Stats.log.log(Level.SEVERE, e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ import com.nidefawl.Stats.ItemResolver.hModItemResolver;
|
|||||||
import com.nidefawl.Stats.datasource.Category;
|
import com.nidefawl.Stats.datasource.Category;
|
||||||
import com.nidefawl.Stats.datasource.PlayerStat;
|
import com.nidefawl.Stats.datasource.PlayerStat;
|
||||||
|
|
||||||
import de.sockenklaus.XmlStats.Datasource.StatsDS;
|
import de.sockenklaus.XmlStats.Datasource.UserstatsDS;
|
||||||
|
|
||||||
// TODO: Auto-generated Javadoc
|
// TODO: Auto-generated Javadoc
|
||||||
/**
|
/**
|
||||||
@@ -46,7 +46,7 @@ import de.sockenklaus.XmlStats.Datasource.StatsDS;
|
|||||||
public class XmlWorkerUserstats extends XmlWorker {
|
public class XmlWorkerUserstats extends XmlWorker {
|
||||||
|
|
||||||
/** The stats ds. */
|
/** The stats ds. */
|
||||||
private StatsDS statsDS;
|
private UserstatsDS statsDS;
|
||||||
private hModItemResolver itemResolver;
|
private hModItemResolver itemResolver;
|
||||||
private String[] resolveCats;
|
private String[] resolveCats;
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ public class XmlWorkerUserstats extends XmlWorker {
|
|||||||
* Instantiates a new xml worker userstats.
|
* Instantiates a new xml worker userstats.
|
||||||
*/
|
*/
|
||||||
public XmlWorkerUserstats(){
|
public XmlWorkerUserstats(){
|
||||||
this.statsDS = new StatsDS();
|
this.statsDS = new UserstatsDS();
|
||||||
itemResolver = new hModItemResolver(new File(statsDS.getDataFolder(),"items.txt"));
|
itemResolver = new hModItemResolver(new File(statsDS.getDataFolder(),"items.txt"));
|
||||||
resolveCats = new String[]{"blockdestroy", "blockcreate", "itemdrop", "itempickup"};
|
resolveCats = new String[]{"blockdestroy", "blockcreate", "itemdrop", "itempickup"};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user