Changed the behavior of userstats.xml. See at README.md.
This commit is contained in:
@@ -16,20 +16,16 @@ For a list of all known players on your server:
|
|||||||
|
|
||||||
http://server:port/users.xml
|
http://server:port/users.xml
|
||||||
|
|
||||||
For the stats of all known players:
|
For the added up stats of all known players:
|
||||||
|
|
||||||
http://server:port/userstats.xml
|
http://server:port/userstats.xml
|
||||||
|
|
||||||
To fetch the stats of the given user:
|
To fetch the stats of the given user:
|
||||||
|
|
||||||
http://server:port/userstats.xml?player=username
|
http://server:port/userstats.xml?player=username
|
||||||
|
|
||||||
This will eventually be changed to a summarized view of all users stats as soon as the selection of users is implemented
|
|
||||||
|
|
||||||
The following commands are planned but not implemented yet:
|
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
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import com.nidefawl.Stats.Stats;
|
import com.nidefawl.Stats.Stats;
|
||||||
|
import com.nidefawl.Stats.datasource.Category;
|
||||||
import com.nidefawl.Stats.datasource.PlayerStat;
|
import com.nidefawl.Stats.datasource.PlayerStat;
|
||||||
import com.nidefawl.Stats.datasource.PlayerStatSQL;
|
import com.nidefawl.Stats.datasource.PlayerStatSQL;
|
||||||
|
|
||||||
@@ -30,13 +31,8 @@ import de.sockenklaus.XmlStats.XmlStats;
|
|||||||
*/
|
*/
|
||||||
public class StatsDS extends Datasource {
|
public class StatsDS extends Datasource {
|
||||||
|
|
||||||
/** The stats plugin. */
|
|
||||||
private Stats statsPlugin;
|
private Stats statsPlugin;
|
||||||
//private Server serverRef;
|
|
||||||
/** The all player names. */
|
|
||||||
private ArrayList<String> allPlayerNames;
|
private ArrayList<String> allPlayerNames;
|
||||||
|
|
||||||
/** The stats. */
|
|
||||||
private HashMap<String, PlayerStat> stats = new HashMap<String, PlayerStat>();
|
private HashMap<String, PlayerStat> stats = new HashMap<String, PlayerStat>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,9 +40,8 @@ public class StatsDS extends Datasource {
|
|||||||
*/
|
*/
|
||||||
public StatsDS() {
|
public StatsDS() {
|
||||||
this.statsPlugin = XmlStats.getStatsPlugin();
|
this.statsPlugin = XmlStats.getStatsPlugin();
|
||||||
//this.serverRef = XmlStats.getServerRef();
|
|
||||||
this.allPlayerNames = fetchAllPlayers();
|
this.allPlayerNames = fetchAllPlayers();
|
||||||
this.stats = fetchAllPlayerStats(allPlayerNames);
|
this.stats = fetchPlayerStats(allPlayerNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,9 +49,9 @@ public class StatsDS extends Datasource {
|
|||||||
*
|
*
|
||||||
* @return the plugin
|
* @return the plugin
|
||||||
*/
|
*/
|
||||||
public Stats getPlugin() {
|
// public Stats getPlugin() {
|
||||||
return this.statsPlugin;
|
// return this.statsPlugin;
|
||||||
}
|
//}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the data folder.
|
* Gets the data folder.
|
||||||
@@ -73,7 +68,7 @@ public class StatsDS extends Datasource {
|
|||||||
* @param pPlayerNames the player names
|
* @param pPlayerNames the player names
|
||||||
* @return the hash map
|
* @return the hash map
|
||||||
*/
|
*/
|
||||||
private HashMap<String, PlayerStat> fetchAllPlayerStats(ArrayList<String> pPlayerNames){
|
private HashMap<String, PlayerStat> fetchPlayerStats(ArrayList<String> pPlayerNames){
|
||||||
HashMap<String, PlayerStat> result = new HashMap<String, PlayerStat>();
|
HashMap<String, PlayerStat> result = new HashMap<String, PlayerStat>();
|
||||||
|
|
||||||
for (String playerName : pPlayerNames){
|
for (String playerName : pPlayerNames){
|
||||||
@@ -94,4 +89,38 @@ public class StatsDS extends Datasource {
|
|||||||
public HashMap<String, PlayerStat> getStats(){
|
public HashMap<String, PlayerStat> getStats(){
|
||||||
return this.stats;
|
return this.stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HashMap<String, HashMap<String, Integer>> getAddedStats(){
|
||||||
|
HashMap <String, HashMap<String, Integer>> result = new HashMap<String, HashMap<String, Integer>>();
|
||||||
|
|
||||||
|
for(String playerName : this.stats.keySet()){
|
||||||
|
PlayerStat player = this.stats.get(playerName);
|
||||||
|
|
||||||
|
for(String catName : player.getCats()){
|
||||||
|
Category cat = player.get(catName);
|
||||||
|
|
||||||
|
for(String entryName : cat.getEntries()){
|
||||||
|
Integer entry = cat.get(entryName);
|
||||||
|
|
||||||
|
if(result.containsKey(catName)){
|
||||||
|
if(result.get(catName).containsKey(entryName)){
|
||||||
|
Integer tempInt = result.get(catName).get(entryName) + entry;
|
||||||
|
|
||||||
|
result.get(catName).put(entryName, tempInt);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result.get(catName).put(entryName, entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
HashMap<String, Integer> tempMap = new HashMap<String, Integer>();
|
||||||
|
tempMap.put(entryName, entry);
|
||||||
|
result.put(catName, tempMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ package de.sockenklaus.XmlStats.XmlWorkers;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -45,13 +46,17 @@ import de.sockenklaus.XmlStats.Datasource.StatsDS;
|
|||||||
public class XmlWorkerUserstats extends XmlWorker {
|
public class XmlWorkerUserstats extends XmlWorker {
|
||||||
|
|
||||||
/** The stats ds. */
|
/** The stats ds. */
|
||||||
StatsDS statsDS = new StatsDS();
|
private StatsDS statsDS;
|
||||||
|
private hModItemResolver itemResolver;
|
||||||
|
private String[] resolveCats;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new xml worker userstats.
|
* Instantiates a new xml worker userstats.
|
||||||
*/
|
*/
|
||||||
public XmlWorkerUserstats(){
|
public XmlWorkerUserstats(){
|
||||||
this.statsDS = new StatsDS();
|
this.statsDS = new StatsDS();
|
||||||
|
itemResolver = new hModItemResolver(new File(statsDS.getDataFolder(),"items.txt"));
|
||||||
|
resolveCats = new String[]{"blockdestroy", "blockcreate", "itemdrop", "itempickup"};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -76,12 +81,44 @@ public class XmlWorkerUserstats extends XmlWorker {
|
|||||||
/*
|
/*
|
||||||
* Hier wird das XML aufgebaut
|
* Hier wird das XML aufgebaut
|
||||||
*/
|
*/
|
||||||
|
if (!parameters.containsKey("player")){
|
||||||
|
// Generate a summarized XML
|
||||||
|
HashMap<String, HashMap<String, Integer>> addedStats = statsDS.getAddedStats();
|
||||||
|
|
||||||
for(String playerName : statsDS.getStats().keySet()){
|
Element elem_player = doc.createElement("player");
|
||||||
if (!parameters.containsKey("player") || (parameters.containsKey("player") && parameters.get("player").contains(playerName))){
|
elem_player.setAttribute("name", "*");
|
||||||
root.appendChild(getPlayerElement(playerName, doc));
|
|
||||||
|
for (String catName : addedStats.keySet()){
|
||||||
|
if (!catName.equals("stats")){
|
||||||
|
Element elem_cat = doc.createElement("category");
|
||||||
|
elem_cat.setAttribute("name", catName);
|
||||||
|
|
||||||
|
for(String entryName : addedStats.get(catName).keySet()){
|
||||||
|
Element elem_stat = doc.createElement("stat");
|
||||||
|
elem_stat.setAttribute("name", entryName);
|
||||||
|
|
||||||
|
if(Arrays.asList(resolveCats).contains(catName)){
|
||||||
|
elem_stat.setAttribute("id", String.valueOf(itemResolver.getItem(entryName)));
|
||||||
|
}
|
||||||
|
elem_stat.setAttribute("value", String.valueOf(addedStats.get(catName).get(entryName)));
|
||||||
|
|
||||||
|
elem_cat.appendChild(elem_stat);
|
||||||
|
}
|
||||||
|
elem_player.appendChild(elem_cat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
root.appendChild(elem_player);
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Generate the XML for the given user(s)
|
||||||
|
for(String playerName : statsDS.getStats().keySet()){
|
||||||
|
if (parameters.containsKey("player") && parameters.get("player").contains(playerName)){
|
||||||
|
root.appendChild(getPlayerElement(playerName, doc));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Hier endet der XML-Aufbau
|
* Hier endet der XML-Aufbau
|
||||||
*/
|
*/
|
||||||
@@ -106,9 +143,6 @@ public class XmlWorkerUserstats extends XmlWorker {
|
|||||||
* @return Returns a XML subtree for the given playerName.
|
* @return Returns a XML subtree for the given playerName.
|
||||||
*/
|
*/
|
||||||
private Element getPlayerElement(String playerName, Document doc){
|
private Element getPlayerElement(String playerName, Document doc){
|
||||||
hModItemResolver itemResolver = new hModItemResolver(new File(statsDS.getDataFolder(),"items.txt"));
|
|
||||||
String[] resolveCats = {"blockdestroy", "blockcreate", "itemdrop", "itempickup"};
|
|
||||||
|
|
||||||
PlayerStat player_stats = statsDS.getStats().get(playerName);
|
PlayerStat player_stats = statsDS.getStats().get(playerName);
|
||||||
|
|
||||||
Element elem_player = doc.createElement("player");
|
Element elem_player = doc.createElement("player");
|
||||||
|
|||||||
Reference in New Issue
Block a user