Latest version, 1.7.1

Using new CB events.
Updated Metrics to R3.
This commit is contained in:
lishid 2012-01-26 20:58:11 -05:00
parent 86daef30f5
commit faed001041
6 changed files with 107 additions and 37 deletions

View file

@ -2,11 +2,11 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="lib" path="D:/Programs/Eclipse/Workspace/bukkit.jar" sourcepath="D:/Programs/Eclipse/Workspace/Bukkit-Source.zip"/>
<classpathentry kind="lib" path="D:/Programs/Eclipse/Workspace/craftbukkit.jar" sourcepath="D:/Programs/Eclipse/Workspace/CraftBukkit-Source.zip"/>
<classpathentry kind="lib" path="D:/Programs/Eclipse/Workspace/PermissionsEx.jar"/>
<classpathentry kind="lib" path="D:/Programs/Eclipse/Workspace/Permissions.jar"/>
<classpathentry kind="lib" path="D:/Programs/Eclipse/Workspace/spout.jar" sourcepath="D:/Programs/Eclipse/Workspace/Spout.zip"/>
<classpathentry kind="lib" path="D:/Programs/Eclipse/Workspace/spoutapi.jar" sourcepath="D:/Programs/Eclipse/Workspace/SpoutAPI.zip"/>
<classpathentry combineaccessrules="false" kind="src" path="/Orebfuscator"/>
<classpathentry kind="lib" path="D:/Dropbox/Projects/Workspace/bukkit.jar" sourcepath="D:/Dropbox/Projects/Workspace/Bukkit-Source.zip"/>
<classpathentry kind="lib" path="D:/Dropbox/Projects/Workspace/craftbukkit.jar" sourcepath="D:/Dropbox/Projects/Workspace/craftbukkit.jar"/>
<classpathentry kind="lib" path="D:/Dropbox/Projects/Workspace/FakePermissions.jar"/>
<classpathentry kind="lib" path="D:/Dropbox/Projects/Workspace/Spout.jar" sourcepath="D:/Dropbox/Projects/Workspace/Spout.zip"/>
<classpathentry kind="lib" path="D:/Dropbox/Projects/Workspace/SpoutAPI.jar" sourcepath="D:/Dropbox/Projects/Workspace/SpoutAPI.zip"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -6,7 +6,6 @@ import lishid.openinv.utils.Metrics;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
@ -49,10 +48,8 @@ public class OpenInv extends JavaPlugin {
mainPlugin.saveConfig();
PluginManager pm = getServer().getPluginManager();
pm.registerEvent(Event.Type.PLAYER_LOGIN, playerListener, Event.Priority.Lowest, this);
pm.registerEvent(Event.Type.PLAYER_INTERACT, playerListener, Event.Priority.Monitor, this);
pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Event.Priority.Lowest, this);
//pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Event.Priority.Monitor, this);
pm.registerEvents(playerListener, this);
pm.registerEvents(entityListener, this);
setupPermissions();

View file

