sender.sendMessage(ChatColor.DARK_RED + "I'm sorry, something funky happened... Import aborted.");
return;
}
List<WorldGroupProfile> mvgroups = mvinventories.getGroupManager().getGroups();
MultiInv.log.info("No groups.yml found. Creating example file...");
YamlConfiguration groups = new YamlConfiguration();
MIYamlFiles.getGroups().clear();
for(WorldGroupProfile mvgroup : mvgroups) {
Set<String> mvworlds = mvgroup.getWorlds();
ArrayList<String> exampleGroup = new ArrayList<String>();
for(String world : mvworlds) {
exampleGroup.add(world);
MIYamlFiles.getGroups().put(world, mvgroup.getName());
}
String group = mvgroup.getName();
groups.set(group, exampleGroup);
MIYamlFiles.saveYamlFile(groups, "groups.yml");
for(OfflinePlayer player1 : Bukkit.getServer().getOfflinePlayers()) {
PlayerProfile playerdata = mvgroup.getPlayerData(ProfileTypes.SURVIVAL, player1);
if(playerdata != null && playerdata.get(Sharables.INVENTORY) != null) {
ItemStack[] inventory = playerdata.get(Sharables.INVENTORY);
ItemStack[] armor = playerdata.get(Sharables.ARMOR);
Integer health = playerdata.get(Sharables.HEALTH);
Integer hunger = playerdata.get(Sharables.FOOD_LEVEL);
Float saturation = playerdata.get(Sharables.SATURATION);
Integer totalexp = playerdata.get(Sharables.TOTAL_EXPERIENCE);
PotionEffect[] potioneffects = playerdata.get(Sharables.POTIONS);
LinkedList<PotionEffect> effects = new LinkedList<PotionEffect>();
if(potioneffects != null) {
for(int i = 0; i < potioneffects.length; i++) {
effects.add(potioneffects[i]);
}
}
if(MIYamlFiles.usesql) {
MIYamlFiles.con.saveInventory(player, group, new MIInventory(inventory, armor, effects), "SURVIVAL");
MIYamlFiles.con.saveHealth(player, group, health);
MIYamlFiles.con.saveHunger(player, group, hunger);
MIYamlFiles.con.saveSaturation(player, group, saturation);
MIYamlFiles.con.saveExperience(player, group, totalexp);
} else {
MIPlayerFile config = new MIPlayerFile(player1, group);
config.saveInventory(new MIInventory(inventory, armor, effects), "SURVIVAL");
config.saveHealth(health);
config.saveHunger(hunger);
config.saveSaturation(saturation);
int[] levels = plugin.getXP(totalexp);
config.saveExperience(totalexp, levels[0], (float) ((float) levels[1] / (float) levels[2]));
}
}
PlayerProfile adventureplayerdata = mvgroup.getPlayerData(ProfileTypes.ADVENTURE, player1);
if(adventureplayerdata != null && adventureplayerdata.get(Sharables.INVENTORY) != null) {
ItemStack[] inventory = adventureplayerdata.get(Sharables.INVENTORY);
ItemStack[] armor = adventureplayerdata.get(Sharables.ARMOR);
PotionEffect[] potioneffects = adventureplayerdata.get(Sharables.POTIONS);
LinkedList<PotionEffect> effects = new LinkedList<PotionEffect>();
if(potioneffects != null) {
for(int i = 0; i < potioneffects.length; i++) {
effects.add(potioneffects[i]);
}
}
if(MIYamlFiles.usesql) {
MIYamlFiles.con.saveInventory(player, group, new MIInventory(inventory, armor, effects), "ADVENTURE");
} else {
MIPlayerFile config = new MIPlayerFile(player1, group);
config.saveInventory(new MIInventory(inventory, armor, effects), "ADVENTURE");
}
}
}
}
for(World world : Bukkit.getWorlds()) {
String worldName = world.getName();
if(!MIYamlFiles.getGroups().containsKey(worldName)) {
WorldProfile worldprofile = mvinventories.getWorldManager().getWorldProfile(worldName);
for(OfflinePlayer player1 : Bukkit.getServer().getOfflinePlayers()) {
PlayerProfile playerdata = worldprofile.getPlayerData(ProfileTypes.SURVIVAL, player1);
if(playerdata != null && playerdata.get(Sharables.INVENTORY) != null) {
ItemStack[] inventory = playerdata.get(Sharables.INVENTORY);
ItemStack[] armor = playerdata.get(Sharables.ARMOR);
Integer health = playerdata.get(Sharables.HEALTH);
Integer hunger = playerdata.get(Sharables.FOOD_LEVEL);
Float saturation = playerdata.get(Sharables.SATURATION);
Integer totalexp = playerdata.get(Sharables.TOTAL_EXPERIENCE);
PotionEffect[] potioneffects = playerdata.get(Sharables.POTIONS);
LinkedList<PotionEffect> effects = new LinkedList<PotionEffect>();
if(potioneffects != null) {
for(int i = 0; i < potioneffects.length; i++) {
effects.add(potioneffects[i]);
}
}
if(MIYamlFiles.usesql) {
MIYamlFiles.con.saveInventory(player, worldName, new MIInventory(inventory, armor, effects), "SURVIVAL");
MIYamlFiles.con.saveHealth(player, worldName, health);
MIYamlFiles.con.saveHunger(player, worldName, hunger);
MIYamlFiles.con.saveSaturation(player, worldName, saturation);
MIYamlFiles.con.saveExperience(player, worldName, totalexp);
} else {
MIPlayerFile config = new MIPlayerFile(player1, worldName);
config.saveInventory(new MIInventory(inventory, armor, effects), "SURVIVAL");
config.saveHealth(health);
config.saveHunger(hunger);
config.saveSaturation(saturation);
int[] levels = plugin.getXP(totalexp);
config.saveExperience(totalexp, levels[0], (float) ((float) levels[1] / (float) levels[2]));
}
}
PlayerProfile adventureplayerdata = worldprofile.getPlayerData(ProfileTypes.ADVENTURE, player1);
if(adventureplayerdata != null && adventureplayerdata.get(Sharables.INVENTORY) != null) {
ItemStack[] inventory = adventureplayerdata.get(Sharables.INVENTORY);
ItemStack[] armor = adventureplayerdata.get(Sharables.ARMOR);
PotionEffect[] potioneffects = adventureplayerdata.get(Sharables.POTIONS);
LinkedList<PotionEffect> effects = new LinkedList<PotionEffect>();
if(potioneffects != null) {
for(int i = 0; i < potioneffects.length; i++) {
effects.add(potioneffects[i]);
}
}
if(MIYamlFiles.usesql) {
MIYamlFiles.con.saveInventory(player, worldName, new MIInventory(inventory, armor, effects), "ADVENTURE");
} else {
MIPlayerFile config = new MIPlayerFile(player1, worldName);
config.saveInventory(new MIInventory(inventory, armor, effects), "ADVENTURE");
}
}
}
}
}
// Once the groups are loaded, let's load them into MultiInv
MIYamlFiles.parseGroups(groups);
// Once the import is done let's disable MultiVerse-Inventories.
Bukkit.getPluginManager().disablePlugin(mvinventories);
sender.sendMessage(ChatColor.DARK_GREEN + "Multiverse-Inventories inventories imported successfuly!");
sender.sendMessage(ChatColor.DARK_GREEN + "Please disable/delete Multiverse-Inventories now.");
}
} else if(command.equalsIgnoreCase("miimport")) {
Plugin p = plugin.getServer().getPluginManager().getPlugin("WorldInventories");
if(p == null) {
sender.sendMessage(ChatColor.DARK_RED + "I'm sorry, WorldInventories isn't loaded... Import aborted.");
} else {
WorldInventories mvinventories;
try {
mvinventories = (WorldInventories) p;
} catch(Exception e) {
MultiInv.log.severe("Unable to import inventories from WorldInventories.");
sender.sendMessage(ChatColor.DARK_RED + "I'm sorry, something funky happened... Import aborted.");
return;
}
ArrayList<Group> mvgroups = WorldInventories.groups;
YamlConfiguration groups = new YamlConfiguration();
MIYamlFiles.getGroups().clear();
for(Group mvgroup : mvgroups) {
List<String> mvworlds = mvgroup.getWorlds();
ArrayList<String> exampleGroup = new ArrayList<String>();
for(String world : mvworlds) {
exampleGroup.add(world);
MIYamlFiles.getGroups().put(world, mvgroup.getName());
}
String group = mvgroup.getName();
groups.set(group, exampleGroup);
MIYamlFiles.saveYamlFile(groups, "groups.yml");
for(OfflinePlayer player1 : Bukkit.getServer().getOfflinePlayers()) {
plugin.getLogger().info("Importing player " + player1.getName() + "'s inventory from group " + mvgroup.getName());
HashMap<Integer, ItemStack[]> pinventory = mvinventories.loadPlayerInventory(player1.getName(), mvgroup, InventoryLoadType.INVENTORY);
HashMap<Integer, ItemStack[]> playerenderchest = mvinventories.loadPlayerInventory(player1.getName(), mvgroup, InventoryLoadType.ENDERCHEST);