Update Metrics. Remove custom sign class. Stupid Bukkit

This commit is contained in:
Steven Scott 2012-12-09 12:59:44 -08:00
parent 422b30d54e
commit 1c58184656
5 changed files with 71 additions and 82 deletions

8
README
View File

@ -207,12 +207,18 @@ createConflict=Gate conflicts with existing gate
============= =============
Known Bugs Known Bugs
============= =============
Unable to reproduce: Stargates teleport a user to the Nether
Unable to reproduce: Stargates teleport a user into the ground/under the ground Unable to reproduce: Stargates teleport a user into the ground/under the ground
Bukkit Issue: Stargate will randomly NPE when drawing a sign. Long-standing Bukkit
issue, that they just made worse by disallowing me to override the
sign class.
============= =============
Changes Changes
============= =============
[Version 0.7.9.2]
- Remove my custom sign class. Stupid Bukkit team.
- Will work with CB 1.4.5 builds, but now will break randomly due to Bukkit screwup
- Update MetricsLite to R6
[Version 0.7.9.1] [Version 0.7.9.1]
- Optimize gate lookup in onPlayerMove - Optimize gate lookup in onPlayerMove
- Resolve issue where Stargates would teleport players to the nether - Resolve issue where Stargates would teleport players to the nether

View File

@ -33,6 +33,7 @@ import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.scheduler.BukkitTask;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
@ -52,7 +53,7 @@ public class MetricsLite {
/** /**
* The current revision number * The current revision number
*/ */
private final static int REVISION = 5; private final static int REVISION = 6;
/** /**
* The base url of the metrics domain * The base url of the metrics domain
@ -89,6 +90,11 @@ public class MetricsLite {
*/ */
private final String guid; private final String guid;
/**
* Debug mode
*/
private final boolean debug;
/** /**
* Lock for synchronization * Lock for synchronization
*/ */
@ -97,7 +103,7 @@ public class MetricsLite {
/** /**
* Id of the scheduled task * Id of the scheduled task
*/ */
private volatile int taskId = -1; private volatile BukkitTask task = null;
public MetricsLite(Plugin plugin) throws IOException { public MetricsLite(Plugin plugin) throws IOException {
if (plugin == null) { if (plugin == null) {
@ -113,6 +119,7 @@ public class MetricsLite {
// add some defaults // add some defaults
configuration.addDefault("opt-out", false); configuration.addDefault("opt-out", false);
configuration.addDefault("guid", UUID.randomUUID().toString()); configuration.addDefault("guid", UUID.randomUUID().toString());
configuration.addDefault("debug", false);
// Do we need to create the file? // Do we need to create the file?
if (configuration.get("guid", null) == null) { if (configuration.get("guid", null) == null) {
@ -122,6 +129,7 @@ public class MetricsLite {
// Load the guid then // Load the guid then
guid = configuration.getString("guid"); guid = configuration.getString("guid");
debug = configuration.getBoolean("debug", false);
} }
/** /**
@ -139,12 +147,12 @@ public class MetricsLite {
} }
// Is metrics already running? // Is metrics already running?
if (taskId >= 0) { if (task != null) {
return true; return true;
} }
// Begin hitting the server with glorious data // Begin hitting the server with glorious data
taskId = plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() { task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
private boolean firstPost = true; private boolean firstPost = true;
@ -153,9 +161,9 @@ public class MetricsLite {
// This has to be synchronized or it can collide with the disable method. // This has to be synchronized or it can collide with the disable method.
synchronized (optOutLock) { synchronized (optOutLock) {
// Disable Task, if it is running and the server owner decided to opt-out // Disable Task, if it is running and the server owner decided to opt-out
if (isOptOut() && taskId > 0) { if (isOptOut() && task != null) {
plugin.getServer().getScheduler().cancelTask(taskId); task.cancel();
taskId = -1; task = null;
} }
} }
@ -168,7 +176,9 @@ public class MetricsLite {
// Each post thereafter will be a ping // Each post thereafter will be a ping
firstPost = false; firstPost = false;
} catch (IOException e) { } catch (IOException e) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage()); if (debug) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
}
} }
} }
}, 0, PING_INTERVAL * 1200); }, 0, PING_INTERVAL * 1200);
@ -188,10 +198,14 @@ public class MetricsLite {
// Reload the metrics file // Reload the metrics file
configuration.load(getConfigFile()); configuration.load(getConfigFile());
} catch (IOException ex) { } catch (IOException ex) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); if (debug) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
}
return true; return true;
} catch (InvalidConfigurationException ex) { } catch (InvalidConfigurationException ex) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); if (debug) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
}
return true; return true;
} }
return configuration.getBoolean("opt-out", false); return configuration.getBoolean("opt-out", false);
@ -213,7 +227,7 @@ public class MetricsLite {
} }
// Enable Task, if it is not running // Enable Task, if it is not running
if (taskId < 0) { if (task == null) {
start(); start();
} }
} }
@ -234,9 +248,9 @@ public class MetricsLite {
} }
// Disable Task, if it is running // Disable Task, if it is running
if (taskId > 0) { if (task != null) {
this.plugin.getServer().getScheduler().cancelTask(taskId); task.cancel();
taskId = -1; task = null;
} }
} }
} }
@ -262,24 +276,52 @@ public class MetricsLite {
* Generic method that posts a plugin to the metrics website * Generic method that posts a plugin to the metrics website
*/ */
private void postPlugin(boolean isPing) throws IOException { private void postPlugin(boolean isPing) throws IOException {
// The plugin's description file containg all of the plugin data such as name, version, author, etc // Server software specific section
final PluginDescriptionFile description = plugin.getDescription(); PluginDescriptionFile description = plugin.getDescription();
String pluginName = description.getName();
boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled
String pluginVersion = description.getVersion();
String serverVersion = Bukkit.getVersion();
int playersOnline = Bukkit.getServer().getOnlinePlayers().length;
// END server software specific section -- all code below does not use any code outside of this class / Java
// Construct the post data // Construct the post data
final StringBuilder data = new StringBuilder(); final StringBuilder data = new StringBuilder();
// The plugin's description file containg all of the plugin data such as name, version, author, etc
data.append(encode("guid")).append('=').append(encode(guid)); data.append(encode("guid")).append('=').append(encode(guid));
encodeDataPair(data, "version", description.getVersion()); encodeDataPair(data, "version", pluginVersion);
encodeDataPair(data, "server", Bukkit.getVersion()); encodeDataPair(data, "server", serverVersion);
encodeDataPair(data, "players", Integer.toString(Bukkit.getServer().getOnlinePlayers().length)); encodeDataPair(data, "players", Integer.toString(playersOnline));
encodeDataPair(data, "revision", String.valueOf(REVISION)); encodeDataPair(data, "revision", String.valueOf(REVISION));
// New data as of R6
String osname = System.getProperty("os.name");
String osarch = System.getProperty("os.arch");
String osversion = System.getProperty("os.version");
String java_version = System.getProperty("java.version");
int coreCount = Runtime.getRuntime().availableProcessors();
// normalize os arch .. amd64 -> x86_64
if (osarch.equals("amd64")) {
osarch = "x86_64";
}
encodeDataPair(data, "osname", osname);
encodeDataPair(data, "osarch", osarch);
encodeDataPair(data, "osversion", osversion);
encodeDataPair(data, "cores", Integer.toString(coreCount));
encodeDataPair(data, "online-mode", Boolean.toString(onlineMode));
encodeDataPair(data, "java_version", java_version);
// If we're pinging, append it // If we're pinging, append it
if (isPing) { if (isPing) {
encodeDataPair(data, "ping", "true"); encodeDataPair(data, "ping", "true");
} }
// Create the url // Create the url
URL url = new URL(BASE_URL + String.format(REPORT_URL, encode(plugin.getDescription().getName()))); URL url = new URL(BASE_URL + String.format(REPORT_URL, encode(pluginName)));
// Connect to the website // Connect to the website
URLConnection connection; URLConnection connection;
@ -310,7 +352,6 @@ public class MetricsLite {
if (response == null || response.startsWith("ERR")) { if (response == null || response.startsWith("ERR")) {
throw new IOException(response); //Throw the exception throw new IOException(response); //Throw the exception
} }
//if (response.startsWith("OK")) - We should get "OK" followed by an optional description if everything goes right
} }
/** /**

View File

@ -694,7 +694,7 @@ public class Portal {
Stargate.debug("Portal::drawSign", "Block: " + id.getBlock().getType() + " @ " + id.getBlock().getLocation()); Stargate.debug("Portal::drawSign", "Block: " + id.getBlock().getType() + " @ " + id.getBlock().getLocation());
return; return;
} }
Sign sign = (Sign)new StargateSign(id.getBlock()); Sign sign = (Sign)id.getBlock().getState();
Stargate.setLine(sign, 0, "-" + name + "-"); Stargate.setLine(sign, 0, "-" + name + "-");
int max = destinations.size() - 1; int max = destinations.size() - 1;
int done = 0; int done = 0;

View File

@ -1,58 +0,0 @@
package net.TheDgtl.Stargate;
import net.minecraft.server.TileEntitySign;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBlockState;
public class StargateSign extends CraftBlockState implements Sign {
private final TileEntitySign sign;
private final String[] lines;
public StargateSign(final Block block) {
super(block);
CraftWorld world = (CraftWorld) block.getWorld();
sign = (TileEntitySign) world.getTileEntityAt(getX(), getY(), getZ());
if (sign != null) {
lines = new String[sign.lines.length];
System.arraycopy(sign.lines, 0, lines, 0, lines.length);
} else {
// Sadly, due to Minecraft having many issues with blocks, chunks
// and entities, we must assume a 4-line sign if the sign is null
lines = new String[4];
}
}
public String[] getLines() {
return lines;
}
public String getLine(int index) throws IndexOutOfBoundsException {
return lines[index];
}
public void setLine(int index, String line) throws IndexOutOfBoundsException {
lines[index] = line;
}
@Override
public boolean update(boolean force) {
boolean result = super.update(force) && (sign != null);
if (result) {
for(int i = 0; i < sign.lines.length; i++) {
if(lines[i] != null) {
sign.lines[i] = lines[i];
} else {
sign.lines[i] = "";
}
}
sign.update();
}
return result;
}
}

View File

@ -1,6 +1,6 @@
name: Stargate name: Stargate
main: net.TheDgtl.Stargate.Stargate main: net.TheDgtl.Stargate.Stargate
version: 0.7.9.1 version: 0.7.9.2
description: Stargate mod for Bukkit description: Stargate mod for Bukkit
author: Drakia author: Drakia
website: http://www.thedgtl.net website: http://www.thedgtl.net