Compare commits
No commits in common. "b04735a0c51d1abbf8237812baed8b7a7f9bdd3a" and "00e66433ed6221b356321d67fb0c7d2073d7aa2d" have entirely different histories.
b04735a0c5
...
00e66433ed
3 changed files with 235 additions and 1 deletions
10
pom.xml
10
pom.xml
|
|
@ -95,6 +95,10 @@
|
||||||
</excludes>
|
</excludes>
|
||||||
</artifactSet>
|
</artifactSet>
|
||||||
<relocations>
|
<relocations>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.bstats</pattern>
|
||||||
|
<shadedPattern>net.coreprotect</shadedPattern>
|
||||||
|
</relocation>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>com.zaxxer</pattern>
|
<pattern>com.zaxxer</pattern>
|
||||||
<shadedPattern>net.coreprotect</shadedPattern>
|
<shadedPattern>net.coreprotect</shadedPattern>
|
||||||
|
|
@ -221,6 +225,12 @@
|
||||||
<version>1.21.1-R0.1-SNAPSHOT</version>
|
<version>1.21.1-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bstats</groupId>
|
||||||
|
<artifactId>bstats-bukkit</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fastasyncworldedit</groupId>
|
<groupId>com.fastasyncworldedit</groupId>
|
||||||
<artifactId>FastAsyncWorldEdit-Core</artifactId>
|
<artifactId>FastAsyncWorldEdit-Core</artifactId>
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package net.coreprotect.services;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.bstats.bukkit.Metrics;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
@ -72,6 +73,9 @@ public class PluginInitializationService {
|
||||||
|
|
||||||
// Start background services
|
// Start background services
|
||||||
startBackgroundServices(plugin);
|
startBackgroundServices(plugin);
|
||||||
|
|
||||||
|
// Start metrics
|
||||||
|
enableMetrics(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
return start;
|
return start;
|
||||||
|
|
@ -149,4 +153,19 @@ public class PluginInitializationService {
|
||||||
// Start consumer
|
// Start consumer
|
||||||
Consumer.startConsumer();
|
Consumer.startConsumer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables metrics reporting
|
||||||
|
*
|
||||||
|
* @param plugin
|
||||||
|
* The CoreProtect plugin instance
|
||||||
|
*/
|
||||||
|
private static void enableMetrics(JavaPlugin plugin) {
|
||||||
|
try {
|
||||||
|
new Metrics(plugin, 2876);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
// Failed to connect to bStats server or something else went wrong
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
@ -22,6 +23,7 @@ import java.util.Set;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
|
|
||||||
|
|
@ -41,6 +43,7 @@ public class NetworkHandler extends Language implements Runnable {
|
||||||
private boolean translate = true;
|
private boolean translate = true;
|
||||||
private static String latestVersion = null;
|
private static String latestVersion = null;
|
||||||
private static String latestEdgeVersion = null;
|
private static String latestEdgeVersion = null;
|
||||||
|
private static String donationKey = null;
|
||||||
|
|
||||||
public NetworkHandler(boolean startup, boolean background) {
|
public NetworkHandler(boolean startup, boolean background) {
|
||||||
this.startup = startup;
|
this.startup = startup;
|
||||||
|
|
@ -55,9 +58,86 @@ public class NetworkHandler extends Language implements Runnable {
|
||||||
return latestEdgeVersion;
|
return latestEdgeVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String donationKey() {
|
||||||
|
return donationKey;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
|
try {
|
||||||
|
boolean keyValidated = true;
|
||||||
|
String keyConfig = Config.getGlobal().DONATION_KEY.trim();
|
||||||
|
if (keyConfig.length() > 0) {
|
||||||
|
URL url = new URL("http://griefus.zhdev.org/license/" + keyConfig);
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
connection.setRequestMethod("GET");
|
||||||
|
connection.setRequestProperty("Accept-Charset", "UTF-8");
|
||||||
|
connection.setRequestProperty("User-Agent", "Griefus");
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
connection.setInstanceFollowRedirects(true);
|
||||||
|
connection.setConnectTimeout(5000);
|
||||||
|
connection.connect();
|
||||||
|
int status = connection.getResponseCode();
|
||||||
|
|
||||||
|
if (status == 200) {
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
|
String response = reader.readLine();
|
||||||
|
if (response != null && response.length() > 0) {
|
||||||
|
String[] remoteKey = response.replaceAll("[^a-zA-Z0-9;]", "").split(";");
|
||||||
|
if (remoteKey.length > 1 && remoteKey[1].equals("1") && remoteKey[0].length() == 8) {
|
||||||
|
donationKey = remoteKey[0];
|
||||||
|
}
|
||||||
|
else if (remoteKey.length > 1) {
|
||||||
|
donationKey = null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
keyValidated = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
keyValidated = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
donationKey = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Path licensePath = Paths.get(ConfigHandler.path + ".license");
|
||||||
|
if (keyValidated && donationKey == null) {
|
||||||
|
if (keyConfig.length() > 0) {
|
||||||
|
Chat.console(Phrase.build(Phrase.INVALID_DONATION_KEY) + " " + Phrase.build(Phrase.CHECK_CONFIG) + ".");
|
||||||
|
}
|
||||||
|
Files.write(licensePath, "".getBytes());
|
||||||
|
}
|
||||||
|
else if (keyValidated) {
|
||||||
|
Files.write(licensePath, donationKey.getBytes());
|
||||||
|
}
|
||||||
|
else if (Files.isReadable(licensePath)) {
|
||||||
|
List<String> licenseFile = Files.readAllLines(licensePath);
|
||||||
|
if (licenseFile.size() == 1) {
|
||||||
|
donationKey = licenseFile.get(0);
|
||||||
|
if (donationKey == null || donationKey.length() != 8 || !donationKey.matches("^[A-Z0-9]+$")) {
|
||||||
|
donationKey = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
// Unable to connect to griefus.zhdev.org
|
||||||
|
}
|
||||||
|
|
||||||
|
if (donationKey != null) {
|
||||||
|
// valid donation key, continue initialization
|
||||||
|
}
|
||||||
|
|
||||||
if (translate) {
|
if (translate) {
|
||||||
try {
|
try {
|
||||||
String lang = Config.getGlobal().LANGUAGE;
|
String lang = Config.getGlobal().LANGUAGE;
|
||||||
|
|
@ -75,7 +155,7 @@ public class NetworkHandler extends Language implements Runnable {
|
||||||
Optional<String> languageHeader = stream.findFirst();
|
Optional<String> languageHeader = stream.findFirst();
|
||||||
if (languageHeader.isPresent()) {
|
if (languageHeader.isPresent()) {
|
||||||
String headerString = languageHeader.get();
|
String headerString = languageHeader.get();
|
||||||
if (headerString.startsWith("# Griefus")) { // verify that valid cache file
|
if (headerString.startsWith("# CoreProtect")) { // verify that valid cache file
|
||||||
String[] split = headerString.split(" ");
|
String[] split = headerString.split(" ");
|
||||||
if (split.length == 6 && split[2].length() > 2 && split[5].length() > 2) {
|
if (split.length == 6 && split[2].length() > 2 && split[5].length() > 2) {
|
||||||
String cacheVersion = split[2].substring(1);
|
String cacheVersion = split[2].substring(1);
|
||||||
|
|
@ -204,6 +284,131 @@ public class NetworkHandler extends Language implements Runnable {
|
||||||
if (startup) {
|
if (startup) {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (ConfigHandler.serverRunning) {
|
||||||
|
int status = 0;
|
||||||
|
int statusEdge = 0;
|
||||||
|
HttpURLConnection connection = null;
|
||||||
|
HttpURLConnection connectionEdge = null;
|
||||||
|
String version = VersionUtils.getPluginVersion();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// CoreProtect Community Edition
|
||||||
|
URL url = new URL("http://update.griefus.zhdev.org/version/");
|
||||||
|
connection = (HttpURLConnection) url.openConnection();
|
||||||
|
connection.setRequestMethod("GET");
|
||||||
|
connection.setRequestProperty("Accept-Charset", "UTF-8");
|
||||||
|
connection.setRequestProperty("User-Agent", "Griefus/v" + version + " (by Intelli)");
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
connection.setInstanceFollowRedirects(true);
|
||||||
|
connection.setConnectTimeout(5000);
|
||||||
|
connection.connect();
|
||||||
|
status = connection.getResponseCode();
|
||||||
|
|
||||||
|
// CoreProtect Edge
|
||||||
|
url = new URL("http://update.griefus.zhdev.org/version-edge/");
|
||||||
|
connectionEdge = (HttpURLConnection) url.openConnection();
|
||||||
|
connectionEdge.setRequestMethod("GET");
|
||||||
|
connectionEdge.setRequestProperty("Accept-Charset", "UTF-8");
|
||||||
|
connectionEdge.setRequestProperty("User-Agent", "Griefus/v" + version + " (by Intelli)");
|
||||||
|
connectionEdge.setDoOutput(true);
|
||||||
|
connectionEdge.setInstanceFollowRedirects(true);
|
||||||
|
connectionEdge.setConnectTimeout(5000);
|
||||||
|
connectionEdge.connect();
|
||||||
|
statusEdge = connectionEdge.getResponseCode();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
// Unable to connect to update.griefus.zhdev.org
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status == 200) {
|
||||||
|
try {
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
|
String response = reader.readLine();
|
||||||
|
|
||||||
|
if (response.length() > 0 && response.length() < 10) {
|
||||||
|
String remoteVersion = response.replaceAll("[^0-9.]", "");
|
||||||
|
if (remoteVersion.contains(".")) {
|
||||||
|
boolean newVersion = VersionUtils.newVersion(version, remoteVersion);
|
||||||
|
if (newVersion) {
|
||||||
|
latestVersion = remoteVersion;
|
||||||
|
if (startup) {
|
||||||
|
Chat.console("--------------------");
|
||||||
|
Chat.console(Phrase.build(Phrase.VERSION_NOTICE, remoteVersion));
|
||||||
|
Chat.console(Phrase.build(Phrase.LINK_DOWNLOAD, "www.griefus.zhdev.org/download/"));
|
||||||
|
Chat.console("--------------------");
|
||||||
|
startup = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
latestVersion = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (statusEdge == 200) {
|
||||||
|
try {
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(connectionEdge.getInputStream()));
|
||||||
|
String response = reader.readLine();
|
||||||
|
|
||||||
|
if (response.length() > 0 && response.length() < 10) {
|
||||||
|
String remoteVersion = response.replaceAll("[^0-9.]", "");
|
||||||
|
if (remoteVersion.contains(".")) {
|
||||||
|
boolean newVersion = VersionUtils.newVersion(version, remoteVersion);
|
||||||
|
if (newVersion) {
|
||||||
|
latestEdgeVersion = remoteVersion;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
latestEdgeVersion = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
/* Stat gathering */
|
||||||
|
int port = Bukkit.getServer().getPort();
|
||||||
|
String stats = port + ":" + (donationKey != null ? donationKey : "") + ":" + version + ConfigHandler.EDITION_BRANCH;
|
||||||
|
URL url = new URL("http://stats.griefus.zhdev.org/u/?data=" + stats);
|
||||||
|
connection = (HttpURLConnection) url.openConnection();
|
||||||
|
connection.setRequestMethod("GET");
|
||||||
|
connection.setRequestProperty("Accept-Charset", "UTF-8");
|
||||||
|
connection.setRequestProperty("User-Agent", "Griefus");
|
||||||
|
connection.setConnectTimeout(5000);
|
||||||
|
connection.connect();
|
||||||
|
connection.getResponseCode();
|
||||||
|
connection.disconnect();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
// Unable to connect to stats.griefus.zhdev.org
|
||||||
|
}
|
||||||
|
|
||||||
|
if (background) {
|
||||||
|
long time = System.currentTimeMillis();
|
||||||
|
long sleepTime = time + 3600000; // 1 hour
|
||||||
|
|
||||||
|
while (ConfigHandler.serverRunning && (time < sleepTime)) {
|
||||||
|
time = System.currentTimeMillis();
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
Chat.console(Phrase.build(Phrase.UPDATE_ERROR));
|
Chat.console(Phrase.build(Phrase.UPDATE_ERROR));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue