Compare commits

...
12 Commits
Author SHA1 Message Date
Ben12345rocks 1cfed8aa98 Bug fix 2018-11-22 18:31:59 -05:00
Ben12345rocks 9f563c37e5 Bug fix 2018-11-22 18:23:15 -05:00
Ben12345rocks d311588984 Update version number 2018-11-22 18:18:27 -05:00
Ben12345rocks 8c5324f602 Fully fix tab complete 2018-11-22 17:40:14 -05:00
Ben12345rocks 17832a0bf7 Bug fix for now 2018-11-21 16:55:04 -05:00
Ben12345rocks 3c415c63c9 Bug fix 2018-11-19 16:55:59 -05:00
Ben12345rocks 6ab27775d2 Bug fix 2018-11-19 16:39:56 -05:00
Ben12345rocks e04bf8210f Minor change 2018-11-18 14:06:19 -05:00
Ben12345rocks 7b4879ddf1 Bug fix 2018-11-18 13:57:22 -05:00
Ben12345rocks 081ac7bb3c Fix misspelling in config 2018-11-18 13:38:48 -05:00
Ben12345rocks d9894c6b74 Add description for placeholders 2018-11-18 13:35:30 -05:00
Ben12345rocks f13f56c830 Add ability to set description for placeholders 2018-11-18 13:26:21 -05:00
11 changed files with 201 additions and 47 deletions

No files matched your search

