Compatiblity with DungeonsXL

This commit is contained in:
Sn0wStorm 2013-06-05 19:44:30 +02:00
parent 84e37ec676
commit edf8c7a840
4 changed files with 57 additions and 13 deletions

View File

@ -118,8 +118,14 @@ public class BCauldron {
if (!bcauldrons.isEmpty()) {
int id = 0;
for (BCauldron cauldron : bcauldrons) {
// cauldrons are sorted in worldUUID.randomId
String prefix = cauldron.block.getWorld().getUID().toString() + "." + id;
String worldName = cauldron.block.getWorld().getName();
String prefix = null;
if (worldName.startsWith("DXL_")) {
prefix = P.p.getDxlName(worldName) + "." + id;
} else {
prefix = cauldron.block.getWorld().getUID().toString() + "." + id;
}
config.set(prefix + ".block", cauldron.block.getX() + "/" + cauldron.block.getY() + "/" + cauldron.block.getZ());
if (cauldron.state != 1) {

View File

@ -155,8 +155,16 @@ public class Barrel {
if (!barrels.isEmpty()) {
int id = 0;
for (Barrel barrel : barrels) {
// barrels are sorted in worldUUID.randomId
String prefix = barrel.spigot.getWorld().getUID().toString() + "." + id;
String worldName = barrel.spigot.getWorld().getName();
String prefix = null;
if (worldName.startsWith("DXL_")) {
prefix = P.p.getDxlName(worldName) + "." + id;
} else {
prefix = barrel.spigot.getWorld().getUID().toString() + "." + id;
}
// block: x/y/z
config.set(prefix + ".spigot", barrel.spigot.getX() + "/" + barrel.spigot.getY() + "/" + barrel.spigot.getZ());

View File

@ -2,13 +2,13 @@ package com.dre.brewery;
import java.util.Map;
import java.util.HashMap;
import java.util.UUID;
import java.io.IOException;
import java.io.File;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.configuration.ConfigurationSection;
import java.io.File;
import org.apache.commons.lang.math.NumberUtils;
import com.dre.brewery.listeners.BlockListener;
@ -18,11 +18,11 @@ import com.dre.brewery.listeners.InventoryListener;
import com.dre.brewery.listeners.WorldListener;
import org.bukkit.event.HandlerList;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import java.io.IOException;
public class P extends JavaPlugin {
public static P p;
@ -151,8 +151,12 @@ public class P extends JavaPlugin {
}
}
for (org.bukkit.World world : p.getServer().getWorlds()) {
loadWorldData(world.getUID().toString());
for (World world : p.getServer().getWorlds()) {
if (world.getName().startsWith("DXL_")) {
loadWorldData(getDxlName(world.getName()), world);
} else {
loadWorldData(world.getUID().toString(), world);
}
}
} else {
@ -179,7 +183,7 @@ public class P extends JavaPlugin {
}
// load Block locations of given world
public void loadWorldData(String uuid) {
public void loadWorldData(String uuid, World world) {
File file = new File(p.getDataFolder(), "data.yml");
if (file.exists()) {
@ -195,7 +199,8 @@ public class P extends JavaPlugin {
if (block != null) {
String[] splitted = block.split("/");
if (splitted.length == 3) {
Block worldBlock = getServer().getWorld(UUID.fromString(uuid)).getBlockAt(parseInt(splitted[0]), parseInt(splitted[1]), parseInt(splitted[2]));
Block worldBlock = world.getBlockAt(parseInt(splitted[0]), parseInt(splitted[1]), parseInt(splitted[2]));
BIngredients ingredients = loadIngredients(section.getConfigurationSection(cauldron + ".ingredients"));
int state = section.getInt(cauldron + ".state", 1);
@ -218,16 +223,19 @@ public class P extends JavaPlugin {
if (spigot != null) {
String[] splitted = spigot.split("/");
if (splitted.length == 3) {
// load itemStacks from invSection
ConfigurationSection invSection = section.getConfigurationSection(barrel + ".inv");
Block block = getServer().getWorld(UUID.fromString(uuid)).getBlockAt(parseInt(splitted[0]), parseInt(splitted[1]), parseInt(splitted[2]));
Block block = world.getBlockAt(parseInt(splitted[0]), parseInt(splitted[1]), parseInt(splitted[2]));
float time = (float) section.getDouble(barrel + ".time", 0.0);
if (invSection != null) {
new Barrel(block, invSection.getValues(true), time);
} else {
// Barrel has no inventory
new Barrel(block, time);
}
} else {
errorLog("Incomplete Block-Data in data.yml: " + section.getCurrentPath() + "." + barrel);
}
@ -283,6 +291,20 @@ public class P extends JavaPlugin {
return NumberUtils.toInt(string, 0);
}
public String getDxlName(String worldName) {
File dungeonFolder = new File(worldName);
if (dungeonFolder.isDirectory()) {
for (File file : dungeonFolder.listFiles()) {
if (!file.isDirectory()) {
if (file.getName().startsWith(".id_")) {
return file.getName().substring(1);
}
}
}
}
return null;
}
public class BreweryRunnable implements Runnable {
public BreweryRunnable() {

View File

@ -4,6 +4,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import org.bukkit.World;
import com.dre.brewery.P;
import com.dre.brewery.BCauldron;
@ -14,12 +15,19 @@ public class WorldListener implements Listener {
@EventHandler
public void onWorldLoad(WorldLoadEvent event) {
P.p.log("loading world with uuid " + event.getWorld().getUID().toString());
P.p.loadWorldData(event.getWorld().getUID().toString());
World world = event.getWorld();
if (world.getName().startsWith("DXL_")) {
P.p.loadWorldData(P.p.getDxlName(world.getName()), world);
} else {
P.p.loadWorldData(event.getWorld().getUID().toString(), world);
}
}
@EventHandler
public void onWorldUnload(WorldUnloadEvent event) {
P.p.log("Unloading world with uuid " + event.getWorld().getUID().toString());
if (!event.isCancelled()) {
P.p.saveData();
Barrel.onUnload(event.getWorld().getName());