40 Commits
0.2 ... v0.5

Author SHA1 Message Date
Pascal Koenig
a4884bdf32 ?? 2012-07-02 18:13:28 +02:00
Pascal Koenig
8def0834c4 renamed branch 2012-02-03 17:29:53 +01:00
Pascal Koenig
70211f66b0 Merge branch 'stats2.0' into v0.4
Conflicts:
	.build.number
	src/de/sockenklaus/XmlStats/Datasource/StatsDS.java
	src/de/sockenklaus/XmlStats/Datasource/UsersDS.java
	src/de/sockenklaus/XmlStats/Objects/NodeCategories.java
	src/de/sockenklaus/XmlStats/Objects/NodeItems.java
	src/de/sockenklaus/XmlStats/Settings.java
	src/de/sockenklaus/XmlStats/XmlStats.java
	src/de/sockenklaus/XmlStats/XmlStatsServerListener.java
	src/de/sockenklaus/XmlStats/XmlWorkers/UserStats.java

Merged stats2.0 into v0.4
2012-02-03 16:58:31 +01:00
Pascal Koenig
969b763e63 Fixed a bug that prevented loading the Stats 2.0 plugin. 2012-02-03 16:45:25 +01:00
Pascal Koenig
6c245b7503 Implemented new Event system. 2012-02-03 16:10:21 +01:00
Pascal Koenig
65cc053677 Added support for Stats 2.0 and bukkit-1.1-R3. 2012-02-03 15:19:26 +01:00
Pascal Koenig
9b2a10d6b3 Added new Stats and Achievements libs 2012-02-03 00:24:41 +01:00
Pascal Koenig
f424b3a76e Currently working on Auth-module... does not compile! 2012-02-02 22:34:49 +01:00
Pascal Koenig
1ccc5244e8 Did some refactoring on datasources. 2011-10-14 01:27:09 +02:00
Pascal Koenig
00fba43537 Added basic classes for automatic auth-key registration. 2011-10-13 00:19:52 +02:00
Pascal Koenig
ecefa61b53 Finished object based XML structure. 2011-10-08 12:45:47 +02:00
Pascal Koenig
d9414e7d49 Added current Achievements lib. 2011-10-08 11:15:37 +02:00
Pascal Koenig
e1ba7c60e7 Work on objects... Refactoring. 2011-10-06 22:49:33 +02:00
Pascal Koenig
379e9fb591 Improved the hierarchy of inheritance... 2011-10-05 19:42:34 +02:00
Pascal Koenig
a022c05ee6 Work on object based XML generation... 2011-10-05 14:04:38 +02:00
Pascal Koenig
4ac770e4e9 Fixed the commit again... 2011-10-05 13:06:54 +02:00
Pascal Koenig
4270515f8c Fix the defect commit 2011-10-04 19:04:48 +02:00
Pascal Koenig
95443bad58 Added build.number to repo. 2011-10-04 10:44:19 +02:00
Pascal Koenig
ebc3e3d1fc Switched version number to v0.4. Fixed a bug in fetchAllPlayers(). Did
some work on object based XML generation.
2011-10-04 10:35:57 +02:00
Pascal Koenig
40d9bceeb1 Pushed version to 0.4. Did some work on object based XML generation. 2011-10-04 10:32:05 +02:00
Pascal Koenig
a2b31e14fc Started re-implementing the XML build process... 2011-10-04 02:03:22 +02:00
Pascal Koenig
670143767d Added "count" attribute to all arrays. This solved issue #18. 2011-10-03 21:16:47 +02:00
Pascal Koenig
373de1f42b Added some exception handling. 2011-09-30 17:08:02 +02:00
Pascal Koenig
57adc1291c Implemented "Register" support and canceled support for iConomy (see:
Issue #20). Did some Refactoring.
2011-09-28 22:51:34 +02:00
Pascal Koenig
a2f8e4e3cd Updated the readme file. 2011-09-25 15:38:22 +02:00
Pascal Koenig
78a8704ab9 added basic server information to each output and fixed minor bug that
prevented error messages on wrong parameters.
2011-09-25 05:30:05 +02:00
Pascal Koenig
48fea3f1a5 Fixed a bug that prevented fetching Data of players with non-lowercase
names. Also added an exception to show an error message when
non-existing players are requested.
2011-09-24 23:53:21 +02:00
Pascal Koenig
7a40761e00 Re-added the item ids in user_stats and added "name" and "description"
tags to achievements_list.
2011-09-19 00:33:03 +02:00
Pascal Koenig
045919558d Fixed a severe bug that crashed the plugin on start. 2011-09-18 23:41:44 +02:00
Pascal Koenig
fca4b8c8cf Merge branch 'achievements'
Conflicts:
	src/de/sockenklaus/XmlStats/Datasource/AchievementsDS.java
	src/de/sockenklaus/XmlStats/Webserver.java
	src/de/sockenklaus/XmlStats/XmlStats.java
2011-09-15 21:55:57 +02:00
Pascal Koenig
2bfa7556e2 Added the "count" attribute to all users-arrays. 2011-09-15 21:48:13 +02:00
Pascal Koenig
7f0f0f5027 Solved issues #12 and #6. Unified Xml layout and added some basic error
handling. So technically issue #14 is solved.
2011-09-15 21:19:36 +02:00
Pascal Koenig
0fbfc27d3c Increased version number to 0.3 and continued unifying the xml schemes. 2011-09-07 00:15:59 +02:00
Pascal Koenig
aa82666069 Started to completely rewrite the xml structure... 2011-09-06 01:26:34 +02:00
Pascal Koenig
b325e0f2dd Started to unify the xml structure to match the common xml semantics and
tried to simplify the xml worker classes.
2011-09-05 01:35:21 +02:00
Pascal Koenig
de2276bdcd Re-enabled the ServerListener to catch plugins that are starting after
XmlStats. Solved issue #13.
2011-09-03 14:00:26 +02:00
Pascal Koenig
5f8f96dcb6 Basicly implemented Achievements support. 2011-09-03 03:51:33 +02:00
Pascal Koenig
f7b9a834ab Corrected defect push. 2011-09-03 02:18:50 +02:00
Pascal Koenig
4381237315 Added the class stubs for Achievements support. 2011-09-03 01:58:29 +02:00
Pascal Koenig
184ccb3cf3 Corrected the README. 2011-09-02 23:23:17 +02:00
51 changed files with 1978 additions and 842 deletions

3
.build.number Normal file
View File

@@ -0,0 +1,3 @@
#Build Number for ANT. Do not edit!
#Fri Feb 03 17:08:59 CET 2012
build.number=73

View File

@@ -2,12 +2,9 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="lib/Stats.jar"/>
<classpathentry kind="lib" path="lib/bukkit-0.0.1-SNAPSHOT.jar">
<attributes>
<attribute name="javadoc_location" value="http://jd.bukkit.org/apidocs/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/iConomy.jar"/>
<classpathentry kind="lib" path="lib/Achievements.jar"/>
<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"/>
</classpath>

3
.gitignore vendored
View File

@@ -1,3 +1,2 @@
bin/
dist/
.build.number
dist/

View File

@@ -1,12 +1,12 @@
#Sat Aug 27 14:58:29 CEST 2011
#Fri Feb 03 00:30:05 CET 2012
eclipse.preferences.version=1
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.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.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=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

View File

@@ -1,18 +1,18 @@
# XmlStats
# XmlStats v0.3
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).
[![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=socke&url=https://github.com/sockenklaus/XmlStats&title=XmlStats&language=&tags=github&category=software)
## 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:
options.webserver-enabled: true
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.
## Usage
### 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
@@ -22,19 +22,33 @@ Afterwards you can access the following xml files:
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:
http://server:port/userstats.xml
http://server:port/user_stats.xml?sum=*
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:
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:

View File

@@ -5,13 +5,16 @@
<property name="dist" value="dist" />
<property name="src" value="src" />
<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="resources" value="resources" />
<property name="author" value="sockenklaus" />
<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>
<buildnumber file=".build.number" />
@@ -33,6 +36,7 @@
<jar jarfile="${dist}/${name}.jar">
<fileset dir="${bin}"/>
<fileset dir="${src}" includes="**/*.java" />
</jar>
</target>

BIN
lib/Achievements.jar Normal file

Binary file not shown.

BIN
lib/Register.jar Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,93 @@
/**
*
*/
package de.sockenklaus.XmlStats.Datasource;
import java.io.File;
import java.util.HashMap;
import org.bukkit.plugin.Plugin;
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.Util;
import de.sockenklaus.XmlStats.Webserver;
import de.sockenklaus.XmlStats.XmlStats;
/**
* @author socrates
*
*/
public class AchievementsDS extends Datasource {
private Plugin ach; // = (Achievements)XmlStatsRegistry.get("achievements");
private static AchievementsDS instance;
private AchievementsDS(){
super();
}
private void hookAchievements(){
Plugin AchievementsTemp = this.xmlstats.getServer().getPluginManager().getPlugin("Achievements");
Webserver webserver = Webserver.getInstance();
this.ach = AchievementsTemp;
XmlStats.LogInfo("Hooked into Achievements!");
webserver.startAchievements();
}
public static AchievementsDS getInstance(){
if(instance == null){
XmlStats.LogDebug("There's no instance of AchievementsDS");
if(Util.checkAchievements()){
XmlStats.LogDebug("Achievements seems to be there...");
instance = new AchievementsDS();
instance.hookAchievements();
}
else {
XmlStats.LogWarn("Achievements not found! Can't hook into it.");
}
}
return instance;
}
public HashMap<String, AchievementListData> getAchievementsList(){
return this.getAchievements().achievementList;
}
public PlayerAchievement getUserAchievement(String playerName){
PlayerAchievement pa;
if(this.getAchievements().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;
}
public Achievements getAchievements(){
return (Achievements)this.ach;
}
}

View File

@@ -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
* the GNU General Public License as published by the Free Software Foundation; either version
@@ -16,32 +16,71 @@ package de.sockenklaus.XmlStats.Datasource;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.World;
import de.sockenklaus.XmlStats.XmlStats;
import de.sockenklaus.XmlStats.Exceptions.XmlStatsException;
// TODO: Auto-generated Javadoc
/**
* The Class Datasource.
*/
public abstract class Datasource {
public class Datasource {
private static Datasource instance;
protected XmlStats xmlstats;
protected Datasource(){
this.xmlstats = XmlStats.getInstance();
}
public static Datasource getInstance(){
if(instance == null) instance = new Datasource();
return instance;
}
/**
* Fetch all players.
*
* @return the array list
*/
public ArrayList<String> fetchAllPlayers(){
File[] files = new File("world/players").listFiles();
List<World> worlds = this.xmlstats.getServer().getWorlds();
ArrayList<String> result = new ArrayList<String>();
for (int i = 0; i < files.length; i++){
int whereDot = files[i].getName().lastIndexOf('.');
for(World world : worlds){
File[] files = new File(world.getName()+"/players").listFiles();
if (0 < whereDot && whereDot <= files[i].getName().length() - 2){
String playerName = files[i].getName().substring(0, whereDot);
for (File file : files){
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;
}
public boolean userExists(String player){
return this.fetchAllPlayers().contains(player);
}
public List<String> fetchValidUsers(List<String> list) throws XmlStatsException{
ArrayList<String> output = new ArrayList<String>();
for (String possibleUser : list){
if(this.userExists(possibleUser)) output.add(possibleUser);
}
if(output.isEmpty()) throw new XmlStatsException("No valid user has been found!");
else return output;
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,120 @@
/*
* 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.HashMap;
import java.util.List;
import org.bukkit.plugin.Plugin;
import com.nijikokun.register.Register;
import com.nijikokun.register.payment.Method;
import com.nijikokun.register.payment.Method.MethodAccount;
import com.nijikokun.register.payment.Methods;
import de.sockenklaus.XmlStats.Util;
import de.sockenklaus.XmlStats.Webserver;
import de.sockenklaus.XmlStats.XmlStats;
import de.sockenklaus.XmlStats.Exceptions.XmlStatsException;
/**
* The Class MoneyDS.
*/
public class RegisterDS extends Datasource {
private static RegisterDS instance;
private Plugin register;
private RegisterDS(){
super();
}
private void hookRegister(){
Plugin registerTemp = this.xmlstats.getServer().getPluginManager().getPlugin("Register");
Webserver webserver = Webserver.getInstance();
this.register = registerTemp;
XmlStats.LogInfo("Hooked into Register");
webserver.startRegister();
}
public static RegisterDS getInstance(){
if(instance == null){
XmlStats.LogDebug("Theres no instance of RegisterDS");
if(Util.checkRegister()){
XmlStats.LogDebug("Seems like there's a working instancen of Register");
instance = new RegisterDS();
instance.hookRegister();
}
else {
XmlStats.LogWarn("Register or no payment method found. Will not hook into Register.");
}
}
return instance;
}
public HashMap<String, Double> getBalances() throws XmlStatsException {
HashMap<String, Double> result = new HashMap<String, Double>();
for (String playerName : fetchAllPlayers()){
result.put(playerName, getBalance(playerName));
}
return result;
}
public Double getBalance(String playerName) throws XmlStatsException {
Double result = 0.0;
if (Util.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+=getBalance(playerName);
}
return result;
}
public Register getRegister(){
return (Register)this.register;
}
}

View File

@@ -0,0 +1,166 @@
/*
* 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.io.File;
import java.util.HashMap;
import java.util.List;
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.PlayerStat;
import com.nidefawl.Stats.datasource.PlayerStatSQL;*/
import de.sockenklaus.XmlStats.Util;
import de.sockenklaus.XmlStats.Webserver;
import de.sockenklaus.XmlStats.XmlStats;
//import de.sockenklaus.XmlStats.XmlStatsRegistry;
// TODO: Auto-generated Javadoc
/**
* The Class StatsDS.
*/
public class StatsDS extends Datasource {
private static StatsDS instance;
private Plugin stats;
private StatsDS(){
super();
}
public static StatsDS getInstance(){
XmlStats.LogDebug("Let's get an instance of StatsDS");
if(instance == null){
XmlStats.LogDebug("There's no instance of StatsDS.");
if(Util.checkStats()){
XmlStats.LogDebug("Looks like Stats is up and running.");
instance = new StatsDS();
instance.hookStats();
}
else {
XmlStats.LogWarn("Stats not found! Can't hook into it.");
}
}
return instance;
}
/**
* Gets the data folder.
*
* @return the data folder
*/
public File getDataFolder(){
return this.stats.getDataFolder();
}
public static HashMap<String, HashMap<String, Integer>> getAddedStats(List<String> playerList){
HashMap <String, HashMap<String, Integer>> result = new HashMap<String, HashMap<String, Integer>>();
for(String playerName : playerList){
PlayerCache player = getPlayerCache(playerName);
for(PlayerStats ps : player.getStats()){
if(!result.containsKey(ps.getCat())){
/*
* Fall 1:
* 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(ps.getName().equals("lastlogin") || ps.getName().equals("lastlogout")){
result.get(ps.getCat()).put(ps.getName(), Math.max(ps.getValue(), currVal));
}
else {
result.get(ps.getCat()).put(ps.getName(), currVal + ps.getValue());
}
}
}
}
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;
}
private static PlayerCache getPlayerCache(String playerName){
return PlayerControl.getPlayerCache(playerName);
}
private void hookStats(){
Plugin StatsTemp = xmlstats.getServer().getPluginManager().getPlugin("Stats");
Webserver webserver = Webserver.getInstance();
this.stats = StatsTemp;
XmlStats.LogInfo("Hooked into Stats!");
webserver.startStats();
}
public Stats getStats(){
return (Stats)this.stats;
}
}

View File

@@ -1,33 +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;
// TODO: Auto-generated Javadoc
/**
* The Class UsersDS.
*/
public class UsersDS extends Datasource {
/**
* Gets the all players.
*
* @return the all players
*/
public ArrayList<String> getAllPlayers(){
return fetchAllPlayers();
}
}

View File

@@ -1,107 +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.io.File;
import java.util.HashMap;
import com.nidefawl.Stats.Stats;
import com.nidefawl.Stats.datasource.Category;
import com.nidefawl.Stats.datasource.PlayerStat;
import com.nidefawl.Stats.datasource.PlayerStatSQL;
import de.sockenklaus.XmlStats.XmlStatsRegistry;
// TODO: Auto-generated Javadoc
/**
* The Class StatsDS.
*/
public class UserstatsDS extends Datasource {
private Stats statsPlugin;
/**
* Instantiates a new stats ds.
*/
public UserstatsDS() {
this.statsPlugin = (Stats)XmlStatsRegistry.get("stats");
}
/**
* Gets the plugin.
*
* @return the plugin
*/
// public Stats getPlugin() {
// return this.statsPlugin;
//}
/**
* Gets the data folder.
*
* @return the data folder
*/
public File getDataFolder(){
return this.statsPlugin.getDataFolder();
}
public HashMap<String, HashMap<String, Integer>> getAddedStats(){
HashMap <String, HashMap<String, Integer>> result = new HashMap<String, HashMap<String, Integer>>();
for(String playerName : this.fetchAllPlayers()){
PlayerStat player = this.getPlayerStat(playerName);
for(String catName : player.getCats()){
Category cat = player.get(catName);
for(String entryName : cat.getEntries()){
Integer entry = cat.get(entryName);
if(result.containsKey(catName)){
if(result.get(catName).containsKey(entryName)){
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 {
HashMap<String, Integer> tempMap = new HashMap<String, Integer>();
tempMap.put(entryName, entry);
result.put(catName, tempMap);
}
}
}
}
return result;
}
public PlayerStat getPlayerStat(String playerName){
PlayerStat result = new PlayerStatSQL(playerName, this.statsPlugin);
result.load();
return result;
}
}

View File

@@ -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);
}
}

View 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;
}
}

View 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()));
}
}

View File

@@ -0,0 +1,27 @@
/**
*
*/
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");
HashMap<String, AchievementListData> achList = AchievementsDS.getInstance().getAchievementsList();
for(String achName : achList.keySet()){
this.childNodes.add(new NodeAchievement(achList.get(achName)));
}
}
}

View 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);
}
}

View File

@@ -0,0 +1,32 @@
/**
*
*/
package de.sockenklaus.XmlStats.Objects;
import java.util.HashMap;
import de.sockenklaus.XmlStats.Datasource.StatsDS;
/**
* @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);
}
}
}

View 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));
}
}

View 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));
}
}

View File

@@ -0,0 +1,24 @@
/**
*
*/
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)));
}
}
}

