Fix the defect commit

This commit is contained in:
Pascal Koenig
2011-10-04 19:04:48 +02:00
parent 95443bad58
commit 4270515f8c
12 changed files with 239 additions and 18 deletions

View File

@@ -5,7 +5,7 @@
<property name="dist" value="dist" />
<property name="src" value="src" />
<property name="name" value="XmlStats" />
<property name="version" value="0.4" />
<property name="version" value="0.3" />
<property name="package" value="de/sockenklaus/XmlStats" />
<property name="resources" value="resources" />
<property name="author" value="sockenklaus" />

View File

@@ -31,7 +31,6 @@ public class AchievementsDS extends Datasource {
Achievements ach = (Achievements)XmlStatsRegistry.get("achievements");
if(xmlstats.checkAchievements()){
XmlStats.LogDebug("Found "+ach.achievementList.size()+" achievements.");
return ach.achievementList;
}
else return new HashMap<String, AchievementListData>();

View File

@@ -18,10 +18,6 @@ import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.World;
import de.sockenklaus.XmlStats.XmlStats;
import de.sockenklaus.XmlStats.XmlStatsRegistry;
import de.sockenklaus.XmlStats.Exceptions.XmlStatsException;
// TODO: Auto-generated Javadoc
@@ -36,24 +32,18 @@ public abstract class Datasource {
* @return the array list
*/
public static ArrayList<String> fetchAllPlayers(){
XmlStats xmlstats = (XmlStats)XmlStatsRegistry.get("xmlstats");
List<World> worlds = xmlstats.getServer().getWorlds();
File[] files = new File("world/players").listFiles();
ArrayList<String> result = new ArrayList<String>();
for(World world : worlds){
File[] files = new File(world.getName()+"/players").listFiles();
for (int i = 0; i < files.length; i++){
int whereDot = files[i].getName().lastIndexOf('.');
for (File file : files){
int whereDot = file.getName().lastIndexOf('.');
if (0 < whereDot && whereDot <= files[i].getName().length() - 2){
String playerName = files[i].getName().substring(0, whereDot);
if (0 < whereDot && whereDot <= file.getName().length() - 2){
String playerName = file.getName().substring(0, whereDot);
if(!result.contains(playerName)) result.add(playerName);
result.add(playerName);
}
}
}
return result;
}

View File

@@ -0,0 +1,55 @@
/**
*
*/
package de.sockenklaus.XmlStats.Objects;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import com.nidefawl.Achievements.AchievementListData;
/**
* @author socrates
*
*/
public class Achievement extends Elem {
private String name;
private String description;
private String category;
private String stat;
private Integer value;
private Integer maxawards;
private String commands;
private Boolean enabled;
public Achievement(AchievementListData ach){
this.name = ach.getName();
this.description = ach.getDescription();
this.category = ach.getCategory();
this.stat = ach.getKey();
this.value = ach.getValue();
this.maxawards = ach.getMaxawards();
this.commands = ach.commands.toString();
this.enabled = ach.isEnabled();
}
protected Achievement(){
}
public Element getXml(Document doc){
Element result = doc.createElement("achievement");
result.setAttribute("enabled", this.enabled ?"true":"false");
result.appendChild(this.addXmlChild("name", this.name, doc));
result.appendChild(this.addXmlChild("description", this.description, doc));
result.appendChild(this.addXmlChild("category", this.category, doc));
result.appendChild(this.addXmlChild("stat", this.stat, doc));
result.appendChild(this.addXmlChild("value", this.value, doc));
result.appendChild(this.addXmlChild("maxawards", this.maxawards, doc));
result.appendChild(this.addXmlChild("commands", this.commands, doc));
return result;
}
}

View File

@@ -0,0 +1,43 @@
/**
*
*/
package de.sockenklaus.XmlStats.Objects;
import java.util.ArrayList;
import java.util.HashMap;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import com.nidefawl.Achievements.AchievementListData;
import de.sockenklaus.XmlStats.Datasource.AchievementsDS;
/**
* @author socrates
*
*/
public class Achievements extends Array {
protected ArrayList<Achievement> childNodes;
public Achievements(){
AchievementsDS ads = new AchievementsDS();
HashMap<String, AchievementListData> achList = ads.getAchievementsList();
for(String achName : achList.keySet()){
this.childNodes.add(new Achievement(achList.get(achName)));
}
}
public Element getXml(Document doc){
Element result = doc.createElement("achievements");
result.setAttribute("count", this.getCountStr());
for(Achievement ach : this.childNodes){
result.appendChild(ach.getXml(doc));
}
return result;
}
}

View File

@@ -0,0 +1,22 @@
/**
*
*/
package de.sockenklaus.XmlStats.Objects;
import java.util.ArrayList;
/**
* @author socrates
*
*/
public abstract class Array {
private ArrayList<?> childNodes;
public int getCountInt(){
return this.childNodes.size();
}
public String getCountStr(){
return String.valueOf(this.childNodes.size());
}
}

View File

@@ -0,0 +1,12 @@
/**
*
*/
package de.sockenklaus.XmlStats.Objects;
/**
* @author socrates
*
*/
public class Categories extends Array {
}

View File

@@ -0,0 +1,25 @@
/**
*
*/
package de.sockenklaus.XmlStats.Objects;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* @author socrates
*
*/
public abstract class Elem {
protected Element addXmlChild(String elemName, String text, Document doc){
Element result = doc.createElement(elemName);
result.setTextContent(text);
return result;
}
protected Element addXmlChild(String elemName, int value, Document doc){
Element result = doc.createElement(elemName);
result.setTextContent(String.valueOf(value));
return result;
}
}

View File

@@ -0,0 +1,14 @@
/**
*
*/
package de.sockenklaus.XmlStats.Objects;
import java.util.ArrayList;
/**
* @author socrates
*
*/
public class Items extends Array {
}

View File

@@ -0,0 +1,38 @@
/**
*
*/
package de.sockenklaus.XmlStats.Objects;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import com.nidefawl.Achievements.PlayerAchievement;
import de.sockenklaus.XmlStats.Datasource.AchievementsDS;
/**
* @author socrates
*
*/
public class UserAchievements extends Achievements {
public UserAchievements(String userName){
AchievementsDS ads = new AchievementsDS();
PlayerAchievement pa = ads.getUserAchievement(userName);
for(String paName : pa.achievements.keySet()){
this.childNodes.add(new UserAchievement(paName, pa.get(paName)));
}
}
public Element getXml(Document doc){
Element result = doc.createElement("achievements");
result.setAttribute("count", this.getCountStr());
for(Achievement ach : this.childNodes){
result.appendChild(((UserAchievement)ach).getXml(doc));
}
return result;
}
}

View File

@@ -0,0 +1,12 @@
/**
*
*/
package de.sockenklaus.XmlStats.Objects;
/**
* @author socrates
*
*/
public class Users extends Array {
}

View File

@@ -56,6 +56,7 @@ public class AchievementsList extends XmlWorker {
Element elem_ach = this.doc.createElement("achievement");
elem_ach.setAttribute("enabled", data.isEnabled()?"true":"false");
<<<<<<< HEAD
Element elem_achname = this.doc.createElement("name");
elem_achname.setTextContent(data.getName());
elem_ach.appendChild(elem_achname);
@@ -84,6 +85,16 @@ public class AchievementsList extends XmlWorker {
elem_commands.setTextContent(data.commands.toString());
elem_ach.appendChild(elem_commands);
=======
elem_ach.appendChild(getTextElem("name", data.getName()));
elem_ach.appendChild(getTextElem("description", data.getDescription()));
elem_ach.appendChild(getTextElem("category", data.getCategory()));
elem_ach.appendChild(getTextElem("stat", data.getKey()));
elem_ach.appendChild(getTextElem("value", data.getValue()));
elem_ach.appendChild(getTextElem("maxawards", data.getMaxawards()));
elem_ach.appendChild(getTextElem("commands", data.commands.toString()));
>>>>>>> parent of 40d9bce... Pushed version to 0.4. Did some work on object based XML generation.
return elem_ach;
}