use of com.bencodez.advancedcore.api.item.ItemBuilder in project VotingPlugin by Ben12345rocks.
the class VotingPluginMain method onPostLoad.
@Override
public void onPostLoad() {
loadVersionFile();
getOptions().setServer(bungeeSettings.getServer());
if (bungeeSettings.isUseBungeecoord()) {
bungeeHandler = new BungeeHandler(this);
bungeeHandler.load();
if (getOptions().getServer().equalsIgnoreCase("PleaseSet")) {
getLogger().warning("Bungeecoord is true and server name is not set, bungeecoord features may not work");
}
}
registerCommands();
checkVotifier();
registerEvents();
loadDirectlyDefined();
checkUpdate = new CheckUpdate(this);
checkUpdate.startUp();
voteReminding = new VoteReminding(this);
voteReminding.loadRemindChecking();
specialRewards = new SpecialRewards(this);
signs = new Signs(this);
coolDownCheck.checkEnabled();
coolDownCheck.load();
Bukkit.getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
signs.loadSigns();
}
});
topVoterHandler = new TopVoterHandler(this);
lastMonthTopVoter = new LinkedHashMap<TopVoterPlayer, Integer>();
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
topVoterHandler.loadLastMonth();
debug("Loaded last month top voters");
}
});
topVoter = new LinkedHashMap<TopVoter, LinkedHashMap<TopVoterPlayer, Integer>>();
for (TopVoter top : TopVoter.values()) {
topVoter.put(top, new LinkedHashMap<TopVoterPlayer, Integer>());
}
voteToday = new LinkedHashMap<TopVoterPlayer, HashMap<VoteSite, LocalDateTime>>();
voteLog = new Logger(plugin, new File(plugin.getDataFolder() + File.separator + "Log", "votelog.txt"));
new AdminGUI(this).loadHook();
// vote party
voteParty = new VoteParty(this);
voteParty.register();
topVoterHandler.register();
metrics();
// javascript api
getJavascriptEngineRequests().add(new JavascriptPlaceholderRequest("User") {
@Override
public Object getObject(OfflinePlayer player) {
return getVotingPluginUserManager().getVotingPluginUser(player);
}
});
getJavascriptEngine().put("VotingPluginHooks", VotingPluginHooks.getInstance());
loadTimer();
// placeholderapi loading
placeholders = new PlaceHolders(this);
placeholders.load();
if (Bukkit.getPluginManager().isPluginEnabled("MVdWPlaceholderAPI")) {
mvdwPlaceholders = new MVdWPlaceholders(this);
mvdwPlaceholders.loadMVdWPlaceholders();
}
// Add rewards
RewardHandler.getInstance().addInjectedReward(new RewardInjectInt("Points", 0) {
@Override
public String onRewardRequest(Reward reward, com.bencodez.advancedcore.api.user.AdvancedCoreUser user, int num, HashMap<String, String> placeholders) {
UserManager.getInstance().getVotingPluginUser(user).addPoints(num);
return null;
}
}.synchronize().addEditButton(new EditGUIButton(new ItemBuilder(Material.PAPER), new EditGUIValueNumber("Points", null) {
@Override
public void setValue(Player player, Number value) {
RewardEditData reward = (RewardEditData) getInv().getData("Reward");
reward.setValue("Points", value.intValue());
}
}.addLore("Give player voting points"))).validator(new RewardInjectValidator() {
@Override
public void onValidate(Reward reward, RewardInject inject, ConfigurationSection data) {
if (data.getInt(inject.getPath(), -1) == 0) {
warning(reward, inject, "Points can not be 0");
}
}
}));
RewardHandler.getInstance().addInjectedReward(new RewardInjectConfigurationSection("VoteBossBar") {
@Override
public String onRewardRequested(Reward arg0, com.bencodez.advancedcore.api.user.AdvancedCoreUser user, ConfigurationSection section, HashMap<String, String> placeholders) {
if (section.getBoolean("Enabled")) {
user.sendBossBar(StringParser.getInstance().replacePlaceHolder(section.getString("Message", ""), placeholders), section.getString("Color", "BLUE"), section.getString("Style", "SOLID"), (double) UserManager.getInstance().getVotingPluginUser(user).getSitesVotedOn() / plugin.getVoteSites().size(), section.getInt("Delay", 30));
}
return null;
}
});
for (final TopVoter top : TopVoter.values()) {
RewardHandler.getInstance().addPlaceholder(new RewardPlaceholderHandle("Total_" + top.toString()) {
@Override
public String getValue(Reward reward, com.bencodez.advancedcore.api.user.AdvancedCoreUser user) {
VotingPluginUser vUser = UserManager.getInstance().getVotingPluginUser(user);
return "" + vUser.getTotal(top);
}
});
}
if (plugin.getConfigFile().isFormatAlternateBroadcastEnabled()) {
broadcastHandler = new BroadcastHandler(plugin, plugin.getConfigFile().getFormatAlternateBroadcastDelay());
plugin.debug("Using alternate broadcast method");
}
plugin.getLogger().info("Enabled VotingPlugin " + plugin.getDescription().getVersion());
if (getProfile().contains("dev")) {
plugin.getLogger().info("Using dev build, this is not a stable build, use at your own risk. Build number: " + buildNumber);
}
boolean hasRewards = RewardHandler.getInstance().hasRewards(getConfigVoteSites().getData(), getConfigVoteSites().getEverySiteRewardPath());
boolean issues = true;
ArrayList<String> services = serverData.getServiceSites();
for (VoteSite site : getVoteSites()) {
if (!site.hasRewards() && !hasRewards) {
issues = false;
plugin.getLogger().warning("No rewards detected for the site: " + site.getKey() + ". See https://github.com/BenCodez/VotingPlugin/wiki/Rewards");
}
boolean contains = false;
for (String service : services) {
if (service.equalsIgnoreCase(site.getServiceSite())) {
contains = true;
}
}
if (!contains) {
issues = false;
plugin.getLogger().warning("No vote has been recieved from " + site.getServiceSite() + ", may be an invalid service site. Please read: https://github.com/BenCodez/VotingPlugin/wiki/Votifier-Troubleshooting");
}
}
if (!issues) {
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@Override
public void run() {
plugin.getLogger().warning("Detected an issue with voting sites, check the server startup log for more details: https://github.com/BenCodez/VotingPlugin/wiki/Votifier-Troubleshooting");
}
}, 30l);
}
}
use of com.bencodez.advancedcore.api.item.ItemBuilder 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.item.ItemBuilder in project VotingPlugin by Ben12345rocks.
the class VoteGUI method getItemSlot.
private ItemBuilder getItemSlot(String slot, Player player) {
ItemBuilder builder = new ItemBuilder(plugin.getGui().getChestVoteGUISlotSection(slot));
String[] lore = new String[1];
lore = ArrayUtils.getInstance().convert(plugin.getGui().getChestVoteGUISlotLore(slot));
String str = plugin.getConfigFile().getVoteTopDefault();
if (lore.length == 0) {
if (slot.equalsIgnoreCase("url")) {
lore = new String[] { "&aClick me" };
} else if (slot.equalsIgnoreCase("next")) {
lore = ArrayUtils.getInstance().convert(new VoteNext(plugin, player, user).getChat(player));
} else if (slot.equalsIgnoreCase("last")) {
lore = ArrayUtils.getInstance().convert(new VoteLast(plugin, player, user).getChat(player));
} else if (slot.equalsIgnoreCase("total")) {
lore = ArrayUtils.getInstance().convert(new VoteTotal(plugin, player, user).getChat(player));
} else if (slot.equalsIgnoreCase("top")) {
if (str.equalsIgnoreCase("monthly")) {
lore = plugin.getTopVoterHandler().topVoterMonthly(1);
} else if (str.equalsIgnoreCase("weekly")) {
lore = plugin.getTopVoterHandler().topVoterWeekly(1);
} else if (str.equalsIgnoreCase("daily")) {
lore = plugin.getTopVoterHandler().topVoterDaily(1);
} else {
lore = plugin.getTopVoterHandler().topVoterAllTime(1);
}
} else if (slot.equalsIgnoreCase("today")) {
String[] today = new VoteToday(plugin, player, user, 1).voteTodayGUI();
ArrayList<String> list = new ArrayList<String>();
if (today.length > 0) {
for (int i = today.length - 1; i < today.length && list.size() < 10 && i >= 0; i--) {
list.add(today[i]);
}
}
lore = ArrayUtils.getInstance().convert(list);
} else if (slot.equalsIgnoreCase("help")) {
lore = new String[] { "Click to view help" };
}
}
builder.setLore(ArrayUtils.getInstance().convert(lore));
return builder;
}
use of com.bencodez.advancedcore.api.item.ItemBuilder 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.item.ItemBuilder 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);
}
Aggregations