Added support for Stats 2.0 and bukkit-1.1-R3.

This commit is contained in:
Pascal Koenig
2012-02-03 15:19:26 +01:00
parent 9b2a10d6b3
commit 65cc053677
21 changed files with 122 additions and 101 deletions

View File

@@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Thu Oct 06 22:29:49 CEST 2011 #Fri Feb 03 15:11:44 CET 2012
build.number=43 build.number=69

View File

@@ -2,13 +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">
<attributes>
<attribute name="javadoc_location" value="http://jd.bukkit.org/apidocs/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/Achievements.jar"/> <classpathentry kind="lib" path="lib/Achievements.jar"/>
<classpathentry kind="lib" path="lib/Register-1.5.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>

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 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

View File

@@ -2,6 +2,8 @@
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).
[![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 ## 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 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.

View File

@@ -13,9 +13,8 @@
<path id="classpath"> <path id="classpath">
<pathelement location="lib/Achievements.jar" /> <pathelement location="lib/Achievements.jar" />
<pathelement location="lib/Stats.jar" /> <pathelement location="lib/Stats.jar" />
<pathelement location="lib/iConomy.jar" /> <pathelement location="lib/bukkit-1.1-R3.jar" />
<pathelement location="lib/bukkit-0.0.1-SNAPSHOT.jar" /> <pathelement location="lib/Register.jar" />
<pathelement location="lib/Register-1.5.jar" />
</path> </path>
<buildnumber file=".build.number" /> <buildnumber file=".build.number" />

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 * 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

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 * 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

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 * 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

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 * 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
@@ -18,10 +18,15 @@ import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; 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;
@@ -43,32 +48,39 @@ public class UserstatsDS extends Datasource {
return statsPlugin.getDataFolder(); return statsPlugin.getDataFolder();
} }
public static HashMap<String, Category> getAddedStats(List<String> playerList){ public static HashMap<String, HashMap<String, Integer>> getAddedStats(List<String> playerList){
HashMap <String, Category> result = new HashMap<String, Category>(); HashMap <String, HashMap<String, Integer>> result = new HashMap<String, HashMap<String, Integer>>();
for(String playerName : playerList){ for(String playerName : playerList){
PlayerStat player = 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
*/
if(result.containsKey(catName)){ HashMap<String, Integer> tmpMap = new HashMap<String, Integer>();
tmpMap.put(ps.getName(), ps.getValue());
if(entryName.equals("lastlogin") || entryName.equals("lastlogout")){ result.put(ps.getCat(), tmpMap);
result.get(catName).put(entryName, Math.max(result.get(catName).get(entryName), entry)); }
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 { else {
result.get(catName).add(entryName, entry); /*
} * 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 { else {
Category tempCat = new Category(); result.get(ps.getCat()).put(ps.getName(), currVal + ps.getValue());
tempCat.add(entryName, entry);
result.put(catName, tempCat);
} }
} }
} }
@@ -77,12 +89,40 @@ public class UserstatsDS extends Datasource {
return result; return result;
} }
public static PlayerStat getPlayerStat(String playerName){ public static HashMap<String, HashMap<String, Integer>> getStats(String playerName){
statsPlugin = (Stats)XmlStatsRegistry.get("stats"); HashMap<String, HashMap<String, Integer>> result = new HashMap<String, HashMap<String, Integer>>();
PlayerStat result = new PlayerStatSQL(playerName, statsPlugin);
result.load(); 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;
}
private static PlayerCache getPlayerCache(String playerName){
return PlayerControl.getPlayerCache(playerName);
} }
} }

View File

@@ -3,7 +3,7 @@
*/ */
package de.sockenklaus.XmlStats.Objects; package de.sockenklaus.XmlStats.Objects;
import com.nidefawl.Stats.datasource.PlayerStat; import java.util.HashMap;
import de.sockenklaus.XmlStats.Datasource.UserstatsDS; import de.sockenklaus.XmlStats.Datasource.UserstatsDS;
@@ -21,9 +21,9 @@ public class NodeCategories extends NodeArray {
*/ */
public NodeCategories(String userName) { public NodeCategories(String userName) {
this(); this();
PlayerStat userStat = UserstatsDS.getPlayerStat(userName); HashMap<String, HashMap<String, Integer>> userStat = UserstatsDS.getStats(userName);
for(String catName : userStat.getCats()){ for(String catName : userStat.keySet()){
NodeCategory node_cat = new NodeCategory(catName, userStat.get(catName)); NodeCategory node_cat = new NodeCategory(catName, userStat.get(catName));
this.appendChild(node_cat); this.appendChild(node_cat);
} }

View File

@@ -3,9 +3,7 @@
*/ */
package de.sockenklaus.XmlStats.Objects; package de.sockenklaus.XmlStats.Objects;
import java.util.Arrays; import java.util.HashMap;
import com.nidefawl.Stats.datasource.Category;
/** /**
* @author socrates * @author socrates
@@ -16,14 +14,11 @@ public class NodeCategory extends NodeList {
/** /**
* @param category * @param category
*/ */
public NodeCategory(String catName, Category category) { public NodeCategory(String catName, HashMap<String, Integer> category) {
super("category"); super("category");
String[] resolveCats = new String[]{"blockdestroy", "blockcreate", "itemdrop", "itempickup"};
Boolean resolve = Arrays.asList(resolveCats).contains(catName);
this.appendChild(new NodeText("name", catName)); this.appendChild(new NodeText("name", catName));
this.appendChild(new NodeItems(category, resolve)); this.appendChild(new NodeItems(category));
} }
} }

View File

@@ -3,12 +3,8 @@
*/ */
package de.sockenklaus.XmlStats.Objects; package de.sockenklaus.XmlStats.Objects;
import java.io.File; import java.util.HashMap;
import com.nidefawl.Stats.ItemResolver.hModItemResolver;
import com.nidefawl.Stats.datasource.Category;
import de.sockenklaus.XmlStats.Datasource.UserstatsDS;
/** /**
* @author socrates * @author socrates
@@ -19,18 +15,10 @@ public class NodeItems extends NodeArray {
/** /**
* @param category * @param category
*/ */
public NodeItems(Category category, Boolean resolve) { public NodeItems(HashMap<String, Integer> category) {
super("items"); super("items");
hModItemResolver itemResolver = new hModItemResolver(new File(UserstatsDS.getDataFolder(),"items.txt")); for(String varName : category.keySet()){
for(String varName : category.getEntries()){
NodeItem node_item = new NodeItem(varName, category.get(varName));
if(resolve){
node_item.setAttribute("id", itemResolver.getItem(varName));
}
this.appendChild(new NodeItem(varName, category.get(varName))); this.appendChild(new NodeItem(varName, category.get(varName)));
} }
} }

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 * 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);
} }
/** /**

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 * 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

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 * 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
@@ -19,13 +19,13 @@ import java.util.logging.Logger;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
import com.nidefawl.Achievements.Achievements; import com.nidefawl.Achievements.Achievements;
import com.nidefawl.Stats.Stats; import terranetworkorg.Stats.Stats;
import com.nijikokun.register.Register; import com.nijikokun.register.Register;
import com.nijikokun.register.payment.Methods; import com.nijikokun.register.payment.Methods;
@@ -196,9 +196,9 @@ public class XmlStats extends JavaPlugin {
* @return true, if is stats hooked * @return true, if is stats hooked
*/ */
public boolean checkStats(){ public boolean checkStats(){
Plugin StatsTemp = getServer().getPluginManager().getPlugin("Stats"); Plugin StatsTemp = getServer().getPluginManager().getPlugin("Stats 2.0");
if(StatsTemp != null && StatsTemp.getClass().getName().equals("com.nidefawl.Stats.Stats") && StatsTemp.isEnabled()) return true; if(StatsTemp != null && StatsTemp.getClass().getName().equals("terranetworkorg.Stats.Stats") && StatsTemp.isEnabled()) return true;
return false; return false;
} }
@@ -260,6 +260,5 @@ public class XmlStats extends JavaPlugin {
XmlStatsServerListener listener = new XmlStatsServerListener(this); XmlStatsServerListener listener = new XmlStatsServerListener(this);
getServer().getPluginManager().registerEvent(Type.PLUGIN_ENABLE, listener, Priority.Monitor, this); getServer().getPluginManager().registerEvent(Type.PLUGIN_ENABLE, listener, Priority.Monitor, this);
//getServer().getPluginManager().registerEvent(Type.PLUGIN_DISABLE, listener, Priority.Monitor, this);
} }
} }

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 * 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

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 * 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

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 * 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
@@ -20,8 +20,6 @@ import java.util.List;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import com.nidefawl.Stats.datasource.Category;
import de.sockenklaus.XmlStats.Datasource.UserstatsDS; import de.sockenklaus.XmlStats.Datasource.UserstatsDS;
import de.sockenklaus.XmlStats.Exceptions.XmlStatsException; import de.sockenklaus.XmlStats.Exceptions.XmlStatsException;
import de.sockenklaus.XmlStats.Objects.NodeCategories; import de.sockenklaus.XmlStats.Objects.NodeCategories;
@@ -59,7 +57,7 @@ public class UserStats extends XmlWorker {
node_users.appendChild(new NodeUser(userName)); node_users.appendChild(new NodeUser(userName));
} }
HashMap<String, Category> addedStats = UserstatsDS.getAddedStats(playerList); HashMap<String, HashMap<String, Integer>> addedStats = UserstatsDS.getAddedStats(playerList);
for(String catName : addedStats.keySet()){ for(String catName : addedStats.keySet()){
NodeCategory node_cat = new NodeCategory(catName, addedStats.get(catName)); NodeCategory node_cat = new NodeCategory(catName, addedStats.get(catName));

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 * 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