@ -4,16 +4,18 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
public class OpenInvEntityListener extends EntityListener{
public class OpenInvEntityListener implements Listener{
OpenInv plugin;
public OpenInvEntityListener(OpenInv scrap) {
plugin = scrap;
}
@Override
public void onEntityDamage(EntityDamageEvent event) {
@EventHandler(priority = EventPriority.LOWEST)
public void onEntityDamage(EntityDamageEvent event) {
if (event instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent evt = (EntityDamageByEntityEvent) event;
Entity attacker = evt.getDamager();

View file

@ -19,19 +19,21 @@ import org.bukkit.block.Chest;
import org.bukkit.block.Sign;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Event.Result;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerLoginEvent;
public class OpenInvPlayerListener extends PlayerListener{
public class OpenInvPlayerListener implements Listener{
OpenInv plugin;
public OpenInvPlayerListener(OpenInv scrap) {
plugin = scrap;
}
@Override
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerLogin(PlayerLoginEvent event)
{
try{
@ -50,7 +52,7 @@ public class OpenInvPlayerListener extends PlayerListener{
catch(Exception e){}
}
@Override
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerInteract(PlayerInteractEvent event)
{
if(event.getAction() == Action.RIGHT_CLICK_BLOCK && event.useInteractedBlock() == Result.DENY)

View file

@ -41,6 +41,11 @@ import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
/**
@ -48,10 +53,46 @@ import java.util.UUID;
*/
public class Metrics {
/**
* Interface used to collect custom data for a plugin
*/
public static abstract class Plotter {
/**
* Get the column name for the plotted point
*
* @return the plotted point's column name
*/
public abstract String getColumnName();
/**
* Get the current value for the plotted point
*
* @return
*/
public abstract int getValue();
@Override
public int hashCode() {
return getColumnName().hashCode() + getValue();
}
@Override
public boolean equals(Object object) {
if (!(object instanceof Plotter)) {
return false;
}
Plotter plotter = (Plotter) object;
return plotter.getColumnName().equals(getColumnName()) && plotter.getValue() == getValue();
}
}
/**
* The metrics revision number
*/
private final static int REVISION = 2;
private final static int REVISION = 3;
/**
* The base url of the metrics domain
@ -71,13 +112,17 @@ public class Metrics {
/**
* Interval of time to ping in minutes
*/
private final static long PING_INTERVAL = 20L;
private final static int PING_INTERVAL = 10;
/**
* A map of the custom data plotters for plugins
*/
private Map<Plugin, Set<Plotter>> customData = Collections.synchronizedMap(new HashMap<Plugin, Set<Plotter>>());
/**
* The plugin configuration file
*/
private final YamlConfiguration configuration;
/**
* Unique server id
@ -103,6 +148,23 @@ public class Metrics {
guid = configuration.getString("guid");
}
/**
* Adds a custom data plotter for a given plugin
*
* @param plugin
* @param plotter
*/
public void addCustomData(Plugin plugin, Plotter plotter) {
Set<Plotter> plotters = customData.get(plugin);
if (plotters == null) {
plotters = Collections.synchronizedSet(new LinkedHashSet<Plotter>());
customData.put(plugin, plotters);
}
plotters.add(plotter);
}
/**
* Begin measuring a plugin
*
@ -126,7 +188,7 @@ public class Metrics {
System.out.println("[Metrics] " + e.getMessage());
}
}
}, 0, PING_INTERVAL * 1200);
}, PING_INTERVAL * 1200, PING_INTERVAL * 1200);
}
/**
@ -137,15 +199,25 @@ public class Metrics {
private void postPlugin(Plugin plugin, boolean isPing) throws IOException {
// Construct the post data
String response = "ERR No response";
String data = encode("guid") + "=" + encode(guid)
+ "&" + encode("version") + "=" + encode(plugin.getDescription().getVersion())
+ "&" + encode("server") + "=" + encode(Bukkit.getVersion())
+ "&" + encode("players") + "=" + encode(Bukkit.getServer().getOnlinePlayers().length + "")
+ "&" + encode("revision") + "=" + encode(REVISION + "");
String data = encode("guid") + '=' + encode(guid)
+ '&' + encode("version") + '=' + encode(plugin.getDescription().getVersion())
+ '&' + encode("server") + '=' + encode(Bukkit.getVersion())
+ '&' + encode("players") + '=' + encode(String.valueOf(Bukkit.getServer().getOnlinePlayers().length))
+ '&' + encode("revision") + '=' + encode(REVISION + "");
// If we're pinging, append it
if (isPing) {
data += "&" + encode("ping") + "=" + encode("true");
data += '&' + encode("ping") + '=' + encode("true");
}
// Add any custom data (if applicable)
Set<Plotter> plotters = customData.get(plugin);
if (plotters != null) {
for (Plotter plotter : plotters) {
data += "&" + encode ("Custom" + plotter.getColumnName())
+ "=" + encode(Integer.toString(plotter.getValue()));
}
}
// Create the url
@ -168,13 +240,10 @@ public class Metrics {
writer.close();
reader.close();
if (response.startsWith("OK")) {
// Useless return, but it documents that we should be receiving OK followed by an optional description
return;
} else if (response.startsWith("ERR")) {
// Throw it to whoever is catching us
throw new IOException(response);
if (response.startsWith("ERR")){
throw new IOException(response); //Throw the exception
}
//if (response.startsWith("OK")) - We should get "OK" followed by an optional description if everything goes right
}
/**
@ -183,7 +252,7 @@ public class Metrics {
* @param text
* @return
*/
private String encode(String text) throws UnsupportedEncodingException {
private static String encode(String text) throws UnsupportedEncodingException {
return URLEncoder.encode(text, "UTF-8");
}

View file

@ -1,6 +1,6 @@
name: OpenInv
main: lishid.openinv.OpenInv
version: 1.7.2
version: 1.7.3
author: lishid
website: http://forums.bukkit.org/threads/15379/
description: >