diff --git a/MCRandomizer/src/scramble/plugin/FurnaceRecipeStore.java b/MCRandomizer/src/scramble/plugin/FurnaceRecipeStore.java index 8507ebf..8e2e6ba 100644 --- a/MCRandomizer/src/scramble/plugin/FurnaceRecipeStore.java +++ b/MCRandomizer/src/scramble/plugin/FurnaceRecipeStore.java @@ -29,5 +29,5 @@ public class FurnaceRecipeStore implements RecipeStore{ public void setResultItem(String item) { this.finalItem=item; } - + //6,12,11,102 } diff --git a/MCRandomizer/src/scramble/plugin/Template.java b/MCRandomizer/src/scramble/plugin/Template.java index 047f483..8835914 100644 --- a/MCRandomizer/src/scramble/plugin/Template.java +++ b/MCRandomizer/src/scramble/plugin/Template.java @@ -4,6 +4,7 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; +import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -12,6 +13,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Random; +import java.util.logging.Level; import java.util.logging.Logger; import net.md_5.bungee.api.ChatColor; import org.bukkit.Bukkit; @@ -67,6 +69,7 @@ public class Template public static ItemStack randomMelonItem; public static int recipe_count=0; public static boolean finished=false; + public static int villager_count=0; PluginDescriptionFile pdfFile; @@ -129,7 +132,7 @@ public class Template String[] splitter = s2.split(","); - List splitter2 = new ArrayList(); + List splitter2 = new ArrayList(); for (int i = 1; i < splitter.length; i++) { Material m = Material.getMaterial(splitter[i]); @@ -301,86 +304,166 @@ public class Template breedingTable.put(canBreed.get(0), canBreed.get(0)); } } - + + boolean IsAlphabeticallyAfter(String name, String name2, String compare2, String compare22) { + for (int i=0;iname2.charAt(i)) { + return true; + } + } else { + break; + } + } + if (name.length()>name2.length()) { + return true; + } else + if (name.length()name2.charAt(i)) { + return true; + } + } + } + return false; + } + } public void onEnable() { - craftingrecipes = new ArrayList(); - smeltingrecipes = new ArrayList(); - shufflelist = new ArrayList(); - archivedshufflelist = new ArrayList(); - shufflelist2 = new ArrayList(); - recipeStorage = new ArrayList(); + // Bukkit.getLogger().setLevel(Level.WARNING); + Bukkit.resetRecipes(); + craftingrecipes = new ArrayList(); + smeltingrecipes = new ArrayList(); + shufflelist = new ArrayList(); + archivedshufflelist = new ArrayList(); + shufflelist2 = new ArrayList(); + recipeStorage = new ArrayList(); plugin = (Template)getPlugin(Template.class); r = new Random(Bukkit.getWorld("world").getSeed()); - List defaultRecipes = new ArrayList(); + Bukkit.getLogger().info("Random seed is "+Bukkit.getWorld("world").getSeed()); + LoadVillagerCount(); + List defaultRecipes = new ArrayList(); Iterator it = Bukkit.recipeIterator(); while (it.hasNext()) { - Recipe r = (Recipe)it.next(); - defaultRecipes.add(r); - shufflelist2.add(r.getResult()); - Bukkit.getLogger().info("Found a recipe for " + r.getResult()); + Recipe r = it.next(); + boolean added=false; + /*if (r instanceof BlastingRecipe || + r instanceof CampfireRecipe || + r instanceof SmokingRecipe || + r instanceof StonecuttingRecipe) {*/ + for (int i=0;i0) { + //Bukkit.getLogger().info(r.getResult().getType().name()+" is alphabetically after "+shufflelist2.get(shufflelist2.size()-1).getType().name()+". Inserting at the end."); + } + shufflelist2.add(r.getResult()); + defaultRecipes.add(r); + } + //Bukkit.getLogger().info("Found a recipe for " + r.getResult()); + //THIS LIST IS NOT SORTED. REQUIRES MANUAL SORTING. + //} + } + for (int i=0;i recipeTypeMap = new HashMap(); + HashMap recipeTypeMap = new HashMap(); + + int blastingrecipe = 0; + int campfirerecipe = 0; + int smokingrecipe = 0; + int stonecuttingrecipe = 0; + + for (int i=0;i 0) { - Recipe rr = (Recipe)defaultRecipes.get(r.nextInt(defaultRecipes.size())); + int recipe_id = r.nextInt(defaultRecipes.size()); + Recipe rr = defaultRecipes.get(recipe_id); + Bukkit.getLogger().info("Adding recipe for "+shufflelist2.get(0)+" at recipe "+recipe_id); boolean modified=true; - try { - if ((rr instanceof BlastingRecipe)) { - BlastingRecipe br = (BlastingRecipe)rr; - BlastingRecipe newbr = new BlastingRecipe(br.getKey(), (ItemStack)shufflelist2.get(0), br.getInputChoice(), br.getExperience(), br.getCookingTime()); - Bukkit.addRecipe(newbr); - } - else if ((rr instanceof CampfireRecipe)) { - CampfireRecipe br = (CampfireRecipe)rr; - CampfireRecipe newbr = new CampfireRecipe(br.getKey(), (ItemStack)shufflelist2.get(0), br.getInputChoice(), br.getExperience(), br.getCookingTime()); - Bukkit.addRecipe(newbr); - } - /*else if ((rr instanceof FurnaceRecipe)) { - FurnaceRecipe br = (FurnaceRecipe)rr; - FurnaceRecipe newbr = new FurnaceRecipe(br.getKey(), (ItemStack)shufflelist2.get(0), br.getInputChoice(), br.getExperience(), br.getCookingTime()); - Bukkit.addRecipe(newbr); - }*/ - else if ((rr instanceof MerchantRecipe)) { - MerchantRecipe br = (MerchantRecipe)rr; - MerchantRecipe newbr = new MerchantRecipe((ItemStack)shufflelist2.get(0), br.getUses(), br.getMaxUses(), true, br.getVillagerExperience(), br.getPriceMultiplier()); - Bukkit.addRecipe(newbr); - } - /*else if ((rr instanceof ShapedRecipe)) { - ShapedRecipe br = (ShapedRecipe)rr; - ShapedRecipe newbr = new ShapedRecipe((ItemStack)shufflelist2.get(0)); - newbr.shape(br.getShape()); - - for (Character c : br.getChoiceMap().keySet()) - { - newbr.setIngredient(c.charValue(), (RecipeChoice)br.getChoiceMap().get(c)); - } - Bukkit.addRecipe(newbr); - } - else if ((rr instanceof ShapelessRecipe)) { - ShapelessRecipe br = (ShapelessRecipe)rr; - ShapelessRecipe newbr = new ShapelessRecipe((ItemStack)shufflelist2.get(0)); - for (ItemStack i : br.getIngredientList()) { - newbr.addIngredient(i.getType()); - } - Bukkit.addRecipe(newbr); - }*/ - else if ((rr instanceof SmokingRecipe)) { - SmokingRecipe br = (SmokingRecipe)rr; - SmokingRecipe newbr = new SmokingRecipe(br.getKey(), (ItemStack)shufflelist2.get(0), br.getInputChoice(), br.getExperience(), br.getCookingTime()); - Bukkit.addRecipe(newbr); - } - else if ((rr instanceof StonecuttingRecipe)) { - StonecuttingRecipe br = (StonecuttingRecipe)rr; - StonecuttingRecipe newbr = new StonecuttingRecipe(br.getKey(), (ItemStack)shufflelist2.get(0), br.getInputChoice()); - Bukkit.addRecipe(newbr); - } else { - modified=false; - } - } - catch (IllegalStateException localIllegalStateException) {} + //int amt = Bukkit.getRecipesFor(shufflelist2.get(0)).size(); + if ((rr instanceof BlastingRecipe)) { + BlastingRecipe br = (BlastingRecipe)rr; + BlastingRecipe newbr = new BlastingRecipe(new NamespacedKey(plugin,"blasting_recipe"+shufflelist2.size()), shufflelist2.get(0), br.getInput().getType(), br.getExperience(), br.getCookingTime()); + Bukkit.addRecipe(newbr); + Bukkit.getLogger().info(" BLASTING"); + blastingrecipe++; + } + else if ((rr instanceof CampfireRecipe)) { + CampfireRecipe br = (CampfireRecipe)rr; + CampfireRecipe newbr = new CampfireRecipe(new NamespacedKey(plugin,"campfire_recipe"+shufflelist2.size()), shufflelist2.get(0), br.getInput().getType(), br.getExperience(), br.getCookingTime()); + Bukkit.addRecipe(newbr); + Bukkit.getLogger().info(" CAMPFIRE"); + campfirerecipe++; + } + /*else if ((rr instanceof FurnaceRecipe)) { + FurnaceRecipe br = (FurnaceRecipe)rr; + FurnaceRecipe newbr = new FurnaceRecipe(br.getKey(), (ItemStack)shufflelist2.get(0), br.getInputChoice(), br.getExperience(), br.getCookingTime()); + Bukkit.addRecipe(newbr); + }*/ + else if ((rr instanceof MerchantRecipe)) { + MerchantRecipe br = (MerchantRecipe)rr; + MerchantRecipe newbr = new MerchantRecipe(shufflelist2.get(0), br.getUses(), br.getMaxUses(), true, br.getVillagerExperience(), br.getPriceMultiplier()); + Bukkit.addRecipe(newbr); + } + /*else if ((rr instanceof ShapedRecipe)) { + ShapedRecipe br = (ShapedRecipe)rr; + ShapedRecipe newbr = new ShapedRecipe((ItemStack)shufflelist2.get(0)); + newbr.shape(br.getShape()); + + for (Character c : br.getChoiceMap().keySet()) + { + newbr.setIngredient(c.charValue(), (RecipeChoice)br.getChoiceMap().get(c)); + } + Bukkit.addRecipe(newbr); + } + else if ((rr instanceof ShapelessRecipe)) { + ShapelessRecipe br = (ShapelessRecipe)rr; + ShapelessRecipe newbr = new ShapelessRecipe((ItemStack)shufflelist2.get(0)); + for (ItemStack i : br.getIngredientList()) { + newbr.addIngredient(i.getType()); + } + Bukkit.addRecipe(newbr); + }*/ + else if ((rr instanceof SmokingRecipe)) { + SmokingRecipe br = (SmokingRecipe)rr; + SmokingRecipe newbr = new SmokingRecipe(new NamespacedKey(plugin,"smoking_recipe"+shufflelist2.size()), shufflelist2.get(0), br.getInput().getType(), br.getExperience(), br.getCookingTime()); + Bukkit.addRecipe(newbr); + Bukkit.getLogger().info(" SMOKING"); + smokingrecipe++; + } + else if ((rr instanceof StonecuttingRecipe)) { + StonecuttingRecipe br = (StonecuttingRecipe)rr; + StonecuttingRecipe newbr = new StonecuttingRecipe(new NamespacedKey(plugin,"stonecutting_recipe"+shufflelist2.size()), shufflelist2.get(0), br.getInput().getType()); + Bukkit.addRecipe(newbr); + Bukkit.getLogger().info(" STONECUTTING"); + stonecuttingrecipe++; + } else { + Bukkit.getLogger().info(" UNMODIFIED ("+rr.getClass().getName()+")"); + modified=false; + } if (modified) { recipeTypeMap.put(rr.getClass().getName(), Integer.valueOf(recipeTypeMap.containsKey(rr.getClass().getName()) ? ((Integer)recipeTypeMap.get(rr.getClass().getName())).intValue() + 1 : 1)); @@ -392,10 +475,16 @@ public class Template setBreedingTable(); randomMelonItem = new ItemStack(Material.getMaterial(Template.archivedshufflelist.get(Template.r.nextInt(Template.archivedshufflelist.size())))); - + + for (String s : recipeTypeMap.keySet()) { Bukkit.getLogger().info(" Randomized " + recipeTypeMap.get(s) + " " + s + " recipes."); } + Bukkit.getLogger().info(""); + Bukkit.getLogger().info("Blasting: "+blastingrecipe); + Bukkit.getLogger().info("Campefire: "+campfirerecipe); + Bukkit.getLogger().info("Smoking: "+smokingrecipe); + Bukkit.getLogger().info("Stonecutting: "+stonecuttingrecipe); PluginManager pm = getServer().getPluginManager(); @@ -405,4 +494,30 @@ public class Template finished=true; } + + public static void LoadVillagerCount() { + File f = new File("villager_count"); + if (f.exists()) { + try { + FileReader fr = new FileReader(f); + BufferedReader br = new BufferedReader(fr); + villager_count = Integer.parseInt(br.readLine()); + Bukkit.getLogger().info(villager_count+" Villagers loaded."); + br.close(); + fr.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + public static void IncreaseAndSaveVillagerCount() { + File f = new File("villager_count"); + try { + FileWriter fw = new FileWriter(f); + fw.write((++villager_count)+""); + fw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } } diff --git a/MCRandomizer/src/scramble/plugin/listener/ExampleListener.java b/MCRandomizer/src/scramble/plugin/listener/ExampleListener.java index 2f2fd02..7242947 100644 --- a/MCRandomizer/src/scramble/plugin/listener/ExampleListener.java +++ b/MCRandomizer/src/scramble/plugin/listener/ExampleListener.java @@ -28,6 +28,7 @@ import org.bukkit.event.inventory.CraftItemEvent; import org.bukkit.event.inventory.FurnaceSmeltEvent; import org.bukkit.event.inventory.PrepareItemCraftEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.Merchant; import org.bukkit.inventory.MerchantRecipe; import org.bukkit.inventory.Recipe; import org.bukkit.inventory.RecipeChoice; @@ -61,18 +62,18 @@ public class ExampleListener implements Listener { public String GenerateRandomName() { StringBuilder name = new StringBuilder(); - boolean consonant=Template.r.nextInt(2)==0; - int strlength = Template.r.nextInt(Template.randomizeAmount(2)+5); - boolean first=false; + Random namer = new Random(Template.villager_count); + boolean consonant=namer.nextInt(2)==0; + int strlength = namer.nextInt(Template.randomizeAmount(namer,2)+5)+1; while ((strlength--)>0) { if (consonant) { - String letter = consonants[Template.r.nextInt(consonants.length)]; + String letter = consonants[namer.nextInt(consonants.length)]; name.append(letter); - if (Template.r.nextInt(4)==0 && Math.abs(name.length()-strlength)<=3) { + if (namer.nextInt(4)==0 && Math.abs(name.length()-strlength)<=3) { name.append(letter); } } else { - name.append(vowels[Template.r.nextInt(vowels.length)]); + name.append(vowels[namer.nextInt(vowels.length)]); } consonant=!consonant; } @@ -88,8 +89,14 @@ public class ExampleListener implements Listener { //Bukkit.getLogger().info(ev.getEntity()+" getting "+ev.getRecipe()); if (ev.getEntity().getCustomName()==null || ev.getEntity().getCustomName().length()==0) { ev.getEntity().setCustomName(GenerateRandomName()); + Template.IncreaseAndSaveVillagerCount(); } + Merchant mm = (Merchant)ev.getEntity(); + //Bukkit.getLogger().info(""+mm.getRecipeCount()); Random ff = new Random(ev.getEntity().getCustomName().hashCode()); + for (int i=0;i