use of com.bencodez.votingplugin.user.VotingPluginUser 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.votingplugin.user.VotingPluginUser 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.votingplugin.user.VotingPluginUser in project VotingPlugin by Ben12345rocks.
the class AdminVotePlaceholdersPlayer method onBook.
@Override
public void onBook(Player player) {
BookWrapper book = new BookWrapper("Placeholders");
for (PlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getPlaceholders()) {
String identifier = placeholder.getIdentifier();
if (identifier.endsWith("_")) {
identifier += "1";
}
String value = placeholder.placeholderRequest(user, identifier);
String msg = identifier + " = " + value;
Layout layout = new Layout(new ArrayList<String>(Arrays.asList("[Json]")));
layout.replaceTextComponent("[Json]", BookUtil.TextBuilder.of(msg).color(ChatColor.AQUA).onHover(BookUtil.HoverAction.showText(value)).build());
book.addLayout(layout);
}
for (NonPlayerPlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getNonPlayerPlaceholders()) {
String identifier = placeholder.getIdentifier();
if (identifier.endsWith("_")) {
identifier += "1";
}
String value = placeholder.placeholderRequest(identifier);
String msg = identifier + " = " + value;
Layout layout = new Layout(new ArrayList<String>(Arrays.asList("[Json]")));
layout.replaceTextComponent("[Json]", BookUtil.TextBuilder.of(msg).color(ChatColor.AQUA).onHover(BookUtil.HoverAction.showText(value)).build());
book.addLayout(layout);
}
book.open(player);
}
use of com.bencodez.votingplugin.user.VotingPluginUser in project VotingPlugin by Ben12345rocks.
the class AdminVotePlaceholdersPlayer method onChat.
@Override
public void onChat(CommandSender sender) {
ArrayList<String> msg = new ArrayList<String>();
msg.add("&cPlaceholders:");
VotingPluginUser placeholderUser = user;
if (plugin.getConfigFile().isUsePrimaryAccountForPlaceholders() && user.hasPrimaryAccount()) {
placeholderUser = UserManager.getInstance().getVotingPluginUser(user.getPrimaryAccount());
}
for (PlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getPlaceholders()) {
String identifier = placeholder.getIdentifier();
if (identifier.endsWith("_")) {
identifier += "1";
}
msg.add("VotingPlugin_" + identifier + " = " + placeholder.placeholderRequest(placeholderUser, identifier));
}
for (NonPlayerPlaceHolder<VotingPluginUser> placeholder : plugin.getPlaceholders().getNonPlayerPlaceholders()) {
String identifier = placeholder.getIdentifier();
if (identifier.endsWith("_")) {
identifier += "1";
}
msg.add("VotingPlugin_" + identifier + " = " + placeholder.placeholderRequest(identifier));
}
sendMessage(msg);
}
use of com.bencodez.votingplugin.user.VotingPluginUser in project VotingPlugin by Ben12345rocks.
the class VotingPluginMain method basicBungeeUpdate.
public void basicBungeeUpdate() {
for (Player player : Bukkit.getOnlinePlayers()) {
VotingPluginUser user = UserManager.getInstance().getVotingPluginUser(player);
user.clearCache();
user.offVote();
user.checkOfflineRewards();
}
}
Aggregations