use of com.bencodez.advancedcore.api.inventory.BInventoryButton in project AdvancedCore by BenCodez.
the class UserGUI method openUserGUI.
/**
* Open user GUI.
*
* @param player the player
* @param playerName the player name
*/
public void openUserGUI(Player player, final String playerName) {
if (!player.hasPermission("AdvancedCore.UserEdit")) {
player.sendMessage("Not enough permissions");
return;
}
BInventory inv = new BInventory("UserGUI: " + playerName);
inv.addData("player", playerName);
inv.addButton(new BInventoryButton("Give Reward File", new String[] {}, new ItemStack(Material.STONE)) {
@Override
public void onClick(ClickEvent clickEvent) {
ArrayList<String> rewards = new ArrayList<String>();
for (Reward reward : plugin.getRewardHandler().getRewards()) {
rewards.add(reward.getRewardName());
}
new ValueRequest().requestString(clickEvent.getPlayer(), "", ArrayUtils.getInstance().convert(rewards), true, new StringListener() {
@Override
public void onInput(Player player, String value) {
AdvancedCoreUser user = plugin.getUserManager().getUser(UserGUI.getInstance().getCurrentPlayer(player));
plugin.getRewardHandler().giveReward(user, value, new RewardOptions());
player.sendMessage("Given " + user.getPlayerName() + " reward file " + value);
}
});
}
});
inv.addButton(new BInventoryButton(new ItemBuilder("WRITABLE_BOOK").setName("Edit Data")) {
@Override
public void onClick(ClickEvent clickEvent) {
Player player = clickEvent.getPlayer();
EditGUI inv = new EditGUI("Edit Data, click to change");
final AdvancedCoreUser user = plugin.getUserManager().getUser(playerName);
for (final String key : user.getData().getKeys()) {
String value = user.getData().getValue(key);
inv.addButton(new EditGUIButton(new ItemBuilder(Material.STONE).setName(key + " = " + value), new EditGUIValueString(key, value) {
@Override
public void setValue(Player player, String value) {
if (value.equals("\"\"")) {
value = "";
}
user.getData().setString(key, value);
openUserGUI(player, playerName);
}
}));
}
inv.openInventory(player);
}
});
inv.addButton(new BInventoryButton(new ItemBuilder(Material.PAPER).setName("&cView player data")) {
@Override
public void onClick(ClickEvent clickEvent) {
AdvancedCoreUser user = plugin.getUserManager().getUser(playerName);
for (String key : user.getData().getKeys()) {
String str = user.getData().getValue(key);
user.sendMessage("&c&l" + key + " &c" + str);
}
}
});
for (BInventoryButton button : extraButtons.values()) {
inv.addButton(button);
}
inv.openInventory(player);
}
use of com.bencodez.advancedcore.api.inventory.BInventoryButton 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.inventory.BInventoryButton in project AdvancedCore by BenCodez.
the class RewardEditLucky method openRename.
public void openRename(Player player, RewardEditData reward) {
EditGUI inv = new EditGUI("Edit Lucky Rename: " + reward.getName());
inv.addData("Reward", reward);
for (String key : reward.getData().getConfigurationSection("Lucky").getKeys(false)) {
inv.addButton(new BInventoryButton(new ItemBuilder(Material.PAPER).setName("&a" + key).addLoreLine("&aClick to rename")) {
@Override
public void onClick(ClickEvent clickEvent) {
new ValueRequestBuilder(new NumberListener() {
@Override
public void onInput(Player player, Number value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue("Lucky." + value.intValue(), reward.getData().getConfigurationSection("Lucky." + key));
reward.setValue("Lucky." + key, null);
reloadAdvancedCore();
open(player, reward);
}
}, new Number[] {}).usingMethod(InputMethod.CHAT).request(clickEvent.getPlayer());
}
});
}
inv.addButton(getBackButtonCustom(reward, new EditGUIValueInventory("") {
@Override
public void openInventory(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
open(player, reward);
}
}));
inv.openInventory(player);
}
use of com.bencodez.advancedcore.api.inventory.BInventoryButton in project AdvancedCore by BenCodez.
the class RewardEditLucky method openEditSub.
public void openEditSub(Player player, RewardEditData reward) {
EditGUI inv = new EditGUI("Edit Lucky Edit Sub: " + reward.getName());
inv.addData("Reward", reward);
for (String key : reward.getData().getConfigurationSection("Lucky").getKeys(false)) {
inv.addButton(new BInventoryButton(new ItemBuilder(Material.PAPER).setName("&a" + key).addLoreLine("&aClick to edit")) {
@Override
public void onClick(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
openSubReward(clickEvent.getPlayer(), "Lucky." + key, reward);
}
});
}
inv.addButton(getBackButtonCustom(reward, new EditGUIValueInventory("") {
@Override
public void openInventory(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
open(player, reward);
}
}));
inv.openInventory(player);
}
use of com.bencodez.advancedcore.api.inventory.BInventoryButton in project AdvancedCore by BenCodez.
the class RewardEditPotions method openEditSub.
public void openEditSub(Player player, RewardEditData reward) {
EditGUI inv = new EditGUI("Edit Potions Edit Sub: " + reward.getName());
inv.addData("Reward", reward);
for (String key : reward.getData().getConfigurationSection("Potions").getKeys(false)) {
inv.addButton(new BInventoryButton(new ItemBuilder(Material.PAPER).setName("&a" + key).addLoreLine("&aClick to edit")) {
@Override
public void onClick(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
openEditSub(player, reward, key);
}
});
}
inv.addButton(getBackButtonCustom(reward, new EditGUIValueInventory("") {
@Override
public void openInventory(ClickEvent clickEvent) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
open(player, reward);
}
}));
inv.openInventory(player);
}
Aggregations