From 9e2ddeb55321b09086a5a27254197d783847e6e3 Mon Sep 17 00:00:00 2001 From: Leonard Kugis Date: Mon, 25 Apr 2022 18:50:36 +0200 Subject: Initial commit --- src/main/java/com/encrox/zombie/Zombie.java | 245 ++++++++++++++++++++++++++++ 1 file changed, 245 insertions(+) create mode 100755 src/main/java/com/encrox/zombie/Zombie.java (limited to 'src/main/java/com/encrox/zombie/Zombie.java') diff --git a/src/main/java/com/encrox/zombie/Zombie.java b/src/main/java/com/encrox/zombie/Zombie.java new file mode 100755 index 0000000..d687f6e --- /dev/null +++ b/src/main/java/com/encrox/zombie/Zombie.java @@ -0,0 +1,245 @@ +package com.encrox.zombie; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Properties; +import java.util.logging.Logger; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginDescriptionFile; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; + +public class Zombie extends JavaPlugin { + + public static Plugin plugin; + public static Logger logger; + public static PluginDescriptionFile pdf; + public static Properties lang; + public static JSONObject config; + public static JSONArray schematicDescriptors; + public static File schematicsDirectory; + public static WorldEditPlugin we; + public static ArrayList maps; + public static ArrayList lobbies; + public static ArrayList games; + public static ZombieWorld zombieWorld; + public static Commander commander; + + public void onEnable() { + pdf = getDescription(); + logger = Logger.getLogger("Minecraft"); + if(setupMyself() && setupWorldEdit()) { + plugin = this; + commander = new Commander(); + getCommand("zombie").setExecutor(commander); + logger.info(pdf.getName() + " " + pdf.getVersion() + " has been enabled."); + } else { + logger.info(pdf.getName() + " " + pdf.getVersion() + " has been disabled."); + } + } + + public boolean setupWorldEdit() { + we = (WorldEditPlugin)Bukkit.getPluginManager().getPlugin("WorldEdit"); + return (we != null); + } + + public boolean setupMyself() { + if(!this.getDataFolder().exists()) + this.getDataFolder().mkdirs(); + schematicsDirectory = new File(this.getDataFolder(), "schematics"); + if(!schematicsDirectory.exists()) + schematicsDirectory.mkdirs(); + File configFile = new File(this.getDataFolder(), "config.json"); + if(!configFile.exists()) { + BufferedInputStream bis; + FileOutputStream out; + try { + bis = new BufferedInputStream(getClass().getClassLoader().getResourceAsStream("config.json")); + out = new FileOutputStream(configFile); + int current; + while((current = bis.read()) != -1) { + out.write(current); + } + bis.close(); + out.close(); + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + BufferedReader br; + StringBuilder sb = new StringBuilder(); + String line; + try { + br = new BufferedReader(new FileReader(configFile)); + while((line = br.readLine()) != null) + sb.append(line); + br.close(); + } catch (Exception e1) { + e1.printStackTrace(); + return false; + } + config = new JSONObject(sb.toString()); + zombieWorld = new ZombieWorld(this, Bukkit.getWorld(config.getString("world"))); + File schematicDescriptorFile = new File(schematicsDirectory, "descriptor.json"); + if(!schematicDescriptorFile.exists()) { + int current; + try { + BufferedInputStream bis = new BufferedInputStream(getClass().getClassLoader().getResourceAsStream("descriptor.json")); + FileOutputStream out = new FileOutputStream(schematicDescriptorFile); + while((current = bis.read()) != -1) { + out.write(current); + } + bis.close(); + out.close(); + } catch(Exception e) { + e.printStackTrace(); + return false; + } + try { + BufferedInputStream bis = new BufferedInputStream(getClass().getClassLoader().getResourceAsStream("schematics/test.schematic")); + FileOutputStream out = new FileOutputStream(new File(schematicsDirectory, "test.schematic")); + while((current = bis.read()) != -1) { + out.write(current); + } + bis.close(); + out.close(); + } catch(Exception e) { + e.printStackTrace(); + return false; + } + } + sb = new StringBuilder(); + try { + br = new BufferedReader(new FileReader(schematicDescriptorFile)); + while((line = br.readLine()) != null) + sb.append(line); + br.close(); + } catch (Exception e1) { + e1.printStackTrace(); + return false; + } + schematicDescriptors = new JSONArray(sb.toString()); + lang = new Properties(); + try { + //TODO + lang.load(getClass().getClassLoader().getResourceAsStream("lang/" + config.getString("locale") + ".properties")); + } catch (FileNotFoundException e) { + e.printStackTrace(); + return false; + } catch (IOException e) { + e.printStackTrace(); + return false; + } + maps = new ArrayList(); + lobbies = new ArrayList(); + games = new ArrayList(); + for(int i = 0, len = schematicDescriptors.length(); i