Merge remote-tracking branch 'origin/master'

Former-commit-id: 551a5123048f121bd8ac961f301dcfea6d743603
This commit is contained in:
sandtechnology committed 2020-08-06 12:25:09 +08:00
commit f818c5b21e
8 files changed
+131 -10

No files matched your search

@@ -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";
@@ -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();
@@ -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() + ".");
}
}
}
@@ -1,5 +0,0 @@
package org.maxgamer.quickshop.util.updater;
public class NewUpdater {
}
@@ -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;
}
@@ -0,0 +1,7 @@
package org.maxgamer.quickshop.util.updater;
public enum VersionType {
STABLE,
SNAPSHOT,
LTS
}
@@ -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();
}
}