Improve auto mod config generator

This commit is contained in:
TfT_02 2014-08-31 19:10:49 +02:00
parent 56cb5c092f
commit eac5d1ee7a
2 changed files with 31 additions and 11 deletions

View File

@ -17,6 +17,7 @@ import org.bukkit.command.CommandSender;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.skills.ModConfigType; import com.gmail.nossr50.datatypes.skills.ModConfigType;
import com.gmail.nossr50.util.Misc;
public class McImportCommand implements CommandExecutor { public class McImportCommand implements CommandExecutor {
int fileAmount; int fileAmount;
@ -49,6 +50,7 @@ public class McImportCommand implements CommandExecutor {
String line; String line;
String materialName; String materialName;
String modName;
// While not at the end of the file // While not at the end of the file
while ((line = in.readLine()) != null) { while ((line = in.readLine()) != null) {
@ -65,19 +67,16 @@ public class McImportCommand implements CommandExecutor {
} }
materialName = split2[0]; materialName = split2[0];
String[] materialSplit = materialName.split("_");
if (materialSplit.length > 1) { // Categorise each material under a mod config type
// Categorise each material under a mod config type ModConfigType type = ModConfigType.getModConfigType(materialName);
ModConfigType type = ModConfigType.getModConfigType(materialName);
if (!materialNames.containsKey(type)) { if (!materialNames.containsKey(type)) {
materialNames.put(type, new ArrayList<String>()); materialNames.put(type, new ArrayList<String>());
}
materialNames.get(type).add(materialName);
continue;
} }
materialNames.get(type).add(materialName);
continue;
} }
} }
catch (FileNotFoundException e) { catch (FileNotFoundException e) {
@ -104,7 +103,7 @@ public class McImportCommand implements CommandExecutor {
HashMap<String, ArrayList<String>> materialNamesType = new HashMap<String, ArrayList<String>>(); HashMap<String, ArrayList<String>> materialNamesType = new HashMap<String, ArrayList<String>>();
for (String materialName : materialNames.get(modConfigType)) { for (String materialName : materialNames.get(modConfigType)) {
String modName = materialName.split("_")[0].toLowerCase(); String modName = Misc.getModName(materialName);
if (!materialNamesType.containsKey(modName)) { if (!materialNamesType.containsKey(modName)) {
materialNamesType.put(modName, new ArrayList<String>()); materialNamesType.put(modName, new ArrayList<String>());

View File

@ -2,6 +2,7 @@ package com.gmail.nossr50.util;
import java.util.Collection; import java.util.Collection;
import java.util.Random; import java.util.Random;
import java.util.Set;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; 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.runnables.player.PlayerProfileLoadingTask;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.google.common.collect.ImmutableSet;
public final class Misc { public final class Misc {
private static Random random = new Random(); 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_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 float LEVELUP_VOLUME = 0.75F; // Use max volume always
public static final Set<String> modNames = ImmutableSet.of("LOTR", "BUILDCRAFT", "ENDERIO", "ENHANCEDBIOMES", "IC2", "METALLURGY", "FORESTRY", "GALACTICRAFT", "RAILCRAFT", "TWILIGHTFOREST", "THAUMCRAFT", "GRAVESTONEMOD", "GROWTHCRAFT", "ARCTICMOBS", "DEMONMOBS", "INFERNOMOBS", "SWAMPMOBS", "MARICULTURE", "MINESTRAPPOLATION");
private Misc() {}; private Misc() {};
public static float getFizzPitch() { 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() { public static Random getRandom() {
return random; return random;
} }