Finished object based XML structure.
This commit is contained in:
@@ -31,38 +31,23 @@ import de.sockenklaus.XmlStats.XmlStatsRegistry;
|
||||
*/
|
||||
public class UserstatsDS extends Datasource {
|
||||
|
||||
private Stats statsPlugin;
|
||||
|
||||
/**
|
||||
* Instantiates a new stats ds.
|
||||
*/
|
||||
public UserstatsDS() {
|
||||
this.statsPlugin = (Stats)XmlStatsRegistry.get("stats");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin.
|
||||
*
|
||||
* @return the plugin
|
||||
*/
|
||||
// public Stats getPlugin() {
|
||||
// return this.statsPlugin;
|
||||
//}
|
||||
private static Stats statsPlugin;
|
||||
|
||||
/**
|
||||
* Gets the data folder.
|
||||
*
|
||||
* @return the data folder
|
||||
*/
|
||||
public File getDataFolder(){
|
||||
return this.statsPlugin.getDataFolder();
|
||||
public static File getDataFolder(){
|
||||
statsPlugin = (Stats)XmlStatsRegistry.get("stats");
|
||||
return statsPlugin.getDataFolder();
|
||||
}
|
||||
|
||||
public HashMap<String, HashMap<String, Integer>> getAddedStats(List<String> playerList){
|
||||
HashMap <String, HashMap<String, Integer>> result = new HashMap<String, HashMap<String, Integer>>();
|
||||
|
||||
public static HashMap<String, Category> getAddedStats(List<String> playerList){
|
||||
HashMap <String, Category> result = new HashMap<String, Category>();
|
||||
|
||||
for(String playerName : playerList){
|
||||
PlayerStat player = this.getPlayerStat(playerName);
|
||||
PlayerStat player = getPlayerStat(playerName);
|
||||
|
||||
for(String catName : player.getCats()){
|
||||
Category cat = player.get(catName);
|
||||
@@ -71,25 +56,19 @@ public class UserstatsDS extends Datasource {
|
||||
Integer entry = cat.get(entryName);
|
||||
|
||||
if(result.containsKey(catName)){
|
||||
if(result.get(catName).containsKey(entryName)){
|
||||
|
||||
if(entryName.equals("lastlogin") || entryName.equals("lastlogout")){
|
||||
result.get(catName).put(entryName, Math.max(result.get(catName).get(entryName), entry));
|
||||
}
|
||||
else {
|
||||
Integer tempInt = result.get(catName).get(entryName) + entry;
|
||||
result.get(catName).put(entryName, tempInt);
|
||||
}
|
||||
|
||||
|
||||
if(entryName.equals("lastlogin") || entryName.equals("lastlogout")){
|
||||
result.get(catName).put(entryName, Math.max(result.get(catName).get(entryName), entry));
|
||||
}
|
||||
else {
|
||||
result.get(catName).put(entryName, entry);
|
||||
result.get(catName).add(entryName, entry);
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
HashMap<String, Integer> tempMap = new HashMap<String, Integer>();
|
||||
tempMap.put(entryName, entry);
|
||||
result.put(catName, tempMap);
|
||||
Category tempCat = new Category();
|
||||
tempCat.add(entryName, entry);
|
||||
result.put(catName, tempCat);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,8 +77,9 @@ public class UserstatsDS extends Datasource {
|
||||
return result;
|
||||
}
|
||||
|
||||
public PlayerStat getPlayerStat(String playerName){
|
||||
PlayerStat result = new PlayerStatSQL(playerName, this.statsPlugin);
|
||||
public static PlayerStat getPlayerStat(String playerName){
|
||||
statsPlugin = (Stats)XmlStatsRegistry.get("stats");
|
||||
PlayerStat result = new PlayerStatSQL(playerName, statsPlugin);
|
||||
|
||||
result.load();
|
||||
|
||||
|
||||
@@ -26,6 +26,15 @@ public abstract class Node {
|
||||
this.attributes.put(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param item
|
||||
*/
|
||||
public void setAttribute(String name, Integer value) {
|
||||
this.setAttribute(name, value.toString());
|
||||
|
||||
}
|
||||
|
||||
public Element getXml(Document doc){
|
||||
Element result = doc.createElement(this.tagName);
|
||||
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
*/
|
||||
package de.sockenklaus.XmlStats.Objects;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import com.nidefawl.Stats.datasource.PlayerStat;
|
||||
|
||||
import de.sockenklaus.XmlStats.Datasource.UserstatsDS;
|
||||
|
||||
/**
|
||||
* @author socrates
|
||||
@@ -12,11 +13,19 @@ import org.w3c.dom.Element;
|
||||
*/
|
||||
public class NodeCategories extends NodeArray {
|
||||
|
||||
public NodeCategories(){
|
||||
super("categories");
|
||||
}
|
||||
/**
|
||||
* @param tagName
|
||||
*/
|
||||
public NodeCategories() {
|
||||
super("categories");
|
||||
|
||||
public NodeCategories(String userName) {
|
||||
this();
|
||||
PlayerStat userStat = UserstatsDS.getPlayerStat(userName);
|
||||
|
||||
for(String catName : userStat.getCats()){
|
||||
NodeCategory node_cat = new NodeCategory(catName, userStat.get(catName));
|
||||
this.appendChild(node_cat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,19 +3,27 @@
|
||||
*/
|
||||
package de.sockenklaus.XmlStats.Objects;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.nidefawl.Stats.datasource.Category;
|
||||
|
||||
/**
|
||||
* @author socrates
|
||||
*
|
||||
*/
|
||||
public class NodeCategory extends NodeList {
|
||||
|
||||
|
||||
/**
|
||||
* @param tagName
|
||||
* @param category
|
||||
*/
|
||||
public NodeCategory(String catName) {
|
||||
public NodeCategory(String catName, Category category) {
|
||||
super("category");
|
||||
|
||||
String[] resolveCats = new String[]{"blockdestroy", "blockcreate", "itemdrop", "itempickup"};
|
||||
Boolean resolve = Arrays.asList(resolveCats).contains(catName);
|
||||
|
||||
this.appendChild(new NodeText("name", catName));
|
||||
this.appendChild(new NodeItems(category, resolve));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,22 +3,20 @@
|
||||
*/
|
||||
package de.sockenklaus.XmlStats.Objects;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* @author socrates
|
||||
*
|
||||
*/
|
||||
public class NodeItem extends Node {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see de.sockenklaus.XmlStats.Objects.Elem#getXml(org.w3c.dom.Document)
|
||||
public class NodeItem extends NodeList {
|
||||
|
||||
/**
|
||||
* @param varName
|
||||
* @param i
|
||||
*/
|
||||
@Override
|
||||
public Element getXml(Document doc) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public NodeItem(String varName, int value) {
|
||||
super("item");
|
||||
|
||||
this.appendChild(new NodeText("name", varName));
|
||||
this.appendChild(new NodeText("value", value));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,8 +3,12 @@
|
||||
*/
|
||||
package de.sockenklaus.XmlStats.Objects;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import java.io.File;
|
||||
|
||||
import com.nidefawl.Stats.ItemResolver.hModItemResolver;
|
||||
import com.nidefawl.Stats.datasource.Category;
|
||||
|
||||
import de.sockenklaus.XmlStats.Datasource.UserstatsDS;
|
||||
|
||||
/**
|
||||
* @author socrates
|
||||
@@ -13,20 +17,21 @@ import org.w3c.dom.Element;
|
||||
public class NodeItems extends NodeArray {
|
||||
|
||||
/**
|
||||
* @param tagName
|
||||
* @param category
|
||||
*/
|
||||
public NodeItems() {
|
||||
public NodeItems(Category category, Boolean resolve) {
|
||||
super("items");
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see de.sockenklaus.XmlStats.Objects.Array#getXml(org.w3c.dom.Document)
|
||||
*/
|
||||
@Override
|
||||
public Element getXml(Document doc) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
hModItemResolver itemResolver = new hModItemResolver(new File(UserstatsDS.getDataFolder(),"items.txt"));
|
||||
|
||||
for(String varName : category.getEntries()){
|
||||
NodeItem node_item = new NodeItem(varName, category.get(varName));
|
||||
|
||||
if(resolve){
|
||||
node_item.setAttribute("id", itemResolver.getItem(varName));
|
||||
}
|
||||
|
||||
this.appendChild(new NodeItem(varName, category.get(varName)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,4 +15,6 @@ public class NodeUsers extends NodeArray {
|
||||
public NodeUsers() {
|
||||
super("users");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -14,20 +14,21 @@
|
||||
*/
|
||||
package de.sockenklaus.XmlStats.XmlWorkers;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import com.nidefawl.Stats.ItemResolver.hModItemResolver;
|
||||
import com.nidefawl.Stats.datasource.Category;
|
||||
import com.nidefawl.Stats.datasource.PlayerStat;
|
||||
|
||||
import de.sockenklaus.XmlStats.Datasource.UserstatsDS;
|
||||
import de.sockenklaus.XmlStats.Exceptions.XmlStatsException;
|
||||
import de.sockenklaus.XmlStats.Objects.NodeCategories;
|
||||
import de.sockenklaus.XmlStats.Objects.NodeCategory;
|
||||
import de.sockenklaus.XmlStats.Objects.NodeList;
|
||||
import de.sockenklaus.XmlStats.Objects.NodeUser;
|
||||
import de.sockenklaus.XmlStats.Objects.NodeUsers;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
@@ -35,20 +36,7 @@ import de.sockenklaus.XmlStats.Exceptions.XmlStatsException;
|
||||
*/
|
||||
public class UserStats extends XmlWorker {
|
||||
|
||||
/** The stats ds. */
|
||||
private UserstatsDS statsDS;
|
||||
private hModItemResolver itemResolver;
|
||||
private String[] resolveCats;
|
||||
|
||||
/**
|
||||
* Instantiates a new xml worker userstats.
|
||||
*/
|
||||
public UserStats(){
|
||||
this.statsDS = new UserstatsDS();
|
||||
itemResolver = new hModItemResolver(new File(statsDS.getDataFolder(),"items.txt"));
|
||||
resolveCats = new String[]{"blockdestroy", "blockcreate", "itemdrop", "itempickup"};
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getXML(java.util.Map)
|
||||
*/
|
||||
@@ -56,134 +44,52 @@ public class UserStats extends XmlWorker {
|
||||
throw new XmlStatsException("No data provided with this query!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a XML subtree for the given player.
|
||||
*
|
||||
* @param playerName the player name
|
||||
* @return Returns a XML subtree for the given playerName.
|
||||
* @paramthis.doc thethis.doc
|
||||
*/
|
||||
private Element getUserElement(String playerName){
|
||||
PlayerStat player_stats = statsDS.getPlayerStat(playerName);
|
||||
|
||||
Element elem_player = this.doc.createElement("user");
|
||||
Element elem_cats = this.doc.createElement("categories");
|
||||
elem_cats.setAttribute("count", String.valueOf(player_stats.getCats().size()));
|
||||
|
||||
elem_player.appendChild(getTextElem("name", playerName));
|
||||
elem_player.appendChild(elem_cats);
|
||||
|
||||
for(String catName : player_stats.getCats()){
|
||||
Category cat = player_stats.get(catName);
|
||||
Element elem_cat = this.doc.createElement("category");
|
||||
Element elem_items = this.doc.createElement("items");
|
||||
elem_items.setAttribute("count", String.valueOf(cat.stats.size()));
|
||||
|
||||
elem_cat.appendChild(getTextElem("name", catName));
|
||||
elem_cat.appendChild(elem_items);
|
||||
elem_cats.appendChild(elem_cat);
|
||||
|
||||
for(String valName : cat.stats.keySet()){
|
||||
Element elem_item = getItemElem(valName, cat.get(valName));
|
||||
|
||||
if(Arrays.asList(resolveCats).contains(catName)){
|
||||
elem_item.setAttribute("id", String.valueOf(itemResolver.getItem(valName)));
|
||||
}
|
||||
|
||||
elem_items.appendChild(elem_item);
|
||||
}
|
||||
}
|
||||
return elem_player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the added up stats element.
|
||||
*
|
||||
* @return the added up stats element
|
||||
*/
|
||||
private Element getAddedUpStatsElement(List<String> playerList){
|
||||
HashMap<String, HashMap<String, Integer>> addedStats = statsDS.getAddedStats(playerList);
|
||||
Element elem_stats = this.doc.createElement("stats");
|
||||
Element elem_cats = this.doc.createElement("categories");
|
||||
elem_cats.setAttribute("count", String.valueOf(addedStats.size()));
|
||||
|
||||
elem_stats.appendChild(elem_cats);
|
||||
|
||||
for (String catName : addedStats.keySet()){
|
||||
Element elem_cat = this.doc.createElement("category");
|
||||
Element elem_items = this.doc.createElement("items");
|
||||
elem_items.setAttribute("count", String.valueOf(addedStats.get(catName).size()));
|
||||
|
||||
elem_cat.appendChild(getTextElem("name", catName));
|
||||
elem_cat.appendChild(elem_items);
|
||||
elem_cats.appendChild(elem_cat);
|
||||
|
||||
for(String entryName : addedStats.get(catName).keySet()){
|
||||
Element elem_item = this.getItemElem(entryName, addedStats.get(catName).get(entryName));
|
||||
|
||||
if(Arrays.asList(resolveCats).contains(catName)){
|
||||
elem_item.setAttribute("id", String.valueOf(itemResolver.getItem(entryName)));
|
||||
}
|
||||
|
||||
elem_items.appendChild(elem_item);
|
||||
}
|
||||
elem_cat.appendChild(elem_items);
|
||||
}
|
||||
|
||||
return elem_stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the item elem.
|
||||
*
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
* @return the item elem
|
||||
*/
|
||||
private Element getItemElem(String key, int value){
|
||||
Element elem_item = this.doc.createElement("item");
|
||||
|
||||
elem_item.appendChild(getTextElem("name", key));
|
||||
elem_item.appendChild(getTextElem("value", String.valueOf(value)));
|
||||
|
||||
return elem_item;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getSumXml(java.util.List, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
protected Element getSumXml(List<String> playerList, Map<String, List<String>> parameters) {
|
||||
Element elem_sum = this.doc.createElement("sum");
|
||||
Element elem_users = this.doc.createElement("users");
|
||||
elem_users.setAttribute("count", String.valueOf(playerList.size()));
|
||||
protected Element getSumXml(List<String> playerList, Map<String, List<String>> parameters) throws XmlStatsException {
|
||||
NodeList node_sum = new NodeList("sum");
|
||||
NodeList node_stats = new NodeList("stats");
|
||||
NodeUsers node_users = new NodeUsers();
|
||||
NodeCategories node_cats = new NodeCategories();
|
||||
|
||||
for (String userName : playerList){
|
||||
Element elem_user = this.doc.createElement("user");
|
||||
elem_user.appendChild(getTextElem("name", userName));
|
||||
|
||||
elem_users.appendChild(elem_user);
|
||||
for(String userName : playerList){
|
||||
node_users.appendChild(new NodeUser(userName));
|
||||
}
|
||||
|
||||
elem_sum.appendChild(elem_users);
|
||||
elem_sum.appendChild(this.getAddedUpStatsElement(playerList));
|
||||
HashMap<String, Category> addedStats = UserstatsDS.getAddedStats(playerList);
|
||||
|
||||
return elem_sum;
|
||||
for(String catName : addedStats.keySet()){
|
||||
NodeCategory node_cat = new NodeCategory(catName, addedStats.get(catName));
|
||||
|
||||
node_cats.appendChild(node_cat);
|
||||
}
|
||||
|
||||
node_sum.appendChild(node_users);
|
||||
node_stats.appendChild(node_cats);
|
||||
node_sum.appendChild(node_stats);
|
||||
|
||||
return node_sum.getXml(this.doc);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getUserXml(java.util.List, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
protected Element getUserXml(List<String> playerList, Map<String, List<String>> parameters) {
|
||||
Element elem_users = this.doc.createElement("users");
|
||||
elem_users.setAttribute("count", String.valueOf(playerList.size()));
|
||||
protected Element getUserXml(List<String> playerList, Map<String, List<String>> parameters) throws XmlStatsException {
|
||||
NodeUsers node_users = new NodeUsers();
|
||||
|
||||
for(String playerName : playerList){
|
||||
elem_users.appendChild(this.getUserElement(playerName));
|
||||
for(String userName : playerList){
|
||||
NodeUser node_user = new NodeUser(userName);
|
||||
NodeCategories node_cats = new NodeCategories(userName);
|
||||
|
||||
node_user.appendChild(node_cats);
|
||||
node_users.appendChild(node_user);
|
||||
}
|
||||
|
||||
return elem_users;
|
||||
return node_users.getXml(this.doc);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user