From 8d9626476305da2e1cf0094d660ce31d4cb0528f Mon Sep 17 00:00:00 2001 From: mezz Date: Fri, 24 Jul 2015 23:08:17 -0700 Subject: [PATCH] Fix #769 Fix #744 issues with flower weights in apiculture.cfg --- lang | 2 +- .../apiculture/flowers/FlowerRegistry.java | 4 --- .../forestry/plugins/PluginApiculture.java | 33 +++++++------------ 3 files changed, 12 insertions(+), 27 deletions(-) diff --git a/lang b/lang index c7ca8074d..0a10dcbeb 160000 --- a/lang +++ b/lang @@ -1 +1 @@ -Subproject commit c7ca8074d09ad1983db35b4caf25c159fd63f549 +Subproject commit 0a10dcbebcb4d4f331ba10b1bc77e9f71fda0403 diff --git a/src/main/java/forestry/apiculture/flowers/FlowerRegistry.java b/src/main/java/forestry/apiculture/flowers/FlowerRegistry.java index 18fe416fe..d78b7cb56 100644 --- a/src/main/java/forestry/apiculture/flowers/FlowerRegistry.java +++ b/src/main/java/forestry/apiculture/flowers/FlowerRegistry.java @@ -111,10 +111,6 @@ public final class FlowerRegistry implements IFlowerRegistry { for (String flowerType : flowerTypes) { Set flowers = this.registeredFlowers.get(flowerType); - - if (flowers.contains(newFlower)) { - throw new IllegalArgumentException("Flower type already exists: " + flowerType + " for flower " + block); - } flowers.add(newFlower); Set blocks = this.registeredBlocks.get(flowerType); diff --git a/src/main/java/forestry/plugins/PluginApiculture.java b/src/main/java/forestry/plugins/PluginApiculture.java index 6499369f4..ad1f6cdc9 100644 --- a/src/main/java/forestry/plugins/PluginApiculture.java +++ b/src/main/java/forestry/plugins/PluginApiculture.java @@ -13,12 +13,9 @@ package forestry.plugins; import com.google.common.collect.ImmutableMap; import java.io.File; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Random; import java.util.Set; @@ -294,7 +291,14 @@ public class PluginApiculture extends ForestryPlugin { } } - LocalizedConfiguration config = new LocalizedConfiguration(configFile, "1.0.0"); + LocalizedConfiguration config = new LocalizedConfiguration(configFile, "2.0.0"); + if (!config.getLoadedConfigVersion().equals(config.getDefinedConfigVersion())) { + boolean deleted = configFile.delete(); + if (deleted) { + config = new LocalizedConfiguration(configFile, "2.0.0"); + setDefaultsForConfig(); + } + } List beekeepingModes = BeeManager.beeRoot.getBeekeepingModes(); String[] validBeekeepingModeNames = new String[beekeepingModes.size()]; @@ -420,10 +424,6 @@ public class PluginApiculture extends ForestryPlugin { flowerRegistry.registerPlantableFlower(Blocks.red_mushroom, 0, 1.0, FlowerManager.FlowerTypeMushrooms); flowerRegistry.registerPlantableFlower(Blocks.cactus, 0, 1.0, FlowerManager.FlowerTypeCacti); - DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(Locale.ENGLISH); - DecimalFormat weightDecimalFormat = new DecimalFormat("#.000", decimalFormatSymbols); - weightDecimalFormat.setGroupingUsed(false); - for (String flowerType : FlowerManager.flowerRegistry.getFlowerTypes()) { Set flowers = FlowerManager.flowerRegistry.getAcceptableFlowers(flowerType); List acceptedFlowerNames = new ArrayList(); @@ -437,9 +437,7 @@ public class PluginApiculture extends ForestryPlugin { } if (flower.isPlantable()) { - double weight = flower.getWeight(); - String weightString = weightDecimalFormat.format(weight); - plantableFlowerNames.add(weightString + ':' + name); + plantableFlowerNames.add(name); } else { acceptedFlowerNames.add(name); } @@ -454,7 +452,7 @@ public class PluginApiculture extends ForestryPlugin { } } - private void loadOldConfig() { + private static void loadOldConfig() { // Config forestry.core.config.deprecated.Configuration apicultureConfig = new forestry.core.config.deprecated.Configuration(); @@ -1032,15 +1030,6 @@ public class PluginApiculture extends ForestryPlugin { for (String string : property.getStringList()) { int idx = string.indexOf(':'); - String weightString = string.substring(0, idx); - double weight; - try { - weight = Double.parseDouble(weightString); - } catch (NumberFormatException e) { - Proxies.log.warning("Invalid weight for plantable flower in config. (" + property.getName() + ')'); - continue; - } - String itemStackString = string.substring(idx + 1); StackUtils.Stack plantableFlower = StackUtils.parseStackString(itemStackString, OreDictionary.WILDCARD_VALUE); if (plantableFlower == null) { @@ -1050,7 +1039,7 @@ public class PluginApiculture extends ForestryPlugin { Block plantableFlowerBlock = plantableFlower.getBlock(); int meta = plantableFlower.getMeta(); if (plantableFlowerBlock != null) { - FlowerManager.flowerRegistry.registerPlantableFlower(plantableFlowerBlock, meta, weight, flowerType); + FlowerManager.flowerRegistry.registerPlantableFlower(plantableFlowerBlock, meta, 1.0, flowerType); } else { Proxies.log.warning("No block found for '" + plantableFlower + "' in config '" + property.getName() + "'."); }