Skip to content

Commit

Permalink
Change internal instruction handling
Browse files Browse the repository at this point in the history
An instruction is now an object with several methods used for parsing
the data. All quest objects (events, conditions etc.) are now referenced
by ID implementations (EventID, ConditionID etc.) which store their
package and name.
  • Loading branch information
RiledUpCrow committed Oct 7, 2016
1 parent 1a9a68f commit fff3ac7
Show file tree
Hide file tree
Showing 185 changed files with 2,731 additions and 2,874 deletions.
94 changes: 41 additions & 53 deletions src/main/java/pl/betoncraft/betonquest/Backpack.java
Expand Up @@ -204,17 +204,14 @@ public Page(int page) {
// if there are other pages, place the buttons
if (page > 0) {
ItemStack previous = null;
String item = Config.getString("default.items.previous_button");
if (item != null) {
try {
previous = new QuestItem(item).generateItem(1);
} catch (InstructionParseException e) {
Debug.error("Could not load previous button: " + e.getMessage());
player.closeInventory();
return;
}
} else {
try {
previous = new QuestItem(new ItemID(Config.getPackage("default"), "previous_button")).generateItem(1);
} catch (ObjectNotFoundException e) {
previous = new ItemStack(Material.GLOWSTONE_DUST);
} catch (InstructionParseException e) {
Debug.error("Could not load previous button: " + e.getMessage());
player.closeInventory();
return;
}
ItemMeta meta = previous.getItemMeta();
meta.setDisplayName(Config.getMessage(lang, "previous").replaceAll("&", "§"));
Expand All @@ -223,17 +220,14 @@ public Page(int page) {
}
if (backpackItems.size() > (page + 1) * 45 - 1) {
ItemStack next;
String item = Config.getString("default.items.next_button");
if (item != null) {
try {
next = new QuestItem(item).generateItem(1);
} catch (InstructionParseException e) {
Debug.error("Could not load next button: " + e.getMessage());
player.closeInventory();
return;
}
} else {
try {
next = new QuestItem(new ItemID(Config.getPackage("default"), "next_button")).generateItem(1);
} catch (ObjectNotFoundException e) {
next = new ItemStack(Material.REDSTONE);
} catch (InstructionParseException e) {
Debug.error("Could not load next button: " + e.getMessage());
player.closeInventory();
return;
}
ItemMeta meta = next.getItemMeta();
meta.setDisplayName(Config.getMessage(lang, "next").replaceAll("&", "§"));
Expand All @@ -242,33 +236,29 @@ public Page(int page) {
}
// set "cancel quest" button
ItemStack cancel;
String item = Config.getString("default.items.cancel_button");
if (item != null) {
try {
cancel = new QuestItem(item).generateItem(1);
} catch (InstructionParseException e) {
Debug.error("Could not load cancel button: " + e.getMessage());
cancel = new ItemStack(Material.BONE);
}
} else {
try {
cancel = new QuestItem(new ItemID(Config.getPackage("default"), "cancel_button")).generateItem(1);
} catch (ObjectNotFoundException e) {
cancel = new ItemStack(Material.BONE);
} catch (InstructionParseException e) {
Debug.error("Could not load cancel button: " + e.getMessage());
player.closeInventory();
return;
}
ItemMeta meta = cancel.getItemMeta();
meta.setDisplayName(Config.getMessage(lang, "cancel").replaceAll("&", "§"));
cancel.setItemMeta(meta);
content[45] = cancel;
// set "compass targets" button
ItemStack compassItem;
String compassInstruction = Config.getString("default.items.compass_button");
if (compassInstruction != null) {
try {
compassItem = new QuestItem(compassInstruction).generateItem(1);
} catch (InstructionParseException e) {
Debug.error("Could not load compass button: " + e.getMessage());
compassItem = new ItemStack(Material.COMPASS);
}
} else {
try {
compassItem = new QuestItem(new ItemID(Config.getPackage("default"), "compass_button")).generateItem(1);
} catch (ObjectNotFoundException e) {
compassItem = new ItemStack(Material.COMPASS);
} catch (InstructionParseException e) {
Debug.error("Could not load compass button: " + e.getMessage());
player.closeInventory();
return;
}
ItemMeta compassMeta = compassItem.getItemMeta();
compassMeta.setDisplayName(Config.getMessage(lang, "compass").replace('&', '&'));
Expand Down Expand Up @@ -523,25 +513,23 @@ public Compass() {
int i = 0;
for (Integer slot : locations.keySet()) {
String name = names.get(slot);
String itemID = items.get(slot);
String item = items.get(slot);
ItemStack compass = null;
if (itemID != null) {
try {
compass = new QuestItem(Config.getString(itemID)).generateItem(1);
} catch (InstructionParseException e) {
Debug.error("Could not load compass button: " + e.getMessage());
try {
compass = new QuestItem(new ItemID(Config.getPackage("default"), item)).generateItem(1);
} catch (InstructionParseException e) {
Debug.error("Could not load compass button: " + e.getMessage());
player.closeInventory();
return;
} catch (NullPointerException e) {
if (e.getMessage().equals("Item instruction is null")) {
player.closeInventory();
return;
} catch (NullPointerException e) {
if (e.getMessage().equals("Item instruction is null")) {
player.closeInventory();
return;
} else {
e.printStackTrace();
return;
}
} else {
e.printStackTrace();
return;
}
} else {
} catch (ObjectNotFoundException e) {
compass = new ItemStack(Material.COMPASS);
}
ItemMeta meta = compass.getItemMeta();
Expand Down

0 comments on commit fff3ac7

Please sign in to comment.