From 58b71e00845e3125b81ca291cb07a658398579ff Mon Sep 17 00:00:00 2001 From: Zino Date: Tue, 16 Jul 2013 17:57:48 +0200 Subject: [PATCH] +Able to invite players to party. --- src/me/blackvein/quests/Party.java | 36 ++++++++++++++++++++++------- src/me/blackvein/quests/Quests.java | 12 +++++++--- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/me/blackvein/quests/Party.java b/src/me/blackvein/quests/Party.java index 4b4338de7..d3c07918f 100644 --- a/src/me/blackvein/quests/Party.java +++ b/src/me/blackvein/quests/Party.java @@ -1,6 +1,10 @@ package me.blackvein.quests; import java.util.LinkedList; + +import org.bukkit.Bukkit; +import org.bukkit.conversations.Conversable; +import org.bukkit.conversations.Conversation; import org.bukkit.conversations.ConversationAbandonedEvent; import org.bukkit.conversations.ConversationAbandonedListener; import org.bukkit.conversations.ConversationContext; @@ -134,9 +138,15 @@ public class Party implements ConversationAbandonedListener, ColorUtil{ public void sendInvite(Quester target){ + //Temporary. + if (factory == null) { + this.initFactory(); + } + Player player = target.getPlayer(); - - + Conversation conversation = factory.buildConversation((Conversable)player); + conversation.getContext().setSessionData("inviter", getLeader().getPlayer().getName()); + conversation.begin(); } public void checkSize(){ @@ -160,9 +170,10 @@ public class Party implements ConversationAbandonedListener, ColorUtil{ } @Override - public void conversationAbandoned(ConversationAbandonedEvent cae) { + public void conversationAbandoned(ConversationAbandonedEvent event) { //TODO: support this. - throw new UnsupportedOperationException("Not supported yet."); + //Player player = (Player) event.getContext().getForWhom(); + //throw new UnsupportedOperationException("Not supported yet."); } private static class PartyPrefix implements ConversationPrefix { @@ -190,24 +201,33 @@ public class Party implements ConversationAbandonedListener, ColorUtil{ @Override public Prompt acceptInput(ConversationContext context, String s) { - Player player = (Player) context.getForWhom(); + Player invited = (Player) context.getForWhom(); if (s.equalsIgnoreCase("Yes")) { String inviterName = (String) context.getSessionData("inviter"); - //Quester quester = + Quester quester = quests.getQuester(invited.getName()); + members.add(quester); + + //send message to inviter and invited + quester.getPlayer().sendMessage(partyPrefix + YELLOW + "Accepted invite."); + Bukkit.getPlayerExact(inviterName).sendMessage(partyPrefix + GREEN + invited.getName() + YELLOW + " has accepted your invitation."); return Prompt.END_OF_CONVERSATION; } else if (s.equalsIgnoreCase("No")) { + + String inviterName = (String) context.getSessionData("inviter"); - player.sendMessage(partyPrefix + YELLOW + "Declined invite."); + invited.sendMessage(partyPrefix + YELLOW + "Declined invite."); + Bukkit.getPlayerExact(inviterName).sendMessage(partyPrefix + GREEN + invited.getName() + YELLOW + " has declined your invitation."); + return Prompt.END_OF_CONVERSATION; } else { - player.sendMessage(RED + "Invalid choice. Type \'Yes\' or \'No\'"); + invited.sendMessage(RED + "Invalid choice. Type \'Yes\' or \'No\'"); return new InvitePrompt(); } diff --git a/src/me/blackvein/quests/Quests.java b/src/me/blackvein/quests/Quests.java index 2d206ad58..675a07e95 100644 --- a/src/me/blackvein/quests/Quests.java +++ b/src/me/blackvein/quests/Quests.java @@ -43,6 +43,7 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.conversations.Conversable; +import org.bukkit.conversations.Conversation; import org.bukkit.conversations.ConversationAbandonedEvent; import org.bukkit.conversations.ConversationAbandonedListener; import org.bukkit.conversations.ConversationContext; @@ -1045,7 +1046,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, LinkedList members = party.getMembers(); player.sendMessage(PURPLE + "- " + PINK + "Party" + PURPLE + " -"); - player.sendMessage(YELLOW + "" + BOLD + "Current Quest: " + RESET + "" + YELLOW + current != null ? (current.getName()) : "(None)"); + player.sendMessage(YELLOW + "" + BOLD + "Current Quest: " + RESET + "" + YELLOW + ((current != null) ? current.getName() : "(None)")); player.sendMessage(PINK + "" + BOLD + "Leader: " + RESET + "" + PINK + leader.name); if(members.isEmpty()) player.sendMessage(PURPLE + "" + BOLD + "Members: " + RESET + "" + PURPLE + "(None)"); @@ -1094,10 +1095,15 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, } if(found != null){ - + if (found.getName().equals(player.getName())) { + player.sendMessage(Party.partyPrefix + RED + "you can't invite yourself!"); + return true; + } if(getQuester(found.getName()).getParty() == null){ - //TODO: do stuff? + //TODO: Invite player to party! + party.sendMessage(Party.partyPrefix + PINK + "" + BOLD + player.getName() + RESET + "" + PINK + " invited: " + BOLD + found.getName() + RESET + "" + PINK + " to the party!" ); + party.sendInvite(getQuester(found.getName())); }else{ player.sendMessage(Party.partyPrefix + RED + "" + BOLD + found.getName() + RESET + "" + RED + " is already in a party!");