From 1c5818465640cfa311fa8b9f0f7155f59b802947 Mon Sep 17 00:00:00 2001 From: Steven Scott Date: Sun, 9 Dec 2012 12:59:44 -0800 Subject: [PATCH] Update Metrics. Remove custom sign class. Stupid Bukkit --- README | 8 ++- src/net/TheDgtl/Stargate/MetricsLite.java | 83 ++++++++++++++++------ src/net/TheDgtl/Stargate/Portal.java | 2 +- src/net/TheDgtl/Stargate/StargateSign.java | 58 --------------- src/plugin.yml | 2 +- 5 files changed, 71 insertions(+), 82 deletions(-) delete mode 100644 src/net/TheDgtl/Stargate/StargateSign.java diff --git a/README b/README index e9eb956..abef3cc 100644 --- a/README +++ b/README @@ -207,12 +207,18 @@ createConflict=Gate conflicts with existing gate ============= 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 +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 ============= +[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] - Optimize gate lookup in onPlayerMove - Resolve issue where Stargates would teleport players to the nether diff --git a/src/net/TheDgtl/Stargate/MetricsLite.java b/src/net/TheDgtl/Stargate/MetricsLite.java index 65fad05..1334e85 100644 --- a/src/net/TheDgtl/Stargate/MetricsLite.java +++ b/src/net/TheDgtl/Stargate/MetricsLite.java @@ -33,6 +33,7 @@ import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; +import org.bukkit.scheduler.BukkitTask; import java.io.BufferedReader; import java.io.File; @@ -52,7 +53,7 @@ public class MetricsLite { /** * The current revision number */ - private final static int REVISION = 5; + private final static int REVISION = 6; /** * The base url of the metrics domain @@ -89,6 +90,11 @@ public class MetricsLite { */ private final String guid; + /** + * Debug mode + */ + private final boolean debug; + /** * Lock for synchronization */ @@ -97,7 +103,7 @@ public class MetricsLite { /** * Id of the scheduled task */ - private volatile int taskId = -1; + private volatile BukkitTask task = null; public MetricsLite(Plugin plugin) throws IOException { if (plugin == null) { @@ -113,6 +119,7 @@ public class MetricsLite { // add some defaults configuration.addDefault("opt-out", false); configuration.addDefault("guid", UUID.randomUUID().toString()); + configuration.addDefault("debug", false); // Do we need to create the file? if (configuration.get("guid", null) == null) { @@ -122,6 +129,7 @@ public class MetricsLite { // Load the guid then guid = configuration.getString("guid"); + debug = configuration.getBoolean("debug", false); } /** @@ -139,12 +147,12 @@ public class MetricsLite { } // Is metrics already running? - if (taskId >= 0) { + if (task != null) { return true; } // 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; @@ -153,9 +161,9 @@ public class MetricsLite { // This has to be synchronized or it can collide with the disable method. synchronized (optOutLock) { // Disable Task, if it is running and the server owner decided to opt-out - if (isOptOut() && taskId > 0) { - plugin.getServer().getScheduler().cancelTask(taskId); - taskId = -1; + if (isOptOut() && task != null) { + task.cancel(); + task = null; } } @@ -168,7 +176,9 @@ public class MetricsLite { // Each post thereafter will be a ping firstPost = false; } 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); @@ -188,10 +198,14 @@ public class MetricsLite { // Reload the metrics file configuration.load(getConfigFile()); } catch (IOException ex) { - Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); + if (debug) { + Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); + } return true; } catch (InvalidConfigurationException ex) { - Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); + if (debug) { + Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); + } return true; } return configuration.getBoolean("opt-out", false); @@ -213,7 +227,7 @@ public class MetricsLite { } // Enable Task, if it is not running - if (taskId < 0) { + if (task == null) { start(); } } @@ -234,9 +248,9 @@ public class MetricsLite { } // Disable Task, if it is running - if (taskId > 0) { - this.plugin.getServer().getScheduler().cancelTask(taskId); - taskId = -1; + if (task != null) { + task.cancel(); + task = null; } } } @@ -262,24 +276,52 @@ public class MetricsLite { * Generic method that posts a plugin to the metrics website */ private void postPlugin(boolean isPing) throws IOException { - // The plugin's description file containg all of the plugin data such as name, version, author, etc - final PluginDescriptionFile description = plugin.getDescription(); + // Server software specific section + 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 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)); - encodeDataPair(data, "version", description.getVersion()); - encodeDataPair(data, "server", Bukkit.getVersion()); - encodeDataPair(data, "players", Integer.toString(Bukkit.getServer().getOnlinePlayers().length)); + encodeDataPair(data, "version", pluginVersion); + encodeDataPair(data, "server", serverVersion); + encodeDataPair(data, "players", Integer.toString(playersOnline)); 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 (isPing) { encodeDataPair(data, "ping", "true"); } // 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 URLConnection connection; @@ -310,7 +352,6 @@ public class MetricsLite { if (response == null || 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 } /** diff --git a/src/net/TheDgtl/Stargate/Portal.java b/src/net/TheDgtl/Stargate/Portal.java index 74cfb16..1cb276c 100644 --- a/src/net/TheDgtl/Stargate/Portal.java +++ b/src/net/TheDgtl/Stargate/Portal.java @@ -694,7 +694,7 @@ public class Portal { Stargate.debug("Portal::drawSign", "Block: " + id.getBlock().getType() + " @ " + id.getBlock().getLocation()); return; } - Sign sign = (Sign)new StargateSign(id.getBlock()); + Sign sign = (Sign)id.getBlock().getState(); Stargate.setLine(sign, 0, "-" + name + "-"); int max = destinations.size() - 1; int done = 0; diff --git a/src/net/TheDgtl/Stargate/StargateSign.java b/src/net/TheDgtl/Stargate/StargateSign.java deleted file mode 100644 index bcf9bde..0000000 --- a/src/net/TheDgtl/Stargate/StargateSign.java +++ /dev/null @@ -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; - } -} diff --git a/src/plugin.yml b/src/plugin.yml index 982709b..713cac5 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: Stargate main: net.TheDgtl.Stargate.Stargate -version: 0.7.9.1 +version: 0.7.9.2 description: Stargate mod for Bukkit author: Drakia website: http://www.thedgtl.net