Merge pull request #8 from BlockCat/master

Fixes and an addition.
This commit is contained in:
BlockCat 2013-08-06 12:38:10 -07:00
commit e36ea0b30c
7 changed files with 5335 additions and 5250 deletions

View File

@ -1,225 +1,231 @@
package me.blackvein.quests;
import java.text.MessageFormat;
import java.util.LinkedList;
import me.blackvein.quests.util.ItemUtil;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.event.NPCDeathEvent;
import net.citizensnpcs.api.event.NPCRightClickEvent;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.ChatColor;
import org.bukkit.conversations.Conversable;
import org.bukkit.conversations.Conversation;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
public class NpcListener implements Listener {
final Quests plugin;
public NpcListener(Quests newPlugin) {
plugin = newPlugin;
}
@EventHandler(priority = EventPriority.LOWEST)
public void onNPCRightClick(NPCRightClickEvent evt) {
if (evt.getClicker().isConversing() == false) {
final Player player = evt.getClicker();
final Quester quester = plugin.getQuester(player.getName());
boolean delivery = false;
if (quester.hasObjective("deliverItem") && player.getItemInHand() != null) {
ItemStack hand = player.getItemInHand();
ItemStack found = null;
for(ItemStack is : quester.currentStage.itemsToDeliver){
if(ItemUtil.compareItems(is, hand, true) == 0){
found = is;
break;
}
}
if (found != null) {
NPC clicked = evt.getNPC();
for (NPC n : quester.currentStage.itemDeliveryTargets) {
if (n.getId() == clicked.getId()) {
quester.deliverItem(hand);
delivery = true;
break;
}
}
}
}
if (plugin.questNPCs.contains(evt.getNPC()) && delivery == false) {
if (plugin.checkQuester(player.getName()) == false) {
if (quester.hasObjective("talkToNPC")) {
quester.interactWithNPC(evt.getNPC());
} else {
LinkedList<Quest> npcQuests = new LinkedList<Quest>();
for (Quest q : plugin.getQuests()) {
if (q.npcStart != null && q.npcStart.getId() == evt.getNPC().getId()) {
npcQuests.add(q);
}
}
if (npcQuests.isEmpty() == false && npcQuests.size() > 1) {
Conversation c = plugin.NPCConversationFactory.buildConversation((Conversable) player);
c.getContext().setSessionData("quests", npcQuests);
c.getContext().setSessionData("npc", evt.getNPC().getName());
c.begin();
} else if (npcQuests.size() == 1) {
Quest q = npcQuests.get(0);
if (!quester.completedQuests.contains(q.name)) {
if (quester.currentQuest == null) {
quester.questToTake = q.name;
String s = extracted(quester);
player.sendMessage(s);
plugin.conversationFactory.buildConversation((Conversable) player).begin();
} else if (quester.currentQuest.equals(q) == false) {
player.sendMessage(ChatColor.YELLOW + "You may only have one active Quest.");
}
} else if (quester.completedQuests.contains(q.name)) {
if (quester.currentQuest == null) {
if (quester.getDifference(q) > 0) {
player.sendMessage(ChatColor.YELLOW + "You may not take " + ChatColor.AQUA + q.name + ChatColor.YELLOW + " again for another " + ChatColor.DARK_PURPLE + Quests.getTime(quester.getDifference(q)) + ChatColor.YELLOW + ".");
} else if (q.redoDelay < 0) {
player.sendMessage(ChatColor.YELLOW + "You have already completed " + ChatColor.AQUA + q.name + ChatColor.YELLOW + ".");
} else {
quester.questToTake = q.name;
String s = extracted(quester);
player.sendMessage(s);
plugin.conversationFactory.buildConversation((Conversable) player).begin();
}
} else if (quester.currentQuest.equals(q) == false) {
player.sendMessage(ChatColor.YELLOW + "You may only have one active Quest.");
}
}
}
}
}
}
}
}
@EventHandler
public void onNPCDeath(NPCDeathEvent evt) {
if (evt.getNPC().getBukkitEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent damageEvent = (EntityDamageByEntityEvent) evt.getNPC().getBukkitEntity().getLastDamageCause();
Entity damager = damageEvent.getDamager();
if (damager != null) {
if (damager instanceof Projectile) {
Projectile p = (Projectile) damager;
if (p.getShooter() instanceof Player) {
Player player = (Player) p.getShooter();
boolean okay = true;
if (plugin.citizens != null) {
if (CitizensAPI.getNPCRegistry().isNPC(player)) {
okay = false;
}
}
if (okay) {
Quester quester = plugin.getQuester(player.getName());
if (quester.hasObjective("killNPC")) {
quester.killNPC(evt.getNPC());
}
}
}
} else if (damager instanceof Player) {
boolean okay = true;
if (plugin.citizens != null) {
if (plugin.citizens.getNPCRegistry().isNPC(damager)) {
okay = false;
}
}
if (okay) {
Player player = (Player) damager;
Quester quester = plugin.getQuester(player.getName());
if (quester.hasObjective("killNPC")) {
quester.killNPC(evt.getNPC());
}
}
}
}
}
}
private String extracted(final Quester quester) {
return MessageFormat.format("{0}- {1}{2}{3} -\n\n{4}{5}\n",
ChatColor.GOLD,
ChatColor.DARK_PURPLE,
quester.questToTake,
ChatColor.GOLD,
ChatColor.RESET, plugin.getQuest(quester.questToTake).description);
}
package me.blackvein.quests;
import java.text.MessageFormat;
import java.util.LinkedList;
import me.blackvein.quests.util.ItemUtil;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.event.NPCDeathEvent;
import net.citizensnpcs.api.event.NPCRightClickEvent;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.ChatColor;
import org.bukkit.conversations.Conversable;
import org.bukkit.conversations.Conversation;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
public class NpcListener implements Listener {
final Quests plugin;
public NpcListener(Quests newPlugin) {
plugin = newPlugin;
}
@EventHandler(priority = EventPriority.LOWEST)
public void onNPCRightClick(NPCRightClickEvent evt) {
if (evt.getClicker().isConversing() == false) {
final Player player = evt.getClicker();
final Quester quester = plugin.getQuester(player.getName());
boolean delivery = false;
if (quester.hasObjective("deliverItem") && player.getItemInHand() != null) {
ItemStack hand = player.getItemInHand();
ItemStack found = null;
for(ItemStack is : quester.currentStage.itemsToDeliver){
if(ItemUtil.compareItems(is, hand, true) == 0){
found = is;
break;
}
}
if (found != null) {
NPC clicked = evt.getNPC();
for (NPC n : quester.currentStage.itemDeliveryTargets) {
if (n.getId() == clicked.getId()) {
quester.deliverItem(hand);
delivery = true;
break;
}
}
}
}
if (plugin.questNPCs.contains(evt.getNPC()) && delivery == false) {
if (plugin.checkQuester(player.getName()) == false) {
if (quester.hasObjective("talkToNPC")) {
quester.interactWithNPC(evt.getNPC());
} else {
LinkedList<Quest> npcQuests = new LinkedList<Quest>();
for (Quest q : plugin.getQuests()) {
if (q.npcStart != null && q.npcStart.getId() == evt.getNPC().getId()) {
npcQuests.add(q);
}
}
if (npcQuests.isEmpty() == false && npcQuests.size() > 1) {
Conversation c = plugin.NPCConversationFactory.buildConversation((Conversable) player);
c.getContext().setSessionData("quests", npcQuests);
c.getContext().setSessionData("npc", evt.getNPC().getName());
c.begin();
} else if (npcQuests.size() == 1) {
Quest q = npcQuests.get(0);
if (!quester.completedQuests.contains(q.name)) {
if (quester.currentQuest == null) {
quester.questToTake = q.name;
String s = extracted(quester);
for (String msg : s.split("<br>")) {
player.sendMessage(msg);
}
plugin.conversationFactory.buildConversation((Conversable) player).begin();
} else if (quester.currentQuest.equals(q) == false) {
player.sendMessage(ChatColor.YELLOW + "You may only have one active Quest.");
}
} else if (quester.completedQuests.contains(q.name)) {
if (quester.currentQuest == null) {
if (quester.getDifference(q) > 0) {
player.sendMessage(ChatColor.YELLOW + "You may not take " + ChatColor.AQUA + q.name + ChatColor.YELLOW + " again for another " + ChatColor.DARK_PURPLE + Quests.getTime(quester.getDifference(q)) + ChatColor.YELLOW + ".");
} else if (q.redoDelay < 0) {
player.sendMessage(ChatColor.YELLOW + "You have already completed " + ChatColor.AQUA + q.name + ChatColor.YELLOW + ".");
} else {
quester.questToTake = q.name;
String s = extracted(quester);
for (String msg : s.split("<br>")) {
player.sendMessage(msg);
}
plugin.conversationFactory.buildConversation((Conversable) player).begin();
}
} else if (quester.currentQuest.equals(q) == false) {
player.sendMessage(ChatColor.YELLOW + "You may only have one active Quest.");
}
}
}
}
}
}
}
}
@EventHandler
public void onNPCDeath(NPCDeathEvent evt) {
if (evt.getNPC().getBukkitEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent damageEvent = (EntityDamageByEntityEvent) evt.getNPC().getBukkitEntity().getLastDamageCause();
Entity damager = damageEvent.getDamager();
if (damager != null) {
if (damager instanceof Projectile) {
Projectile p = (Projectile) damager;
if (p.getShooter() instanceof Player) {
Player player = (Player) p.getShooter();
boolean okay = true;
if (plugin.citizens != null) {
if (CitizensAPI.getNPCRegistry().isNPC(player)) {
okay = false;
}
}
if (okay) {
Quester quester = plugin.getQuester(player.getName());
if (quester.hasObjective("killNPC")) {
quester.killNPC(evt.getNPC());
}
}
}
} else if (damager instanceof Player) {
boolean okay = true;
if (plugin.citizens != null) {
if (plugin.citizens.getNPCRegistry().isNPC(damager)) {
okay = false;
}
}
if (okay) {
Player player = (Player) damager;
Quester quester = plugin.getQuester(player.getName());
if (quester.hasObjective("killNPC")) {
quester.killNPC(evt.getNPC());
}
}
}
}
}
}
private String extracted(final Quester quester) {
return MessageFormat.format("{0}- {1}{2}{3} -\n\n{4}{5}\n",
ChatColor.GOLD,
ChatColor.DARK_PURPLE,
quester.questToTake,
ChatColor.GOLD,
ChatColor.RESET, plugin.getQuest(quester.questToTake).description);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -173,7 +173,13 @@ public class Quest {
q.reset();
q.completedQuests.add(name);
String none = ChatColor.GRAY + "- (None)";
player.sendMessage(Quests.parseString(finished, q.currentQuest));
String ps = Quests.parseString(finished, q.currentQuest);
for (String msg : ps.split("<br>")) {
player.sendMessage(msg);
}
if(moneyReward > 0 && Quests.economy != null){
Quests.economy.depositPlayer(q.name, moneyReward);
none = null;

View File

@ -391,11 +391,29 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil {
for (Quest q : quests.getQuests()) {
if (q.getName().equalsIgnoreCase(input) || q.getName().toLowerCase().contains(input.toLowerCase())) {
if (q.getName().equalsIgnoreCase(input)) {
loadQuest(context, q);
return new CreateMenuPrompt();
}
}
for (Quest q : quests.getQuests()) {
if (q.getName().toLowerCase().startsWith(input.toLowerCase())) {
loadQuest(context, q);
return new CreateMenuPrompt();
}
}
for (Quest q : quests.getQuests()) {
if (q.getName().toLowerCase().contains(input.toLowerCase())) {
loadQuest(context, q);
return new CreateMenuPrompt();
}
}
return new SelectEditPrompt();
@ -611,6 +629,12 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil {
public Prompt acceptInput(ConversationContext context, String input) {
if (input.equalsIgnoreCase("cancel") == false) {
if (input.startsWith("++")) {
if (context.getSessionData(CK.Q_ASK_MESSAGE) != null) {
context.setSessionData(CK.Q_ASK_MESSAGE, context.getSessionData(CK.Q_ASK_MESSAGE) + " " + input.substring(2));
return new CreateMenuPrompt();
}
}
context.setSessionData(CK.Q_ASK_MESSAGE, input);
}
@ -632,6 +656,12 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil {
public Prompt acceptInput(ConversationContext context, String input) {
if (input.equalsIgnoreCase("cancel") == false) {
if (input.startsWith("++")) {
if (context.getSessionData(CK.Q_FINISH_MESSAGE) != null) {
context.setSessionData(CK.Q_FINISH_MESSAGE, context.getSessionData(CK.Q_FINISH_MESSAGE) + " " + input.substring(2));
return new CreateMenuPrompt();
}
}
context.setSessionData(CK.Q_FINISH_MESSAGE, input);
}

View File

@ -3,6 +3,8 @@ package me.blackvein.quests;
import java.io.File;
import java.util.*;
import java.util.Map.Entry;
import java.util.logging.Level;
import me.ThaH3lper.com.LoadBosses.LoadBoss;
import me.blackvein.quests.util.ItemUtil;
import net.citizensnpcs.api.CitizensAPI;
@ -2071,7 +2073,14 @@ public class Quester {
}
}
if (stage == null) {
currentQuest = quest;
currentQuest.completeQuest(this);
Quests.log.log(Level.SEVERE, "[Quests] Invalid stage for player: \"" + name + "\". Quest ended.");
return true;
}
currentQuest = quest;
currentStage = stage;

File diff suppressed because it is too large Load Diff

View File

@ -1,150 +1,176 @@
package me.blackvein.quests.prompts;
import java.text.MessageFormat;
import java.util.LinkedList;
import me.blackvein.quests.ColorUtil;
import me.blackvein.quests.Quest;
import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.conversations.Conversable;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import org.bukkit.conversations.StringPrompt;
import org.bukkit.entity.Player;
public class QuestAcceptPrompt extends StringPrompt implements ColorUtil {
final Quests plugin;
Quester quester;
LinkedList<Quest> quests;
public QuestAcceptPrompt(Quests plugin) {
this.plugin = plugin;
}
@Override
public String getPromptText(ConversationContext cc) {
quests = (LinkedList<Quest>) cc.getSessionData("quests");
quester = plugin.getQuester(((Player) cc.getForWhom()).getName());
String npc = (String) cc.getSessionData("npc");
String menu = YELLOW + "- " + GOLD + "Quests" + " | " + npc + YELLOW + " -\n";
for (int i = 1; i <= quests.size(); i++) {
Quest quest = quests.get(i - 1);
if (quester.completedQuests.contains(quest.getName())) {
menu += DARKGREEN + "" + BOLD + "" + i + ". " + RESET + "" + GREEN + "" + ITALIC + quest.getName() + RESET + "" + GREEN + " (Completed)\n";
} else {
menu += GOLD + "" + BOLD + "" + i + ". " + RESET + "" + YELLOW + "" + ITALIC + quest.getName() + "\n";
}
}
menu += GOLD + "" + BOLD + "" + (quests.size() + 1) + ". " + RESET + "" + ColorUtil.GRAY + "Cancel\n";
menu += WHITE + "Enter an option";
return menu;
}
@Override
public Prompt acceptInput(ConversationContext cc, String input) {
int numInput = -1;
try {
numInput = Integer.parseInt(input);
} catch (Exception e) {
//Continue
}
if (input.equalsIgnoreCase("Cancel") || numInput == (quests.size() + 1)) {
cc.getForWhom().sendRawMessage(YELLOW + "Cancelled.");
return Prompt.END_OF_CONVERSATION;
} else {
Quest q = null;
for (Quest quest : quests) {
if (quest.getName().equalsIgnoreCase(input) || StringUtils.containsIgnoreCase(quest.getName(), input) || numInput == (quests.indexOf(quest) + 1)) {
q = quest;
break;
}
}
if (q == null) {
cc.getForWhom().sendRawMessage(RED + "Invalid Selection!");
return new QuestAcceptPrompt(plugin);
} else {
Player player = quester.getPlayer();
if (!quester.completedQuests.contains(q.name)) {
if (quester.currentQuest == null) {
if(q.testRequirements(quester)){
quester.questToTake = q.name;
String s = extracted(quester);
player.sendMessage(s);
plugin.conversationFactory.buildConversation((Conversable) player).begin();
}else{
player.sendMessage(q.failRequirements);
}
} else if (quester.currentQuest.equals(q) == false) {
player.sendMessage(ChatColor.YELLOW + "You may only have one active Quest.");
}
} else if (quester.completedQuests.contains(q.name)) {
if (quester.currentQuest == null) {
if (quester.getDifference(q) > 0) {
player.sendMessage(ChatColor.YELLOW + "You may not take " + ChatColor.AQUA + q.name + ChatColor.YELLOW + " again for another " + ChatColor.DARK_PURPLE + Quests.getTime(quester.getDifference(q)) + ChatColor.YELLOW + ".");
} else if (q.redoDelay < 0) {
player.sendMessage(ChatColor.YELLOW + "You have already completed " + ChatColor.AQUA + q.name + ChatColor.YELLOW + ".");
} else {
quester.questToTake = q.name;
String s = extracted(quester);
player.sendMessage(s);
plugin.conversationFactory.buildConversation((Conversable) player).begin();
}
} else if (quester.currentQuest.equals(q) == false) {
player.sendMessage(ChatColor.YELLOW + "You may only have one active Quest.");
}
}
return Prompt.END_OF_CONVERSATION;
}
}
}
private String extracted(final Quester quester) {
return MessageFormat.format("{0}- {1}{2}{3} -\n\n{4}{5}\n",
ChatColor.GOLD,
ChatColor.DARK_PURPLE,
quester.questToTake,
ChatColor.GOLD,
ChatColor.RESET, plugin.getQuest(quester.questToTake).description);
}
}
package me.blackvein.quests.prompts;
import java.text.MessageFormat;
import java.util.LinkedList;
import me.blackvein.quests.ColorUtil;
import me.blackvein.quests.Quest;
import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.conversations.Conversable;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import org.bukkit.conversations.StringPrompt;
import org.bukkit.entity.Player;
public class QuestAcceptPrompt extends StringPrompt implements ColorUtil {
final Quests plugin;
Quester quester;
LinkedList<Quest> quests;
public QuestAcceptPrompt(Quests plugin) {
this.plugin = plugin;
}
@Override
public String getPromptText(ConversationContext cc) {
quests = (LinkedList<Quest>) cc.getSessionData("quests");
quester = plugin.getQuester(((Player) cc.getForWhom()).getName());
String npc = (String) cc.getSessionData("npc");
String menu = YELLOW + "- " + GOLD + "Quests" + " | " + npc + YELLOW + " -\n";
for (int i = 1; i <= quests.size(); i++) {
Quest quest = quests.get(i - 1);
if (quester.completedQuests.contains(quest.getName())) {
menu += DARKGREEN + "" + BOLD + "" + i + ". " + RESET + "" + GREEN + "" + ITALIC + quest.getName() + RESET + "" + GREEN + " (Completed)\n";
} else {
menu += GOLD + "" + BOLD + "" + i + ". " + RESET + "" + YELLOW + "" + ITALIC + quest.getName() + "\n";
}
}
menu += GOLD + "" + BOLD + "" + (quests.size() + 1) + ". " + RESET + "" + ColorUtil.GRAY + "Cancel\n";
menu += WHITE + "Enter an option";
return menu;
}
@Override
public Prompt acceptInput(ConversationContext cc, String input) {
int numInput = -1;
try {
numInput = Integer.parseInt(input);
} catch (Exception e) {
//Continue
}
if (input.equalsIgnoreCase("Cancel") || numInput == (quests.size() + 1)) {
cc.getForWhom().sendRawMessage(YELLOW + "Cancelled.");
return Prompt.END_OF_CONVERSATION;
} else {
Quest q = null;
for (Quest quest : quests) {
if (quest.getName().equalsIgnoreCase(input)) {
q = quest;
break;
}
}
if (q == null)
for (Quest quest : quests) {
if (numInput == (quests.indexOf(quest) + 1)) {
q = quest;
break;
}
}
if (q == null)
for (Quest quest : quests) {
if (StringUtils.containsIgnoreCase(quest.getName(), input)) {
q = quest;
break;
}
}
if (q == null) {
cc.getForWhom().sendRawMessage(RED + "Invalid Selection!");
return new QuestAcceptPrompt(plugin);
} else {
Player player = quester.getPlayer();
if (!quester.completedQuests.contains(q.name)) {
if (quester.currentQuest == null) {
if(q.testRequirements(quester)){
quester.questToTake = q.name;
String s = extracted(quester);
for (String msg : s.split("<br>")) {
player.sendMessage(msg);
}
plugin.conversationFactory.buildConversation((Conversable) player).begin();
}else{
player.sendMessage(q.failRequirements);
}
} else if (quester.currentQuest.equals(q) == false) {
player.sendMessage(ChatColor.YELLOW + "You may only have one active Quest.");
}
} else if (quester.completedQuests.contains(q.name)) {
if (quester.currentQuest == null) {
if (quester.getDifference(q) > 0) {
player.sendMessage(ChatColor.YELLOW + "You may not take " + ChatColor.AQUA + q.name + ChatColor.YELLOW + " again for another " + ChatColor.DARK_PURPLE + Quests.getTime(quester.getDifference(q)) + ChatColor.YELLOW + ".");
} else if (q.redoDelay < 0) {
player.sendMessage(ChatColor.YELLOW + "You have already completed " + ChatColor.AQUA + q.name + ChatColor.YELLOW + ".");
} else {
quester.questToTake = q.name;
String s = extracted(quester);
for (String msg : s.split("<br>")) {
player.sendMessage(msg);
}
plugin.conversationFactory.buildConversation((Conversable) player).begin();
}
} else if (quester.currentQuest.equals(q) == false) {
player.sendMessage(ChatColor.YELLOW + "You may only have one active Quest.");
}
}
return Prompt.END_OF_CONVERSATION;
}
}
}
private String extracted(final Quester quester) {
return MessageFormat.format("{0}- {1}{2}{3} -\n\n{4}{5}\n",
ChatColor.GOLD,
ChatColor.DARK_PURPLE,
quester.questToTake,
ChatColor.GOLD,
ChatColor.RESET, plugin.getQuest(quester.questToTake).description);
}
}