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 org.bukkit.inventory.ItemStack;
- import com.turt2live.xmail.XMail;
- public class AddItemDialog extends ValidatingPrompt {
- private final XMail plugin = XMail.getInstance();
- private Inventory items;
- // TODO: Remove debug
- int tid = -1;
- public AddItemDialog(){
- items = plugin.getServer().createInventory(null, 45, "Items to send");
- }
- @Override
- public String getPromptText(ConversationContext context){
- Player player = (Player) context.getForWhom();
- if(player.getOpenInventory() != null){
- player.getOpenInventory().close();
- }
- player.openInventory(items);
- // TODO: Wait for bukkit fix
- // TODO: REMOVE DEBUG
- tid = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable(){
- @Override
- public void run(){
- for(ItemStack i : items.getContents()){
- System.out.println(i);
- }
- System.out.println("-----");
- }
- }, 40, 40);
- return "Type 'done' when done, or 'show' to reopen.";
- }
- @Override
- protected Prompt acceptValidatedInput(ConversationContext context, String input){
- // TODO: REMOVE DEBUG
- if(tid != -1){
- plugin.getServer().getScheduler().cancelTask(tid);
- }
- 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();
- }
- player.openInventory(items);
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment