Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*******************************************************************************
- * Copyright (c) 2012 turt2live (Travis Ralston).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the GNU Lesser Public License v2.1
- * which accompanies this distribution, and is available at
- * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
- *
- * Contributors:
- * turt2live (Travis Ralston) - initial API and implementation
- ******************************************************************************/
- package com.turt2live.xmail.mail.factory;
- import org.bukkit.conversations.ConversationContext;
- import org.bukkit.conversations.Prompt;
- import org.bukkit.conversations.ValidatingPrompt;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.Inventory;
- import com.turt2live.xmail.XMail;
- public class AddItemDialog extends ValidatingPrompt {
- private final XMail plugin = XMail.getInstance();
- @Override
- public String getPromptText(ConversationContext context){
- Player player = (Player) context.getForWhom();
- if(player.getOpenInventory() != null){
- player.getOpenInventory().close();
- }
- if(context.getSessionData("inventory") == null){
- context.setSessionData("inventory", plugin.getServer().createInventory(null, 45, "Items to send"));
- }
- Inventory items = (Inventory) context.getSessionData("inventory");
- player.openInventory(items);
- return "Type 'done' when done, or 'show' to reopen.";
- }
- @Override
- protected Prompt acceptValidatedInput(ConversationContext context, String input){
- if(context.getSessionData("inventory") == null){
- context.setSessionData("inventory", plugin.getServer().createInventory(null, 45, "Items to send"));
- }
- Inventory items = (Inventory) context.getSessionData("inventory");
- context.setSessionData("items", items.getContents());
- if(!XMail.getInstance().canDoMoney() || !XMail.getInstance().getXMailConfig().allowMoney){
- return new SendMailDialog();
- }
- return new Question("Would you like to add money?", new AddMoneyDialog(), new SendMailDialog());
- }
- @Override
- protected boolean isInputValid(ConversationContext context, String input){
- if(input.equalsIgnoreCase("done")){
- return true;
- }else if(input.equalsIgnoreCase("show")){
- Player player = (Player) context.getForWhom();
- if(player.getOpenInventory() != null){
- player.getOpenInventory().close();
- }
- if(context.getSessionData("inventory") == null){
- context.setSessionData("inventory", plugin.getServer().createInventory(null, 45, "Items to send"));
- }
- Inventory items = (Inventory) context.getSessionData("inventory");
- player.openInventory(items);
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment