Advertisement
Guest User

Untitled

a guest
Mar 1st, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.76 KB | None | 0 0
  1. package me.energeticeddie.energeticffa;
  2.  
  3. import java.io.FileInputStream;
  4. import java.util.HashMap;
  5. import java.io.FileNotFoundException;
  6. import java.io.FileOutputStream;
  7. import java.io.IOException;
  8. import java.io.ObjectInputStream;
  9. import java.io.ObjectOutputStream;
  10. import java.util.ArrayList;
  11. import java.util.List;
  12. import org.bukkit.Bukkit;
  13. import org.bukkit.Location;
  14. import org.bukkit.Material;
  15. import org.bukkit.OfflinePlayer;
  16. import org.bukkit.World;
  17. import org.bukkit.configuration.file.FileConfiguration;
  18. import org.bukkit.configuration.file.FileConfigurationOptions;
  19. import org.bukkit.entity.Player;
  20. import org.bukkit.inventory.ItemStack;
  21. import org.bukkit.plugin.java.JavaPlugin;
  22.  
  23. public class EnergeticFFA extends JavaPlugin {
  24. private Executor cmd;
  25. public static HashMap<String, ItemStack[]> PlayerInventories = new HashMap<String, ItemStack[]>();
  26. public static HashMap<String, ItemStack[]> PlayerArmor = new HashMap<String, ItemStack[]>();
  27. public static HashMap<String, Location> PlayerLocations = new HashMap<String, Location>();
  28. public static HashMap<String, Integer> KillStreak = new HashMap<String, Integer>();
  29. public static HashMap<String, String> LocationSave = new HashMap<String, String>();
  30. public static HashMap<String, String> isIn = new HashMap<String, String>();
  31.  
  32. @SuppressWarnings("unchecked")
  33. public void onEnable() {
  34. loadConfig();
  35. this.cmd = new Executor(this);
  36. getCommand("ffa").setExecutor(this.cmd);
  37. try {
  38. isIn = loadStatus("PlayerStatus.bin");
  39. KillStreak = loadKills("PlayerKills.bin");
  40. LocationSave = loadLocations("PlayerLocations.bin");
  41. } catch (FileNotFoundException e) {
  42. System.out
  43. .println("[Free-For-All] Player data file(s) not found. Generating file...");
  44. } catch (ClassNotFoundException e) {
  45. System.out
  46. .println("[Free-For-All] Player data file(s) not found. Generating file...");
  47. } catch (IOException e) {
  48. e.printStackTrace();
  49. }
  50. for (String s : LocationSave.keySet()) {
  51. String[] loc = ((String) LocationSave.get(s)).split(" ");
  52. World w = Bukkit.getWorld(loc[0]);
  53. int x = Integer.valueOf(loc[1]).intValue();
  54. int y = Integer.valueOf(loc[2]).intValue();
  55. int z = Integer.valueOf(loc[3]).intValue();
  56. Location l = new Location(w, x, y, z);
  57. PlayerLocations.put(s, l);
  58. }
  59. for (String s : getConfig().getStringList("Save-List")) {
  60. ItemStack[] item = null;
  61. Object o = getConfig().get("Save." + s + ".Inventory");
  62. if ((o instanceof ItemStack[])) {
  63. item = (ItemStack[]) o;
  64. } else if ((o instanceof List)) {
  65. List<String> itemlist = new ArrayList<String>();
  66. itemlist = (List<String>) o;
  67. item = (ItemStack[]) itemlist.toArray(new ItemStack[0]);
  68. }
  69. PlayerInventories.put(s, item);
  70. o = getConfig().get("Save." + s + ".Armor");
  71. if ((o instanceof ItemStack[])) {
  72. item = (ItemStack[]) o;
  73. } else if ((o instanceof List)) {
  74. List<String> itemlist = new ArrayList<String>();
  75. itemlist = (List<String>) o;
  76. item = (ItemStack[]) itemlist.toArray(new ItemStack[0]);
  77. }
  78. PlayerArmor.put(s, item);
  79. getConfig().set("Save." + s, null);
  80. getConfig().getStringList("Save-List").remove(s);
  81. }
  82. saveConfig();
  83. getServer().getPluginManager().registerEvents(new RegionSelection(),
  84. this);
  85. getServer().getPluginManager().registerEvents(new ArenaListener(this),
  86. this);
  87. getServer().getPluginManager().registerEvents(
  88. new TeleportListener(this), this);
  89. getServer().getPluginManager().registerEvents(
  90. new KillStreakListener(this), this);
  91. getServer().getPluginManager().registerEvents(
  92. new PlayerDamageListener(), this);
  93. getServer().getPluginManager().registerEvents(new PlayerQuitListener(),
  94. this);
  95. long delay = getConfig().getInt("Heal-Delay") * 20;
  96. getServer().getScheduler().scheduleSyncRepeatingTask(this,
  97. new Runnable() {
  98. public void run() {
  99. for (String s : ArenaListener.heal) {
  100. OfflinePlayer player = Bukkit.getOfflinePlayer(s);
  101. if (player.isOnline()) {
  102. Player p = Bukkit.getPlayer(s);
  103. if (p.getHealth() < 20) {
  104. p.setHealth(p.getHealth()
  105. + EnergeticFFA.this.getConfig()
  106. .getInt("Heal-Amount"));
  107. }
  108. } else {
  109. ArenaListener.heal.remove(s);
  110. }
  111. }
  112. }
  113. }, delay, delay);
  114. System.out.println("Free-For-All version ["
  115. + getDescription().getVersion() + "] loaded");
  116. }
  117.  
  118. public void onDisable() {
  119. for (String s : PlayerLocations.keySet()) {
  120. Location loc = (Location) PlayerLocations.get(s);
  121. int x = loc.getBlockX();
  122. int y = loc.getBlockY();
  123. int z = loc.getBlockZ();
  124. String world = loc.getWorld().toString();
  125. String location = world + " " + Integer.toString(x) + " "
  126. + Integer.toString(y) + " " + Integer.toString(z);
  127. LocationSave.put(s, location);
  128. }
  129. for (String s : PlayerInventories.keySet()) {
  130. ItemStack[] item = (ItemStack[]) PlayerInventories.get(s);
  131. getConfig().set("Save." + s + ".Inventory", item);
  132. getConfig().set("creator.Inventory", item);
  133. List<String> list = getConfig().getStringList("Save-List");
  134. list.add(s);
  135. getConfig().set("Save-List", list);
  136. }
  137. for (String s : PlayerArmor.keySet()) {
  138. ItemStack[] item = (ItemStack[]) PlayerArmor.get(s);
  139. getConfig().set("Save." + s + ".Armor", item);
  140. }
  141. saveConfig();
  142. try {
  143. saveLocations(LocationSave, "PlayerLocations.bin");
  144. saveKills(KillStreak, "PlayerKills.bin");
  145. saveStatus(isIn, "PlayerStatus.bin");
  146. } catch (IOException e) {
  147. System.out.println("[Free-For-All] Error saving player data!");
  148. }
  149. System.out.println("Free-For-All version ["
  150. + getDescription().getVersion() + "] unloaded");
  151. }
  152.  
  153. public static void saveInventories(
  154. HashMap<String, ItemStack[]> PlayerInventories, String path)
  155. throws IOException {
  156. System.out.println("[Free-For-All] Saving player data file...");
  157. try {
  158. ObjectOutputStream oos = new ObjectOutputStream(
  159. new FileOutputStream(
  160. "plugins/EnergeticFFA/PlayerInventories.bin"));
  161. oos.writeObject(PlayerInventories);
  162. oos.flush();
  163. oos.close();
  164. System.out
  165. .println("[Free-For-All] Player data file successfully saved.");
  166. } catch (FileNotFoundException e) {
  167. System.out
  168. .println("[Free-For-All] Player data file not found. Generating file...");
  169. }
  170. }
  171.  
  172.  
  173. //Block commands in arena.
  174.  
  175.  
  176.  
  177. public static void saveArmor(HashMap<String, ItemStack[]> PlayerArmor,
  178. String path) throws IOException {
  179. System.out.println("[Free-For-All] Saving player data file...");
  180. try {
  181. ObjectOutputStream oos = new ObjectOutputStream(
  182. new FileOutputStream("plugins/EnergeticFFA/PlayerArmor.bin"));
  183. oos.writeObject(PlayerArmor);
  184. oos.flush();
  185. oos.close();
  186. System.out
  187. .println("[Free-For-All] Player data file successfully saved.");
  188. } catch (FileNotFoundException e) {
  189. System.out
  190. .println("[Free-For-All] Player data file not found. Generating file...");
  191. }
  192. }
  193.  
  194. public static void saveKills(HashMap<String, Integer> KillStreak,
  195. String path) throws IOException {
  196. System.out.println("[Free-For-All] Saving player data file...");
  197. try {
  198. ObjectOutputStream oos = new ObjectOutputStream(
  199. new FileOutputStream("plugins/EnergeticFFA/PlayerKills.bin"));
  200. oos.writeObject(KillStreak);
  201. oos.flush();
  202. oos.close();
  203. System.out
  204. .println("[Free-For-All] Player data file successfully saved.");
  205. } catch (FileNotFoundException e) {
  206. System.out
  207. .println("[Free-For-All] Player data file not found. Generating file...");
  208. }
  209. }
  210.  
  211. public static void saveLocations(HashMap<String, String> LocationSave,
  212. String path) throws IOException {
  213. System.out.println("[Free-For-All] Saving player data file...");
  214. try {
  215. ObjectOutputStream oos = new ObjectOutputStream(
  216. new FileOutputStream(
  217. "plugins/EnergeticFFA/PlayerLocations.bin"));
  218. oos.writeObject(LocationSave);
  219. oos.flush();
  220. oos.close();
  221. System.out
  222. .println("[Free-For-All] Player data file successfully saved.");
  223. } catch (FileNotFoundException e) {
  224. System.out
  225. .println("[Free-For-All] Player data file not found. Generating file...");
  226. }
  227. }
  228.  
  229. public static void saveStatus(HashMap<String, String> isIn, String path)
  230. throws IOException {
  231. System.out.println("[Free-For-All] Saving player data file...");
  232. try {
  233. ObjectOutputStream oos = new ObjectOutputStream(
  234. new FileOutputStream(
  235. "plugins/EnergeticFFA/PlayerStatus.bin"));
  236. oos.writeObject(isIn);
  237. oos.flush();
  238. oos.close();
  239. System.out
  240. .println("[Free-For-All] Player data file successfully saved.");
  241. } catch (FileNotFoundException e) {
  242. System.out
  243. .println("[Free-For-All] Player data file not found. Generating file...");
  244. }
  245. }
  246.  
  247. @SuppressWarnings("unchecked")
  248. public static HashMap<String, ItemStack[]> loadInventories(String path)
  249. throws FileNotFoundException, IOException, ClassNotFoundException {
  250. ObjectInputStream ois = new ObjectInputStream(new FileInputStream(
  251. "plugins/EnergeticFFA/PlayerInventories.bin"));
  252. Object result = ois.readObject();
  253. ois.close();
  254. return (HashMap<String, ItemStack[]>) result;
  255. }
  256.  
  257. @SuppressWarnings("unchecked")
  258. public static HashMap<String, String> loadLocations(String path)
  259. throws FileNotFoundException, IOException, ClassNotFoundException {
  260. ObjectInputStream ois = new ObjectInputStream(new FileInputStream(
  261. "plugins/EnergeticFFA/PlayerLocations.bin"));
  262. Object result = ois.readObject();
  263. ois.close();
  264. return (HashMap<String, String>) result;
  265. }
  266.  
  267. @SuppressWarnings("unchecked")
  268. public static HashMap<String, Integer> loadKills(String path)
  269. throws FileNotFoundException, IOException, ClassNotFoundException {
  270. ObjectInputStream ois = new ObjectInputStream(new FileInputStream(
  271. "plugins/EnergeticFFA/PlayerKills.bin"));
  272. Object result = ois.readObject();
  273. ois.close();
  274. return (HashMap<String, Integer>) result;
  275. }
  276.  
  277. @SuppressWarnings("unchecked")
  278. public static HashMap<String, String> loadStatus(String path)
  279. throws FileNotFoundException, IOException, ClassNotFoundException {
  280. ObjectInputStream ois = new ObjectInputStream(new FileInputStream(
  281. "plugins/EnergeticFFA/PlayerStatus.bin"));
  282. Object result = ois.readObject();
  283. ois.close();
  284. return (HashMap<String, String>) result;
  285. }
  286.  
  287. @SuppressWarnings("unchecked")
  288. public static HashMap<String, ItemStack[]> loadArmor(String path)
  289. throws FileNotFoundException, IOException, ClassNotFoundException {
  290. ObjectInputStream ois = new ObjectInputStream(new FileInputStream(
  291. "plugins/EnergeticFFA/PlayerArmor.bin"));
  292. Object result = ois.readObject();
  293. ois.close();
  294. return (HashMap<String, ItemStack[]>) result;
  295. }
  296.  
  297. @SuppressWarnings("deprecation")
  298. public void loadConfig() {
  299. FileConfiguration cfg = getConfig();
  300. FileConfigurationOptions cfgOptions = cfg.options();
  301. List<String> list = new ArrayList<String>();
  302. cfg.addDefault("Arenas", list);
  303. cfg.addDefault("Delay-Time", Integer.valueOf(10));
  304. cfg.addDefault("Heal-Amount", Integer.valueOf(1));
  305. cfg.addDefault("Heal-Delay", Integer.valueOf(3));
  306. if (!getConfig().contains("KillStreak")) {
  307. List<String> l = new ArrayList<String>();
  308. l.add("276 1");
  309. l.add("275 1");
  310. l.add("322 2");
  311. l.add(Integer.toString(Material.IRON_SWORD.getId()) + " 1");
  312. cfg.addDefault("KillStreak.5.Items", l);
  313. List<String> llss = new ArrayList<String>();
  314. llss.add("276 1");
  315. cfg.addDefault("KillStreak.5.Remove", llss);
  316. cfg.addDefault("Arena", "");
  317. cfg.addDefault(
  318. "KillStreak.5.Message",
  319. "&bYou have been awarded&a 1&b iron sword and &a 1&b stone axe and &a 2&b golden apples.");
  320. List<String> ls = new ArrayList<String>();
  321. cfg.addDefault(
  322. "KillStreak.10.Armor",
  323. Integer.toString(Material.DIAMOND_HELMET.getId())
  324. + " "
  325. + Integer.toString(Material.DIAMOND_CHESTPLATE
  326. .getId())
  327. + " "
  328. + Integer.toString(Material.DIAMOND_LEGGINGS
  329. .getId()) + " "
  330. + Integer.toString(Material.DIAMOND_BOOTS.getId()));
  331. ls.add(Integer.toString(Material.IRON_AXE.getId()) + " 1");
  332. ls.add(Integer.toString(Material.BOW.getId()) + " 1");
  333. ls.add(Integer.toString(Material.ARROW.getId()) + " 64");
  334. ls.add(Integer.toString(Material.GOLDEN_APPLE.getId()) + " 3");
  335. ls.add(Integer.toString(Material.DIAMOND_SWORD.getId()) + " 1");
  336. cfg.addDefault("KillStreak.10.Items", ls);
  337. List<String> llll = new ArrayList<String>();
  338. llll.add("275 1");
  339. llll.add(Integer.toString(Material.IRON_SWORD.getId()) + " 1");
  340. cfg.addDefault("KillStreak.10.Remove", llll);
  341. cfg.addDefault(
  342. "KillStreak.10.Message",
  343. "&bYou have been awarded&a diamond armor&b, Swiftness 2,&a 1&b diamond sword,&a 1&b iron axe,&a 1&b bow,&a 64&b arrows, and&a 3&b gold apples.");
  344. List<String> lst = new ArrayList<String>();
  345. lst.add("speed 180");
  346. cfg.addDefault("KillStreak.10.Potions", lst);
  347. List<String> ll = new ArrayList<String>();
  348. ll.add(Integer.toString(Material.GOLDEN_APPLE.getId()) + " 6");
  349. ll.add(Integer.toString(Material.DIAMOND_AXE.getId()) + " 1h");
  350. cfg.addDefault("KillStreak.15.Items", ll);
  351. List<String> lllll = new ArrayList<String>();
  352. lllll.add(Integer.toString(Material.IRON_AXE.getId()) + " 1");
  353. cfg.addDefault("KillStreak.15.Remove", lllll);
  354. List<String> lls = new ArrayList<String>();
  355. lls.add("speed 180");
  356. cfg.addDefault("KillStreak.15.Potions", lls);
  357. cfg.addDefault("KillStreak.15.Message",
  358. "&bYou have been awarded&a 6 golden apples&b and&a Swiftness 2&a.");
  359. }
  360. List<String> liiist = new ArrayList<String>();
  361. cfg.addDefault("Save-List", liiist);
  362. cfgOptions.copyDefaults(true);
  363. cfgOptions.header("This is the Free-For-All configuration file."
  364. + System.getProperty("line.separator"));
  365. cfgOptions.copyHeader(true);
  366. saveConfig();
  367. }
  368. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement