Skip to content

Commit

Permalink
Max Health on a Thread
Browse files Browse the repository at this point in the history
  • Loading branch information
ChagnonSebastien committed Jun 29, 2016
1 parent 4e4c8bf commit a177900
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Bukkit/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CubeRunner
main : me.poutineqc.cuberunner.CubeRunner
version: 2.5.1
version: 2.5.2
description: Blocks are falling over your head! Can you outrun them?
load: postworld
author: PoutineQc
Expand Down
41 changes: 24 additions & 17 deletions Bukkit/src/me/poutineqc/cuberunner/Updater.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,16 @@ public final class Updater implements Listener {

private final CubeRunner plugin;
private final int id;
private boolean lastVersion;
private String latestVersion;

private boolean lastVersion = true;
private String latestVersion = "";

public Updater(final CubeRunner plugin) {
this.plugin = plugin;

id = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
public void run() {
checkForLastVersion(plugin);
if (!lastVersion) {
notifyConsole(plugin);
}
}
}, 0, 72000L);
}
Expand All @@ -48,24 +45,35 @@ public void onPlayerJoin(PlayerJoinEvent event) {
notifyPlayer(event.getPlayer());
}

private void checkForLastVersion(CubeRunner plugin) {
try {
lastVersion = getInfoFromServer();
} catch (IOException e) {
plugin.getLogger().warning("Could not find the latest version available.");
stop();
return;
}
private void checkForLastVersion(final CubeRunner plugin) {
new Thread(new Runnable() {

@Override
public void run() {
try {
lastVersion = getInfoFromServer();
} catch (IOException e) {
plugin.getLogger().warning("Could not find the latest version available.");
stop();
return;
}

if (!lastVersion) {
notifyConsole(plugin);
}
}
}).start();
}

private boolean getInfoFromServer() throws IOException {

URL oracle = new URL(spigotPage + "history");
URLConnection urlConn = oracle.openConnection();
urlConn.addRequestProperty("User-Agent", "Mozilla/4.76");
InputStream is = urlConn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is, 4 * 1024);
BufferedReader in = new BufferedReader(new InputStreamReader(bis, StandardCharsets.UTF_8));

latestVersion = null;
String inputLine;
while ((inputLine = in.readLine()) != null && latestVersion == null)
Expand All @@ -76,7 +84,6 @@ private boolean getInfoFromServer() throws IOException {
if (latestVersion == null) {
throw new IOException("Could not find the version on the page.");
}

return latestVersion.equalsIgnoreCase(plugin.getDescription().getVersion());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void imaxStats(Player player) {
player.setLevel(0);
player.setExp(0);
player.setGameMode(GameMode.ADVENTURE);
player.setHealth(20);
player.setHealth(player.getMaxHealth());
player.setFoodLevel(20);
player.setSaturation(20);
for (PotionEffect effect : player.getActivePotionEffects())
Expand Down

0 comments on commit a177900

Please sign in to comment.