Merge pull request #135 from Parabot/feature/issue-134

[FEATURE] Added nightly support for randoms
This commit is contained in:
Jeroen Ketelaar
2016-10-23 02:01:38 +02:00
committed by GitHub
5 changed files with 14 additions and 15 deletions
+1 -1
View File
@@ -73,7 +73,7 @@
<dependency>
<groupId>org.parabot</groupId>
<artifactId>internal-api</artifactId>
<version>1.4.4</version>
<version>1.4.41</version>
</dependency>
</dependencies>
+2 -3
View File
@@ -33,6 +33,8 @@ public final class Landing {
parseArgs(args);
Directories.validate();
Core.verbose(TranslationHelper.translate("DEBUG_MODE") + Core.inDebugMode());
try {
@@ -48,9 +50,6 @@ public final class Landing {
return;
}
Core.verbose(TranslationHelper.translate("VALIDATING_DIRECTORIES"));
Directories.validate();
Core.verbose(TranslationHelper.translate("VALIDATION_ACCOUNT_MANAGER"));
AccountManager.validate();
@@ -12,7 +12,7 @@ public class Configuration extends org.parabot.api.Configuration {
public static final String GET_SCRIPTS = "http://bdn.parabot.org/api/get.php?action=scripts_scripts&server=";
public static final String GET_SCRIPT = "http://bdn.parabot.org/api/get.php?action=scripts_script&id=";
public static final String GET_SERVER_PROVIDERS = "http://bdn.parabot.org/api/get.php?action=server_providers";
public static final String GET_SERVER_PROVIDER = "http://bdn.parabot.org/api/get.php?action=server_provider&name=";
public static final String GET_SERVER_PROVIDER = "http://v3.bdn.parabot.org/api/bot/download/provider?nightly=%s";
public static final String GET_SERVER_PROVIDER_INFO = "http://bdn.parabot.org/api/get.php?action=server_information&name=";
public static final String GET_SERVER_SETTINGS = "http://bdn.parabot.org/api/get.php?action=get_settings";
public static final String GET_BOT_VERSION = "http://bdn.parabot.org/api/v2/bot/version";
@@ -24,6 +24,4 @@ public class Configuration extends org.parabot.api.Configuration {
public static final String ITEM_API = DATA_API + "items/";
public static final Version BOT_VERSION = ProjectProperties.getProjectVersion();
public static final String NIGHTLY_APPEND = "?nightly=true";
}
@@ -1,12 +1,11 @@
package org.parabot.core.parsers.randoms;
import org.parabot.api.io.WebUtil;
import org.parabot.core.Configuration;
import org.parabot.core.Context;
import org.parabot.core.Core;
import org.parabot.core.Directories;
import org.parabot.core.io.NoProgressListener;
import org.parabot.core.io.ProgressListener;
import org.parabot.environment.api.utils.WebUtil;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
@@ -20,9 +19,11 @@ import java.net.URLClassLoader;
*/
public class PublicRandoms extends RandomParser {
private String fileName = ((Configuration.BOT_VERSION.isNightly()) ? "randoms-nightly.jar" : "randoms.jar");
@Override
public void parse() {
File myJar = new File(Directories.getCachePath() + "/randoms.jar");
File myJar = new File(Directories.getCachePath() + File.separator + fileName);
if (!myJar.exists() || !myJar.canRead()) {
download();
}
@@ -46,12 +47,14 @@ public class PublicRandoms extends RandomParser {
private void download() {
try {
File random = new File(Directories.getCachePath() + "/randoms.jar");
File random = new File(Directories.getCachePath() + File.separator + fileName);
if (random.exists()) {
Core.verbose("Public random dependency already exists, no need to download it...");
return;
}
String downloadLink = Configuration.GET_RANDOMS;
String downloadLink = ((Configuration.BOT_VERSION.isNightly()) ? Configuration.GET_RANDOMS + Configuration.NIGHTLY_APPEND : Configuration.GET_RANDOMS);
WebUtil.downloadFile(new URL(downloadLink), random, new NoProgressListener());
} catch (Exception e) {
e.printStackTrace();
@@ -54,8 +54,7 @@ public class PublicServerExecuter extends ServerExecuter {
final File destination = new File(Directories.getCachePath(),
serverProviderInfo.getCRC32() + ".jar");
final String jarUrl = Configuration.GET_SERVER_PROVIDER
+ this.serverName;
final String jarUrl = String.format(Configuration.GET_SERVER_PROVIDER, Configuration.BOT_VERSION.isNightly());
Core.verbose("Downloading: " + jarUrl + " ...");
@@ -63,7 +62,7 @@ public class PublicServerExecuter extends ServerExecuter {
Core.verbose("Found cached server provider [CRC32: " + serverProviderInfo.getCRC32() + "]");
} else {
WebUtil.downloadFile(new URL(jarUrl), destination,
VerboseLoader.get(), manager.getAccount().getURLUsername(), manager.getAccount().getURLPassword());
VerboseLoader.get());
Core.verbose("Server provider downloaded...");
}