diff --git a/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/pom.xml b/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/pom.xml index 2c02322e7..52ebd07c0 100644 --- a/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/pom.xml +++ b/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/pom.xml @@ -24,15 +24,5 @@ zt-zip 1.9 - - org.apache.httpcomponents - httpclient - 4.5.2 - - - org.slf4j - slf4j-simple - 1.7.21 - diff --git a/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/src/nautilus/game/arcade/uhc/WorldGen.java b/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/src/nautilus/game/arcade/uhc/WorldGen.java index 812b1f45a..24d2483e7 100644 --- a/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/src/nautilus/game/arcade/uhc/WorldGen.java +++ b/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/src/nautilus/game/arcade/uhc/WorldGen.java @@ -1,27 +1,21 @@ package nautilus.game.arcade.uhc; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ThreadLocalRandom; -import java.util.concurrent.TimeUnit; import java.util.logging.Level; import net.minecraft.server.v1_8_R3.BiomeBase; import org.apache.commons.io.FileUtils; -import org.apache.http.HttpResponse; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.message.BasicHeader; -import org.apache.http.protocol.HTTP; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Difficulty; @@ -42,14 +36,10 @@ import org.zeroturnaround.zip.ByteSource; import org.zeroturnaround.zip.FileSource; import org.zeroturnaround.zip.ZipEntrySource; import org.zeroturnaround.zip.ZipUtil; - -import com.google.gson.Gson; -import com.google.gson.JsonObject; +import org.zeroturnaround.zip.commons.IOUtils; public class WorldGen extends JavaPlugin implements Listener { - private static final int TIMEOUT = (int) TimeUnit.SECONDS.toMillis(10); - // The world will be -MAP_SIZE to MAP_SIZE large private static final int MAP_SIZE = 1000; private static final int VIEW_DISTANCE = 5; @@ -295,32 +285,20 @@ public class WorldGen extends JavaPlugin implements Listener FileUtils.deleteQuietly(worldFolder); - RequestConfig config = RequestConfig.custom() - .setConnectTimeout(TIMEOUT) - .setSocketTimeout(TIMEOUT) - .build(); - - CloseableHttpClient httpClient = HttpClientBuilder.create() - .setDefaultRequestConfig(config) - .build(); - - HttpPost request = new HttpPost("http://" + API_HOST_MAP.get("ENDERCHEST") + "/map/uhc/upload"); - request.addHeader(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); - - JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty("name", outputFile.getName()); - jsonObject.addProperty("location", outputFile.toURI().toString()); - - request.setEntity(new StringEntity(new Gson().toJson(jsonObject), StandardCharsets.UTF_8)); - try { getLogger().info("Uploading " + seed + "!"); - HttpResponse response = httpClient.execute(request); - if (response.getStatusLine().getStatusCode() != 200) + URL url = new URL("http://" + API_HOST_MAP.get("ENDERCHEST") + "/map/uhc/upload?name=" + outputFile.getName()); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("POST"); + connection.setDoOutput(true); + IOUtils.copy(new FileInputStream(outputFile), connection.getOutputStream()); + connection.connect(); + + if (connection.getResponseCode() != 200) { - if (response.getStatusLine().getStatusCode() == 409) + if (connection.getResponseCode() == 409) { getLogger().warning("Oops - Server rejected " + seed + " because it was already generated"); @@ -331,7 +309,7 @@ public class WorldGen extends JavaPlugin implements Listener } else { - getLogger().severe("Failed to upload " + seed + ": " + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase()); + getLogger().severe("Failed to upload " + seed + ": " + connection.getResponseCode() + " " + connection.getResponseMessage()); } } else