View 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;
}
}

View 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;
}
}

View File

@@ -0,0 +1,34 @@
/**
*
*/
package de.sockenklaus.XmlStats.Objects;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import de.sockenklaus.XmlStats.XmlStats;
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.getInstance().userExists(name)){
Server server = XmlStats.getInstance().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!");
}
}
}

View 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()));
}
}

View File

@@ -0,0 +1,29 @@
/**
*
*/
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");
if (Datasource.getInstance().userExists(userName)){
PlayerAchievement pa = AchievementsDS.getInstance().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.");
}
}

View File

@@ -0,0 +1,20 @@
/**
*
*/
package de.sockenklaus.XmlStats.Objects;
/**
* @author socrates
*
*/
public class NodeUsers extends NodeArray {
/**
* @param tagName
*/
public NodeUsers() {
super("users");
}
}

View File

@@ -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
* the GNU General Public License as published by the Free Software Foundation; either version
@@ -15,8 +15,9 @@
package de.sockenklaus.XmlStats;
import java.io.File;
import java.io.IOException;
import org.bukkit.util.config.Configuration;
import org.bukkit.configuration.file.YamlConfiguration;
// TODO: Auto-generated Javadoc
/**
@@ -25,28 +26,37 @@ import org.bukkit.util.config.Configuration;
public class Settings {
private static final String configFilename = "config.yml";
private Configuration conf;
private YamlConfiguration conf;
/**
* Instantiates a new settings.
*
* @param xmlStats the xml stats
*/
public Settings(XmlStats xmlStats){
File f = new File(xmlStats.getDataFolder(), configFilename);
conf = new Configuration(f);
private Settings(){
File f = new File(XmlStats.getInstance().getDataFolder(), configFilename);
if(f.exists()){
conf.load();
conf = YamlConfiguration.loadConfiguration(f);
}
else {
conf.setProperty("options.webserver-enabled", true);
conf.setProperty("options.webserver-port", 9123);
conf.setProperty("options.verbose-enabled", true);
conf.save();
conf.set("options.webserver-enabled", true);
conf.set("options.webserver-port", 9123);
conf.set("options.verbose-enabled", true);
try {
conf.save(f);
}catch(IOException e){
XmlStats.LogError("Something went wrong with the conf-file: "+e.getMessage());
}
}
}
public static synchronized Settings getInstance(){
if(instance == null) instance = new Settings();
return instance;
}
/**
* Gets the int.
*
@@ -54,7 +64,7 @@ public class Settings {
* @return the int
*/
public int getInt(String path){
return conf.getInt(path, -1);
return this.conf.getInt(path, -1);
}
/**
@@ -64,7 +74,7 @@ public class Settings {
* @return the boolean
*/
public boolean getBoolean(String path){
return conf.getBoolean(path, false);
return this.conf.getBoolean(path, false);
}
/**
@@ -74,7 +84,7 @@ public class Settings {
* @return the string
*/
public String getString(String path){
return conf.getString(path, "");
return this.conf.getString(path, "");
}
/**
@@ -84,7 +94,7 @@ public class Settings {
* @param value the value
*/
public void setProperty(String path, Object value){
conf.setProperty(path, value);
conf.set(path, value);
}
/**

View File

@@ -0,0 +1,45 @@
/**
*
*/
package de.sockenklaus.XmlStats;
import org.bukkit.plugin.Plugin;
import com.nijikokun.register.payment.Methods;
/**
* @author socrates
*
*/
public class Util {
/**
* Checks if is Achievements hooked.
*
* @return true, if is Achievements hooked
*/
public static boolean checkAchievements(){
Plugin AchievementsTemp = XmlStats.getInstance().getServer().getPluginManager().getPlugin("Achievements");
if(AchievementsTemp != null && AchievementsTemp.getClass().getName().equals("com.nidefawl.Achievements.Achievements") && AchievementsTemp.isEnabled()) return true;
return false;
}
public static boolean checkRegister(){
Plugin registerTemp = XmlStats.getInstance().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 stats hooked.
*
* @return true, if is stats hooked
*/
public static boolean checkStats(){
Plugin StatsTemp = XmlStats.getInstance().getServer().getPluginManager().getPlugin("Stats");
if(StatsTemp != null && StatsTemp.getClass().getName().equals("com.nidefawl.Stats.Stats") && StatsTemp.isEnabled()) return true;
return false;
}
}

View File

@@ -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
* the GNU General Public License as published by the Free Software Foundation; either version
@@ -29,6 +29,8 @@ public class Webserver {
private InetSocketAddress address;
private HttpServer server = null;
private static Webserver instance;
private Settings settings;
/**
* Instantiates a new web server.
@@ -36,10 +38,23 @@ public class Webserver {
* @param port the port
* @throws IOException Signals that an I/O exception has occurred.
*/
public Webserver() throws IOException {
Settings settingsTemp = (Settings)XmlStatsRegistry.get("settings");
this.start(settingsTemp.getInt("options.webserver-port"));
private Webserver() throws IOException {
this.settings = Settings.getInstance();
this.start(this.settings.getInt("options.webserver-port"));
}
public static synchronized Webserver getInstance() {
if(instance == null) {
try {
instance = new Webserver();
}
catch (IOException ex){
XmlStats.LogError("An error occured while creating the webserver!");
XmlStats.LogError(ex.getMessage());
ex.printStackTrace();
}
}
return instance;
}
/**
@@ -61,10 +76,8 @@ public class Webserver {
public void reload() throws IOException {
this.stop();
Settings settingsTemp = (Settings)XmlStatsRegistry.get("settings");
this.start(settingsTemp.getInt("options.webserver-port"));
this.start(this.settings.getInt("options.webserver-port"));
}
private void start(int port) throws IOException {
@@ -72,24 +85,53 @@ public class Webserver {
this.server = null;
this.address = new InetSocketAddress(port);
XmlStats.LogDebug("Opened socket on port "+port);
this.server = HttpServer.create(this.address, 0);
XmlStats.LogDebug("Created webserver.");
this.server.createContext("/user_list.xml", new UserList());
XmlStats.LogDebug("Created context /user_list.xml.");
this.server.createContext("/users.xml", new XmlWorkerUsers());
this.server.createContext("/auth_register.xml", new AuthRegister());
XmlStats.LogDebug("Created context /auth_register.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.createContext("/auth_deregister.xml", new AuthDeregister());
XmlStats.LogDebug("Created context /auth_deregister.xml.");
this.server.start();
XmlStats.LogDebug("Started webserver.");
}
public void startRegister(){
XmlStats.LogDebug("Casting startRegister()");
if (this.isRunning() && Util.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");
}
}
public void startAchievements(){
if(this.isRunning() && Util.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");
}
}
public void startStats(){
if(this.isRunning() && Util.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");
}
}
}

View File

@@ -0,0 +1,87 @@
/**
*
*/
package de.sockenklaus.XmlStats;
import java.io.File;
import java.util.ArrayList;
import org.bukkit.util.config.Configuration;
import de.sockenklaus.XmlStats.Exceptions.XmlStatsException;
/**
* @author socrates
*
*/
public class XSAuth {
private static XSAuth instance;
private File authKeyFile;
private Configuration authKeyConf;
private String currentKey;
private String pendingKey;
private XSAuth(){
this.authKeyFile = new File(XmlStats.getInstance().getDataFolder(), "auth_keys.yml");
this.currentKey = "";
this.authKeyConf = new Configuration(this.authKeyFile);
if(this.authKeyFile.exists()){
this.authKeyConf.load();
}
else {
this.authKeyConf.setProperty("keys", new ArrayList<String>());
this.authKeyConf.save();
}
}
public static XSAuth getInstance(){
if(instance == null) instance = new XSAuth();
return instance;
}
public boolean whitelistHasKey(String key){
if(this.authKeyConf.getList("keys") != null && this.authKeyConf.getList("keys").contains(key)) return true;
else return false;
}
public void authAddKey(String key){
}
public void setCurrentKey(String currentKey){
this.currentKey = currentKey;
}
public String getCurrentKey(){
return this.currentKey;
}
/**
* @throws XmlStatsException
*
*/
public void addCurrentToWhitelist() throws XmlStatsException {
if(whitelistHasKey(this.currentKey)){
throw new XmlStatsException("Current key "+this.currentKey+" is already known to the whitelist.");
}
else if(this.currentKey.equals(this.pendingKey)){
throw new XmlStatsException("Current key "+this.currentKey+" is already awaiting clearance.");
}
else {
}
}
/**
*
*/
public void remCurrentFromWhitelist() {
// TODO Auto-generated method stub
}
}

View File

@@ -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
* the GNU General Public License as published by the Free Software Foundation; either version
@@ -19,11 +19,14 @@ import java.util.logging.Logger;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import com.iConomy.iConomy;
import com.nidefawl.Stats.Stats;
import com.nidefawl.Achievements.Achievements;
import terranetworkorg.Stats.Stats;
import com.nijikokun.register.Register;
import com.nijikokun.register.payment.Methods;
// TODO: Auto-generated Javadoc
/**
@@ -35,27 +38,34 @@ public class XmlStats extends JavaPlugin {
private String version;
private final static String logprefix = "[XmlStats]";
private boolean enabled = false;
private static XmlStats instance;
public static XmlStats getInstance(){
if(instance == null){
instance = new XmlStats();
}
return instance;
}
/* (non-Javadoc)
* @see org.bukkit.plugin.Plugin#onDisable()
*/
@Override
public void onDisable() {
Webserver webserverTemp = (Webserver)XmlStatsRegistry.get("webserver");
Webserver webserverTemp = Webserver.getInstance();
if(this.enabled && webserverTemp.isRunning()){
this.enabled = false;
XmlStatsRegistry.flush();
webserverTemp.stop();
LogDebug("Webserver stopped.");
getServer().getScheduler().cancelTasks(this);
}
LogInfo("Plugin Disabled");
LogInfo("XmlStats Disabled");
}
/* (non-Javadoc)
* @see org.bukkit.plugin.Plugin#onEnable()
*/
@@ -65,30 +75,22 @@ public class XmlStats extends JavaPlugin {
getDataFolder().mkdirs();
XmlStatsRegistry.put("settings", new Settings(this));
XmlStatsRegistry.put("xmlstats", this);
instance = this;
Settings settingsTemp = (Settings)XmlStatsRegistry.get("settings");
Settings settingsTemp = Settings.getInstance();
LogDebug("Settings read:");
LogDebug("options.webserver-enabled: "+settingsTemp.getBoolean("options.webserver-enabled"));
LogDebug("options.webserver-port: "+settingsTemp.getInt("options.webserver-port"));
LogDebug("options.verbose-enabled: "+settingsTemp.getBoolean("options.verbose-enabled"));
this.hookPlugins();
if (settingsTemp.getBoolean("options.webserver-enabled")){
try {
XmlStatsRegistry.put("webserver", new Webserver());
Webserver.getInstance();
this.enabled = true;
LogInfo("XmStats "+this.version+" enabled");
}
catch (Exception ex){
LogError("Fehler beim Erstellen des Webservers:");
LogError(ex.getMessage());
ex.printStackTrace();
}
this.enabled = true;
LogInfo("XmStats "+this.version+" enabled");
this.hookPlugins();
this.registerEvents();
}
else {
LogWarn("Webserver ist derzeit in der "+settingsTemp.getSettingsFilename()+" deaktiviert.");
@@ -130,7 +132,7 @@ public class XmlStats extends JavaPlugin {
* @param Message the message
*/
public static void LogDebug(String Message){
Settings settingsTemp = (Settings)XmlStatsRegistry.get("settings");
Settings settingsTemp = Settings.getInstance();
if(settingsTemp.getBoolean("options.verbose-enabled")){
log.log(Level.INFO, logprefix+"[DEBUG] "+Message);
}
@@ -140,57 +142,59 @@ public class XmlStats extends JavaPlugin {
* Hook plugins.
*/
protected void hookPlugins(){
Plugin StatsTemp = getServer().getPluginManager().getPlugin("Stats");
Plugin iConomyTemp = getServer().getPluginManager().getPlugin("iConomy");
if(StatsTemp != null){
if(StatsTemp.isEnabled() && StatsTemp.getClass().getName().equals("com.nidefawl.Stats.Stats")){
XmlStatsRegistry.put("stats", (Stats)StatsTemp);
LogInfo("Hooked into Stats!");
}
if(Util.checkStats()) StatsDS.getInstance();
if(Util.checkAchievements()) AchievementsDS.getInstance();
if(Util.checkRegister()) RegisterDS.getInstance();
}
protected void hookAchievements(){
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 {
LogError("Stats not found! Can't hook into it.");
LogWarn("Achievements not found! Can't hook into it.");
}
if (iConomyTemp != null) {
if (iConomyTemp.isEnabled() && iConomyTemp.getClass().getName().equals("com.iConomy.iConomy")) {
XmlStatsRegistry.put("iconomy", (iConomy)iConomyTemp);
LogInfo("Hooked into iConomy");
}
}
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 {
LogError("iConomy not found! Can't hook into it.");
LogWarn("Stats not found! Can't hook into it.");
}
}
}
/**
* Checks if is stats hooked.
*
* @return true, if is stats hooked
*/
public static boolean isStatsHooked(){
Stats StatsTemp = (Stats)XmlStatsRegistry.get("stats");
public boolean checkStats(){
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.getClass().getName().equals("com.nidefawl.Stats.Stats") && StatsTemp.isEnabled()) return true;
if(StatsTemp != null && StatsTemp.getClass().getName().equals("terranetworkorg.Stats.Stats") && StatsTemp.isEnabled()){
LogDebug("terranetworkorg.Stats.Stats is enabled.");
return true;
}
LogDebug("terranetworkorg.Stats.Stats is not enabled.");
return false;
}
}
/**
* Checks if is i conomy hooked.
*
* @return true, if is i conomy hooked
*/
public static boolean isiConomyHooked(){
iConomy iConomyTemp = (iConomy)XmlStatsRegistry.get("iconomy");
if (iConomyTemp != null){
if (iConomyTemp.getClass().getName().equals("com.iConomy.iConomy") && iConomyTemp.isEnabled()) return true;
}
return false;
}
/* (non-Javadoc)
* @see org.bukkit.plugin.java.JavaPlugin#onCommand(org.bukkit.command.CommandSender, org.bukkit.command.Command, java.lang.String, java.lang.String[])
*/
@@ -219,6 +223,14 @@ public class XmlStats extends JavaPlugin {
protected void reload() {
this.onDisable();
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.");
}
}

View File

@@ -1,57 +0,0 @@
/**
*
*/
package de.sockenklaus.XmlStats;
import java.util.HashMap;
// TODO: Auto-generated Javadoc
/**
* The Class XmlStatsRegistry.
*
* @author socrates
*/
public class XmlStatsRegistry {
private HashMap<String, Object> register = null;
private static XmlStatsRegistry instance = null;
/**
* Instantiates a new xml stats registry.
*/
private XmlStatsRegistry(){
register = new HashMap<String, Object>();
}
/**
* Put.
*
* @param key the key
* @param value the value
*/
public static void put(String key, Object value){
if(instance == null){
instance = new XmlStatsRegistry();
}
instance.register.put(key, value);
}
/**
* Get.
*
* @param key the key
* @return the object
*/
static public Object get(String key){
if(instance == null){
instance = new XmlStatsRegistry();
}
return instance.register.get(key);
}
/**
* Flush.
*/
public static void flush(){
instance = null;
}
}

View File

@@ -0,0 +1,69 @@
/**
*
*/
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;
import de.sockenklaus.XmlStats.Datasource.AchievementsDS;
import de.sockenklaus.XmlStats.Datasource.RegisterDS;
import de.sockenklaus.XmlStats.Datasource.StatsDS;
/**
* @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") && Util.checkAchievements()){
AchievementsDS.getInstance();
}
if(this.identifyPlugin(event, "register") && Util.checkRegister()){
RegisterDS.getInstance();
}
}
private boolean identifyPlugin(PluginEnableEvent event, String name){
XmlStats.LogDebug(event.getPlugin().getDescription().getName()+" fired an event!");
return event.getPlugin().getDescription().getName().equalsIgnoreCase(name);
}
}

View 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);
}
}

View File

@@ -0,0 +1,49 @@
/**
*
*/
package de.sockenklaus.XmlStats.XmlWorkers;
import java.util.List;
import java.util.Map;
import org.w3c.dom.Element;
import de.sockenklaus.XmlStats.Exceptions.XmlStatsException;
/**
* @author socrates
*
*/
public class AuthDeregister extends XmlWorker {
/* (non-Javadoc)
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getXml(java.util.Map)
*/
@Override
protected Element getXml(Map<String, List<String>> parameters)
throws XmlStatsException {
// TODO Auto-generated method stub
return null;
}
/* (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 {
// TODO Auto-generated method stub
return null;
}
/* (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 {
// TODO Auto-generated method stub
return null;
}
}

View File

@@ -0,0 +1,114 @@
/**
*
*/
package de.sockenklaus.XmlStats.XmlWorkers;
import java.io.File;
import java.util.List;
import java.util.Map;
import org.bukkit.util.config.Configuration;
import org.w3c.dom.Element;
import de.sockenklaus.XmlStats.XSAuth;
import de.sockenklaus.XmlStats.XmlStats;
import de.sockenklaus.XmlStats.Exceptions.XmlStatsException;
/**
* @author socrates
*
*/
public class AuthRegister extends XmlWorker {
private String authKeyFilename;
private String tempAuthKeyFilname;
public AuthRegister(){
super();
this.authKeyFilename = "auth_keys.yaml";
this.tempAuthKeyFilname = "auth_keys_tmp.yml";
}
/* (non-Javadoc)
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getXml(java.util.Map)
*/
@Override
protected Element getXml(Map<String, List<String>> parameters) throws XmlStatsException {
XSAuth authmodule = XSAuth.getInstance();
if(authmodule.getCurrentKey().isEmpty()){
XmlStats.LogWarn("auth_register: There should be a key, but acutally there is no...");
throw new XmlStatsException("auth_register: There should be a key, but actually there is no...");
}
else if (parameters.containsKey("delete") && parameters.get("delete").get(0).equals("true")){
authmodule.remCurrentFromWhitelist();
}
else {
authmodule.addCurrentToWhitelist();
}
/*if(parameters.containsKey("key")){
for (String key : parameters.get("key")){
XmlStats x_temp = XmlStats.getInstance();
File authKeyFile = new File(x_temp.getDataFolder(), this.authKeyFilename);
Configuration authKeyConf = new Configuration(authKeyFile);
if(authKeyFile.exists()){
authKeyConf.load();
/*
* Hier kann geschaut werden, ob der Key in der AuthKey steht
*
*
return null;
}
else {
/*
* Datei existiert nicht, Key kann nicht existieren
*
File tempAuthKeyFile = new File(x_temp.getDataFolder(), this.tempAuthKeyFilname);
Configuration tempAuthKeyConf = new Configuration(tempAuthKeyFile);
if(tempAuthKeyFile.exists()){
tempAuthKeyConf.load();
if(tempAuthKeyConf.getList("keys") != null && tempAuthKeyConf.getList("keys").contains(key)){
/*
* Key existiert schon in auth_keys_tmp... mach was
*
return null;
}
else tempAuthKeyConf.setProperty("keys.key",key);
}
else {
tempAuthKeyConf.setProperty("keys.key", key);
/*
* Key wurde in auth_keys_tmp eingetragen... jetzt reagieren.
*
return null;
}
tempAuthKeyConf.save();
}
}
}
else throw new XmlStatsException("No key given!");*/
}
/* (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);
}
}

View File

@@ -0,0 +1,54 @@
/**
*
*/
package de.sockenklaus.XmlStats.XmlWorkers;
import java.util.List;
import java.util.Map;
import org.w3c.dom.Element;
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 {
/* (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);
}
}

View 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.RegisterDS;
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 RegisterDS regDS;
public UserBalances(){
this.regDS = RegisterDS.getInstance();
}
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", this.regDS.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 = this.regDS.getSum(userList);
node_sum.appendChild(new NodeText("balance", sum));
return node_sum.getXml(this.doc);
}
}

View 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.getInstance().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);
}
}

View File

@@ -0,0 +1,104 @@
/*
* 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;
<<<<<<< HEAD
import com.nidefawl.Stats.datasource.Category;
import de.sockenklaus.XmlStats.Datasource.StatsDS;
=======
import de.sockenklaus.XmlStats.Datasource.UserstatsDS;
>>>>>>> stats2.0
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));
}
<<<<<<< HEAD
HashMap<String, Category> addedStats = StatsDS.getInstance().getAddedStats(playerList);
=======
HashMap<String, HashMap<String, Integer>> addedStats = UserstatsDS.getAddedStats(playerList);
>>>>>>> stats2.0
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);
}
}

View File

@@ -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
* 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.IOException;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URLDecoder;
@@ -25,25 +26,49 @@ import java.util.List;
import java.util.Map;
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.HttpContext;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpExchange;
import de.sockenklaus.XmlStats.XSAuth;
import de.sockenklaus.XmlStats.XmlStats;
import de.sockenklaus.XmlStats.Datasource.Datasource;
import de.sockenklaus.XmlStats.Exceptions.XmlStatsException;
// TODO: Auto-generated Javadoc
/**
* The Class XmlWorker.
*/
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)
* @see com.sun.net.httpserver.HttpHandler#handle(com.sun.net.httpserver.HttpExchange)
*/
public void handle(HttpExchange exchange) {
Map<String, List<String>> parameters = new HashMap<String, List<String>>();
Datasource datasource = Datasource.getInstance();
Headers headers = exchange.getRequestHeaders();
if("get".equalsIgnoreCase(exchange.getRequestMethod())){
@@ -51,53 +76,164 @@ public abstract class XmlWorker implements HttpHandler {
String xmlResponse = "";
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.getInstance();
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 {
parameters = parseParameters(queryString);
} catch(UnsupportedEncodingException ex){
XmlStats.LogWarn("Fehler beim Parsen des HTTP-Query-Strings.");
XmlStats.LogWarn(ex.getMessage());
}
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.");
/*
* Check whether there is an auth key or not and set the currentKey
*/
XSAuth authmodule = XSAuth.getInstance();
if (parameters.containsKey("authkey") && !parameters.get("authkey").isEmpty()){
authmodule.setCurrentKey(parameters.get("authkey").get(0));
}
else authmodule.setCurrentKey("");
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");
/*
* Actually create the XML
*/
if(parameters.containsKey("user")){
if (parameters.get("user").contains("*")){
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)) {
byteResponse = compressData(xmlResponse.getBytes());
exchange.getResponseHeaders().set("Content-encoding", "gzip");
}
else {
byteResponse = xmlResponse.getBytes();
catch(XmlStatsException e){
root.setAttribute("status", "error");
root.appendChild(getTextElem("error", e.getMessage()));
}
catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
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.getResponseBody().write(byteResponse);
exchange.getResponseBody().write(byteResponse);
}
catch(IOException ex){
XmlStats.LogError("Fehler beim Senden der HTTP-Antwort.");
XmlStats.LogError(ex.getMessage());
}
catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
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.
*
@@ -115,52 +251,44 @@ public abstract class XmlWorker implements HttpHandler {
String param[] = pair.split("[=]");
String key = null;
String value = null;
String[] valueArr = null;
if(param.length > 0){
key = URLDecoder.decode(param[0].toLowerCase(), System.getProperty("file.encoding"));
valueArr = new String[1];
valueArr[0] = "";
}
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);
}
else {
List<String> values = new ArrayList<String>();
values.add(value);
result.put(key, values);
}
result.put(key, values);
}
}
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){
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] output;
try {
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);
gzip.write(input);
gzip.close();
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){
XmlStats.LogError("GZIP-Compression failed! Returning empty byte[]");
@@ -184,4 +312,23 @@ public abstract class XmlWorker implements HttpHandler {
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;
}
}

View File

@@ -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 "";
}
}

View File

@@ -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 "";
}
}

View File

@@ -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;
}
}