Compare commits
40 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6231f9bf2d | ||
|
|
5a007d02f9 | ||
|
|
8be79fadc6 | ||
|
|
969b763e63 | ||
|
|
6c245b7503 | ||
|
|
65cc053677 | ||
|
|
9b2a10d6b3 | ||
|
|
ecefa61b53 | ||
|
|
d9414e7d49 | ||
|
|
e1ba7c60e7 | ||
|
|
379e9fb591 | ||
|
|
a022c05ee6 | ||
|
|
4ac770e4e9 | ||
|
|
4270515f8c | ||
|
|
5c8a6b1865 | ||
|
|
95443bad58 | ||
|
|
9a985737d6 | ||
|
|
2597c12183 | ||
|
|
ebc3e3d1fc | ||
|
|
40d9bceeb1 | ||
|
|
a2b31e14fc | ||
|
|
670143767d | ||
|
|
373de1f42b | ||
|
|
57adc1291c | ||
|
|
a2f8e4e3cd | ||
|
|
78a8704ab9 | ||
|
|
48fea3f1a5 | ||
|
|
7a40761e00 | ||
|
|
045919558d | ||
|
|
fca4b8c8cf | ||
|
|
2bfa7556e2 | ||
|
|
7f0f0f5027 | ||
|
|
0fbfc27d3c | ||
|
|
aa82666069 | ||
|
|
b325e0f2dd | ||
|
|
de2276bdcd | ||
|
|
5f8f96dcb6 | ||
|
|
f7b9a834ab | ||
|
|
4381237315 | ||
|
|
184ccb3cf3 |
3
.build.number
Normal file
3
.build.number
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#Build Number for ANT. Do not edit!
|
||||||
|
#Fri Feb 03 16:29:04 CET 2012
|
||||||
|
build.number=72
|
||||||
@@ -2,12 +2,9 @@
|
|||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry kind="src" path="src"/>
|
||||||
<classpathentry kind="lib" path="lib/Stats.jar"/>
|
<classpathentry kind="lib" path="lib/Stats.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/bukkit-0.0.1-SNAPSHOT.jar">
|
<classpathentry kind="lib" path="lib/Achievements.jar"/>
|
||||||
<attributes>
|
|
||||||
<attribute name="javadoc_location" value="http://jd.bukkit.org/apidocs/"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="lib" path="lib/iConomy.jar"/>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
|
<classpathentry kind="lib" path="lib/bukkit-1.1-R3.jar"/>
|
||||||
|
<classpathentry kind="lib" path="lib/Register.jar"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,2 @@
|
|||||||
bin/
|
bin/
|
||||||
dist/
|
dist/
|
||||||
.build.number
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
#Sat Aug 27 14:58:29 CEST 2011
|
#Fri Feb 03 00:30:05 CET 2012
|
||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
org.eclipse.jdt.core.compiler.source=1.6
|
org.eclipse.jdt.core.compiler.source=1.7
|
||||||
|
|||||||
34
README.md
34
README.md
@@ -1,18 +1,18 @@
|
|||||||
# XmlStats
|
# XmlStats v0.4
|
||||||
|
|
||||||
This plugin for the Bukkit Minecraft Server API ([Homepage](http://bukkit.org) | [Github](https://github.com/Bukkit/Bukkit )) offers the possibility to access some playerstats via xml files. The provided data is basically generated by [Stats](https://github.com/nidefawl/Stats).
|
This plugin for the Bukkit Minecraft Server API ([Homepage](http://bukkit.org) | [Github](https://github.com/Bukkit/Bukkit )) offers the possibility to access some playerstats via xml files. The provided data is basically generated by [Stats](https://github.com/nidefawl/Stats).
|
||||||
|
|
||||||
|
[](https://flattr.com/submit/auto?user_id=socke&url=https://github.com/sockenklaus/XmlStats&title=XmlStats&language=&tags=github&category=software)
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
To install the plugin, simply place the compiled **XmlStats.jar** in your servers plugin directory and execute the /reload-command on your server. The plugin will create it's config file in the /plugins/XmlStats directory. To enable the webserver of the plugin you have to edit the config.yml, set the following value and reload the server again:
|
To install the plugin, simply place the compiled **XmlStats.jar** in your servers plugin directory and execute the /reload-command on your server. The plugin will create it's config file in the /plugins/XmlStats directory.
|
||||||
|
|
||||||
options.webserver-enabled: true
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
### Game side
|
### Game side
|
||||||
|
|
||||||
At this time of the development you are only able to reload the plugin without reloading the whole server:
|
At this time of the development an Op is able to reload the plugin without reloading the whole server:
|
||||||
|
|
||||||
/xmlstats reload
|
/xmlstats reload
|
||||||
|
|
||||||
@@ -22,20 +22,34 @@ Afterwards you can access the following xml files:
|
|||||||
|
|
||||||
For a list of all known players on your server:
|
For a list of all known players on your server:
|
||||||
|
|
||||||
http://server:port/users.xml
|
http://server:port/user_list.xml
|
||||||
|
|
||||||
For the added up stats of all known players:
|
For the added up stats of all known players:
|
||||||
|
|
||||||
http://server:port/userstats.xml
|
http://server:port/user_stats.xml?sum=*
|
||||||
|
|
||||||
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/user_stats.xml?user=username
|
||||||
|
|
||||||
|
Or to fetch the stats of a list of users:
|
||||||
|
|
||||||
|
http://server:port/user_stats.xml?user=user1,user2
|
||||||
|
|
||||||
|
You can combine these parameters, so you can receive the sum of some users and specific stats:
|
||||||
|
|
||||||
|
http://server:port/user_stats.xml?sum=user1,user2&user=*
|
||||||
|
|
||||||
To get data provided by the iConomy plugin:
|
To get data provided by the iConomy plugin:
|
||||||
|
|
||||||
http://server:port/money.xml
|
http://server:port/user_balances.xml?user=*
|
||||||
|
http://server:port/user_balances.xml?sum=*
|
||||||
|
|
||||||
|
Also you can request achievement data provided by the achievements plugin via:
|
||||||
|
|
||||||
|
http://server:port/achievements_list.xml
|
||||||
|
http://server:port/user_achievements.xml?user=*
|
||||||
|
|
||||||
You can request gzip compressed files by using the parameter gzip=true. This works on all files:
|
You can request gzip compressed files by using the parameter gzip=true. This works on all files:
|
||||||
|
|
||||||
http://server:port/userstats.xml?gzip=true
|
http://server:port/userstats.xml?gzip=true
|
||||||
|
|||||||
@@ -5,13 +5,16 @@
|
|||||||
<property name="dist" value="dist" />
|
<property name="dist" value="dist" />
|
||||||
<property name="src" value="src" />
|
<property name="src" value="src" />
|
||||||
<property name="name" value="XmlStats" />
|
<property name="name" value="XmlStats" />
|
||||||
<property name="version" value="0.2" />
|
<property name="version" value="0.4" />
|
||||||
<property name="package" value="de/sockenklaus/XmlStats" />
|
<property name="package" value="de/sockenklaus/XmlStats" />
|
||||||
<property name="resources" value="resources" />
|
<property name="resources" value="resources" />
|
||||||
<property name="author" value="sockenklaus" />
|
<property name="author" value="sockenklaus" />
|
||||||
|
|
||||||
<path id="classpath">
|
<path id="classpath">
|
||||||
<pathelement location="lib/" />
|
<pathelement location="lib/Achievements.jar" />
|
||||||
|
<pathelement location="lib/Stats.jar" />
|
||||||
|
<pathelement location="lib/bukkit-1.1-R3.jar" />
|
||||||
|
<pathelement location="lib/Register.jar" />
|
||||||
</path>
|
</path>
|
||||||
|
|
||||||
<buildnumber file=".build.number" />
|
<buildnumber file=".build.number" />
|
||||||
@@ -33,6 +36,7 @@
|
|||||||
|
|
||||||
<jar jarfile="${dist}/${name}.jar">
|
<jar jarfile="${dist}/${name}.jar">
|
||||||
<fileset dir="${bin}"/>
|
<fileset dir="${bin}"/>
|
||||||
|
<fileset dir="${src}" includes="**/*.java" />
|
||||||
</jar>
|
</jar>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
|
|||||||
BIN
lib/Achievements.jar
Normal file
BIN
lib/Achievements.jar
Normal file
Binary file not shown.
BIN
lib/Register.jar
Normal file
BIN
lib/Register.jar
Normal file
Binary file not shown.
BIN
lib/Stats.jar
BIN
lib/Stats.jar
Binary file not shown.
Binary file not shown.
BIN
lib/iConomy.jar
BIN
lib/iConomy.jar
Binary file not shown.
73
src/de/sockenklaus/XmlStats/Datasource/AchievementsDS.java
Normal file
73
src/de/sockenklaus/XmlStats/Datasource/AchievementsDS.java
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.sockenklaus.XmlStats.Datasource;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import com.nidefawl.Achievements.AchievementListData;
|
||||||
|
import com.nidefawl.Achievements.Achievements;
|
||||||
|
import com.nidefawl.Achievements.PlayerAchievement;
|
||||||
|
import com.nidefawl.Achievements.PlayerAchievementFile;
|
||||||
|
import com.nidefawl.Achievements.PlayerAchievementSQL;
|
||||||
|
|
||||||
|
import de.sockenklaus.XmlStats.XmlStats;
|
||||||
|
import de.sockenklaus.XmlStats.XmlStatsRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author socrates
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class AchievementsDS extends Datasource {
|
||||||
|
private XmlStats xmlstats = null;
|
||||||
|
|
||||||
|
public AchievementsDS(){
|
||||||
|
this.xmlstats = (XmlStats)XmlStatsRegistry.get("xmlstats");
|
||||||
|
}
|
||||||
|
//HashMap<String, PlayerAchievement> playerAchievementsList;
|
||||||
|
|
||||||
|
public HashMap<String, AchievementListData> getAchievementsList(){
|
||||||
|
Achievements ach = (Achievements)XmlStatsRegistry.get("achievements");
|
||||||
|
|
||||||
|
if(xmlstats.checkAchievements()){
|
||||||
|
return ach.achievementList;
|
||||||
|
}
|
||||||
|
else return new HashMap<String, AchievementListData>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*public void refreshPlayerAchievements(){
|
||||||
|
PlayerAchievement pa;
|
||||||
|
Achievements ach = (Achievements)XmlStatsRegistry.get("achievements");
|
||||||
|
|
||||||
|
if(ach.useSQL){
|
||||||
|
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
public PlayerAchievement getUserAchievement(String playerName){
|
||||||
|
|
||||||
|
PlayerAchievement pa;
|
||||||
|
Achievements ach = (Achievements)XmlStatsRegistry.get("achievements");
|
||||||
|
|
||||||
|
if(ach.useSQL){
|
||||||
|
String location = ach.getDataFolder().getPath() + File.separator + playerName + ".txt";
|
||||||
|
File fold = new File(location);
|
||||||
|
|
||||||
|
pa = new PlayerAchievementSQL(playerName);
|
||||||
|
if(fold.exists()){
|
||||||
|
PlayerAchievement paold = new PlayerAchievementFile(ach.getDataFolder().getPath(), playerName);
|
||||||
|
paold.load();
|
||||||
|
File fnew = new File(location + ".old");
|
||||||
|
fold.renameTo(fnew);
|
||||||
|
pa.copy(paold);
|
||||||
|
pa.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else pa = new PlayerAchievementFile(ach.getDataFolder().getPath(), playerName);
|
||||||
|
|
||||||
|
pa.load();
|
||||||
|
|
||||||
|
return pa;
|
||||||
|
}
|
||||||
|
}
|
||||||
87
src/de/sockenklaus/XmlStats/Datasource/BalancesDS.java
Normal file
87
src/de/sockenklaus/XmlStats/Datasource/BalancesDS.java
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) [2011] [Pascal Koenig]
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it under the terms of
|
||||||
|
* the GNU General Public License as published by the Free Software Foundation; either version
|
||||||
|
* 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program;
|
||||||
|
* if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.sockenklaus.XmlStats.Datasource;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.nijikokun.register.payment.Method;
|
||||||
|
import com.nijikokun.register.payment.Method.MethodAccount;
|
||||||
|
import com.nijikokun.register.payment.Methods;
|
||||||
|
|
||||||
|
import de.sockenklaus.XmlStats.XmlStats;
|
||||||
|
import de.sockenklaus.XmlStats.XmlStatsRegistry;
|
||||||
|
import de.sockenklaus.XmlStats.Exceptions.XmlStatsException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class MoneyDS.
|
||||||
|
*/
|
||||||
|
public class BalancesDS extends Datasource {
|
||||||
|
|
||||||
|
private ArrayList<String> allPlayers;
|
||||||
|
private XmlStats xmlstats;
|
||||||
|
|
||||||
|
public BalancesDS(){
|
||||||
|
this.allPlayers = fetchAllPlayers();
|
||||||
|
this.xmlstats = (XmlStats)XmlStatsRegistry.get("xmlstats");
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, Double> getBalances() throws XmlStatsException {
|
||||||
|
HashMap<String, Double> result = new HashMap<String, Double>();
|
||||||
|
|
||||||
|
for (String playerName : allPlayers){
|
||||||
|
result.put(playerName, getBalance(playerName));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getBalance(String playerName) throws XmlStatsException {
|
||||||
|
Double result = 0.0;
|
||||||
|
|
||||||
|
if (xmlstats.checkRegister()){
|
||||||
|
|
||||||
|
Method paymentMethod = Methods.getMethod();
|
||||||
|
|
||||||
|
if(paymentMethod.hasAccount(playerName)){
|
||||||
|
MethodAccount account = paymentMethod.getAccount(playerName);
|
||||||
|
|
||||||
|
if (account != null){
|
||||||
|
result = account.balance();
|
||||||
|
}
|
||||||
|
else throw new XmlStatsException("The player \""+playerName+"\" has an account but it isn't valid.");
|
||||||
|
}
|
||||||
|
else throw new XmlStatsException("The player \""+playerName+"\" doesn't have a bank account.");
|
||||||
|
}
|
||||||
|
else throw new XmlStatsException("Something went wrong! /user_balances.xml shouldn't be enabled but it's datasource was called!");
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getSum(List<String> list) throws XmlStatsException {
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
for(String playerName : list){
|
||||||
|
result+=this.getBalance(playerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) [2011] [Pascal K<EFBFBD>nig]
|
* Copyright (C) [2011] [Pascal Koenig]
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it under the terms of
|
* This program is free software; you can redistribute it and/or modify it under the terms of
|
||||||
* the GNU General Public License as published by the Free Software Foundation; either version
|
* the GNU General Public License as published by the Free Software Foundation; either version
|
||||||
@@ -16,6 +16,13 @@ package de.sockenklaus.XmlStats.Datasource;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
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
|
// TODO: Auto-generated Javadoc
|
||||||
/**
|
/**
|
||||||
@@ -28,20 +35,40 @@ public abstract class Datasource {
|
|||||||
*
|
*
|
||||||
* @return the array list
|
* @return the array list
|
||||||
*/
|
*/
|
||||||
public ArrayList<String> fetchAllPlayers(){
|
public static ArrayList<String> fetchAllPlayers(){
|
||||||
File[] files = new File("world/players").listFiles();
|
XmlStats xmlstats = (XmlStats)XmlStatsRegistry.get("xmlstats");
|
||||||
|
List<World> worlds = xmlstats.getServer().getWorlds();
|
||||||
ArrayList<String> result = new ArrayList<String>();
|
ArrayList<String> result = new ArrayList<String>();
|
||||||
|
|
||||||
for (int i = 0; i < files.length; i++){
|
for(World world : worlds){
|
||||||
int whereDot = files[i].getName().lastIndexOf('.');
|
File[] files = new File(world.getName()+"/players").listFiles();
|
||||||
|
|
||||||
if (0 < whereDot && whereDot <= files[i].getName().length() - 2){
|
for (File file : files){
|
||||||
String playerName = files[i].getName().substring(0, whereDot);
|
int whereDot = file.getName().lastIndexOf('.');
|
||||||
|
|
||||||
result.add(playerName);
|
if (0 < whereDot && whereDot <= file.getName().length() - 2){
|
||||||
|
String playerName = file.getName().substring(0, whereDot);
|
||||||
|
|
||||||
|
if(!result.contains(playerName)) result.add(playerName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean userExists(String player){
|
||||||
|
return fetchAllPlayers().contains(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> fetchValidUsers(List<String> list) throws XmlStatsException{
|
||||||
|
ArrayList<String> output = new ArrayList<String>();
|
||||||
|
|
||||||
|
for (String possibleUser : list){
|
||||||
|
if(Datasource.userExists(possibleUser)) output.add(possibleUser);
|
||||||
|
}
|
||||||
|
if(output.isEmpty()) throw new XmlStatsException("No valid user has been found!");
|
||||||
|
else return output;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) [2011] [Pascal K<>nig]
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify it under the terms of
|
|
||||||
* the GNU General Public License as published by the Free Software Foundation; either version
|
|
||||||
* 3 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
||||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
* See the GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with this program;
|
|
||||||
* if not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
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;
|
|
||||||
import de.sockenklaus.XmlStats.XmlStatsRegistry;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Class MoneyDS.
|
|
||||||
*/
|
|
||||||
public class MoneyDS extends Datasource {
|
|
||||||
|
|
||||||
private iConomy iConomy;
|
|
||||||
private ArrayList<String> allPlayers;
|
|
||||||
|
|
||||||
public MoneyDS(){
|
|
||||||
this.iConomy = (iConomy)XmlStatsRegistry.get("iconomy");
|
|
||||||
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.LogWarn("The player \""+playerName+"\" has an account but it isn't valid. Bad data will return.");
|
|
||||||
}
|
|
||||||
else XmlStats.LogWarn("The player \""+playerName+"\" 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) [2011] [Pascal K<EFBFBD>nig]
|
* Copyright (C) [2011] [Pascal Koenig]
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it under the terms of
|
* This program is free software; you can redistribute it and/or modify it under the terms of
|
||||||
* the GNU General Public License as published by the Free Software Foundation; either version
|
* the GNU General Public License as published by the Free Software Foundation; either version
|
||||||
@@ -14,20 +14,9 @@
|
|||||||
*/
|
*/
|
||||||
package de.sockenklaus.XmlStats.Datasource;
|
package de.sockenklaus.XmlStats.Datasource;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
// TODO: Auto-generated Javadoc
|
// TODO: Auto-generated Javadoc
|
||||||
/**
|
/**
|
||||||
* The Class UsersDS.
|
* The Class UsersDS.
|
||||||
*/
|
*/
|
||||||
public class UsersDS extends Datasource {
|
public class UsersDS extends Datasource {
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Gets the all players.
|
|
||||||
*
|
|
||||||
* @return the all players
|
|
||||||
*/
|
|
||||||
public ArrayList<String> getAllPlayers(){
|
|
||||||
return fetchAllPlayers();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) [2011] [Pascal K<EFBFBD>nig]
|
* Copyright (C) [2011] [Pascal Koenig]
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it under the terms of
|
* This program is free software; you can redistribute it and/or modify it under the terms of
|
||||||
* the GNU General Public License as published by the Free Software Foundation; either version
|
* the GNU General Public License as published by the Free Software Foundation; either version
|
||||||
@@ -16,11 +16,17 @@ package de.sockenklaus.XmlStats.Datasource;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.nidefawl.Stats.Stats;
|
import terranetworkorg.Stats.Stats;
|
||||||
|
import terranetworkorg.Stats.Storage.PlayerCache;
|
||||||
|
import terranetworkorg.Stats.Storage.PlayerControl;
|
||||||
|
import terranetworkorg.Stats.Storage.PlayerStats;
|
||||||
|
|
||||||
|
/*import com.nidefawl.Stats.Stats;
|
||||||
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 com.nidefawl.Stats.datasource.PlayerStatSQL;
|
import com.nidefawl.Stats.datasource.PlayerStatSQL;*/
|
||||||
|
|
||||||
import de.sockenklaus.XmlStats.XmlStatsRegistry;
|
import de.sockenklaus.XmlStats.XmlStatsRegistry;
|
||||||
|
|
||||||
@@ -30,78 +36,93 @@ 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(){
|
public static HashMap<String, HashMap<String, Integer>> getAddedStats(List<String> playerList){
|
||||||
HashMap <String, HashMap<String, Integer>> result = new HashMap<String, HashMap<String, Integer>>();
|
HashMap <String, HashMap<String, Integer>> result = new HashMap<String, HashMap<String, Integer>>();
|
||||||
|
|
||||||
for(String playerName : this.fetchAllPlayers()){
|
for(String playerName : playerList){
|
||||||
PlayerStat player = this.getPlayerStat(playerName);
|
PlayerCache player = getPlayerCache(playerName);
|
||||||
|
|
||||||
for(String catName : player.getCats()){
|
for(PlayerStats ps : player.getStats()){
|
||||||
Category cat = player.get(catName);
|
if(!result.containsKey(ps.getCat())){
|
||||||
|
/*
|
||||||
for(String entryName : cat.getEntries()){
|
* Fall 1:
|
||||||
Integer entry = cat.get(entryName);
|
* Result enthaelt schon die Kat nicht
|
||||||
|
*/
|
||||||
|
HashMap<String, Integer> tmpMap = new HashMap<String, Integer>();
|
||||||
|
tmpMap.put(ps.getName(), ps.getValue());
|
||||||
|
result.put(ps.getCat(), tmpMap);
|
||||||
|
}
|
||||||
|
else if(!result.get(ps.getCat()).containsKey(ps.getName())){
|
||||||
|
/*
|
||||||
|
* Fall 2: Result enthaelt Cat aber Stat nicht.
|
||||||
|
*/
|
||||||
|
result.get(ps.getCat()).put(ps.getName(), ps.getValue());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/*
|
||||||
|
* Fall 3: Es ist beides schon vorhanden
|
||||||
|
*/
|
||||||
|
Integer currVal = result.get(ps.getCat()).get(ps.getName());
|
||||||
|
|
||||||
if(result.containsKey(catName)){
|
if(ps.getName().equals("lastlogin") || ps.getName().equals("lastlogout")){
|
||||||
if(result.get(catName).containsKey(entryName)){
|
result.get(ps.getCat()).put(ps.getName(), Math.max(ps.getValue(), currVal));
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
result.get(catName).put(entryName, entry);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
HashMap<String, Integer> tempMap = new HashMap<String, Integer>();
|
result.get(ps.getCat()).put(ps.getName(), currVal + ps.getValue());
|
||||||
tempMap.put(entryName, entry);
|
|
||||||
result.put(catName, tempMap);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HashMap<String, HashMap<String, Integer>> getStats(String playerName){
|
||||||
|
HashMap<String, HashMap<String, Integer>> result = new HashMap<String, HashMap<String, Integer>>();
|
||||||
|
|
||||||
|
PlayerCache player = getPlayerCache(playerName);
|
||||||
|
|
||||||
|
for(PlayerStats ps : player.getStats()){
|
||||||
|
if(!result.containsKey(ps.getCat())){
|
||||||
|
/*
|
||||||
|
* Fall 1: Result enthaelt die Kategorie nicht.
|
||||||
|
*/
|
||||||
|
HashMap<String, Integer> tmpMap = new HashMap<String, Integer>();
|
||||||
|
tmpMap.put(ps.getName(), ps.getValue());
|
||||||
|
result.put(ps.getCat(), tmpMap);
|
||||||
|
}
|
||||||
|
else if(!result.get(ps.getCat()).containsKey(ps.getName())){
|
||||||
|
/*
|
||||||
|
* Fall 2: Result kennt Kategorie, aber nicht den Stat.
|
||||||
|
*/
|
||||||
|
result.get(ps.getCat()).put(ps.getName(), ps.getValue());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/*
|
||||||
|
* Fall 3 (sollte nicht auftreten): Result kennt beides schon.
|
||||||
|
* Im Zweifel ueberschreiben...
|
||||||
|
*/
|
||||||
|
result.get(ps.getCat()).put(ps.getName(), ps.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerStat getPlayerStat(String playerName){
|
private static PlayerCache getPlayerCache(String playerName){
|
||||||
PlayerStat result = new PlayerStatSQL(playerName, this.statsPlugin);
|
return PlayerControl.getPlayerCache(playerName);
|
||||||
|
|
||||||
result.load();
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.sockenklaus.XmlStats.Exceptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author socrates
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class XmlStatsException extends Exception {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = -6660078004710596491L;
|
||||||
|
|
||||||
|
public XmlStatsException(String s){
|
||||||
|
super(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
47
src/de/sockenklaus/XmlStats/Objects/Node.java
Normal file
47
src/de/sockenklaus/XmlStats/Objects/Node.java
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.sockenklaus.XmlStats.Objects;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author socrates
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class Node {
|
||||||
|
|
||||||
|
protected String tagName;
|
||||||
|
protected HashMap<String, String> attributes;
|
||||||
|
|
||||||
|
public Node(){
|
||||||
|
this.attributes = new HashMap<String, String>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAttribute(String name, String 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){
|
||||||
|
Element result = doc.createElement(this.tagName);
|
||||||
|
|
||||||
|
for(String attrName : this.attributes.keySet()){
|
||||||
|
result.setAttribute(attrName, this.attributes.get(attrName));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
30
src/de/sockenklaus/XmlStats/Objects/NodeAchievement.java
Normal file
30
src/de/sockenklaus/XmlStats/Objects/NodeAchievement.java
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.sockenklaus.XmlStats.Objects;
|
||||||
|
|
||||||
|
import com.nidefawl.Achievements.AchievementListData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author socrates
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class NodeAchievement extends NodeList {
|
||||||
|
|
||||||
|
public NodeAchievement(){
|
||||||
|
super("achievement");
|
||||||
|
}
|
||||||
|
|
||||||
|
public NodeAchievement(AchievementListData ach){
|
||||||
|
super("achievement");
|
||||||
|
|
||||||
|
this.childNodes.add(new NodeText("name", ach.getName()));
|
||||||
|
this.childNodes.add(new NodeText("description", ach.getDescription()));
|
||||||
|
this.childNodes.add(new NodeText("category", ach.getCategory()));
|
||||||
|
this.childNodes.add(new NodeText("stat", ach.getKey()));
|
||||||
|
this.childNodes.add(new NodeText("value", ach.getValue()));
|
||||||
|
this.childNodes.add(new NodeText("maxawards", ach.getMaxawards()));
|
||||||
|
this.childNodes.add(new NodeText("commands", ach.commands.toString()));
|
||||||
|
this.attributes.put("enabled", String.valueOf(ach.isEnabled()));
|
||||||
|
}
|
||||||
|
}
|
||||||
28
src/de/sockenklaus/XmlStats/Objects/NodeAchievements.java
Normal file
28
src/de/sockenklaus/XmlStats/Objects/NodeAchievements.java
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.sockenklaus.XmlStats.Objects;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import com.nidefawl.Achievements.AchievementListData;
|
||||||
|
|
||||||
|
import de.sockenklaus.XmlStats.Datasource.AchievementsDS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author socrates
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class NodeAchievements extends NodeArray {
|
||||||
|
|
||||||
|
public NodeAchievements(){
|
||||||
|
super("achievements");
|
||||||
|
AchievementsDS ads = new AchievementsDS();
|
||||||
|
|
||||||
|
HashMap<String, AchievementListData> achList = ads.getAchievementsList();
|
||||||
|
|
||||||
|
for(String achName : achList.keySet()){
|
||||||
|
this.childNodes.add(new NodeAchievement(achList.get(achName)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
24
src/de/sockenklaus/XmlStats/Objects/NodeArray.java
Normal file
24
src/de/sockenklaus/XmlStats/Objects/NodeArray.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.sockenklaus.XmlStats.Objects;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author socrates
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class NodeArray extends NodeList {
|
||||||
|
|
||||||
|
public NodeArray(String tagName){
|
||||||
|
super(tagName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Element getXml(Document doc){
|
||||||
|
this.attributes.put("count", String.valueOf(this.childNodes.size()));
|
||||||
|
|
||||||
|
return super.getXml(doc);
|
||||||
|
}
|
||||||
|
}
|
||||||
31
src/de/sockenklaus/XmlStats/Objects/NodeCategories.java
Normal file
31
src/de/sockenklaus/XmlStats/Objects/NodeCategories.java
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.sockenklaus.XmlStats.Objects;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import de.sockenklaus.XmlStats.Datasource.UserstatsDS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author socrates
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class NodeCategories extends NodeArray {
|
||||||
|
|
||||||
|
public NodeCategories(){
|
||||||
|
super("categories");
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param tagName
|
||||||
|
*/
|
||||||
|
public NodeCategories(String userName) {
|
||||||
|
this();
|
||||||
|
HashMap<String, HashMap<String, Integer>> userStat = UserstatsDS.getStats(userName);
|
||||||
|
|
||||||
|
for(String catName : userStat.keySet()){
|
||||||
|
NodeCategory node_cat = new NodeCategory(catName, userStat.get(catName));
|
||||||
|
this.appendChild(node_cat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
24
src/de/sockenklaus/XmlStats/Objects/NodeCategory.java
Normal file
24
src/de/sockenklaus/XmlStats/Objects/NodeCategory.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.sockenklaus.XmlStats.Objects;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author socrates
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class NodeCategory extends NodeList {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param category
|
||||||
|
*/
|
||||||
|
public NodeCategory(String catName, HashMap<String, Integer> category) {
|
||||||
|
super("category");
|
||||||
|
|
||||||
|
this.appendChild(new NodeText("name", catName));
|
||||||
|
this.appendChild(new NodeItems(category));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
22
src/de/sockenklaus/XmlStats/Objects/NodeItem.java
Normal file
22
src/de/sockenklaus/XmlStats/Objects/NodeItem.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.sockenklaus.XmlStats.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author socrates
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class NodeItem extends NodeList {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param varName
|
||||||
|
* @param i
|
||||||
|
*/
|
||||||
|
public NodeItem(String varName, int value) {
|
||||||
|
super("item");
|
||||||
|
|
||||||
|
this.appendChild(new NodeText("name", varName));
|
||||||
|
this.appendChild(new NodeText("value", value));
|
||||||
|
}
|
||||||
|
}
|
||||||
25
src/de/sockenklaus/XmlStats/Objects/NodeItems.java
Normal file
25
src/de/sockenklaus/XmlStats/Objects/NodeItems.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.sockenklaus.XmlStats.Objects;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author socrates
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class NodeItems extends NodeArray {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param category
|
||||||
|
*/
|
||||||
|
public NodeItems(HashMap<String, Integer> category) {
|
||||||
|
super("items");
|
||||||
|
|
||||||
|
for(String varName : category.keySet()){
|
||||||
|
this.appendChild(new NodeItem(varName, category.get(varName)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/de/sockenklaus/XmlStats/Objects/NodeList.java
Normal file
36
src/de/sockenklaus/XmlStats/Objects/NodeList.java
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.sockenklaus.XmlStats.Objects;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author socrates
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class NodeList extends Node {
|
||||||
|
protected ArrayList<Node> childNodes;
|
||||||
|
|
||||||
|
public NodeList(String tagName){
|
||||||
|
this.childNodes = new ArrayList<Node>();
|
||||||
|
this.tagName = tagName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void appendChild(Node child){
|
||||||
|
this.childNodes.add(child);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Element getXml(Document doc){
|
||||||
|
Element result = super.getXml(doc);
|
||||||
|
|
||||||
|
for(Node node : this.childNodes){
|
||||||
|
result.appendChild(node.getXml(doc));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
43
src/de/sockenklaus/XmlStats/Objects/NodeText.java
Normal file
43
src/de/sockenklaus/XmlStats/Objects/NodeText.java
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.sockenklaus.XmlStats.Objects;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author socrates
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class NodeText extends Node {
|
||||||
|
|
||||||
|
protected String textContent;
|
||||||
|
|
||||||
|
public NodeText(String tagName){
|
||||||
|
this.tagName = tagName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NodeText(String tagName, String textContent){
|
||||||
|
this(tagName);
|
||||||
|
this.textContent = textContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NodeText(String tagName, Integer intContent) {
|
||||||
|
this(tagName);
|
||||||
|
this.textContent = intContent.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public NodeText(String tagName, Double dblContent){
|
||||||
|
this(tagName);
|
||||||
|
this.textContent = dblContent.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Element getXml(Document doc){
|
||||||
|
Element result = super.getXml(doc);
|
||||||
|
|
||||||
|
if (!this.textContent.isEmpty()) result.setTextContent(this.textContent);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
35
src/de/sockenklaus/XmlStats/Objects/NodeUser.java
Normal file
35
src/de/sockenklaus/XmlStats/Objects/NodeUser.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.sockenklaus.XmlStats.Objects;
|
||||||
|
|
||||||
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import de.sockenklaus.XmlStats.XmlStats;
|
||||||
|
import de.sockenklaus.XmlStats.XmlStatsRegistry;
|
||||||
|
import de.sockenklaus.XmlStats.Datasource.Datasource;
|
||||||
|
import de.sockenklaus.XmlStats.Exceptions.XmlStatsException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author socrates
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class NodeUser extends NodeList {
|
||||||
|
|
||||||
|
public NodeUser(String name) throws XmlStatsException{
|
||||||
|
super("user");
|
||||||
|
if (Datasource.userExists(name)){
|
||||||
|
Server server = ((XmlStats)XmlStatsRegistry.get("xmlstats")).getServer();
|
||||||
|
Player player = server.getPlayer(name);
|
||||||
|
|
||||||
|
String status = (player != null && player.isOnline()) ?"online":"offline";
|
||||||
|
this.attributes.put("status", status);
|
||||||
|
this.childNodes.add(new NodeText("name", name));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new XmlStatsException("The given user doesn't exist!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
20
src/de/sockenklaus/XmlStats/Objects/NodeUserAchievement.java
Normal file
20
src/de/sockenklaus/XmlStats/Objects/NodeUserAchievement.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.sockenklaus.XmlStats.Objects;
|
||||||
|
|
||||||
|
import com.nidefawl.Achievements.Achievement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author socrates
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class NodeUserAchievement extends NodeList {
|
||||||
|
|
||||||
|
public NodeUserAchievement(String paName, Achievement achievement){
|
||||||
|
super("achievement");
|
||||||
|
this.childNodes.add(new NodeText("name", paName));
|
||||||
|
this.childNodes.add(new NodeText("count", achievement.getCount()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.sockenklaus.XmlStats.Objects;
|
||||||
|
|
||||||
|
import com.nidefawl.Achievements.PlayerAchievement;
|
||||||
|
|
||||||
|
import de.sockenklaus.XmlStats.Datasource.AchievementsDS;
|
||||||
|
import de.sockenklaus.XmlStats.Datasource.Datasource;
|
||||||
|
import de.sockenklaus.XmlStats.Exceptions.XmlStatsException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author socrates
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class NodeUserAchievements extends NodeArray {
|
||||||
|
public NodeUserAchievements(String userName) throws XmlStatsException{
|
||||||
|
super("achivements");
|
||||||
|
AchievementsDS ads = new AchievementsDS();
|
||||||
|
|
||||||
|
if (Datasource.userExists(userName)){
|
||||||
|
PlayerAchievement pa = ads.getUserAchievement(userName);
|
||||||
|
|
||||||
|
for(String paName : pa.achievements.keySet()){
|
||||||
|
this.childNodes.add(new NodeUserAchievement(paName, pa.get(paName)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else throw new XmlStatsException("The given username is not valid.");
|
||||||
|
}
|
||||||
|
}
|
||||||
20
src/de/sockenklaus/XmlStats/Objects/NodeUsers.java
Normal file
20
src/de/sockenklaus/XmlStats/Objects/NodeUsers.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.sockenklaus.XmlStats.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author socrates
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class NodeUsers extends NodeArray {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param tagName
|
||||||
|
*/
|
||||||
|
public NodeUsers() {
|
||||||
|
super("users");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) [2011] [Pascal K<EFBFBD>nig]
|
* Copyright (C) [2011] [Pascal Koenig]
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it under the terms of
|
* This program is free software; you can redistribute it and/or modify it under the terms of
|
||||||
* the GNU General Public License as published by the Free Software Foundation; either version
|
* the GNU General Public License as published by the Free Software Foundation; either version
|
||||||
@@ -15,8 +15,9 @@
|
|||||||
package de.sockenklaus.XmlStats;
|
package de.sockenklaus.XmlStats;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.bukkit.util.config.Configuration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
// TODO: Auto-generated Javadoc
|
// TODO: Auto-generated Javadoc
|
||||||
/**
|
/**
|
||||||
@@ -25,7 +26,7 @@ import org.bukkit.util.config.Configuration;
|
|||||||
public class Settings {
|
public class Settings {
|
||||||
|
|
||||||
private static final String configFilename = "config.yml";
|
private static final String configFilename = "config.yml";
|
||||||
private Configuration conf;
|
private YamlConfiguration conf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new settings.
|
* Instantiates a new settings.
|
||||||
@@ -35,15 +36,18 @@ public class Settings {
|
|||||||
public Settings(XmlStats xmlStats){
|
public Settings(XmlStats xmlStats){
|
||||||
File f = new File(xmlStats.getDataFolder(), configFilename);
|
File f = new File(xmlStats.getDataFolder(), configFilename);
|
||||||
|
|
||||||
conf = new Configuration(f);
|
|
||||||
if(f.exists()){
|
if(f.exists()){
|
||||||
conf.load();
|
conf = YamlConfiguration.loadConfiguration(f);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
conf.setProperty("options.webserver-enabled", true);
|
conf.set("options.webserver-enabled", true);
|
||||||
conf.setProperty("options.webserver-port", 9123);
|
conf.set("options.webserver-port", 9123);
|
||||||
conf.setProperty("options.verbose-enabled", true);
|
conf.set("options.verbose-enabled", true);
|
||||||
conf.save();
|
try {
|
||||||
|
conf.save(f);
|
||||||
|
}catch(IOException e){
|
||||||
|
XmlStats.LogError("Something went wrong with the conf-file: "+e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +88,7 @@ public class Settings {
|
|||||||
* @param value the value
|
* @param value the value
|
||||||
*/
|
*/
|
||||||
public void setProperty(String path, Object value){
|
public void setProperty(String path, Object value){
|
||||||
conf.setProperty(path, value);
|
conf.set(path, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) [2011] [Pascal K<EFBFBD>nig]
|
* Copyright (C) [2011] [Pascal Koenig]
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it under the terms of
|
* This program is free software; you can redistribute it and/or modify it under the terms of
|
||||||
* the GNU General Public License as published by the Free Software Foundation; either version
|
* the GNU General Public License as published by the Free Software Foundation; either version
|
||||||
@@ -29,6 +29,7 @@ public class Webserver {
|
|||||||
|
|
||||||
private InetSocketAddress address;
|
private InetSocketAddress address;
|
||||||
private HttpServer server = null;
|
private HttpServer server = null;
|
||||||
|
private XmlStats xmlstats = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new web server.
|
* Instantiates a new web server.
|
||||||
@@ -38,7 +39,7 @@ public class Webserver {
|
|||||||
*/
|
*/
|
||||||
public Webserver() throws IOException {
|
public Webserver() throws IOException {
|
||||||
Settings settingsTemp = (Settings)XmlStatsRegistry.get("settings");
|
Settings settingsTemp = (Settings)XmlStatsRegistry.get("settings");
|
||||||
|
this.xmlstats = (XmlStats)XmlStatsRegistry.get("xmlstats");
|
||||||
this.start(settingsTemp.getInt("options.webserver-port"));
|
this.start(settingsTemp.getInt("options.webserver-port"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,24 +73,47 @@ public class Webserver {
|
|||||||
this.server = null;
|
this.server = null;
|
||||||
|
|
||||||
this.address = new InetSocketAddress(port);
|
this.address = new InetSocketAddress(port);
|
||||||
|
XmlStats.LogDebug("Opened socket on port "+port);
|
||||||
|
|
||||||
this.server = HttpServer.create(this.address, 0);
|
this.server = HttpServer.create(this.address, 0);
|
||||||
|
XmlStats.LogDebug("Created webserver.");
|
||||||
|
|
||||||
this.server.createContext("/users.xml", new XmlWorkerUsers());
|
this.server.createContext("/user_list.xml", new UserList());
|
||||||
|
XmlStats.LogDebug("Created context /user_list.xml.");
|
||||||
if(XmlStats.isStatsHooked()){
|
|
||||||
server.createContext("/userstats.xml", new XmlWorkerUserstats());
|
|
||||||
XmlStats.LogInfo("Stats seems to be loaded correctly. Enabling /userstats.xml");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (XmlStats.isiConomyHooked()){
|
|
||||||
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();
|
||||||
|
XmlStats.LogDebug("Started webserver.");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void startRegister(){
|
||||||
|
XmlStats.LogDebug("Casting startRegister()");
|
||||||
|
if (this.isRunning() && xmlstats.checkRegister()){
|
||||||
|
server.createContext("/user_balances.xml", new UserBalances());
|
||||||
|
XmlStats.LogInfo("Register seems to be loaded correctly. Enabling /user_balances.xml");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
XmlStats.LogWarn("Register or webserver not loaded correctly. Disabling /users_balances.xml");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void startAchievements(){
|
||||||
|
if(this.isRunning() && xmlstats.checkAchievements()){
|
||||||
|
server.createContext("/user_achievements.xml", new UserAchievements());
|
||||||
|
server.createContext("/achievements_list.xml", new AchievementsList());
|
||||||
|
XmlStats.LogInfo("Achievements seems to be loaded correctly. Enabling /user_achievements.xml");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
XmlStats.LogWarn("Achievements or webserver not loaded correctly. Disabling /user_achievements.xml");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void startStats(){
|
||||||
|
if(this.isRunning() && xmlstats.checkStats()){
|
||||||
|
server.createContext("/user_stats.xml", new UserStats());
|
||||||
|
XmlStats.LogInfo("Stats seems to be loaded correctly. Enabling /user_stats.xml");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
XmlStats.LogWarn("Stats or webserver not loaded correctly. Disabling /user_stats.xml");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) [2011] [Pascal K<EFBFBD>nig]
|
* Copyright (C) [2011] [Pascal Koenig]
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it under the terms of
|
* This program is free software; you can redistribute it and/or modify it under the terms of
|
||||||
* the GNU General Public License as published by the Free Software Foundation; either version
|
* the GNU General Public License as published by the Free Software Foundation; either version
|
||||||
@@ -22,8 +22,10 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import com.iConomy.iConomy;
|
import com.nidefawl.Achievements.Achievements;
|
||||||
import com.nidefawl.Stats.Stats;
|
import terranetworkorg.Stats.Stats;
|
||||||
|
import com.nijikokun.register.Register;
|
||||||
|
import com.nijikokun.register.payment.Methods;
|
||||||
|
|
||||||
// TODO: Auto-generated Javadoc
|
// TODO: Auto-generated Javadoc
|
||||||
/**
|
/**
|
||||||
@@ -46,14 +48,13 @@ public class XmlStats extends JavaPlugin {
|
|||||||
if(this.enabled && webserverTemp.isRunning()){
|
if(this.enabled && webserverTemp.isRunning()){
|
||||||
this.enabled = false;
|
this.enabled = false;
|
||||||
|
|
||||||
XmlStatsRegistry.flush();
|
|
||||||
|
|
||||||
webserverTemp.stop();
|
webserverTemp.stop();
|
||||||
|
LogDebug("Webserver stopped.");
|
||||||
|
|
||||||
|
XmlStatsRegistry.flush();
|
||||||
getServer().getScheduler().cancelTasks(this);
|
getServer().getScheduler().cancelTasks(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
LogInfo("Plugin Disabled");
|
LogInfo("XmlStats Disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@@ -74,15 +75,15 @@ public class XmlStats extends JavaPlugin {
|
|||||||
LogDebug("options.webserver-enabled: "+settingsTemp.getBoolean("options.webserver-enabled"));
|
LogDebug("options.webserver-enabled: "+settingsTemp.getBoolean("options.webserver-enabled"));
|
||||||
LogDebug("options.webserver-port: "+settingsTemp.getInt("options.webserver-port"));
|
LogDebug("options.webserver-port: "+settingsTemp.getInt("options.webserver-port"));
|
||||||
LogDebug("options.verbose-enabled: "+settingsTemp.getBoolean("options.verbose-enabled"));
|
LogDebug("options.verbose-enabled: "+settingsTemp.getBoolean("options.verbose-enabled"));
|
||||||
|
|
||||||
this.hookPlugins();
|
|
||||||
|
|
||||||
if (settingsTemp.getBoolean("options.webserver-enabled")){
|
if (settingsTemp.getBoolean("options.webserver-enabled")){
|
||||||
try {
|
try {
|
||||||
XmlStatsRegistry.put("webserver", new Webserver());
|
XmlStatsRegistry.put("webserver", new Webserver());
|
||||||
|
|
||||||
this.enabled = true;
|
this.enabled = true;
|
||||||
LogInfo("XmStats "+this.version+" enabled");
|
LogInfo("XmStats "+this.version+" enabled");
|
||||||
|
this.hookPlugins();
|
||||||
|
this.registerEvents();
|
||||||
}
|
}
|
||||||
catch (Exception ex){
|
catch (Exception ex){
|
||||||
LogError("Fehler beim Erstellen des Webservers:");
|
LogError("Fehler beim Erstellen des Webservers:");
|
||||||
@@ -140,40 +141,70 @@ public class XmlStats extends JavaPlugin {
|
|||||||
* Hook plugins.
|
* Hook plugins.
|
||||||
*/
|
*/
|
||||||
protected void hookPlugins(){
|
protected void hookPlugins(){
|
||||||
Plugin StatsTemp = getServer().getPluginManager().getPlugin("Stats");
|
this.hookAchievements();
|
||||||
Plugin iConomyTemp = getServer().getPluginManager().getPlugin("iConomy");
|
this.hookRegister();
|
||||||
|
this.hookStats();
|
||||||
if(StatsTemp != null){
|
}
|
||||||
if(StatsTemp.isEnabled() && StatsTemp.getClass().getName().equals("com.nidefawl.Stats.Stats")){
|
|
||||||
XmlStatsRegistry.put("stats", (Stats)StatsTemp);
|
protected void hookRegister(){
|
||||||
LogInfo("Hooked into Stats!");
|
Plugin registerTemp = getServer().getPluginManager().getPlugin("Register");
|
||||||
}
|
Webserver webserver = (Webserver)XmlStatsRegistry.get("webserver");
|
||||||
|
|
||||||
|
if (this.checkRegister()) {
|
||||||
|
XmlStatsRegistry.put("register", (Register)registerTemp);
|
||||||
|
LogInfo("Hooked into Register");
|
||||||
|
webserver.startRegister();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LogError("Stats not found! Can't hook into it.");
|
LogWarn("Register or no payment method found! Can't hook into it.");
|
||||||
}
|
}
|
||||||
if (iConomyTemp != null) {
|
}
|
||||||
if (iConomyTemp.isEnabled() && iConomyTemp.getClass().getName().equals("com.iConomy.iConomy")) {
|
|
||||||
XmlStatsRegistry.put("iconomy", (iConomy)iConomyTemp);
|
protected void hookAchievements(){
|
||||||
LogInfo("Hooked into iConomy");
|
Plugin AchievementsTemp = getServer().getPluginManager().getPlugin("Achievements");
|
||||||
}
|
Webserver webserver = (Webserver)XmlStatsRegistry.get("webserver");
|
||||||
|
|
||||||
|
if(this.checkAchievements()){
|
||||||
|
XmlStatsRegistry.put("achievements", (Achievements)AchievementsTemp);
|
||||||
|
LogInfo("Hooked into Achievements!");
|
||||||
|
webserver.startAchievements();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LogError("iConomy not found! Can't hook into it.");
|
LogWarn("Achievements not found! Can't hook into it.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void hookStats(){
|
||||||
|
Plugin StatsTemp = getServer().getPluginManager().getPlugin("Stats 2.0");
|
||||||
|
LogDebug("Got Plugin \"Stats 2.0\"");
|
||||||
|
Webserver webserver = (Webserver)XmlStatsRegistry.get("webserver");
|
||||||
|
LogDebug("Got webserver-object");
|
||||||
|
|
||||||
|
if(this.checkStats()){
|
||||||
|
XmlStatsRegistry.put("stats", (Stats)StatsTemp);
|
||||||
|
LogInfo("Hooked into Stats!");
|
||||||
|
webserver.startStats();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogWarn("Stats not found! Can't hook into it.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if is stats hooked.
|
* Checks if is stats hooked.
|
||||||
*
|
*
|
||||||
* @return true, if is stats hooked
|
* @return true, if is stats hooked
|
||||||
*/
|
*/
|
||||||
public static boolean isStatsHooked(){
|
public boolean checkStats(){
|
||||||
Stats StatsTemp = (Stats)XmlStatsRegistry.get("stats");
|
LogDebug("Stats 2.0? Are you there?");
|
||||||
|
Plugin StatsTemp = getServer().getPluginManager().getPlugin("Stats 2.0");
|
||||||
|
LogDebug("Got object \"Stats 2.0\"");
|
||||||
|
|
||||||
if (StatsTemp != null){
|
if(StatsTemp != null && StatsTemp.getClass().getName().equals("terranetworkorg.Stats.Stats") && StatsTemp.isEnabled()){
|
||||||
if(StatsTemp.getClass().getName().equals("com.nidefawl.Stats.Stats") && StatsTemp.isEnabled()) return true;
|
LogDebug("terranetworkorg.Stats.Stats is enabled.");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
LogDebug("terranetworkorg.Stats.Stats is not enabled.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,12 +213,22 @@ public class XmlStats extends JavaPlugin {
|
|||||||
*
|
*
|
||||||
* @return true, if is i conomy hooked
|
* @return true, if is i conomy hooked
|
||||||
*/
|
*/
|
||||||
public static boolean isiConomyHooked(){
|
public boolean checkRegister(){
|
||||||
iConomy iConomyTemp = (iConomy)XmlStatsRegistry.get("iconomy");
|
Plugin registerTemp = getServer().getPluginManager().getPlugin("Register");
|
||||||
|
|
||||||
|
if (registerTemp != null && registerTemp.getClass().getName().equals("com.nijikokun.register.Register") && registerTemp.isEnabled() && Methods.hasMethod()) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if is Achievements hooked.
|
||||||
|
*
|
||||||
|
* @return true, if is Achievements hooked
|
||||||
|
*/
|
||||||
|
public boolean checkAchievements(){
|
||||||
|
Plugin AchievementsTemp = getServer().getPluginManager().getPlugin("Achievements");
|
||||||
|
|
||||||
if (iConomyTemp != null){
|
if(AchievementsTemp != null && AchievementsTemp.getClass().getName().equals("com.nidefawl.Achievements.Achievements") && AchievementsTemp.isEnabled()) return true;
|
||||||
if (iConomyTemp.getClass().getName().equals("com.iConomy.iConomy") && iConomyTemp.isEnabled()) return true;
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,6 +260,14 @@ public class XmlStats extends JavaPlugin {
|
|||||||
protected void reload() {
|
protected void reload() {
|
||||||
this.onDisable();
|
this.onDisable();
|
||||||
this.onEnable();
|
this.onEnable();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerEvents(){
|
||||||
|
LogDebug("Trying to register ServerListener");
|
||||||
|
XmlStatsServerListener listener = new XmlStatsServerListener(this);
|
||||||
|
LogDebug("Listener-object created.");
|
||||||
|
|
||||||
|
getServer().getPluginManager().registerEvents(listener, this);
|
||||||
|
LogDebug("Event registered.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
63
src/de/sockenklaus/XmlStats/XmlStatsServerListener.java
Normal file
63
src/de/sockenklaus/XmlStats/XmlStatsServerListener.java
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.sockenklaus.XmlStats;
|
||||||
|
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.server.PluginDisableEvent;
|
||||||
|
import org.bukkit.event.server.PluginEnableEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author socrates
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class XmlStatsServerListener implements Listener {
|
||||||
|
private XmlStats plugin;
|
||||||
|
|
||||||
|
public XmlStatsServerListener(XmlStats plugin){
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPluginDisable(PluginDisableEvent event){
|
||||||
|
/*
|
||||||
|
* TODO
|
||||||
|
* Not implemented yet!
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*Plugin iConomy = (Plugin)XmlStatsRegistry.get("iconomy");
|
||||||
|
Plugin Stats = (Plugin)XmlStatsRegistry.get("stats");
|
||||||
|
Plugin Achievements = (Plugin)XmlStatsRegistry.get("achievements");
|
||||||
|
|
||||||
|
if (!XmlStats.checkAchievements()){
|
||||||
|
|
||||||
|
}
|
||||||
|
if(!XmlStats.checkiConomy()){
|
||||||
|
|
||||||
|
}
|
||||||
|
if(!XmlStats.checkStats()){
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPluginEnable(PluginEnableEvent event){
|
||||||
|
XmlStats.LogDebug("onPluginEnable fired");
|
||||||
|
|
||||||
|
if(this.identifyPlugin(event, "stats 2.0")){
|
||||||
|
XmlStats.LogDebug("Stats 2.0 fired the event");
|
||||||
|
this.plugin.hookStats();
|
||||||
|
}
|
||||||
|
if(this.identifyPlugin(event, "achievements")){
|
||||||
|
this.plugin.hookAchievements();
|
||||||
|
}
|
||||||
|
if(this.identifyPlugin(event, "register")){
|
||||||
|
this.plugin.hookRegister();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean identifyPlugin(PluginEnableEvent event, String name){
|
||||||
|
return event.getPlugin().getDescription().getName().equalsIgnoreCase(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
43
src/de/sockenklaus/XmlStats/XmlWorkers/AchievementsList.java
Normal file
43
src/de/sockenklaus/XmlStats/XmlWorkers/AchievementsList.java
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.sockenklaus.XmlStats.XmlWorkers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
import de.sockenklaus.XmlStats.Objects.NodeAchievements;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author socrates
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class AchievementsList extends XmlWorker {
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getXml(java.util.Map)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected Element getXml(Map<String, List<String>> parameters) {
|
||||||
|
NodeAchievements ach = new NodeAchievements();
|
||||||
|
return ach.getXml(this.doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (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) {
|
||||||
|
return this.getXml(parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (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) {
|
||||||
|
return this.getXml(parameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
61
src/de/sockenklaus/XmlStats/XmlWorkers/UserAchievements.java
Normal file
61
src/de/sockenklaus/XmlStats/XmlWorkers/UserAchievements.java
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.sockenklaus.XmlStats.XmlWorkers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
import de.sockenklaus.XmlStats.Datasource.AchievementsDS;
|
||||||
|
import de.sockenklaus.XmlStats.Exceptions.XmlStatsException;
|
||||||
|
import de.sockenklaus.XmlStats.Objects.NodeUser;
|
||||||
|
import de.sockenklaus.XmlStats.Objects.NodeUserAchievements;
|
||||||
|
import de.sockenklaus.XmlStats.Objects.NodeUsers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author socrates
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class UserAchievements extends XmlWorker {
|
||||||
|
|
||||||
|
AchievementsDS achDS;
|
||||||
|
|
||||||
|
public UserAchievements(){
|
||||||
|
this.achDS = new AchievementsDS();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getXML(java.util.Map)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected Element getXml(Map<String, List<String>> parameters) throws XmlStatsException {
|
||||||
|
throw new XmlStatsException("No data provided with this query!");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (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) throws XmlStatsException {
|
||||||
|
throw new XmlStatsException("sum="+parameters.get("sum")+" does not deliver any data!");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getUserXml(java.util.List, java.util.Map)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected Element getUserXml(List<String> userList, Map<String, List<String>> parameters) throws XmlStatsException{
|
||||||
|
NodeUsers node_users = new NodeUsers();
|
||||||
|
|
||||||
|
for(String userName : userList){
|
||||||
|
NodeUser node_user = new NodeUser(userName);
|
||||||
|
node_user.appendChild(new NodeUserAchievements(userName));
|
||||||
|
node_users.appendChild(node_user);
|
||||||
|
}
|
||||||
|
|
||||||
|
return node_users.getXml(this.doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
86
src/de/sockenklaus/XmlStats/XmlWorkers/UserBalances.java
Normal file
86
src/de/sockenklaus/XmlStats/XmlWorkers/UserBalances.java
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) [2011] [Pascal Koenig]
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it under the terms of
|
||||||
|
* the GNU General Public License as published by the Free Software Foundation; either version
|
||||||
|
* 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program;
|
||||||
|
* if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.sockenklaus.XmlStats.XmlWorkers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
import de.sockenklaus.XmlStats.Datasource.BalancesDS;
|
||||||
|
import de.sockenklaus.XmlStats.Exceptions.XmlStatsException;
|
||||||
|
import de.sockenklaus.XmlStats.Objects.NodeList;
|
||||||
|
import de.sockenklaus.XmlStats.Objects.NodeText;
|
||||||
|
import de.sockenklaus.XmlStats.Objects.NodeUser;
|
||||||
|
import de.sockenklaus.XmlStats.Objects.NodeUsers;
|
||||||
|
|
||||||
|
// TODO: Auto-generated Javadoc
|
||||||
|
/**
|
||||||
|
* The Class XmlWorkerMoney.
|
||||||
|
*/
|
||||||
|
public class UserBalances extends XmlWorker {
|
||||||
|
|
||||||
|
private BalancesDS moneyDS;
|
||||||
|
|
||||||
|
public UserBalances(){
|
||||||
|
this.moneyDS = new BalancesDS();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected Element getUserXml(List<String> playerList, Map<String, List<String>> parameters) throws XmlStatsException {
|
||||||
|
|
||||||
|
NodeUsers node_users = new NodeUsers();
|
||||||
|
|
||||||
|
for(String userName : playerList){
|
||||||
|
NodeUser node_user = new NodeUser(userName);
|
||||||
|
node_user.appendChild(new NodeText("balance", moneyDS.getBalance(userName)));
|
||||||
|
|
||||||
|
node_users.appendChild(node_user);
|
||||||
|
}
|
||||||
|
|
||||||
|
return node_users.getXml(this.doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getXML(java.util.Map)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Element getXml(Map<String, List<String>> parameters) throws XmlStatsException {
|
||||||
|
throw new XmlStatsException("No data provided with this query!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getSumXml(java.util.List, java.util.Map)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected Element getSumXml(List<String> userList, Map<String, List<String>> parameters) throws XmlStatsException {
|
||||||
|
|
||||||
|
NodeList node_sum = new NodeList("sum");
|
||||||
|
NodeUsers node_users = new NodeUsers();
|
||||||
|
|
||||||
|
node_sum.appendChild(node_users);
|
||||||
|
|
||||||
|
for(String userName : userList){
|
||||||
|
NodeUser node_user = new NodeUser(userName);
|
||||||
|
node_users.appendChild(node_user);
|
||||||
|
}
|
||||||
|
|
||||||
|
int sum = moneyDS.getSum(userList);
|
||||||
|
node_sum.appendChild(new NodeText("balance", sum));
|
||||||
|
|
||||||
|
return node_sum.getXml(this.doc);
|
||||||
|
}
|
||||||
|
}
|
||||||
64
src/de/sockenklaus/XmlStats/XmlWorkers/UserList.java
Normal file
64
src/de/sockenklaus/XmlStats/XmlWorkers/UserList.java
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) [2011] [Pascal Koenig]
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it under the terms of
|
||||||
|
* the GNU General Public License as published by the Free Software Foundation; either version
|
||||||
|
* 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program;
|
||||||
|
* if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.sockenklaus.XmlStats.XmlWorkers;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
import de.sockenklaus.XmlStats.Datasource.Datasource;
|
||||||
|
import de.sockenklaus.XmlStats.Exceptions.XmlStatsException;
|
||||||
|
import de.sockenklaus.XmlStats.Objects.NodeUser;
|
||||||
|
import de.sockenklaus.XmlStats.Objects.NodeUsers;
|
||||||
|
|
||||||
|
// TODO: Auto-generated Javadoc
|
||||||
|
/**
|
||||||
|
* The Class XmlWorkerUsers.
|
||||||
|
*/
|
||||||
|
public class UserList extends XmlWorker {
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getXML(java.util.Map)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Element getXml(Map<String, List<String>> parameters) throws XmlStatsException {
|
||||||
|
|
||||||
|
NodeUsers node_users = new NodeUsers();
|
||||||
|
|
||||||
|
for(String playerName : Datasource.fetchAllPlayers()){
|
||||||
|
node_users.appendChild(new NodeUser(playerName));
|
||||||
|
}
|
||||||
|
|
||||||
|
return node_users.getXml(this.doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (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) throws XmlStatsException {
|
||||||
|
return this.getXml(parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (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) throws XmlStatsException {
|
||||||
|
return this.getXml(parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
94
src/de/sockenklaus/XmlStats/XmlWorkers/UserStats.java
Normal file
94
src/de/sockenklaus/XmlStats/XmlWorkers/UserStats.java
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) [2011] [Pascal Koenig]
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it under the terms of
|
||||||
|
* the GNU General Public License as published by the Free Software Foundation; either version
|
||||||
|
* 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program;
|
||||||
|
* if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.sockenklaus.XmlStats.XmlWorkers;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
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
|
||||||
|
/**
|
||||||
|
* The Class XmlWorkerUserstats.
|
||||||
|
*/
|
||||||
|
public class UserStats extends XmlWorker {
|
||||||
|
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getXML(java.util.Map)
|
||||||
|
*/
|
||||||
|
public Element getXml(Map<String, List<String>> parameters) throws XmlStatsException {
|
||||||
|
throw new XmlStatsException("No data provided with this query!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* (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) 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){
|
||||||
|
node_users.appendChild(new NodeUser(userName));
|
||||||
|
}
|
||||||
|
|
||||||
|
HashMap<String, HashMap<String, Integer>> addedStats = UserstatsDS.getAddedStats(playerList);
|
||||||
|
|
||||||
|
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) throws XmlStatsException {
|
||||||
|
NodeUsers node_users = new NodeUsers();
|
||||||
|
|
||||||
|
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 node_users.getXml(this.doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) [2011] [Pascal K<EFBFBD>nig]
|
* Copyright (C) [2011] [Pascal Koenig]
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it under the terms of
|
* This program is free software; you can redistribute it and/or modify it under the terms of
|
||||||
* the GNU General Public License as published by the Free Software Foundation; either version
|
* the GNU General Public License as published by the Free Software Foundation; either version
|
||||||
@@ -16,6 +16,7 @@ package de.sockenklaus.XmlStats.XmlWorkers;
|
|||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.StringWriter;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
@@ -25,19 +26,43 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.zip.GZIPOutputStream;
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.transform.Transformer;
|
||||||
|
import javax.xml.transform.TransformerConfigurationException;
|
||||||
|
import javax.xml.transform.TransformerException;
|
||||||
|
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.sun.net.httpserver.Headers;
|
import com.sun.net.httpserver.Headers;
|
||||||
import com.sun.net.httpserver.HttpContext;
|
import com.sun.net.httpserver.HttpContext;
|
||||||
import com.sun.net.httpserver.HttpHandler;
|
import com.sun.net.httpserver.HttpHandler;
|
||||||
import com.sun.net.httpserver.HttpExchange;
|
import com.sun.net.httpserver.HttpExchange;
|
||||||
|
|
||||||
import de.sockenklaus.XmlStats.XmlStats;
|
import de.sockenklaus.XmlStats.XmlStats;
|
||||||
|
import de.sockenklaus.XmlStats.XmlStatsRegistry;
|
||||||
|
import de.sockenklaus.XmlStats.Datasource.Datasource;
|
||||||
|
import de.sockenklaus.XmlStats.Exceptions.XmlStatsException;
|
||||||
|
|
||||||
// TODO: Auto-generated Javadoc
|
// TODO: Auto-generated Javadoc
|
||||||
/**
|
/**
|
||||||
* The Class XmlWorker.
|
* The Class XmlWorker.
|
||||||
*/
|
*/
|
||||||
public abstract class XmlWorker implements HttpHandler {
|
public abstract class XmlWorker implements HttpHandler {
|
||||||
|
protected DocumentBuilderFactory factory;
|
||||||
|
protected DocumentBuilder builder;
|
||||||
|
protected Document doc;
|
||||||
|
protected DOMSource source;
|
||||||
|
protected StringWriter writer;
|
||||||
|
protected StreamResult result;
|
||||||
|
protected TransformerFactory tf;
|
||||||
|
protected Transformer transformer;
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see com.sun.net.httpserver.HttpHandler#handle(com.sun.net.httpserver.HttpExchange)
|
* @see com.sun.net.httpserver.HttpHandler#handle(com.sun.net.httpserver.HttpExchange)
|
||||||
*/
|
*/
|
||||||
@@ -51,53 +76,158 @@ public abstract class XmlWorker implements HttpHandler {
|
|||||||
String xmlResponse = "";
|
String xmlResponse = "";
|
||||||
byte[] byteResponse = null;
|
byte[] byteResponse = null;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Parse the parameters
|
||||||
|
*/
|
||||||
|
this.factory = DocumentBuilderFactory.newInstance();
|
||||||
|
try {
|
||||||
|
this.builder = this.factory.newDocumentBuilder();
|
||||||
|
} catch (ParserConfigurationException e1) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
this.doc = this.builder.newDocument();
|
||||||
|
try {
|
||||||
|
this.source = new DOMSource(this.doc);
|
||||||
|
this.writer = new StringWriter();
|
||||||
|
this.result = new StreamResult(this.writer);
|
||||||
|
this.tf = TransformerFactory.newInstance();
|
||||||
|
this.transformer = this.tf.newTransformer();
|
||||||
|
} catch (TransformerConfigurationException e1) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Element root = this.doc.createElement("xmlstats");
|
||||||
|
List<String> userList;
|
||||||
|
this.doc.appendChild(root);
|
||||||
|
|
||||||
|
XmlStats xmlstats = (XmlStats)XmlStatsRegistry.get("xmlstats");
|
||||||
|
|
||||||
|
Element server = this.doc.createElement("server");
|
||||||
|
server.appendChild(getTextElem("version", xmlstats.getServer().getVersion()));
|
||||||
|
server.appendChild(getTextElem("name", xmlstats.getServer().getServerName()));
|
||||||
|
server.appendChild(getTextElem("ip", xmlstats.getServer().getIp()));
|
||||||
|
|
||||||
|
root.appendChild(server);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
parameters = parseParameters(queryString);
|
parameters = parseParameters(queryString);
|
||||||
} catch(UnsupportedEncodingException ex){
|
|
||||||
XmlStats.LogWarn("Fehler beim Parsen des HTTP-Query-Strings.");
|
/*
|
||||||
XmlStats.LogWarn(ex.getMessage());
|
* Create the XML doc stuff....
|
||||||
}
|
*/
|
||||||
|
|
||||||
xmlResponse = getXML(parameters);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Check if the clients sends the header "Accept-encoding", the option "gzip-enabled" is true and the clients supports gzip.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(parameters.containsKey("gzip") && parameters.get("gzip").contains("true")){
|
|
||||||
XmlStats.LogDebug("Raw gzip requested.");
|
|
||||||
|
|
||||||
HttpContext context = exchange.getHttpContext();
|
/*
|
||||||
String filename = context.getPath().substring(1);
|
* Actually create the XML
|
||||||
|
*/
|
||||||
|
|
||||||
byteResponse = compressData(xmlResponse.getBytes());
|
if(parameters.containsKey("user")){
|
||||||
exchange.getResponseHeaders().set("Content-type", "application/gzip");
|
if (parameters.get("user").contains("*")){
|
||||||
exchange.getResponseHeaders().set("Content-disposition", "attachment; filename="+filename+".gzip");
|
userList = Datasource.fetchAllPlayers();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
userList = Datasource.fetchValidUsers(parameters.get("user"));
|
||||||
|
}
|
||||||
|
|
||||||
|
root.appendChild(getUserXml(userList, parameters));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(parameters.containsKey("sum")){
|
||||||
|
if(parameters.get("sum").contains("*")){
|
||||||
|
userList = Datasource.fetchAllPlayers();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
userList = Datasource.fetchValidUsers(parameters.get("sum"));
|
||||||
|
}
|
||||||
|
root.appendChild(getSumXml(userList, parameters));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!parameters.containsKey("sum") && !parameters.containsKey("user")){
|
||||||
|
root.appendChild(getXml(parameters));
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Build string from XML
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
else if(clientAcceptsGzip(headers)) {
|
catch(XmlStatsException e){
|
||||||
byteResponse = compressData(xmlResponse.getBytes());
|
root.setAttribute("status", "error");
|
||||||
exchange.getResponseHeaders().set("Content-encoding", "gzip");
|
root.appendChild(getTextElem("error", e.getMessage()));
|
||||||
}
|
|
||||||
else {
|
|
||||||
byteResponse = xmlResponse.getBytes();
|
|
||||||
}
|
}
|
||||||
|
catch (UnsupportedEncodingException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
this.transformer.transform(this.source, this.result);
|
||||||
|
|
||||||
|
xmlResponse = this.writer.toString();
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check if the clients sends the header "Accept-encoding", the option "gzip-enabled" is true and the clients supports gzip.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if(parameters.containsKey("gzip") && parameters.get("gzip").contains("true")){
|
||||||
|
XmlStats.LogDebug("Raw gzip requested.");
|
||||||
|
|
||||||
|
HttpContext context = exchange.getHttpContext();
|
||||||
|
String filename = context.getPath().substring(1);
|
||||||
|
|
||||||
|
byteResponse = compressData(xmlResponse.getBytes());
|
||||||
|
exchange.getResponseHeaders().set("Content-type", "application/gzip");
|
||||||
|
exchange.getResponseHeaders().set("Content-disposition", "attachment; filename="+filename+".gzip");
|
||||||
|
}
|
||||||
|
else if(clientAcceptsGzip(headers)) {
|
||||||
|
byteResponse = compressData(xmlResponse.getBytes());
|
||||||
|
exchange.getResponseHeaders().set("Content-encoding", "gzip");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
byteResponse = xmlResponse.getBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, byteResponse.length);
|
exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, byteResponse.length);
|
||||||
exchange.getResponseBody().write(byteResponse);
|
exchange.getResponseBody().write(byteResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
catch(IOException ex){
|
catch(IOException ex){
|
||||||
XmlStats.LogError("Fehler beim Senden der HTTP-Antwort.");
|
XmlStats.LogError("Fehler beim Senden der HTTP-Antwort.");
|
||||||
XmlStats.LogError(ex.getMessage());
|
XmlStats.LogError(ex.getMessage());
|
||||||
}
|
}
|
||||||
|
catch (TransformerException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
exchange.close();
|
exchange.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param parameters
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected abstract Element getXml(Map<String, List<String>> parameters) throws XmlStatsException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param playerList
|
||||||
|
* @param parameters
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected abstract Element getSumXml(List<String> playerList, Map<String, List<String>> parameters) throws XmlStatsException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param playerList
|
||||||
|
* @param parameters
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected abstract Element getUserXml(List<String> playerList, Map<String, List<String>> parameters) throws XmlStatsException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the parameters.
|
* Parses the parameters.
|
||||||
*
|
*
|
||||||
@@ -115,52 +245,44 @@ public abstract class XmlWorker implements HttpHandler {
|
|||||||
String param[] = pair.split("[=]");
|
String param[] = pair.split("[=]");
|
||||||
|
|
||||||
String key = null;
|
String key = null;
|
||||||
String value = null;
|
String[] valueArr = null;
|
||||||
|
|
||||||
if(param.length > 0){
|
if(param.length > 0){
|
||||||
key = URLDecoder.decode(param[0].toLowerCase(), System.getProperty("file.encoding"));
|
key = URLDecoder.decode(param[0].toLowerCase(), System.getProperty("file.encoding"));
|
||||||
|
valueArr = new String[1];
|
||||||
|
valueArr[0] = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(param.length > 1){
|
if(param.length > 1){
|
||||||
value = URLDecoder.decode(param[1].toLowerCase(), System.getProperty("file.encoding"));
|
valueArr = URLDecoder.decode(param[1], System.getProperty("file.encoding")).split(",");
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> values = new ArrayList<String>();
|
||||||
|
for (String value : valueArr){
|
||||||
|
if (!values.contains(value)){
|
||||||
|
XmlStats.LogDebug("ParseParameters() found: "+key+" = "+value);
|
||||||
|
values.add(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.containsKey(key)){
|
|
||||||
List<String> values = result.get(key);
|
|
||||||
|
|
||||||
values.add(value);
|
result.put(key, values);
|
||||||
}
|
|
||||||
else {
|
|
||||||
List<String> values = new ArrayList<String>();
|
|
||||||
values.add(value);
|
|
||||||
|
|
||||||
result.put(key, values);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the xML.
|
|
||||||
*
|
|
||||||
* @param parameters the parameters
|
|
||||||
* @return the xML
|
|
||||||
*/
|
|
||||||
abstract String getXML(Map<String, List<String>> parameters);
|
|
||||||
|
|
||||||
private byte[] compressData(byte[] input){
|
private byte[] compressData(byte[] input){
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
byte[] output;
|
byte[] output;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
XmlStats.LogDebug("OK... let's try gzip compression...");
|
XmlStats.LogDebug("OK... let's try gzip compression...");
|
||||||
XmlStats.LogDebug("Actual size of the xml file: "+input.length+"Bytes");
|
XmlStats.LogDebug("Actual size of the xml file: "+input.length+" B");
|
||||||
GZIPOutputStream gzip = new GZIPOutputStream(out);
|
GZIPOutputStream gzip = new GZIPOutputStream(out);
|
||||||
gzip.write(input);
|
gzip.write(input);
|
||||||
gzip.close();
|
gzip.close();
|
||||||
output = out.toByteArray();
|
output = out.toByteArray();
|
||||||
XmlStats.LogDebug("Compressed size of the xml file: "+output.length+"Bytes");
|
XmlStats.LogDebug("Compressed size of the xml file: "+output.length+" B");
|
||||||
}
|
}
|
||||||
catch(IOException e){
|
catch(IOException e){
|
||||||
XmlStats.LogError("GZIP-Compression failed! Returning empty byte[]");
|
XmlStats.LogError("GZIP-Compression failed! Returning empty byte[]");
|
||||||
@@ -184,4 +306,23 @@ public abstract class XmlWorker implements HttpHandler {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the text elem.
|
||||||
|
*
|
||||||
|
* @param elemName the elem name
|
||||||
|
* @param text the text
|
||||||
|
* @return the text elem
|
||||||
|
*/
|
||||||
|
protected Element getTextElem(String elemName, String text){
|
||||||
|
Element result = this.doc.createElement(elemName);
|
||||||
|
result.setTextContent(text);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Element getTextElem(String elemName, int value){
|
||||||
|
Element result = this.doc.createElement(elemName);
|
||||||
|
result.setTextContent(String.valueOf(value));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,96 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) [2011] [Pascal K<>nig]
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify it under the terms of
|
|
||||||
* the GNU General Public License as published by the Free Software Foundation; either version
|
|
||||||
* 3 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
||||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
* See the GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with this program;
|
|
||||||
* if not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package de.sockenklaus.XmlStats.XmlWorkers;
|
|
||||||
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
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
|
|
||||||
/**
|
|
||||||
* The Class XmlWorkerMoney.
|
|
||||||
*/
|
|
||||||
public class XmlWorkerMoney extends XmlWorker {
|
|
||||||
|
|
||||||
private MoneyDS moneyDS;
|
|
||||||
|
|
||||||
public XmlWorkerMoney(){
|
|
||||||
this.moneyDS = new MoneyDS();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getXML(java.util.Map)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getXML(Map<String, List<String>> parameters) {
|
|
||||||
try {
|
|
||||||
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 "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,114 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) [2011] [Pascal K<>nig]
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify it under the terms of
|
|
||||||
* the GNU General Public License as published by the Free Software Foundation; either version
|
|
||||||
* 3 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
||||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
* See the GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with this program;
|
|
||||||
* if not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package de.sockenklaus.XmlStats.XmlWorkers;
|
|
||||||
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
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.bukkit.entity.Player;
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
import com.nidefawl.Stats.Stats;
|
|
||||||
|
|
||||||
import de.sockenklaus.XmlStats.XmlStats;
|
|
||||||
import de.sockenklaus.XmlStats.XmlStatsRegistry;
|
|
||||||
import de.sockenklaus.XmlStats.Datasource.UsersDS;
|
|
||||||
|
|
||||||
// TODO: Auto-generated Javadoc
|
|
||||||
/**
|
|
||||||
* The Class XmlWorkerUsers.
|
|
||||||
*/
|
|
||||||
public class XmlWorkerUsers extends XmlWorker {
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getXML(java.util.Map)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getXML(Map<String, List<String>> parameters) {
|
|
||||||
UsersDS users = new UsersDS();
|
|
||||||
|
|
||||||
try {
|
|
||||||
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();
|
|
||||||
|
|
||||||
Element root = doc.createElement("players");
|
|
||||||
root.setAttribute("count", String.valueOf(users.getAllPlayers().size()));
|
|
||||||
doc.appendChild(root);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get list online player names
|
|
||||||
*/
|
|
||||||
XmlStats pluginTemp= (XmlStats)XmlStatsRegistry.get("xmlstats");
|
|
||||||
|
|
||||||
Player[] onlinePlayers = pluginTemp.getServer().getOnlinePlayers();
|
|
||||||
List<String> onlinePlayerNames = new ArrayList<String>();
|
|
||||||
|
|
||||||
if (onlinePlayers != null){
|
|
||||||
for (int i = 0; i < onlinePlayers.length; i++){
|
|
||||||
onlinePlayerNames.add(onlinePlayers[i].getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* Got list of online player names
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Hier wird das XML aufgebaut
|
|
||||||
*/
|
|
||||||
|
|
||||||
for(String playerName : users.getAllPlayers()){
|
|
||||||
|
|
||||||
Element elem_player = doc.createElement("player");
|
|
||||||
elem_player.setAttribute("name", playerName);
|
|
||||||
|
|
||||||
elem_player.setAttribute("status", onlinePlayerNames.contains(playerName) ? "online":"offline");
|
|
||||||
|
|
||||||
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 "";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,177 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) [2011] [Pascal K<>nig]
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify it under the terms of
|
|
||||||
* the GNU General Public License as published by the Free Software Foundation; either version
|
|
||||||
* 3 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
||||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
* See the GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with this program;
|
|
||||||
* if not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package de.sockenklaus.XmlStats.XmlWorkers;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
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 com.nidefawl.Stats.ItemResolver.hModItemResolver;
|
|
||||||
import com.nidefawl.Stats.datasource.Category;
|
|
||||||
import com.nidefawl.Stats.datasource.PlayerStat;
|
|
||||||
|
|
||||||
import de.sockenklaus.XmlStats.Datasource.UserstatsDS;
|
|
||||||
|
|
||||||
// TODO: Auto-generated Javadoc
|
|
||||||
/**
|
|
||||||
* The Class XmlWorkerUserstats.
|
|
||||||
*/
|
|
||||||
public class XmlWorkerUserstats extends XmlWorker {
|
|
||||||
|
|
||||||
/** The stats ds. */
|
|
||||||
private UserstatsDS statsDS;
|
|
||||||
private hModItemResolver itemResolver;
|
|
||||||
private String[] resolveCats;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new xml worker userstats.
|
|
||||||
*/
|
|
||||||
public XmlWorkerUserstats(){
|
|
||||||
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)
|
|
||||||
*/
|
|
||||||
public String getXML(Map<String, List<String>> parameters) {
|
|
||||||
try {
|
|
||||||
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();
|
|
||||||
|
|
||||||
Element root = doc.createElement("stats");
|
|
||||||
doc.appendChild(root);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Hier wird das XML aufgebaut
|
|
||||||
*/
|
|
||||||
if (!parameters.containsKey("player")){
|
|
||||||
// Generate a summarized XML
|
|
||||||
|
|
||||||
root.appendChild(getAddedUpStatsElement(doc));
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Generate the XML for the given user(s)
|
|
||||||
for(String playerName : statsDS.fetchAllPlayers()){
|
|
||||||
if (parameters.containsKey("player") && parameters.get("player").contains(playerName.toLowerCase())){
|
|
||||||
root.appendChild(getPlayerElement(playerName, doc));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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 "";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build a XML subtree for the given player.
|
|
||||||
*
|
|
||||||
* @param playerName the player name
|
|
||||||
* @param doc the doc
|
|
||||||
* @return Returns a XML subtree for the given playerName.
|
|
||||||
*/
|
|
||||||
private Element getPlayerElement(String playerName, Document doc){
|
|
||||||
PlayerStat player_stats = statsDS.getPlayerStat(playerName);
|
|
||||||
|
|
||||||
Element elem_player = doc.createElement("player");
|
|
||||||
elem_player.setAttribute("name", playerName);
|
|
||||||
|
|
||||||
for(String catName : player_stats.getCats()){
|
|
||||||
Category cat = player_stats.get(catName);
|
|
||||||
Element elem_cat = doc.createElement("category");
|
|
||||||
elem_cat.setAttribute("name", catName);
|
|
||||||
|
|
||||||
for(String valName : cat.stats.keySet()){
|
|
||||||
int value = cat.get(valName);
|
|
||||||
Element elem_value = doc.createElement("stat");
|
|
||||||
|
|
||||||
elem_value.setAttribute("name", valName);
|
|
||||||
|
|
||||||
if (Arrays.asList(resolveCats).contains(catName)){
|
|
||||||
elem_value.setAttribute("id", String.valueOf(itemResolver.getItem(valName)));
|
|
||||||
}
|
|
||||||
elem_value.setAttribute("value", String.valueOf(value));
|
|
||||||
|
|
||||||
elem_cat.appendChild(elem_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
elem_player.appendChild(elem_cat);
|
|
||||||
}
|
|
||||||
return elem_player;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Element getAddedUpStatsElement(Document doc){
|
|
||||||
HashMap<String, HashMap<String, Integer>> addedStats = statsDS.getAddedStats();
|
|
||||||
|
|
||||||
Element elem_player = doc.createElement("player");
|
|
||||||
elem_player.setAttribute("name", "*");
|
|
||||||
|
|
||||||
for (String catName : addedStats.keySet()){
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return elem_player;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user