diff --git a/src/main/java/com/gmail/nossr50/commands/McImportCommand.java b/src/main/java/com/gmail/nossr50/commands/McImportCommand.java index a372dca0d..17a755048 100644 --- a/src/main/java/com/gmail/nossr50/commands/McImportCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/McImportCommand.java @@ -17,6 +17,7 @@ import org.bukkit.command.CommandSender; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.datatypes.skills.ModConfigType; +import com.gmail.nossr50.util.Misc; public class McImportCommand implements CommandExecutor { int fileAmount; @@ -49,6 +50,7 @@ public class McImportCommand implements CommandExecutor { String line; String materialName; + String modName; // While not at the end of the file while ((line = in.readLine()) != null) { @@ -65,19 +67,16 @@ public class McImportCommand implements CommandExecutor { } materialName = split2[0]; - String[] materialSplit = materialName.split("_"); - if (materialSplit.length > 1) { - // Categorise each material under a mod config type - ModConfigType type = ModConfigType.getModConfigType(materialName); + // Categorise each material under a mod config type + ModConfigType type = ModConfigType.getModConfigType(materialName); - if (!materialNames.containsKey(type)) { - materialNames.put(type, new ArrayList()); - } - - materialNames.get(type).add(materialName); - continue; + if (!materialNames.containsKey(type)) { + materialNames.put(type, new ArrayList()); } + + materialNames.get(type).add(materialName); + continue; } } catch (FileNotFoundException e) { @@ -104,7 +103,7 @@ public class McImportCommand implements CommandExecutor { HashMap> materialNamesType = new HashMap>(); for (String materialName : materialNames.get(modConfigType)) { - String modName = materialName.split("_")[0].toLowerCase(); + String modName = Misc.getModName(materialName); if (!materialNamesType.containsKey(modName)) { materialNamesType.put(modName, new ArrayList()); diff --git a/src/main/java/com/gmail/nossr50/util/Misc.java b/src/main/java/com/gmail/nossr50/util/Misc.java index 6a21339cc..18f6f8253 100644 --- a/src/main/java/com/gmail/nossr50/util/Misc.java +++ b/src/main/java/com/gmail/nossr50/util/Misc.java @@ -2,6 +2,7 @@ package com.gmail.nossr50.util; import java.util.Collection; import java.util.Random; +import java.util.Set; import org.bukkit.Location; import org.bukkit.Material; @@ -16,6 +17,8 @@ import com.gmail.nossr50.events.items.McMMOItemSpawnEvent; import com.gmail.nossr50.runnables.player.PlayerProfileLoadingTask; import com.gmail.nossr50.util.player.UserManager; +import com.google.common.collect.ImmutableSet; + public final class Misc { private static Random random = new Random(); @@ -36,6 +39,8 @@ public final class Misc { public static final float LEVELUP_PITCH = 0.5F; // Reduced to differentiate between vanilla level-up public static final float LEVELUP_VOLUME = 0.75F; // Use max volume always + public static final Set modNames = ImmutableSet.of("LOTR", "BUILDCRAFT", "ENDERIO", "ENHANCEDBIOMES", "IC2", "METALLURGY", "FORESTRY", "GALACTICRAFT", "RAILCRAFT", "TWILIGHTFOREST", "THAUMCRAFT", "GRAVESTONEMOD", "GROWTHCRAFT", "ARCTICMOBS", "DEMONMOBS", "INFERNOMOBS", "SWAMPMOBS", "MARICULTURE", "MINESTRAPPOLATION"); + private Misc() {}; public static float getFizzPitch() { @@ -123,6 +128,22 @@ public final class Misc { } } + public static String getModName(String materialName) { + for (String mod : modNames) { + if (materialName.contains(mod)) { + return mod; + } + } + + String[] materialSplit = materialName.split("_"); + + if (materialSplit.length > 1) { + return materialSplit[0].toLowerCase(); + } + + return "UnknownMods"; + } + public static Random getRandom() { return random; }