+3 -2
View File
@@ -165,9 +165,10 @@ Format:
# Lines for each vote site
# %time% = time, using timeformat below
# %timesince% = time since vote
Line: '&3%SiteName%: &6%timeSince% ago'
Line: '&3%SiteName%: &6%timeSince%'
# Spelling of TimeType can be changed under Format.Commands.TimeFormats
TimeFormat: '%amount% %TimeType%'
LastVoted: '%times% ago'
NeverVoted: 'Never voted'
# Format for /vote total
@@ -245,7 +246,7 @@ Format:
# See https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
TimeFormat: 'EEE, d MMM yyyy HH:mm'
TimeFomrats:
TimeFormats:
Day: 'Day'
Days: 'Days'
Hour: 'Hour'
-4
View File
@@ -126,15 +126,11 @@ commands:
adminvoteusers:
description: Command Alias
aliases: avusers
adminvoteClearTotal:
description: Command Alias
aliases: avClearTotal
adminvoteConvertFromData:
description: Command Alias
aliases: avConvertFromData
adminvoteClearTotal:
description: Command Alias
aliases: avClearTotal
adminvoteBackgroundUpdate:
description: Command Alias
aliases: avBackgroundUpdate
+1 -1
View File
@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.Ben12345rocks</groupId>
<artifactId>VotingPlugin</artifactId>
<version>5.16.2</version>
<version>5.16.3</version>
<packaging>jar</packaging>
<name>VotingPlugin</name>
<properties>
@@ -901,7 +901,23 @@ public class CommandLoader {
if (identifier.endsWith("_")) {
identifier += "#";
}
msg.add("%VotingPlugin_" + identifier + "%");
if (placeholder.hasDescription()) {
msg.add("%VotingPlugin_" + identifier + "% - " + placeholder.getDescription());
} else {
msg.add("%VotingPlugin_" + identifier + "%");
}
}
for (PlaceHolder placeholder : PlaceHolders.getInstance().getNonPlayerPlaceholders()) {
String identifier = placeholder.getIdentifier();
if (identifier.endsWith("_")) {
identifier += "#";
}
if (placeholder.hasDescription()) {
msg.add("%VotingPlugin_" + identifier + "% - " + placeholder.getDescription());
} else {
msg.add("%VotingPlugin_" + identifier + "%");
}
}
sendMessage(sender, msg);
@@ -938,10 +954,29 @@ public class CommandLoader {
+ placeholder.placeholderRequest(user.getOfflinePlayer(), user, identifier));
}
for (PlaceHolder placeholder : PlaceHolders.getInstance().getNonPlayerPlaceholders()) {
String identifier = placeholder.getIdentifier();
if (identifier.endsWith("_")) {
identifier += "1";
}
msg.add("%VotingPlugin_" + identifier + "% = "
+ placeholder.placeholderRequest(user.getOfflinePlayer(), user, identifier));
}
sendMessage(sender, msg);
}
});
plugin.getAdminVoteCommand()
.add(new CommandHandler(new String[] { "" }, "VotingPlugin.Commands.AdminVote|" + adminPerm,
"Base command") {
@Override
public void execute(CommandSender sender, String[] args) {
sendMessage(sender, "&cInvalid command, see /adminvote help");
}
});
ArrayList<CommandHandler> avCommands = com.Ben12345rocks.AdvancedCore.Commands.CommandLoader.getInstance()
.getBasicAdminCommands("VotingPlugin");
for (CommandHandler cmd : avCommands) {
@@ -965,7 +1000,6 @@ public class CommandLoader {
plugin.getCommand("vote" + arg)
.setTabCompleter(new AliasesTabCompleter().setCMDHandle(cmdHandle, false));
plugin.getCommand("vote" + arg).setPermission(cmdHandle.getPerm().split("|")[0]);
} catch (Exception ex) {
plugin.debug("Failed to load command and tab completer for /vote" + arg);
}
@@ -983,7 +1017,6 @@ public class CommandLoader {
plugin.getCommand("adminvote" + arg)
.setTabCompleter(new AliasesTabCompleter().setCMDHandle(cmdHandle, true));
plugin.getCommand("adminvote" + arg).setPermission(cmdHandle.getPerm().split("|")[0]);
} catch (Exception ex) {
plugin.debug("Failed to load command and tab completer for /adminvote" + arg + ": "
+ ex.getMessage());
@@ -993,12 +1026,6 @@ public class CommandLoader {
}
}
for (String cmd : plugin.getDescription().getCommands().keySet()) {
String perm = plugin.getCommand(cmd).getPermission();
if (perm == null) {
plugin.debug("/" + cmd + " does not have a permission set");
}
}
}
/**
@@ -1857,4 +1884,67 @@ public class CommandLoader {
public void setCommands(HashMap<String, CommandHandler> commands) {
this.commands = commands;
}
public boolean isVotingPluginCommand(Player player, String cmd) {
if (plugin.getCommand(cmd) != null || cmd.startsWith("votingplugin")) {
return true;
}
for (String str : plugin.getDescription().getCommands().keySet()) {
for (String str1 : plugin.getCommand(str).getAliases()) {
if (str1.equalsIgnoreCase(cmd)) {
return true;
}
}
}
return false;
}
public boolean hasPermission(Player player, String cmd) {
if (cmd.startsWith("votingplugin:")) {
cmd = cmd.substring("votingplugin:".length());
}
boolean adminCommand = false;
if (cmd.startsWith("vote")) {
cmd = cmd.substring("vote".length());
} else if (cmd.startsWith("v")) {
cmd = cmd.substring(1);
} else if (cmd.startsWith("av")) {
adminCommand = true;
cmd = cmd.substring("av".length());
} else if (cmd.startsWith("adminvote")) {
adminCommand = true;
cmd = cmd.substring("adminvote".length());
}
// plugin.debug(cmd);
if (!adminCommand) {
for (CommandHandler handle : plugin.getVoteCommand()) {
if (handle.isCommand(cmd)) {
// plugin.debug("is handle " + ArrayUtils.getInstance()
// .makeStringList(ArrayUtils.getInstance().convert(handle.getArgs())));
if (handle.hasPerm(player)) {
// plugin.debug("has perm");
return true;
} else {
// plugin.debug("no perm " + cmd);
}
}
}
} else {
for (CommandHandler handle : plugin.getAdminVoteCommand()) {
if (handle.isCommand(cmd)) {
// plugin.debug("is handle " + ArrayUtils.getInstance()
// .makeStringList(ArrayUtils.getInstance().convert(handle.getArgs())));
if (handle.hasPerm(player)) {
// plugin.debug("has perm");
return true;
} else {
// plugin.debug("no perm " + cmd);
}
}
}
}
return false;
}
}
@@ -669,6 +669,9 @@ public class Commands {
Config.getInstance().getFormatTimeFormatsSeconds()), "amount", "" + diffSeconds);
}
info = StringUtils.getInstance()
.replacePlaceHolder(Config.getInstance().getFormatCommandsVoteLastLastVoted(), "times", info);
return info;
}
return Config.getInstance().getFormatCommandsVoteLastNeverVoted();
@@ -63,9 +63,14 @@ public class Config extends YMLFile {
@Getter
private String formatCommandsVoteLastLine;
@ConfigDataString(path = "Format.Commands.Vote.Last.NeverVoted", defaultValue = "Never voted")
@Getter
private String formatCommandsVoteLastNeverVoted;
@ConfigDataString(path = "Format.Commands.Vote.Last.LastVoted", defaultValue = "%times% ago")
@Getter
private String formatCommandsVoteLastLastVoted;
@ConfigDataString(path = "Format.TimeFormats.Days", defaultValue = "Days")
@Getter
@@ -0,0 +1,44 @@
package com.Ben12345rocks.VotingPlugin.Listeners;
import java.util.ArrayList;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandSendEvent;
import com.Ben12345rocks.VotingPlugin.Main;
import com.Ben12345rocks.VotingPlugin.Commands.CommandLoader;
// TODO: Auto-generated Javadoc
/**
* The Class PlayerJoinEvent.
*/
public class PlayerCommandSendListener implements Listener {
@SuppressWarnings("unused")
private static Main plugin;
public PlayerCommandSendListener(Main plugin) {
PlayerCommandSendListener.plugin = plugin;
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onTab(PlayerCommandSendEvent event) {
ArrayList<String> removeCmds = new ArrayList<String>();
ArrayList<String> whiteListed = new ArrayList<String>();
for (String cmd : event.getCommands()) {
if (CommandLoader.getInstance().isVotingPluginCommand(event.getPlayer(), cmd)) {
if (!CommandLoader.getInstance().hasPermission(event.getPlayer(), cmd) && !whiteListed.contains(cmd)) {
removeCmds.add(cmd);
// plugin.debug("removed " + cmd);
} else {
removeCmds.remove(cmd);
whiteListed.add(cmd);
// plugin.debug("has " + cmd);
}
}
}
event.getCommands().removeAll(removeCmds);
}
}
@@ -83,6 +83,7 @@ public class PlayerVoteListener implements Listener {
}
User user = UserManager.getInstance().getVotingPluginUser(playerName);
user.updateName();
if (Config.getInstance().isClearCacheOnVote()) {
user.clearCache();
@@ -47,6 +47,7 @@ import com.Ben12345rocks.VotingPlugin.Config.Config;
import com.Ben12345rocks.VotingPlugin.Config.ConfigVoteSites;
import com.Ben12345rocks.VotingPlugin.Data.ServerData;
import com.Ben12345rocks.VotingPlugin.Listeners.BlockBreak;
import com.Ben12345rocks.VotingPlugin.Listeners.PlayerCommandSendListener;
import com.Ben12345rocks.VotingPlugin.Listeners.PlayerInteract;
import com.Ben12345rocks.VotingPlugin.Listeners.PlayerJoinEvent;
import com.Ben12345rocks.VotingPlugin.Listeners.PlayerVoteListener;
@@ -869,6 +870,8 @@ public class Main extends JavaPlugin {
pm.registerEvents(new VotingPluginUpdateEvent(this), this);
pm.registerEvents(new PlayerCommandSendListener(this), this);
plugin.debug("Loaded Events");
}
@@ -12,6 +12,8 @@ public abstract class PlaceHolder {
private String identifier;
@Getter
private boolean useStartsWith = false;
@Getter
private String description;
public PlaceHolder(String identifier) {
this.identifier = identifier;
@@ -42,4 +44,13 @@ public abstract class PlaceHolder {
return this;
}
public PlaceHolder withDescription(String desc) {
description = desc;
return this;
}
public boolean hasDescription() {
return description != null;
}
}
@@ -97,7 +97,7 @@ public class PlaceHolders {
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
return Integer.toString(user.getTotal(TopVoter.Monthly));
}
});
}.withDescription("Month total"));
placeholders.add(new PlaceHolder("alltimetotal") {
@@ -105,7 +105,7 @@ public class PlaceHolders {
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
return Integer.toString(user.getTotal(TopVoter.AllTime));
}
});
}.withDescription("Alltime total"));
placeholders.add(new PlaceHolder("lastmonthtotal") {
@@ -113,7 +113,7 @@ public class PlaceHolders {
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
return Integer.toString(user.getLastMonthTotal());
}
});
}.withDescription("Last month total"));
// end of older placeholders
@@ -123,7 +123,7 @@ public class PlaceHolders {
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
return "" + user.getDisableBroadcast();
}
});
}.withDescription("Returns true/false if user has broadcast disabled"));
placeholders.add(new PlaceHolder("MilestoneCount") {
@@ -131,7 +131,7 @@ public class PlaceHolders {
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
return "" + user.getMilestoneCount();
}
});
}.withDescription("User milestonecount"));
for (final String identifier : Config.getInstance().getIdentifiers()) {
if (Config.getInstance().getIdentifierLimit(identifier) > 0) {
@@ -141,7 +141,7 @@ public class PlaceHolders {
public String placeholderRequest(OfflinePlayer p, User user, String ident) {
return "" + user.getVoteShopIdentifierLimit(identifier);
}
});
}.withDescription("User voteshop limit for " + identifier));
}
}
@@ -152,7 +152,7 @@ public class PlaceHolders {
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
return Integer.toString(user.getTotal(top));
}
});
}.withDescription("User total for " + top.getName()));
}
placeholders.add(new PlaceHolder("BestDailyTotal") {
@@ -161,7 +161,7 @@ public class PlaceHolders {
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
return Integer.toString(user.getHighestDailyTotal());
}
});
}.withDescription("Best daily total"));
placeholders.add(new PlaceHolder("BestWeeklyTotal") {
@@ -169,7 +169,7 @@ public class PlaceHolders {
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
return Integer.toString(user.getHighestWeeklyTotal());
}
});
}.withDescription("Best weekly total"));
placeholders.add(new PlaceHolder("BestMonthlyTotal") {
@@ -177,7 +177,7 @@ public class PlaceHolders {
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
return Integer.toString(user.getHighestMonthlyTotal());
}
});
}.withDescription("Best monthly total"));
placeholders.add(new PlaceHolder("DailyVoteStreak") {
@@ -185,7 +185,7 @@ public class PlaceHolders {
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
return Integer.toString(user.getDayVoteStreak());
}
});
}.withDescription("Current daily votestreak"));
placeholders.add(new PlaceHolder("WeeklyVoteStreak") {
@@ -193,7 +193,7 @@ public class PlaceHolders {
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
return Integer.toString(user.getWeekVoteStreak());
}
});
}.withDescription("Current weekly votestreak"));
placeholders.add(new PlaceHolder("MonthVoteStreak") {
@@ -201,7 +201,7 @@ public class PlaceHolders {
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
return Integer.toString(user.getMonthVoteStreak());
}
});
}.withDescription("Current month votestreak"));
placeholders.add(new PlaceHolder("BestDailyVoteStreak") {
@@ -209,7 +209,7 @@ public class PlaceHolders {
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
return Integer.toString(user.getBestDayVoteStreak());
}
});
}.withDescription("Best daily votestreak"));
placeholders.add(new PlaceHolder("BestWeeklyVoteStreak") {
@@ -217,7 +217,7 @@ public class PlaceHolders {
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
return Integer.toString(user.getBestWeekVoteStreak());
}
});
}.withDescription("Best weekly votestreak"));
placeholders.add(new PlaceHolder("BestMonthVoteStreak") {
@@ -225,7 +225,7 @@ public class PlaceHolders {
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
return Integer.toString(user.getBestMonthVoteStreak());
}
});
}.withDescription("Best month votestreak"));
placeholders.add(new PlaceHolder("Points") {
@@ -233,7 +233,7 @@ public class PlaceHolders {
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
return Integer.toString(user.getPoints());
}
});
}.withDescription("User points"));
placeholders.add(new PlaceHolder("CanVote") {
@@ -241,7 +241,7 @@ public class PlaceHolders {
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
return Boolean.toString(user.canVoteAll());
}
});
}.withDescription("Return true/false if player can vote on all sites"));
for (final VoteSite voteSite : plugin.getVoteSites()) {
placeholders.add(new PlaceHolder("Next_" + voteSite.getKey()) {
@@ -250,14 +250,14 @@ public class PlaceHolders {
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
return Commands.getInstance().voteCommandNextInfo(user, voteSite);
}
});
}.withDescription("How long until user can vote on " + voteSite.getKey()));
placeholders.add(new PlaceHolder("Last_" + voteSite.getKey()) {
@Override
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
return Commands.getInstance().voteCommandLastDuration(user, voteSite);
}
});
}.withDescription("How long ago user voted on " + voteSite.getKey()));
}
placeholders.add(new PlaceHolder("Top_All_Position") {
@@ -273,7 +273,7 @@ public class PlaceHolders {
}
return "";
}
});
}.withDescription("Get user top voter position"));
placeholders.add(new PlaceHolder("Top_All_") {
@@ -289,7 +289,7 @@ public class PlaceHolders {
}
return "";
}
}.useStartsWith());
}.useStartsWith().withDescription("Get user at postion in top voter"));
placeholders.add(new PlaceHolder("Top_Month_Position") {
@@ -304,7 +304,7 @@ public class PlaceHolders {
}
return "";
}
});
}.withDescription("Get user top voter position"));
placeholders.add(new PlaceHolder("Top_Month_") {
@@ -320,7 +320,7 @@ public class PlaceHolders {
}
return "";
}
}.useStartsWith());
}.useStartsWith().withDescription("Get user at postion in top voter"));
placeholders.add(new PlaceHolder("Top_Week_Position") {
@@ -335,7 +335,7 @@ public class PlaceHolders {
}
return "";
}
});
}.withDescription("Get user top voter position"));
placeholders.add(new PlaceHolder("Top_Week_") {
@@ -351,7 +351,7 @@ public class PlaceHolders {
}
return "";
}
}.useStartsWith());
}.useStartsWith().withDescription("Get user at postion in top voter"));
placeholders.add(new PlaceHolder("Top_Daily_Position") {
@@ -366,7 +366,7 @@ public class PlaceHolders {
}
return "";
}
});
}.withDescription("Get user top voter position"));
placeholders.add(new PlaceHolder("Top_Daily_") {
@@ -382,7 +382,7 @@ public class PlaceHolders {
}
return "";
}
}.useStartsWith());
}.useStartsWith().withDescription("Get user at postion in top voter"));
// non players
@@ -392,7 +392,7 @@ public class PlaceHolders {
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
return Integer.toString(VoteParty.getInstance().getTotalVotes());
}
});
}.withDescription("Current amount of voteparty votes"));
nonPlayerPlaceholders.add(new PlaceHolder("VotePartyVotesNeeded") {
@@ -400,7 +400,7 @@ public class PlaceHolders {
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
return Integer.toString(VoteParty.getInstance().getNeededVotes());
}
});
}.withDescription("Voteparty votes needed"));
nonPlayerPlaceholders.add(new PlaceHolder("VotePartyVotesRequired") {
@@ -408,6 +408,6 @@ public class PlaceHolders {
public String placeholderRequest(OfflinePlayer p, User user, String identifier) {
return Integer.toString(VoteParty.getInstance().getVotesRequired());
}
});
}.withDescription("Amount of votes needed for voteparty"));
}
}