Fix item prompts (including load from hand), add invalid delivery item

msg and update lang
This commit is contained in:
HappyPikachu 2015-02-11 20:05:45 -05:00
parent d8bb3718c8
commit 9f9e94422e
3 changed files with 58 additions and 28 deletions

View File

@ -12,6 +12,7 @@ import net.citizensnpcs.api.event.NPCRightClickEvent;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.conversations.Conversable;
import org.bukkit.conversations.Conversation;
import org.bukkit.entity.Entity;
@ -64,10 +65,10 @@ public class NpcListener implements Listener {
}
if (found != null) {
NPC clicked = evt.getNPC();
if (found != null) {
for (Integer n : quester.getCurrentStage(quest).itemDeliveryTargets) {
if (n == clicked.getId()) {
quester.deliverItem(quest, hand);
@ -78,6 +79,31 @@ public class NpcListener implements Listener {
break;
} else if (!hand.getType().equals(Material.AIR)){
for (Integer n : quester.getCurrentStage(quest).itemDeliveryTargets) {
if (n == clicked.getId()) {
String text = "";
if (hand.hasItemMeta()) {
text += ChatColor.LIGHT_PURPLE + "" + ChatColor.ITALIC + (hand.getItemMeta().hasDisplayName() ? hand.getItemMeta().getDisplayName() + ChatColor.GRAY + " (" : "");
}
text += ChatColor.AQUA + Quester.prettyItemString(hand.getType().name()) + (hand.getDurability() != 0 ? (":" + hand.getDurability()) : "") + ChatColor.GRAY;
if (hand.hasItemMeta()) {
text += (hand.getItemMeta().hasDisplayName() ? ")" : "");
}
text += " x " + ChatColor.DARK_AQUA + hand.getAmount() + ChatColor.GRAY;
evt.getClicker().sendMessage(Lang.get("questInvalidDeliveryItem").replaceAll("<item>", text));
break;
}
}
break;
}
}

View File

@ -27,10 +27,11 @@ import org.bukkit.inventory.meta.ItemMeta;
public class ItemStackPrompt extends FixedSetPrompt implements ColorUtil {
//Stores itemstack in "tempStack" context data.
//Stores name in "tempName"
//Stores amount in "tempAmount"
//Stores data in "tempData"
//Stores enchantments in "tempEnchantments"
//Stores name in "tempName"
//Stores display name in "tempDisplay"
//Stores lore in "tempLore"
final Prompt oldPrompt;
@ -57,7 +58,7 @@ public class ItemStackPrompt extends FixedSetPrompt implements ColorUtil {
menu += YELLOW + "" + BOLD + "2. " + RESET + "" + GOLD + Lang.get("itemCreateSetAmount") + "\n";
menu += YELLOW + "" + BOLD + "3. " + RESET + "" + GOLD + Lang.get("itemCreateSetData") + "\n";
menu += YELLOW + "" + BOLD + "4. " + RESET + "" + GOLD + Lang.get("itemCreateSetEnchs") + "\n";
menu += YELLOW + "" + BOLD + "5. " + RESET + "" + ITALIC + GOLD + Lang.get("itemCreateSetName") + "\n";
menu += YELLOW + "" + BOLD + "5. " + RESET + "" + ITALIC + GOLD + Lang.get("itemCreateSetDisplay") + "\n";
menu += YELLOW + "" + BOLD + "6. " + RESET + "" + ITALIC + GOLD + Lang.get("itemCreateSetLore") + "\n";
menu += YELLOW + "" + BOLD + "7. " + RESET + "" + RED + Lang.get("cancel") + "\n";
menu += YELLOW + "" + BOLD + "8. " + RESET + "" + GREEN + Lang.get("done") + "\n";
@ -79,11 +80,12 @@ public class ItemStackPrompt extends FixedSetPrompt implements ColorUtil {
} else {
cc.setSessionData("tempName", is.getType().name());
cc.setSessionData("tempAmount", is.getAmount());
cc.setSessionData("tempData", null);
cc.setSessionData("tempEnchantments", null);
cc.setSessionData("tempName", null);
cc.setSessionData("tempDisplay", null);
cc.setSessionData("tempLore", null);
cc.setSessionData("tempAmount", is.getAmount());
if (is.getDurability() != 0) {
cc.setSessionData("tempData", is.getDurability());
}
@ -94,7 +96,7 @@ public class ItemStackPrompt extends FixedSetPrompt implements ColorUtil {
ItemMeta meta = is.getItemMeta();
if (meta.hasDisplayName()) {
cc.setSessionData("tempName", ChatColor.stripColor(meta.getDisplayName()));
cc.setSessionData("tempDisplay", ChatColor.stripColor(meta.getDisplayName()));
}
if (meta.hasLore()) {
LinkedList<String> lore = new LinkedList<String>();
@ -110,7 +112,7 @@ public class ItemStackPrompt extends FixedSetPrompt implements ColorUtil {
}
} else if (input.equalsIgnoreCase("1")) {
return new IDPrompt();
return new NamePrompt();
} else if (input.equalsIgnoreCase("2")) {
if (cc.getSessionData("tempName") != null) {
@ -141,7 +143,7 @@ public class ItemStackPrompt extends FixedSetPrompt implements ColorUtil {
} else if (input.equalsIgnoreCase("5")) {
if (cc.getSessionData("tempName") != null && cc.getSessionData("tempAmount") != null) {
return new NamePrompt();
return new DisplayPrompt();
} else {
cc.getForWhom().sendRawMessage(RED + Lang.get("itemCreateNoNameAmount"));
return new ItemStackPrompt(oldPrompt);
@ -159,20 +161,22 @@ public class ItemStackPrompt extends FixedSetPrompt implements ColorUtil {
} else if (input.equalsIgnoreCase("7")) {
cc.setSessionData("tempStack", null);
cc.setSessionData("tempName", null);
cc.setSessionData("tempAmount", null);
cc.setSessionData("tempData", null);
cc.setSessionData("tempEnchantments", null);
cc.setSessionData("tempName", null);
cc.setSessionData("tempDisplay", null);
cc.setSessionData("tempLore", null);
} else if (input.equalsIgnoreCase("8")) {
if (cc.getSessionData("tempName") != null && cc.getSessionData("tempAmount") != null) {
String name = (String) cc.getSessionData("tempName");
int amount = (Integer) cc.getSessionData("tempAmount");
short data = -1;
Map<Enchantment, Integer> enchs = null;
String name = null;
String display = null;
LinkedList<String> lore = null;
if (cc.getSessionData("tempData") != null) {
@ -181,8 +185,8 @@ public class ItemStackPrompt extends FixedSetPrompt implements ColorUtil {
if (cc.getSessionData("tempEnchantments") != null) {
enchs = (Map<Enchantment, Integer>) cc.getSessionData("tempEnchantments");
}
if (cc.getSessionData("tempName") != null) {
name = (String) cc.getSessionData("tempName");
if (cc.getSessionData("tempDisplay") != null) {
display = (String) cc.getSessionData("tempDisplay");
}
if (cc.getSessionData("tempLore") != null) {
lore = (LinkedList<String>) cc.getSessionData("tempLore");
@ -199,8 +203,8 @@ public class ItemStackPrompt extends FixedSetPrompt implements ColorUtil {
meta.addEnchant(e.getKey(), e.getValue(), true);
}
}
if (name != null) {
meta.setDisplayName(name);
if (display != null) {
meta.setDisplayName(display);
}
if (lore != null) {
meta.setLore(lore);
@ -210,7 +214,6 @@ public class ItemStackPrompt extends FixedSetPrompt implements ColorUtil {
cc.setSessionData("tempStack", stack);
cc.setSessionData("newItem", Boolean.TRUE);
} else {
cc.getForWhom().sendRawMessage(RED + Lang.get("itemCreateNoNameAmount"));
return new ItemStackPrompt(oldPrompt);
@ -226,7 +229,7 @@ public class ItemStackPrompt extends FixedSetPrompt implements ColorUtil {
}
}
private class IDPrompt extends StringPrompt {
private class NamePrompt extends StringPrompt {
@Override
public String getPromptText(ConversationContext cc) {
@ -249,7 +252,7 @@ public class ItemStackPrompt extends FixedSetPrompt implements ColorUtil {
Material mat = ItemData.getMaterial(input);
if (mat == null) {
cc.getForWhom().sendRawMessage(RED + Lang.get("itemCreateInvalidName"));
return new IDPrompt();
return new NamePrompt();
} else {
cc.setSessionData("tempName", mat.name());
@ -261,7 +264,7 @@ public class ItemStackPrompt extends FixedSetPrompt implements ColorUtil {
cc.setSessionData("tempData", data);
} catch (NumberFormatException e) {
cc.getForWhom().sendRawMessage(RED + Lang.get("itemCreateInvalidData"));
return new IDPrompt();
return new NamePrompt();
}
}
return new ItemStackPrompt(oldPrompt);
@ -447,7 +450,7 @@ public class ItemStackPrompt extends FixedSetPrompt implements ColorUtil {
}
private class NamePrompt extends StringPrompt {
private class DisplayPrompt extends StringPrompt {
@Override
public String getPromptText(ConversationContext cc) {
@ -460,11 +463,11 @@ public class ItemStackPrompt extends FixedSetPrompt implements ColorUtil {
input = Quests.parseString(input);
cc.setSessionData("tempName", input);
cc.setSessionData("tempDisplay", input);
} else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) {
cc.setSessionData("tempName", null);
cc.setSessionData("tempDisplay", null);
}
@ -509,7 +512,7 @@ public class ItemStackPrompt extends FixedSetPrompt implements ColorUtil {
String item;
if (cc.getSessionData("tempName") == null) {
if (cc.getSessionData("tempDisplay") == null) {
String name = (String) cc.getSessionData("tempName");
item = AQUA + Quester.prettyItemString(name);
@ -520,7 +523,7 @@ public class ItemStackPrompt extends FixedSetPrompt implements ColorUtil {
} else {
item = PINK + "" + ITALIC + (String) cc.getSessionData("tempName") + RESET + "" + GRAY + " (";
item = PINK + "" + ITALIC + (String) cc.getSessionData("tempDisplay") + RESET + "" + GRAY + " (";
String name = (String) cc.getSessionData("tempName");
item += AQUA + Quester.prettyItemString(name);
if (cc.getSessionData("tempData") != null) {

View File

@ -90,6 +90,7 @@ public class Lang {
langMap.put("questTooEarly", "You may not take <quest> again for another <time>.");
langMap.put("questAlreadyCompleted", "You have already completed <quest>.");
langMap.put("questInvalidLocation", "You may not take <quest> at this location.");
langMap.put("questInvalidDeliveryItem", "<item> is not a required item for this quest!");
langMap.put("questSelectedLocation", "Selected location");
@ -717,10 +718,10 @@ public class Lang {
//Item Prompt
langMap.put("itemCreateLoadHand", "Load item in hand");
langMap.put("itemCreateSetName", "Set name");
langMap.put("itemCreateSetAmount", "Set Amount");
langMap.put("itemCreateSetAmount", "Set amount");
langMap.put("itemCreateSetData", "Set data");
langMap.put("itemCreateSetEnchs", "Add/clear enchantments");
langMap.put("itemCreateSetName", "Set name");
langMap.put("itemCreateSetDisplay", "Set display name");
langMap.put("itemCreateSetLore", "Set lore");
langMap.put("itemCreateEnterName", "Enter an item name, or 'cancel' to return.");
@ -728,7 +729,7 @@ public class Lang {
langMap.put("itemCreateEnterData", "Enter item data, or 'clear' to clear the data, or 'cancel' to return.");
langMap.put("itemCreateEnterEnch", "Enter an enchantment name, or 'clear' to clear the enchantments, or 'cancel' to return.");
langMap.put("itemCreateEnterLevel", "Enter a level (number) for <enchantment>");
langMap.put("itemCreateEnterName", "Enter item name, or 'clear' to clear the custom name, or 'cancel' to return.");
langMap.put("itemCreateEnterDisplay", "Enter item display name, or 'clear' to clear the display name, or 'cancel' to return.");
langMap.put("itemCreateEnterLore", "Enter item lore, separating each line by a semi-colon ; or 'clear' to clear the lore, or 'cancel' to return.");
langMap.put("itemCreateLoaded", "Item loaded.");