Skip to content

Commit

Permalink
Fixing some NPEs in the menu builder, altering some length title mess…
Browse files Browse the repository at this point in the history
…ages because of Bukkits 32 char limit
  • Loading branch information
ProgrammerDan committed Feb 6, 2016
1 parent 8c69355 commit 8bf6c6a
Showing 1 changed file with 30 additions and 31 deletions.
61 changes: 30 additions & 31 deletions src/com/github/igotyou/FactoryMod/utility/MenuBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public void openFactoryBrowser(Player p, String startingFac) {
// creation option
ItemStack creationStack = new ItemStack(Material.CHEST);
ISUtils.setName(creationStack, "Setup");
ISUtils.addLore(creationStack, ChatColor.LIGHT_PURPLE
+ "Click to display more information",
ISUtils.addLore(creationStack,
ChatColor.LIGHT_PURPLE + "Click to display more information",
ChatColor.LIGHT_PURPLE + "on how to setup this factory");
Clickable creationClickable = new Clickable(creationStack) {
@Override
Expand Down Expand Up @@ -139,10 +139,9 @@ public void clicked(Player arg0) {
// upgrade option
ItemStack upgradeStack = new ItemStack(Material.FURNACE);
ISUtils.setName(upgradeStack, "Upgrades");
ISUtils.addLore(upgradeStack, ChatColor.LIGHT_PURPLE
+ "Click to display more information about",
ChatColor.LIGHT_PURPLE
+ "the possible upgrades to this factory");
ISUtils.addLore(upgradeStack,
ChatColor.LIGHT_PURPLE + "Click to display more information about",
ChatColor.LIGHT_PURPLE + "the possible upgrades to this factory");
Clickable upgradeClickable = new Clickable(upgradeStack) {
@Override
public void clicked(Player arg0) {
Expand All @@ -159,12 +158,15 @@ public void clicked(Player arg0) {
private void openRecipeBrowser(Player p, String facName) {
ClickableInventory.forceCloseInventory(p);
ClickableInventory recipeInventory = new ClickableInventory(36,
"All recipes for " + facName);
"Recipes for " + facName); // Bukkit has 32 char limit on inventory
FurnCraftChestEgg egg = (FurnCraftChestEgg) manager.getEgg(facName);
List<IRecipe> recipes = egg.getRecipes();

// put recipes
for (int i = 0; i < recipes.size(); i++) {
if (recipes.get(i) == null) {
continue;
}
Clickable c = new Clickable(
((InputRecipe) recipes.get(i)).getRecipeRepresentation()) {
@Override
Expand All @@ -179,8 +181,8 @@ public void clicked(Player arg0) {
// back option
ItemStack backStack = new ItemStack(Material.ARROW);
ISUtils.setName(backStack, "Back to factory overview");
ISUtils.addLore(backStack, ChatColor.LIGHT_PURPLE
+ "Click to go back");
ISUtils.addLore(backStack,
ChatColor.LIGHT_PURPLE + "Click to go back");
Clickable backClickable = new Clickable(backStack) {
@Override
public void clicked(Player arg0) {
Expand All @@ -197,21 +199,19 @@ private void openSetupBrowser(Player p, String facName) {
FurnCraftChestEgg egg = (FurnCraftChestEgg) manager.getEgg(facName);
FurnCraftChestEgg parEgg = (FurnCraftChestEgg) manager
.getEgg(parentFactories.get(facName));
ClickableInventory ci = new ClickableInventory(54, "How to get a "
+ egg.getName());
ClickableInventory ci = new ClickableInventory(54, "Create a "
+ egg.getName()); // Bukkit has 32 char limit on inventory
ItemStack cr = new ItemStack(Material.WORKBENCH);
ItemStack fur = new ItemStack(Material.FURNACE);
ItemStack che = new ItemStack(Material.CHEST);
if (parEgg == null) {// creation factory
ISUtils.setLore(cr, ChatColor.LIGHT_PURPLE
+ "This factory can be created with",
ChatColor.LIGHT_PURPLE
+ "a normal crafting table, furnace and chest");
ISUtils.setLore(che, ChatColor.LIGHT_PURPLE
+ "Arrange the 3 blocks like this,", ChatColor.LIGHT_PURPLE
+ "put the materials below in the chest",
ChatColor.LIGHT_PURPLE
+ "and hit the craftingtable with a stick");
ISUtils.setLore(cr,
ChatColor.LIGHT_PURPLE + "This factory can be created with",
ChatColor.LIGHT_PURPLE + "a normal crafting table, furnace and chest");
ISUtils.setLore(che,
ChatColor.LIGHT_PURPLE + "Arrange the 3 blocks like this,",
ChatColor.LIGHT_PURPLE + "put the materials below in the chest",
ChatColor.LIGHT_PURPLE + "and hit the crafting table with a stick");
DecorationStack furnDec = new DecorationStack(fur);
DecorationStack chestDec = new DecorationStack(che);
DecorationStack craStack = new DecorationStack(cr);
Expand Down Expand Up @@ -256,8 +256,9 @@ public void clicked(Player arg0) {
}
};
ci.setSlot(craCli, 4);
ISUtils.setLore(fur, ChatColor.LIGHT_PURPLE
+ "Click to display information", ChatColor.LIGHT_PURPLE + "on this factory");
ISUtils.setLore(fur,
ChatColor.LIGHT_PURPLE + "Click to display information",
ChatColor.LIGHT_PURPLE + "on this factory");
Clickable furCli = new Clickable(fur) {
@Override
public void clicked(Player arg0) {
Expand Down Expand Up @@ -296,8 +297,7 @@ public void clicked(Player arg0) {
ci.setSlot(input, 22);
ItemStack backStack = new ItemStack(Material.ARROW);
ISUtils.setName(backStack, "Back to factory overview");
ISUtils.addLore(backStack, ChatColor.LIGHT_PURPLE
+ "Click to go back");
ISUtils.addLore(backStack, ChatColor.LIGHT_PURPLE + "Click to go back");
Clickable backClickable = new Clickable(backStack) {
@Override
public void clicked(Player arg0) {
Expand All @@ -312,18 +312,18 @@ private void openUpgradeBrowser(Player p, String facName) {
ClickableInventory.forceCloseInventory(p);
FurnCraftChestEgg egg = (FurnCraftChestEgg) manager
.getEgg(factoryViewed.get(p.getUniqueId()));
ClickableInventory ci = new ClickableInventory(18, "Possible upgrades");
List<IRecipe> upgrades = new LinkedList<IRecipe>();
for (IRecipe recipe : egg.getRecipes()) {
if (recipe instanceof Upgraderecipe) {
upgrades.add(recipe);
}
}
ClickableInventory ci = new ClickableInventory(
Math.max(18, (upgrades.size() / 9) * 9), "Possible upgrades");
if (upgrades.size() == 0) {
ItemStack bar = new ItemStack(Material.BARRIER);
ISUtils.setName(bar, "No upgrades available");
ISUtils.addLore(bar, ChatColor.LIGHT_PURPLE
+ "Click to go back");
ISUtils.addLore(bar, ChatColor.LIGHT_PURPLE + "Click to go back");
Clickable noUpgrades = new Clickable(bar) {
@Override
public void clicked(Player p) {
Expand All @@ -335,8 +335,8 @@ public void clicked(Player p) {
for (IRecipe recipe : upgrades) {
ItemStack recStack = ((InputRecipe) recipe)
.getRecipeRepresentation();
ISUtils.setLore(recStack, ChatColor.LIGHT_PURPLE
+ "Click to display more information");
ISUtils.setLore(recStack,
ChatColor.LIGHT_PURPLE + "Click to display more information");
Clickable c = new Clickable(
((InputRecipe) recipe).getRecipeRepresentation()) {
@Override
Expand All @@ -350,8 +350,7 @@ public void clicked(Player p) {
}
ItemStack backStack = new ItemStack(Material.ARROW);
ISUtils.setName(backStack, "Back to factory overview");
ISUtils.addLore(backStack, ChatColor.LIGHT_PURPLE
+ "Click to go back");
ISUtils.addLore(backStack, ChatColor.LIGHT_PURPLE + "Click to go back");
Clickable backClickable = new Clickable(backStack) {
@Override
public void clicked(Player arg0) {
Expand Down

0 comments on commit 8bf6c6a

Please sign in to comment.