Finished object based XML structure.
This commit is contained in:
@@ -31,38 +31,23 @@ import de.sockenklaus.XmlStats.XmlStatsRegistry;
|
|||||||
*/
|
*/
|
||||||
public class UserstatsDS extends Datasource {
|
public class UserstatsDS extends Datasource {
|
||||||
|
|
||||||
private Stats statsPlugin;
|
private static 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;
|
|
||||||
//}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the data folder.
|
* Gets the data folder.
|
||||||
*
|
*
|
||||||
* @return the data folder
|
* @return the data folder
|
||||||
*/
|
*/
|
||||||
public File getDataFolder(){
|
public static File getDataFolder(){
|
||||||
return this.statsPlugin.getDataFolder();
|
statsPlugin = (Stats)XmlStatsRegistry.get("stats");
|
||||||
|
return statsPlugin.getDataFolder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<String, HashMap<String, Integer>> getAddedStats(List<String> playerList){
|
public static HashMap<String, Category> getAddedStats(List<String> playerList){
|
||||||
HashMap <String, HashMap<String, Integer>> result = new HashMap<String, HashMap<String, Integer>>();
|
HashMap <String, Category> result = new HashMap<String, Category>();
|
||||||
|
|
||||||
for(String playerName : playerList){
|
for(String playerName : playerList){
|
||||||
PlayerStat player = this.getPlayerStat(playerName);
|
PlayerStat player = getPlayerStat(playerName);
|
||||||
|
|
||||||
for(String catName : player.getCats()){
|
for(String catName : player.getCats()){
|
||||||
Category cat = player.get(catName);
|
Category cat = player.get(catName);
|
||||||
@@ -71,25 +56,19 @@ public class UserstatsDS extends Datasource {
|
|||||||
Integer entry = cat.get(entryName);
|
Integer entry = cat.get(entryName);
|
||||||
|
|
||||||
if(result.containsKey(catName)){
|
if(result.containsKey(catName)){
|
||||||
if(result.get(catName).containsKey(entryName)){
|
|
||||||
|
if(entryName.equals("lastlogin") || entryName.equals("lastlogout")){
|
||||||
if(entryName.equals("lastlogin") || entryName.equals("lastlogout")){
|
result.get(catName).put(entryName, Math.max(result.get(catName).get(entryName), entry));
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result.get(catName).put(entryName, entry);
|
result.get(catName).add(entryName, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
HashMap<String, Integer> tempMap = new HashMap<String, Integer>();
|
Category tempCat = new Category();
|
||||||
tempMap.put(entryName, entry);
|
tempCat.add(entryName, entry);
|
||||||
result.put(catName, tempMap);
|
result.put(catName, tempCat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,8 +77,9 @@ public class UserstatsDS extends Datasource {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerStat getPlayerStat(String playerName){
|
public static PlayerStat getPlayerStat(String playerName){
|
||||||
PlayerStat result = new PlayerStatSQL(playerName, this.statsPlugin);
|
statsPlugin = (Stats)XmlStatsRegistry.get("stats");
|
||||||
|
PlayerStat result = new PlayerStatSQL(playerName, statsPlugin);
|
||||||
|
|
||||||
result.load();
|
result.load();
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,15 @@ public abstract class Node {
|
|||||||
this.attributes.put(name, value);
|
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){
|
public Element getXml(Document doc){
|
||||||
Element result = doc.createElement(this.tagName);
|
Element result = doc.createElement(this.tagName);
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,9 @@
|
|||||||
*/
|
*/
|
||||||
package de.sockenklaus.XmlStats.Objects;
|
package de.sockenklaus.XmlStats.Objects;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
import com.nidefawl.Stats.datasource.PlayerStat;
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
import de.sockenklaus.XmlStats.Datasource.UserstatsDS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author socrates
|
* @author socrates
|
||||||
@@ -12,11 +13,19 @@ import org.w3c.dom.Element;
|
|||||||
*/
|
*/
|
||||||
public class NodeCategories extends NodeArray {
|
public class NodeCategories extends NodeArray {
|
||||||
|
|
||||||
|
public NodeCategories(){
|
||||||
|
super("categories");
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @param tagName
|
* @param tagName
|
||||||
*/
|
*/
|
||||||
public NodeCategories() {
|
public NodeCategories(String userName) {
|
||||||
super("categories");
|
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;
|
package de.sockenklaus.XmlStats.Objects;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import com.nidefawl.Stats.datasource.Category;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author socrates
|
* @author socrates
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class NodeCategory extends NodeList {
|
public class NodeCategory extends NodeList {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param tagName
|
* @param category
|
||||||
*/
|
*/
|
||||||
public NodeCategory(String catName) {
|
public NodeCategory(String catName, Category category) {
|
||||||
super("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;
|
package de.sockenklaus.XmlStats.Objects;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author socrates
|
* @author socrates
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class NodeItem extends Node {
|
public class NodeItem extends NodeList {
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/**
|
||||||
* @see de.sockenklaus.XmlStats.Objects.Elem#getXml(org.w3c.dom.Document)
|
* @param varName
|
||||||
|
* @param i
|
||||||
*/
|
*/
|
||||||
@Override
|
public NodeItem(String varName, int value) {
|
||||||
public Element getXml(Document doc) {
|
super("item");
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
this.appendChild(new NodeText("name", varName));
|
||||||
|
this.appendChild(new NodeText("value", value));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,12 @@
|
|||||||
*/
|
*/
|
||||||
package de.sockenklaus.XmlStats.Objects;
|
package de.sockenklaus.XmlStats.Objects;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
import java.io.File;
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
import com.nidefawl.Stats.ItemResolver.hModItemResolver;
|
||||||
|
import com.nidefawl.Stats.datasource.Category;
|
||||||
|
|
||||||
|
import de.sockenklaus.XmlStats.Datasource.UserstatsDS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author socrates
|
* @author socrates
|
||||||
@@ -13,20 +17,21 @@ import org.w3c.dom.Element;
|
|||||||
public class NodeItems extends NodeArray {
|
public class NodeItems extends NodeArray {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param tagName
|
* @param category
|
||||||
*/
|
*/
|
||||||
public NodeItems() {
|
public NodeItems(Category category, Boolean resolve) {
|
||||||
super("items");
|
super("items");
|
||||||
// TODO Auto-generated constructor stub
|
|
||||||
}
|
hModItemResolver itemResolver = new hModItemResolver(new File(UserstatsDS.getDataFolder(),"items.txt"));
|
||||||
|
|
||||||
/* (non-Javadoc)
|
for(String varName : category.getEntries()){
|
||||||
* @see de.sockenklaus.XmlStats.Objects.Array#getXml(org.w3c.dom.Document)
|
NodeItem node_item = new NodeItem(varName, category.get(varName));
|
||||||
*/
|
|
||||||
@Override
|
if(resolve){
|
||||||
public Element getXml(Document doc) {
|
node_item.setAttribute("id", itemResolver.getItem(varName));
|
||||||
// TODO Auto-generated method stub
|
}
|
||||||
return null;
|
|
||||||
}
|
this.appendChild(new NodeItem(varName, category.get(varName)));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,4 +15,6 @@ public class NodeUsers extends NodeArray {
|
|||||||
public NodeUsers() {
|
public NodeUsers() {
|
||||||
super("users");
|
super("users");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,20 +14,21 @@
|
|||||||
*/
|
*/
|
||||||
package de.sockenklaus.XmlStats.XmlWorkers;
|
package de.sockenklaus.XmlStats.XmlWorkers;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
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 de.sockenklaus.XmlStats.Datasource.UserstatsDS;
|
import de.sockenklaus.XmlStats.Datasource.UserstatsDS;
|
||||||
import de.sockenklaus.XmlStats.Exceptions.XmlStatsException;
|
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
|
// TODO: Auto-generated Javadoc
|
||||||
/**
|
/**
|
||||||
@@ -35,20 +36,7 @@ import de.sockenklaus.XmlStats.Exceptions.XmlStatsException;
|
|||||||
*/
|
*/
|
||||||
public class UserStats extends XmlWorker {
|
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)
|
/* (non-Javadoc)
|
||||||
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getXML(java.util.Map)
|
* @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!");
|
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)
|
/* (non-Javadoc)
|
||||||
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getSumXml(java.util.List, java.util.Map)
|
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getSumXml(java.util.List, java.util.Map)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected Element getSumXml(List<String> playerList, Map<String, List<String>> parameters) {
|
protected Element getSumXml(List<String> playerList, Map<String, List<String>> parameters) throws XmlStatsException {
|
||||||
Element elem_sum = this.doc.createElement("sum");
|
NodeList node_sum = new NodeList("sum");
|
||||||
Element elem_users = this.doc.createElement("users");
|
NodeList node_stats = new NodeList("stats");
|
||||||
elem_users.setAttribute("count", String.valueOf(playerList.size()));
|
NodeUsers node_users = new NodeUsers();
|
||||||
|
NodeCategories node_cats = new NodeCategories();
|
||||||
|
|
||||||
for (String userName : playerList){
|
for(String userName : playerList){
|
||||||
Element elem_user = this.doc.createElement("user");
|
node_users.appendChild(new NodeUser(userName));
|
||||||
elem_user.appendChild(getTextElem("name", userName));
|
|
||||||
|
|
||||||
elem_users.appendChild(elem_user);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
elem_sum.appendChild(elem_users);
|
HashMap<String, Category> addedStats = UserstatsDS.getAddedStats(playerList);
|
||||||
elem_sum.appendChild(this.getAddedUpStatsElement(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)
|
/* (non-Javadoc)
|
||||||
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getUserXml(java.util.List, java.util.Map)
|
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getUserXml(java.util.List, java.util.Map)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected Element getUserXml(List<String> playerList, Map<String, List<String>> parameters) {
|
protected Element getUserXml(List<String> playerList, Map<String, List<String>> parameters) throws XmlStatsException {
|
||||||
Element elem_users = this.doc.createElement("users");
|
NodeUsers node_users = new NodeUsers();
|
||||||
elem_users.setAttribute("count", String.valueOf(playerList.size()));
|
|
||||||
|
|
||||||
for(String playerName : playerList){
|
for(String userName : playerList){
|
||||||
elem_users.appendChild(this.getUserElement(playerName));
|
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