From 6aa87119a0fc951a6e86da2cc83c43ea2ee842cb Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Fri, 23 Dec 2016 01:30:31 -0500 Subject: [PATCH] Oh god this is the ugliest code I've written in a while --- .../dungeons/dungeons/GenericDungeonA1.java | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/buttondevteam/alipresents/components/dungeons/dungeons/GenericDungeonA1.java b/src/buttondevteam/alipresents/components/dungeons/dungeons/GenericDungeonA1.java index b4c13f5..4f70d62 100644 --- a/src/buttondevteam/alipresents/components/dungeons/dungeons/GenericDungeonA1.java +++ b/src/buttondevteam/alipresents/components/dungeons/dungeons/GenericDungeonA1.java @@ -1,6 +1,7 @@ package buttondevteam.alipresents.components.dungeons.dungeons; import org.bukkit.Location; +import org.bukkit.World; import org.bukkit.plugin.java.JavaPlugin; public class GenericDungeonA1 extends Dungeon{ @@ -15,14 +16,22 @@ public class GenericDungeonA1 extends Dungeon{ this.plugin = plugin; } private boolean initDungeon(JavaPlugin plugin){ + /* if (plugin.getServer().getWorld("Dungeons") == null || plugin.getServer().getWorld("world") == null){ plugin.getServer().broadcastMessage("GenericDungeonA1Error! One of the worlds is null!"); plugin.getServer().broadcastMessage("Available Worlds... " + plugin.getServer().getWorlds().toString()); return false; + }*/ + if ((entrance = loadLocation(plugin, "dungeons.dungeona1.enter")) == null){ + if(plugin.getServer().getWorld("Dungeons") != null){ + entrance = new Location(plugin.getServer().getWorld("Dungeons"), -7.5, 138.0, -91.5); + } + } + if ((exit = loadLocation(plugin, "dungeons.dungeona1.exit")) == null){ + if (plugin.getServer().getWorld("world") != null){ + exit = plugin.getServer().getWorld("world").getSpawnLocation().clone(); + } } - - entrance = new Location(plugin.getServer().getWorld("Dungeons"), -7.5, 138.0, -91.5); - exit = plugin.getServer().getWorld("world").getSpawnLocation().clone(); if (entrance == null || exit == null){ plugin.getServer().broadcastMessage("DungeonA1Error! Dungeon Entrance or Exit is null!"); @@ -32,12 +41,14 @@ public class GenericDungeonA1 extends Dungeon{ } return true; } + @Override public void setEntrance(Location location){ - plugin.getConfig().set("dungeons.dungeona1.entrance", entrance); - plugin.saveConfig(); + saveLocation(plugin, "dungeons.dungeona1.enter", location); entrance = location; } + @Override public void setExit(Location location){ + saveLocation(plugin, "dungeons.dungeona1.exit", location); exit = location; } @Override @@ -48,5 +59,23 @@ public class GenericDungeonA1 extends Dungeon{ public Location getDungeonExit() { return exit; } - + private void saveLocation(JavaPlugin plugin, String path, Location location){ + plugin.getConfig().set(path+".world", location.getWorld().getName()); + plugin.getConfig().set(path+".x", location.getX()); + plugin.getConfig().set(path+".y", location.getY()); + plugin.getConfig().set(path+".z", location.getZ()); + plugin.saveConfig(); + } + private Location loadLocation(JavaPlugin plugin, String path){ + try{ + World world = plugin.getServer().getWorld(plugin.getConfig().getString(path+".world")); + double x = plugin.getConfig().getDouble(path+".x"); + double y = plugin.getConfig().getDouble(path+".y"); + double z = plugin.getConfig().getDouble(path+".z"); + return new Location(world, x, y, z); + }catch(Exception e){ + e.printStackTrace(); + return null; + } + } }