Cleanup
This commit is contained in:
parent
dedcd254b0
commit
f8dbbce106
@ -19,16 +19,16 @@
|
||||
<version>1.8.8-1.9-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mineplex</groupId>
|
||||
<artifactId>mineplex-core</artifactId>
|
||||
<version>dev-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.zeroturnaround</groupId>
|
||||
<artifactId>zt-zip</artifactId>
|
||||
<version>1.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
|
@ -7,7 +7,9 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
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;
|
||||
@ -28,20 +30,16 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Difficulty;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.spigotmc.WatchdogThread;
|
||||
import org.zeroturnaround.zip.ZipEntrySource;
|
||||
import org.zeroturnaround.zip.ZipUtil;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import mineplex.core.common.Constants;
|
||||
import mineplex.core.common.api.ApiHost;
|
||||
|
||||
public class WorldGen extends JavaPlugin implements Runnable, Listener
|
||||
public class WorldGen extends JavaPlugin
|
||||
{
|
||||
private static final int TIMEOUT = (int) TimeUnit.SECONDS.toMillis(10);
|
||||
|
||||
@ -51,6 +49,35 @@ public class WorldGen extends JavaPlugin implements Runnable, Listener
|
||||
private static final int MAX_Z = 1000;
|
||||
private static final int VIEW_DISTANCE = 5;
|
||||
|
||||
private static final String API_HOST_FILE = "api-config.dat";
|
||||
private static final Map<String, String> API_HOST_MAP = new HashMap<>();
|
||||
|
||||
static
|
||||
{
|
||||
try
|
||||
{
|
||||
File configFile = new File(API_HOST_FILE);
|
||||
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(configFile);
|
||||
|
||||
for (String key : configuration.getKeys(false))
|
||||
{
|
||||
String ip = configuration.getConfigurationSection(key).getString("ip");
|
||||
// Use parseInt to catch non-ints instead of a 0
|
||||
int port = Integer.parseInt(configuration.getConfigurationSection(key).getString("port"));
|
||||
if (ip == null)
|
||||
{
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
API_HOST_MAP.put(key, ip + ":" + port);
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
@ -61,26 +88,15 @@ public class WorldGen extends JavaPlugin implements Runnable, Listener
|
||||
|
||||
WatchdogThread.doStop();
|
||||
|
||||
getServer().getScheduler().runTaskTimer(this, this, 20L, 20L * 5L);
|
||||
getServer().getPluginManager().registerEvents(this, this);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(AsyncPlayerPreLoginEvent event)
|
||||
{
|
||||
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
||||
event.setKickMessage("Shoo, go away");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
try
|
||||
{
|
||||
File root = new File(".");
|
||||
|
||||
if (!root.exists())
|
||||
{
|
||||
getLogger().severe("Root folder does not exist. Aborting");
|
||||
getServer().shutdown();
|
||||
System.exit(0);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -90,7 +106,7 @@ public class WorldGen extends JavaPlugin implements Runnable, Listener
|
||||
if (!outputDirectory.mkdir())
|
||||
{
|
||||
getLogger().severe("Could not create output folder. Aborting");
|
||||
getServer().shutdown();
|
||||
System.exit(0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -102,6 +118,7 @@ public class WorldGen extends JavaPlugin implements Runnable, Listener
|
||||
if (outputFile.exists())
|
||||
{
|
||||
getLogger().info("Seed " + seed + " has already been generated. Skipping");
|
||||
System.exit(0);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -110,14 +127,14 @@ public class WorldGen extends JavaPlugin implements Runnable, Listener
|
||||
if (!outputFile.createNewFile())
|
||||
{
|
||||
getLogger().severe("Could not create new output file. Aborting");
|
||||
getServer().shutdown();
|
||||
System.exit(0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
getLogger().log(Level.SEVERE, "Could not create new output file. Aborting", e);
|
||||
getServer().shutdown();
|
||||
System.exit(0);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -181,7 +198,7 @@ public class WorldGen extends JavaPlugin implements Runnable, Listener
|
||||
if (regionFiles == null)
|
||||
{
|
||||
getLogger().severe("Unexpected null region files. Aborting");
|
||||
getServer().shutdown();
|
||||
System.exit(0);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -266,14 +283,14 @@ public class WorldGen extends JavaPlugin implements Runnable, Listener
|
||||
.setDefaultRequestConfig(config)
|
||||
.build();
|
||||
|
||||
HttpPost request = new HttpPost("http://" + ApiHost.getEnderchestService().getHost() + ":" + ApiHost.getEnderchestService().getPort() + "/map/uhc/upload");
|
||||
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(Constants.GSON.toJson(jsonObject), StandardCharsets.UTF_8));
|
||||
request.setEntity(new StringEntity(new Gson().toJson(jsonObject), StandardCharsets.UTF_8));
|
||||
|
||||
try
|
||||
{
|
||||
@ -315,4 +332,10 @@ public class WorldGen extends JavaPlugin implements Runnable, Listener
|
||||
getLogger().info("Finished generating world seed " + seed);
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
t.printStackTrace();
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user