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
This commit is contained in:
Pascal Koenig
2012-02-03 16:58:31 +01:00
23 changed files with 222 additions and 107 deletions

View File

@@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Fri Oct 14 01:25:23 CEST 2011
build.number=66
#Fri Feb 03 16:29:04 CET 2012
build.number=72

View File

@@ -2,13 +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/Achievements.jar"/>
<classpathentry kind="lib" path="lib/Register-1.5.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>

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

@@ -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).
[![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.

View File

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

Binary file not shown.

Binary file not shown.

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

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

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
@@ -17,13 +17,16 @@ 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 org.bukkit.plugin.Plugin;
import com.nidefawl.Stats.Stats;
/*import com.nidefawl.Stats.Stats;
import com.nidefawl.Stats.datasource.Category;
import com.nidefawl.Stats.datasource.PlayerStat;
import com.nidefawl.Stats.datasource.PlayerStatSQL;
import com.nidefawl.Stats.datasource.PlayerStatSQL;*/
import de.sockenklaus.XmlStats.Util;
import de.sockenklaus.XmlStats.Webserver;
@@ -67,48 +70,83 @@ public class StatsDS extends Datasource {
public File getDataFolder(){
return this.stats.getDataFolder();
}
public HashMap<String, Category> getAddedStats(List<String> playerList){
HashMap <String, Category> result = new HashMap<String, Category>();
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){
PlayerStat player = getPlayerStat(playerName);
PlayerCache player = getPlayerCache(playerName);
for(String catName : player.getCats()){
Category cat = player.get(catName);
for(String entryName : cat.getEntries()){
Integer entry = cat.get(entryName);
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(result.containsKey(catName)){
if(entryName.equals("lastlogin") || entryName.equals("lastlogout")){
result.get(catName).put(entryName, Math.max(result.get(catName).get(entryName), entry));
}
else {
result.get(catName).add(entryName, entry);
}
if(ps.getName().equals("lastlogin") || ps.getName().equals("lastlogout")){
result.get(ps.getCat()).put(ps.getName(), Math.max(ps.getValue(), currVal));
}
else {
Category tempCat = new Category();
tempCat.add(entryName, entry);
result.put(catName, tempCat);
result.get(ps.getCat()).put(ps.getName(), currVal + ps.getValue());
}
}
}
}
return result;
}
public PlayerStat getPlayerStat(String playerName){
PlayerStat result = new PlayerStatSQL(playerName, this.getStats());
public static HashMap<String, HashMap<String, Integer>> getStats(String playerName){
HashMap<String, HashMap<String, Integer>> result = new HashMap<String, HashMap<String, Integer>>();
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;
}
private static PlayerCache getPlayerCache(String playerName){
return PlayerControl.getPlayerCache(playerName);
}
private void hookStats(){

View File

@@ -3,7 +3,7 @@
*/
package de.sockenklaus.XmlStats.Objects;
import com.nidefawl.Stats.datasource.PlayerStat;
import java.util.HashMap;
import de.sockenklaus.XmlStats.Datasource.StatsDS;
@@ -21,9 +21,10 @@ public class NodeCategories extends NodeArray {
*/
public NodeCategories(String userName) {
this();
PlayerStat userStat = StatsDS.getInstance().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));
this.appendChild(node_cat);
}

View File

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

View File

@@ -3,12 +3,7 @@
*/
package de.sockenklaus.XmlStats.Objects;
import java.io.File;
import com.nidefawl.Stats.ItemResolver.hModItemResolver;
import com.nidefawl.Stats.datasource.Category;
import de.sockenklaus.XmlStats.Datasource.StatsDS;
import java.util.HashMap;
/**
* @author socrates
@@ -19,18 +14,10 @@ public class NodeItems extends NodeArray {
/**
* @param category
*/
public NodeItems(Category category, Boolean resolve) {
public NodeItems(HashMap<String, Integer> category) {
super("items");
hModItemResolver itemResolver = new hModItemResolver(new File(StatsDS.getInstance().getDataFolder(),"items.txt"));
for(String varName : category.getEntries()){
NodeItem node_item = new NodeItem(varName, category.get(varName));
if(resolve){
node_item.setAttribute("id", itemResolver.getItem(varName));
}
for(String varName : category.keySet()){
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
* 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,8 +26,8 @@ import org.bukkit.util.config.Configuration;
public class Settings {
private static final String configFilename = "config.yml";
private static Settings instance;
private Configuration conf;
private YamlConfiguration conf;
/**
* Instantiates a new settings.
@@ -35,16 +36,19 @@ public class Settings {
*/
private Settings(){
File f = new File(XmlStats.getInstance().getDataFolder(), configFilename);
this.conf = new Configuration(f);
if(f.exists()){
this.conf.load();
conf = YamlConfiguration.loadConfiguration(f);
}
else {
this.conf.setProperty("options.webserver-enabled", true);
this.conf.setProperty("options.webserver-port", 9123);
this.conf.setProperty("options.verbose-enabled", true);
this.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());
}
}
}
@@ -90,7 +94,7 @@ public class Settings {
* @param value the value
*/
public void setProperty(String path, Object value){
this.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
* 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
* the GNU General Public License as published by the Free Software Foundation; either version
@@ -19,13 +19,14 @@ import java.util.logging.Logger;
import org.bukkit.command.Command;
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.java.JavaPlugin;
import de.sockenklaus.XmlStats.Datasource.AchievementsDS;
import de.sockenklaus.XmlStats.Datasource.RegisterDS;
import de.sockenklaus.XmlStats.Datasource.StatsDS;
import com.nidefawl.Achievements.Achievements;
import terranetworkorg.Stats.Stats;
import com.nijikokun.register.Register;
import com.nijikokun.register.payment.Methods;
// TODO: Auto-generated Javadoc
/**
@@ -145,6 +146,53 @@ public class XmlStats extends JavaPlugin {
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 {
LogWarn("Achievements not found! Can't hook into it.");
}
}
protected void hookStats(){
Plugin StatsTemp = getServer().getPluginManager().getPlugin("Stats 2.0");
LogDebug("Got Plugin \"Stats 2.0\"");
Webserver webserver = (Webserver)XmlStatsRegistry.get("webserver");
LogDebug("Got webserver-object");
if(this.checkStats()){
XmlStatsRegistry.put("stats", (Stats)StatsTemp);
LogInfo("Hooked into Stats!");
webserver.startStats();
}
else {
LogWarn("Stats not found! Can't hook into it.");
}
}
/**
* Checks if is stats hooked.
*
* @return true, if is stats hooked
*/
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 && 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;
}
/* (non-Javadoc)
* @see org.bukkit.plugin.java.JavaPlugin#onCommand(org.bukkit.command.CommandSender, org.bukkit.command.Command, java.lang.String, java.lang.String[])
@@ -174,11 +222,14 @@ public class XmlStats extends JavaPlugin {
protected void reload() {
this.onDisable();
this.onEnable();
}
private void registerEvents(){
XmlStatsServerListener listener = new XmlStatsServerListener();
LogDebug("Trying to register ServerListener");
XmlStatsServerListener listener = new XmlStatsServerListener(this);
LogDebug("Listener-object created.");
getServer().getPluginManager().registerEvent(Type.PLUGIN_ENABLE, listener, Priority.Monitor, this);
getServer().getPluginManager().registerEvents(listener, this);
LogDebug("Event registered.");
}
}

View File

@@ -3,8 +3,10 @@
*/
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 org.bukkit.event.server.ServerListener;
import de.sockenklaus.XmlStats.Datasource.AchievementsDS;
import de.sockenklaus.XmlStats.Datasource.RegisterDS;
@@ -14,11 +16,43 @@ import de.sockenklaus.XmlStats.Datasource.StatsDS;
* @author socrates
*
*/
public class XmlStatsServerListener extends ServerListener {
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){
if(this.identifyPlugin(event, "stats") && Util.checkStats()){
StatsDS.getInstance();
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();

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

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

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
@@ -20,9 +20,13 @@ 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;
@@ -59,7 +63,11 @@ public class UserStats extends XmlWorker {
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));

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