Made the chests use own configfile... 3rd try
This commit is contained in:
parent
1ebab85ead
commit
2ae5363b4b
@ -29,14 +29,14 @@ public class Chests implements Listener {
|
||||
int blockx = blocklocation.getBlockX();
|
||||
int blocky = blocklocation.getBlockY();
|
||||
int blockz = blocklocation.getBlockZ();
|
||||
if (plugin.getConfig().getStringList("StorageXYZ").contains(blockx + "," + blocky + "," + blockz)) {
|
||||
if (plugin.getChests().getStringList("StorageXYZ").contains(blockx + "," + blocky + "," + blockz)) {
|
||||
if(p.hasPermission("HungerArena.Chest.Break") && plugin.getArena(p)== null){
|
||||
List<String> list2 = plugin.getConfig().getStringList("StorageXYZ");
|
||||
List<String> list2 = plugin.getChests().getStringList("StorageXYZ");
|
||||
list2.remove(blockx + "," + blocky + "," + blockz);
|
||||
plugin.getConfig().set("Storage." + blockx + "," + blocky+ "," + blockz, null);
|
||||
plugin.getConfig().set("StorageXYZ", list2);
|
||||
plugin.getConfig().options().copyDefaults(true);
|
||||
plugin.saveConfig();
|
||||
plugin.getChests().set("Storage." + blockx + "," + blocky+ "," + blockz, null);
|
||||
plugin.getChests().set("StorageXYZ", list2);
|
||||
plugin.getChests().options().copyDefaults(true);
|
||||
plugin.saveChests();
|
||||
p.sendMessage("[HungerArena] Chest Removed!");
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
@ -60,20 +60,20 @@ public class Chests implements Listener {
|
||||
int blocky = block.getY();
|
||||
int blockz = block.getZ();
|
||||
String blockw = block.getWorld().getName().toString();
|
||||
if(!plugin.getConfig().contains("Storage." + blockx + "," + blocky + "," + blockz + ".Location.X")){
|
||||
plugin.getConfig().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".Location.X", blockx);
|
||||
plugin.getConfig().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".Location.Y", blocky);
|
||||
plugin.getConfig().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".Location.Z",blockz);
|
||||
plugin.getConfig().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".Location.W", blockw);
|
||||
plugin.getConfig().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".ItemsInStorage", itemsinchest);
|
||||
plugin.getConfig().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".Arena", a);
|
||||
if(!plugin.getChests().contains("Storage." + blockx + "," + blocky + "," + blockz + ".Location.X")){ //getConfig greift auf normale cfg zu.. -> eigene Routine
|
||||
plugin.getChests().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".Location.X", blockx);
|
||||
plugin.getChests().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".Location.Y", blocky);
|
||||
plugin.getChests().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".Location.Z",blockz);
|
||||
plugin.getChests().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".Location.W", blockw);
|
||||
plugin.getChests().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".ItemsInStorage", itemsinchest);
|
||||
plugin.getChests().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".Arena", a);
|
||||
}
|
||||
List<String> list2 = plugin.getConfig().getStringList("StorageXYZ");
|
||||
List<String> list2 = plugin.getChests().getStringList("StorageXYZ");
|
||||
if(!list2.contains(blockx + "," + blocky + "," + blockz)){
|
||||
list2.add(blockx + "," + blocky + "," + blockz);
|
||||
plugin.getConfig().set("StorageXYZ", list2);
|
||||
plugin.getConfig().options().copyDefaults(true);
|
||||
plugin.saveConfig();
|
||||
plugin.getChests().set("StorageXYZ", list2);
|
||||
plugin.getChests().options().copyDefaults(true);
|
||||
plugin.saveChests();
|
||||
p.sendMessage(ChatColor.GREEN + "Thank you for finding this undiscovered chest, it has been stored!!");
|
||||
}
|
||||
}
|
||||
|
@ -664,14 +664,14 @@ public class HaCommands implements CommandExecutor {
|
||||
a = Integer.parseInt(args[1]);
|
||||
int list056;
|
||||
list056 = 0;
|
||||
int limit = plugin.config.getStringList("StorageXYZ").size();
|
||||
int limit = plugin.MyChests.getStringList("StorageXYZ").size();
|
||||
while(limit > list056){
|
||||
String xyz2 = plugin.getConfig().getStringList("StorageXYZ").get(list056);
|
||||
int chestx = plugin.getConfig().getInt("Storage." + xyz2 + ".Location.X");
|
||||
int chesty = plugin.getConfig().getInt("Storage." + xyz2 + ".Location.Y");
|
||||
int chestz = plugin.getConfig().getInt("Storage." + xyz2 + ".Location.Z");
|
||||
int chesta = plugin.getConfig().getInt("Storage." + xyz2 + ".Arena");
|
||||
String chestw = plugin.getConfig().getString("Storage." + xyz2 + ".Location.W");
|
||||
String xyz2 = plugin.getChests().getStringList("StorageXYZ").get(list056);
|
||||
int chestx = plugin.getChests().getInt("Storage." + xyz2 + ".Location.X");
|
||||
int chesty = plugin.getChests().getInt("Storage." + xyz2 + ".Location.Y");
|
||||
int chestz = plugin.getChests().getInt("Storage." + xyz2 + ".Location.Z");
|
||||
int chesta = plugin.getChests().getInt("Storage." + xyz2 + ".Arena");
|
||||
String chestw = plugin.getChests().getString("Storage." + xyz2 + ".Location.W");
|
||||
Block blockatlocation = Bukkit.getWorld(chestw).getBlockAt(chestx, chesty, chestz);
|
||||
plugin.exists = false;
|
||||
if(chesta== a){
|
||||
@ -681,7 +681,7 @@ public class HaCommands implements CommandExecutor {
|
||||
if(chesta== a){
|
||||
chest.getInventory().clear();
|
||||
ItemStack[] itemsinchest = null;
|
||||
Object o = plugin.getConfig().get("Storage." + xyz2 + ".ItemsInStorage");
|
||||
Object o = plugin.getChests().get("Storage." + xyz2 + ".ItemsInStorage");
|
||||
if(o instanceof ItemStack[]){
|
||||
itemsinchest = (ItemStack[]) o;
|
||||
}else if(o instanceof List){
|
||||
@ -702,13 +702,13 @@ public class HaCommands implements CommandExecutor {
|
||||
}else{
|
||||
int list056;
|
||||
list056 = 0;
|
||||
int limit = plugin.config.getStringList("StorageXYZ").size();
|
||||
int limit = plugin.MyChests.getStringList("StorageXYZ").size();
|
||||
while(limit > list056){
|
||||
String xyz2 = plugin.getConfig().getStringList("StorageXYZ").get(list056);
|
||||
int chestx = plugin.getConfig().getInt("Storage." + xyz2 + ".Location.X");
|
||||
int chesty = plugin.getConfig().getInt("Storage." + xyz2 + ".Location.Y");
|
||||
int chestz = plugin.getConfig().getInt("Storage." + xyz2 + ".Location.Z");
|
||||
String chestw = plugin.getConfig().getString("Storage." + xyz2 + ".Location.W");
|
||||
String xyz2 = plugin.getChests().getStringList("StorageXYZ").get(list056);
|
||||
int chestx = plugin.getChests().getInt("Storage." + xyz2 + ".Location.X");
|
||||
int chesty = plugin.getChests().getInt("Storage." + xyz2 + ".Location.Y");
|
||||
int chestz = plugin.getChests().getInt("Storage." + xyz2 + ".Location.Z");
|
||||
String chestw = plugin.getChests().getString("Storage." + xyz2 + ".Location.W");
|
||||
Block blockatlocation = Bukkit.getWorld(chestw).getBlockAt(chestx, chesty, chestz);
|
||||
plugin.exists = false;
|
||||
if(blockatlocation.getState() instanceof Chest){
|
||||
@ -716,7 +716,7 @@ public class HaCommands implements CommandExecutor {
|
||||
Chest chest = (Chest) blockatlocation.getState();
|
||||
chest.getInventory().clear();
|
||||
ItemStack[] itemsinchest = null;
|
||||
Object o = plugin.getConfig().get("Storage." + xyz2 + ".ItemsInStorage");
|
||||
Object o = plugin.getChests().get("Storage." + xyz2 + ".ItemsInStorage");
|
||||
if(o instanceof ItemStack[]){
|
||||
itemsinchest = (ItemStack[]) o;
|
||||
}else if(o instanceof List){
|
||||
@ -1110,14 +1110,14 @@ public class HaCommands implements CommandExecutor {
|
||||
a = Integer.parseInt(args[1]);
|
||||
int list056;
|
||||
list056 = 0;
|
||||
int limit = plugin.config.getStringList("StorageXYZ").size();
|
||||
int limit = plugin.MyChests.getStringList("StorageXYZ").size();
|
||||
while(limit > list056){
|
||||
String xyz2 = plugin.getConfig().getStringList("StorageXYZ").get(list056);
|
||||
int chestx = plugin.getConfig().getInt("Storage." + xyz2 + ".Location.X");
|
||||
int chesty = plugin.getConfig().getInt("Storage." + xyz2 + ".Location.Y");
|
||||
int chestz = plugin.getConfig().getInt("Storage." + xyz2 + ".Location.Z");
|
||||
int chesta = plugin.getConfig().getInt("Storage." + xyz2 + ".Arena");
|
||||
String chestw = plugin.getConfig().getString("Storage." + xyz2 + ".Location.W");
|
||||
String xyz2 = plugin.getChests().getStringList("StorageXYZ").get(list056);
|
||||
int chestx = plugin.getChests().getInt("Storage." + xyz2 + ".Location.X");
|
||||
int chesty = plugin.getChests().getInt("Storage." + xyz2 + ".Location.Y");
|
||||
int chestz = plugin.getChests().getInt("Storage." + xyz2 + ".Location.Z");
|
||||
int chesta = plugin.getChests().getInt("Storage." + xyz2 + ".Arena");
|
||||
String chestw = plugin.getChests().getString("Storage." + xyz2 + ".Location.W");
|
||||
Block blockatlocation = Bukkit.getWorld(chestw).getBlockAt(chestx, chesty, chestz);
|
||||
plugin.exists = false;
|
||||
if(chesta== a){
|
||||
@ -1127,7 +1127,7 @@ public class HaCommands implements CommandExecutor {
|
||||
if(chesta== a){
|
||||
chest.getInventory().clear();
|
||||
ItemStack[] itemsinchest = null;
|
||||
Object o = plugin.getConfig().get("Storage." + xyz2 + ".ItemsInStorage");
|
||||
Object o = plugin.getChests().get("Storage." + xyz2 + ".ItemsInStorage");
|
||||
if(o instanceof ItemStack[]){
|
||||
itemsinchest = (ItemStack[]) o;
|
||||
}else if(o instanceof List){
|
||||
@ -1148,13 +1148,13 @@ public class HaCommands implements CommandExecutor {
|
||||
}else{
|
||||
int list056;
|
||||
list056 = 0;
|
||||
int limit = plugin.config.getStringList("StorageXYZ").size();
|
||||
int limit = plugin.MyChests.getStringList("StorageXYZ").size();
|
||||
while(limit > list056){
|
||||
String xyz2 = plugin.getConfig().getStringList("StorageXYZ").get(list056);
|
||||
int chestx = plugin.getConfig().getInt("Storage." + xyz2 + ".Location.X");
|
||||
int chesty = plugin.getConfig().getInt("Storage." + xyz2 + ".Location.Y");
|
||||
int chestz = plugin.getConfig().getInt("Storage." + xyz2 + ".Location.Z");
|
||||
String chestw = plugin.getConfig().getString("Storage." + xyz2 + ".Location.W");
|
||||
String xyz2 = plugin.getChests().getStringList("StorageXYZ").get(list056);
|
||||
int chestx = plugin.getChests().getInt("Storage." + xyz2 + ".Location.X");
|
||||
int chesty = plugin.getChests().getInt("Storage." + xyz2 + ".Location.Y");
|
||||
int chestz = plugin.getChests().getInt("Storage." + xyz2 + ".Location.Z");
|
||||
String chestw = plugin.getChests().getString("Storage." + xyz2 + ".Location.W");
|
||||
Block blockatlocation = Bukkit.getWorld(chestw).getBlockAt(chestx, chesty, chestz);
|
||||
plugin.exists = false;
|
||||
if(blockatlocation.getState() instanceof Chest){
|
||||
@ -1162,7 +1162,7 @@ public class HaCommands implements CommandExecutor {
|
||||
Chest chest = (Chest) blockatlocation.getState();
|
||||
chest.getInventory().clear();
|
||||
ItemStack[] itemsinchest = null;
|
||||
Object o = plugin.getConfig().get("Storage." + xyz2 + ".ItemsInStorage");
|
||||
Object o = plugin.getChests().get("Storage." + xyz2 + ".ItemsInStorage");
|
||||
if(o instanceof ItemStack[]){
|
||||
itemsinchest = (ItemStack[]) o;
|
||||
}else if(o instanceof List){
|
||||
|
@ -70,8 +70,12 @@ public class Main extends JavaPlugin{
|
||||
public File spawnsFile = null;
|
||||
public FileConfiguration data = null;
|
||||
public File dataFile = null;
|
||||
public File managementFile = null;
|
||||
public FileConfiguration management = null;
|
||||
public File managementFile = null;
|
||||
|
||||
public FileConfiguration MyChests = null;
|
||||
public File ChestsFile = null;
|
||||
|
||||
public ArrayList<ItemStack> Reward = new ArrayList<ItemStack>();
|
||||
public ArrayList<ItemStack> Cost = new ArrayList<ItemStack>();
|
||||
public ArrayList<ItemStack> Fee = new ArrayList<ItemStack>();
|
||||
@ -100,6 +104,9 @@ public class Main extends JavaPlugin{
|
||||
management = this.getManagement();
|
||||
management.options().copyDefaults(true);
|
||||
this.saveManagement();
|
||||
MyChests = this.getChests();
|
||||
MyChests.options().copyDefaults(true);
|
||||
this.saveChests();
|
||||
getServer().getPluginManager().registerEvents(DeathListener, this);
|
||||
getServer().getPluginManager().registerEvents(SpectatorListener, this);
|
||||
getServer().getPluginManager().registerEvents(FreezeListener, this);
|
||||
@ -309,6 +316,37 @@ public class Main extends JavaPlugin{
|
||||
this.getLogger().log(Level.SEVERE, "Could not save config to " + managementFile, ex);
|
||||
}
|
||||
}
|
||||
//Jeppa: Add routine like the others for loading Chests with their very own file..
|
||||
public void reloadChests() {
|
||||
if (ChestsFile == null) {
|
||||
ChestsFile = new File(getDataFolder(), "Chests.yml");
|
||||
}
|
||||
MyChests = YamlConfiguration.loadConfiguration(ChestsFile);
|
||||
|
||||
// Look for defaults in the jar
|
||||
InputStream defConfigStream = this.getResource("Chests.yml");
|
||||
if (defConfigStream != null) {
|
||||
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
|
||||
MyChests.setDefaults(defConfig);
|
||||
}
|
||||
}
|
||||
public FileConfiguration getChests() {
|
||||
if (MyChests == null) {
|
||||
this.reloadChests();
|
||||
}
|
||||
return MyChests;
|
||||
}
|
||||
public void saveChests() {
|
||||
if (MyChests == null || ChestsFile == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
getChests().save(ChestsFile);
|
||||
} catch (IOException ex) {
|
||||
this.getLogger().log(Level.SEVERE, "Could not save config to " + ChestsFile, ex);
|
||||
}
|
||||
}
|
||||
//^^
|
||||
public void winner(final Integer a){
|
||||
String[] Spawncoords = spawns.getString("Spawn_coords").split(",");
|
||||
World spawnw = getServer().getWorld(Spawncoords[3]);
|
||||
|
Loading…
Reference in New Issue
Block a user