turt2live

Untitled

Dec 17th, 2012
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.64 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. import org.bukkit.inventory.ItemStack;
  19.  
  20. import com.turt2live.xmail.XMail;
  21.  
  22. public class AddItemDialog extends ValidatingPrompt {
  23.  
  24.     private final XMail plugin = XMail.getInstance();
  25.     private Inventory items;
  26.  
  27.     // TODO: Remove debug
  28.     int tid = -1;
  29.  
  30.     public AddItemDialog(){
  31.         items = plugin.getServer().createInventory(null, 45, "Items to send");
  32.     }
  33.  
  34.     @Override
  35.     public String getPromptText(ConversationContext context){
  36.         Player player = (Player) context.getForWhom();
  37.         if(player.getOpenInventory() != null){
  38.             player.getOpenInventory().close();
  39.         }
  40.         player.openInventory(items);
  41.         // TODO: Wait for bukkit fix
  42.         // TODO: REMOVE DEBUG
  43.         tid = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable(){
  44.             @Override
  45.             public void run(){
  46.                 for(ItemStack i : items.getContents()){
  47.                     System.out.println(i);
  48.                 }
  49.                 System.out.println("-----");
  50.             }
  51.         }, 40, 40);
  52.         return "Type 'done' when done, or 'show' to reopen.";
  53.     }
  54.  
  55.     @Override
  56.     protected Prompt acceptValidatedInput(ConversationContext context, String input){
  57.         // TODO: REMOVE DEBUG
  58.         if(tid != -1){
  59.             plugin.getServer().getScheduler().cancelTask(tid);
  60.         }
  61.         context.setSessionData("items", items.getContents());
  62.         if(!XMail.getInstance().canDoMoney() || !XMail.getInstance().getXMailConfig().allowMoney){
  63.             return new SendMailDialog();
  64.         }
  65.         return new Question("Would you like to add money?", new AddMoneyDialog(), new SendMailDialog());
  66.     }
  67.  
  68.     @Override
  69.     protected boolean isInputValid(ConversationContext context, String input){
  70.         if(input.equalsIgnoreCase("done")){
  71.             return true;
  72.         }else if(input.equalsIgnoreCase("show")){
  73.             Player player = (Player) context.getForWhom();
  74.             if(player.getOpenInventory() != null){
  75.                 player.getOpenInventory().close();
  76.             }
  77.             player.openInventory(items);
  78.         }
  79.         return false;
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment