Skip to content

Instantly share code, notes, and snippets.

@tehbeard
Created December 17, 2012 21:22
Show Gist options
  • Select an option

  • Save tehbeard/4322395 to your computer and use it in GitHub Desktop.

Select an option

Save tehbeard/4322395 to your computer and use it in GitHub Desktop.
/*******************************************************************************
* 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.StringPrompt;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import com.turt2live.xmail.XMail;
public class AddItemDialog extends StringPrompt {
private final XMail plugin = XMail.getInstance();
@Override
public String getPromptText(ConversationContext context){
Player player = (Player) context.getForWhom();
if(context.getSessionData("inventory") == null){
System.out.println("Initializing in promptText");
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
public Prompt acceptInput(ConversationContext context, String input) {
if(!input.equalsIgnoreCase("done")){
return this;
}
if(context.getSessionData("inventory") == null){
System.out.println("Initializing in AcceptValidated");
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());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment