Skip to content

Commit 8bf6c6a

Browse files
committed
Fixing some NPEs in the menu builder, altering some length title messages because of Bukkits 32 char limit
1 parent 8c69355 commit 8bf6c6a

1 file changed

Lines changed: 30 additions & 31 deletions

File tree

src/com/github/igotyou/FactoryMod/utility/MenuBuilder.java

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ public void openFactoryBrowser(Player p, String startingFac) {
109109
// creation option
110110
ItemStack creationStack = new ItemStack(Material.CHEST);
111111
ISUtils.setName(creationStack, "Setup");
112-
ISUtils.addLore(creationStack, ChatColor.LIGHT_PURPLE
113-
+ "Click to display more information",
112+
ISUtils.addLore(creationStack,
113+
ChatColor.LIGHT_PURPLE + "Click to display more information",
114114
ChatColor.LIGHT_PURPLE + "on how to setup this factory");
115115
Clickable creationClickable = new Clickable(creationStack) {
116116
@Override
@@ -139,10 +139,9 @@ public void clicked(Player arg0) {
139139
// upgrade option
140140
ItemStack upgradeStack = new ItemStack(Material.FURNACE);
141141
ISUtils.setName(upgradeStack, "Upgrades");
142-
ISUtils.addLore(upgradeStack, ChatColor.LIGHT_PURPLE
143-
+ "Click to display more information about",
144-
ChatColor.LIGHT_PURPLE
145-
+ "the possible upgrades to this factory");
142+
ISUtils.addLore(upgradeStack,
143+
ChatColor.LIGHT_PURPLE + "Click to display more information about",
144+
ChatColor.LIGHT_PURPLE + "the possible upgrades to this factory");
146145
Clickable upgradeClickable = new Clickable(upgradeStack) {
147146
@Override
148147
public void clicked(Player arg0) {
@@ -159,12 +158,15 @@ public void clicked(Player arg0) {
159158
private void openRecipeBrowser(Player p, String facName) {
160159
ClickableInventory.forceCloseInventory(p);
161160
ClickableInventory recipeInventory = new ClickableInventory(36,
162-
"All recipes for " + facName);
161+
"Recipes for " + facName); // Bukkit has 32 char limit on inventory
163162
FurnCraftChestEgg egg = (FurnCraftChestEgg) manager.getEgg(facName);
164163
List<IRecipe> recipes = egg.getRecipes();
165164

166165
// put recipes
167166
for (int i = 0; i < recipes.size(); i++) {
167+
if (recipes.get(i) == null) {
168+
continue;
169+
}
168170
Clickable c = new Clickable(
169171
((InputRecipe) recipes.get(i)).getRecipeRepresentation()) {
170172
@Override
@@ -179,8 +181,8 @@ public void clicked(Player arg0) {
179181
// back option
180182
ItemStack backStack = new ItemStack(Material.ARROW);
181183
ISUtils.setName(backStack, "Back to factory overview");
182-
ISUtils.addLore(backStack, ChatColor.LIGHT_PURPLE
183-
+ "Click to go back");
184+
ISUtils.addLore(backStack,
185+
ChatColor.LIGHT_PURPLE + "Click to go back");
184186
Clickable backClickable = new Clickable(backStack) {
185187
@Override
186188
public void clicked(Player arg0) {
@@ -197,21 +199,19 @@ private void openSetupBrowser(Player p, String facName) {
197199
FurnCraftChestEgg egg = (FurnCraftChestEgg) manager.getEgg(facName);
198200
FurnCraftChestEgg parEgg = (FurnCraftChestEgg) manager
199201
.getEgg(parentFactories.get(facName));
200-
ClickableInventory ci = new ClickableInventory(54, "How to get a "
201-
+ egg.getName());
202+
ClickableInventory ci = new ClickableInventory(54, "Create a "
203+
+ egg.getName()); // Bukkit has 32 char limit on inventory
202204
ItemStack cr = new ItemStack(Material.WORKBENCH);
203205
ItemStack fur = new ItemStack(Material.FURNACE);
204206
ItemStack che = new ItemStack(Material.CHEST);
205207
if (parEgg == null) {// creation factory
206-
ISUtils.setLore(cr, ChatColor.LIGHT_PURPLE
207-
+ "This factory can be created with",
208-
ChatColor.LIGHT_PURPLE
209-
+ "a normal crafting table, furnace and chest");
210-
ISUtils.setLore(che, ChatColor.LIGHT_PURPLE
211-
+ "Arrange the 3 blocks like this,", ChatColor.LIGHT_PURPLE
212-
+ "put the materials below in the chest",
213-
ChatColor.LIGHT_PURPLE
214-
+ "and hit the craftingtable with a stick");
208+
ISUtils.setLore(cr,
209+
ChatColor.LIGHT_PURPLE + "This factory can be created with",
210+
ChatColor.LIGHT_PURPLE + "a normal crafting table, furnace and chest");
211+
ISUtils.setLore(che,
212+
ChatColor.LIGHT_PURPLE + "Arrange the 3 blocks like this,",
213+
ChatColor.LIGHT_PURPLE + "put the materials below in the chest",
214+
ChatColor.LIGHT_PURPLE + "and hit the crafting table with a stick");
215215
DecorationStack furnDec = new DecorationStack(fur);
216216
DecorationStack chestDec = new DecorationStack(che);
217217
DecorationStack craStack = new DecorationStack(cr);
@@ -256,8 +256,9 @@ public void clicked(Player arg0) {
256256
}
257257
};
258258
ci.setSlot(craCli, 4);
259-
ISUtils.setLore(fur, ChatColor.LIGHT_PURPLE
260-
+ "Click to display information", ChatColor.LIGHT_PURPLE + "on this factory");
259+
ISUtils.setLore(fur,
260+
ChatColor.LIGHT_PURPLE + "Click to display information",
261+
ChatColor.LIGHT_PURPLE + "on this factory");
261262
Clickable furCli = new Clickable(fur) {
262263
@Override
263264
public void clicked(Player arg0) {
@@ -296,8 +297,7 @@ public void clicked(Player arg0) {
296297
ci.setSlot(input, 22);
297298
ItemStack backStack = new ItemStack(Material.ARROW);
298299
ISUtils.setName(backStack, "Back to factory overview");
299-
ISUtils.addLore(backStack, ChatColor.LIGHT_PURPLE
300-
+ "Click to go back");
300+
ISUtils.addLore(backStack, ChatColor.LIGHT_PURPLE + "Click to go back");
301301
Clickable backClickable = new Clickable(backStack) {
302302
@Override
303303
public void clicked(Player arg0) {
@@ -312,18 +312,18 @@ private void openUpgradeBrowser(Player p, String facName) {
312312
ClickableInventory.forceCloseInventory(p);
313313
FurnCraftChestEgg egg = (FurnCraftChestEgg) manager
314314
.getEgg(factoryViewed.get(p.getUniqueId()));
315-
ClickableInventory ci = new ClickableInventory(18, "Possible upgrades");
316315
List<IRecipe> upgrades = new LinkedList<IRecipe>();
317316
for (IRecipe recipe : egg.getRecipes()) {
318317
if (recipe instanceof Upgraderecipe) {
319318
upgrades.add(recipe);
320319
}
321320
}
321+
ClickableInventory ci = new ClickableInventory(
322+
Math.max(18, (upgrades.size() / 9) * 9), "Possible upgrades");
322323
if (upgrades.size() == 0) {
323324
ItemStack bar = new ItemStack(Material.BARRIER);
324325
ISUtils.setName(bar, "No upgrades available");
325-
ISUtils.addLore(bar, ChatColor.LIGHT_PURPLE
326-
+ "Click to go back");
326+
ISUtils.addLore(bar, ChatColor.LIGHT_PURPLE + "Click to go back");
327327
Clickable noUpgrades = new Clickable(bar) {
328328
@Override
329329
public void clicked(Player p) {
@@ -335,8 +335,8 @@ public void clicked(Player p) {
335335
for (IRecipe recipe : upgrades) {
336336
ItemStack recStack = ((InputRecipe) recipe)
337337
.getRecipeRepresentation();
338-
ISUtils.setLore(recStack, ChatColor.LIGHT_PURPLE
339-
+ "Click to display more information");
338+
ISUtils.setLore(recStack,
339+
ChatColor.LIGHT_PURPLE + "Click to display more information");
340340
Clickable c = new Clickable(
341341
((InputRecipe) recipe).getRecipeRepresentation()) {
342342
@Override
@@ -350,8 +350,7 @@ public void clicked(Player p) {
350350
}
351351
ItemStack backStack = new ItemStack(Material.ARROW);
352352
ISUtils.setName(backStack, "Back to factory overview");
353-
ISUtils.addLore(backStack, ChatColor.LIGHT_PURPLE
354-
+ "Click to go back");
353+
ISUtils.addLore(backStack, ChatColor.LIGHT_PURPLE + "Click to go back");
355354
Clickable backClickable = new Clickable(backStack) {
356355
@Override
357356
public void clicked(Player arg0) {

0 commit comments

Comments
 (0)