use of com.bencodez.advancedcore.api.inventory.BInventory in project VotingPlugin by Ben12345rocks.
the class CommandLoader method loadCommands.
/**
* Load commands.
*/
public void loadCommands() {
loadAdminVoteCommand();
loadVoteCommand();
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
com.bencodez.advancedcore.thread.Thread.getInstance().run(new Runnable() {
@Override
public void run() {
loadTabComplete();
UserGUI.getInstance().addPluginButton(plugin, new BInventoryButton("Force Vote", new String[] {}, new ItemStack(Material.STONE)) {
@Override
public void onClick(ClickEvent clickEvent) {
Player player = clickEvent.getPlayer();
ArrayList<String> voteSites = new ArrayList<String>();
for (VoteSite voteSite : plugin.getVoteSites()) {
voteSites.add(voteSite.getKey());
}
new ValueRequest().requestString(player, "", ArrayUtils.getInstance().convert(voteSites), true, new StringListener() {
@Override
public void onInput(Player player, String value) {
PlayerVoteEvent voteEvent = new PlayerVoteEvent(plugin.getVoteSite(value, true), UserGUI.getInstance().getCurrentPlayer(player), plugin.getVoteSiteServiceSite(value), false);
plugin.getServer().getPluginManager().callEvent(voteEvent);
player.sendMessage("Forced vote for " + UserGUI.getInstance().getCurrentPlayer(player) + " on " + value);
}
});
}
});
UserGUI.getInstance().addPluginButton(plugin, new BInventoryButton("MileStones", new String[0], new ItemStack(Material.STONE)) {
@Override
public void onClick(ClickEvent event) {
Player player = event.getWhoClicked();
String playerName = (String) event.getMeta(player, "Player");
BInventory inv = new BInventory("MileStones: " + playerName);
for (String mileStoneName : plugin.getSpecialRewardsConfig().getMilestoneVotes()) {
if (StringParser.getInstance().isInt(mileStoneName)) {
int mileStone = Integer.parseInt(mileStoneName);
inv.addButton(inv.getNextSlot(), new BInventoryButton("" + mileStone, new String[] { "Enabled: " + plugin.getSpecialRewardsConfig().getMilestoneRewardEnabled(mileStone), "&cClick to set wether this has been completed or not" }, new ItemStack(Material.STONE)) {
@Override
public void onClick(ClickEvent clickEvent) {
if (StringParser.getInstance().isInt(clickEvent.getClickedItem().getItemMeta().getDisplayName())) {
Player player = clickEvent.getPlayer();
int mileStone = Integer.parseInt(clickEvent.getClickedItem().getItemMeta().getDisplayName());
String playerName = (String) event.getMeta(player, "Player");
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(playerName);
new ValueRequest().requestBoolean(player, "" + user.hasGottenMilestone(mileStone), new BooleanListener() {
@Override
public void onInput(Player player, boolean value) {
String playerName = UserGUI.getInstance().getCurrentPlayer(player);
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(playerName);
user.setHasGotteMilestone(mileStone, value);
player.sendMessage("Set milestone completetion to " + value + " on " + mileStone);
}
});
}
}
});
}
}
}
});
}
});
}
});
}
use of com.bencodez.advancedcore.api.inventory.BInventory in project VotingPlugin by Ben12345rocks.
the class VoteBest method onChest.
@Override
public void onChest(Player player) {
BInventory inv = new BInventory(plugin.getGui().getChestVoteBestName());
inv.addPlaceholder("player", user.getPlayerName());
inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteBestDayBestItem()).addPlaceholder("Best", "" + user.getBestDayVoteStreak())) {
@Override
public void onClick(ClickEvent clickEvent) {
}
});
inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteBestWeekBestItem()).addPlaceholder("Best", "" + user.getBestWeekVoteStreak())) {
@Override
public void onClick(ClickEvent clickEvent) {
}
});
inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteBestMonthBestItem()).addPlaceholder("Best", "" + user.getBestMonthVoteStreak())) {
@Override
public void onClick(ClickEvent clickEvent) {
}
});
if (plugin.getGui().isChestVoteBestBackButton()) {
inv.addButton(plugin.getCommandLoader().getBackButton(user));
}
inv.openInventory(player);
}
use of com.bencodez.advancedcore.api.inventory.BInventory in project VotingPlugin by Ben12345rocks.
the class VoteGUI method onChest.
@Override
public void onChest(Player player) {
if (this.user == null) {
user = UserManager.getInstance().getVotingPluginUser(player);
}
BInventory inv = new BInventory(plugin.getGui().getChestVoteGUIName());
if (!plugin.getConfigFile().isAlwaysCloseInventory()) {
inv.dontClose();
}
if (player.getUniqueId().toString().equals(user.getUUID())) {
inv.requirePermission("VotingPlugin.Commands.Vote.GUI");
} else {
inv.requirePermission("VotingPlugin.Commands.Vote.GUI.Other");
}
inv.addPlaceholder("points", "" + user.getPoints());
inv.addPlaceholder("player", user.getPlayerName());
inv.addPlaceholder("top", plugin.getConfigFile().getVoteTopDefault());
for (String slot : plugin.getGui().getChestVoteGUISlots()) {
ItemBuilder builder = getItemSlot(slot, player);
inv.addButton(new UpdatingBInventoryButton(builder, 1000, 1000) {
@Override
public void onClick(ClickEvent event) {
Player player = event.getWhoClicked();
String cmd = plugin.getGui().getChestVoteGUISlotCommand(slot);
if (cmd.equalsIgnoreCase("none")) {
return;
} else if (!cmd.equals("")) {
event.runSync(new Runnable() {
@Override
public void run() {
player.performCommand(cmd);
}
});
} else {
if (slot.equalsIgnoreCase("url")) {
new VoteURL(plugin, player, user, true).open();
} else if (slot.equalsIgnoreCase("next")) {
new VoteNext(plugin, player, user).open(GUIMethod.CHEST);
} else if (slot.equalsIgnoreCase("last")) {
new VoteLast(plugin, player, user).open(GUIMethod.CHEST);
} else if (slot.equalsIgnoreCase("total")) {
new VoteTotal(plugin, player, user).open(GUIMethod.CHEST);
} else if (slot.equalsIgnoreCase("top")) {
new VoteTopVoter(plugin, player, user, TopVoter.getDefault(), 1).open(GUIMethod.CHEST);
} else if (slot.equalsIgnoreCase("today")) {
new VoteToday(plugin, player, user, 1).open(GUIMethod.CHEST);
} else if (slot.equalsIgnoreCase("help")) {
player.performCommand("vote help");
} else if (slot.equalsIgnoreCase("shop")) {
new VoteShop(plugin, player, user).open(GUIMethod.CHEST);
} else if (slot.equalsIgnoreCase("lastmonth")) {
new VoteTopVoterLastMonth(plugin, player, user).open(GUIMethod.CHEST);
} else if (slot.equalsIgnoreCase("best")) {
new VoteBest(plugin, player, user).open(GUIMethod.CHEST);
} else if (slot.equalsIgnoreCase("streak")) {
new VoteStreak(plugin, player, user).open(GUIMethod.CHEST);
}
}
if (RewardHandler.getInstance().hasRewards(plugin.getGui().getData(), plugin.getGui().getChestVoteGUISlotRewardsPath(slot))) {
RewardHandler.getInstance().giveReward(UserManager.getInstance().getVotingPluginUser(player), plugin.getGui().getData(), plugin.getGui().getChestVoteGUISlotRewardsPath(slot), new RewardOptions().addPlaceholder("identifier", slot));
}
}
@Override
public ItemBuilder onUpdate(Player player) {
ItemBuilder item = getItemSlot(slot, player);
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(player);
item.addPlaceholder("points", "" + user.getPoints());
item.addPlaceholder("player", user.getPlayerName());
item.addPlaceholder("top", plugin.getConfigFile().getVoteTopDefault());
return item;
}
});
}
inv.openInventory(player);
}
use of com.bencodez.advancedcore.api.inventory.BInventory in project VotingPlugin by Ben12345rocks.
the class VoteShop method onChest.
@Override
public void onChest(Player player) {
if (!plugin.getGui().getChestVoteShopEnabled()) {
player.sendMessage(StringParser.getInstance().colorize(plugin.getGui().getChestVoteShopDisabled()));
return;
}
if (this.user == null) {
user = plugin.getVotingPluginUserManager().getVotingPluginUser(player);
}
BInventory inv = new BInventory(plugin.getGui().getChestVoteShopName());
inv.addPlaceholder("points", "" + user.getPoints());
inv.dontClose();
for (final String identifier : plugin.getGui().getChestShopIdentifiers()) {
String perm = plugin.getGui().getChestVoteShopPermission(identifier);
boolean hasPerm = false;
if (perm.isEmpty()) {
hasPerm = true;
} else {
hasPerm = player.hasPermission(perm);
}
int limit = plugin.getGui().getChestShopIdentifierLimit(identifier);
boolean limitPass = true;
if (limit > 0) {
if (user.getVoteShopIdentifierLimit(identifier) >= limit) {
limitPass = false;
}
}
if (!plugin.getGui().getChestVoteShopNotBuyable(identifier)) {
if (hasPerm && (limitPass || !plugin.getGui().isChestVoteShopHideLimitedReached())) {
ItemBuilder builder = new ItemBuilder(plugin.getGui().getChestShopIdentifierSection(identifier));
inv.addButton(new BInventoryButton(builder) {
@Override
public void onClick(ClickEvent event) {
Player player = event.getWhoClicked();
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(player);
user.clearCache();
String identifier = (String) getData("identifier");
int limit = (int) getData("Limit");
int points = plugin.getGui().getChestShopIdentifierCost(identifier);
if (identifier != null) {
if (plugin.getGui().getChestVoteShopCloseGUI(identifier)) {
event.getButton().getInv().closeInv(player, null);
}
// limit fail-safe, should never be needed, except in rare cases
boolean limitPass = true;
if (limit > 0) {
if (user.getVoteShopIdentifierLimit(identifier) >= limit) {
limitPass = false;
}
}
if (limitPass) {
if (!plugin.getGui().isChestVoteShopRequireConfirmation(identifier)) {
HashMap<String, String> placeholders = new HashMap<String, String>();
placeholders.put("identifier", plugin.getGui().getChestShopIdentifierIdentifierName(identifier));
placeholders.put("points", "" + points);
placeholders.put("limit", "" + limit);
if (user.removePoints(points)) {
plugin.getLogger().info("VoteShop: " + user.getPlayerName() + "/" + user.getUUID() + " bought " + identifier + " for " + points);
RewardHandler.getInstance().giveReward(user, plugin.getGui().getData(), plugin.getGui().getChestShopIdentifierRewardsPath(identifier), new RewardOptions().setPlaceholders(placeholders));
user.sendMessage(StringParser.getInstance().replacePlaceHolder(plugin.getGui().getCHESTVoteShopPurchase(identifier), placeholders));
if (limit > 0) {
user.setVoteShopIdentifierLimit(identifier, user.getVoteShopIdentifierLimit(identifier) + 1);
}
} else {
user.sendMessage(StringParser.getInstance().replacePlaceHolder(plugin.getConfigFile().getFormatShopFailedMsg(), placeholders));
}
} else {
new VoteShopConfirm(plugin, player, user, identifier).open(GUIMethod.CHEST);
}
} else {
user.sendMessage(plugin.getGui().getChestVoteShopLimitReached());
}
}
}
}.addData("identifier", identifier).addData("Limit", limit));
}
} else {
if (hasPerm) {
ItemBuilder builder = new ItemBuilder(plugin.getGui().getChestShopIdentifierSection(identifier));
inv.addButton(new BInventoryButton(builder) {
@Override
public void onClick(ClickEvent event) {
}
}.dontClose().addData("identifier", identifier).addData("Limit", limit));
}
}
}
if (plugin.getGui().getChestVoteShopBackButton()) {
inv.addButton(plugin.getCommandLoader().getBackButton(user));
}
inv.openInventory(player);
}
use of com.bencodez.advancedcore.api.inventory.BInventory in project VotingPlugin by Ben12345rocks.
the class VoteTopVoter method onChest.
@Override
public void onChest(Player player) {
try {
if (top == null) {
top = TopVoter.getDefault();
}
Set<Entry<TopVoterPlayer, Integer>> users = null;
String topVoter = top.getName();
@SuppressWarnings("unchecked") LinkedHashMap<TopVoterPlayer, Integer> topVotes = (LinkedHashMap<TopVoterPlayer, Integer>) plugin.getTopVoter(top).clone();
users = topVotes.entrySet();
BInventory inv = new BInventory(plugin.getGui().getChestVoteTopName());
inv.addPlaceholder("topvoter", topVoter);
if (!plugin.getConfigFile().isAlwaysCloseInventory()) {
inv.dontClose();
}
int pos = 1;
for (Entry<TopVoterPlayer, Integer> entry : users) {
ItemBuilder playerItem;
if (plugin.getGui().isChestVoteTopUseSkull()) {
playerItem = new ItemBuilder(entry.getKey().getPlayerHead());
} else {
playerItem = new ItemBuilder(Material.valueOf(plugin.getGui().getChestVoteTopPlayerItemMaterial()));
}
playerItem.setLore(new ArrayList<String>());
inv.addButton(new BInventoryButton(playerItem.setName(plugin.getGui().getChestVoteTopItemName()).addLoreLine(plugin.getGui().getChestVoteTopItemLore()).addPlaceholder("position", "" + pos).addPlaceholder("player", entry.getKey().getPlayerName()).addPlaceholder("votes", "" + entry.getValue())) {
@Override
public void onClick(ClickEvent clickEvent) {
if (plugin.getGui().getChestVoteTopOpenMainGUIOnClick()) {
TopVoterPlayer user = (TopVoterPlayer) getData("User");
new VoteGUI(plugin, player, user.getUser()).open(GUIMethod.valueOf(plugin.getGui().getGuiMethodGUI().toUpperCase()));
} else {
getInv().forceClose(clickEvent.getPlayer());
}
}
}.addData("player", entry.getKey().getPlayerName()).addData("User", entry.getKey()));
pos++;
}
final TopVoter cur = top;
inv.getPageButtons().add(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteTopSwitchItem()).addPlaceholder("Top", topVoter)) {
@Override
public void onClick(ClickEvent clickEvent) {
if (!clickEvent.getClick().equals(ClickType.RIGHT)) {
new VoteTopVoter(plugin, player, user, cur.next(), 0).open(GUIMethod.CHEST);
} else {
new VoteTopVoter(plugin, player, user, cur.prev(), 0).open(GUIMethod.CHEST);
}
}
});
if (plugin.getGui().getChestVoteTopBackButton()) {
inv.getPageButtons().add(plugin.getCommandLoader().getBackButton(user).setSlot(1));
}
inv.setPages(true);
inv.setMaxInvSize(plugin.getGui().getChestVoteTopSize());
inv.openInventory(player);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations