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!
#Thu Oct 06 22:29:49 CEST 2011
build.number=43
#Fri Feb 03 15:11:44 CET 2012
build.number=69

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

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

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
@@ -18,10 +18,15 @@ import java.io.File;
import java.util.HashMap;
import java.util.List;
import com.nidefawl.Stats.Stats;
import terranetworkorg.Stats.Stats;
import terranetworkorg.Stats.Storage.PlayerCache;
import terranetworkorg.Stats.Storage.PlayerControl;
import terranetworkorg.Stats.Storage.PlayerStats;
/*import com.nidefawl.Stats.Stats;
import com.nidefawl.Stats.datasource.Category;
import com.nidefawl.Stats.datasource.PlayerStat;
import com.nidefawl.Stats.datasource.PlayerStatSQL;
import com.nidefawl.Stats.datasource.PlayerStatSQL;*/
import de.sockenklaus.XmlStats.XmlStatsRegistry;
@@ -43,32 +48,39 @@ public class UserstatsDS extends Datasource {
return statsPlugin.getDataFolder();
}
public static 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);
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);
}
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 {
Category tempCat = new Category();
tempCat.add(entryName, entry);
result.put(catName, tempCat);
result.get(ps.getCat()).put(ps.getName(), currVal + ps.getValue());
}
}
}
@@ -77,12 +89,40 @@ public class UserstatsDS extends Datasource {
return result;
}
public static PlayerStat getPlayerStat(String playerName){
statsPlugin = (Stats)XmlStatsRegistry.get("stats");
PlayerStat result = new PlayerStatSQL(playerName, statsPlugin);
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);
}
}

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.UserstatsDS;
@@ -21,9 +21,9 @@ public class NodeCategories extends NodeArray {
*/
public NodeCategories(String userName) {
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));
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,8 @@
*/
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
@@ -19,18 +15,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(UserstatsDS.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,7 +26,7 @@ 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.
@@ -35,15 +36,18 @@ public class Settings {
public Settings(XmlStats xmlStats){
File f = new File(xmlStats.getDataFolder(), configFilename);
conf = new Configuration(f);
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());
}
}
}
@@ -84,7 +88,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

@@ -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,13 @@ 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 org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
import com.nidefawl.Achievements.Achievements;
import com.nidefawl.Stats.Stats;
import terranetworkorg.Stats.Stats;
import com.nijikokun.register.Register;
import com.nijikokun.register.payment.Methods;
@@ -196,9 +196,9 @@ public class XmlStats extends JavaPlugin {
* @return true, if is stats hooked
*/
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;
}
@@ -260,6 +260,5 @@ public class XmlStats extends JavaPlugin {
XmlStatsServerListener listener = new XmlStatsServerListener(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
* 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,8 +20,6 @@ import java.util.List;
import org.w3c.dom.Element;
import com.nidefawl.Stats.datasource.Category;
import de.sockenklaus.XmlStats.Datasource.UserstatsDS;
import de.sockenklaus.XmlStats.Exceptions.XmlStatsException;
import de.sockenklaus.XmlStats.Objects.NodeCategories;
@@ -59,7 +57,7 @@ public class UserStats extends XmlWorker {
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()){
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