diff --git a/MobArena.jar b/MobArena.jar index dd45ff7..e8350f1 100644 Binary files a/MobArena.jar and b/MobArena.jar differ diff --git a/bin/plugin.yml b/bin/plugin.yml index 8702e4c..c4417db 100644 --- a/bin/plugin.yml +++ b/bin/plugin.yml @@ -1,6 +1,6 @@ name: MobArena main: com.garbagemule.MobArena.MobArena -version: 0.89 +version: 0.89.1 commands: ma: description: Base command for MobArena diff --git a/src/com/garbagemule/MobArena/ArenaManager.java b/src/com/garbagemule/MobArena/ArenaManager.java index 80a6c39..7d38651 100644 --- a/src/com/garbagemule/MobArena/ArenaManager.java +++ b/src/com/garbagemule/MobArena/ArenaManager.java @@ -36,6 +36,7 @@ public class ArenaManager protected static boolean isSetup = false; protected static boolean isEnabled = true; protected static boolean isProtected = true; + protected static boolean checkUpdates = true; // Location variables for the arena region. protected static Location p1 = null; @@ -125,6 +126,7 @@ public class ArenaManager p1 = MAUtils.getCoords("p1"); p2 = MAUtils.getCoords("p2"); spawnpoints = MAUtils.getSpawnPoints(); + checkUpdates = MAUtils.getUpdateNotification(); // Set the boolean if all variables are valid. ArenaManager.isSetup = MAUtils.verifyData(); @@ -286,6 +288,7 @@ public class ArenaManager { p.teleport(spectatorLoc); MAUtils.clearInventory(p); + p.setFireTicks(0); p.setHealth(20); tellAll(p.getName() + " died!"); diff --git a/src/com/garbagemule/MobArena/MACommands.java b/src/com/garbagemule/MobArena/MACommands.java index f9e5c1d..301835a 100644 --- a/src/com/garbagemule/MobArena/MACommands.java +++ b/src/com/garbagemule/MobArena/MACommands.java @@ -118,6 +118,18 @@ public class MACommands implements CommandExecutor return true; } + if (cmd.equals("check")) + { + if (!arg.equals("updates")) + { + ArenaManager.tellPlayer(p, "/ma check updates"); + return true; + } + + MAUtils.checkForUpdates(p, true); + return true; + } + // ma force end if (cmd.equals("force")) { diff --git a/src/com/garbagemule/MobArena/MADamageListener.java b/src/com/garbagemule/MobArena/MADamageListener.java index daf1a43..c6734b0 100644 --- a/src/com/garbagemule/MobArena/MADamageListener.java +++ b/src/com/garbagemule/MobArena/MADamageListener.java @@ -42,7 +42,6 @@ public class MADamageListener extends EntityListener return; event.setCancelled(true); - p.setFireTicks(0); ArenaManager.playerDeath(p); } diff --git a/src/com/garbagemule/MobArena/MADisconnectListener.java b/src/com/garbagemule/MobArena/MADisconnectListener.java index bc6a3c7..c44a98b 100644 --- a/src/com/garbagemule/MobArena/MADisconnectListener.java +++ b/src/com/garbagemule/MobArena/MADisconnectListener.java @@ -7,6 +7,7 @@ import org.bukkit.event.player.PlayerListener; import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerKickEvent; +import org.bukkit.event.player.PlayerJoinEvent; /** * This listener acts when a player is kicked or disconnected @@ -43,4 +44,24 @@ public class MADisconnectListener extends PlayerListener ArenaManager.playerLeave(p); } } + + public void onPlayerJoin(PlayerJoinEvent event) + { + if (!ArenaManager.checkUpdates) + return; + + final Player p = event.getPlayer(); + + if (!event.getPlayer().isOp()) + return; + + ArenaManager.server.getScheduler().scheduleSyncDelayedTask(ArenaManager.plugin, + new Runnable() + { + public void run() + { + MAUtils.checkForUpdates(p, true); + } + }, 100); + } } \ No newline at end of file diff --git a/src/com/garbagemule/MobArena/MAUtils.java b/src/com/garbagemule/MobArena/MAUtils.java index 7cc63d5..120fdca 100644 --- a/src/com/garbagemule/MobArena/MAUtils.java +++ b/src/com/garbagemule/MobArena/MAUtils.java @@ -1,10 +1,14 @@ package com.garbagemule.MobArena; +import java.net.URL; +import java.net.URI; +import java.net.HttpURLConnection; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.util.Scanner; import java.util.Arrays; import java.util.List; import java.util.LinkedList; @@ -245,6 +249,18 @@ public class MAUtils return new Configuration(configFile); } + public static boolean getUpdateNotification() + { + Configuration c = ArenaManager.config; + c.load(); + + boolean result = c.getBoolean("updatenotification", false); + c.setProperty("updatenotification", result); + c.save(); + + return result; + } + public static List getDisabledCommands() { Configuration c = ArenaManager.config; @@ -445,6 +461,9 @@ public class MAUtils */ public static boolean inRegion(Location loc) { + if (!loc.getWorld().getName().equals(ArenaManager.world.getName())) + return false; + Location p1 = ArenaManager.p1; Location p2 = ArenaManager.p2; @@ -632,6 +651,54 @@ public class MAUtils } } + /** + * Checks if there is a new update of MobArena and notifies the + * player if the boolean specified is true + */ + public static void checkForUpdates(final Player p, boolean response) + { + String site = "http://forums.bukkit.org/threads/818.19144/"; + try + { + // Make a URL of the site address + //URL baseURL = new URL(site); + URI baseURL = new URI(site); + + // Open the connection and don't redirect. + HttpURLConnection con = (HttpURLConnection) baseURL.toURL().openConnection(); + con.setInstanceFollowRedirects(false); + + String header = con.getHeaderField("Location"); + + // If something's wrong with the connection... + if (header == null) + { + ArenaManager.tellPlayer(p, "Couldn't connect to the MobArena thread."); + return; + } + + // Otherwise, grab the location header to get the real URI. + String url = new URI(con.getHeaderField("Location")).toString(); + + // If the current version is the same as the thread version. + if (url.contains(ArenaManager.plugin.getDescription().getVersion().replace(".", "-"))) + { + if (!response) + return; + + ArenaManager.tellPlayer(p, "Your version of MobArena is up to date!"); + return; + } + + // Otherwise, notify the player that there is a new version. + ArenaManager.tellPlayer(p, "There is a new version of MobArena available!");; + } + catch (Exception e) + { + e.printStackTrace(); + } + } + /** * Turns the current set of players into an array, and grabs a random * element out of it. diff --git a/src/com/garbagemule/MobArena/MobArena.java b/src/com/garbagemule/MobArena/MobArena.java index c07b0fb..c7158ab 100644 --- a/src/com/garbagemule/MobArena/MobArena.java +++ b/src/com/garbagemule/MobArena/MobArena.java @@ -61,6 +61,7 @@ public class MobArena extends JavaPlugin pm.registerEvent(Event.Type.PLAYER_TELEPORT, teleportListener, Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_QUIT, discListener, Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_KICK, discListener, Priority.Normal, this); + pm.registerEvent(Event.Type.PLAYER_JOIN, discListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_DAMAGE, blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Priority.Normal, this);