From 2f9bb0f022643a52e4234dec49022190c33bfcdd Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Wed, 5 Aug 2020 20:08:28 +0800
Subject: [PATCH 1/3] Poi
Former-commit-id: 4514a67ef8ba14dfbc3967cefc35f71e161bd4a7
---
.../maxgamer/quickshop/economy/EconomyTransaction.java | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/main/java/org/maxgamer/quickshop/economy/EconomyTransaction.java b/src/main/java/org/maxgamer/quickshop/economy/EconomyTransaction.java
index 1d550446f..b954a41ab 100644
--- a/src/main/java/org/maxgamer/quickshop/economy/EconomyTransaction.java
+++ b/src/main/java/org/maxgamer/quickshop/economy/EconomyTransaction.java
@@ -135,6 +135,7 @@ public class EconomyTransaction {
steps = TransactionSteps.TAX;
if (tax > 0 && taxAccount != null && !core.deposit(taxAccount, tax)) {
this.lastError = "Failed to deposit tax account: " + tax;
+ callback.onTaxFailed(this);
//Tax never should failed.
}
steps = TransactionSteps.DONE;
@@ -155,6 +156,9 @@ public class EconomyTransaction {
if (steps == TransactionSteps.CHECK) {
return rollbackSteps; //We did nothing, just checks balance
}
+ if (steps == TransactionSteps.WITHDRAW) {
+ return rollbackSteps; //We did nothing, because the trade failed so no anybody money changes.
+ }
if (steps == TransactionSteps.DEPOSIT || steps == TransactionSteps.TAX) {
if (from != null && !core.deposit(from, amount)) { //Rollback withdraw
if (!continueWhenFailed) {
@@ -201,6 +205,10 @@ public class EconomyTransaction {
Util.debugLog("Transaction failed: " + economyTransaction.getLastError() + ".");
}
+ default void onTaxFailed(@NotNull EconomyTransaction economyTransaction) {
+ Util.debugLog("Tax Transaction failed: " + economyTransaction.getLastError() + ".");
+ }
+
}
}
From ce3318fa38f3fb0576c30e36f134cac4a571160b Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Wed, 5 Aug 2020 20:10:13 +0800
Subject: [PATCH 2/3] 4.0.4.5
Former-commit-id: 948441f27f9f6b8c37a04e15e2a16d4718c75d15
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index e0306afe1..85118da31 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
org.maxgamer
QuickShop
- 4.0.4.4
+ 4.0.4.5
From 151f31be4168a1ee506e759c5841fd00436dbed9 Mon Sep 17 00:00:00 2001
From: Ghost_chu <2908803755@qq.com>
Date: Wed, 5 Aug 2020 20:34:51 +0800
Subject: [PATCH 3/3] Improve the updater
Former-commit-id: 6c308a8b40d808ad6e865d2d794564281f7a1573
---
.../org/maxgamer/quickshop/BuildInfo.java | 5 +-
.../org/maxgamer/quickshop/QuickShop.java | 2 +-
.../quickshop/util/updater/NewUpdater.java | 5 -
.../quickshop/util/updater/QuickUpdater.java | 15 +++
.../quickshop/util/updater/VersionType.java | 7 ++
.../util/updater/impl/JenkinsUpdater.java | 97 +++++++++++++++++++
6 files changed, 122 insertions(+), 9 deletions(-)
delete mode 100644 src/main/java/org/maxgamer/quickshop/util/updater/NewUpdater.java
create mode 100644 src/main/java/org/maxgamer/quickshop/util/updater/QuickUpdater.java
create mode 100644 src/main/java/org/maxgamer/quickshop/util/updater/VersionType.java
create mode 100644 src/main/java/org/maxgamer/quickshop/util/updater/impl/JenkinsUpdater.java
diff --git a/src/main/java/org/maxgamer/quickshop/BuildInfo.java b/src/main/java/org/maxgamer/quickshop/BuildInfo.java
index 4183659b8..c4e226092 100644
--- a/src/main/java/org/maxgamer/quickshop/BuildInfo.java
+++ b/src/main/java/org/maxgamer/quickshop/BuildInfo.java
@@ -2,7 +2,7 @@ package org.maxgamer.quickshop;
import lombok.Getter;
import org.bukkit.configuration.file.YamlConfiguration;
-import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.InputStream;
@@ -18,8 +18,7 @@ public class BuildInfo {
private final String pomGruopId;
private final String pomArtifactId;
- public BuildInfo(@NotNull QuickShop plugin) {
- InputStream inputStream = plugin.getResource("BUILDINFO");
+ public BuildInfo(@Nullable InputStream inputStream) {
if (inputStream == null) {
buildId = "Unknown";
buildTag = "Unknown";
diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java
index 6626d4386..63b5a8f61 100644
--- a/src/main/java/org/maxgamer/quickshop/QuickShop.java
+++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java
@@ -505,7 +505,7 @@ public class QuickShop extends JavaPlugin {
getLogger().info("QuickShop Reremake - Early boot step - Booting up...");
//BEWARE THESE ONLY RUN ONCE
instance = this;
- this.buildInfo = new BuildInfo(this);
+ this.buildInfo = new BuildInfo(getResource("BUILDINFO"));
QuickShopAPI.setupApi(this);
//noinspection ResultOfMethodCallIgnored
getDataFolder().mkdirs();
diff --git a/src/main/java/org/maxgamer/quickshop/util/updater/NewUpdater.java b/src/main/java/org/maxgamer/quickshop/util/updater/NewUpdater.java
deleted file mode 100644
index a1657af76..000000000
--- a/src/main/java/org/maxgamer/quickshop/util/updater/NewUpdater.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package org.maxgamer.quickshop.util.updater;
-
-public class NewUpdater {
-
-}
diff --git a/src/main/java/org/maxgamer/quickshop/util/updater/QuickUpdater.java b/src/main/java/org/maxgamer/quickshop/util/updater/QuickUpdater.java
new file mode 100644
index 000000000..04c5ab792
--- /dev/null
+++ b/src/main/java/org/maxgamer/quickshop/util/updater/QuickUpdater.java
@@ -0,0 +1,15 @@
+package org.maxgamer.quickshop.util.updater;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.io.IOException;
+
+public interface QuickUpdater {
+ @NotNull VersionType getCurrentRunning();
+
+ boolean isLatest(@NotNull VersionType versionType) throws IOException;
+
+ @NotNull byte[] update(@NotNull VersionType versionType) throws IOException;
+
+ void install(byte[] bytes) throws IOException;
+}
diff --git a/src/main/java/org/maxgamer/quickshop/util/updater/VersionType.java b/src/main/java/org/maxgamer/quickshop/util/updater/VersionType.java
new file mode 100644
index 000000000..cc22c8cb8
--- /dev/null
+++ b/src/main/java/org/maxgamer/quickshop/util/updater/VersionType.java
@@ -0,0 +1,7 @@
+package org.maxgamer.quickshop.util.updater;
+
+public enum VersionType {
+ STABLE,
+ SNAPSHOT,
+ LTS
+}
diff --git a/src/main/java/org/maxgamer/quickshop/util/updater/impl/JenkinsUpdater.java b/src/main/java/org/maxgamer/quickshop/util/updater/impl/JenkinsUpdater.java
new file mode 100644
index 000000000..45699cc89
--- /dev/null
+++ b/src/main/java/org/maxgamer/quickshop/util/updater/impl/JenkinsUpdater.java
@@ -0,0 +1,97 @@
+package org.maxgamer.quickshop.util.updater.impl;
+
+import lombok.AllArgsConstructor;
+import org.bukkit.plugin.InvalidDescriptionException;
+import org.bukkit.plugin.PluginDescriptionFile;
+import org.jetbrains.annotations.NotNull;
+import org.maxgamer.quickshop.BuildInfo;
+import org.maxgamer.quickshop.QuickShop;
+import org.maxgamer.quickshop.nonquickshopstuff.com.sk89q.worldedit.util.net.HttpRequest;
+import org.maxgamer.quickshop.util.Util;
+import org.maxgamer.quickshop.util.updater.QuickUpdater;
+import org.maxgamer.quickshop.util.updater.VersionType;
+
+import java.io.*;
+import java.net.URL;
+
+@AllArgsConstructor
+public class JenkinsUpdater implements QuickUpdater {
+ private final BuildInfo pluginBuildInfo;
+
+ @Override
+ public @NotNull VersionType getCurrentRunning() {
+ return VersionType.STABLE; //TODO LTS
+ }
+
+ @Override
+ public boolean isLatest(@NotNull VersionType versionType) throws IOException {
+ InputStream inputStream = HttpRequest.get(new URL("https://ci.codemc.io/job/Ghost-chu/job/QuickShop-Reremake/lastSuccessfulBuild/artifact/target/BUILDINFO"))
+ .header("User-Agent", "QuickShop-" + QuickShop.getFork() + " " + QuickShop.getVersion())
+ .execute()
+ .expectResponseCode(200)
+ .getInputStream();
+ BuildInfo buildInfo = new BuildInfo(inputStream);
+ return buildInfo.getBuildId().equalsIgnoreCase(pluginBuildInfo.getBuildId()) || buildInfo.getGitCommit().equalsIgnoreCase(pluginBuildInfo.getGitCommit());
+ }
+
+ @Override
+ public byte[] update(@NotNull VersionType versionType) throws IOException {
+ InputStream is = HttpRequest.get(new URL("https://ci.codemc.io/job/Ghost-chu/job/QuickShop-Reremake/lastSuccessfulBuild/artifact/target/QuickShop.jar"))
+ .header("User-Agent", "QuickShop-" + QuickShop.getFork() + " " + QuickShop.getVersion())
+ .execute()
+ .getInputStream();
+ try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
+ byte[] buff = new byte[1024];
+ int len;
+ long downloaded = 0;
+ if (is == null) {
+ throw new IOException("Failed downloading: Cannot open connection with remote server.");
+ }
+ while ((len = is.read(buff)) != -1) {
+ os.write(buff, 0, len);
+ downloaded += len;
+ Util.debugLog("File Downloader: " + downloaded + " bytes.");
+ }
+ is.close();
+ byte[] file = os.toByteArray();
+ os.close();
+ return file;
+ }
+ }
+
+ @Override
+ public void install(byte[] bytes) throws IOException {
+ File pluginFolder = new File("plugins");
+ if (!pluginFolder.exists()) {
+ throw new RuntimeException("Can't find the plugins folder.");
+ }
+ if (!pluginFolder.isDirectory()) {
+ throw new RuntimeException("Plugins not a folder.");
+ }
+ File[] plugins = pluginFolder.listFiles();
+ if (plugins == null) {
+ throw new IOException("Can't get the files in plugins folder");
+ }
+ File quickshop = null;
+ for (File plugin : plugins) {
+ try {
+ PluginDescriptionFile desc = QuickShop.getInstance().getPluginLoader().getPluginDescription(plugin);
+ if (!desc.getName().equals(QuickShop.getInstance().getDescription().getName())) {
+ continue;
+ }
+ Util.debugLog("Selected: " + plugin.getPath());
+ quickshop = plugin;
+ break;
+ } catch (InvalidDescriptionException e) { // Ignore }
+ }
+ }
+ if (quickshop == null) {
+ throw new IOException("Failed to get QuickShop Jar File.");
+ }
+
+ OutputStream outputStream = new FileOutputStream(quickshop, false);
+ outputStream.write(bytes);
+ outputStream.flush();
+ outputStream.close();
+ }
+}