Added an Update Checker, closes #559

This commit is contained in:
TfT_02 2013-02-18 22:54:47 +01:00
parent d9aad67ca5
commit cf0f075acb
8 changed files with 96 additions and 0 deletions

View File

@ -9,6 +9,7 @@ Key:
Version 1.4.00-dev Version 1.4.00-dev
+ Added new Child Skill - Smelting! + Added new Child Skill - Smelting!
+ Added a version check, admins will get notified when a new version is available!
+ Added new cancellable McMMOPlayerDisarmEvent for Citizens compatibility - fires whenever a player is disarmed. + Added new cancellable McMMOPlayerDisarmEvent for Citizens compatibility - fires whenever a player is disarmed.
+ Added config options for Hylian Luck skill + Added config options for Hylian Luck skill
+ Added display values to Unarmed command for Iron Grip + Added display values to Unarmed command for Iron Grip

View File

@ -35,6 +35,8 @@ public class Config extends ConfigLoader {
public boolean getDonateMessageEnabled() { return config.getBoolean("Commands.mcmmo.Donate_Message", true); } public boolean getDonateMessageEnabled() { return config.getBoolean("Commands.mcmmo.Donate_Message", true); }
public int getSaveInterval() { return config.getInt("General.Save_Interval", 10); } public int getSaveInterval() { return config.getInt("General.Save_Interval", 10); }
public boolean getStatsTrackingEnabled() { return config.getBoolean("General.Stats_Tracking", true); } public boolean getStatsTrackingEnabled() { return config.getBoolean("General.Stats_Tracking", true); }
public boolean getUpdateCheckEnabled() { return config.getBoolean("General.Update_Check", true); }
public boolean getPreferBeta() { return config.getBoolean("General.Prefer_Beta", false); }
public boolean getEventCallbackEnabled() { return config.getBoolean("General.Event_Callback", true); } public boolean getEventCallbackEnabled() { return config.getBoolean("General.Event_Callback", true); }
public boolean getBackupsEnabled() { return config.getBoolean("General.Generate_Backups", true); } public boolean getBackupsEnabled() { return config.getBoolean("General.Generate_Backups", true); }
public boolean getPartyDisplayNames() { return config.getBoolean("Commands.p.Use_Display_Names", true); } public boolean getPartyDisplayNames() { return config.getBoolean("Commands.p.Use_Display_Names", true); }

View File

@ -236,6 +236,11 @@ public class PlayerListener implements Listener {
if (plugin.isXPEventEnabled()) { if (plugin.isXPEventEnabled()) {
player.sendMessage(LocaleLoader.getString("XPRate.Event", Config.getInstance().getExperienceGainsGlobalMultiplier())); player.sendMessage(LocaleLoader.getString("XPRate.Event", Config.getInstance().getExperienceGainsGlobalMultiplier()));
} }
if (player.hasPermission("mcmmo.tools.updatecheck") && mcMMO.p.updateAvailable) {
player.sendMessage(LocaleLoader.getString("UpdateChecker.outdated"));
player.sendMessage(LocaleLoader.getString("UpdateChecker.newavailable"));
}
} }
/** /**

View File

@ -32,6 +32,7 @@ import com.gmail.nossr50.listeners.EntityListener;
import com.gmail.nossr50.listeners.InventoryListener; import com.gmail.nossr50.listeners.InventoryListener;
import com.gmail.nossr50.listeners.PlayerListener; import com.gmail.nossr50.listeners.PlayerListener;
import com.gmail.nossr50.listeners.WorldListener; import com.gmail.nossr50.listeners.WorldListener;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mods.config.CustomArmorConfig; import com.gmail.nossr50.mods.config.CustomArmorConfig;
import com.gmail.nossr50.mods.config.CustomBlocksConfig; import com.gmail.nossr50.mods.config.CustomBlocksConfig;
import com.gmail.nossr50.mods.config.CustomEntityConfig; import com.gmail.nossr50.mods.config.CustomEntityConfig;
@ -49,6 +50,7 @@ import com.gmail.nossr50.skills.runnables.BleedTimer;
import com.gmail.nossr50.skills.runnables.SkillMonitor; import com.gmail.nossr50.skills.runnables.SkillMonitor;
import com.gmail.nossr50.spout.SpoutConfig; import com.gmail.nossr50.spout.SpoutConfig;
import com.gmail.nossr50.spout.SpoutTools; import com.gmail.nossr50.spout.SpoutTools;
import com.gmail.nossr50.util.UpdateCheck;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
public class mcMMO extends JavaPlugin { public class mcMMO extends JavaPlugin {
@ -75,6 +77,9 @@ public class mcMMO extends JavaPlugin {
private static String usersFile; private static String usersFile;
private static String modDirectory; private static String modDirectory;
// Update Check
public boolean updateAvailable;
// Spout Check // Spout Check
public static boolean spoutEnabled = false; public static boolean spoutEnabled = false;
@ -121,6 +126,16 @@ public class mcMMO extends JavaPlugin {
placeStore = ChunkManagerFactory.getChunkManager(); // Get our ChunkletManager placeStore = ChunkManagerFactory.getChunkManager(); // Get our ChunkletManager
new MobStoreCleaner(); // Automatically starts and stores itself new MobStoreCleaner(); // Automatically starts and stores itself
try {
updateAvailable = Config.getInstance().getUpdateCheckEnabled() && UpdateCheck.updateAvailable();
} catch (Exception e) {
updateAvailable = false;
}
if (updateAvailable) {
getLogger().info(LocaleLoader.getString("UpdateChecker.outdated"));
getLogger().info(LocaleLoader.getString("UpdateChecker.newavailable"));
}
} }
/** /**

View File

@ -0,0 +1,62 @@
package com.gmail.nossr50.util;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.UnknownHostException;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
public class UpdateCheck {
private UpdateCheck() {}
public static boolean updateAvailable() throws Exception {
String checkType = "release";
if (Config.getInstance().getPreferBeta()) {
checkType = "latest";
}
String version = mcMMO.p.getDescription().getVersion();
URL url = new URL("http://api.bukget.org/api2/bukkit/plugin/mcmmo/"+checkType);
InputStreamReader isr;
try {
isr = new InputStreamReader(url.openStream());
} catch (UnknownHostException e) {
return false;
}
String newVersion;
try {
JSONParser jp = new JSONParser();
Object o = jp.parse(isr);
if (!(o instanceof JSONObject)) {
isr.close();
return false;
}
JSONObject jo = (JSONObject) o;
jo = (JSONObject) jo.get("versions");
newVersion = (String) jo.get("version");
String[] oldTokens = version.replaceAll("(?i)(-)(.+?)(-)", "").split("[.]|[b]");
String[] newTokens = newVersion.replaceAll("(?i)(-)(.+?)(-)", "").split("[.]|[b]");
for (int i = 0; i < 4; i++) {
Integer newVer = Integer.parseInt(newTokens[i]);
Integer oldVer = Integer.parseInt(oldTokens[i]);
if (oldVer < newVer) {
isr.close();
return true;
}
}
return false;
} catch (ParseException e) {
isr.close();
return false;
}
}
}

View File

@ -14,6 +14,9 @@ General:
Save_Interval: 10 Save_Interval: 10
#Allow mcMMO to report on basic anonymous usage #Allow mcMMO to report on basic anonymous usage
Stats_Tracking: true Stats_Tracking: true
#Allow mcMMO to check if a new version is available
Update_Check: true
Prefer_Beta: false
#Allow mcMMO to inform other plugins of damage being dealt #Allow mcMMO to inform other plugins of damage being dealt
Event_Callback: true Event_Callback: true
#Allow mcMMO to create zip backups for flatfile data on shutdown. #Allow mcMMO to create zip backups for flatfile data on shutdown.

View File

@ -725,3 +725,7 @@ Commands.Description.skillreset=Reset mcMMO levels for a user
Commands.Description.vampirism=Modify the mcMMO vampirism percentage or toggle vampirism mode on/off Commands.Description.vampirism=Modify the mcMMO vampirism percentage or toggle vampirism mode on/off
Commands.Description.xplock=Lock your mcMMO XP bar to a specific mcMMO skill Commands.Description.xplock=Lock your mcMMO XP bar to a specific mcMMO skill
Commands.Description.xprate=Modify the mcMMO XP rate or start an mcMMO XP event Commands.Description.xprate=Modify the mcMMO XP rate or start an mcMMO XP event
#UPDATE CHECKER
UpdateChecker.outdated=You are using an outdated version of mcMMO!
UpdateChecker.newavailable=There is a new version available on BukkitDev.

View File

@ -1369,6 +1369,7 @@ permissions:
mcmmo.tools.mcrefresh: true mcmmo.tools.mcrefresh: true
mcmmo.tools.mcremove: true mcmmo.tools.mcremove: true
mcmmo.tools.mmoedit: true mcmmo.tools.mmoedit: true
mcmmo.tools.updatecheck: true
mcmmo.tools.mcgod: mcmmo.tools.mcgod:
default: false default: false
description: Allows access to mcgod command description: Allows access to mcgod command
@ -1396,3 +1397,6 @@ permissions:
mcmmo.commands.mcpurge: true mcmmo.commands.mcpurge: true
mcmmo.commands.mmoedit: true mcmmo.commands.mmoedit: true
mcmmo.commands.mmoedit.others: true mcmmo.commands.mmoedit.others: true
mcmmo.tools.updatecheck:
default: false
description: Notifies admins if there is a new version of mcMMO available