turt2live

Untitled

Dec 17th, 2012
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.70 KB | None | 0 0
  1. /*******************************************************************************
  2.  * Copyright (c) 2012 turt2live (Travis Ralston).
  3.  * All rights reserved. This program and the accompanying materials
  4.  * are made available under the terms of the GNU Lesser Public License v2.1
  5.  * which accompanies this distribution, and is available at
  6.  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  7.  *
  8.  * Contributors:
  9.  * turt2live (Travis Ralston) - initial API and implementation
  10.  ******************************************************************************/
  11. package com.turt2live.xmail.mail.factory;
  12.  
  13. import org.bukkit.conversations.ConversationContext;
  14. import org.bukkit.conversations.Prompt;
  15. import org.bukkit.conversations.ValidatingPrompt;
  16. import org.bukkit.entity.Player;
  17. import org.bukkit.inventory.Inventory;
  18.  
  19. import com.turt2live.xmail.XMail;
  20.  
  21. public class AddItemDialog extends ValidatingPrompt {
  22.  
  23.     private final XMail plugin = XMail.getInstance();
  24.  
  25.     @Override
  26.     public String getPromptText(ConversationContext context){
  27.         Player player = (Player) context.getForWhom();
  28.         if(player.getOpenInventory() != null){
  29.             player.getOpenInventory().close();
  30.         }
  31.         if(context.getSessionData("inventory") == null){
  32.             context.setSessionData("inventory", plugin.getServer().createInventory(null, 45, "Items to send"));
  33.         }
  34.         Inventory items = (Inventory) context.getSessionData("inventory");
  35.         player.openInventory(items);
  36.         return "Type 'done' when done, or 'show' to reopen.";
  37.     }
  38.  
  39.     @Override
  40.     protected Prompt acceptValidatedInput(ConversationContext context, String input){
  41.         if(context.getSessionData("inventory") == null){
  42.             context.setSessionData("inventory", plugin.getServer().createInventory(null, 45, "Items to send"));
  43.         }
  44.         Inventory items = (Inventory) context.getSessionData("inventory");
  45.         context.setSessionData("items", items.getContents());
  46.         if(!XMail.getInstance().canDoMoney() || !XMail.getInstance().getXMailConfig().allowMoney){
  47.             return new SendMailDialog();
  48.         }
  49.         return new Question("Would you like to add money?", new AddMoneyDialog(), new SendMailDialog());
  50.     }
  51.  
  52.     @Override
  53.     protected boolean isInputValid(ConversationContext context, String input){
  54.         if(input.equalsIgnoreCase("done")){
  55.             return true;
  56.         }else if(input.equalsIgnoreCase("show")){
  57.             Player player = (Player) context.getForWhom();
  58.             if(player.getOpenInventory() != null){
  59.                 player.getOpenInventory().close();
  60.             }
  61.             if(context.getSessionData("inventory") == null){
  62.                 context.setSessionData("inventory", plugin.getServer().createInventory(null, 45, "Items to send"));
  63.             }
  64.             Inventory items = (Inventory) context.getSessionData("inventory");
  65.             player.openInventory(items);
  66.         }
  67.         return false;
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment