diff --git a/lib/nuvotifier.jar b/lib/nuvotifier.jar new file mode 100644 index 0000000..7a59a1d Binary files /dev/null and b/lib/nuvotifier.jar differ diff --git a/pom.xml b/pom.xml index a9470d3..804a8c4 100644 --- a/pom.xml +++ b/pom.xml @@ -100,14 +100,14 @@ - - papermc - https://repo.papermc.io/repository/maven-public/ - jitpack.io https://jitpack.io/ + + papermc + https://repo.papermc.io/repository/maven-public/ + placeholderapi https://repo.extendedclip.com/content/repositories/placeholderapi/ @@ -132,18 +132,6 @@ provided - - com.github.megavexnetwork.scoreboard-library - scoreboard-library-api - 2.1.3 - - - com.github.megavexnetwork.scoreboard-library - scoreboard-library-implementation - 2.1.3 - runtime - - me.clip placeholderapi @@ -171,12 +159,13 @@ 4.9.2 provided + - com.google.guava - guava - 33.1.0-jre - compile + com.vexsoftware + nuvotifier-universal + 2.7.3 + ${basedir}/lib/nuvotifier.jar + system - \ No newline at end of file diff --git a/src/main/java/cc/fascinated/Aetheria.java b/src/main/java/cc/fascinated/Aetheria.java index bd3233a..518df59 100644 --- a/src/main/java/cc/fascinated/Aetheria.java +++ b/src/main/java/cc/fascinated/Aetheria.java @@ -4,13 +4,18 @@ import cc.fascinated.account.AccountManager; import cc.fascinated.chat.ChatManager; import cc.fascinated.command.CommandManager; import cc.fascinated.commandspy.CommandSpyManager; +import cc.fascinated.config.Config; +import cc.fascinated.config.Lang; import cc.fascinated.event.EventManager; import cc.fascinated.metrics.MetricManager; +import cc.fascinated.misc.RenderDistanceManager; import cc.fascinated.motd.MotdManager; import cc.fascinated.placeholder.PlaceholderManager; import cc.fascinated.playercolor.PlayerColorManager; -import cc.fascinated.renderdistance.RenderDistanceManager; +import cc.fascinated.staffchat.StaffChatManager; +import cc.fascinated.staffchat.command.StaffChatCommand; import cc.fascinated.utils.BuildData; +import cc.fascinated.vote.VoteManager; import cc.fascinated.worldsize.WorldSizeManager; import lombok.Getter; import org.bukkit.plugin.java.JavaPlugin; @@ -38,6 +43,9 @@ public class Aetheria extends JavaPlugin { public void onEnable() { saveDefaultConfig(); + Config.clear(); + Lang.clear(); + new AccountManager(); new EventManager(); @@ -50,5 +58,7 @@ public class Aetheria extends JavaPlugin { new MotdManager(); new CommandSpyManager(); new RenderDistanceManager(); + new VoteManager(); + new StaffChatManager(); } } \ No newline at end of file diff --git a/src/main/java/cc/fascinated/account/Account.java b/src/main/java/cc/fascinated/account/Account.java index 9553746..d8d2eaf 100644 --- a/src/main/java/cc/fascinated/account/Account.java +++ b/src/main/java/cc/fascinated/account/Account.java @@ -2,11 +2,11 @@ package cc.fascinated.account; import cc.fascinated.Aetheria; import cc.fascinated.config.Lang; -import cc.fascinated.playercolor.PlayerColor; +import cc.fascinated.playercolor.PlayerColorProfile; import cc.fascinated.utils.Style; +import cc.fascinated.vote.VoteProfile; import lombok.EqualsAndHashCode; import lombok.Getter; -import lombok.SneakyThrows; import lombok.extern.log4j.Log4j2; import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; @@ -25,6 +25,7 @@ public class Account { * Profile keys. */ private static final String playerColorProfileId = "playerColorProfile"; + private static final String voteProfileId = "voteProfile"; /** * The last hashcode of the account. This is used to check if any changes @@ -40,6 +41,11 @@ public class Account { @EqualsAndHashCode.Exclude private final UUID uuid; + /** + * The name of the player. + */ + private final String name; + /** * The first time the player joined the server. */ @@ -65,7 +71,8 @@ public class Account { /** * Account profiles. */ - private final PlayerColor playerColorProfile; + private final PlayerColorProfile playerColorProfile; + private final VoteProfile voteProfile; public Account(UUID uuid) { //log.info("Loading account for " + uuid); @@ -98,9 +105,11 @@ public class Account { this.lastLogin = config.getLong("lastLogin"); this.lastLogin = System.currentTimeMillis(); // Update last login + this.name = Bukkit.getOfflinePlayer(uuid).getName(); // Load profiles - this.playerColorProfile = new PlayerColor(this, this.getProfileSection(playerColorProfileId)); + this.playerColorProfile = new PlayerColorProfile(this, this.getProfileSection(playerColorProfileId)); + this.voteProfile = new VoteProfile(this, this.getProfileSection(voteProfileId)); this.lastHash = this.hashCode(); @@ -114,20 +123,13 @@ public class Account { * @param key the key to save the profile under */ private void saveProfile(Profile profile, String key) { - profile.save(config.getConfigurationSection(key) == null ? config.createSection(key) : config.getConfigurationSection(key)); + profile.save(this.getProfileSection(key)); } private ConfigurationSection getProfileSection(String key) { - return this.config.getConfigurationSection(key); - } - - /** - * Get the name of the player. - * - * @return the name - */ - public String getName() { - return this.getPlayer().getName(); + return this.config.getConfigurationSection(key) != null + ? this.config.getConfigurationSection(key) + : this.config.createSection(key); } /** @@ -148,6 +150,15 @@ public class Account { return Bukkit.getOfflinePlayer(uuid); } + /** + * Check if the player is online. + * + * @return if the player is online + */ + public boolean isOnline() { + return this.getPlayer() != null; + } + /** * Send a message to the player. * @@ -204,7 +215,6 @@ public class Account { * @param saveProfiles if the profiles should be saved * @return true if the account was saved, false otherwise */ - @SneakyThrows public boolean save(boolean saveProfiles) { if (this.lastHash == this.hashCode()) { return false; // No changes have been made @@ -215,9 +225,16 @@ public class Account { if (saveProfiles) { this.saveProfile(this.playerColorProfile, playerColorProfileId); + this.saveProfile(this.voteProfile, voteProfileId); } - this.config.save(this.file); // Save the account to disk + try { + this.config.save(this.file); // Save the account to disk + } catch (Exception ex) { + log.warn("Failed to save account for " + this.uuid); + ex.printStackTrace(); + return false; + } this.lastHash = this.hashCode(); // Update the last hash return true; } diff --git a/src/main/java/cc/fascinated/account/AccountManager.java b/src/main/java/cc/fascinated/account/AccountManager.java index b184fe1..df5d748 100644 --- a/src/main/java/cc/fascinated/account/AccountManager.java +++ b/src/main/java/cc/fascinated/account/AccountManager.java @@ -5,13 +5,11 @@ import cc.fascinated.account.command.SaveAccountsCommand; import cc.fascinated.command.CommandManager; import cc.fascinated.config.Config; import cc.fascinated.config.Lang; -import cc.fascinated.playercolor.PlayerColor; +import cc.fascinated.playercolor.PlayerColorProfile; import cc.fascinated.utils.DiscordWebhook; import cc.fascinated.utils.Manager; import cc.fascinated.utils.Priority; import cc.fascinated.utils.Style; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; import com.viaversion.viaversion.api.Via; import lombok.extern.log4j.Log4j2; import org.bukkit.Bukkit; @@ -23,31 +21,23 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; +import java.util.*; import java.util.concurrent.TimeUnit; @Log4j2 public class AccountManager extends Manager implements Listener { private final long SAVE_INTERVAL = 5; // in minutes - private static final Cache ACCOUNTS = CacheBuilder.newBuilder() - .expireAfterAccess(30, TimeUnit.MINUTES) - .removalListener(notification -> { - Account account = (Account) notification.getValue(); - if (account != null) { - account.save(); // Save the account when it is removed from the cache - log.info("Saved account for {} because it was removed from the cache.", account.getName()); - } - }) - .build(); + private static final Map ACCOUNTS = new HashMap<>(); public AccountManager() { CommandManager.registerCommand(new SaveAccountsCommand()); Aetheria.INSTANCE.getServer().getPluginManager().registerEvents(this, Aetheria.INSTANCE); for (Player player : Bukkit.getOnlinePlayers()) { + if (isAccountLoaded(player.getUniqueId())) { // Don't load the account if it's already loaded + continue; + } loadAccount(player.getUniqueId()); } @@ -68,7 +58,7 @@ public class AccountManager extends Manager implements Listener { * @return the account */ public static Account getAccount(UUID uuid) { - return ACCOUNTS.getIfPresent(uuid); + return ACCOUNTS.get(uuid); } /** @@ -78,7 +68,7 @@ public class AccountManager extends Manager implements Listener { * @return true if the account is already registered, false otherwise */ private boolean isAccountLoaded(UUID uuid) { - return ACCOUNTS.getIfPresent(uuid) != null; + return ACCOUNTS.containsKey(uuid); } /** @@ -92,19 +82,23 @@ public class AccountManager extends Manager implements Listener { } /** - * Save all accounts to disk. + * Save dirty accounts to disk. */ public static void saveAccounts() { long before = System.currentTimeMillis(), saved = 0; // The amount of accounts that were saved log.info("Saving accounts..."); - for (Map.Entry entry : ACCOUNTS.asMap().entrySet()) { - Account account = entry.getValue(); + List toRemove = new ArrayList<>(); + for (Account account : ACCOUNTS.values()) { boolean didSave = account.save(); // Save the account if (didSave) { saved++; } + if (!account.isOnline()) { + toRemove.add(account); + } } + toRemove.forEach(account -> ACCOUNTS.remove(account.getUuid())); // Unload offline accounts log.info("Saved {}/{} accounts. ({}ms)", saved, ACCOUNTS.size(), System.currentTimeMillis() - before); } @@ -120,7 +114,7 @@ public class AccountManager extends Manager implements Listener { @Override public void onPlayerJoin(Account account, PlayerJoinEvent event) { String joinMessage = Lang.JOIN_MESSAGE.getAsString(); - PlayerColor playerColorProfile = account.getPlayerColorProfile(); + PlayerColorProfile playerColorProfile = account.getPlayerColorProfile(); if (!account.getPlayer().hasPlayedBefore()) { joinMessage = Lang.FIRST_JOIN_MESSAGE.getAsString(); diff --git a/src/main/java/cc/fascinated/config/Config.java b/src/main/java/cc/fascinated/config/Config.java index 6fa1e18..94eee0f 100644 --- a/src/main/java/cc/fascinated/config/Config.java +++ b/src/main/java/cc/fascinated/config/Config.java @@ -33,7 +33,7 @@ public enum Config { /** * Cache of the config values. */ - private final HashMap cache = new HashMap<>(); + private static final HashMap cache = new HashMap<>(); /** * The configuration. @@ -76,4 +76,11 @@ public enum Config { public int getAsInt() { return (int) get(); } + + /** + * Clear the cache. + */ + public static void clear() { + cache.clear(); + } } diff --git a/src/main/java/cc/fascinated/config/Lang.java b/src/main/java/cc/fascinated/config/Lang.java index 88eabbd..1d7702d 100644 --- a/src/main/java/cc/fascinated/config/Lang.java +++ b/src/main/java/cc/fascinated/config/Lang.java @@ -24,6 +24,7 @@ public enum Lang { VOTE_COMMAND_HEADER("vote-command.header"), VOTE_COMMAND_FORMAT("vote-command.format"), VOTE_COMMAND_LINKS("vote-command.links"), + VOTE_STATS_COMMAND("vote-stats-command"), SAVE_ACCOUNTS_COMMAND_SAVING("save-accounts-command.saving"), SAVE_ACCOUNTS_COMMAND_SAVED("save-accounts-command.saved"), BLOCKED_MESSAGE("blocked-message"), @@ -35,7 +36,11 @@ public enum Lang { COMMAND_SPY_ENABLED("command-spy.toggled-on"), COMMAND_SPY_DISABLED("command-spy.toggled-off"), COMMAND_SPY_FORMAT("command-spy.format"), - RENDER_DISTANCE_MESSAGE("render-distance-message"); + RENDER_DISTANCE_MESSAGE("render-distance-message"), + VOTE_VOTED("vote.voted"), + VOTE_BROADCAST("vote.broadcast"), + STAFF_CHAT_FORMAT("staff-chat.format"), + STAFF_CHAT_USAGE("staff-chat.usage"); /** * The path of the lang in the lang.yml file. @@ -49,7 +54,7 @@ public enum Lang { /** * Cache of the lang values. */ - private final HashMap cache = new HashMap<>(); + private static final HashMap cache = new HashMap<>(); /** * The lang configuration. @@ -88,4 +93,11 @@ public enum Lang { public List getAsStringList() { return (List) get(); } + + /** + * Clear the cache. + */ + public static void clear() { + cache.clear(); + } } diff --git a/src/main/java/cc/fascinated/event/EventListener.java b/src/main/java/cc/fascinated/event/EventListener.java index a4e3c74..17068f7 100644 --- a/src/main/java/cc/fascinated/event/EventListener.java +++ b/src/main/java/cc/fascinated/event/EventListener.java @@ -2,6 +2,7 @@ package cc.fascinated.event; import cc.fascinated.account.Account; import cc.fascinated.utils.Priority; +import com.vexsoftware.votifier.model.VotifierEvent; import io.papermc.paper.event.player.AsyncChatEvent; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; @@ -24,4 +25,5 @@ public interface EventListener { default void onCommandPreProcess(Account account, PlayerCommandPreprocessEvent event) {} default void onServerListPing(ServerListPingEvent event) {} default void onEntityDeath(EntityDeathEvent event) {} + default void onVote(Account account, VotifierEvent event) {} } diff --git a/src/main/java/cc/fascinated/event/EventManager.java b/src/main/java/cc/fascinated/event/EventManager.java index 4686d8b..3c6bb1c 100644 --- a/src/main/java/cc/fascinated/event/EventManager.java +++ b/src/main/java/cc/fascinated/event/EventManager.java @@ -3,7 +3,10 @@ package cc.fascinated.event; import cc.fascinated.Aetheria; import cc.fascinated.account.Account; import cc.fascinated.account.AccountManager; +import com.vexsoftware.votifier.model.VotifierEvent; import io.papermc.paper.event.player.AsyncChatEvent; +import lombok.Getter; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -25,6 +28,7 @@ public class EventManager implements Listener { /** * All registered listeners. */ + @Getter private static final List LISTENERS = Collections.synchronizedList(new LinkedList<>()); public EventManager() { @@ -114,4 +118,16 @@ public class EventManager implements Listener { listener.onEntityDeath(event); } } + + @EventHandler + public void onVote(VotifierEvent event) { + Account account = AccountManager.getAccount(Bukkit.getOfflinePlayer(event.getVote().getUsername()).getUniqueId()); + if (account == null) { + return; + } + + for (EventListener listener : LISTENERS) { + listener.onVote(account, event); + } + } } diff --git a/src/main/java/cc/fascinated/renderdistance/RenderDistanceManager.java b/src/main/java/cc/fascinated/misc/RenderDistanceManager.java similarity index 94% rename from src/main/java/cc/fascinated/renderdistance/RenderDistanceManager.java rename to src/main/java/cc/fascinated/misc/RenderDistanceManager.java index 2ef6c78..bf18edd 100644 --- a/src/main/java/cc/fascinated/renderdistance/RenderDistanceManager.java +++ b/src/main/java/cc/fascinated/misc/RenderDistanceManager.java @@ -1,4 +1,4 @@ -package cc.fascinated.renderdistance; +package cc.fascinated.misc; import cc.fascinated.account.Account; import cc.fascinated.config.Lang; diff --git a/src/main/java/cc/fascinated/playercolor/PlayerColorManager.java b/src/main/java/cc/fascinated/playercolor/PlayerColorManager.java index 04e7706..0087327 100644 --- a/src/main/java/cc/fascinated/playercolor/PlayerColorManager.java +++ b/src/main/java/cc/fascinated/playercolor/PlayerColorManager.java @@ -94,7 +94,7 @@ public class PlayerColorManager extends Manager { @Override public void onPlayerJoin(Account account, PlayerJoinEvent event) { - PlayerColor playerColor = account.getPlayerColorProfile(); + PlayerColorProfile playerColor = account.getPlayerColorProfile(); Team team = PlayerColorManager.getScoreboardTeam(playerColor.getColor()); team.addEntry(account.getName()); @@ -102,7 +102,7 @@ public class PlayerColorManager extends Manager { @Override public void onPlayerQuit(Account account, PlayerQuitEvent event) { - PlayerColor playerColor = account.getPlayerColorProfile(); + PlayerColorProfile playerColor = account.getPlayerColorProfile(); Team team = PlayerColorManager.getScoreboardTeam(playerColor.getColor()); team.removeEntry(account.getName()); diff --git a/src/main/java/cc/fascinated/playercolor/PlayerColor.java b/src/main/java/cc/fascinated/playercolor/PlayerColorProfile.java similarity index 89% rename from src/main/java/cc/fascinated/playercolor/PlayerColor.java rename to src/main/java/cc/fascinated/playercolor/PlayerColorProfile.java index ac3ec5c..5e57cb7 100644 --- a/src/main/java/cc/fascinated/playercolor/PlayerColor.java +++ b/src/main/java/cc/fascinated/playercolor/PlayerColorProfile.java @@ -10,14 +10,14 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.scoreboard.Team; @Getter @Setter @EqualsAndHashCode(callSuper = false) -public class PlayerColor extends Profile { +public class PlayerColorProfile extends Profile { /** * The current color of the player. */ private NamedTextColor color; - public PlayerColor(Account account, ConfigurationSection section) { + public PlayerColorProfile(Account account, ConfigurationSection section) { super(account, section); if (section == null) { diff --git a/src/main/java/cc/fascinated/playercolor/command/PlayerColorCommand.java b/src/main/java/cc/fascinated/playercolor/command/PlayerColorCommand.java index 4c97076..4c743c4 100644 --- a/src/main/java/cc/fascinated/playercolor/command/PlayerColorCommand.java +++ b/src/main/java/cc/fascinated/playercolor/command/PlayerColorCommand.java @@ -2,7 +2,7 @@ package cc.fascinated.playercolor.command; import cc.fascinated.account.Account; import cc.fascinated.command.Command; -import cc.fascinated.playercolor.PlayerColor; +import cc.fascinated.playercolor.PlayerColorProfile; import cc.fascinated.playercolor.PlayerColorManager; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -19,7 +19,7 @@ public class PlayerColorCommand extends Command { @Override public void execute(Account account, String[] args) { List validColors = PlayerColorManager.getValidColors(); - PlayerColor playerColorProfile = account.getPlayerColorProfile(); + PlayerColorProfile playerColorProfile = account.getPlayerColorProfile(); if (args.length == 0) { account.sendMessage(Component.text("§b§lPLAYERCOLOR §7» §fYour current color is: ").append(Component.text(playerColorProfile.getColor().toString()).color(playerColorProfile.getColor()))); diff --git a/src/main/java/cc/fascinated/staffchat/StaffChatManager.java b/src/main/java/cc/fascinated/staffchat/StaffChatManager.java new file mode 100644 index 0000000..22b6769 --- /dev/null +++ b/src/main/java/cc/fascinated/staffchat/StaffChatManager.java @@ -0,0 +1,11 @@ +package cc.fascinated.staffchat; + +import cc.fascinated.staffchat.command.StaffChatCommand; +import cc.fascinated.utils.Manager; + +public class StaffChatManager extends Manager { + + public StaffChatManager() { + registerCommand(new StaffChatCommand()); + } +} diff --git a/src/main/java/cc/fascinated/staffchat/command/StaffChatCommand.java b/src/main/java/cc/fascinated/staffchat/command/StaffChatCommand.java new file mode 100644 index 0000000..397440a --- /dev/null +++ b/src/main/java/cc/fascinated/staffchat/command/StaffChatCommand.java @@ -0,0 +1,38 @@ +package cc.fascinated.staffchat.command; + +import cc.fascinated.account.Account; +import cc.fascinated.account.AccountManager; +import cc.fascinated.command.Command; +import cc.fascinated.config.Lang; +import org.bukkit.Bukkit; + +public class StaffChatCommand extends Command { + + public StaffChatCommand() { + super("staffchat", "aetheria.command.staffchat"); + } + + @Override + public void execute(Account account, String[] args) { + if (args.length == 0) { + account.sendMessage(Lang.STAFF_CHAT_USAGE.getAsString()); + return; + } + + StringBuilder message = new StringBuilder(); + for (String arg : args) { + message.append(arg).append(" "); + } + + Bukkit.getOnlinePlayers().stream() + .filter(player -> player.hasPermission("aetheria.command.staffchat")) + .forEach(player -> { + Account staffAccount = AccountManager.getAccount(player.getUniqueId()); + staffAccount.sendMessage(Lang.STAFF_CHAT_FORMAT.getAsString() + .replace("%player%", account.getPlayer().getName()) + .replace("%message%", message.toString()) + .replace("player-color", account.getPlayerColorProfile().getColor().toString()) + ); + }); + } +} diff --git a/src/main/java/cc/fascinated/utils/MessageUtils.java b/src/main/java/cc/fascinated/utils/MessageUtils.java index 75f4e80..42b9eb5 100644 --- a/src/main/java/cc/fascinated/utils/MessageUtils.java +++ b/src/main/java/cc/fascinated/utils/MessageUtils.java @@ -17,4 +17,13 @@ public class MessageUtils { } } } + + /** + * Broadcast a message to all players. + * + * @param message the message to broadcast + */ + public static void broadcast(String message) { + Bukkit.broadcast(Style.getMiniMessage().deserialize(message)); + } } diff --git a/src/main/java/cc/fascinated/vote/VoteManager.java b/src/main/java/cc/fascinated/vote/VoteManager.java new file mode 100644 index 0000000..a1edd5d --- /dev/null +++ b/src/main/java/cc/fascinated/vote/VoteManager.java @@ -0,0 +1,32 @@ +package cc.fascinated.vote; + +import cc.fascinated.account.Account; +import cc.fascinated.command.CommandManager; +import cc.fascinated.config.Lang; +import cc.fascinated.playercolor.PlayerColorProfile; +import cc.fascinated.utils.Manager; +import cc.fascinated.utils.MessageUtils; +import cc.fascinated.vote.command.VoteStatsCommand; +import com.vexsoftware.votifier.model.VotifierEvent; + +public class VoteManager extends Manager { + + public VoteManager() { + CommandManager.registerCommand(new VoteStatsCommand()); + } + + @Override + public void onVote(Account account, VotifierEvent event) { + VoteProfile voteProfile = account.getVoteProfile(); + PlayerColorProfile playerColorProfile = account.getPlayerColorProfile(); + voteProfile.addVote(); // Add the vote to the player's profile + + MessageUtils.broadcast(Lang.VOTE_BROADCAST.getAsString() + .replace("%player%", account.getPlayer().getName()) + .replace("player-color", playerColorProfile.getColor().toString()) + ); + account.sendMessage(Lang.VOTE_VOTED.getAsString() + .replace("%votes%", voteProfile.getTotalVotes() + "") + ); + } +} diff --git a/src/main/java/cc/fascinated/vote/VoteProfile.java b/src/main/java/cc/fascinated/vote/VoteProfile.java new file mode 100644 index 0000000..b2e8bd9 --- /dev/null +++ b/src/main/java/cc/fascinated/vote/VoteProfile.java @@ -0,0 +1,43 @@ +package cc.fascinated.vote; + +import cc.fascinated.account.Account; +import cc.fascinated.account.Profile; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import org.bukkit.configuration.ConfigurationSection; + +@Getter @EqualsAndHashCode(callSuper = false) +public class VoteProfile extends Profile { + + private int totalVotes; + private int voteTokens; + + public VoteProfile(Account account, ConfigurationSection section) { + super(account, section); + + if (section == null) { + this.totalVotes = 0; + this.voteTokens = 0; + } else { + this.totalVotes = section.getInt("totalVotes"); + this.voteTokens = section.getInt("voteTokens"); + } + } + + /** + * Adds a vote to the player. + *

+ * This gets called when a player votes for the server. + *

+ */ + public void addVote() { + this.totalVotes++; + this.voteTokens++; + } + + @Override + public void save(ConfigurationSection section) { + section.set("totalVotes", this.totalVotes); + section.set("voteTokens", this.voteTokens); + } +} diff --git a/src/main/java/cc/fascinated/vote/command/VoteStatsCommand.java b/src/main/java/cc/fascinated/vote/command/VoteStatsCommand.java new file mode 100644 index 0000000..06a7c67 --- /dev/null +++ b/src/main/java/cc/fascinated/vote/command/VoteStatsCommand.java @@ -0,0 +1,22 @@ +package cc.fascinated.vote.command; + +import cc.fascinated.account.Account; +import cc.fascinated.command.Command; +import cc.fascinated.config.Lang; + +public class VoteStatsCommand extends Command { + + public VoteStatsCommand() { + super("votestats"); + } + + @Override + public void execute(Account account, String[] args) { + for (String line : Lang.VOTE_STATS_COMMAND.getAsStringList()) { + account.sendMessage(line + .replace("%total-votes%", account.getVoteProfile().getTotalVotes() + "") + .replace("%vote-tokens%", account.getVoteProfile().getVoteTokens() + "") + ); + } + } +} diff --git a/src/main/resources/lang.yml b/src/main/resources/lang.yml index 8034015..3c8a5d2 100644 --- a/src/main/resources/lang.yml +++ b/src/main/resources/lang.yml @@ -17,6 +17,14 @@ command-spy: render-distance-message: "Your render distance is now set to %distance%, this is because you are opped." +vote: + voted: "Thank you for voting! You have received 1x Vote Token. You have voted %votes% times." + broadcast: "%player% has voted for the server! Do /vote to get rewards!" + +staff-chat: + usage: "Usage: /staffchat " + format: "[SC] %player% » %message%" + help-command: - "Commands:" - "/kill - Kills you" @@ -49,4 +57,8 @@ vote-command: - "https://best-minecraft-servers.co/server-aetheria.16373/vote" save-accounts-command: saving: "Saving accounts..." - saved: "Accounts saved!" \ No newline at end of file + saved: "Accounts saved!" +vote-stats-command: + - "Your vote statistics:" + - " Total Votes: %total-votes%" + - " Vote Tokens: %vote-tokens%" \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 5485871..ac43ac3 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -33,4 +33,12 @@ commands: usage: "/saveaccounts" commandspy: description: "Toggles command spy" - usage: "/commandspy" \ No newline at end of file + usage: "/commandspy" + votestats: + description: "Shows your vote stats" + usage: "/votestats" + staffchat: + description: "Toggles staff chat" + usage: "/staffchat " + aliases: + - sc \ No newline at end of file