use of com.bencodez.advancedcore.api.valuerequest.book.BookManager in project AdvancedCore by BenCodez.
the class StringRequester method request.
/**
* Request.
*
* @param player the player
* @param method the method
* @param currentValue the current value
* @param promptText the prompt text
* @param options the options
* @param allowCustomOption the allow custom option
* @param listener the listener
*/
public void request(Player player, InputMethod method, String currentValue, LinkedHashMap<String, ItemStack> options, String promptText, boolean allowCustomOption, StringListener listener) {
if ((options == null || options.size() == 0) && method.equals(InputMethod.INVENTORY) && allowCustomOption) {
method = InputMethod.CHAT;
}
if (AdvancedCorePlugin.getInstance().getOptions().getDisabledRequestMethods().contains(method.toString())) {
player.sendMessage("Disabled method: " + method.toString());
}
if (method.equals(InputMethod.INVENTORY)) {
if (options == null) {
player.sendMessage("There are no choices to choice from to use this method");
return;
}
BInventory inv = new BInventory("Click one of the following:");
for (Entry<String, ItemStack> entry : options.entrySet()) {
inv.addButton(inv.getNextSlot(), new BInventoryButton(entry.getKey(), new String[] {}, entry.getValue()) {
@Override
public void onClick(ClickEvent clickEvent) {
listener.onInput(clickEvent.getPlayer(), clickEvent.getClickedItem().getItemMeta().getDisplayName());
}
});
}
if (allowCustomOption) {
inv.addButton(inv.getNextSlot(), new BInventoryButton("&cClick to enter custom value", new String[] {}, new ItemStack(Material.ANVIL)) {
@Override
public void onClick(ClickEvent clickEvent) {
new ValueRequest().requestString(clickEvent.getPlayer(), listener);
}
});
}
inv.openInventory(player);
} else if (method.equals(InputMethod.CHAT)) {
if (options != null && options.size() != 0) {
AdvancedCoreUser user = AdvancedCorePlugin.getInstance().getUserManager().getUser(player);
user.sendMessage("&cClick one of the following options below:");
PlayerUtils.getInstance().setPlayerMeta(player, "ValueRequestString", listener);
for (String option : options.keySet()) {
TextComponent comp = new TextComponent(option);
comp.setClickEvent(new net.md_5.bungee.api.chat.ClickEvent(Action.RUN_COMMAND, "/" + AdvancedCorePlugin.getInstance().getName() + "valuerequestinput String " + option));
user.sendJson(comp);
}
if (allowCustomOption) {
String option = "CustomValue";
TextComponent comp = new TextComponent(option);
comp.setClickEvent(new net.md_5.bungee.api.chat.ClickEvent(Action.RUN_COMMAND, "/" + AdvancedCorePlugin.getInstance().getName() + "valuerequestinput String " + option));
user.sendJson(comp);
}
} else {
ConversationFactory convoFactory = new ConversationFactory(AdvancedCorePlugin.getInstance()).withModality(true).withEscapeSequence("cancel").withTimeout(60);
PromptManager prompt = new PromptManager(promptText + " Current value: " + currentValue, convoFactory);
prompt.stringPrompt(player, new PromptReturnString() {
@Override
public void onInput(ConversationContext context, Conversable conversable, String input) {
Bukkit.getScheduler().runTaskAsynchronously(AdvancedCorePlugin.getInstance(), new Runnable() {
@Override
public void run() {
listener.onInput((Player) conversable, input);
}
});
}
});
}
} else if (method.equals(InputMethod.BOOK)) {
new BookManager(player, currentValue, new BookSign() {
@Override
public void onBookSign(Player player, String input) {
listener.onInput(player, input);
}
});
} else if (method.equals(InputMethod.SIGN)) {
AdvancedCorePlugin.getInstance().getSignMenu().open(player.getUniqueId(), new String[] { "", "", "", "" }, new InputReceiver() {
@Override
public void receive(Player player, String[] text) {
String str = "";
for (String t : text) {
str += t;
}
listener.onInput(player, str);
}
});
} else {
player.sendMessage("Invalid method/disabled method, change your request method");
}
}
use of com.bencodez.advancedcore.api.valuerequest.book.BookManager in project AdvancedCore by BenCodez.
the class NumberRequester method request.
/**
* Request.
*
* @param player the player
* @param method the method
* @param currentValue the current value
* @param promptText the prompt text
* @param options the options
* @param allowCustomOption the allow custom option
* @param listener the listener
*/
public void request(Player player, InputMethod method, String currentValue, LinkedHashMap<Number, ItemStack> options, String promptText, boolean allowCustomOption, NumberListener listener) {
if (method.equals(InputMethod.SIGN)) {
method = InputMethod.INVENTORY;
}
if ((options == null || options.size() == 0) && method.equals(InputMethod.INVENTORY) && allowCustomOption) {
method = InputMethod.CHAT;
}
if (AdvancedCorePlugin.getInstance().getOptions().getDisabledRequestMethods().contains(method.toString())) {
player.sendMessage("Disabled method: " + method.toString());
}
if (method.equals(InputMethod.INVENTORY)) {
if (options == null) {
player.sendMessage("There are no choices to choice from to use this method");
return;
}
BInventory inv = new BInventory("Click one of the following:");
for (Entry<Number, ItemStack> entry : options.entrySet()) {
inv.addButton(inv.getNextSlot(), new BInventoryButton(entry.getKey().toString(), new String[] {}, entry.getValue()) {
@Override
public void onClick(ClickEvent clickEvent) {
String num = clickEvent.getClickedItem().getItemMeta().getDisplayName();
try {
Number number = Double.valueOf(num);
listener.onInput(clickEvent.getPlayer(), number);
} catch (NumberFormatException ex) {
ex.printStackTrace();
}
}
});
}
if (allowCustomOption) {
inv.addButton(inv.getNextSlot(), new BInventoryButton("&cClick to enter custom value", new String[] {}, new ItemStack(Material.ANVIL)) {
@Override
public void onClick(ClickEvent clickEvent) {
new ValueRequest().requestNumber(clickEvent.getPlayer(), listener);
}
});
}
inv.openInventory(player);
} else if (method.equals(InputMethod.CHAT)) {
if (options != null && options.size() != 0) {
AdvancedCoreUser user = AdvancedCorePlugin.getInstance().getUserManager().getUser(player);
user.sendMessage("&cClick one of the following options below:");
PlayerUtils.getInstance().setPlayerMeta(player, "ValueRequestNumber", listener);
for (Number num : options.keySet()) {
String option = num.toString();
TextComponent comp = new TextComponent(option);
comp.setClickEvent(new net.md_5.bungee.api.chat.ClickEvent(Action.RUN_COMMAND, "/" + AdvancedCorePlugin.getInstance().getName() + "valuerequestinput Number " + option));
user.sendJson(comp);
}
if (allowCustomOption) {
String option = "CustomValue";
TextComponent comp = new TextComponent(option);
comp.setClickEvent(new net.md_5.bungee.api.chat.ClickEvent(Action.RUN_COMMAND, "/" + AdvancedCorePlugin.getInstance().getName() + "valuerequestinput Number " + option));
user.sendJson(comp);
}
} else {
ConversationFactory convoFactory = new ConversationFactory(AdvancedCorePlugin.getInstance()).withModality(true).withEscapeSequence("cancel").withTimeout(60);
PromptManager prompt = new PromptManager(promptText + " Current value: " + currentValue, convoFactory);
prompt.stringPrompt(player, new PromptReturnString() {
@Override
public void onInput(ConversationContext context, Conversable conversable, String input) {
String num = input;
try {
Number number = Double.valueOf(num);
Bukkit.getScheduler().runTaskAsynchronously(AdvancedCorePlugin.getInstance(), new Runnable() {
@Override
public void run() {
listener.onInput((Player) conversable, number);
}
});
} catch (NumberFormatException ex) {
ex.printStackTrace();
}
}
});
}
} else if (method.equals(InputMethod.BOOK)) {
new BookManager(player, currentValue.toString(), new BookSign() {
@Override
public void onBookSign(Player player, String input) {
String num = input;
try {
Number number = Double.valueOf(num);
listener.onInput(player, number);
} catch (NumberFormatException ex) {
ex.printStackTrace();
}
}
});
} else {
player.sendMessage("Invalid method/disabled method, change your request method");
}
}
use of com.bencodez.advancedcore.api.valuerequest.book.BookManager in project AdvancedCore by BenCodez.
the class BooleanRequester method request.
/**
* Request.
*
* @param player the player
* @param method the method
* @param currentValue the current value
* @param promptText the prompt text
* @param listener the listener
*/
public void request(Player player, InputMethod method, String currentValue, String promptText, BooleanListener listener) {
if (AdvancedCorePlugin.getInstance().getOptions().getDisabledRequestMethods().contains(method.toString())) {
player.sendMessage("Disabled method: " + method.toString());
}
if (method.equals(InputMethod.SIGN)) {
method = InputMethod.INVENTORY;
}
if (method.equals(InputMethod.INVENTORY)) {
BInventory inv = new BInventory("Click one of the following:");
inv.addButton(inv.getNextSlot(), new BInventoryButton("True", new String[] {}, new ItemStack(Material.REDSTONE_BLOCK)) {
@Override
public void onClick(ClickEvent clickEvent) {
listener.onInput(clickEvent.getPlayer(), Boolean.valueOf(clickEvent.getClickedItem().getItemMeta().getDisplayName()));
}
});
inv.addButton(inv.getNextSlot(), new BInventoryButton("False", new String[] {}, new ItemStack(Material.IRON_BLOCK)) {
@Override
public void onClick(ClickEvent clickEvent) {
listener.onInput(clickEvent.getPlayer(), Boolean.valueOf(clickEvent.getClickedItem().getItemMeta().getDisplayName()));
}
});
inv.openInventory(player);
} else if (method.equals(InputMethod.CHAT)) {
AdvancedCoreUser user = AdvancedCorePlugin.getInstance().getUserManager().getUser(player);
user.sendMessage("&cClick one of the following options below:");
String option = "True";
TextComponent comp = new TextComponent(option);
PlayerUtils.getInstance().setPlayerMeta(player, "ValueRequestBoolean", listener);
comp.setClickEvent(new net.md_5.bungee.api.chat.ClickEvent(Action.RUN_COMMAND, "/" + AdvancedCorePlugin.getInstance().getName() + "valuerequestinput Boolean " + option));
user.sendJson(comp);
option = "False";
comp = new TextComponent(option);
comp.setClickEvent(new net.md_5.bungee.api.chat.ClickEvent(Action.RUN_COMMAND, "/" + AdvancedCorePlugin.getInstance().getName() + "valuerequestinput Boolean " + option));
user.sendJson(comp);
} else if (method.equals(InputMethod.BOOK)) {
new BookManager(player, currentValue, new BookSign() {
@Override
public void onBookSign(Player player, String input) {
listener.onInput(player, Boolean.valueOf(input));
}
});
} else {
player.sendMessage("Invalid method/disabled method, change your request method");
}
}
Aggregations