├── .github
├── FUNDING.yml
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ ├── feature_request.md
│ └── question-concerns.md
├── dependabot.yml
└── workflows
│ ├── publish-javadoc.yml
│ └── stale.yml
├── LICENSE.md
├── README.md
└── VotingPlugin
├── .gitignore
├── .project
├── pom.xml
└── src
├── main
├── java
│ └── com
│ │ └── bencodez
│ │ └── votingplugin
│ │ ├── BungeeHandler.java
│ │ ├── VotingPluginHooks.java
│ │ ├── VotingPluginMain.java
│ │ ├── VotingPluginMetrics.java
│ │ ├── broadcast
│ │ └── BroadcastHandler.java
│ │ ├── commands
│ │ ├── CommandLoader.java
│ │ ├── executers
│ │ │ ├── CommandAdminVote.java
│ │ │ ├── CommandAliases.java
│ │ │ └── CommandVote.java
│ │ ├── gui
│ │ │ ├── AdminGUI.java
│ │ │ ├── admin
│ │ │ │ ├── AdminVoteConfirmation.java
│ │ │ │ ├── AdminVoteHelp.java
│ │ │ │ ├── AdminVotePerms.java
│ │ │ │ ├── AdminVotePlaceholders.java
│ │ │ │ ├── AdminVotePlaceholdersPlayer.java
│ │ │ │ ├── AdminVoteTopPoints.java
│ │ │ │ ├── AdminVoteVoteParty.java
│ │ │ │ ├── AdminVoteVotePlayer.java
│ │ │ │ ├── cumulative
│ │ │ │ │ ├── AdminVoteCumulative.java
│ │ │ │ │ └── AdminVoteCumulativeRemove.java
│ │ │ │ ├── milestones
│ │ │ │ │ ├── AdminVoteMilestoneRemove.java
│ │ │ │ │ └── AdminVoteMilestones.java
│ │ │ │ └── voteshop
│ │ │ │ │ ├── AdminVoteVoteShop.java
│ │ │ │ │ ├── AdminVoteVoteShopItem.java
│ │ │ │ │ ├── AdminVoteVoteShopItemRemove.java
│ │ │ │ │ └── AdminVoteVoteShopItems.java
│ │ │ └── player
│ │ │ │ ├── VoteBest.java
│ │ │ │ ├── VoteGUI.java
│ │ │ │ ├── VoteHelp.java
│ │ │ │ ├── VoteLast.java
│ │ │ │ ├── VoteNext.java
│ │ │ │ ├── VoteShop.java
│ │ │ │ ├── VoteShopConfirm.java
│ │ │ │ ├── VoteStreak.java
│ │ │ │ ├── VoteToday.java
│ │ │ │ ├── VoteTopVoter.java
│ │ │ │ ├── VoteTopVoterLastMonth.java
│ │ │ │ ├── VoteTopVoterPreviousMonths.java
│ │ │ │ ├── VoteTotal.java
│ │ │ │ ├── VoteURL.java
│ │ │ │ └── VoteURLVoteSite.java
│ │ └── tabcompleter
│ │ │ ├── AdminVoteTabCompleter.java
│ │ │ ├── AliasesTabCompleter.java
│ │ │ └── VoteTabCompleter.java
│ │ ├── config
│ │ ├── BungeeSettings.java
│ │ ├── Config.java
│ │ ├── ConfigVoteSites.java
│ │ ├── GUI.java
│ │ ├── ShopFile.java
│ │ └── SpecialRewardsConfig.java
│ │ ├── cooldown
│ │ └── CoolDownCheck.java
│ │ ├── data
│ │ └── ServerData.java
│ │ ├── events
│ │ ├── PlayerPostVoteEvent.java
│ │ ├── PlayerReceivePointsEvent.java
│ │ ├── PlayerSpecialRewardEvent.java
│ │ ├── PlayerVoteCoolDownEndEvent.java
│ │ ├── PlayerVoteEvent.java
│ │ ├── PlayerVoteSiteCoolDownEndEvent.java
│ │ ├── SpecialRewardType.java
│ │ └── VotePartyEvent.java
│ │ ├── listeners
│ │ ├── BlockBreak.java
│ │ ├── BungeeVotifierEvent.java
│ │ ├── PlayerInteract.java
│ │ ├── PlayerJoinEvent.java
│ │ ├── PlayerVoteListener.java
│ │ ├── SignChange.java
│ │ ├── VotiferEvent.java
│ │ └── VotingPluginUpdateEvent.java
│ │ ├── objects
│ │ └── VoteSite.java
│ │ ├── placeholders
│ │ ├── MVdWPlaceholders.java
│ │ ├── PlaceHolders.java
│ │ ├── PlaceholderCacheLevel.java
│ │ └── VotingPluginExpansion.java
│ │ ├── proxy
│ │ ├── BungeeMessageData.java
│ │ ├── BungeeMethod.java
│ │ ├── BungeeVersion.java
│ │ ├── OfflineBungeeVote.java
│ │ ├── ProxyMysqlUserTable.java
│ │ ├── VotingPluginProxy.java
│ │ ├── VotingPluginProxyCommand.java
│ │ ├── VotingPluginProxyConfig.java
│ │ ├── bungee
│ │ │ ├── BStatsMetricsBungee.java
│ │ │ ├── Config.java
│ │ │ ├── NonVotedPlayersCache.java
│ │ │ ├── VoteCache.java
│ │ │ ├── VoteEventBungee.java
│ │ │ ├── VotingPluginBungee.java
│ │ │ └── VotingPluginBungeeCommand.java
│ │ ├── multiproxy
│ │ │ ├── MultiProxyHandler.java
│ │ │ ├── MultiProxyMethod.java
│ │ │ ├── MultiProxyServerSocketConfiguration.java
│ │ │ ├── MultiProxyServerSocketConfigurationBungee.java
│ │ │ └── MultiProxyServerSocketConfigurationVelocity.java
│ │ └── velocity
│ │ │ ├── Config.java
│ │ │ ├── NonVotedPlayersCache.java
│ │ │ ├── VoteCache.java
│ │ │ ├── VoteEventVelocity.java
│ │ │ ├── VotingPluginChannelIdentifier.java
│ │ │ ├── VotingPluginVelocity.java
│ │ │ └── VotingPluginVelocityCommand.java
│ │ ├── servicesites
│ │ └── ServiceSiteHandler.java
│ │ ├── signs
│ │ ├── SignHandler.java
│ │ └── Signs.java
│ │ ├── specialrewards
│ │ └── SpecialRewards.java
│ │ ├── test
│ │ └── VoteTester.java
│ │ ├── timequeue
│ │ ├── TimeQueueHandler.java
│ │ └── VoteTimeQueue.java
│ │ ├── topvoter
│ │ ├── TopVoter.java
│ │ ├── TopVoterHandler.java
│ │ └── TopVoterPlayer.java
│ │ ├── updater
│ │ └── CheckUpdate.java
│ │ ├── user
│ │ ├── UserManager.java
│ │ └── VotingPluginUser.java
│ │ ├── voteparty
│ │ └── VoteParty.java
│ │ └── votereminding
│ │ └── VoteReminding.java
└── resources
│ ├── BungeeSettings.yml
│ ├── Config.yml
│ ├── GUI.yml
│ ├── Shop.yml
│ ├── SpecialRewards.yml
│ ├── VoteSites.yml
│ ├── bungee.yml
│ ├── bungeeconfig.yml
│ ├── plugin.yml
│ └── votingpluginversion.yml
└── test
└── java
└── com
└── bencodez
└── votingplugin
└── tests
├── HttpURLConnectionMock.java
├── VotePartyTest.java
├── VoteSiteTest.java
├── VotingPluginProxyTest.java
├── VotingPluginProxyTestImpl.java
└── VotingPluginProxyVoteCacheTest.java
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: BenCodez # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | #patreon: # Replace with a single Patreon username
5 | #open_collective: # Replace with a single Open Collective username
6 | #ko_fi: # Replace with a single Ko-fi username
7 | #tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | #community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | #liberapay: # Replace with a single Liberapay username
10 | #issuehunt: # Replace with a single IssueHunt username
11 | #lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
12 | #polar: # Replace with a single Polar username
13 | #buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
14 | custom: ["https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YQBX25RTXJ5DG"]
15 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Bug report for VotingPlugin
4 | title: ''
5 | labels: Possible Bug
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Versions**
11 | Plugin version and spigot version.
12 |
13 | **Describe the bug**
14 | A clear and concise description of what the bug is.
15 |
16 | **To Reproduce**
17 | Steps to reproduce the behavior:
18 | 1. Go to '...'
19 | 2. Click on '....'
20 | 3. Scroll down to '....'
21 | 4. See error
22 |
23 | **Expected behavior**
24 | A clear and concise description of what you expected to happen.
25 |
26 | **Screenshots/Configs**
27 | If applicable, add screenshots to help explain your problem and/or configs relating to the issue.
28 |
29 | **Additional context**
30 | Add any other context about the problem here.
31 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea
4 | title: ''
5 | labels: Possible Feature
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/question-concerns.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Question/Concerns
3 | about: Ask about a question or a concern about the plugin
4 | title: ''
5 | labels: Question/Concern
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Versions**
11 | Plugin version and spigot version
12 |
13 | **Relevant information**
14 | Configs that relate to the issue in a pastebin.
15 |
16 | **Context**
17 | Context about the question/concern
18 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | # To get started with Dependabot version updates, you'll need to specify which
2 | # package ecosystems to update and where the package manifests are located.
3 | # Please see the documentation for all configuration options:
4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5 |
6 | version: 2
7 | updates:
8 | - package-ecosystem: "maven" # See documentation for possible values
9 | directory: "/VotingPlugin/" # Location of package manifests
10 | schedule:
11 | interval: "weekly"
12 |
--------------------------------------------------------------------------------
/.github/workflows/publish-javadoc.yml:
--------------------------------------------------------------------------------
1 | name: Deploy Javadoc
2 |
3 | on:
4 | release:
5 | types: [published]
6 | branches:
7 | - master
8 | - main
9 |
10 | jobs:
11 | publish:
12 | runs-on: ubuntu-latest
13 | steps:
14 | - name: Deploy JavaDoc 🚀
15 | uses: MathieuSoysal/Javadoc-publisher.yml@main
16 | with:
17 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18 | javadoc-branch: gh-pages
19 | java-version: 17
20 | target-folder: ''
21 | project: maven # or gradle
22 | # subdirectories: moduleA moduleB #for subdirectories support, needs to be run with custom command
23 | custom-command: mvn -f VotingPlugin/pom.xml deploy -P javadoc javadoc:aggregate
24 | javadoc-source-folder: 'VotingPlugin/target/apidocs'
25 |
--------------------------------------------------------------------------------
/.github/workflows/stale.yml:
--------------------------------------------------------------------------------
1 | # This workflow warns and then closes issues and PRs that have had no activity for a specified amount of time.
2 | #
3 | # You can adjust the behavior by modifying this file.
4 | # For more information, see:
5 | # https://github.com/actions/stale
6 | name: Mark stale issues and pull requests
7 |
8 | on:
9 | schedule:
10 | - cron: '19 16 * * *'
11 |
12 | jobs:
13 | stale:
14 |
15 | runs-on: ubuntu-latest
16 | permissions:
17 | issues: write
18 | pull-requests: write
19 |
20 | steps:
21 | - uses: actions/stale@v5
22 | with:
23 | repo-token: ${{ secrets.GITHUB_TOKEN }}
24 | stale-issue-message: 'Stale issue message'
25 | stale-pr-message: 'Stale pull request message'
26 | stale-issue-label: 'no-issue-activity'
27 | stale-pr-label: 'no-pr-activity'
28 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # VotingPlugin
2 | Plugin on SpigotMC
3 | https://www.spigotmc.org/resources/votingplugin.15358/
4 |
5 | ### Maven:
6 |
7 |
8 | BenCodez Repo
9 | https://nexus.bencodez.com/repository/maven-public/
10 |
11 |
12 |
13 | com.bencodez
14 | votingplugin
15 | LATEST
16 | provided
17 |
18 |
19 | Versions:
20 | LATEST - latest stable release
21 |
22 |
23 |
--------------------------------------------------------------------------------
/VotingPlugin/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 | /target/
3 | /doc/
4 | /.idea/
5 | /*.iml
6 | /.settings/
7 | /.classpath
8 | /.factorypath
9 | /.apt_generated_tests/
10 |
--------------------------------------------------------------------------------
/VotingPlugin/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | VotingPlugin
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.m2e.core.maven2Builder
15 |
16 |
17 |
18 |
19 | org.eclipse.wst.validation.validationbuilder
20 |
21 |
22 |
23 |
24 | org.eclipse.m2e.core.maven2Builder
25 |
26 |
27 |
28 |
29 |
30 | org.eclipse.m2e.core.maven2Nature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/VotingPluginHooks.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin;
2 |
3 | import org.bukkit.entity.Player;
4 |
5 | import com.bencodez.advancedcore.api.rewards.injected.RewardInject;
6 | import com.bencodez.advancedcore.api.rewards.injectedrequirement.RequirementInject;
7 | import com.bencodez.votingplugin.user.UserManager;
8 | import com.bencodez.votingplugin.user.VotingPluginUser;
9 |
10 | public class VotingPluginHooks {
11 | private static VotingPluginHooks instance = new VotingPluginHooks();
12 |
13 | public static VotingPluginHooks getInstance() {
14 | return instance;
15 | }
16 |
17 | public void addCustomRequirement(RequirementInject inject) {
18 | getMainClass().getRewardHandler().addInjectedRequirements(inject);
19 | }
20 |
21 | public void addCustomReward(RewardInject inject) {
22 | getMainClass().getRewardHandler().addInjectedReward(inject);
23 | }
24 |
25 | public void backgroundUpdate(Player player) {
26 | VotingPluginUser user = getUserManager().getVotingPluginUser(player);
27 | user.offVote();
28 | user.checkOfflineRewards();
29 | }
30 |
31 | public VotingPluginMain getMainClass() {
32 | return VotingPluginMain.plugin;
33 | }
34 |
35 | public UserManager getUserManager() {
36 | return getMainClass().getVotingPluginUserManager();
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/broadcast/BroadcastHandler.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.broadcast;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 | import java.util.concurrent.ConcurrentLinkedQueue;
6 | import java.util.concurrent.Executors;
7 | import java.util.concurrent.ScheduledExecutorService;
8 | import java.util.concurrent.TimeUnit;
9 |
10 | import org.bukkit.Bukkit;
11 | import org.bukkit.entity.Player;
12 |
13 | import com.bencodez.advancedcore.api.messages.PlaceholderUtils;
14 | import com.bencodez.advancedcore.api.misc.MiscUtils;
15 | import com.bencodez.simpleapi.messages.MessageAPI;
16 | import com.bencodez.votingplugin.VotingPluginMain;
17 |
18 | public class BroadcastHandler {
19 | private VotingPluginMain plugin;
20 | private ScheduledExecutorService timer;
21 | ConcurrentLinkedQueue votedPlayers = new ConcurrentLinkedQueue<>();
22 |
23 | public BroadcastHandler(VotingPluginMain plugin, int delay) {
24 | this.plugin = plugin;
25 | schedule(delay);
26 | }
27 |
28 | public void check() {
29 | int size = votedPlayers.size();
30 | if (size > 0) {
31 | for (int i = 0; i < size; i++) {
32 | votedPlayers.poll();
33 | }
34 | String bc = MessageAPI.colorize(plugin.getConfigFile().getFormatAlternateBroadcastBroadcast());
35 | String playersText = "";
36 | while (!votedPlayers.isEmpty()) {
37 | playersText += votedPlayers.remove();
38 | if (!votedPlayers.isEmpty()) {
39 | playersText += ", ";
40 | }
41 | }
42 | HashMap placeholders = new HashMap<>();
43 | placeholders.put("numberofplayers", "" + size);
44 | placeholders.put("players", playersText);
45 | bc = PlaceholderUtils.replacePlaceHolder(bc, placeholders);
46 | ArrayList players = new ArrayList<>();
47 | for (Player p : Bukkit.getOnlinePlayers()) {
48 | if (!plugin.getVotingPluginUserManager().getVotingPluginUser(p).getDisableBroadcast()) {
49 | players.add(p);
50 | }
51 | }
52 |
53 | MiscUtils.getInstance().broadcast(bc, players);
54 | }
55 | }
56 |
57 | public void onVote(String player) {
58 | votedPlayers.add(player);
59 | }
60 |
61 | public void schedule(int delay) {
62 | if (timer != null) {
63 | timer.shutdownNow();
64 | timer = Executors.newScheduledThreadPool(1);
65 | } else {
66 | timer = Executors.newScheduledThreadPool(1);
67 | }
68 | timer.scheduleWithFixedDelay(new Runnable() {
69 |
70 | @Override
71 | public void run() {
72 | check();
73 | }
74 | }, 60, 60 * delay, TimeUnit.SECONDS);
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/executers/CommandAdminVote.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.executers;
2 |
3 | import org.bukkit.command.Command;
4 | import org.bukkit.command.CommandExecutor;
5 | import org.bukkit.command.CommandSender;
6 |
7 | import com.bencodez.advancedcore.api.command.CommandHandler;
8 | import com.bencodez.simpleapi.messages.MessageAPI;
9 | import com.bencodez.votingplugin.VotingPluginMain;
10 |
11 | // TODO: Auto-generated Javadoc
12 | /**
13 | * The Class CommandAdminVote.
14 | */
15 | public class CommandAdminVote implements CommandExecutor {
16 |
17 | private VotingPluginMain plugin;
18 |
19 | public CommandAdminVote(VotingPluginMain plugin) {
20 | this.plugin = plugin;
21 | }
22 |
23 | /*
24 | * (non-Javadoc)
25 | *
26 | * @see org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.
27 | * CommandSender , org.bukkit.command.Command, java.lang.String,
28 | * java.lang.String[])
29 | */
30 | @Override
31 | public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
32 | for (CommandHandler commandHandler : plugin.getAdminVoteCommand()) {
33 | if (commandHandler.runCommand(sender, args)) {
34 | return true;
35 | }
36 | }
37 |
38 | // invalid command
39 | sender.sendMessage(MessageAPI.colorize(plugin.getConfigFile().getFormatInvalidCommandAdminVote()));
40 |
41 | return true;
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/executers/CommandAliases.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.executers;
2 |
3 | import java.util.ArrayList;
4 |
5 | import org.bukkit.command.Command;
6 | import org.bukkit.command.CommandExecutor;
7 | import org.bukkit.command.CommandSender;
8 |
9 | import com.bencodez.advancedcore.api.command.CommandHandler;
10 | import com.bencodez.simpleapi.array.ArrayUtils;
11 | import com.bencodez.simpleapi.messages.MessageAPI;
12 | import com.bencodez.votingplugin.VotingPluginMain;
13 |
14 | // TODO: Auto-generated Javadoc
15 | /**
16 | * The Class CommandAliases.
17 | */
18 | public class CommandAliases implements CommandExecutor {
19 |
20 | private boolean adminCommand;
21 |
22 | /** The cmd handle. */
23 | private CommandHandler cmdHandle;
24 |
25 | /** The plugin. */
26 | private VotingPluginMain plugin = VotingPluginMain.plugin;
27 |
28 | public CommandAliases(CommandHandler cmdHandle, boolean adminCommand) {
29 | this.cmdHandle = cmdHandle;
30 | this.adminCommand = adminCommand;
31 | }
32 |
33 | /*
34 | * (non-Javadoc)
35 | *
36 | * @see org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.
37 | * CommandSender , org.bukkit.command.Command, java.lang.String,
38 | * java.lang.String[])
39 | */
40 | @Override
41 | public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
42 |
43 | ArrayList argsNew = new ArrayList<>();
44 | argsNew.add(cmdHandle.getArgs()[0]);
45 | for (String arg : args) {
46 | argsNew.add(arg);
47 | }
48 | plugin.debug("Attempting cmd...");
49 | plugin.debug("Inputed args: " + ArrayUtils.makeStringList(argsNew));
50 |
51 | ArrayList handles = new ArrayList<>();
52 | if (adminCommand) {
53 | handles.addAll(plugin.getAdminVoteCommand());
54 | } else {
55 | handles.addAll(plugin.getVoteCommand());
56 | }
57 |
58 | for (CommandHandler cmdHandle : handles) {
59 | if (cmdHandle.getArgs().length > args.length) {
60 | for (String arg : cmdHandle.getArgs()[0].split("&")) {
61 | if (cmd.getName().equalsIgnoreCase("vote" + arg)
62 | || cmd.getName().equalsIgnoreCase("adminvote" + arg)) {
63 | argsNew.set(0, arg);
64 |
65 | boolean argsMatch = true;
66 | for (int i = 0; i < argsNew.size(); i++) {
67 | if (i < cmdHandle.getArgs().length) {
68 | if (!cmdHandle.argsMatch(argsNew.get(i), i)) {
69 | argsMatch = false;
70 | }
71 | }
72 |
73 | }
74 |
75 | if (argsMatch) {
76 | if (cmdHandle.runCommand(sender, ArrayUtils.convert(argsNew))) {
77 | plugin.debug("cmd found, ran cmd");
78 | return true;
79 | }
80 | }
81 | }
82 | }
83 | }
84 | }
85 |
86 | /*
87 | * for (String arg : cmdHandle.getArgs()[0].split("&")) { argsNew.set(0, arg);
88 | * if (cmdHandle.runCommand(sender, Utils.getInstance().convertArray(argsNew)))
89 | * { plugin.debug( "cmd found, ran cmd"); return true; } }
90 | */
91 |
92 | // invalid command
93 | if (adminCommand) {
94 | sender.sendMessage(MessageAPI.colorize(plugin.getConfigFile().getFormatInvalidCommandAdminVote()));
95 | } else {
96 | sender.sendMessage(MessageAPI.colorize(plugin.getConfigFile().getFormatInvalidCommandVote()));
97 | }
98 | return true;
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/executers/CommandVote.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.executers;
2 |
3 | import org.bukkit.command.Command;
4 | import org.bukkit.command.CommandExecutor;
5 | import org.bukkit.command.CommandSender;
6 |
7 | import com.bencodez.advancedcore.api.command.CommandHandler;
8 | import com.bencodez.simpleapi.messages.MessageAPI;
9 | import com.bencodez.votingplugin.VotingPluginMain;
10 |
11 | // TODO: Auto-generated Javadoc
12 | /**
13 | * The Class CommandVote.
14 | */
15 | public class CommandVote implements CommandExecutor {
16 |
17 | /** The instance. */
18 | private static CommandVote instance = new CommandVote();
19 |
20 | /** The plugin. */
21 | private static VotingPluginMain plugin;
22 |
23 | /**
24 | * Gets the single instance of CommandVote.
25 | *
26 | * @return single instance of CommandVote
27 | */
28 | public static CommandVote getInstance() {
29 | return instance;
30 | }
31 |
32 | /**
33 | * Instantiates a new command vote.
34 | */
35 | private CommandVote() {
36 | }
37 |
38 | /**
39 | * Instantiates a new command vote.
40 | *
41 | * @param plugin the plugin
42 | */
43 | public CommandVote(VotingPluginMain plugin) {
44 | CommandVote.plugin = plugin;
45 | }
46 |
47 | /*
48 | * (non-Javadoc)
49 | *
50 | * @see org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.
51 | * CommandSender , org.bukkit.command.Command, java.lang.String,
52 | * java.lang.String[])
53 | */
54 | @Override
55 | public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
56 |
57 | for (CommandHandler commandHandler : plugin.getVoteCommand()) {
58 | if (commandHandler.runCommand(sender, args)) {
59 | return true;
60 | }
61 | }
62 |
63 | // invalid command
64 | sender.sendMessage(MessageAPI.colorize(plugin.getConfigFile().getFormatInvalidCommandVote()));
65 | return true;
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/admin/AdminVoteConfirmation.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.gui.admin;
2 |
3 | import java.util.ArrayList;
4 |
5 | import org.bukkit.Material;
6 | import org.bukkit.command.CommandSender;
7 | import org.bukkit.entity.Player;
8 |
9 | import com.bencodez.advancedcore.api.gui.GUIHandler;
10 | import com.bencodez.advancedcore.api.gui.GUIMethod;
11 | import com.bencodez.advancedcore.api.inventory.BInventory;
12 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
13 | import com.bencodez.advancedcore.api.inventory.BInventoryButton;
14 | import com.bencodez.advancedcore.api.item.ItemBuilder;
15 | import com.bencodez.votingplugin.VotingPluginMain;
16 |
17 | public abstract class AdminVoteConfirmation extends GUIHandler {
18 |
19 | @SuppressWarnings("unused")
20 | private VotingPluginMain plugin;
21 | private String title;
22 |
23 | public AdminVoteConfirmation(VotingPluginMain plugin, CommandSender player, String title) {
24 | super(plugin, player);
25 | this.plugin = plugin;
26 | this.title = title;
27 | }
28 |
29 | @Override
30 | public ArrayList getChat(CommandSender sender) {
31 | return null;
32 | }
33 |
34 | @Override
35 | public void onBook(Player player) {
36 | }
37 |
38 | @Override
39 | public void onChat(CommandSender sender) {
40 |
41 | }
42 |
43 | @Override
44 | public void onChest(Player player) {
45 | BInventory inv = new BInventory(title);
46 | inv.addButton(new BInventoryButton(new ItemBuilder(Material.EMERALD_BLOCK).setName("&aConfirm")) {
47 |
48 | @Override
49 | public void onClick(ClickEvent clickEvent) {
50 | onConfirm(clickEvent.getPlayer());
51 | }
52 | });
53 | inv.addButton(new BInventoryButton(new ItemBuilder(Material.REDSTONE_BLOCK).setName("&aCancel")) {
54 |
55 | @Override
56 | public void onClick(ClickEvent clickEvent) {
57 | onDeny(clickEvent.getPlayer());
58 | }
59 | });
60 | inv.openInventory(player);
61 | }
62 |
63 | public abstract void onConfirm(Player p);
64 |
65 | public abstract void onDeny(Player p);
66 |
67 | @Override
68 | public void open() {
69 | open(GUIMethod.CHEST);
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/admin/AdminVoteHelp.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.gui.admin;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collections;
5 | import java.util.HashMap;
6 |
7 | import org.bukkit.command.CommandSender;
8 | import org.bukkit.entity.Player;
9 |
10 | import com.bencodez.advancedcore.api.command.CommandHandler;
11 | import com.bencodez.advancedcore.api.gui.GUIHandler;
12 | import com.bencodez.advancedcore.api.gui.GUIMethod;
13 | import com.bencodez.simpleapi.messages.MessageAPI;
14 | import com.bencodez.votingplugin.VotingPluginMain;
15 |
16 | import net.md_5.bungee.api.chat.TextComponent;
17 |
18 | public class AdminVoteHelp extends GUIHandler {
19 |
20 | private int page;
21 | private VotingPluginMain plugin;
22 |
23 | public AdminVoteHelp(VotingPluginMain plugin, CommandSender player, int page) {
24 | super(plugin, player);
25 | this.plugin = plugin;
26 | this.page = page;
27 | }
28 |
29 | /**
30 | * Admin help.
31 | *
32 | * @param sender the sender
33 | * @param page the page
34 | * @return the array list
35 | */
36 | public ArrayList adminHelp(CommandSender sender, int page) {
37 | int pagesize = plugin.getConfigFile().getFormatPageSize();
38 | ArrayList msg = new ArrayList<>();
39 | ArrayList text = adminHelpText(sender);
40 |
41 | int maxPage = text.size() / pagesize;
42 | if ((text.size() % pagesize) != 0) {
43 | maxPage++;
44 | }
45 |
46 | msg.add(MessageAPI.stringToComp("&6&lVotingPlugin Admin Help " + (page) + "/" + maxPage));
47 | msg.add(MessageAPI.stringToComp("&6&l() = Needed"));
48 | msg.add(MessageAPI.stringToComp("&6&lAliases: adminvote, av"));
49 |
50 | for (int i = pagesize * (page - 1); (i < text.size()) && (i < ((page) * pagesize)); i++) {
51 | msg.add(text.get(i));
52 | }
53 |
54 | return msg;
55 | }
56 |
57 | /**
58 | * Admin help text.
59 | *
60 | * @param sender the sender
61 | * @return the array list
62 | */
63 | public ArrayList adminHelpText(CommandSender sender) {
64 | ArrayList msg = new ArrayList<>();
65 | HashMap unsorted = new HashMap<>();
66 |
67 | boolean requirePerms = plugin.getConfigFile().isFormatCommandsVoteHelpRequirePermission();
68 |
69 | for (CommandHandler cmdHandle : plugin.getAdminVoteCommand()) {
70 | if (!requirePerms || cmdHandle.hasPerm(sender)) {
71 | unsorted.put(cmdHandle.getHelpLineCommand("/adminvote"), cmdHandle.getHelpLine("/adminvote"));
72 | }
73 | }
74 | ArrayList unsortedList = new ArrayList<>();
75 | unsortedList.addAll(unsorted.keySet());
76 | Collections.sort(unsortedList, String.CASE_INSENSITIVE_ORDER);
77 | for (String cmd : unsortedList) {
78 | msg.add(unsorted.get(cmd));
79 | }
80 |
81 | return msg;
82 | }
83 |
84 | @Override
85 | public ArrayList getChat(CommandSender sender) {
86 | return null;
87 | }
88 |
89 | @Override
90 | public void onBook(Player player) {
91 | }
92 |
93 | @Override
94 | public void onChat(CommandSender sender) {
95 | sendMessageJson(adminHelp(sender, page));
96 | }
97 |
98 | @Override
99 | public void onChest(Player player) {
100 |
101 | }
102 |
103 | @Override
104 | public void open() {
105 | open(GUIMethod.CHAT);
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/admin/AdminVotePlaceholders.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.gui.admin;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Arrays;
5 |
6 | import org.bukkit.ChatColor;
7 | import org.bukkit.command.CommandSender;
8 | import org.bukkit.entity.Player;
9 |
10 | import com.bencodez.advancedcore.api.bookgui.BookWrapper;
11 | import com.bencodez.advancedcore.api.bookgui.Layout;
12 | import com.bencodez.advancedcore.api.gui.GUIHandler;
13 | import com.bencodez.advancedcore.api.gui.GUIMethod;
14 | import com.bencodez.advancedcore.api.placeholder.NonPlayerPlaceHolder;
15 | import com.bencodez.advancedcore.api.placeholder.PlaceHolder;
16 | import com.bencodez.votingplugin.VotingPluginMain;
17 | import com.bencodez.votingplugin.user.VotingPluginUser;
18 |
19 | import xyz.upperlevel.spigot.book.BookUtil;
20 |
21 | public class AdminVotePlaceholders extends GUIHandler {
22 |
23 | private VotingPluginMain plugin;
24 |
25 | public AdminVotePlaceholders(VotingPluginMain plugin, CommandSender player) {
26 | super(plugin, player);
27 | this.plugin = plugin;
28 | }
29 |
30 | @Override
31 | public ArrayList getChat(CommandSender sender) {
32 | return null;
33 | }
34 |
35 | @Override
36 | public void onBook(Player player) {
37 | BookWrapper book = new BookWrapper("Placeholders");
38 |
39 | for (PlaceHolder placeholder : plugin.getPlaceholders().getPlaceholders()) {
40 | String msg = "";
41 | String identifier = placeholder.getIdentifier().toLowerCase();
42 | if (identifier.endsWith("_")) {
43 | identifier += "#";
44 | }
45 | if (placeholder.hasDescription()) {
46 | msg = "votingplugin_" + identifier + " - " + placeholder.getDescription();
47 | } else {
48 | msg = "votingplugin_" + identifier + "";
49 | }
50 |
51 | Layout layout = new Layout(new ArrayList<>(Arrays.asList("[Json]")));
52 | layout.replaceTextComponent("[Json]", BookUtil.TextBuilder.of(identifier).color(ChatColor.AQUA)
53 | .onHover(BookUtil.HoverAction.showText(msg)).build());
54 | book.addLayout(layout);
55 | }
56 |
57 | for (NonPlayerPlaceHolder placeholder : plugin.getPlaceholders().getNonPlayerPlaceholders()) {
58 | String msg = "";
59 | String identifier = placeholder.getIdentifier().toLowerCase();
60 | if (identifier.endsWith("_")) {
61 | identifier += "#";
62 | }
63 | if (placeholder.hasDescription()) {
64 | msg = "votingplugin_" + identifier + " - " + placeholder.getDescription();
65 | } else {
66 | msg = "votingplugin_" + identifier + "";
67 | }
68 |
69 | Layout layout = new Layout(new ArrayList<>(Arrays.asList("[Json]")));
70 | layout.replaceTextComponent("[Json]", BookUtil.TextBuilder.of(identifier).color(ChatColor.AQUA)
71 | .onHover(BookUtil.HoverAction.showText(msg)).build());
72 | book.addLayout(layout);
73 |
74 | }
75 |
76 | book.open(player);
77 |
78 | }
79 |
80 | @Override
81 | public void onChat(CommandSender sender) {
82 | ArrayList msg = new ArrayList<>();
83 | msg.add("&cPlaceholders:");
84 | for (PlaceHolder placeholder : plugin.getPlaceholders().getPlaceholders()) {
85 | String identifier = placeholder.getIdentifier().toLowerCase();
86 | if (identifier.endsWith("_")) {
87 | identifier += "#";
88 | }
89 | if (placeholder.hasDescription()) {
90 | msg.add("votingplugin_" + identifier + " - " + placeholder.getDescription());
91 | } else {
92 | msg.add("votingplugin_" + identifier + "");
93 | }
94 | }
95 |
96 | for (NonPlayerPlaceHolder placeholder : plugin.getPlaceholders().getNonPlayerPlaceholders()) {
97 | String identifier = placeholder.getIdentifier().toLowerCase();
98 | if (identifier.endsWith("_")) {
99 | identifier += "#";
100 | }
101 | if (placeholder.hasDescription()) {
102 | msg.add("votingplugin_" + identifier + " - " + placeholder.getDescription());
103 | } else {
104 | msg.add("votingplugin_" + identifier + "");
105 | }
106 | }
107 |
108 | sendMessage(msg);
109 | }
110 |
111 | @Override
112 | public void onChest(Player player) {
113 |
114 | }
115 |
116 | @Override
117 | public void open() {
118 | open(GUIMethod.CHAT);
119 | }
120 |
121 | }
122 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/admin/AdminVotePlaceholdersPlayer.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.gui.admin;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Arrays;
5 |
6 | import org.bukkit.ChatColor;
7 | import org.bukkit.command.CommandSender;
8 | import org.bukkit.entity.Player;
9 |
10 | import com.bencodez.advancedcore.api.bookgui.BookWrapper;
11 | import com.bencodez.advancedcore.api.bookgui.Layout;
12 | import com.bencodez.advancedcore.api.gui.GUIHandler;
13 | import com.bencodez.advancedcore.api.gui.GUIMethod;
14 | import com.bencodez.advancedcore.api.placeholder.NonPlayerPlaceHolder;
15 | import com.bencodez.advancedcore.api.placeholder.PlaceHolder;
16 | import com.bencodez.votingplugin.VotingPluginMain;
17 | import com.bencodez.votingplugin.user.VotingPluginUser;
18 |
19 | import xyz.upperlevel.spigot.book.BookUtil;
20 |
21 | public class AdminVotePlaceholdersPlayer extends GUIHandler {
22 |
23 | private VotingPluginMain plugin;
24 | private VotingPluginUser user;
25 |
26 | public AdminVotePlaceholdersPlayer(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) {
27 | super(plugin, player);
28 | this.plugin = plugin;
29 | this.user = user;
30 | }
31 |
32 | @Override
33 | public ArrayList getChat(CommandSender sender) {
34 | return null;
35 | }
36 |
37 | @Override
38 | public void onBook(Player player) {
39 | BookWrapper book = new BookWrapper("Placeholders");
40 |
41 | for (PlaceHolder placeholder : plugin.getPlaceholders().getPlaceholders()) {
42 | String identifier = placeholder.getIdentifier().toLowerCase();
43 | if (identifier.endsWith("_")) {
44 | identifier += "1";
45 | }
46 | String value = placeholder.placeholderRequest(user, identifier);
47 | String msg = identifier + " = " + value;
48 | Layout layout = new Layout(new ArrayList<>(Arrays.asList("[Json]")));
49 | layout.replaceTextComponent("[Json]", BookUtil.TextBuilder.of(msg).color(ChatColor.AQUA)
50 | .onHover(BookUtil.HoverAction.showText(value)).build());
51 | book.addLayout(layout);
52 | }
53 |
54 | for (NonPlayerPlaceHolder placeholder : plugin.getPlaceholders().getNonPlayerPlaceholders()) {
55 |
56 | String identifier = placeholder.getIdentifier().toLowerCase();
57 | if (identifier.endsWith("_")) {
58 | identifier += "1";
59 | }
60 | String value = placeholder.placeholderRequest(identifier);
61 | String msg = identifier + " = " + value;
62 |
63 | Layout layout = new Layout(new ArrayList<>(Arrays.asList("[Json]")));
64 | layout.replaceTextComponent("[Json]", BookUtil.TextBuilder.of(msg).color(ChatColor.AQUA)
65 | .onHover(BookUtil.HoverAction.showText(value)).build());
66 | book.addLayout(layout);
67 | }
68 | book.open(player);
69 | }
70 |
71 | @Override
72 | public void onChat(CommandSender sender) {
73 | ArrayList msg = new ArrayList<>();
74 | msg.add("&cPlaceholders:");
75 | VotingPluginUser placeholderUser = user;
76 | if (plugin.getConfigFile().isUsePrimaryAccountForPlaceholders() && user.hasPrimaryAccount()) {
77 | placeholderUser = plugin.getVotingPluginUserManager().getVotingPluginUser(user.getPrimaryAccount());
78 | }
79 | for (PlaceHolder placeholder : plugin.getPlaceholders().getPlaceholders()) {
80 | String identifier = placeholder.getIdentifier().toLowerCase();
81 | if (identifier.endsWith("_")) {
82 | identifier += "1";
83 | }
84 | msg.add("votingplugin_" + identifier + " = " + placeholder.placeholderRequest(placeholderUser, identifier));
85 | }
86 |
87 | for (NonPlayerPlaceHolder placeholder : plugin.getPlaceholders().getNonPlayerPlaceholders()) {
88 | String identifier = placeholder.getIdentifier().toLowerCase();
89 | if (identifier.endsWith("_")) {
90 | identifier += "1";
91 | }
92 |
93 | msg.add("votingplugin_" + identifier + " = " + placeholder.placeholderRequest(identifier));
94 | }
95 | sendMessage(msg);
96 | }
97 |
98 | @Override
99 | public void onChest(Player player) {
100 |
101 | }
102 |
103 | @Override
104 | public void open() {
105 | open(GUIMethod.CHAT);
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/admin/AdminVoteVotePlayer.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.gui.admin;
2 |
3 | import java.util.ArrayList;
4 |
5 | import org.bukkit.command.CommandSender;
6 | import org.bukkit.entity.Player;
7 |
8 | import com.bencodez.advancedcore.api.gui.GUIHandler;
9 | import com.bencodez.advancedcore.api.gui.GUIMethod;
10 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
11 | import com.bencodez.advancedcore.api.inventory.BInventoryButton;
12 | import com.bencodez.advancedcore.api.inventory.editgui.EditGUI;
13 | import com.bencodez.votingplugin.VotingPluginMain;
14 | import com.bencodez.votingplugin.events.PlayerVoteEvent;
15 | import com.bencodez.votingplugin.objects.VoteSite;
16 |
17 | public class AdminVoteVotePlayer extends GUIHandler {
18 |
19 | private String playerName;
20 | private VotingPluginMain plugin;
21 |
22 | public AdminVoteVotePlayer(VotingPluginMain plugin, CommandSender player, String playerName) {
23 | super(plugin, player);
24 | this.plugin = plugin;
25 | this.playerName = playerName;
26 | }
27 |
28 | @Override
29 | public ArrayList getChat(CommandSender sender) {
30 | return null;
31 | }
32 |
33 | @Override
34 | public void onBook(Player player) {
35 | }
36 |
37 | @Override
38 | public void onChat(CommandSender sender) {
39 |
40 | }
41 |
42 | @Override
43 | public void onChest(Player player) {
44 | EditGUI inv = new EditGUI("Trigger vote for " + playerName);
45 | inv.requirePermission("VotingPlugin.Commands.AdminVote.Vote|VotingPlugin.Admin");
46 |
47 | for (VoteSite site : plugin.getVoteSitesEnabled()) {
48 | inv.addButton(new BInventoryButton(site.getItem().setName(site.getKey())) {
49 |
50 | @Override
51 | public void onClick(ClickEvent clickEvent) {
52 | VoteSite site = (VoteSite) getData("site");
53 | PlayerVoteEvent voteEvent = new PlayerVoteEvent(site, playerName, site.getServiceSite(), false);
54 | sendMessage(clickEvent.getPlayer(), "&cTriggering vote...");
55 | if (voteEvent.getVoteSite() != null) {
56 | if (!voteEvent.getVoteSite().isVaidServiceSite()) {
57 | sendMessage(clickEvent.getPlayer(),
58 | "&cPossible issue with service site, has the server gotten the vote from "
59 | + voteEvent.getServiceSite() + "?");
60 | }
61 | }
62 | plugin.getServer().getPluginManager().callEvent(voteEvent);
63 |
64 | if (plugin.isYmlError()) {
65 | sendMessage(clickEvent.getPlayer(),
66 | "&3Detected yml error, please check server log for details");
67 | }
68 | }
69 | }.addData("site", site));
70 | }
71 |
72 | inv.openInventory(player);
73 | }
74 |
75 | @Override
76 | public void open() {
77 | open(GUIMethod.CHEST);
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/admin/cumulative/AdminVoteCumulative.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.gui.admin.cumulative;
2 |
3 | import java.util.ArrayList;
4 |
5 | import org.bukkit.Material;
6 | import org.bukkit.command.CommandSender;
7 | import org.bukkit.entity.Player;
8 |
9 | import com.bencodez.advancedcore.api.gui.GUIHandler;
10 | import com.bencodez.advancedcore.api.gui.GUIMethod;
11 | import com.bencodez.advancedcore.api.inventory.BInventory;
12 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
13 | import com.bencodez.advancedcore.api.inventory.BInventoryButton;
14 | import com.bencodez.advancedcore.api.item.ItemBuilder;
15 | import com.bencodez.advancedcore.api.valuerequest.InputMethod;
16 | import com.bencodez.advancedcore.api.valuerequest.ValueRequest;
17 | import com.bencodez.advancedcore.api.valuerequest.ValueRequestBuilder;
18 | import com.bencodez.advancedcore.api.valuerequest.listeners.NumberListener;
19 | import com.bencodez.advancedcore.command.gui.RewardEditGUI;
20 | import com.bencodez.simpleapi.messages.MessageAPI;
21 | import com.bencodez.votingplugin.VotingPluginMain;
22 |
23 | public class AdminVoteCumulative extends GUIHandler {
24 |
25 | private VotingPluginMain plugin;
26 |
27 | public AdminVoteCumulative(VotingPluginMain plugin, CommandSender player) {
28 | super(plugin, player);
29 | this.plugin = plugin;
30 | }
31 |
32 | @Override
33 | public ArrayList getChat(CommandSender sender) {
34 | return null;
35 | }
36 |
37 | @Override
38 | public void onBook(Player player) {
39 | }
40 |
41 | @Override
42 | public void onChat(CommandSender sender) {
43 |
44 | }
45 |
46 | @Override
47 | public void onChest(Player player) {
48 | BInventory inv = new BInventory("Edit Cumulative");
49 | inv.requirePermission("VotingPlugin.Commands.AdminVote.Edit.Cumulative");
50 | inv.addButton(
51 | new BInventoryButton(new ItemBuilder(Material.PAPER).setName("&cEdit existing cumulative rewards")) {
52 |
53 | @Override
54 | public void onClick(ClickEvent clickEvent) {
55 | ArrayList nums = new ArrayList<>();
56 | for (String num : plugin.getSpecialRewardsConfig().getCumulativeVotes()) {
57 | if (MessageAPI.isInt(num)) {
58 | nums.add(Integer.parseInt(num));
59 | }
60 | }
61 | Number[] options = new Number[nums.size()];
62 | for (int i = 0; i < nums.size(); i++) {
63 | options[i] = nums.get(i);
64 | }
65 | new ValueRequestBuilder(new NumberListener() {
66 |
67 | @Override
68 | public void onInput(Player player, Number value) {
69 | RewardEditGUI.getInstance().openRewardGUI(clickEvent.getPlayer(),
70 | plugin.getRewardHandler()
71 | .getDirectlyDefined("Cumulative." + value.intValue() + ".Rewards"));
72 | }
73 | }, options).allowCustomOption(false).usingMethod(InputMethod.INVENTORY)
74 | .request(clickEvent.getPlayer());
75 |
76 | }
77 | });
78 |
79 | inv.addButton(new BInventoryButton(new ItemBuilder(Material.EMERALD_BLOCK).setName("&aAdd cumulative reward")) {
80 |
81 | @Override
82 | public void onClick(ClickEvent clickEvent) {
83 | new ValueRequest().requestNumber(player, new NumberListener() {
84 |
85 | @Override
86 | public void onInput(Player player, Number value) {
87 | plugin.getSpecialRewardsConfig().setCumulative(value.intValue());
88 | plugin.reload();
89 | }
90 | });
91 | }
92 | });
93 |
94 | inv.addButton(new BInventoryButton(new ItemBuilder(Material.REDSTONE_BLOCK).setName("&cRemove cumulative")) {
95 |
96 | @Override
97 | public void onClick(ClickEvent clickEvent) {
98 | new AdminVoteCumulativeRemove(plugin, clickEvent.getPlayer()).open();
99 | }
100 | });
101 | inv.openInventory(player);
102 | }
103 |
104 | @Override
105 | public void open() {
106 | open(GUIMethod.CHEST);
107 | }
108 |
109 | }
110 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/admin/cumulative/AdminVoteCumulativeRemove.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.gui.admin.cumulative;
2 |
3 | import java.util.ArrayList;
4 |
5 | import org.bukkit.Material;
6 | import org.bukkit.command.CommandSender;
7 | import org.bukkit.entity.Player;
8 |
9 | import com.bencodez.advancedcore.api.gui.GUIHandler;
10 | import com.bencodez.advancedcore.api.gui.GUIMethod;
11 | import com.bencodez.advancedcore.api.inventory.BInventory;
12 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
13 | import com.bencodez.advancedcore.api.inventory.BInventoryButton;
14 | import com.bencodez.advancedcore.api.item.ItemBuilder;
15 | import com.bencodez.votingplugin.VotingPluginMain;
16 | import com.bencodez.votingplugin.commands.gui.admin.AdminVoteConfirmation;
17 |
18 | public class AdminVoteCumulativeRemove extends GUIHandler {
19 |
20 | private VotingPluginMain plugin;
21 |
22 | public AdminVoteCumulativeRemove(VotingPluginMain plugin, CommandSender player) {
23 | super(plugin, player);
24 | this.plugin = plugin;
25 | }
26 |
27 | @Override
28 | public ArrayList getChat(CommandSender sender) {
29 | return null;
30 | }
31 |
32 | @Override
33 | public void onBook(Player player) {
34 | }
35 |
36 | @Override
37 | public void onChat(CommandSender sender) {
38 |
39 | }
40 |
41 | @Override
42 | public void onChest(Player player) {
43 | BInventory inv = new BInventory("Remove cumulative");
44 | inv.requirePermission("VotingPlugin.Commands.AdminVote.Edit.Cumulative");
45 | for (final String votes : plugin.getSpecialRewardsConfig().getCumulativeVotes()) {
46 | inv.addButton(new BInventoryButton(
47 | new ItemBuilder(Material.PAPER, 1).setName(votes).addLoreLine("&c&lClick to remove")) {
48 |
49 | @Override
50 | public void onClick(ClickEvent clickEvent) {
51 | new AdminVoteConfirmation(plugin, clickEvent.getPlayer(), "Remove cumulative " + votes + "?") {
52 |
53 | @Override
54 | public void onConfirm(Player p) {
55 | plugin.getSpecialRewardsConfig().removeCumulative(votes);
56 | p.sendMessage("Removed cumulative " + votes);
57 | plugin.reload();
58 | }
59 |
60 | @Override
61 | public void onDeny(Player p) {
62 | new AdminVoteCumulative(plugin, p);
63 | }
64 | }.open();
65 |
66 | }
67 | });
68 | }
69 | inv.openInventory(player);
70 | }
71 |
72 | @Override
73 | public void open() {
74 | open(GUIMethod.CHEST);
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/admin/milestones/AdminVoteMilestoneRemove.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.gui.admin.milestones;
2 |
3 | import java.util.ArrayList;
4 |
5 | import org.bukkit.Material;
6 | import org.bukkit.command.CommandSender;
7 | import org.bukkit.entity.Player;
8 |
9 | import com.bencodez.advancedcore.api.gui.GUIHandler;
10 | import com.bencodez.advancedcore.api.gui.GUIMethod;
11 | import com.bencodez.advancedcore.api.inventory.BInventory;
12 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
13 | import com.bencodez.advancedcore.api.inventory.BInventoryButton;
14 | import com.bencodez.advancedcore.api.item.ItemBuilder;
15 | import com.bencodez.votingplugin.VotingPluginMain;
16 | import com.bencodez.votingplugin.commands.gui.admin.AdminVoteConfirmation;
17 |
18 | public class AdminVoteMilestoneRemove extends GUIHandler {
19 |
20 | private VotingPluginMain plugin;
21 |
22 | public AdminVoteMilestoneRemove(VotingPluginMain plugin, CommandSender player) {
23 | super(plugin, player);
24 | this.plugin = plugin;
25 | }
26 |
27 | @Override
28 | public ArrayList getChat(CommandSender sender) {
29 | return null;
30 | }
31 |
32 | @Override
33 | public void onBook(Player player) {
34 | }
35 |
36 | @Override
37 | public void onChat(CommandSender sender) {
38 |
39 | }
40 |
41 | @Override
42 | public void onChest(Player player) {
43 | BInventory inv = new BInventory("Remove milestones");
44 | inv.requirePermission("VotingPlugin.Commands.AdminVote.Edit.MileStones");
45 | for (final String votes : plugin.getSpecialRewardsConfig().getMilestoneVotes()) {
46 | inv.addButton(new BInventoryButton(
47 | new ItemBuilder(Material.PAPER, 1).setName(votes).addLoreLine("&c&lClick to remove")) {
48 |
49 | @Override
50 | public void onClick(ClickEvent clickEvent) {
51 | new AdminVoteConfirmation(plugin, clickEvent.getPlayer(), "Remove milestone " + votes + "?") {
52 |
53 | @Override
54 | public void onConfirm(Player p) {
55 | plugin.getSpecialRewardsConfig().removeMilestone(votes);
56 | p.sendMessage("Removed milestone " + votes);
57 | plugin.reload();
58 | }
59 |
60 | @Override
61 | public void onDeny(Player p) {
62 | new AdminVoteMilestones(plugin, p);
63 | }
64 | }.open();
65 |
66 | }
67 | });
68 | }
69 | inv.openInventory(player);
70 | }
71 |
72 | @Override
73 | public void open() {
74 | open(GUIMethod.CHEST);
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/admin/milestones/AdminVoteMilestones.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.gui.admin.milestones;
2 |
3 | import java.util.ArrayList;
4 |
5 | import org.bukkit.Material;
6 | import org.bukkit.command.CommandSender;
7 | import org.bukkit.entity.Player;
8 |
9 | import com.bencodez.advancedcore.api.gui.GUIHandler;
10 | import com.bencodez.advancedcore.api.gui.GUIMethod;
11 | import com.bencodez.advancedcore.api.inventory.BInventory;
12 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
13 | import com.bencodez.advancedcore.api.inventory.BInventoryButton;
14 | import com.bencodez.advancedcore.api.item.ItemBuilder;
15 | import com.bencodez.advancedcore.api.valuerequest.InputMethod;
16 | import com.bencodez.advancedcore.api.valuerequest.ValueRequest;
17 | import com.bencodez.advancedcore.api.valuerequest.ValueRequestBuilder;
18 | import com.bencodez.advancedcore.api.valuerequest.listeners.NumberListener;
19 | import com.bencodez.advancedcore.command.gui.RewardEditGUI;
20 | import com.bencodez.simpleapi.messages.MessageAPI;
21 | import com.bencodez.votingplugin.VotingPluginMain;
22 |
23 | public class AdminVoteMilestones extends GUIHandler {
24 |
25 | private VotingPluginMain plugin;
26 |
27 | public AdminVoteMilestones(VotingPluginMain plugin, CommandSender player) {
28 | super(plugin, player);
29 | this.plugin = plugin;
30 | }
31 |
32 | @Override
33 | public ArrayList getChat(CommandSender sender) {
34 | return null;
35 | }
36 |
37 | @Override
38 | public void onBook(Player player) {
39 | }
40 |
41 | @Override
42 | public void onChat(CommandSender sender) {
43 |
44 | }
45 |
46 | @Override
47 | public void onChest(Player player) {
48 | BInventory inv = new BInventory("Edit MileStones");
49 | inv.requirePermission("VotingPlugin.Commands.AdminVote.Edit.MileStones");
50 | inv.addButton(
51 | new BInventoryButton(new ItemBuilder(Material.PAPER).setName("&cEdit existing milestone rewards")) {
52 |
53 | @Override
54 | public void onClick(ClickEvent clickEvent) {
55 | ArrayList nums = new ArrayList<>();
56 | for (String num : plugin.getSpecialRewardsConfig().getMilestoneVotes()) {
57 | if (MessageAPI.isInt(num)) {
58 | nums.add(Integer.parseInt(num));
59 | }
60 | }
61 | Number[] options = new Number[nums.size()];
62 | for (int i = 0; i < nums.size(); i++) {
63 | options[i] = nums.get(i);
64 | }
65 | new ValueRequestBuilder(new NumberListener() {
66 |
67 | @Override
68 | public void onInput(Player player, Number value) {
69 | RewardEditGUI.getInstance().openRewardGUI(clickEvent.getPlayer(),
70 | plugin.getRewardHandler()
71 | .getDirectlyDefined("MileStones." + value.intValue() + ".Rewards"));
72 | }
73 | }, options).allowCustomOption(false).usingMethod(InputMethod.INVENTORY)
74 | .request(clickEvent.getPlayer());
75 |
76 | }
77 | });
78 |
79 | inv.addButton(new BInventoryButton(new ItemBuilder(Material.EMERALD_BLOCK).setName("&aAdd milestone")) {
80 |
81 | @Override
82 | public void onClick(ClickEvent clickEvent) {
83 | new ValueRequest().requestNumber(player, new NumberListener() {
84 |
85 | @Override
86 | public void onInput(Player player, Number value) {
87 | plugin.getSpecialRewardsConfig().setMilestone(value.intValue());
88 | plugin.reload();
89 | }
90 | });
91 | }
92 | });
93 |
94 | inv.addButton(new BInventoryButton(new ItemBuilder(Material.REDSTONE_BLOCK).setName("&cRemove milestone")) {
95 |
96 | @Override
97 | public void onClick(ClickEvent clickEvent) {
98 | new AdminVoteMilestoneRemove(plugin, clickEvent.getPlayer()).open();
99 | }
100 | });
101 | inv.openInventory(player);
102 | }
103 |
104 | @Override
105 | public void open() {
106 | open(GUIMethod.CHEST);
107 | }
108 |
109 | }
110 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/admin/voteshop/AdminVoteVoteShop.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.gui.admin.voteshop;
2 |
3 | import java.util.ArrayList;
4 |
5 | import org.bukkit.Material;
6 | import org.bukkit.command.CommandSender;
7 | import org.bukkit.entity.Player;
8 |
9 | import com.bencodez.advancedcore.api.gui.GUIHandler;
10 | import com.bencodez.advancedcore.api.gui.GUIMethod;
11 | import com.bencodez.advancedcore.api.inventory.BInventory;
12 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
13 | import com.bencodez.advancedcore.api.inventory.BInventoryButton;
14 | import com.bencodez.advancedcore.api.item.ItemBuilder;
15 | import com.bencodez.advancedcore.api.valuerequest.ValueRequest;
16 | import com.bencodez.advancedcore.api.valuerequest.listeners.StringListener;
17 | import com.bencodez.votingplugin.VotingPluginMain;
18 |
19 | public class AdminVoteVoteShop extends GUIHandler {
20 |
21 | private VotingPluginMain plugin;
22 |
23 | public AdminVoteVoteShop(VotingPluginMain plugin, CommandSender player) {
24 | super(plugin, player);
25 | this.plugin = plugin;
26 | }
27 |
28 | @Override
29 | public ArrayList getChat(CommandSender sender) {
30 | return null;
31 | }
32 |
33 | @Override
34 | public void onBook(Player player) {
35 | }
36 |
37 | @Override
38 | public void onChat(CommandSender sender) {
39 |
40 | }
41 |
42 | @Override
43 | public void onChest(Player player) {
44 | BInventory inv = new BInventory("Edit VoteShop");
45 | inv.requirePermission("VotingPlugin.Commands.AdminVote.Edit.VoteShop");
46 | inv.addButton(new BInventoryButton(new ItemBuilder(Material.DIAMOND).setName("&cEdit existing item")) {
47 |
48 | @Override
49 | public void onClick(ClickEvent clickEvent) {
50 | new AdminVoteVoteShopItems(plugin, clickEvent.getPlayer()).open(GUIMethod.CHEST);
51 | }
52 | });
53 |
54 | inv.addButton(new BInventoryButton(new ItemBuilder(Material.EMERALD_BLOCK).setName("&aAdd voteshop item")) {
55 |
56 | @Override
57 | public void onClick(ClickEvent clickEvent) {
58 | new ValueRequest().requestString(player, new StringListener() {
59 |
60 | @Override
61 | public void onInput(Player player, String value) {
62 | plugin.getShopFile().createShop(value);
63 | plugin.reload();
64 | }
65 | });
66 | }
67 | });
68 |
69 | inv.addButton(new BInventoryButton(new ItemBuilder(Material.REDSTONE_BLOCK).setName("&cRemove item")) {
70 |
71 | @Override
72 | public void onClick(ClickEvent clickEvent) {
73 | new AdminVoteVoteShopItemRemove(plugin, clickEvent.getPlayer()).open();
74 | }
75 | });
76 | inv.openInventory(player);
77 | }
78 |
79 | @Override
80 | public void open() {
81 | open(GUIMethod.CHEST);
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/admin/voteshop/AdminVoteVoteShopItemRemove.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.gui.admin.voteshop;
2 |
3 | import java.util.ArrayList;
4 |
5 | import org.bukkit.command.CommandSender;
6 | import org.bukkit.entity.Player;
7 |
8 | import com.bencodez.advancedcore.api.gui.GUIHandler;
9 | import com.bencodez.advancedcore.api.gui.GUIMethod;
10 | import com.bencodez.advancedcore.api.inventory.BInventory;
11 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
12 | import com.bencodez.advancedcore.api.inventory.BInventoryButton;
13 | import com.bencodez.advancedcore.api.item.ItemBuilder;
14 | import com.bencodez.votingplugin.VotingPluginMain;
15 | import com.bencodez.votingplugin.commands.gui.admin.AdminVoteConfirmation;
16 |
17 | public class AdminVoteVoteShopItemRemove extends GUIHandler {
18 |
19 | private VotingPluginMain plugin;
20 |
21 | public AdminVoteVoteShopItemRemove(VotingPluginMain plugin, CommandSender player) {
22 | super(plugin, player);
23 | this.plugin = plugin;
24 | }
25 |
26 | @Override
27 | public ArrayList getChat(CommandSender sender) {
28 | return null;
29 | }
30 |
31 | @Override
32 | public void onBook(Player player) {
33 | }
34 |
35 | @Override
36 | public void onChat(CommandSender sender) {
37 |
38 | }
39 |
40 | @Override
41 | public void onChest(Player player) {
42 | BInventory inv = new BInventory("Edit VoteShop Remove Item");
43 | inv.requirePermission("VotingPlugin.Commands.AdminVote.Edit.VoteShop");
44 |
45 | for (final String identifier : plugin.getShopFile().getShopIdentifiers()) {
46 | inv.addButton(
47 | new BInventoryButton(new ItemBuilder(plugin.getShopFile().getShopIdentifierSection(identifier))
48 | .addLoreLine("&c&lClick to remove")) {
49 |
50 | @Override
51 | public void onClick(ClickEvent clickEvent) {
52 | new AdminVoteConfirmation(plugin, clickEvent.getPlayer(),
53 | "Remove shop item " + identifier + "?") {
54 |
55 | @Override
56 | public void onConfirm(Player p) {
57 | plugin.getShopFile().removeShop(identifier);
58 | p.sendMessage("Removed " + identifier);
59 | plugin.reload();
60 | }
61 |
62 | @Override
63 | public void onDeny(Player p) {
64 | new AdminVoteVoteShop(plugin, p).open();
65 | }
66 | }.open();
67 |
68 | }
69 | }.addData("ident", identifier));
70 | }
71 | inv.openInventory(player);
72 | }
73 |
74 | @Override
75 | public void open() {
76 | open(GUIMethod.CHEST);
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/admin/voteshop/AdminVoteVoteShopItems.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.gui.admin.voteshop;
2 |
3 | import java.util.ArrayList;
4 |
5 | import org.bukkit.command.CommandSender;
6 | import org.bukkit.entity.Player;
7 |
8 | import com.bencodez.advancedcore.api.gui.GUIHandler;
9 | import com.bencodez.advancedcore.api.gui.GUIMethod;
10 | import com.bencodez.advancedcore.api.inventory.BInventory;
11 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
12 | import com.bencodez.advancedcore.api.inventory.BInventoryButton;
13 | import com.bencodez.advancedcore.api.item.ItemBuilder;
14 | import com.bencodez.votingplugin.VotingPluginMain;
15 |
16 | public class AdminVoteVoteShopItems extends GUIHandler {
17 |
18 | private VotingPluginMain plugin;
19 |
20 | public AdminVoteVoteShopItems(VotingPluginMain plugin, CommandSender player) {
21 | super(plugin, player);
22 | this.plugin = plugin;
23 | }
24 |
25 | @Override
26 | public ArrayList getChat(CommandSender sender) {
27 | return null;
28 | }
29 |
30 | @Override
31 | public void onBook(Player player) {
32 | }
33 |
34 | @Override
35 | public void onChat(CommandSender sender) {
36 |
37 | }
38 |
39 | @Override
40 | public void onChest(Player player) {
41 | BInventory inv = new BInventory("Edit VoteShop Items");
42 | inv.requirePermission("VotingPlugin.Commands.AdminVote.Edit.VoteShop");
43 |
44 | for (String identifier : plugin.getShopFile().getShopIdentifiers()) {
45 | inv.addButton(
46 | new BInventoryButton(new ItemBuilder(plugin.getShopFile().getShopIdentifierSection(identifier))) {
47 |
48 | @Override
49 | public void onClick(ClickEvent clickEvent) {
50 | new AdminVoteVoteShopItem(plugin, clickEvent.getPlayer(), (String) getData("ident"))
51 | .open(GUIMethod.CHEST);
52 |
53 | }
54 | }.addData("ident", identifier));
55 | }
56 |
57 | inv.openInventory(player);
58 | }
59 |
60 | @Override
61 | public void open() {
62 | open(GUIMethod.CHEST);
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteBest.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.gui.player;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 |
6 | import org.bukkit.command.CommandSender;
7 | import org.bukkit.entity.Player;
8 |
9 | import com.bencodez.advancedcore.api.gui.GUIHandler;
10 | import com.bencodez.advancedcore.api.gui.GUIMethod;
11 | import com.bencodez.advancedcore.api.inventory.BInventory;
12 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
13 | import com.bencodez.advancedcore.api.inventory.BInventoryButton;
14 | import com.bencodez.advancedcore.api.item.ItemBuilder;
15 | import com.bencodez.advancedcore.api.messages.PlaceholderUtils;
16 | import com.bencodez.advancedcore.api.rewards.RewardBuilder;
17 | import com.bencodez.simpleapi.array.ArrayUtils;
18 | import com.bencodez.votingplugin.VotingPluginMain;
19 | import com.bencodez.votingplugin.user.VotingPluginUser;
20 |
21 | public class VoteBest extends GUIHandler {
22 |
23 | private VotingPluginMain plugin;
24 | private VotingPluginUser user;
25 |
26 | public VoteBest(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) {
27 | super(plugin, player);
28 | this.plugin = plugin;
29 | this.user = user;
30 | }
31 |
32 | @Override
33 | public ArrayList getChat(CommandSender sender) {
34 | ArrayList msg = new ArrayList<>();
35 | msg.add(plugin.getConfigFile().getFormatCommandsVoteBestTitle());
36 | msg.addAll(plugin.getConfigFile().getFormatCommandsVoteBestLines());
37 |
38 | HashMap placeholders = new HashMap<>();
39 | placeholders.put("HighestDailyTotal", "" + user.getHighestDailyTotal());
40 | placeholders.put("HighestWeeklyTotal", "" + user.getHighestWeeklyTotal());
41 | placeholders.put("HighestMonthlyTotal", "" + user.getHighestMonthlyTotal());
42 |
43 | placeholders.put("player", user.getPlayerName());
44 |
45 | msg = PlaceholderUtils.replacePlaceHolder(msg, placeholders);
46 |
47 | return ArrayUtils.colorize(msg);
48 | }
49 |
50 | @Override
51 | public void onBook(Player player) {
52 | // TODO
53 | }
54 |
55 | @Override
56 | public void onChat(CommandSender sender) {
57 | sendMessage(getChat(sender));
58 | }
59 |
60 | @Override
61 | public void onChest(Player player) {
62 | BInventory inv = new BInventory(plugin.getGui().getChestVoteBestName());
63 | inv.addPlaceholder("player", user.getPlayerName());
64 |
65 | inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteBestDayBestItem())
66 | .addPlaceholder("Best", "" + user.getBestDayVoteStreak())) {
67 |
68 | @Override
69 | public void onClick(ClickEvent clickEvent) {
70 |
71 | }
72 | });
73 |
74 | inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteBestWeekBestItem())
75 | .addPlaceholder("Best", "" + user.getBestWeekVoteStreak())) {
76 |
77 | @Override
78 | public void onClick(ClickEvent clickEvent) {
79 |
80 | }
81 | });
82 |
83 | inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteBestMonthBestItem())
84 | .addPlaceholder("Best", "" + user.getBestMonthVoteStreak())) {
85 |
86 | @Override
87 | public void onClick(ClickEvent clickEvent) {
88 |
89 | }
90 | });
91 |
92 | if (plugin.getGui().isChestVoteBestBackButton()) {
93 | inv.addButton(plugin.getCommandLoader().getBackButton(user));
94 | }
95 |
96 | String guiPath = "VoteBest";
97 | for (final String str : plugin.getGui().getChestGUIExtraItems(guiPath)) {
98 | inv.addButton(
99 | new BInventoryButton(new ItemBuilder(plugin.getGui().getChestGUIExtraItemsItem(guiPath, str))) {
100 |
101 | @Override
102 | public void onClick(ClickEvent clickEvent) {
103 | new RewardBuilder(plugin.getGui().getData(),
104 | "CHEST." + guiPath + ".ExtraItems." + str + "."
105 | + clickEvent.getButton().getLastRewardsPath(player))
106 | .setGiveOffline(false).send(clickEvent.getPlayer());
107 |
108 | }
109 | });
110 | }
111 |
112 | inv.openInventory(player);
113 | }
114 |
115 | @Override
116 | public void open() {
117 | open(GUIMethod.valueOf(plugin.getGui().getGuiMethodBest().toUpperCase()));
118 | }
119 |
120 | }
121 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteHelp.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.gui.player;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collections;
5 | import java.util.HashMap;
6 |
7 | import org.bukkit.command.CommandSender;
8 | import org.bukkit.entity.Player;
9 |
10 | import com.bencodez.advancedcore.api.command.CommandHandler;
11 | import com.bencodez.advancedcore.api.gui.GUIHandler;
12 | import com.bencodez.advancedcore.api.gui.GUIMethod;
13 | import com.bencodez.simpleapi.messages.MessageAPI;
14 | import com.bencodez.simpleapi.nms.NMSManager;
15 | import com.bencodez.votingplugin.VotingPluginMain;
16 |
17 | import net.md_5.bungee.api.ChatColor;
18 | import net.md_5.bungee.api.chat.TextComponent;
19 |
20 | public class VoteHelp extends GUIHandler {
21 |
22 | private int page;
23 | private VotingPluginMain plugin;
24 |
25 | public VoteHelp(VotingPluginMain plugin, CommandSender player, int page) {
26 | super(plugin, player);
27 | this.plugin = plugin;
28 | this.page = page;
29 | }
30 |
31 | @Override
32 | public ArrayList getChat(CommandSender sender) {
33 | return null;
34 | }
35 |
36 | public ArrayList helpText(CommandSender sender) {
37 | ArrayList msg = new ArrayList<>();
38 | HashMap unsorted = new HashMap<>();
39 |
40 | boolean requirePerms = plugin.getConfigFile().isFormatCommandsVoteHelpRequirePermission();
41 |
42 | String colorStr = plugin.getConfigFile().getFormatCommandsVoteHelpHoverColor();
43 | ChatColor hoverColor = null;
44 | try {
45 | hoverColor = ChatColor.of(colorStr);
46 | } catch (Exception e) {
47 | plugin.getLogger().warning("Failed to get color for hover help message");
48 | e.printStackTrace();
49 | hoverColor = ChatColor.AQUA;
50 | }
51 | for (CommandHandler cmdHandle : plugin.getVoteCommand()) {
52 | if (!requirePerms || cmdHandle.hasPerm(sender)) {
53 | unsorted.put(cmdHandle.getHelpLineCommand("/vote"), cmdHandle.getHelpLine("/vote",
54 | plugin.getConfigFile().getFormatCommandsVoteHelpLine(), hoverColor));
55 | }
56 | }
57 | ArrayList unsortedList = new ArrayList<>();
58 | unsortedList.addAll(unsorted.keySet());
59 | Collections.sort(unsortedList, String.CASE_INSENSITIVE_ORDER);
60 | for (String cmd : unsortedList) {
61 | msg.add(unsorted.get(cmd));
62 | }
63 |
64 | return msg;
65 | }
66 |
67 | public ArrayList helpTextLegacy(CommandSender sender) {
68 | ArrayList msg = new ArrayList<>();
69 | HashMap unsorted = new HashMap<>();
70 |
71 | boolean requirePerms = plugin.getConfigFile().isFormatCommandsVoteHelpRequirePermission();
72 |
73 | for (CommandHandler cmdHandle : plugin.getVoteCommand()) {
74 | if (!requirePerms || cmdHandle.hasPerm(sender)) {
75 | unsorted.put(cmdHandle.getHelpLineCommand("/vote"),
76 | cmdHandle.getHelpLine("/vote", plugin.getConfigFile().getFormatCommandsVoteHelpLine()));
77 | }
78 | }
79 | ArrayList unsortedList = new ArrayList<>();
80 | unsortedList.addAll(unsorted.keySet());
81 | Collections.sort(unsortedList, String.CASE_INSENSITIVE_ORDER);
82 | for (String cmd : unsortedList) {
83 | msg.add(unsorted.get(cmd));
84 | }
85 |
86 | return msg;
87 | }
88 |
89 | @Override
90 | public void onBook(Player player) {
91 |
92 | }
93 |
94 | @Override
95 | public void onChat(CommandSender sender) {
96 | sendMessageJson(voteHelpText(sender));
97 | }
98 |
99 | @Override
100 | public void onChest(Player player) {
101 |
102 | }
103 |
104 | @Override
105 | public void open() {
106 | open(GUIMethod.CHAT);
107 | }
108 |
109 | public ArrayList voteHelpText(CommandSender sender) {
110 | int pagesize = plugin.getConfigFile().getFormatPageSize();
111 | ArrayList msg = new ArrayList<>();
112 | ArrayList text = new ArrayList<>();
113 | if (NMSManager.getInstance().isVersion("1.12")) {
114 | text = helpTextLegacy(sender);
115 | } else {
116 | text = helpText(sender);
117 | }
118 |
119 | int maxPage = text.size() / pagesize;
120 | if ((text.size() % pagesize) != 0) {
121 | maxPage++;
122 | }
123 |
124 | msg.add(MessageAPI
125 | .stringToComp(plugin.getConfigFile().getFormatCommandsVoteHelpTitle() + " " + page + "/" + maxPage));
126 |
127 | for (int i = pagesize * (page - 1); (i < text.size()) && (i < ((page) * pagesize)); i++) {
128 | msg.add(text.get(i));
129 | }
130 |
131 | return msg;
132 | }
133 |
134 | }
135 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteLast.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.gui.player;
2 |
3 | import java.util.ArrayList;
4 |
5 | import org.bukkit.command.CommandSender;
6 | import org.bukkit.entity.Player;
7 |
8 | import com.bencodez.advancedcore.api.gui.GUIHandler;
9 | import com.bencodez.advancedcore.api.gui.GUIMethod;
10 | import com.bencodez.advancedcore.api.inventory.BInventory;
11 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
12 | import com.bencodez.advancedcore.api.inventory.BInventoryButton;
13 | import com.bencodez.advancedcore.api.inventory.UpdatingBInventoryButton;
14 | import com.bencodez.advancedcore.api.item.ItemBuilder;
15 | import com.bencodez.advancedcore.api.messages.PlaceholderUtils;
16 | import com.bencodez.advancedcore.api.rewards.RewardBuilder;
17 | import com.bencodez.simpleapi.array.ArrayUtils;
18 | import com.bencodez.simpleapi.messages.MessageAPI;
19 | import com.bencodez.votingplugin.VotingPluginMain;
20 | import com.bencodez.votingplugin.objects.VoteSite;
21 | import com.bencodez.votingplugin.user.VotingPluginUser;
22 |
23 | public class VoteLast extends GUIHandler {
24 |
25 | private VotingPluginMain plugin;
26 | private VotingPluginUser user;
27 |
28 | public VoteLast(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) {
29 | super(plugin, player);
30 | this.plugin = plugin;
31 | this.user = user;
32 | }
33 |
34 | @Override
35 | public ArrayList getChat(CommandSender sender) {
36 | ArrayList msg = new ArrayList<>();
37 |
38 | String playerName = user.getPlayerName();
39 |
40 | msg.add(MessageAPI.replaceIgnoreCase(plugin.getConfigFile().getFormatCommandsVoteLastTitle(), "%player%",
41 | playerName));
42 |
43 | for (VoteSite voteSite : plugin.getVoteSitesEnabled()) {
44 | if (!voteSite.isHidden()) {
45 | msg.add(user.voteCommandLastLine(voteSite));
46 | }
47 | }
48 |
49 | return ArrayUtils.colorize(msg);
50 | }
51 |
52 | @Override
53 | public void onBook(Player player) {
54 | // TODO
55 | }
56 |
57 | @Override
58 | public void onChat(CommandSender sender) {
59 | sendMessage(getChat(sender));
60 | }
61 |
62 | @Override
63 | public void onChest(Player player) {
64 | BInventory inv = new BInventory(plugin.getGui().getChestVoteLastName());
65 | inv.addPlaceholder("player", user.getPlayerName());
66 | for (VoteSite site : plugin.getVoteSitesEnabled()) {
67 | if (!site.isHidden()) {
68 | inv.addButton(inv.getNextSlot(),
69 | new UpdatingBInventoryButton(plugin, site.getItem().setName(site.getDisplayName())
70 | .setLore(user.voteCommandLastGUILine(site)).setAmountNone(1), 1000, 1000) {
71 |
72 | @Override
73 | public void onClick(ClickEvent event) {
74 | if (plugin.getGui().isChestVoteLastClickableLinks()) {
75 | Player player = event.getPlayer();
76 | if (player != null) {
77 | VotingPluginUser user = plugin.getVotingPluginUserManager()
78 | .getVotingPluginUser(player);
79 | user.sendMessage(
80 | PlaceholderUtils
81 | .replacePlaceHolder(
82 | PlaceholderUtils.replacePlaceHolder(
83 | PlaceholderUtils.replacePlaceHolder(
84 | plugin.getGui()
85 | .getChestVoteURLURLText(),
86 | "voteurl", site.getVoteURL()),
87 | "sitename", site.getDisplayName()),
88 | "player", player.getName()));
89 |
90 | }
91 | }
92 | }
93 |
94 | @Override
95 | public ItemBuilder onUpdate(Player p) {
96 | return site.getItem().setName(site.getDisplayName())
97 | .setLore(user.voteCommandLastGUILine(site)).setAmountNone(1);
98 | }
99 | });
100 | }
101 | }
102 |
103 | String guiPath = "VoteLast";
104 | for (final String str : plugin.getGui().getChestGUIExtraItems(guiPath)) {
105 | inv.addButton(
106 | new BInventoryButton(new ItemBuilder(plugin.getGui().getChestGUIExtraItemsItem(guiPath, str))) {
107 |
108 | @Override
109 | public void onClick(ClickEvent clickEvent) {
110 | new RewardBuilder(plugin.getGui().getData(),
111 | "CHEST." + guiPath + ".ExtraItems." + str + "."
112 | + clickEvent.getButton().getLastRewardsPath(player))
113 | .setGiveOffline(false).send(clickEvent.getPlayer());
114 |
115 | }
116 | });
117 | }
118 |
119 | if (plugin.getGui().isChestVoteLastBackButton()) {
120 | inv.addButton(plugin.getCommandLoader().getBackButton(user));
121 | }
122 |
123 | inv.openInventory(player);
124 | }
125 |
126 | @Override
127 | public void open() {
128 | open(GUIMethod.valueOf(plugin.getGui().getGuiMethodLast().toUpperCase()));
129 | }
130 |
131 | }
132 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteNext.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.gui.player;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Arrays;
5 |
6 | import org.bukkit.command.CommandSender;
7 | import org.bukkit.entity.Player;
8 |
9 | import com.bencodez.advancedcore.api.bookgui.BookWrapper;
10 | import com.bencodez.advancedcore.api.bookgui.Layout;
11 | import com.bencodez.advancedcore.api.gui.GUIHandler;
12 | import com.bencodez.advancedcore.api.gui.GUIMethod;
13 | import com.bencodez.advancedcore.api.inventory.BInventory;
14 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
15 | import com.bencodez.advancedcore.api.inventory.BInventoryButton;
16 | import com.bencodez.advancedcore.api.inventory.UpdatingBInventoryButton;
17 | import com.bencodez.advancedcore.api.item.ItemBuilder;
18 | import com.bencodez.advancedcore.api.messages.PlaceholderUtils;
19 | import com.bencodez.advancedcore.api.rewards.RewardBuilder;
20 | import com.bencodez.simpleapi.messages.MessageAPI;
21 | import com.bencodez.votingplugin.VotingPluginMain;
22 | import com.bencodez.votingplugin.objects.VoteSite;
23 | import com.bencodez.votingplugin.user.VotingPluginUser;
24 |
25 | import xyz.upperlevel.spigot.book.BookUtil;
26 |
27 | public class VoteNext extends GUIHandler {
28 |
29 | private VotingPluginMain plugin;
30 | private VotingPluginUser user;
31 |
32 | public VoteNext(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) {
33 | super(plugin, player);
34 | this.plugin = plugin;
35 | this.user = user;
36 | }
37 |
38 | @Override
39 | public ArrayList getChat(CommandSender sender) {
40 | ArrayList msg = new ArrayList<>();
41 |
42 | String playerName = user.getPlayerName();
43 |
44 | msg.add(MessageAPI.colorize(MessageAPI
45 | .replaceIgnoreCase(plugin.getConfigFile().getFormatCommandsVoteNextTitle(), "%player%", playerName)));
46 |
47 | for (VoteSite voteSite : plugin.getVoteSitesEnabled()) {
48 | if (!voteSite.isHidden()) {
49 | String msgLine = plugin.getConfigFile().getFormatCommandsVoteNextLayout();
50 |
51 | msgLine = MessageAPI.replaceIgnoreCase(msgLine, "%info%", user.voteCommandNextInfo(voteSite));
52 |
53 | msgLine = MessageAPI.replaceIgnoreCase(msgLine, "%SiteName%", voteSite.getDisplayName());
54 | msg.add(MessageAPI.colorize(msgLine));
55 | }
56 | }
57 | return msg;
58 | }
59 |
60 | @Override
61 | public void onBook(Player player) {
62 | BookWrapper book = new BookWrapper(plugin.getGui().getBookVoteURLBookGUITitle());
63 |
64 | // add colors/config options
65 | for (VoteSite site : plugin.getVoteSitesEnabled()) {
66 | if (!site.isHidden()) {
67 | Layout nextLayout = new Layout(new ArrayList<>(Arrays.asList("[Json]")));
68 | nextLayout.replaceTextComponent("[Json]",
69 | BookUtil.TextBuilder.of(book.colorize(site.getDisplayName()))
70 | .onClick(BookUtil.ClickAction.openUrl(site.getVoteURLJsonStrip()))
71 | .onHover(BookUtil.HoverAction.showText(user.voteCommandNextInfo(site))).build());
72 | book.addLayout(nextLayout);
73 | }
74 | }
75 | book.addLine();
76 |
77 | book.open(player);
78 | }
79 |
80 | @Override
81 | public void onChat(CommandSender sender) {
82 | sendMessage(getChat(sender));
83 | }
84 |
85 | @Override
86 | public void onChest(Player player) {
87 | BInventory inv = new BInventory(plugin.getGui().getChestVoteNextName());
88 | inv.addPlaceholder("player", user.getPlayerName());
89 | for (VoteSite site : plugin.getVoteSitesEnabled()) {
90 | if (!site.isHidden()) {
91 | String siteNameDisplay = plugin.getGui().getChestVoteNextCustomSiteNamesDisplays(site.getKey());
92 | if (siteNameDisplay.isEmpty()) {
93 | siteNameDisplay = site.getDisplayName();
94 | }
95 | inv.addButton(inv.getNextSlot(),
96 | new UpdatingBInventoryButton(plugin,
97 | site.getItem().setName(siteNameDisplay)
98 | .setLore(PlaceholderUtils.replacePlaceHolder(
99 | plugin.getGui().getChestVoteNextLine(), "time",
100 | user.voteCommandNextInfo(site)))
101 | .setAmountNone(1),
102 | 1000, 1000) {
103 |
104 | @Override
105 | public void onClick(ClickEvent clickEvent) {
106 |
107 | }
108 |
109 | @Override
110 | public ItemBuilder onUpdate(Player player) {
111 | return site.getItem().setName(site.getDisplayName())
112 | .setLore(user.voteCommandNextInfo(site)).setAmountNone(1)
113 | .addPlaceholder("player", user.getPlayerName());
114 | }
115 | });
116 | }
117 | }
118 |
119 | String guiPath = "VoteNext";
120 | for (final String str : plugin.getGui().getChestGUIExtraItems(guiPath)) {
121 | inv.addButton(
122 | new BInventoryButton(new ItemBuilder(plugin.getGui().getChestGUIExtraItemsItem(guiPath, str))) {
123 |
124 | @Override
125 | public void onClick(ClickEvent clickEvent) {
126 | new RewardBuilder(plugin.getGui().getData(),
127 | "CHEST." + guiPath + ".ExtraItems." + str + "."
128 | + clickEvent.getButton().getLastRewardsPath(player))
129 | .setGiveOffline(false).send(clickEvent.getPlayer());
130 |
131 | }
132 | });
133 | }
134 |
135 | if (plugin.getGui().isChestVoteNextBackButton()) {
136 | inv.addButton(plugin.getCommandLoader().getBackButton(user));
137 | }
138 | inv.openInventory(player);
139 | }
140 |
141 | @Override
142 | public void open() {
143 | open(GUIMethod.valueOf(plugin.getGui().getGuiMethodNext().toUpperCase()));
144 | }
145 |
146 | }
147 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteShopConfirm.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.gui.player;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 |
6 | import org.bukkit.command.CommandSender;
7 | import org.bukkit.entity.Player;
8 |
9 | import com.bencodez.advancedcore.api.gui.GUIHandler;
10 | import com.bencodez.advancedcore.api.gui.GUIMethod;
11 | import com.bencodez.advancedcore.api.inventory.BInventory;
12 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
13 | import com.bencodez.advancedcore.api.inventory.BInventoryButton;
14 | import com.bencodez.advancedcore.api.item.ItemBuilder;
15 | import com.bencodez.advancedcore.api.messages.PlaceholderUtils;
16 | import com.bencodez.advancedcore.api.rewards.RewardOptions;
17 | import com.bencodez.simpleapi.player.PlayerUtils;
18 | import com.bencodez.votingplugin.VotingPluginMain;
19 | import com.bencodez.votingplugin.user.VotingPluginUser;
20 |
21 | public class VoteShopConfirm extends GUIHandler {
22 |
23 | private String identifier;
24 | private VotingPluginMain plugin;
25 | private VotingPluginUser user;
26 |
27 | public VoteShopConfirm(VotingPluginMain plugin, CommandSender player, VotingPluginUser user, String identifier) {
28 | super(plugin, player);
29 | this.plugin = plugin;
30 | this.user = user;
31 | this.identifier = identifier;
32 | }
33 |
34 | @Override
35 | public ArrayList getChat(CommandSender arg0) {
36 | return null;
37 | }
38 |
39 | @Override
40 | public void onBook(Player player) {
41 | }
42 |
43 | @Override
44 | public void onChat(CommandSender sender) {
45 | }
46 |
47 | @Override
48 | public void onChest(Player player) {
49 | PlayerUtils.setPlayerMeta(plugin, player, "ident", identifier);
50 | BInventory inv = new BInventory(plugin.getShopFile().getShopConfirmPurchaseTitle());
51 | inv.dontClose();
52 | inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getShopFile().getShopConfirmPurchaseYesItem())) {
53 |
54 | @Override
55 | public void onClick(ClickEvent event) {
56 | user.cache();
57 | int points = plugin.getShopFile().getShopIdentifierCost(identifier);
58 | int limit = plugin.getShopFile().getShopIdentifierLimit(identifier);
59 | HashMap placeholders = new HashMap<>();
60 | placeholders.put("identifier", identifier);
61 | placeholders.put("points", "" + points);
62 | placeholders.put("limit", "" + limit);
63 | if (user.removePoints(points, true)) {
64 | plugin.getLogger().info("VoteShop: " + user.getPlayerName() + "/" + user.getUUID() + " bought "
65 | + identifier + " for " + points);
66 | if (plugin.getConfigFile().isTrackShopPurchases()) {
67 | plugin.getServerData().addVoteShopPurchase(identifier);
68 | }
69 |
70 | plugin.getRewardHandler().giveReward(user, plugin.getShopFile().getData(),
71 | plugin.getShopFile().getShopIdentifierRewardsPath(identifier),
72 | new RewardOptions().setPlaceholders(placeholders));
73 |
74 | user.sendMessage(PlaceholderUtils
75 | .replacePlaceHolder(plugin.getShopFile().getVoteShopPurchase(identifier), placeholders));
76 | if (limit > 0) {
77 | user.setVoteShopIdentifierLimit(identifier, user.getVoteShopIdentifierLimit(identifier) + 1);
78 | }
79 | } else {
80 | user.sendMessage(PlaceholderUtils
81 | .replacePlaceHolder(plugin.getConfigFile().getFormatShopFailedMsg(), placeholders));
82 | }
83 | if (plugin.getShopFile().getVoteShopCloseGUI(identifier)) {
84 | event.getButton().getInv().closeInv(player, null);
85 | } else {
86 | new VoteShop(plugin, event.getPlayer(), user).open();
87 | }
88 |
89 | }
90 | });
91 | inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getShopFile().getShopConfirmPurchaseNoItem())) {
92 |
93 | @Override
94 | public void onClick(ClickEvent event) {
95 | if (plugin.getShopFile().getVoteShopCloseGUI(identifier)) {
96 | event.getButton().getInv().closeInv(player, null);
97 | } else {
98 | new VoteShop(plugin, event.getPlayer(), user).open();
99 | }
100 | }
101 | });
102 | inv.openInventory(player);
103 | }
104 |
105 | @Override
106 | public void open() {
107 | open(GUIMethod.CHEST);
108 | }
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteStreak.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.gui.player;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 |
6 | import org.bukkit.command.CommandSender;
7 | import org.bukkit.entity.Player;
8 |
9 | import com.bencodez.advancedcore.api.gui.GUIHandler;
10 | import com.bencodez.advancedcore.api.gui.GUIMethod;
11 | import com.bencodez.advancedcore.api.inventory.BInventory;
12 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
13 | import com.bencodez.advancedcore.api.inventory.BInventoryButton;
14 | import com.bencodez.advancedcore.api.item.ItemBuilder;
15 | import com.bencodez.advancedcore.api.messages.PlaceholderUtils;
16 | import com.bencodez.advancedcore.api.rewards.RewardBuilder;
17 | import com.bencodez.simpleapi.array.ArrayUtils;
18 | import com.bencodez.votingplugin.VotingPluginMain;
19 | import com.bencodez.votingplugin.user.VotingPluginUser;
20 |
21 | public class VoteStreak extends GUIHandler {
22 |
23 | @SuppressWarnings("unused")
24 | private VotingPluginMain plugin;
25 | private VotingPluginUser user;
26 |
27 | public VoteStreak(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) {
28 | super(plugin, player);
29 | this.plugin = plugin;
30 | this.user = user;
31 | }
32 |
33 | @Override
34 | public ArrayList getChat(CommandSender sender) {
35 | ArrayList msg = new ArrayList<>();
36 | msg.add(plugin.getConfigFile().getFormatCommandsVoteStreakTitle());
37 | msg.addAll(plugin.getConfigFile().getFormatCommandsVoteStreakLines());
38 |
39 | HashMap placeholders = new HashMap<>();
40 | placeholders.put("DailyStreak", "" + user.getDayVoteStreak());
41 | placeholders.put("WeeklyStreak", "" + user.getWeekVoteStreak());
42 | placeholders.put("MonthlyStreak", "" + user.getMonthVoteStreak());
43 |
44 | placeholders.put("BestDailyStreak", "" + user.getBestDayVoteStreak());
45 | placeholders.put("BestWeeklyStreak", "" + user.getBestWeekVoteStreak());
46 | placeholders.put("BestMonthlyStreak", "" + user.getBestMonthVoteStreak());
47 |
48 | placeholders.put("player", user.getPlayerName());
49 |
50 | msg = PlaceholderUtils.replacePlaceHolder(msg, placeholders);
51 |
52 | return ArrayUtils.colorize(msg);
53 | }
54 |
55 | @Override
56 | public void onBook(Player player) {
57 | // TODO
58 | }
59 |
60 | @Override
61 | public void onChat(CommandSender sender) {
62 | sendMessage(getChat(sender));
63 | }
64 |
65 | @Override
66 | public void onChest(Player player) {
67 | BInventory inv = new BInventory(plugin.getGui().getChestVoteStreakName());
68 | inv.addPlaceholder("player", user.getPlayerName());
69 |
70 | inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteStreakCurrentDayStreakItem())
71 | .addPlaceholder("Streak", "" + user.getDayVoteStreak())) {
72 |
73 | @Override
74 | public void onClick(ClickEvent clickEvent) {
75 |
76 | }
77 | });
78 |
79 | inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteStreakCurrentWeekStreakItem())
80 | .addPlaceholder("Streak", "" + user.getWeekVoteStreak())) {
81 |
82 | @Override
83 | public void onClick(ClickEvent clickEvent) {
84 |
85 | }
86 | });
87 |
88 | inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteStreakCurrentMonthStreakItem())
89 | .addPlaceholder("Streak", "" + user.getMonthVoteStreak())) {
90 |
91 | @Override
92 | public void onClick(ClickEvent clickEvent) {
93 |
94 | }
95 | });
96 |
97 | inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteStreakHighestDayStreakItem())
98 | .addPlaceholder("Streak", "" + user.getBestDayVoteStreak())) {
99 |
100 | @Override
101 | public void onClick(ClickEvent clickEvent) {
102 |
103 | }
104 | });
105 |
106 | inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteStreakHighestWeekStreakItem())
107 | .addPlaceholder("Streak", "" + user.getBestWeekVoteStreak())) {
108 |
109 | @Override
110 | public void onClick(ClickEvent clickEvent) {
111 |
112 | }
113 | });
114 |
115 | inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteStreakHighestMonthStreakItem())
116 | .addPlaceholder("Streak", "" + user.getBestMonthVoteStreak())) {
117 |
118 | @Override
119 | public void onClick(ClickEvent clickEvent) {
120 |
121 | }
122 | });
123 |
124 | String guiPath = "VoteStreak";
125 | for (final String str : plugin.getGui().getChestGUIExtraItems(guiPath)) {
126 | inv.addButton(
127 | new BInventoryButton(new ItemBuilder(plugin.getGui().getChestGUIExtraItemsItem(guiPath, str))) {
128 |
129 | @Override
130 | public void onClick(ClickEvent clickEvent) {
131 | new RewardBuilder(plugin.getGui().getData(),
132 | "CHEST." + guiPath + ".ExtraItems." + str + "."
133 | + clickEvent.getButton().getLastRewardsPath(player))
134 | .setGiveOffline(false).send(clickEvent.getPlayer());
135 |
136 | }
137 | });
138 | }
139 |
140 | if (plugin.getGui().isChestVoteStreakBackButton()) {
141 | inv.addButton(plugin.getCommandLoader().getBackButton(user));
142 | }
143 |
144 | inv.openInventory(player);
145 | }
146 |
147 | @Override
148 | public void open() {
149 | open(GUIMethod.valueOf(plugin.getGui().getGuiMethodStreak().toUpperCase()));
150 | }
151 |
152 | }
153 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteTopVoterLastMonth.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.gui.player;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Map.Entry;
5 | import java.util.Set;
6 |
7 | import org.bukkit.Material;
8 | import org.bukkit.command.CommandSender;
9 | import org.bukkit.entity.Player;
10 |
11 | import com.bencodez.advancedcore.api.gui.GUIHandler;
12 | import com.bencodez.advancedcore.api.gui.GUIMethod;
13 | import com.bencodez.advancedcore.api.inventory.BInventory;
14 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
15 | import com.bencodez.advancedcore.api.inventory.BInventoryButton;
16 | import com.bencodez.advancedcore.api.item.ItemBuilder;
17 | import com.bencodez.votingplugin.VotingPluginMain;
18 | import com.bencodez.votingplugin.topvoter.TopVoterPlayer;
19 | import com.bencodez.votingplugin.user.VotingPluginUser;
20 |
21 | public class VoteTopVoterLastMonth extends GUIHandler {
22 |
23 | private VotingPluginMain plugin;
24 | private VotingPluginUser user;
25 |
26 | public VoteTopVoterLastMonth(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) {
27 | super(plugin, player);
28 | this.plugin = plugin;
29 | this.user = user;
30 | }
31 |
32 | @Override
33 | public ArrayList getChat(CommandSender arg0) {
34 | return null;
35 | }
36 |
37 | @Override
38 | public void onBook(Player player) {
39 | // TODO
40 | }
41 |
42 | @Override
43 | public void onChat(CommandSender sender) {
44 | }
45 |
46 | @Override
47 | public void onChest(Player player) {
48 | Set> users = null;
49 |
50 | users = plugin.getLastMonthTopVoter().entrySet();
51 |
52 | BInventory inv = new BInventory(plugin.getGui().getChestVoteTopName());
53 | inv.addPlaceholder("topvoter", "Last Month");
54 | if (!plugin.getConfigFile().isAlwaysCloseInventory()) {
55 | inv.dontClose();
56 | }
57 |
58 | int pos = 1;
59 | for (Entry entry : users) {
60 | ItemBuilder playerItem;
61 |
62 | if (plugin.getGui().isChestVoteTopUseSkull()) {
63 | playerItem = new ItemBuilder(entry.getKey().getPlayerHead());
64 | } else {
65 | playerItem = new ItemBuilder(Material.valueOf(plugin.getGui().getChestVoteTopPlayerItemMaterial()));
66 | }
67 |
68 | playerItem.setLore(new ArrayList<>());
69 |
70 | inv.addButton(new BInventoryButton(playerItem.setName(plugin.getGui().getChestVoteTopItemName())
71 | .addLoreLine(plugin.getGui().getChestVoteTopItemLore()).addPlaceholder("position", "" + pos)
72 | .addPlaceholder("player", entry.getKey().getPlayerName())
73 | .addPlaceholder("votes", "" + entry.getValue())) {
74 |
75 | @Override
76 | public void onClick(ClickEvent clickEvent) {
77 | TopVoterPlayer user = (TopVoterPlayer) getData("User");
78 | new VoteGUI(plugin, player, user.getUser())
79 | .open(GUIMethod.valueOf(plugin.getGui().getGuiMethodGUI().toUpperCase()));
80 | }
81 | }.addData("player", entry.getKey().getPlayerName()).addData("User", entry.getKey()));
82 | pos++;
83 | }
84 |
85 | if (plugin.getGui().isChestVoteTopBackButton()) {
86 | inv.getPageButtons().add(plugin.getCommandLoader().getBackButton(user).setSlot(1));
87 | }
88 |
89 | inv.setPages(true);
90 | inv.setMaxInvSize(plugin.getGui().getChestVoteTopSize());
91 | inv.openInventory(player);
92 | }
93 |
94 | @Override
95 | public void open() {
96 | open(GUIMethod.CHEST);
97 | }
98 |
99 | }
100 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteTopVoterPreviousMonths.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.gui.player;
2 |
3 | import java.time.YearMonth;
4 | import java.util.ArrayList;
5 | import java.util.Collections;
6 | import java.util.List;
7 | import java.util.Map.Entry;
8 | import java.util.Set;
9 | import java.util.stream.Collectors;
10 |
11 | import org.bukkit.Material;
12 | import org.bukkit.command.CommandSender;
13 | import org.bukkit.entity.Player;
14 | import org.bukkit.event.inventory.ClickType;
15 |
16 | import com.bencodez.advancedcore.api.gui.GUIHandler;
17 | import com.bencodez.advancedcore.api.gui.GUIMethod;
18 | import com.bencodez.advancedcore.api.inventory.BInventory;
19 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
20 | import com.bencodez.advancedcore.api.inventory.BInventoryButton;
21 | import com.bencodez.advancedcore.api.item.ItemBuilder;
22 | import com.bencodez.votingplugin.VotingPluginMain;
23 | import com.bencodez.votingplugin.topvoter.TopVoterPlayer;
24 | import com.bencodez.votingplugin.user.VotingPluginUser;
25 |
26 | import net.md_5.bungee.api.ChatColor;
27 |
28 | public class VoteTopVoterPreviousMonths extends GUIHandler {
29 |
30 | private VotingPluginMain plugin;
31 | private VotingPluginUser user;
32 | private int index = -1;
33 |
34 | public VoteTopVoterPreviousMonths(VotingPluginMain plugin, CommandSender player, VotingPluginUser user, int index) {
35 | super(plugin, player);
36 | this.plugin = plugin;
37 | this.user = user;
38 | this.index = index;
39 | }
40 |
41 | @Override
42 | public ArrayList getChat(CommandSender arg0) {
43 | return null;
44 | }
45 |
46 | public void next(int index) {
47 |
48 | }
49 |
50 | @Override
51 | public void onBook(Player player) {
52 | // TODO
53 | }
54 |
55 | @Override
56 | public void onChat(CommandSender sender) {
57 | }
58 |
59 | @Override
60 | public void onChest(Player player) {
61 |
62 | Set months = plugin.getPreviousMonthsTopVoters().keySet();
63 |
64 | List yearMonthList = months.stream().sorted(Collections.reverseOrder()).collect(Collectors.toList());
65 | YearMonth yearMonth = null;
66 |
67 | if (index < 0) {
68 | if (!yearMonthList.isEmpty()) {
69 | yearMonth = yearMonthList.get(0);
70 | }
71 | player.sendMessage(ChatColor.RED + "Can't open previous months, no data");
72 | return;
73 | }
74 | if (yearMonthList.size() <= index) {
75 | player.sendMessage(ChatColor.RED + "Can't open previous months, no data for requested index");
76 | return;
77 | }
78 | yearMonth = yearMonthList.get(index);
79 |
80 | Set> users = null;
81 | if (!plugin.getPreviousMonthsTopVoters().containsKey(yearMonth)) {
82 | player.sendMessage(ChatColor.RED + "Can't open previous months, no data");
83 | return;
84 | }
85 | users = plugin.getPreviousMonthsTopVoters().get(yearMonth).entrySet();
86 |
87 | BInventory inv = new BInventory(plugin.getGui().getChestVoteTopName());
88 | inv.addPlaceholder("topvoter", yearMonth.toString());
89 | if (!plugin.getConfigFile().isAlwaysCloseInventory()) {
90 | inv.dontClose();
91 | }
92 |
93 | int pos = 1;
94 | for (Entry entry : users) {
95 | ItemBuilder playerItem;
96 |
97 | if (plugin.getGui().isChestVoteTopUseSkull()) {
98 | playerItem = new ItemBuilder(entry.getKey().getPlayerHead());
99 | } else {
100 | playerItem = new ItemBuilder(Material.valueOf(plugin.getGui().getChestVoteTopPlayerItemMaterial()));
101 | }
102 |
103 | playerItem.setLore(new ArrayList<>());
104 |
105 | inv.addButton(new BInventoryButton(playerItem.setName(plugin.getGui().getChestVoteTopItemName())
106 | .addLoreLine(plugin.getGui().getChestVoteTopItemLore()).addPlaceholder("position", "" + pos)
107 | .addPlaceholder("player", entry.getKey().getPlayerName())
108 | .addPlaceholder("votes", "" + entry.getValue())) {
109 |
110 | @Override
111 | public void onClick(ClickEvent clickEvent) {
112 | TopVoterPlayer user = (TopVoterPlayer) getData("User");
113 | new VoteGUI(plugin, player, user.getUser())
114 | .open(GUIMethod.valueOf(plugin.getGui().getGuiMethodGUI().toUpperCase()));
115 | }
116 | }.addData("player", entry.getKey().getPlayerName()).addData("User", entry.getKey()));
117 | pos++;
118 | }
119 |
120 | inv.getPageButtons().add(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestVoteTopSwitchItem())
121 | .addPlaceholder("Top", yearMonth.toString())) {
122 |
123 | @Override
124 | public void onClick(ClickEvent clickEvent) {
125 | if (!clickEvent.getClick().equals(ClickType.RIGHT)) {
126 | new VoteTopVoterPreviousMonths(plugin, player, user, index + 1).open(GUIMethod.CHEST);
127 | } else {
128 | new VoteTopVoterPreviousMonths(plugin, player, user, index - 1).open(GUIMethod.CHEST);
129 | }
130 | }
131 | });
132 |
133 | if (plugin.getGui().isChestVoteTopBackButton()) {
134 | inv.getPageButtons().add(plugin.getCommandLoader().getBackButton(user).setSlot(1));
135 | }
136 |
137 | inv.setPages(true);
138 | inv.setMaxInvSize(plugin.getGui().getChestVoteTopSize());
139 | inv.openInventory(player);
140 | }
141 |
142 | @Override
143 | public void open() {
144 | open(GUIMethod.CHEST);
145 | }
146 |
147 | }
148 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteTotal.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.gui.player;
2 |
3 | import java.util.ArrayList;
4 |
5 | import org.bukkit.command.CommandSender;
6 | import org.bukkit.entity.Player;
7 |
8 | import com.bencodez.advancedcore.api.gui.GUIHandler;
9 | import com.bencodez.advancedcore.api.gui.GUIMethod;
10 | import com.bencodez.advancedcore.api.inventory.BInventory;
11 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
12 | import com.bencodez.advancedcore.api.inventory.BInventoryButton;
13 | import com.bencodez.advancedcore.api.inventory.UpdatingBInventoryButton;
14 | import com.bencodez.advancedcore.api.item.ItemBuilder;
15 | import com.bencodez.advancedcore.api.rewards.RewardBuilder;
16 | import com.bencodez.simpleapi.array.ArrayUtils;
17 | import com.bencodez.simpleapi.messages.MessageAPI;
18 | import com.bencodez.votingplugin.VotingPluginMain;
19 | import com.bencodez.votingplugin.topvoter.TopVoter;
20 | import com.bencodez.votingplugin.user.VotingPluginUser;
21 |
22 | public class VoteTotal extends GUIHandler {
23 |
24 | private VotingPluginMain plugin;
25 | private VotingPluginUser user;
26 |
27 | public VoteTotal(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) {
28 | super(plugin, player);
29 | this.plugin = plugin;
30 | this.user = user;
31 | }
32 |
33 | @Override
34 | public ArrayList getChat(CommandSender arg0) {
35 | ArrayList msg = new ArrayList<>();
36 |
37 | int daily = user.getTotal(TopVoter.Daily);
38 | int weekly = user.getTotal(TopVoter.Weekly);
39 | int month = user.getTotal(TopVoter.Monthly);
40 | int all = user.getTotal(TopVoter.AllTime);
41 |
42 | for (String s : plugin.getConfigFile().getFormatCommandsVoteTotal()) {
43 | String str = MessageAPI.replaceIgnoreCase(s, "%DailyTotal%", "" + daily);
44 | str = MessageAPI.replaceIgnoreCase(str, "%WeeklyTotal%", "" + weekly);
45 | str = MessageAPI.replaceIgnoreCase(str, "%MonthlyTotal%", "" + month);
46 | str = MessageAPI.replaceIgnoreCase(str, "%AllTimeTotal%", "" + all);
47 | str = MessageAPI.replaceIgnoreCase(str, "%player%", user.getPlayerName());
48 | msg.add(str);
49 | }
50 |
51 | return ArrayUtils.colorize(msg);
52 | }
53 |
54 | @Override
55 | public void onBook(Player player) {
56 | // future release?
57 | }
58 |
59 | @Override
60 | public void onChat(CommandSender sender) {
61 | sendMessage(getChat(sender));
62 | }
63 |
64 | @Override
65 | public void onChest(Player player) {
66 | BInventory inv = new BInventory(plugin.getGui().getChestVoteTotalName());
67 | inv.addPlaceholder("player", user.getPlayerName());
68 |
69 | for (final TopVoter top : TopVoter.values()) {
70 | inv.addButton(new UpdatingBInventoryButton(plugin,
71 | new ItemBuilder(plugin.getGui().getChestVoteTotalItem(top))
72 | .addPlaceholder("Total", "" + user.getTotal(top)).addPlaceholder("topvoter", top.getName()),
73 | 1000, 1000) {
74 |
75 | @Override
76 | public void onClick(ClickEvent clickEvent) {
77 |
78 | }
79 |
80 | @Override
81 | public ItemBuilder onUpdate(Player arg0) {
82 | return new ItemBuilder(plugin.getGui().getChestVoteTotalItem(top))
83 | .addPlaceholder("Total", "" + user.getTotal(top)).addPlaceholder("topvoter", top.getName())
84 | .addPlaceholder("player", user.getPlayerName());
85 | }
86 | });
87 | }
88 |
89 | String guiPath = "VoteTotal";
90 | for (final String str : plugin.getGui().getChestGUIExtraItems(guiPath)) {
91 | inv.addButton(
92 | new BInventoryButton(new ItemBuilder(plugin.getGui().getChestGUIExtraItemsItem(guiPath, str))) {
93 |
94 | @Override
95 | public void onClick(ClickEvent clickEvent) {
96 | new RewardBuilder(plugin.getGui().getData(),
97 | "CHEST." + guiPath + ".ExtraItems." + str + "."
98 | + clickEvent.getButton().getLastRewardsPath(player))
99 | .setGiveOffline(false).send(clickEvent.getPlayer());
100 |
101 | }
102 | });
103 | }
104 |
105 | if (plugin.getGui().isChestVoteTotalBackButton()) {
106 | inv.addButton(plugin.getCommandLoader().getBackButton(user));
107 | }
108 | inv.openInventory(player);
109 | }
110 |
111 | @Override
112 | public void open() {
113 | open(GUIMethod.valueOf(plugin.getGui().getGuiMethodTotal().toUpperCase()));
114 | }
115 |
116 | }
117 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteURLVoteSite.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.gui.player;
2 |
3 | import java.util.ArrayList;
4 |
5 | import org.bukkit.Material;
6 | import org.bukkit.command.CommandSender;
7 | import org.bukkit.entity.Player;
8 |
9 | import com.bencodez.advancedcore.api.gui.GUIHandler;
10 | import com.bencodez.advancedcore.api.gui.GUIMethod;
11 | import com.bencodez.advancedcore.api.inventory.BInventory;
12 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
13 | import com.bencodez.advancedcore.api.inventory.BInventoryButton;
14 | import com.bencodez.advancedcore.api.inventory.UpdatingBInventoryButton;
15 | import com.bencodez.advancedcore.api.item.ItemBuilder;
16 | import com.bencodez.votingplugin.VotingPluginMain;
17 | import com.bencodez.votingplugin.objects.VoteSite;
18 | import com.bencodez.votingplugin.user.VotingPluginUser;
19 |
20 | public class VoteURLVoteSite extends GUIHandler {
21 |
22 | private VotingPluginMain plugin;
23 | private VotingPluginUser user;
24 | private String voteSite;
25 |
26 | public VoteURLVoteSite(VotingPluginMain plugin, CommandSender player, VotingPluginUser user, String voteSite) {
27 | super(plugin, player);
28 | this.plugin = plugin;
29 | this.user = user;
30 | this.voteSite = voteSite;
31 | }
32 |
33 | @Override
34 | public ArrayList getChat(CommandSender arg0) {
35 | // TODO Auto-generated method stub
36 | return null;
37 | }
38 |
39 | @Override
40 | public void onBook(Player player) {
41 |
42 | }
43 |
44 | @Override
45 | public void onChat(CommandSender sender) {
46 | }
47 |
48 | @Override
49 | public void onChest(Player player) {
50 | if (!plugin.isVoteSite(voteSite)) {
51 | player.sendMessage("Not a valid votesite");
52 | return;
53 | }
54 | VoteSite site = plugin.getVoteSite(voteSite, true);
55 | BInventory inv = new BInventory(plugin.getGui().getChestVoteURLSiteName());
56 | inv.addPlaceholder("site", site.getDisplayName());
57 | inv.setMeta(player, "VoteSite", site);
58 | if (!plugin.getConfigFile().isAlwaysCloseInventory()) {
59 | inv.dontClose();
60 | }
61 |
62 | inv.addButton(
63 | new BInventoryButton(new ItemBuilder(Material.BOW).setName("&4URL").addLoreLine("Click to see URL")) {
64 |
65 | @Override
66 | public void onClick(ClickEvent clickEvent) {
67 | VoteSite site = (VoteSite) clickEvent.getMeta("VoteSite");
68 | clickEvent.getWhoClicked().sendMessage(site.getVoteURL());
69 | }
70 | });
71 |
72 | inv.addButton(new UpdatingBInventoryButton(plugin,
73 | new ItemBuilder(Material.COMPASS).setName("&4Next Vote").addLoreLine(user.voteCommandNextInfo(site)),
74 | 1000, 1000) {
75 |
76 | @Override
77 | public void onClick(ClickEvent clickEvent) {
78 | new VoteURL(plugin, clickEvent.getPlayer(), user, true).open();
79 | }
80 |
81 | @Override
82 | public ItemBuilder onUpdate(Player arg0) {
83 | return new ItemBuilder(Material.COMPASS).setName("&4Next Vote")
84 | .addLoreLine(user.voteCommandNextInfo(site));
85 | }
86 | });
87 |
88 | inv.addButton(new BInventoryButton(
89 | new ItemBuilder(Material.CLOCK).setName("&4Last Vote").addLoreLine(user.voteCommandLastLine(site))) {
90 |
91 | @Override
92 | public void onClick(ClickEvent clickEvent) {
93 | new VoteURL(plugin, clickEvent.getPlayer(), user, true).open();
94 | }
95 | });
96 |
97 | if (plugin.getGui().isChestVoteURLBackButton()) {
98 | inv.addButton(plugin.getCommandLoader().getBackButton(user));
99 | }
100 | inv.openInventory(player);
101 |
102 | }
103 |
104 | @Override
105 | public void open() {
106 | open(GUIMethod.CHEST);
107 | }
108 |
109 | }
110 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/tabcompleter/AdminVoteTabCompleter.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.tabcompleter;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collections;
5 | import java.util.HashSet;
6 | import java.util.List;
7 | import java.util.Set;
8 |
9 | import org.bukkit.command.Command;
10 | import org.bukkit.command.CommandSender;
11 | import org.bukkit.command.TabCompleter;
12 |
13 | import com.bencodez.advancedcore.api.command.AdvancedCoreTabCompleteHandler;
14 | import com.bencodez.simpleapi.messages.MessageAPI;
15 | import com.bencodez.votingplugin.VotingPluginMain;
16 |
17 | /**
18 | * The Class AdminVoteTabCompleter.
19 | */
20 | public class AdminVoteTabCompleter implements TabCompleter {
21 |
22 | /** The plugin. */
23 | VotingPluginMain plugin = VotingPluginMain.plugin;
24 |
25 | /*
26 | * (non-Javadoc)
27 | *
28 | * @see org.bukkit.command.TabCompleter#onTabComplete(org.bukkit.command.
29 | * CommandSender, org.bukkit.command.Command, java.lang.String,
30 | * java.lang.String[])
31 | */
32 | @Override
33 | public List onTabComplete(CommandSender sender, Command cmd, String alias, String[] args) {
34 |
35 | List tab = new ArrayList<>();
36 |
37 | Set cmds = new HashSet<>();
38 |
39 | cmds.addAll(AdvancedCoreTabCompleteHandler.getInstance().getTabCompleteOptions(plugin.getAdminVoteCommand(),
40 | sender, args, args.length - 1));
41 |
42 | for (String str : cmds) {
43 | if (MessageAPI.startsWithIgnoreCase(str, args[args.length - 1])) {
44 | tab.add(str);
45 | }
46 | }
47 |
48 | Collections.sort(tab, String.CASE_INSENSITIVE_ORDER);
49 | return tab;
50 |
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/tabcompleter/AliasesTabCompleter.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.tabcompleter;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collections;
5 | import java.util.HashSet;
6 | import java.util.List;
7 | import java.util.Set;
8 | import java.util.concurrent.ConcurrentHashMap;
9 |
10 | import org.bukkit.command.Command;
11 | import org.bukkit.command.CommandSender;
12 | import org.bukkit.command.TabCompleter;
13 |
14 | import com.bencodez.advancedcore.api.command.CommandHandler;
15 | import com.bencodez.simpleapi.array.ArrayUtils;
16 | import com.bencodez.simpleapi.command.TabCompleteHandler;
17 | import com.bencodez.simpleapi.messages.MessageAPI;
18 | import com.bencodez.votingplugin.VotingPluginMain;
19 |
20 | /**
21 | * The Class AliasesTabCompleter.
22 | */
23 | public class AliasesTabCompleter implements TabCompleter {
24 |
25 | private boolean adminCommand;
26 |
27 | /** The cmd handle. */
28 | public CommandHandler cmdHandle;
29 |
30 | /** The plugin. */
31 | VotingPluginMain plugin = VotingPluginMain.plugin;
32 |
33 | /*
34 | * (non-Javadoc)
35 | *
36 | * @see org.bukkit.command.TabCompleter#onTabComplete(org.bukkit.command.
37 | * CommandSender, org.bukkit.command.Command, java.lang.String,
38 | * java.lang.String[])
39 | */
40 | @Override
41 | public List onTabComplete(CommandSender sender, Command cmd, String alias, String[] argsIn) {
42 | ArrayList msgArray = new ArrayList<>();
43 | msgArray.add("");
44 | for (String arg : argsIn) {
45 | msgArray.add(arg);
46 | }
47 |
48 | String[] args = ArrayUtils.convert(msgArray);
49 |
50 | ArrayList tab = new ArrayList<>();
51 |
52 | Set cmds = new HashSet<>();
53 |
54 | ArrayList cmdHandlers = new ArrayList<>();
55 |
56 | if (adminCommand) {
57 | cmdHandlers.addAll(plugin.getAdminVoteCommand());
58 | } else {
59 | cmdHandlers.addAll(plugin.getVoteCommand());
60 | }
61 | ConcurrentHashMap> tabCompletes = TabCompleteHandler.getInstance()
62 | .getTabCompleteOptions();
63 | for (CommandHandler cmdHandle : cmdHandlers) {
64 | if (cmdHandle.getArgs().length >= argsIn.length) {
65 | for (String arg : cmdHandle.getArgs()[0].split("&")) {
66 | if (cmd.getName().equalsIgnoreCase("vote" + arg)
67 | || cmd.getName().equalsIgnoreCase("adminvote" + arg)) {
68 | // plugin.debug("Found cmd... attempting to get tab
69 | // complete");
70 | args[0] = arg;
71 | boolean argsMatch = true;
72 | for (int i = 0; i < argsIn.length; i++) {
73 | if (args.length >= i) {
74 | if (!cmdHandle.argsMatch(args[i], i)) {
75 | argsMatch = false;
76 | }
77 | }
78 | }
79 |
80 | if (argsMatch) {
81 |
82 | cmds.addAll(cmdHandle.getTabCompleteOptions(sender, args, argsIn.length, tabCompletes));
83 | }
84 |
85 | }
86 | }
87 | }
88 | }
89 |
90 | for (String str : cmds) {
91 | if (MessageAPI.startsWithIgnoreCase(str, args[args.length - 1])) {
92 | tab.add(str);
93 | }
94 | }
95 |
96 | Collections.sort(tab, String.CASE_INSENSITIVE_ORDER);
97 |
98 | return tab;
99 | }
100 |
101 | public AliasesTabCompleter setCMDHandle(CommandHandler cmd, boolean adminCommand) {
102 | cmdHandle = cmd;
103 | this.adminCommand = adminCommand;
104 | return this;
105 | }
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/tabcompleter/VoteTabCompleter.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.commands.tabcompleter;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collections;
5 | import java.util.HashSet;
6 | import java.util.List;
7 | import java.util.Set;
8 |
9 | import org.bukkit.command.Command;
10 | import org.bukkit.command.CommandSender;
11 | import org.bukkit.command.TabCompleter;
12 |
13 | import com.bencodez.advancedcore.api.command.AdvancedCoreTabCompleteHandler;
14 | import com.bencodez.simpleapi.messages.MessageAPI;
15 | import com.bencodez.votingplugin.VotingPluginMain;
16 |
17 | // TODO: Auto-generated Javadoc
18 | /**
19 | * The Class VoteTabCompleter.
20 | */
21 | public class VoteTabCompleter implements TabCompleter {
22 |
23 | /** The plugin. */
24 | VotingPluginMain plugin = VotingPluginMain.plugin;
25 |
26 | /*
27 | * (non-Javadoc)
28 | *
29 | * @see org.bukkit.command.TabCompleter#onTabComplete(org.bukkit.command.
30 | * CommandSender, org.bukkit.command.Command, java.lang.String,
31 | * java.lang.String[])
32 | */
33 | @Override
34 | public List onTabComplete(CommandSender sender, Command cmd, String alias, String[] args) {
35 |
36 | ArrayList tab = new ArrayList<>();
37 |
38 | Set cmds = new HashSet<>();
39 |
40 | cmds.addAll(AdvancedCoreTabCompleteHandler.getInstance().getTabCompleteOptions(plugin.getVoteCommand(), sender,
41 | args, args.length - 1));
42 |
43 | for (String str : cmds) {
44 | if (MessageAPI.startsWithIgnoreCase(str, args[args.length - 1])) {
45 | tab.add(str);
46 | }
47 | }
48 |
49 | Collections.sort(tab, String.CASE_INSENSITIVE_ORDER);
50 |
51 | return tab;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/config/BungeeSettings.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.config;
2 |
3 | import java.io.File;
4 | import java.util.ArrayList;
5 |
6 | import com.bencodez.simpleapi.file.YMLFile;
7 | import com.bencodez.simpleapi.file.annotation.AnnotationHandler;
8 | import com.bencodez.simpleapi.file.annotation.ConfigDataBoolean;
9 | import com.bencodez.simpleapi.file.annotation.ConfigDataInt;
10 | import com.bencodez.simpleapi.file.annotation.ConfigDataListString;
11 | import com.bencodez.simpleapi.file.annotation.ConfigDataString;
12 | import com.bencodez.votingplugin.VotingPluginMain;
13 |
14 | import lombok.Getter;
15 |
16 | public class BungeeSettings extends YMLFile {
17 |
18 | @ConfigDataBoolean(path = "BungeeBroadcast")
19 | @Getter
20 | private boolean bungeeBroadcast = false;
21 |
22 | @ConfigDataBoolean(path = "BungeeBroadcastAlways")
23 | @Getter
24 | private boolean bungeeBroadcastAlways = false;
25 |
26 | @ConfigDataBoolean(path = "BungeeDebug")
27 | @Getter
28 | private boolean bungeeDebug = false;
29 |
30 | @ConfigDataString(path = "BungeeMethod")
31 | @Getter
32 | private String bungeeMethod = "PLUGINMESSAGING";
33 |
34 | @ConfigDataString(path = "Redis.Host")
35 | @Getter
36 | private String RedisHost = "";
37 |
38 | @ConfigDataString(path = "Redis.Username")
39 | @Getter
40 | private String RedisUsername = "";
41 |
42 | @ConfigDataString(path = "PluginMessageChannel")
43 | @Getter
44 | private String pluginMessagingChannel = "vp:vp";
45 |
46 | @ConfigDataBoolean(path = "PluginMessageEncryption")
47 | @Getter
48 | private boolean pluginMessageEncryption = false;
49 |
50 | @ConfigDataString(path = "Redis.Prefix")
51 | @Getter
52 | private String RedisPrefix = "";
53 |
54 | @ConfigDataString(path = "Redis.Password")
55 | @Getter
56 | private String RedisPassword = "";
57 |
58 | @ConfigDataInt(path = "Redis.Port")
59 | @Getter
60 | private int RedisPort = 6379;
61 |
62 | @ConfigDataString(path = "MQTT.ClientID")
63 | @Getter
64 | private String mqttClientID = "";
65 |
66 | @ConfigDataString(path = "MQTT.BrokerURL")
67 | @Getter
68 | private String mqttBrokerURL = "tcp://localhost:1883";
69 |
70 | @ConfigDataString(path = "MQTT.Username")
71 | @Getter
72 | private String mqttUsername = "";
73 |
74 | @ConfigDataString(path = "MQTT.Password")
75 | @Getter
76 | private String mqttPassword = "";
77 |
78 | @ConfigDataString(path = "MQTT.Prefix")
79 | @Getter
80 | private String mqttPrefix = "";
81 |
82 | @ConfigDataString(path = "BungeeServer.Host")
83 | @Getter
84 | private String bungeeServerHost = "";
85 |
86 | @ConfigDataInt(path = "BungeeServer.Port")
87 | @Getter
88 | private int bungeeServerPort = 1297;
89 |
90 | @ConfigDataBoolean(path = "PerServerPoints")
91 | @Getter
92 | private boolean perServerPoints = false;
93 |
94 | @ConfigDataBoolean(path = "PerServerMilestones")
95 | @Getter
96 | private boolean perServerMilestones = false;
97 |
98 | @ConfigDataBoolean(path = "GiveExtraAllSitesRewards")
99 | @Getter
100 | private boolean giveExtraAllSitesRewards = false;
101 |
102 | @ConfigDataBoolean(path = "PerServerRewards")
103 | @Getter
104 | private boolean perServerRewards = false;
105 |
106 | @ConfigDataBoolean(path = "RemoveInvalidUsers")
107 | @Getter
108 | private boolean removeInvalidUsers = false;
109 |
110 | @ConfigDataString(path = "Server")
111 | @Getter
112 | private String server = "PleaseSet";
113 |
114 | @ConfigDataString(path = "SpigotServer.Host")
115 | @Getter
116 | private String spigotServerHost = "";
117 |
118 | @ConfigDataInt(path = "SpigotServer.Port")
119 | @Getter
120 | private int spigotServerPort = 1298;
121 |
122 | @ConfigDataBoolean(path = "TriggerVotifierEvent")
123 | @Getter
124 | private boolean triggerVotifierEvent = false;
125 |
126 | @ConfigDataBoolean(path = "UseBungeecord", secondPath = "UseBungeecoord")
127 | @Getter
128 | private boolean useBungeecoord = false;
129 |
130 | @ConfigDataBoolean(path = "VotifierBypass")
131 | @Getter
132 | private boolean votifierBypass = false;
133 |
134 | @ConfigDataBoolean(path = "DisableBroadcast")
135 | @Getter
136 | private boolean disableBroadcast = false;
137 |
138 | @ConfigDataBoolean(path = "GlobalData.UseMainMySQL")
139 | @Getter
140 | private boolean globlalDataUseMainMySQL = true;
141 |
142 | @ConfigDataBoolean(path = "GlobalData.Enabled")
143 | @Getter
144 | private boolean globlalDataEnabled = false;
145 |
146 | @ConfigDataListString(path = "BungeeVotePartyGlobalCommands")
147 | @Getter
148 | private ArrayList bungeeVotePartyGlobalCommands = new ArrayList<>();
149 |
150 | public BungeeSettings(VotingPluginMain plugin) {
151 | super(plugin, new File(plugin.getDataFolder(), "BungeeSettings.yml"));
152 | }
153 |
154 | public String getServerNameStorage() {
155 | return getServer().replace("-", "_");
156 | }
157 |
158 | @Override
159 | public void loadValues() {
160 | new AnnotationHandler().load(getData(), this);
161 | }
162 |
163 | @Override
164 | public void onFileCreation() {
165 | getPlugin().saveResource("BungeeSettings.yml", true);
166 | }
167 | }
168 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerPostVoteEvent.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.events;
2 |
3 | import org.bukkit.event.Event;
4 | import org.bukkit.event.HandlerList;
5 |
6 | import com.bencodez.votingplugin.objects.VoteSite;
7 | import com.bencodez.votingplugin.proxy.BungeeMessageData;
8 | import com.bencodez.votingplugin.user.VotingPluginUser;
9 |
10 | import lombok.Getter;
11 | import lombok.Setter;
12 |
13 | // TODO: Auto-generated Javadoc
14 | /**
15 | * The Class PlayerVoteEvent.
16 | */
17 | public class PlayerPostVoteEvent extends Event {
18 |
19 | /** The Constant handlers. */
20 | private static final HandlerList handlers = new HandlerList();
21 |
22 | /**
23 | * Gets the handler list.
24 | *
25 | * @return the handler list
26 | */
27 | public static HandlerList getHandlerList() {
28 | return handlers;
29 | }
30 |
31 | @Getter
32 | @Setter
33 | private boolean bungee = false;
34 |
35 | @Getter
36 | @Setter
37 | private BungeeMessageData bungeeTextTotals;
38 |
39 | @Getter
40 | @Setter
41 | private boolean cancelled;
42 |
43 | @Getter
44 | @Setter
45 | private boolean forceBungee = false;
46 |
47 | @Getter
48 | @Setter
49 | private VotingPluginUser user;
50 |
51 | @Getter
52 | @Setter
53 | private boolean realVote = true;
54 |
55 | @Getter
56 | @Setter
57 | private VoteSite voteSite;
58 |
59 | @Getter
60 | @Setter
61 | private long voteTime = 0;
62 |
63 | @Getter
64 | @Setter
65 | private VotingPluginUser votingPluginUser;
66 |
67 | public PlayerPostVoteEvent(VoteSite voteSite, VotingPluginUser user, boolean realVote, boolean forceBungee,
68 | long voteTime) {
69 | super(true);
70 | this.user = user;
71 | this.voteSite = voteSite;
72 | this.realVote = realVote;
73 | this.forceBungee = forceBungee;
74 | this.voteTime = voteTime;
75 | }
76 |
77 | /*
78 | * (non-Javadoc)
79 | *
80 | * @see org.bukkit.event.Event#getHandlers()
81 | */
82 | @Override
83 | public HandlerList getHandlers() {
84 | return handlers;
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerReceivePointsEvent.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.events;
2 |
3 | import org.bukkit.event.Event;
4 | import org.bukkit.event.HandlerList;
5 |
6 | import com.bencodez.votingplugin.user.VotingPluginUser;
7 |
8 | import lombok.Getter;
9 | import lombok.Setter;
10 |
11 | // TODO: Auto-generated Javadoc
12 | /**
13 | * The Class PlayerVoteEvent.
14 | */
15 | public class PlayerReceivePointsEvent extends Event {
16 |
17 | /** The Constant handlers. */
18 | private static final HandlerList handlers = new HandlerList();
19 |
20 | /**
21 | * Gets the handler list.
22 | *
23 | * @return the handler list
24 | */
25 | public static HandlerList getHandlerList() {
26 | return handlers;
27 | }
28 |
29 | @Getter
30 | @Setter
31 | private boolean cancelled;
32 |
33 | @Getter
34 | @Setter
35 | private VotingPluginUser player;
36 |
37 | @Getter
38 | @Setter
39 | private int points;
40 |
41 | @Getter
42 | @Setter
43 | private String serviceSite = "";
44 |
45 | public PlayerReceivePointsEvent(VotingPluginUser user, int points) {
46 | super(true);
47 | this.player = user;
48 | this.points = points;
49 | }
50 |
51 | /*
52 | * (non-Javadoc)
53 | *
54 | * @see org.bukkit.event.Event#getHandlers()
55 | */
56 | @Override
57 | public HandlerList getHandlers() {
58 | return handlers;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerSpecialRewardEvent.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.events;
2 |
3 | import org.bukkit.event.Event;
4 | import org.bukkit.event.HandlerList;
5 |
6 | import com.bencodez.votingplugin.user.VotingPluginUser;
7 |
8 | import lombok.Getter;
9 | import lombok.Setter;
10 |
11 | // TODO: Auto-generated Javadoc
12 | /**
13 | * The Class PlayerVoteEvent.
14 | */
15 | public class PlayerSpecialRewardEvent extends Event {
16 |
17 | /** The Constant handlers. */
18 | private static final HandlerList handlers = new HandlerList();
19 |
20 | /**
21 | * Gets the handler list.
22 | *
23 | * @return the handler list
24 | */
25 | public static HandlerList getHandlerList() {
26 | return handlers;
27 | }
28 |
29 | @Getter
30 | @Setter
31 | private boolean cancelled;
32 |
33 | @Getter
34 | @Setter
35 | private SpecialRewardType type;
36 |
37 | @Getter
38 | @Setter
39 | private VotingPluginUser user;
40 |
41 | public PlayerSpecialRewardEvent(VotingPluginUser user, SpecialRewardType type) {
42 | super(true);
43 | this.type = type;
44 | this.user = user;
45 | }
46 |
47 | /*
48 | * (non-Javadoc)
49 | *
50 | * @see org.bukkit.event.Event#getHandlers()
51 | */
52 | @Override
53 | public HandlerList getHandlers() {
54 | return handlers;
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerVoteCoolDownEndEvent.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.events;
2 |
3 | import org.bukkit.event.Event;
4 | import org.bukkit.event.HandlerList;
5 |
6 | import com.bencodez.votingplugin.user.VotingPluginUser;
7 |
8 | import lombok.Getter;
9 | import lombok.Setter;
10 |
11 | // TODO: Auto-generated Javadoc
12 | /**
13 | * The Class PlayerVoteEvent.
14 | */
15 | public class PlayerVoteCoolDownEndEvent extends Event {
16 |
17 | /** The Constant handlers. */
18 | private static final HandlerList handlers = new HandlerList();
19 |
20 | /**
21 | * Gets the handler list.
22 | *
23 | * @return the handler list
24 | */
25 | public static HandlerList getHandlerList() {
26 | return handlers;
27 | }
28 |
29 | @Getter
30 | @Setter
31 | private boolean cancelled;
32 |
33 | @Getter
34 | @Setter
35 | private VotingPluginUser player;
36 |
37 | public PlayerVoteCoolDownEndEvent(VotingPluginUser user) {
38 | super(true);
39 | player = user;
40 | }
41 |
42 | /*
43 | * (non-Javadoc)
44 | *
45 | * @see org.bukkit.event.Event#getHandlers()
46 | */
47 | @Override
48 | public HandlerList getHandlers() {
49 | return handlers;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerVoteEvent.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.events;
2 |
3 | import org.bukkit.event.Event;
4 | import org.bukkit.event.HandlerList;
5 |
6 | import com.bencodez.votingplugin.objects.VoteSite;
7 | import com.bencodez.votingplugin.proxy.BungeeMessageData;
8 | import com.bencodez.votingplugin.user.VotingPluginUser;
9 |
10 | import lombok.Getter;
11 | import lombok.Setter;
12 |
13 | // TODO: Auto-generated Javadoc
14 | /**
15 | * The Class PlayerVoteEvent.
16 | */
17 | public class PlayerVoteEvent extends Event {
18 |
19 | /** The Constant handlers. */
20 | private static final HandlerList handlers = new HandlerList();
21 |
22 | /**
23 | * Gets the handler list.
24 | *
25 | * @return the handler list
26 | */
27 | public static HandlerList getHandlerList() {
28 | return handlers;
29 | }
30 |
31 | @Getter
32 | @Setter
33 | private boolean addTotals = true;
34 |
35 | @Getter
36 | @Setter
37 | private boolean bungee = false;
38 |
39 | @Getter
40 | @Setter
41 | private BungeeMessageData bungeeTextTotals;
42 |
43 | @Getter
44 | @Setter
45 | private boolean cancelled;
46 |
47 | @Getter
48 | @Setter
49 | private boolean forceBungee = false;
50 |
51 | @Getter
52 | @Setter
53 | private String player;
54 |
55 | @Getter
56 | @Setter
57 | private boolean realVote = true;
58 |
59 | @Getter
60 | @Setter
61 | private String serviceSite = "";
62 |
63 | @Getter
64 | @Setter
65 | private long time;
66 |
67 | @Getter
68 | @Setter
69 | private VoteSite voteSite;
70 |
71 | @Getter
72 | @Setter
73 | private VotingPluginUser votingPluginUser;
74 |
75 | @Getter
76 | @Setter
77 | private boolean wasOnline;
78 |
79 | @Getter
80 | @Setter
81 | private boolean broadcast = true;
82 |
83 | @Getter
84 | @Setter
85 | private int voteNumber = 1;
86 |
87 | public PlayerVoteEvent(VoteSite voteSite, String voteUsername, String serviceSite, boolean realVote) {
88 | super(true);
89 | this.player = voteUsername;
90 | this.voteSite = voteSite;
91 | this.realVote = realVote;
92 | this.serviceSite = serviceSite;
93 | }
94 |
95 | /*
96 | * (non-Javadoc)
97 | *
98 | * @see org.bukkit.event.Event#getHandlers()
99 | */
100 | @Override
101 | public HandlerList getHandlers() {
102 | return handlers;
103 | }
104 |
105 | }
106 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerVoteSiteCoolDownEndEvent.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.events;
2 |
3 | import org.bukkit.event.Event;
4 | import org.bukkit.event.HandlerList;
5 |
6 | import com.bencodez.votingplugin.objects.VoteSite;
7 | import com.bencodez.votingplugin.user.VotingPluginUser;
8 |
9 | import lombok.Getter;
10 | import lombok.Setter;
11 |
12 | // TODO: Auto-generated Javadoc
13 | /**
14 | * The Class PlayerVoteEvent.
15 | */
16 | public class PlayerVoteSiteCoolDownEndEvent extends Event {
17 |
18 | /** The Constant handlers. */
19 | private static final HandlerList handlers = new HandlerList();
20 |
21 | /**
22 | * Gets the handler list.
23 | *
24 | * @return the handler list
25 | */
26 | public static HandlerList getHandlerList() {
27 | return handlers;
28 | }
29 |
30 | @Getter
31 | @Setter
32 | private boolean cancelled;
33 |
34 | @Getter
35 | @Setter
36 | private VotingPluginUser player;
37 |
38 | @Getter
39 | @Setter
40 | private VoteSite site;
41 |
42 | public PlayerVoteSiteCoolDownEndEvent(VotingPluginUser user, VoteSite site) {
43 | super(true);
44 | player = user;
45 | this.site = site;
46 | }
47 |
48 | /*
49 | * (non-Javadoc)
50 | *
51 | * @see org.bukkit.event.Event#getHandlers()
52 | */
53 | @Override
54 | public HandlerList getHandlers() {
55 | return handlers;
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/SpecialRewardType.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.events;
2 |
3 | import lombok.Getter;
4 |
5 | public enum SpecialRewardType {
6 | ALLSITE, CUMMULATIVE, FIRSTVOTE, FIRSTVOTETODAY, MILESTONE, VOTESTREAK, ALMOSTALLSITES;
7 |
8 | @Getter
9 | private int amount = -1;
10 |
11 | @Getter
12 | private String type = "";
13 |
14 | public SpecialRewardType setAmount(int num) {
15 | amount = num;
16 | return this;
17 | }
18 |
19 | public SpecialRewardType setType(String type) {
20 | this.type = type;
21 | return this;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/VotePartyEvent.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.events;
2 |
3 | import org.bukkit.event.Event;
4 | import org.bukkit.event.HandlerList;
5 |
6 | import lombok.Getter;
7 | import lombok.Setter;
8 |
9 | // TODO: Auto-generated Javadoc
10 | /**
11 | * The Class PlayerVoteEvent.
12 | */
13 | public class VotePartyEvent extends Event {
14 |
15 | /** The Constant handlers. */
16 | private static final HandlerList handlers = new HandlerList();
17 |
18 | /**
19 | * Gets the handler list.
20 | *
21 | * @return the handler list
22 | */
23 | public static HandlerList getHandlerList() {
24 | return handlers;
25 | }
26 |
27 | @Getter
28 | @Setter
29 | private boolean cancelled;
30 |
31 | public VotePartyEvent() {
32 | super(true);
33 | }
34 |
35 | /*
36 | * (non-Javadoc)
37 | *
38 | * @see org.bukkit.event.Event#getHandlers()
39 | */
40 | @Override
41 | public HandlerList getHandlers() {
42 | return handlers;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/listeners/BlockBreak.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.listeners;
2 |
3 | import org.bukkit.Location;
4 | import org.bukkit.block.Sign;
5 | import org.bukkit.event.EventHandler;
6 | import org.bukkit.event.EventPriority;
7 | import org.bukkit.event.Listener;
8 | import org.bukkit.event.block.BlockBreakEvent;
9 |
10 | import com.bencodez.votingplugin.VotingPluginMain;
11 | import com.bencodez.votingplugin.signs.SignHandler;
12 |
13 | // TODO: Auto-generated Javadoc
14 | /**
15 | * The Class BlockBreak.
16 | */
17 | public class BlockBreak implements Listener {
18 |
19 | /** The plugin. */
20 | private VotingPluginMain plugin;
21 |
22 | /**
23 | * Instantiates a new block break.
24 | *
25 | * @param plugin the plugin
26 | */
27 | public BlockBreak(VotingPluginMain plugin) {
28 | this.plugin = plugin;
29 | }
30 |
31 | /**
32 | * On block break.
33 | *
34 | * @param event the event
35 | */
36 | @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
37 | public void onBlockBreak(BlockBreakEvent event) {
38 | if (event.getBlock().getState() instanceof Sign) {
39 | Sign s = (Sign) event.getBlock().getState();
40 | final Location loc = s.getLocation();
41 | plugin.getBukkitScheduler().runTaskAsynchronously(plugin, new Runnable() {
42 |
43 | @Override
44 | public void run() {
45 | for (SignHandler sign : plugin.getSigns().getSigns()) {
46 | if (sign.getLocation().equals(loc)) {
47 | sign.removeSign();
48 | sign.setValid(false);
49 | }
50 | }
51 | }
52 | });
53 | }
54 |
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/listeners/BungeeVotifierEvent.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.listeners;
2 |
3 | import com.bencodez.votingplugin.VotingPluginMain;
4 | import com.bencodez.votingplugin.events.PlayerVoteEvent;
5 | import com.vexsoftware.votifier.model.Vote;
6 | import com.vexsoftware.votifier.model.VotifierEvent;
7 |
8 | public class BungeeVotifierEvent {
9 | public void send(VotingPluginMain plugin, PlayerVoteEvent event) {
10 | plugin.debug("Triggering vote event");
11 | plugin.getBukkitScheduler().runTask(plugin, new Runnable() {
12 |
13 | @Override
14 | public void run() {
15 | VotifierEvent e = new VotifierEvent(
16 | new Vote(event.getServiceSite(), event.getPlayer(), "VotingPlugin", "" + event.getTime()));
17 | plugin.getServer().getPluginManager().callEvent(e);
18 | }
19 | });
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/listeners/PlayerInteract.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.listeners;
2 |
3 | import org.bukkit.block.Sign;
4 | import org.bukkit.block.Skull;
5 | import org.bukkit.entity.Player;
6 | import org.bukkit.event.EventHandler;
7 | import org.bukkit.event.EventPriority;
8 | import org.bukkit.event.Listener;
9 | import org.bukkit.event.block.Action;
10 | import org.bukkit.event.player.PlayerInteractEvent;
11 |
12 | import com.bencodez.advancedcore.api.misc.PlayerManager;
13 | import com.bencodez.simpleapi.player.PlayerUtils;
14 | import com.bencodez.votingplugin.VotingPluginMain;
15 | import com.bencodez.votingplugin.signs.SignHandler;
16 |
17 | // TODO: Auto-generated Javadoc
18 | /**
19 | * The Class PlayerInteract.
20 | */
21 | public class PlayerInteract implements Listener {
22 |
23 | /** The plugin. */
24 | private VotingPluginMain plugin;
25 |
26 | /**
27 | * Instantiates a new player interact.
28 | *
29 | * @param plugin the plugin
30 | */
31 | public PlayerInteract(VotingPluginMain plugin) {
32 | this.plugin = plugin;
33 | }
34 |
35 | /**
36 | * On player interact.
37 | *
38 | * @param event the event
39 | */
40 | @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
41 | public void onPlayerInteract(PlayerInteractEvent event) {
42 | if (plugin.getConfigFile().isDisableInteractEvent()) {
43 | return;
44 | }
45 | if (plugin.getSigns().getSigns().size() > 0) {
46 | Player player = event.getPlayer();
47 | if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
48 | // plugin.debug("Checking for sign click");
49 | if (event.getClickedBlock().getState() instanceof Sign) {
50 | // plugin.debug(player.getName() + " right clicked a sign");
51 | for (SignHandler sign : plugin.getSigns().getSigns()) {
52 | if (sign.isLocationSame(event.getClickedBlock().getLocation())) {
53 | // plugin.debug(player.getName() +
54 | // " right clicked a top voter sign, sending message");
55 | plugin.getVotingPluginUserManager().getVotingPluginUser(player)
56 | .sendMessage(sign.getRightClickMessage());
57 |
58 | if (!sign.isSkullSet()) {
59 | if (PlayerManager.getInstance().hasServerPermission(event.getPlayer().getName(),
60 | "VotingPlugin.Sign.Create")
61 | || PlayerManager.getInstance().hasServerPermission(event.getPlayer().getName(),
62 | "VotingPlugin.Admin")) {
63 | player.sendMessage("Skull not set, click to set skull");
64 | PlayerUtils.setPlayerMeta(plugin, player, "skullset", sign.getSign());
65 | }
66 | }
67 | }
68 | }
69 |
70 | } else if (event.getClickedBlock().getState() instanceof Skull) {
71 | Object ob = PlayerUtils.getPlayerMeta(plugin, player, "skullset");
72 | if (ob != null) {
73 | String sign1 = (String) ob;
74 | for (SignHandler sign : plugin.getSigns().getSigns()) {
75 | if (sign.getSign().equals(sign1)) {
76 | sign.setSkullLocation(event.getClickedBlock().getLocation());
77 | sign.storeSign();
78 | sign.checkSkulls();
79 | player.sendMessage("Skull set");
80 | }
81 | }
82 | PlayerUtils.setPlayerMeta(plugin, player, "skullset", null);
83 | }
84 | }
85 | }
86 |
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/listeners/PlayerJoinEvent.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.listeners;
2 |
3 | import org.bukkit.entity.Player;
4 | import org.bukkit.event.EventHandler;
5 | import org.bukkit.event.EventPriority;
6 | import org.bukkit.event.Listener;
7 | import org.bukkit.event.player.PlayerQuitEvent;
8 |
9 | import com.bencodez.advancedcore.listeners.AdvancedCoreLoginEvent;
10 | import com.bencodez.votingplugin.VotingPluginMain;
11 | import com.bencodez.votingplugin.user.VotingPluginUser;
12 |
13 | // TODO: Auto-generated Javadoc
14 | /**
15 | * The Class PlayerJoinEvent.
16 | */
17 | public class PlayerJoinEvent implements Listener {
18 |
19 | /** The plugin. */
20 | private VotingPluginMain plugin;
21 |
22 | /**
23 | * Instantiates a new player join event.
24 | *
25 | * @param plugin the plugin
26 | */
27 | public PlayerJoinEvent(VotingPluginMain plugin) {
28 | this.plugin = plugin;
29 | }
30 |
31 | private void login(Player player) {
32 | VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(player);
33 | if (player.isOp() && plugin.isYmlError()) {
34 | user.sendMessage("&cVotingPlugin: Detected yml error, please check console for details");
35 | }
36 |
37 | boolean data = user.getData().hasData();
38 | // run remind
39 | user.loginMessage();
40 |
41 | if (data) {
42 | // give offline vote (if they voted offline)
43 | user.offVote();
44 | } else {
45 | plugin.debug("No data detected for " + player.getUniqueId().toString() + "/" + player.getName());
46 | }
47 |
48 | user.loginRewards();
49 |
50 | plugin.getPlaceholders().onUpdate(user, true);
51 |
52 | if (plugin.getBungeeSettings().isUseBungeecoord()) {
53 | plugin.getBungeeHandler().getGlobalMessageHandler().sendMessage("Login", user.getPlayerName(),
54 | user.getUUID(), plugin.getBungeeSettings().getServer());
55 | }
56 | }
57 |
58 | /**
59 | * On player login.
60 | *
61 | * @param event the event
62 | */
63 | @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
64 | public void onPlayerLogin(AdvancedCoreLoginEvent event) {
65 | if (event.getPlayer() == null || !plugin.isMySQLOkay()) {
66 | return;
67 | }
68 |
69 | login(event.getPlayer());
70 |
71 | }
72 |
73 | @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
74 | public void onPlayerQuit(PlayerQuitEvent event) {
75 | if (plugin != null && plugin.isEnabled()) {
76 | final Player player = event.getPlayer();
77 | plugin.getLoginTimer().execute(new Runnable() {
78 |
79 | @Override
80 | public void run() {
81 | VotingPluginMain.plugin.getAdvancedTab().remove(player.getUniqueId());
82 |
83 | VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(player);
84 | user.dontCache();
85 | user.logoutRewards();
86 | plugin.getPlaceholders().onLogout(user);
87 | }
88 | });
89 | }
90 | }
91 | }
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/listeners/SignChange.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.listeners;
2 |
3 | import org.bukkit.event.EventHandler;
4 | import org.bukkit.event.Listener;
5 | import org.bukkit.event.block.SignChangeEvent;
6 |
7 | import com.bencodez.advancedcore.api.misc.PlayerManager;
8 | import com.bencodez.simpleapi.messages.MessageAPI;
9 | import com.bencodez.votingplugin.VotingPluginMain;
10 |
11 | // TODO: Auto-generated Javadoc
12 | /**
13 | * The Class SignChange.
14 | */
15 | public class SignChange implements Listener {
16 |
17 | /** The plugin. */
18 | private VotingPluginMain plugin;
19 |
20 | /**
21 | * Instantiates a new sign change.
22 | *
23 | * @param plugin the plugin
24 | */
25 | public SignChange(VotingPluginMain plugin) {
26 | this.plugin = plugin;
27 | }
28 |
29 | /**
30 | * On sign change.
31 | *
32 | * @param event the event
33 | */
34 | @EventHandler(ignoreCancelled = true)
35 | public void onSignChange(SignChangeEvent event) {
36 | if (event.getLine(0).equalsIgnoreCase("[VotingPlugin]")) {
37 | if (PlayerManager.getInstance().hasServerPermission(event.getPlayer().getName(), "VotingPlugin.Sign.Create")
38 | || PlayerManager.getInstance().hasServerPermission(event.getPlayer().getName(),
39 | "VotingPlugin.Admin")) {
40 | String data = event.getLine(2);
41 | if (!data.equalsIgnoreCase("all") && !data.equalsIgnoreCase("monthly")
42 | && !data.equalsIgnoreCase("weekly") && !data.equalsIgnoreCase("daily")) {
43 | return;
44 | }
45 | try {
46 | plugin.getServerData().addSign(event.getBlock().getLocation(), event.getLine(2),
47 | Integer.parseInt(event.getLine(1)));
48 | event.getPlayer().sendMessage(MessageAPI.colorize("&aAdded sign!"));
49 | plugin.getBukkitScheduler().runTaskAsynchronously(plugin, new Runnable() {
50 |
51 | @Override
52 | public void run() {
53 | plugin.getSigns().updateSigns();
54 | plugin.getSigns().storeSigns();
55 | }
56 | });
57 | } catch (Exception ex) {
58 | event.getPlayer().sendMessage(MessageAPI.colorize("&cError on sign creation!"));
59 | ex.printStackTrace();
60 | }
61 | } else {
62 | event.getPlayer().sendMessage(MessageAPI.colorize(plugin.getConfigFile().getFormatNoPerms()));
63 | }
64 | }
65 |
66 | }
67 |
68 | }
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/listeners/VotiferEvent.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.listeners;
2 |
3 | import java.util.ArrayList;
4 |
5 | import org.bukkit.event.EventHandler;
6 | import org.bukkit.event.EventPriority;
7 | import org.bukkit.event.Listener;
8 |
9 | import com.bencodez.simpleapi.array.ArrayUtils;
10 | import com.bencodez.votingplugin.VotingPluginMain;
11 | import com.bencodez.votingplugin.events.PlayerVoteEvent;
12 | import com.bencodez.votingplugin.proxy.BungeeMethod;
13 | import com.vexsoftware.votifier.model.Vote;
14 | import com.vexsoftware.votifier.model.VotifierEvent;
15 |
16 | // TODO: Auto-generated Javadoc
17 | /**
18 | * The Class VotiferEvent.
19 | */
20 | public class VotiferEvent implements Listener {
21 |
22 | /** The plugin. */
23 | private VotingPluginMain plugin;
24 |
25 | /**
26 | * Instantiates a new votifer event.
27 | *
28 | * @param plugin the plugin
29 | */
30 | public VotiferEvent(VotingPluginMain plugin) {
31 | this.plugin = plugin;
32 | }
33 |
34 | /**
35 | * On votifer event.
36 | *
37 | * @param event the event
38 | */
39 | @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
40 | public void onVotiferEvent(VotifierEvent event) {
41 |
42 | Vote vote = event.getVote();
43 | String str = vote.getServiceName();
44 | if (str.isEmpty()) {
45 | str = "Empty";
46 | }
47 | final String voteSite = str;
48 | final String IP = vote.getAddress();
49 | final String voteUsername = vote.getUsername().trim();
50 | if (IP.equals("VotingPlugin")) {
51 | // ignore own plugin calls of event
52 | return;
53 | }
54 |
55 | if (voteUsername.length() == 0) {
56 | plugin.getLogger().warning("No name from vote on " + voteSite);
57 | return;
58 | }
59 |
60 | plugin.getLogger()
61 | .info("Received a vote from service site '" + voteSite + "' by player '" + voteUsername + "'!");
62 |
63 | plugin.debug("PlayerUsername: " + voteUsername);
64 | plugin.debug("VoteSite: " + voteSite);
65 | plugin.debug("IP: " + IP);
66 |
67 | plugin.getVoteTimer().submit(new Runnable() {
68 |
69 | @Override
70 | public void run() {
71 | try {
72 | plugin.getServerData().addServiceSite(voteSite);
73 | if (plugin.getBungeeSettings().isUseBungeecoord() && !plugin.getBungeeSettings().isVotifierBypass()
74 | && (plugin.getBungeeHandler().getMethod().equals(BungeeMethod.PLUGINMESSAGING)
75 | || plugin.getBungeeHandler().getMethod().equals(BungeeMethod.SOCKETS)
76 | || plugin.getBungeeHandler().getMethod().equals(BungeeMethod.MQTT)
77 | || plugin.getBungeeHandler().getMethod().equals(BungeeMethod.REDIS))) {
78 | plugin.getLogger().severe(
79 | "Ignoring vote from votifier since pluginmessaging, socket, redis, or mqtt bungee method is enabled, this means you aren't setup correctly for those methods, please check: https://github.com/BenCodez/VotingPlugin/wiki/Bungeecord-Setups");
80 | return;
81 | }
82 | String matchSite = "";
83 | if (plugin.getConfigFile().isAdvancedServiceSiteHandling()) {
84 | if (plugin.getServiceSiteHandler() != null) {
85 | matchSite = plugin.getServiceSiteHandler().matchReverse(voteSite);
86 | }
87 | }
88 |
89 | String voteSiteNameStr = plugin.getVoteSiteName(false, voteSite, matchSite);
90 |
91 | ArrayList sites = plugin.getConfigVoteSites().getVoteSitesNames(false);
92 | boolean createSite = false;
93 | if (sites != null) {
94 | if (!ArrayUtils.containsIgnoreCase(sites, voteSiteNameStr)) {
95 | createSite = true;
96 | }
97 | } else {
98 | createSite = true;
99 | }
100 |
101 | String serviceSite = voteSite;
102 |
103 | if (plugin.getConfigFile().isAutoCreateVoteSites() && createSite) {
104 | plugin.getLogger().warning("VoteSite with service site '" + voteSiteNameStr
105 | + "' does not exist, attempting to generate...");
106 | plugin.getConfigVoteSites().generateVoteSite(voteSiteNameStr);
107 |
108 | plugin.getLogger().info("Current known service sites: "
109 | + ArrayUtils.makeStringList(plugin.getServerData().getServiceSites()));
110 | }
111 |
112 | if (plugin.getTimeChecker().isActiveProcessing()
113 | && plugin.getConfigFile().isQueueVotesDuringTimeChange()) {
114 | // time change in progress
115 | plugin.debug("Adding vote to time queue " + voteUsername + "/" + voteSite);
116 | plugin.getTimeQueueHandler().addVote(voteUsername, voteSite);
117 |
118 | return;
119 | }
120 |
121 | String voteSiteName = plugin.getVoteSiteName(true, serviceSite, matchSite);
122 |
123 | PlayerVoteEvent voteEvent = new PlayerVoteEvent(plugin.getVoteSite(voteSiteName, true),
124 | voteUsername, voteSite, true);
125 | plugin.getServer().getPluginManager().callEvent(voteEvent);
126 |
127 | if (voteEvent.isCancelled()) {
128 | plugin.debug("Vote cancelled");
129 | return;
130 | }
131 | } catch (Exception e) {
132 | plugin.getLogger().severe("Error occured during vote processing");
133 | e.printStackTrace();
134 | }
135 |
136 | }
137 | });
138 | }
139 |
140 | }
141 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/listeners/VotingPluginUpdateEvent.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.listeners;
2 |
3 | import org.bukkit.event.EventHandler;
4 | import org.bukkit.event.EventPriority;
5 | import org.bukkit.event.Listener;
6 |
7 | import com.bencodez.advancedcore.listeners.PluginUpdateVersionEvent;
8 | import com.bencodez.votingplugin.VotingPluginMain;
9 |
10 | // TODO: Auto-generated Javadoc
11 | /**
12 | * The Class AdvancedCoreUpdateEvent.
13 | */
14 | public class VotingPluginUpdateEvent implements Listener {
15 |
16 | /** The plugin. */
17 | private VotingPluginMain plugin;
18 |
19 | /**
20 | * Instantiates a new advanced core update event.
21 | *
22 | * @param plugin the plugin
23 | */
24 | public VotingPluginUpdateEvent(VotingPluginMain plugin) {
25 | this.plugin = plugin;
26 | }
27 |
28 | /**
29 | * On plugin update.
30 | *
31 | * @param event the event
32 | */
33 | @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
34 | public void onPluginUpdate(PluginUpdateVersionEvent event) {
35 | if (event.getPlugin().getName().equals(plugin.getDescription().getName())) {
36 | if (!event.getOldVersion().equals("")) {
37 | plugin.getLogger().info("VotingPlugin Updated to " + plugin.getDescription().getVersion() + " from "
38 | + event.getOldVersion());
39 | }
40 | }
41 | }
42 |
43 | }
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/placeholders/MVdWPlaceholders.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.placeholders;
2 |
3 | import org.bukkit.Bukkit;
4 |
5 | import com.bencodez.advancedcore.api.placeholder.NonPlayerPlaceHolder;
6 | import com.bencodez.advancedcore.api.placeholder.PlaceHolder;
7 | import com.bencodez.votingplugin.VotingPluginMain;
8 | import com.bencodez.votingplugin.user.VotingPluginUser;
9 |
10 | import be.maximvdw.placeholderapi.PlaceholderAPI;
11 | import be.maximvdw.placeholderapi.PlaceholderReplaceEvent;
12 | import be.maximvdw.placeholderapi.PlaceholderReplacer;
13 |
14 | // TODO: Auto-generated Javadoc
15 | /**
16 | * The Class PlaceHolders.
17 | */
18 | public class MVdWPlaceholders {
19 |
20 | /** The plugin. */
21 | private VotingPluginMain plugin;
22 |
23 | /**
24 | * Instantiates a new place holders.
25 | *
26 | * @param plugin the plugin
27 | */
28 | public MVdWPlaceholders(VotingPluginMain plugin) {
29 | this.plugin = plugin;
30 | }
31 |
32 | public void loadMVdWPlaceholders() {
33 | if (Bukkit.getPluginManager().isPluginEnabled("MVdWPlaceholderAPI")) {
34 | // The plugin is enabled
35 | for (final PlaceHolder place : plugin.getPlaceholders().getPlaceholders()) {
36 | String str = place.getIdentifier();
37 | if (!str.endsWith("_")) {
38 | PlaceholderAPI.registerPlaceholder(VotingPluginMain.plugin, "VotingPlugin_" + str,
39 | new PlaceholderReplacer() {
40 |
41 | @Override
42 | public String onPlaceholderReplace(PlaceholderReplaceEvent event) {
43 | VotingPluginUser user = plugin.getVotingPluginUserManager()
44 | .getVotingPluginUser(event.getOfflinePlayer());
45 | if (plugin.getConfigFile().isUsePrimaryAccountForPlaceholders()
46 | && user.hasPrimaryAccount()) {
47 | user = plugin.getVotingPluginUserManager()
48 | .getVotingPluginUser(user.getPrimaryAccount());
49 | }
50 | return place.placeholderRequest(user,
51 | event.getPlaceholder().substring("VotingPlugin_".length()));
52 | }
53 |
54 | });
55 | }
56 |
57 | }
58 |
59 | for (final NonPlayerPlaceHolder place : plugin.getPlaceholders()
60 | .getNonPlayerPlaceholders()) {
61 | String str = place.getIdentifier();
62 | if (!str.endsWith("_")) {
63 | PlaceholderAPI.registerPlaceholder(VotingPluginMain.plugin, "VotingPlugin_" + str,
64 | new PlaceholderReplacer() {
65 |
66 | @Override
67 | public String onPlaceholderReplace(PlaceholderReplaceEvent event) {
68 | return place.placeholderRequest(
69 | event.getPlaceholder().substring("VotingPlugin_".length()));
70 | }
71 |
72 | });
73 | }
74 |
75 | }
76 | }
77 | }
78 | }
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/placeholders/PlaceholderCacheLevel.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.placeholders;
2 |
3 | public enum PlaceholderCacheLevel {
4 | NONE, SPECIFIC, AUTO, AUTOALL, SPECIFICALL;
5 |
6 | public static PlaceholderCacheLevel getCache(String str) {
7 | for (PlaceholderCacheLevel v : PlaceholderCacheLevel.values()) {
8 | if (v.toString().equalsIgnoreCase(str)) {
9 | return v;
10 | }
11 | }
12 | return AUTO;
13 | }
14 |
15 | public boolean onlineOnly() {
16 | if ((this == AUTOALL) || (this == SPECIFICALL)) {
17 | return false;
18 | }
19 | return true;
20 | }
21 |
22 | public boolean shouldCache() {
23 | switch (this) {
24 | case AUTO:
25 | return true;
26 | case NONE:
27 | return false;
28 | case SPECIFIC:
29 | return false;
30 | case SPECIFICALL:
31 | return false;
32 | case AUTOALL:
33 | return true;
34 | default:
35 | return false;
36 | }
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/placeholders/VotingPluginExpansion.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.placeholders;
2 |
3 | import org.bukkit.OfflinePlayer;
4 |
5 | import com.bencodez.votingplugin.VotingPluginMain;
6 |
7 | import me.clip.placeholderapi.expansion.PlaceholderExpansion;
8 |
9 | public class VotingPluginExpansion extends PlaceholderExpansion {
10 |
11 | private VotingPluginMain plugin;
12 |
13 | public VotingPluginExpansion(VotingPluginMain plugin) {
14 | this.plugin = plugin;
15 | }
16 |
17 | @Override
18 | public String getAuthor() {
19 | return "bencodez";
20 | }
21 |
22 | @Override
23 | public String getIdentifier() {
24 | return "votingplugin";
25 | }
26 |
27 | @Override
28 | public String getVersion() {
29 | return "1.6";
30 | }
31 |
32 | @Override
33 | public String onRequest(OfflinePlayer p, String indendifier) {
34 | return plugin.getPlaceholders().getPlaceHolder(p, indendifier);
35 | }
36 |
37 | @Override
38 | public boolean persist() {
39 | return true;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/BungeeMessageData.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.proxy;
2 |
3 | import java.util.regex.Pattern;
4 |
5 | import lombok.Getter;
6 | import lombok.Setter;
7 |
8 | public class BungeeMessageData {
9 |
10 | // Message string
11 | // alltimetotal//monthtotal//weeklytotal//dailytotal//points//milestonecount//votepartycurrent//votepartyrequired//datemonthtotal
12 |
13 | @Getter
14 | @Setter
15 | private int allTimeTotal = 0;
16 | @Getter
17 | @Setter
18 | private int dailyTotal = 0;
19 | @Getter
20 | @Setter
21 | private int milestoneCount = 0;
22 | @Getter
23 | @Setter
24 | private int monthTotal = 0;
25 | @Getter
26 | @Setter
27 | private int dateMonthTotal = 0;
28 | @Getter
29 | @Setter
30 | private int points = 0;
31 | @Getter
32 | @Setter
33 | private int weeklyTotal = 0;
34 | @Getter
35 | @Setter
36 | private int votePartyCurrent = 0;
37 | @Getter
38 | @Setter
39 | private int votePartyRequired = 0;
40 |
41 | public BungeeMessageData(int allTimeTotal, int monthTotal, int weeklyTotal, int dailyTotal, int points,
42 | int milestoneCount, int votePartyCurrent, int votePartyRequired, int dateMonthTotal) {
43 | this.allTimeTotal = allTimeTotal;
44 | this.monthTotal = monthTotal;
45 | this.weeklyTotal = weeklyTotal;
46 | this.dailyTotal = dailyTotal;
47 | this.points = points;
48 | this.milestoneCount = milestoneCount;
49 | this.votePartyCurrent = votePartyCurrent;
50 | this.votePartyRequired = votePartyRequired;
51 | this.dateMonthTotal = dateMonthTotal;
52 | }
53 |
54 | public BungeeMessageData(String str) {
55 | String[] data = str.split(Pattern.quote("//"));
56 | if (data.length >= 6) {
57 | allTimeTotal = Integer.parseInt(data[0]);
58 | monthTotal = Integer.parseInt(data[1]);
59 | weeklyTotal = Integer.parseInt(data[2]);
60 | dailyTotal = Integer.parseInt(data[3]);
61 | points = Integer.parseInt(data[4]);
62 | milestoneCount = Integer.parseInt(data[5]);
63 | }
64 | if (data.length >= 8) {
65 | votePartyCurrent = Integer.parseInt(data[6]);
66 | votePartyRequired = Integer.parseInt(data[7]);
67 | }
68 | if (data.length >= 9) {
69 | dateMonthTotal = Integer.parseInt(data[8]);
70 | }
71 | }
72 |
73 | @Override
74 | public String toString() {
75 | return allTimeTotal + "//" + monthTotal + "//" + weeklyTotal + "//" + dailyTotal + "//" + points + "//"
76 | + milestoneCount + "//" + votePartyCurrent + "//" + votePartyRequired;
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/BungeeMethod.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.proxy;
2 |
3 | public enum BungeeMethod {
4 | MYSQL, PLUGINMESSAGING, SOCKETS, REDIS, MQTT;
5 |
6 | public boolean requiresPlayerOnline() {
7 | return this == MYSQL || this == PLUGINMESSAGING;
8 | }
9 |
10 | public static BungeeMethod getByName(String str) {
11 | for (BungeeMethod method : values()) {
12 | if (method.toString().equalsIgnoreCase(str)) {
13 | return method;
14 | }
15 | }
16 | return PLUGINMESSAGING;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/BungeeVersion.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.proxy;
2 |
3 | public class BungeeVersion {
4 | public static int getPluginMessageVersion() {
5 | return 1;
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/OfflineBungeeVote.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.proxy;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 |
6 | public class OfflineBungeeVote {
7 |
8 | @Getter
9 | private String playerName;
10 | @Getter
11 | private boolean realVote;
12 | @Getter
13 | private String service;
14 | @Getter
15 | @Setter
16 | private String text;
17 | @Getter
18 | private long time;
19 | @Getter
20 | private String uuid;
21 |
22 | public OfflineBungeeVote(String playerName, String uuid, String service, long time, boolean realVote, String text) {
23 | this.playerName = playerName;
24 | this.uuid = uuid;
25 | this.service = service;
26 | this.time = time;
27 | this.realVote = realVote;
28 | this.text = text;
29 | }
30 |
31 | @Override
32 | public String toString() {
33 | return "VoteCache:" + playerName + "/" + uuid + "/" + service + "/" + time + "/" + realVote + "/" + text;
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/VotingPluginProxyCommand.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.proxy;
2 |
3 | import com.bencodez.advancedcore.api.time.TimeType;
4 |
5 | public class VotingPluginProxyCommand {
6 | private VotingPluginProxy plugin;
7 |
8 | public VotingPluginProxyCommand(VotingPluginProxy plugin) {
9 | this.plugin = plugin;
10 | }
11 |
12 | /**
13 | * Execute the command and return a message as a String.
14 | *
15 | * @param args Command arguments
16 | * @return The resulting message to send
17 | */
18 | public String execute(String[] args) {
19 | if (args.length == 0)
20 | return "&cPlease provide a valid command. Use 'help' to view all commands.";
21 |
22 | switch (args[0].toLowerCase()) {
23 | case "reload":
24 | plugin.reloadCore(false);
25 | return "&aReloading VotingPlugin";
26 |
27 | case "reloadmysql":
28 | plugin.reloadCore(true);
29 | return "&aReloading VotingPlugin including MySQL";
30 |
31 | case "vote":
32 | if (args.length >= 3) {
33 | String user = args[1];
34 | String site = args[2];
35 | plugin.vote(user, site, false, true, 0, null, null);
36 | return "&aVote sent for " + user + " on " + site;
37 | }
38 | return "&cUsage: vote ";
39 |
40 | case "forcetimechange":
41 | if (args.length >= 2) {
42 | plugin.getBungeeTimeChecker().forceChanged(TimeType.getTimeType(args[1]));
43 | return "&aTriggered time change to " + args[1];
44 | }
45 | return "&cUsage: forcetimechange ";
46 |
47 | case "status":
48 | return handleStatusCommand();
49 |
50 | case "multiproxystatus":
51 | plugin.getMultiProxyHandler().sendMultiProxyServerMessage("Status");
52 | return "&aSent status message across multi-proxy";
53 |
54 | case "help":
55 | return getHelpMessage();
56 |
57 | case "voteparty":
58 | return handleVotePartyCommand(args);
59 |
60 | default:
61 | return "&cUnknown command. Use 'help' to view all commands.";
62 | }
63 | }
64 |
65 | private String handleStatusCommand() {
66 | BungeeMethod method = plugin.getMethod();
67 | switch (method) {
68 | case SOCKETS:
69 | plugin.status();
70 | return "&aChecking status via sockets. Check console for details.";
71 |
72 | case PLUGINMESSAGING:
73 | case REDIS:
74 | plugin.status();
75 | plugin.sendServerNameMessage();
76 | return "&aChecking status with method: " + method.toString().toLowerCase();
77 |
78 | default:
79 | return "&cStatus command unavailable for the current connection method.";
80 | }
81 | }
82 |
83 | private String handleVotePartyCommand(String[] args) {
84 | if (args.length > 1) {
85 | if ("force".equalsIgnoreCase(args[1])) {
86 | plugin.setCurrentVotePartyVotes(plugin.getCurrentVotePartyVotesRequired());
87 | plugin.checkVoteParty();
88 | return "&aVote party forced";
89 | } else if ("setvotecount".equalsIgnoreCase(args[1]) && args.length > 2 && isInt(args[2])) {
90 | plugin.setCurrentVotePartyVotes(Integer.parseInt(args[2]));
91 | return "&aSet current vote party votes to " + args[2];
92 | } else {
93 | return "&cInvalid usage. Use 'help' for correct syntax.";
94 | }
95 | }
96 | return "&cUsage: voteparty ";
97 | }
98 |
99 | private String getHelpMessage() {
100 | StringBuilder helpBuilder = new StringBuilder("&aVotingPlugin Commands:\n");
101 | helpBuilder.append("/votingplugin reload - Reload the plugin\n");
102 | helpBuilder.append("/votingplugin reloadmysql - Reload the plugin including MySQL\n");
103 | helpBuilder.append("/votingplugin vote - Send a vote\n");
104 | helpBuilder.append("/votingplugin forcetimechange - Force a time change\n");
105 | helpBuilder.append("/votingplugin status - Check connection status\n");
106 | helpBuilder.append("/votingplugin multiproxystatus - Send status message across proxies\n");
107 | helpBuilder.append("/votingplugin voteparty - Trigger or modify vote party\n");
108 | return helpBuilder.toString();
109 | }
110 |
111 | private boolean isInt(String str) {
112 | try {
113 | Integer.parseInt(str);
114 | return true;
115 | } catch (NumberFormatException e) {
116 | return false;
117 | }
118 | }
119 |
120 | }
121 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/VotingPluginProxyConfig.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.proxy;
2 |
3 | import java.util.Collection;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | public interface VotingPluginProxyConfig {
8 |
9 | public boolean getAllowUnJoined();
10 |
11 | public String getBedrockPlayerPrefix();
12 |
13 | public List getBlockedServers();
14 |
15 | public boolean getBroadcast();
16 |
17 | public String getBungeeHost();
18 |
19 | public boolean getBungeeManageTotals();
20 |
21 | public String getBungeeMethod();
22 |
23 | public int getBungeePort();
24 |
25 | public String getPluginMessageChannel();
26 |
27 | public boolean getPluginMessageEncryption();
28 |
29 | public boolean getDebug();
30 |
31 | public String getMqttClientID();
32 |
33 | public String getMqttBrokerURL();
34 |
35 | public String getMqttUsername();
36 |
37 | public String getMqttPassword();
38 |
39 | public String getMqttPrefix();
40 |
41 | public String getFallBack();
42 |
43 | public boolean getGlobalDataEnabled();
44 |
45 | public boolean getGlobalDataUseMainMySQL();
46 |
47 | public int getLimitVotePoints();
48 |
49 | public int getMaxAmountOfVotesPerDay();
50 |
51 | public String getMultiProxyMethod();
52 |
53 | public boolean getMultiProxyOneGlobalReward();
54 |
55 | public String getMultiProxyRedisHost();
56 |
57 | public String getMultiProxyRedisPassword();
58 |
59 | public int getMultiProxyRedisPort();
60 |
61 | public boolean getMultiProxyRedisUseExistingConnection();
62 |
63 | public String getMultiProxyRedisUsername();
64 |
65 | public Collection getMultiProxyServers();
66 |
67 | public Map getMultiProxyServersConfiguration(String s);
68 |
69 | public String getMultiProxySocketHostHost();
70 |
71 | public int getMultiProxySocketHostPort();
72 |
73 | public boolean getMultiProxySupport();
74 |
75 | public boolean getOnlineMode();
76 |
77 | public int getPointsOnVote();
78 |
79 | public boolean getPrimaryServer();
80 |
81 | public String getProxyServerName();
82 |
83 | public List getProxyServers();
84 |
85 | public String getRedisHost();
86 |
87 | public String getRedisPassword();
88 |
89 | public int getRedisPort();
90 |
91 | public String getRedisPrefix();
92 |
93 | public String getRedisUsername();
94 |
95 | public boolean getSendVotesToAllServers();
96 |
97 | public Map getSpigotServerConfiguration(String s);
98 |
99 | public Collection getSpigotServers();
100 |
101 | public boolean getStoreMonthTotalsWithDate();
102 |
103 | public boolean getTimeChangeFailSafeBypass();
104 |
105 | public int getTimeHourOffSet();
106 |
107 | public String getTimeZone();
108 |
109 | public boolean getUseMonthDateTotalsAsPrimaryTotal();
110 |
111 | public boolean getUUIDLookup();
112 |
113 | public int getVoteCacheTime();
114 |
115 | public String getVotePartyBroadcast();
116 |
117 | public List getVotePartyBungeeCommands();
118 |
119 | public boolean getVotePartyEnabled();
120 |
121 | public int getVotePartyIncreaseVotesRequired();
122 |
123 | public boolean getVotePartySendToAllServers();
124 |
125 | public List getVotePartyServersToSend();
126 |
127 | public int getVotePartyVotesRequired();
128 |
129 | public boolean getWaitForUserOnline();
130 |
131 | public List getWhiteListedServers();
132 |
133 | public Collection getWaitUntilVoteDelaySites();
134 |
135 | public String getWaitUntilVoteDelayService(String site);
136 |
137 | public int getWaitUntilVoteDelayVoteDelay(String site);
138 |
139 | public int getWaitUntilVoteDelayVoteDelayMin(String site);
140 |
141 | public boolean getResetMilestonesMonthly();
142 |
143 | public int getWaitUntilVoteDelayVoteDelayHour(String site);
144 |
145 | public boolean getWaitUntilVoteDelayVoteDelayDaily(String site);
146 |
147 | public void load();
148 |
149 | public void save();
150 |
151 | }
152 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/bungee/NonVotedPlayersCache.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.proxy.bungee;
2 |
3 | import java.io.File;
4 |
5 | import com.bencodez.simpleapi.file.BungeeJsonFile;
6 | import com.velocitypowered.api.proxy.Player;
7 |
8 | import lombok.Getter;
9 | import net.md_5.bungee.config.Configuration;
10 |
11 | public class NonVotedPlayersCache extends BungeeJsonFile {
12 | private VotingPluginBungee plugin;
13 | @Getter
14 | private Configuration data;
15 |
16 | public NonVotedPlayersCache(VotingPluginBungee plugin) {
17 | super(new File(plugin.getDataFolder(), "nonvotedplayerscache.json"));
18 | this.plugin = plugin;
19 | }
20 |
21 | public void addPlayer(Player player) {
22 | if (!plugin.getVotingPluginProxy().getProxyMySQL().containsKeyQuery(player.getUniqueId().toString())) {
23 | addPlayer(player.getUniqueId().toString(), player.getUsername());
24 | }
25 | }
26 |
27 | public void addPlayer(String uuid, String playerName) {
28 | setString("NonVotedPlayers." + playerName + ".UUID", uuid);
29 | setLong("NonVotedPlayers." + playerName + ".LastTime", System.currentTimeMillis());
30 | save();
31 | }
32 |
33 | public void addPlayerCheck(String uuid, String playerName) {
34 | if (!plugin.getVotingPluginProxy().getProxyMySQL().containsKeyQuery(uuid)) {
35 | addPlayer(uuid, playerName);
36 | }
37 | }
38 |
39 | public void check() {
40 | for (String player : getKeys("NonVotedPlayers")) {
41 | long time = getLong("NonVotedPlayers." + player + ".LastTime", 0);
42 | if ((System.currentTimeMillis() - time) > 1000 * 60 * 60 * 24 * 5) {
43 | removePlayer(player);
44 | } else {
45 | String uuid = getString("NonVotedPlayers." + player + ".UUID", "");
46 | if (!uuid.isEmpty()) {
47 | if (plugin.getVotingPluginProxy().getProxyMySQL().containsKeyQuery(uuid)) {
48 | removePlayer(player);
49 | }
50 | } else {
51 | removePlayer(player);
52 | }
53 | }
54 | }
55 | save();
56 | }
57 |
58 | public String playerExists(String playerName) {
59 | String uuid = getString("NonVotedPlayers." + playerName + ".UUID", "");
60 | if (!uuid.isEmpty()) {
61 | return uuid;
62 | }
63 | return "";
64 | }
65 |
66 | private void removePlayer(String player) {
67 | plugin.debug("Removing nonvotedplayer: " + player);
68 | remove("NonVotedPlayers." + player);
69 |
70 | save();
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/bungee/VoteCache.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.proxy.bungee;
2 |
3 | import java.io.File;
4 | import java.util.Collection;
5 |
6 | import com.bencodez.simpleapi.file.BungeeJsonFile;
7 | import com.bencodez.votingplugin.proxy.OfflineBungeeVote;
8 | import com.bencodez.votingplugin.timequeue.VoteTimeQueue;
9 | import com.google.gson.JsonElement;
10 |
11 | public class VoteCache extends BungeeJsonFile {
12 | private VotingPluginBungee bungee;
13 |
14 | public VoteCache(VotingPluginBungee bungee) {
15 | super(new File(bungee.getDataFolder(), "votecache.json"));
16 | this.bungee = bungee;
17 | initialize();
18 | }
19 |
20 | private void initialize() {
21 | if (!bungee.getDataFolder().exists()) {
22 | bungee.getDataFolder().mkdir();
23 | }
24 | // Reload the JSON file to ensure latest data
25 | reload();
26 | }
27 |
28 | public void addTimedVote(int num, VoteTimeQueue voteTimedQueue) {
29 | String path = "TimedVoteCache." + num;
30 | setString(path + ".Name", voteTimedQueue.getName());
31 | setString(path + ".Service", voteTimedQueue.getService());
32 | setLong(path + ".Time", voteTimedQueue.getTime());
33 | }
34 |
35 | public void addVote(String server, int num, OfflineBungeeVote voteData) {
36 | String path = "VoteCache." + server + "." + num;
37 | setString(path + ".Name", voteData.getPlayerName());
38 | setString(path + ".Service", voteData.getService());
39 | setString(path + ".UUID", voteData.getUuid());
40 | setLong(path + ".Time", voteData.getTime());
41 | setBoolean(path + ".Real", voteData.isRealVote());
42 | setString(path + ".Text", voteData.getText());
43 | }
44 |
45 | public void addVoteOnline(String player, int num, OfflineBungeeVote voteData) {
46 | String path = "OnlineCache." + player + "." + num;
47 | setString(path + ".Name", voteData.getPlayerName());
48 | setString(path + ".Service", voteData.getService());
49 | setString(path + ".UUID", voteData.getUuid());
50 | setLong(path + ".Time", voteData.getTime());
51 | setBoolean(path + ".Real", voteData.isRealVote());
52 | setString(path + ".Text", voteData.getText());
53 | }
54 |
55 | public void clearData() {
56 | setString("VoteCache", null);
57 | setString("OnlineCache", null);
58 | setString("TimedVoteCache", null);
59 | save();
60 | }
61 |
62 | public Collection getOnlineVotes(String name) {
63 | return getKeys("OnlineCache." + name);
64 | }
65 |
66 | public JsonElement getOnlineVotes(String name, String num) {
67 | return getNode("OnlineCache." + name + "." + num);
68 | }
69 |
70 | public Collection getPlayers() {
71 | return getKeys("OnlineCache");
72 | }
73 |
74 | public Collection getServers() {
75 | return getKeys("VoteCache");
76 | }
77 |
78 | public Collection getServerVotes(String server) {
79 | return getKeys("VoteCache." + server);
80 | }
81 |
82 | public JsonElement getServerVotes(String server, String num) {
83 | return getNode("VoteCache." + server + "." + num);
84 | }
85 |
86 | public Collection getTimedVoteCache() {
87 | return getKeys("TimedVoteCache");
88 | }
89 |
90 | public JsonElement getTimedVoteCache(String key) {
91 | return getNode("TimedVoteCache." + key);
92 | }
93 |
94 | public int getVotePartyCache(String server) {
95 | return getInt("VoteParty.Cache." + server, 0);
96 | }
97 |
98 | public int getVotePartyCurrentVotes() {
99 | return getInt("VoteParty.CurrentVotes", 0);
100 | }
101 |
102 | public int getVotePartyInreaseVotesRequired() {
103 | return getInt("VoteParty.IncreaseVotes", 0);
104 | }
105 |
106 | public void setVotePartyCache(String server, int amount) {
107 | setInt("VoteParty.Cache." + server, amount);
108 | }
109 |
110 | public void setVotePartyCurrentVotes(int amount) {
111 | setInt("VoteParty.CurrentVotes", amount);
112 | }
113 |
114 | public void setVotePartyInreaseVotesRequired(int amount) {
115 | setInt("VoteParty.IncreaseVotes", amount);
116 | }
117 |
118 | @Override
119 | public void save() {
120 | super.save();
121 | }
122 |
123 | @Override
124 | public void reload() {
125 | super.reload();
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/bungee/VoteEventBungee.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.proxy.bungee;
2 |
3 | import com.vexsoftware.votifier.bungee.events.VotifierEvent;
4 | import com.vexsoftware.votifier.model.Vote;
5 |
6 | import net.md_5.bungee.event.EventHandler;
7 |
8 | public class VoteEventBungee implements net.md_5.bungee.api.plugin.Listener {
9 | private VotingPluginBungee plugin;
10 |
11 | public VoteEventBungee(VotingPluginBungee plugin) {
12 | this.plugin = plugin;
13 | }
14 |
15 | @EventHandler
16 | public void onVote(VotifierEvent event) {
17 | plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
18 |
19 | @SuppressWarnings("deprecation")
20 | @Override
21 | public void run() {
22 | Vote vote = event.getVote();
23 | String serviceSite = vote.getServiceName();
24 | plugin.getLogger().info("Vote received " + vote.getUsername() + " from service site " + serviceSite);
25 |
26 | if (serviceSite.isEmpty()) {
27 | serviceSite = "Empty";
28 | vote.setServiceName(serviceSite);
29 | }
30 |
31 | plugin.getVotingPluginProxy().vote(vote.getUsername(), serviceSite, true, true, 0, null, null);
32 | }
33 | });
34 |
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/bungee/VotingPluginBungeeCommand.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BenCodez/VotingPlugin/4861c041e43ba6b3aec0d1ee98655aaa17d8bbf8/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/bungee/VotingPluginBungeeCommand.java
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/multiproxy/MultiProxyMethod.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.proxy.multiproxy;
2 |
3 | public enum MultiProxyMethod {
4 | SOCKETS, REDIS;
5 |
6 | public static MultiProxyMethod getByName(String str) {
7 | for (MultiProxyMethod method : values()) {
8 | if (method.toString().equalsIgnoreCase(str)) {
9 | return method;
10 | }
11 | }
12 | return MultiProxyMethod.SOCKETS;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/multiproxy/MultiProxyServerSocketConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.proxy.multiproxy;
2 |
3 | public interface MultiProxyServerSocketConfiguration {
4 | String getHost();
5 |
6 | int getPort();
7 |
8 | String getServerName();
9 | }
10 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/multiproxy/MultiProxyServerSocketConfigurationBungee.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.proxy.multiproxy;
2 |
3 | import java.util.Map;
4 |
5 | public class MultiProxyServerSocketConfigurationBungee implements MultiProxyServerSocketConfiguration {
6 | private String server;
7 | private String host = "";
8 | private int port;
9 |
10 | public MultiProxyServerSocketConfigurationBungee(String s, Map config) {
11 | server = s;
12 | if (config.containsKey("Host")) {
13 | host = (String) config.get("Host");
14 | }
15 | if (config.containsKey("Port")) {
16 | port = (int) config.get("Port");
17 | } else {
18 | port = 1298;
19 | }
20 | }
21 |
22 | @Override
23 | public String getHost() {
24 | return host;
25 | }
26 |
27 | @Override
28 | public int getPort() {
29 | return port;
30 | }
31 |
32 | @Override
33 | public String getServerName() {
34 | return server;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/multiproxy/MultiProxyServerSocketConfigurationVelocity.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.proxy.multiproxy;
2 |
3 | import ninja.leaping.configurate.ConfigurationNode;
4 |
5 | public class MultiProxyServerSocketConfigurationVelocity implements MultiProxyServerSocketConfiguration {
6 |
7 | private String server;
8 | private String host;
9 | private int port;
10 |
11 | public MultiProxyServerSocketConfigurationVelocity(String s, ConfigurationNode config) {
12 | server = s;
13 | host = config.getNode("Host").getString("0.0.0.0");
14 | port = config.getNode("Port").getInt(1298);
15 |
16 | }
17 |
18 | @Override
19 | public String getHost() {
20 | return host;
21 | }
22 |
23 | @Override
24 | public int getPort() {
25 | return port;
26 | }
27 |
28 | @Override
29 | public String getServerName() {
30 | return server;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/velocity/NonVotedPlayersCache.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.proxy.velocity;
2 |
3 | import java.io.File;
4 |
5 | import com.bencodez.simpleapi.file.velocity.VelocityJSONFile;
6 | import com.velocitypowered.api.proxy.Player;
7 |
8 | public class NonVotedPlayersCache extends VelocityJSONFile {
9 |
10 | private VotingPluginVelocity plugin;
11 |
12 | public NonVotedPlayersCache(File file, VotingPluginVelocity plugin) {
13 | super(file);
14 | this.plugin = plugin;
15 | }
16 |
17 | public void addPlayer(Player player) {
18 | if (!plugin.getVotingPluginProxy().getProxyMySQL().containsKeyQuery(player.getUniqueId().toString())) {
19 | addPlayer(player.getUniqueId().toString(), player.getUsername());
20 | }
21 | }
22 |
23 | public void addPlayer(String uuid, String playerName) {
24 | getNode("NonVotedPlayers", playerName, "UUID").setValue(uuid);
25 | getNode("NonVotedPlayers", playerName, "LastTime").setValue(System.currentTimeMillis());
26 | save();
27 | }
28 |
29 | public void addPlayerCheck(String uuid, String playerName) {
30 | if (!plugin.getVotingPluginProxy().getProxyMySQL().containsKeyQuery(uuid)) {
31 | addPlayer(uuid, playerName);
32 | }
33 | }
34 |
35 | public void check() {
36 | for (String player : getKeys(getNode("NonVotedPlayers"))) {
37 | long time = getNode("NonVotedPlayers", player, "LastTime").getLong(0);
38 | if ((System.currentTimeMillis() - time) > 1000 * 60 * 60 * 24 * 5) {
39 | remove(player);
40 | } else {
41 | String uuid = getNode("NonVotedPlayers", player, "UUID").getString("");
42 | if (!uuid.isEmpty()) {
43 | if (plugin.getVotingPluginProxy().getProxyMySQL().containsKeyQuery(uuid)) {
44 | remove(player);
45 | }
46 | } else {
47 | remove(player);
48 | }
49 | }
50 | }
51 | save();
52 | }
53 |
54 | public String playerExists(String playerName) {
55 | if (!getNode("NonVotedPlayers", playerName).isEmpty()) {
56 | return getNode("NonVotedPlayers", playerName, "UUID").getString("");
57 | }
58 | return "";
59 | }
60 |
61 | private void remove(String player) {
62 | plugin.debug("Removing nonvotedplayer: " + player);
63 |
64 | getNode("NonVotedPlayers", player).setValue(null);
65 |
66 | save();
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/velocity/VoteCache.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.proxy.velocity;
2 |
3 | import java.io.File;
4 | import java.util.Collection;
5 |
6 | import com.bencodez.simpleapi.file.velocity.VelocityJSONFile;
7 | import com.bencodez.votingplugin.proxy.OfflineBungeeVote;
8 | import com.bencodez.votingplugin.timequeue.VoteTimeQueue;
9 |
10 | import ninja.leaping.configurate.ConfigurationNode;
11 |
12 | public class VoteCache extends VelocityJSONFile {
13 |
14 | public VoteCache(File file) {
15 | super(file);
16 | }
17 |
18 | public void addTimedVote(int num, VoteTimeQueue voteTimedQueue) {
19 | getNode("TimedVoteCache", "" + num, "Name").setValue(voteTimedQueue.getName());
20 | getNode("TimedVoteCache", "" + num, "Service").setValue(voteTimedQueue.getService());
21 | getNode("TimedVoteCache", "" + num, "Time").setValue(voteTimedQueue.getTime());
22 | }
23 |
24 | public void addVote(String server, int num, OfflineBungeeVote voteData) {
25 |
26 | getNode("VoteCache", server, "" + num, "Name").setValue(voteData.getPlayerName());
27 | getNode("VoteCache", server, "" + num, "Service").setValue(voteData.getService());
28 | getNode("VoteCache", server, "" + num, "UUID").setValue(voteData.getUuid());
29 | getNode("VoteCache", server, "" + num, "Time").setValue(voteData.getTime());
30 | getNode("VoteCache", server, "" + num, "Real").setValue(voteData.isRealVote());
31 | getNode("VoteCache", server, "" + num, "Text").setValue(voteData.getText());
32 | }
33 |
34 | public void addVoteOnline(String player, int num, OfflineBungeeVote voteData) {
35 |
36 | getNode("OnlineCache", player, "" + num, "Name").setValue(voteData.getPlayerName());
37 | getNode("OnlineCache", player, "" + num, "Service").setValue(voteData.getService());
38 | getNode("OnlineCache", player, "" + num, "UUID").setValue(voteData.getUuid());
39 | getNode("OnlineCache", player, "" + num, "Time").setValue(voteData.getTime());
40 | getNode("OnlineCache", player, "" + num, "Real").setValue(voteData.isRealVote());
41 | getNode("OnlineCache", player, "" + num, "Text").setValue(voteData.getText());
42 | }
43 |
44 | public void clearData() {
45 | getNode("VoteCache").setValue(null);
46 | getNode("OnlineCache").setValue(null);
47 | getNode("TimedVoteCache").setValue(null);
48 | save();
49 | }
50 |
51 | public Collection getOnlineVotes(String name) {
52 | return getKeys(getNode("OnlineCache", name));
53 | }
54 |
55 | public ConfigurationNode getOnlineVotes(String name, String num) {
56 | return getNode("OnlineCache", name, num);
57 | }
58 |
59 | public Collection getPlayers() {
60 | return getKeys(getNode("OnlineCache"));
61 | }
62 |
63 | public Collection getServers() {
64 | return getKeys(getNode("VoteCache"));
65 | }
66 |
67 | public Collection getServerVotes(String server) {
68 | return getKeys(getNode("VoteCache", server));
69 | }
70 |
71 | public ConfigurationNode getServerVotes(String server, String num) {
72 | return getNode("VoteCache", server, num);
73 | }
74 |
75 | public Collection getTimedVoteCache() {
76 | return getKeys(getNode("TimedVoteCache"));
77 | }
78 |
79 | public ConfigurationNode getTimedVoteCache(String name) {
80 | return getNode("TimedVoteCache", name);
81 | }
82 |
83 | public int getVotePartyCache(String server) {
84 | return getNode("VoteParty").getNode("Cache").getNode(server).getInt(0);
85 | }
86 |
87 | public int getVotePartyCurrentVotes() {
88 | return getInt(getNode("VoteParty").getNode("CurrentVotes"), 0);
89 | }
90 |
91 | public int getVotePartyInreaseVotesRequired() {
92 | return getInt(getNode("VoteParty").getNode("IncreaseVotes"), 0);
93 | }
94 |
95 | public void setVotePartyCache(String server, int amount) {
96 | getNode("VoteParty").getNode("Cache").getNode(server).setValue(amount);
97 | }
98 |
99 | public void setVotePartyCurrentVotes(int amount) {
100 | getNode("VoteParty").getNode("CurrentVotes").setValue(amount);
101 | }
102 |
103 | public void setVotePartyInreaseVotesRequired(int amount) {
104 | getNode("VoteParty").getNode("IncreaseVotes").setValue(amount);
105 | }
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/velocity/VoteEventVelocity.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.proxy.velocity;
2 |
3 | import com.velocitypowered.api.event.Subscribe;
4 | import com.vexsoftware.votifier.velocity.event.VotifierEvent;
5 |
6 | public class VoteEventVelocity {
7 | private VotingPluginVelocity plugin;
8 |
9 | public VoteEventVelocity(VotingPluginVelocity plugin) {
10 | this.plugin = plugin;
11 | }
12 |
13 | @Subscribe
14 | public void onVotifierEvent(VotifierEvent event) {
15 | final String serviceSiteVote = event.getVote().getServiceName();
16 | final String name = event.getVote().getUsername();
17 | plugin.getTimer().execute(new Runnable() {
18 |
19 | @Override
20 | public void run() {
21 | String serviceSite = serviceSiteVote;
22 | plugin.getLogger().info("Vote received " + name + " from service site " + serviceSite);
23 | if (serviceSite.isEmpty()) {
24 | serviceSite = "Empty";
25 | }
26 |
27 | plugin.getVotingPluginProxy().vote(name, serviceSite, true, false, 0, null, null);
28 | }
29 | });
30 |
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/velocity/VotingPluginChannelIdentifier.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.proxy.velocity;
2 |
3 | import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
4 |
5 | public class VotingPluginChannelIdentifier implements ChannelIdentifier {
6 | public VotingPluginChannelIdentifier() {
7 | }
8 |
9 | @Override
10 | public String getId() {
11 | return "vp:vp";
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/velocity/VotingPluginVelocityCommand.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BenCodez/VotingPlugin/4861c041e43ba6b3aec0d1ee98655aaa17d8bbf8/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/velocity/VotingPluginVelocityCommand.java
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/servicesites/ServiceSiteHandler.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.servicesites;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 | import java.io.InputStreamReader;
7 | import java.net.MalformedURLException;
8 | import java.net.URL;
9 | import java.util.HashMap;
10 | import java.util.Map.Entry;
11 |
12 | import com.bencodez.votingplugin.VotingPluginMain;
13 |
14 | import lombok.Getter;
15 |
16 | public class ServiceSiteHandler {
17 | @Getter
18 | private HashMap serviceSites = new HashMap<>();
19 | private VotingPluginMain plugin;
20 |
21 | public ServiceSiteHandler(VotingPluginMain plugin) {
22 | this.plugin = plugin;
23 | loadFromGithub();
24 | for (Entry entry : serviceSites.entrySet()) {
25 | plugin.extraDebug(entry.getKey() + " - " + entry.getValue());
26 | }
27 |
28 | }
29 |
30 | public boolean contains(String service) {
31 | for (Entry entry : serviceSites.entrySet()) {
32 | if (entry.getKey().equalsIgnoreCase(service)) {
33 | return true;
34 | }
35 | }
36 | return false;
37 | }
38 |
39 | public void loadFromGithub() {
40 | try {
41 | readFromWeb("https://github.com/BenCodez/VotingPlugin/wiki/Minecraft-Server-Lists");
42 | } catch (IOException e) {
43 | e.printStackTrace();
44 | }
45 | }
46 |
47 | public String match(String service) {
48 | for (Entry entry : serviceSites.entrySet()) {
49 | if (entry.getKey().equalsIgnoreCase(service)) {
50 | return entry.getValue();
51 | }
52 | }
53 | return service;
54 | }
55 |
56 | public String matchReverse(String service) {
57 | for (Entry entry : serviceSites.entrySet()) {
58 | if (entry.getValue().equalsIgnoreCase(service)) {
59 | return entry.getKey();
60 | }
61 | }
62 | return service;
63 | }
64 |
65 | public void readFromWeb(String webURL) throws IOException {
66 | serviceSites.clear();
67 | URL url = new URL(webURL);
68 | InputStream is = url.openStream();
69 | try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
70 | String line;
71 | boolean rawFound = false;
72 | while ((line = br.readLine()) != null) {
73 | if (line.contains("")) {
74 | rawFound = true;
75 | } else if (!line.contains(" - ")) {
76 | rawFound = false;
77 | } else if (rawFound) {
78 | String data = line.replaceAll("- ", "").replaceAll("
", "");
79 | String[] split = data.split(" - ");
80 | if (split.length > 0) {
81 | serviceSites.put(split[0], split[1]);
82 | }
83 |
84 | }
85 | }
86 | } catch (MalformedURLException e) {
87 | plugin.debug(e);
88 | // e.printStackTrace();
89 | // throw new MalformedURLException("URL is malformed!!");
90 | } catch (IOException e) {
91 | plugin.debug(e);
92 | // e.printStackTrace();
93 | // throw new IOException();
94 | }
95 |
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/signs/Signs.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.signs;
2 |
3 | import java.util.ArrayList;
4 |
5 | import org.bukkit.Location;
6 |
7 | import com.bencodez.votingplugin.VotingPluginMain;
8 |
9 | import lombok.Getter;
10 | import lombok.Setter;
11 |
12 | // TODO: Auto-generated Javadoc
13 | /**
14 | * The Class Signs.
15 | */
16 | public class Signs {
17 | private VotingPluginMain plugin;
18 |
19 | @Getter
20 | @Setter
21 | private ArrayList signs;
22 |
23 | public Signs(VotingPluginMain plugin) {
24 | this.plugin = plugin;
25 | this.signs = new ArrayList<>();
26 | }
27 |
28 | /**
29 | * Gets the sign from location.
30 | *
31 | * @param loc the loc
32 | * @return the sign from location
33 | */
34 | public String getSignFromLocation(Location loc) {
35 | for (String sign : plugin.getServerData().getSigns()) {
36 | if (plugin.getServerData().getSignLocation(sign).equals(loc)) {
37 | return sign;
38 | }
39 | }
40 |
41 | return null;
42 | }
43 |
44 | /**
45 | * Load signs.
46 | */
47 | public void loadSigns() {
48 | setSigns(new ArrayList<>());
49 | for (String sign : plugin.getServerData().getSigns()) {
50 | // plugin.getLogger().info("Loading sign " + sign);
51 | getSigns().add(new SignHandler(plugin, sign, plugin.getServerData().getSignLocation(sign),
52 | plugin.getServerData().getSignSkullLocation(sign), plugin.getServerData().getSignData(sign),
53 | plugin.getServerData().getSignPosition(sign)));
54 | }
55 | }
56 |
57 | /**
58 | * Store signs.
59 | */
60 | public void storeSigns() {
61 | for (SignHandler sign : getSigns()) {
62 | sign.storeSign();
63 | }
64 | }
65 |
66 | /**
67 | * Update signs.
68 | */
69 | public void updateSigns() {
70 | int time = 0;
71 | for (int i = getSigns().size() - 1; i >= 0; i--) {
72 | if (!getSigns().get(i).isValid()) {
73 | plugin.debug(
74 | "Sign " + i + " invalid, removing from data: " + getSigns().get(i).getLocation().toString());
75 | getSigns().get(i).removeSign();
76 | getSigns().remove(i);
77 | } else {
78 | getSigns().get(i).updateLines();
79 | getSigns().get(i).updateSign(time);
80 | time += 1;
81 | }
82 | }
83 |
84 | plugin.debug(getSigns().size() + " Signs updated");
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/timequeue/TimeQueueHandler.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.timequeue;
2 |
3 | import java.time.LocalDateTime;
4 | import java.time.ZoneId;
5 | import java.util.Queue;
6 | import java.util.concurrent.ConcurrentLinkedQueue;
7 | import java.util.concurrent.TimeUnit;
8 |
9 | import org.bukkit.configuration.ConfigurationSection;
10 | import org.bukkit.event.EventHandler;
11 | import org.bukkit.event.EventPriority;
12 | import org.bukkit.event.Listener;
13 |
14 | import com.bencodez.advancedcore.api.time.events.DateChangedEvent;
15 | import com.bencodez.votingplugin.VotingPluginMain;
16 | import com.bencodez.votingplugin.events.PlayerVoteEvent;
17 |
18 | import lombok.Getter;
19 |
20 | public class TimeQueueHandler implements Listener {
21 | @Getter
22 | private Queue timeChangeQueue = new ConcurrentLinkedQueue<>();
23 |
24 | private VotingPluginMain plugin;
25 |
26 | public TimeQueueHandler(VotingPluginMain plugin) {
27 | this.plugin = plugin;
28 | load();
29 | }
30 |
31 | public void addVote(String voteUsername, String voteSiteName) {
32 | timeChangeQueue.add(new VoteTimeQueue(voteUsername, voteSiteName,
33 | LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()));
34 | }
35 |
36 | public void load() {
37 | for (String str : plugin.getServerData().getTimedVoteCacheKeys()) {
38 | ConfigurationSection data = plugin.getServerData().getTimedVoteCacheSection(str);
39 | timeChangeQueue
40 | .add(new VoteTimeQueue(data.getString("Name"), data.getString("Service"), data.getLong("Time")));
41 | }
42 | plugin.getServerData().clearTimedVoteCache();
43 | plugin.getVoteTimer().schedule(new Runnable() {
44 |
45 | @Override
46 | public void run() {
47 | processQueue();
48 | }
49 | }, 120, TimeUnit.SECONDS);
50 | }
51 |
52 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
53 | public void postTimeChange(DateChangedEvent event) {
54 | plugin.getVoteTimer().schedule(new Runnable() {
55 |
56 | @Override
57 | public void run() {
58 | processQueue();
59 | }
60 | }, 5, TimeUnit.SECONDS);
61 | }
62 |
63 | public void processQueue() {
64 | while (getTimeChangeQueue().size() > 0) {
65 | VoteTimeQueue vote = getTimeChangeQueue().remove();
66 | PlayerVoteEvent voteEvent = new PlayerVoteEvent(
67 | plugin.getVoteSite(plugin.getVoteSiteName(true, vote.getService()), true), vote.getName(),
68 | vote.getService(), true);
69 | voteEvent.setTime(voteEvent.getTime());
70 | plugin.getServer().getPluginManager().callEvent(voteEvent);
71 |
72 | if (voteEvent.isCancelled()) {
73 | plugin.debug("Vote cancelled");
74 | return;
75 | }
76 | }
77 | }
78 |
79 | public void save() {
80 | if (!timeChangeQueue.isEmpty()) {
81 | int num = 0;
82 | for (VoteTimeQueue vote : timeChangeQueue) {
83 | plugin.getServerData().addTimeVoted(num, vote);
84 | num++;
85 | }
86 | }
87 | timeChangeQueue.clear();
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/timequeue/VoteTimeQueue.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.timequeue;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 |
6 | public class VoteTimeQueue {
7 | @Getter
8 | @Setter
9 | private String name;
10 | @Getter
11 | @Setter
12 | private String service;
13 | @Getter
14 | @Setter
15 | private long time;
16 |
17 | public VoteTimeQueue(String name, String service, long time) {
18 | this.name = name;
19 | this.service = service;
20 | this.time = time;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/topvoter/TopVoter.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.topvoter;
2 |
3 | import java.util.ArrayList;
4 |
5 | import com.bencodez.advancedcore.api.time.TimeType;
6 | import com.bencodez.votingplugin.VotingPluginMain;
7 |
8 | import lombok.Getter;
9 |
10 | public enum TopVoter {
11 | AllTime, Monthly, Weekly, Daily;
12 |
13 | public static TopVoter getDefault() {
14 | TopVoter top = getTopVoter(VotingPluginMain.plugin.getConfigFile().getVoteTopDefault());
15 | if (top != null) {
16 | return top;
17 | }
18 | return AllTime;
19 | }
20 |
21 | public static TopVoter getTopVoter(String str) {
22 | for (TopVoter value : values()) {
23 | if (value.toString().equalsIgnoreCase(str)) {
24 | return value;
25 | }
26 | }
27 | return AllTime;
28 | }
29 |
30 | public static TopVoter of(TimeType type) {
31 | switch (type) {
32 | case DAY:
33 | return Daily;
34 | case MONTH:
35 | return Monthly;
36 | case WEEK:
37 | return Weekly;
38 | default:
39 | return null;
40 | }
41 | }
42 |
43 | public static TopVoter[] valuesMinusAllTime() {
44 | return new TopVoter[] { TopVoter.Daily, TopVoter.Weekly, TopVoter.Monthly };
45 | }
46 |
47 | @Getter
48 | private ArrayList switchItems = new ArrayList<>();
49 |
50 | public String getColumnName() {
51 | switch (this) {
52 | case AllTime:
53 | return "AllTimeTotal";
54 | case Daily:
55 | return "DailyTotal";
56 | case Monthly:
57 | return "MonthTotal";
58 | case Weekly:
59 | return "WeeklyTotal";
60 | default:
61 | return null;
62 |
63 | }
64 | }
65 |
66 | public String getLastColumnName() {
67 | switch (this) {
68 | case AllTime:
69 | return null;
70 | case Daily:
71 | return "LastDailyTotal";
72 | case Monthly:
73 | return "LastMonthTotal";
74 | case Weekly:
75 | return "LastWeeklyTotal";
76 | default:
77 | return null;
78 |
79 | }
80 | }
81 |
82 | public String getName() {
83 | if (this.equals(TopVoter.Monthly)) {
84 | return VotingPluginMain.plugin.getConfigFile().getFormatTopVoterMonthly();
85 | }
86 | if (this.equals(TopVoter.Weekly)) {
87 | return VotingPluginMain.plugin.getConfigFile().getFormatTopVoterWeekly();
88 | }
89 | if (this.equals(TopVoter.Daily)) {
90 | return VotingPluginMain.plugin.getConfigFile().getFormatTopVoterDaily();
91 | } else {
92 | return VotingPluginMain.plugin.getConfigFile().getFormatTopVoterAllTime();
93 | }
94 | }
95 |
96 | public TopVoter next() {
97 | ArrayList list = new ArrayList<>();
98 | if (switchItems != null && !switchItems.isEmpty()) {
99 | list.addAll(switchItems);
100 | } else {
101 | if (VotingPluginMain.plugin.getConfigFile().isLoadTopVoterAllTime()) {
102 | list.add(TopVoter.AllTime);
103 | }
104 | if (VotingPluginMain.plugin.getConfigFile().isLoadTopVoterMonthly()) {
105 | list.add(TopVoter.Monthly);
106 | }
107 | if (VotingPluginMain.plugin.getConfigFile().isLoadTopVoterWeekly()) {
108 | list.add(TopVoter.Weekly);
109 | }
110 | if (VotingPluginMain.plugin.getConfigFile().isLoadTopVoterDaily()) {
111 | list.add(TopVoter.Daily);
112 | }
113 | }
114 |
115 | for (int i = 0; i < list.size(); i++) {
116 | if (list.get(i).equals(this)) {
117 | int next = i + 1;
118 | if (next > list.size() - 1) {
119 | next = 0;
120 | }
121 | return list.get(next);
122 | }
123 | }
124 | return TopVoter.AllTime;
125 | }
126 |
127 | public TopVoter prev() {
128 | ArrayList list = new ArrayList<>();
129 | if (switchItems != null && !switchItems.isEmpty()) {
130 | list.addAll(switchItems);
131 | } else {
132 | if (VotingPluginMain.plugin.getConfigFile().isLoadTopVoterAllTime()) {
133 | list.add(TopVoter.AllTime);
134 | }
135 | if (VotingPluginMain.plugin.getConfigFile().isLoadTopVoterMonthly()) {
136 | list.add(TopVoter.Monthly);
137 | }
138 | if (VotingPluginMain.plugin.getConfigFile().isLoadTopVoterWeekly()) {
139 | list.add(TopVoter.Weekly);
140 | }
141 | if (VotingPluginMain.plugin.getConfigFile().isLoadTopVoterDaily()) {
142 | list.add(TopVoter.Daily);
143 | }
144 | }
145 | for (int i = list.size() - 1; i >= 0; i--) {
146 | if (list.get(i).equals(this)) {
147 | int prev = i - 1;
148 | if (prev < 0) {
149 | prev = list.size() - 1;
150 | }
151 | return list.get(prev);
152 | }
153 | }
154 | return TopVoter.AllTime;
155 | }
156 | }
157 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/topvoter/TopVoterPlayer.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.topvoter;
2 |
3 | import java.util.UUID;
4 |
5 | import org.bukkit.inventory.ItemStack;
6 |
7 | import com.bencodez.votingplugin.VotingPluginMain;
8 | import com.bencodez.votingplugin.user.VotingPluginUser;
9 |
10 | import lombok.Getter;
11 | import lombok.Setter;
12 |
13 | public class TopVoterPlayer {
14 | @Getter
15 | @Setter
16 | private UUID uuid;
17 | @Getter
18 | @Setter
19 | private String playerName;
20 |
21 | @Getter
22 | @Setter
23 | private Long lastVoteTime;
24 |
25 | public TopVoterPlayer(UUID uuid, String playerName, Long lastVoteTime) {
26 | this.uuid = uuid;
27 | this.playerName = playerName;
28 | this.lastVoteTime = lastVoteTime;
29 | }
30 |
31 | public ItemStack getPlayerHead() {
32 | return VotingPluginMain.plugin.getSkullCacheHandler().getSkull(uuid, playerName);
33 | }
34 |
35 | public VotingPluginUser getUser() {
36 | return VotingPluginMain.plugin.getVotingPluginUserManager().getVotingPluginUser(getUuid(), getPlayerName());
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/java/com/bencodez/votingplugin/updater/CheckUpdate.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.updater;
2 |
3 | import java.util.Timer;
4 | import java.util.TimerTask;
5 |
6 | import com.bencodez.simpleapi.updater.Updater;
7 | import com.bencodez.votingplugin.VotingPluginMain;
8 |
9 | // TODO: Auto-generated Javadoc
10 | /**
11 | * The Class CheckUpdate.
12 | */
13 | public class CheckUpdate {
14 |
15 | private VotingPluginMain plugin;
16 |
17 | public CheckUpdate(VotingPluginMain plugin) {
18 | this.plugin = plugin;
19 | }
20 |
21 | /**
22 | * Check update.
23 | */
24 | public void checkUpdate() {
25 | if (plugin.getConfigFile().isDisableUpdateChecking()
26 | || plugin.getDescription().getVersion().endsWith("SNAPSHOT")) {
27 | return;
28 | }
29 | plugin.setUpdater(new Updater(plugin, 15358, false));
30 | final Updater.UpdateResult result = plugin.getUpdater().getResult();
31 | switch (result) {
32 | case FAIL_SPIGOT: {
33 | plugin.getLogger().info("Failed to check for update for " + plugin.getName() + "!");
34 | break;
35 | }
36 | case NO_UPDATE: {
37 | plugin.getLogger().info(plugin.getName() + " is up to date! Version: " + plugin.getUpdater().getVersion());
38 | break;
39 | }
40 | case UPDATE_AVAILABLE: {
41 | plugin.getLogger().info(plugin.getName() + " has an update available! Your Version: "
42 | + plugin.getDescription().getVersion() + " New Version: " + plugin.getUpdater().getVersion());
43 | break;
44 | }
45 | default: {
46 | break;
47 | }
48 | }
49 | }
50 |
51 | public void checkUpdateBasic() {
52 | if (plugin.getConfigFile().isDisableUpdateChecking()) {
53 | return;
54 | }
55 | plugin.setUpdater(new Updater(plugin, 15358, false));
56 | final Updater.UpdateResult result = plugin.getUpdater().getResult();
57 | switch (result) {
58 | case UPDATE_AVAILABLE: {
59 | plugin.getLogger().info(plugin.getName() + " has an update available! Your Version: "
60 | + plugin.getDescription().getVersion() + " New Version: " + plugin.getUpdater().getVersion());
61 | break;
62 | }
63 | default: {
64 | break;
65 | }
66 | }
67 | }
68 |
69 | /**
70 | * Start up.
71 | */
72 | public void startUp() {
73 | if (plugin.getConfigFile().isDisableUpdateChecking()
74 | || plugin.getDescription().getVersion().endsWith("SNAPSHOT")) {
75 | return;
76 | }
77 | plugin.getBukkitScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
78 |
79 | @Override
80 | public void run() {
81 | checkUpdate();
82 | new Timer().schedule(new TimerTask() {
83 |
84 | @Override
85 | public void run() {
86 | checkUpdateBasic();
87 | }
88 | }, 1000 * 60 * 1200, 1000 * 60 * 1200);
89 |
90 | }
91 | }, 10);
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/resources/Shop.yml:
--------------------------------------------------------------------------------
1 | VoteShop:
2 | Enabled: true
3 | Name: 'VoteShop'
4 | BackButton: true
5 | # Hide items in vote shop which user can not buy
6 | HideLimitedReached: true
7 | # Requires above to be false
8 | LimitReached: '&aYou reached your limit'
9 | RequireConfirmation: false
10 | Disabled: '&cVote shop disabled'
11 | # If true, shop gui will reopen, updating all placeholders
12 | ReopenGUIOnPurchase: false
13 |
14 | Shop:
15 | # Identifier
16 | # Used in placeholders for formats
17 | # Do not have spaces in the identifier
18 | # Change the identifier for each shop item
19 | Diamond:
20 | Identifier_Name: 'Diamond'
21 | # Item
22 | Material: 'DIAMOND'
23 | Amount: 1
24 | Name: '&4Buy A Diamond'
25 | # You can set skulls of the player using the following
26 | # Remove the # to enable
27 | #Skull: '%Player%'
28 | Lore:
29 | - '&c&lCost: &c3 Voting Points'
30 | # Number of voting points this cost
31 | Cost: 3
32 | # Permission required, leave blank for no permission
33 | Permission: ''
34 | # Hide if player doesn't have permission (only if permission is set)
35 | HideOnNoPermission: true
36 | # Whether or not to keep GUI open after purchase
37 | CloseGUI: true
38 | # Require confirmation on purchase, overrides global option above
39 | RequireConfirmation: false
40 | # Overrides other purchase message
41 | #PurchaseMessage: 'Thanks for the purchase'
42 | # Limit how many times you can buy this
43 | #Limit: 3
44 | # Reset limit daily/weekly/monthly
45 | #Reset:
46 | #Daily: false
47 | #Weekly: false
48 | #Monthly: false
49 | # If true, item is not buyable
50 | #NotBuyable: false
51 | # Rewards to run if player buys successfully
52 | Rewards:
53 | # Run command on purchase
54 | #Commands:
55 | #- 'command here'
56 | Items:
57 | Diamond:
58 | Material: 'DIAMOND'
59 | Amount: 1
60 |
61 | # VoteShop extra items for display only
62 | #ExtraItems:
63 | #ItemIdentifier:
64 | #...
65 |
66 | ShopConfirmPurchase:
67 | Title: 'Confirm Purchase?'
68 | YesItem:
69 | Material: EMERALD_BLOCK
70 | Amount: 1
71 | Name: '&aYes'
72 | NoItem:
73 | Material: BARRIER
74 | Amount: 1
75 | Name: '&cNo'
76 |
77 |
--------------------------------------------------------------------------------
/VotingPlugin/src/main/resources/VoteSites.yml:
--------------------------------------------------------------------------------
1 | VoteSites:
2 | # VoteSite key
3 | # Used for saving data for votesites
4 | # Use a short name if you can
5 | # No spaces or dots
6 | ExampleVoteSite:
7 | # Enable voteSite
8 | # If false, votesite will not be loaded by plugin
9 | # Default: false
10 | Enabled: false
11 |
12 | # Display name of voting site
13 | Name: 'ExampleVoteSite'
14 |
15 | # Priority of this site
16 | # Used for sorted list
17 | # High prority, higher on the list
18 | Priority: 5
19 |
20 | # If true, voteside will be hidden from some GUI's, similar to being disabled
21 | Hidden: false
22 |
23 | # The serviceName from the vote, has to be correct to work correctly
24 | # Gotten from voting on the site (will be in console/log)
25 | # Usually is the main part of the url(e.g. PlanetMinecraft.com), but not always
26 | # See console when you vote (it will notify you if the plugin didn't find a votingsite matching the service site
27 | ServiceSite: 'PlanetMinecraft.com'
28 |
29 | # vote url for /vote
30 | # Format for this can be set in Config.yml
31 | # Do not include colors here
32 | # If you need to force a url set the url as this:
33 | # VoteURL: '[Text="ANY TEXT TO CLICK ON HERE",url="URLHERE"]'
34 | VoteURL: 'link to vote URL here, used in /vote'
35 |
36 | # Time between votes in hours (used for /vote next)
37 | # Most sites are 24 hours
38 | VoteDelay: 24
39 |
40 | # Use to have a minute votedelay
41 | # Must set a value on VoteDelay if you plan on only using this setting
42 | #VoteDelayMin: 30
43 |
44 | # Require waiting until votedelay time has pasted in order to accept vote
45 | # Recommend: false
46 | WaitUntilVoteDelay: false
47 |
48 | # Reset vote delay each day (for certain sites that do this)
49 | # Recommend: false
50 | VoteDelayDaily: false
51 |
52 | # Replaces offset, set the exact hour based on server time
53 | # Include server time offset when setting this
54 | # 2 = 2 am server time
55 | # Use 1-24
56 | #VoteDelayDailyHour: 14
57 |
58 | # If true, rewards can be executed offline (requires ForceOffline to be true in the reward)
59 | # Setting this to true will execute the reward offline while the player is offline
60 | # This basiclly disables offline voting if set to true, don't misinterpret this option
61 | ForceOffline: false
62 |
63 | # Requrie a permission to view site in GUI
64 | # If empty or not set anyone can view (default)
65 | #PermissionToView: 'Perm.here'
66 |
67 | # VoteSite Material for some GUI's
68 | # Removing this may result in an error, required on each site
69 | DisplayItem:
70 | Material: 'DIAMOND'
71 | Amount: 1
72 |
73 | # Reward to run when cooldown ends for this votesite
74 | # Enable PerSiteCoolDownEvents in Config.yml to use this
75 | #CoolDownEndRewards:
76 | # Messages:
77 | # Player: '&aTime to go vote on site1'
78 |
79 | # Rewards to give
80 | # https://github.com/BenCodez/AdvancedCore/wiki/Rewards
81 | Rewards:
82 | # Execute console commands
83 | Commands:
84 | - 'say hello'
85 | # Send player a message
86 | Messages:
87 | Player: 'You voted'
88 | # Site 2 example
89 | Site2:
90 | Enabled: false
91 | Name: 'Site2'
92 | ServiceSite: 'Crafty.gg'
93 | VoteURL: 'link to vote URL here, used in /vote'
94 | VoteDelay: 24
95 | DisplayItem:
96 | Material: 'DIAMOND'
97 | Amount: 1
98 | Rewards:
99 | Commands:
100 | - 'say hello'
101 | # Advanced example
102 | # 50% chance for reward1, if reward1 not given then 20% chance to get reward2, if reward2 not given then fallback
103 | AdvancedPriority:
104 | # Similar to priority, but no need to have to use reward files
105 | # Add requirements under each reward
106 | # Will go in order from list here and try to run each of the following rewards...
107 | # This name can be anything, but they need to be different
108 | Reward1:
109 | Chance: 50
110 | # Any other requirement here
111 | # If any requirement fails, the next reward will be attempted
112 | # Use permission requirement for rank based rewards
113 | #RequirePermission: true
114 | #Permission: 'permhere'
115 | Messages:
116 | Player: 'You got first reward'
117 | Reward2:
118 | Chance: 20
119 | Messages:
120 | Player: 'You got second reward'
121 | # Fallback, 100% chance, after other rewards fail chances
122 | Fallback:
123 | Messages:
124 | Player: 'You got unlucky'
125 |
126 | # Give 1 diamond regardless of above
127 | Items:
128 | item1:
129 | Material: DIAMOND
130 | Amount: 1
131 |
132 | Messages:
133 | Player: 'You voted'
134 |
135 | # Reward for any site
136 | # Similar to AnySiteReward
137 | # This requires the site to be configured in order to get the reward.
138 | EverySiteReward: {}
--------------------------------------------------------------------------------
/VotingPlugin/src/main/resources/bungee.yml:
--------------------------------------------------------------------------------
1 | name: ${project.name}
2 | version: ${project.version}
3 | main: com.bencodez.votingplugin.proxy.bungee.VotingPluginBungee
4 | author: BenCodez
5 | softDepends:
6 | - RedisBungee
--------------------------------------------------------------------------------
/VotingPlugin/src/main/resources/votingpluginversion.yml:
--------------------------------------------------------------------------------
1 | time: '${timestamp}'
2 | profile: '${build.profile.id}'
3 | version: '${project.version}'
4 | buildnumber: '${build.number}'
--------------------------------------------------------------------------------
/VotingPlugin/src/test/java/com/bencodez/votingplugin/tests/HttpURLConnectionMock.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.tests;
2 |
3 | import static org.mockito.Mockito.mock;
4 | import static org.mockito.Mockito.when;
5 |
6 | import java.io.ByteArrayInputStream;
7 | import java.io.InputStream;
8 | import java.net.HttpURLConnection;
9 | import java.net.URL;
10 |
11 | public class HttpURLConnectionMock {
12 |
13 | public static void setupMockHttpURLConnection(String playerName, int responseCode, String responseBody)
14 | throws Exception {
15 | // Mock URL and HttpURLConnection
16 | URL mockUrl = mock(URL.class);
17 | HttpURLConnection mockConnection = mock(HttpURLConnection.class);
18 |
19 | when(mockUrl.openConnection()).thenReturn(mockConnection);
20 | when(mockConnection.getResponseCode()).thenReturn(responseCode);
21 | InputStream mockInputStream = new ByteArrayInputStream(responseBody.getBytes());
22 | when(mockConnection.getInputStream()).thenReturn(mockInputStream);
23 |
24 | // When new URL is called, return the mocked URL
25 | // Note: This requires PowerMockito or a similar tool to mock the `new` keyword
26 | // Here, it's simplified and assumes the method uses a helper that can be mocked
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/VotingPlugin/src/test/java/com/bencodez/votingplugin/tests/VotePartyTest.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BenCodez/VotingPlugin/4861c041e43ba6b3aec0d1ee98655aaa17d8bbf8/VotingPlugin/src/test/java/com/bencodez/votingplugin/tests/VotePartyTest.java
--------------------------------------------------------------------------------
/VotingPlugin/src/test/java/com/bencodez/votingplugin/tests/VoteSiteTest.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.tests;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertEquals;
4 | import static org.junit.jupiter.api.Assertions.assertTrue;
5 | import static org.mockito.ArgumentMatchers.anyString;
6 | import static org.mockito.Mockito.mock;
7 | import static org.mockito.Mockito.when;
8 |
9 | import java.util.ArrayList;
10 | import java.util.Arrays;
11 |
12 | import org.junit.jupiter.api.BeforeEach;
13 | import org.junit.jupiter.api.Test;
14 |
15 | import com.bencodez.votingplugin.VotingPluginMain;
16 | import com.bencodez.votingplugin.config.Config;
17 | import com.bencodez.votingplugin.config.ConfigVoteSites;
18 | import com.bencodez.votingplugin.data.ServerData;
19 | import com.bencodez.votingplugin.objects.VoteSite;
20 |
21 | public class VoteSiteTest {
22 |
23 | private VotingPluginMain plugin;
24 |
25 | @BeforeEach
26 | public void setUp() {
27 | // Create a mock instance of VotingPluginMain.
28 | plugin = mock(VotingPluginMain.class);
29 |
30 | // Create dummy stubs using Mockito for ConfigVoteSites.
31 | ConfigVoteSites dummyConfigVoteSites = mock(ConfigVoteSites.class);
32 | when(dummyConfigVoteSites.getVoteURL(anyString())).thenReturn("example.com");
33 | when(dummyConfigVoteSites.getServiceSite(anyString())).thenReturn("ServiceSite");
34 | when(dummyConfigVoteSites.getVoteDelay(anyString())).thenReturn(30.0);
35 | when(dummyConfigVoteSites.getVoteDelayMin(anyString())).thenReturn(15.0);
36 | when(dummyConfigVoteSites.getVoteSiteEnabled(anyString())).thenReturn(true);
37 | when(dummyConfigVoteSites.getPriority(anyString())).thenReturn(1);
38 | when(dummyConfigVoteSites.getDisplayName(anyString())).thenReturn("DisplayName");
39 | when(dummyConfigVoteSites.getItem(anyString())).thenReturn(null);
40 | // (Stub additional methods as needed)
41 |
42 | // Create a dummy Config.
43 | Config dummyConfigFile = mock(Config.class);
44 | when(dummyConfigFile.isFormatCommandsVoteForceLinks()).thenReturn(true);
45 | when(dummyConfigFile.getFormatBroadCastMsg()).thenReturn("Broadcast: {player} voted on {sitename}");
46 |
47 | // Create a dummy ServerData.
48 | ServerData dummyServerData = mock(ServerData.class);
49 | // Instead of casting Arrays.asList, wrap it in a new ArrayList.
50 | when(dummyServerData.getServiceSites())
51 | .thenReturn(new ArrayList<>(Arrays.asList("ServiceSite", "AnotherSite")));
52 |
53 | // Stub the plugin methods to return our dummy configuration objects.
54 | when(plugin.getConfigVoteSites()).thenReturn(dummyConfigVoteSites);
55 | when(plugin.getConfigFile()).thenReturn(dummyConfigFile);
56 | when(plugin.getServerData()).thenReturn(dummyServerData);
57 | }
58 |
59 | @Test
60 | public void testInitSetsValuesCorrectly() {
61 | // Construct a VoteSite with site name "site.test".
62 | VoteSite voteSite = new VoteSite(plugin, "site.test");
63 |
64 | // The key is created by replacing dots with underscores.
65 | assertEquals("site_test", voteSite.getKey(), "Key should have dots replaced with underscores");
66 |
67 | // The dummy config returns "DisplayName" for display name.
68 | assertEquals("DisplayName", voteSite.getDisplayName(), "Display name should be loaded from config");
69 |
70 | // voteURL is loaded from dummy and should be "example.com"
71 | assertEquals("example.com", voteSite.getVoteURL(false), "VoteURL should be set from config");
72 |
73 | // Service site, vote delays, and enabled flag are set as expected.
74 | assertEquals("ServiceSite", voteSite.getServiceSite(), "ServiceSite should be set from config");
75 | assertEquals(30.0, voteSite.getVoteDelay(), "VoteDelay should be set from config");
76 | assertEquals(15.0, voteSite.getVoteDelayMin(), "VoteDelayMin should be set from config");
77 | assertTrue(voteSite.isEnabled(), "VoteSite should be enabled");
78 | }
79 |
80 | @Test
81 | public void testGetVoteURLJson() {
82 | VoteSite voteSite = new VoteSite(plugin, "site.test");
83 | // After init, voteURL is "example.com" (from dummy config)
84 | // In getVoteURL(true), if the format-forced links option is enabled,
85 | // and since "example.com" does not start with "http", the returned string
86 | // should be:
87 | // [Text="example.com",url="http://example.com"]
88 | String url = voteSite.getVoteURL(true);
89 | assertEquals("[Text=\"example.com\",url=\"http://example.com\"]", url,
90 | "JSON-formatted vote URL should be generated correctly");
91 | }
92 |
93 | @Test
94 | public void testLoadingDebugContainsExpectedValues() {
95 | VoteSite voteSite = new VoteSite(plugin, "site.test");
96 | String debug = voteSite.loadingDebug();
97 | assertTrue(debug.contains("site_test"), "Debug output should contain the key");
98 | assertTrue(debug.contains("DisplayName"), "Debug output should contain the display name");
99 | assertTrue(debug.contains("30.0"), "Debug output should contain the vote delay");
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/VotingPlugin/src/test/java/com/bencodez/votingplugin/tests/VotingPluginProxyTest.java:
--------------------------------------------------------------------------------
1 |
2 | package com.bencodez.votingplugin.tests;
3 |
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
5 | import static org.mockito.Mockito.doNothing;
6 | import static org.mockito.Mockito.when;
7 |
8 | import org.junit.jupiter.api.BeforeEach;
9 | import org.junit.jupiter.api.Test;
10 | import org.mockito.InjectMocks;
11 | import org.mockito.Mock;
12 | import org.mockito.Mockito;
13 | import org.mockito.MockitoAnnotations;
14 |
15 | import com.bencodez.advancedcore.bungeeapi.globaldata.GlobalDataHandlerProxy;
16 | import com.bencodez.votingplugin.proxy.ProxyMysqlUserTable;
17 | import com.bencodez.votingplugin.proxy.VotingPluginProxy;
18 | import com.bencodez.votingplugin.proxy.VotingPluginProxyConfig;
19 | import com.bencodez.votingplugin.proxy.multiproxy.MultiProxyHandler;
20 |
21 | public class VotingPluginProxyTest {
22 |
23 | @InjectMocks
24 | private VotingPluginProxyTestImpl votingPluginProxy;
25 |
26 | @Mock
27 | private ProxyMysqlUserTable proxyMySQL;
28 |
29 | @Mock
30 | private VotingPluginProxyConfig config;
31 |
32 | @Mock
33 | private GlobalDataHandlerProxy globalDataHandler;
34 |
35 | @Mock
36 | private MultiProxyHandler multiProxyHandler;
37 |
38 | @BeforeEach
39 | void setUp() {
40 | MockitoAnnotations.openMocks(this);
41 | votingPluginProxy.setProxyMySQL(proxyMySQL);
42 | votingPluginProxy.setGlobalDataHandler(globalDataHandler);
43 | votingPluginProxy.setMultiProxyHandler(multiProxyHandler);
44 |
45 | // Mocking config methods
46 | when(config.getVotePartyEnabled()).thenReturn(true);
47 | when(config.getVotePartyVotesRequired()).thenReturn(5);
48 | when(config.getVotePartyIncreaseVotesRequired()).thenReturn(5);
49 | when(config.getBungeeManageTotals()).thenReturn(true);
50 | when(config.getPluginMessageEncryption()).thenReturn(false);
51 | when(config.getDebug()).thenReturn(false);
52 | }
53 |
54 | @Test
55 | void testAddVoteParty() {
56 | // Initial votePartyVotes should be 0
57 | assertEquals(0, votingPluginProxy.getVotePartyVotes());
58 |
59 | // Spy on the votingPluginProxy object
60 | VotingPluginProxy spyProxy = Mockito.spy(votingPluginProxy);
61 | doNothing().when(spyProxy).checkVoteParty();
62 |
63 | // Add one vote party
64 | spyProxy.addCurrentVotePartyVotes(1);
65 |
66 | // Verify that votePartyVotes increased by 1
67 | assertEquals(1, spyProxy.getVotePartyVotes());
68 | }
69 |
70 |
71 |
72 | @Test
73 | void testAddCurrentVotePartyVotes() {
74 | // Initial votePartyVotes should be 0
75 | assertEquals(0, votingPluginProxy.getVotePartyVotes());
76 |
77 | // Add 3 votes
78 | votingPluginProxy.addCurrentVotePartyVotes(3);
79 | assertEquals(3, votingPluginProxy.getVotePartyVotes());
80 |
81 | // Add 2 more votes
82 | votingPluginProxy.addCurrentVotePartyVotes(2);
83 | assertEquals(5, votingPluginProxy.getVotePartyVotes());
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/VotingPlugin/src/test/java/com/bencodez/votingplugin/tests/VotingPluginProxyTestImpl.java:
--------------------------------------------------------------------------------
1 | package com.bencodez.votingplugin.tests;
2 |
3 | import java.io.File;
4 | import java.util.Arrays;
5 | import java.util.HashSet;
6 | import java.util.Set;
7 | import java.util.UUID;
8 |
9 | import org.mockito.Mockito;
10 |
11 | import com.bencodez.votingplugin.proxy.VotingPluginProxy;
12 | import com.bencodez.votingplugin.proxy.VotingPluginProxyConfig;
13 |
14 | public class VotingPluginProxyTestImpl extends VotingPluginProxy {
15 |
16 | @Override
17 | public void addNonVotedPlayer(String uuid, String playerName) {
18 | // Implementation for testing purposes
19 | }
20 |
21 | @Override
22 | public void broadcast(String message) {
23 | // Implementation for testing purposes
24 | }
25 |
26 | @Override
27 | public Set getAllAvailableServers() {
28 | return new HashSet<>(Arrays.asList("Server1", "Server2"));
29 | }
30 |
31 | @Override
32 | public VotingPluginProxyConfig getConfig() {
33 | return Mockito.mock(VotingPluginProxyConfig.class);
34 | }
35 |
36 | @Override
37 | public String getCurrentPlayerServer(String player) {
38 | return "Server1";
39 | }
40 |
41 | @Override
42 | public File getDataFolderPlugin() {
43 | return new File(".");
44 | }
45 |
46 | @Override
47 | public String getProperName(String uuid, String playerName) {
48 | return playerName;
49 | }
50 |
51 | @Override
52 | public String getUUID(String playerName) {
53 | return UUID.randomUUID().toString();
54 | }
55 |
56 | @Override
57 | public String getPluginVersion() {
58 | return "1.0.0";
59 | }
60 |
61 | @Override
62 | public int getVoteCacheCurrentVotePartyVotes() {
63 | return 0;
64 | }
65 |
66 | @Override
67 | public long getVoteCacheLastUpdated() {
68 | return System.currentTimeMillis();
69 | }
70 |
71 | @Override
72 | public int getVoteCachePrevDay() {
73 | return 1;
74 | }
75 |
76 | @Override
77 | public String getVoteCachePrevMonth() {
78 | return "January-2023";
79 | }
80 |
81 | @Override
82 | public int getVoteCachePrevWeek() {
83 | return 1;
84 | }
85 |
86 | @Override
87 | public int getVoteCacheVotePartyIncreaseVotesRequired() {
88 | return 10;
89 | }
90 |
91 | @Override
92 | public boolean isPlayerOnline(String playerName) {
93 | return true;
94 | }
95 |
96 | @Override
97 | public boolean isServerValid(String server) {
98 | return true;
99 | }
100 |
101 | @Override
102 | public boolean isSomeoneOnlineServer(String server) {
103 | return true;
104 | }
105 |
106 | @Override
107 | public boolean isVoteCacheIgnoreTime() {
108 | return false;
109 | }
110 |
111 | @Override
112 | public void runAsync(Runnable run) {
113 | run.run();
114 | }
115 |
116 | @Override
117 | public void runConsoleCommand(String command) {
118 | // Mocked for testing
119 | }
120 |
121 | @Override
122 | public void saveVoteCacheFile() {
123 | // Mocked for testing
124 | }
125 |
126 | @Override
127 | public void reloadCore(boolean mysql) {
128 | // Mocked for testing
129 | }
130 |
131 | @Override
132 | public void log(String message) {
133 | // For testing, simply print the message
134 | System.out.println("LOG: " + message);
135 | }
136 |
137 | @Override
138 | public void logSevere(String message) {
139 | // For testing, simply print the severe message
140 | System.err.println("SEVERE: " + message);
141 | }
142 |
143 | @Override
144 | public void warn(String message) {
145 | // For testing, simply print the warning message
146 | System.err.println("WARNING: " + message);
147 | }
148 |
149 | @Override
150 | public void debug(String str) {
151 | // TODO Auto-generated method stub
152 |
153 | }
154 |
155 | @Override
156 | public void sendPluginMessageData(String server, String channel, byte[] data, boolean queue) {
157 | // TODO Auto-generated method stub
158 |
159 | }
160 |
161 | @Override
162 | public void setVoteCacheLastUpdated() {
163 | // TODO Auto-generated method stub
164 |
165 | }
166 |
167 | @Override
168 | public void setVoteCachePrevDay(int day) {
169 | // TODO Auto-generated method stub
170 |
171 | }
172 |
173 | @Override
174 | public void setVoteCachePrevMonth(String text) {
175 | // TODO Auto-generated method stub
176 |
177 | }
178 |
179 | @Override
180 | public void setVoteCachePrevWeek(int week) {
181 | // TODO Auto-generated method stub
182 |
183 | }
184 |
185 | @Override
186 | public void setVoteCacheVoteCacheIgnoreTime(boolean ignore) {
187 | // TODO Auto-generated method stub
188 |
189 | }
190 |
191 | @Override
192 | public void setVoteCacheVotePartyCurrentVotes(int votes) {
193 | // TODO Auto-generated method stub
194 |
195 | }
196 |
197 | @Override
198 | public void setVoteCacheVotePartyIncreaseVotesRequired(int votes) {
199 | // TODO Auto-generated method stub
200 |
201 | }
202 | }
203 |
--------------------------------------------------------------------------------
/VotingPlugin/src/test/java/com/bencodez/votingplugin/tests/VotingPluginProxyVoteCacheTest.java:
--------------------------------------------------------------------------------
1 |
2 | package com.bencodez.votingplugin.tests;
3 |
4 | import static org.junit.jupiter.api.Assertions.assertFalse;
5 | import static org.junit.jupiter.api.Assertions.assertTrue;
6 | import static org.mockito.ArgumentMatchers.anyString;
7 | import static org.mockito.ArgumentMatchers.eq;
8 | import static org.mockito.Mockito.CALLS_REAL_METHODS;
9 | import static org.mockito.Mockito.mock;
10 | import static org.mockito.Mockito.never;
11 | import static org.mockito.Mockito.verify;
12 | import static org.mockito.Mockito.when;
13 |
14 | import java.time.LocalDateTime;
15 | import java.time.ZoneId;
16 | import java.util.ArrayList;
17 | import java.util.UUID;
18 | import java.util.concurrent.ConcurrentHashMap;
19 |
20 | import org.junit.jupiter.api.BeforeEach;
21 | import org.junit.jupiter.api.Test;
22 |
23 | import com.bencodez.votingplugin.proxy.OfflineBungeeVote;
24 | import com.bencodez.votingplugin.proxy.VotingPluginProxy;
25 | import com.bencodez.votingplugin.proxy.VotingPluginProxyConfig;
26 |
27 | public class VotingPluginProxyVoteCacheTest {
28 | private VotingPluginProxy proxy;
29 | private VotingPluginProxyConfig config;
30 | private ConcurrentHashMap> cachedOnlineVotes;
31 | private ConcurrentHashMap> cachedVotes;
32 |
33 | @BeforeEach
34 | public void setUp() {
35 | proxy = mock(VotingPluginProxy.class, CALLS_REAL_METHODS);
36 | config = mock(VotingPluginProxyConfig.class);
37 | when(proxy.getConfig()).thenReturn(config);
38 | cachedOnlineVotes = new ConcurrentHashMap<>();
39 | cachedVotes = new ConcurrentHashMap<>();
40 | proxy.setCachedOnlineVotes(cachedOnlineVotes);
41 | proxy.setCachedVotes(cachedVotes);
42 | }
43 |
44 | @Test
45 | void checkVoteCacheTime_removesExpiredVotesFromCachedOnlineVotes() {
46 | when(config.getVoteCacheTime()).thenReturn(1); // 1 day
47 | long currentTime = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
48 | long expiredTime = currentTime - (2 * 24 * 60 * 60 * 1000); // 2 days ago
49 |
50 | ArrayList votes = new ArrayList<>();
51 | votes.add(new OfflineBungeeVote("player1", "uuid1", "service1", expiredTime, true, "text1"));
52 | cachedOnlineVotes.put("server1", votes);
53 |
54 | proxy.checkVoteCacheTime();
55 |
56 | assertTrue(cachedOnlineVotes.get("server1").isEmpty());
57 | }
58 |
59 | @Test
60 | void checkVoteCacheTime_doesNotRemoveNonExpiredVotesFromCachedOnlineVotes() {
61 | when(config.getVoteCacheTime()).thenReturn(1); // 1 day
62 | long currentTime = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
63 | long validTime = currentTime - (12 * 60 * 60 * 1000); // 12 hours ago
64 |
65 | ArrayList votes = new ArrayList<>();
66 | votes.add(new OfflineBungeeVote("player1", "uuid1", "service1", validTime, true, "text1"));
67 | cachedOnlineVotes.put("server1", votes);
68 |
69 | proxy.checkVoteCacheTime();
70 |
71 | assertFalse(cachedOnlineVotes.get("server1").isEmpty());
72 | }
73 |
74 | @Test
75 | void checkVoteCacheTime_removesExpiredVotesFromCachedVotes() {
76 | when(config.getVoteCacheTime()).thenReturn(1); // 1 day
77 | long currentTime = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
78 | long expiredTime = currentTime - (2 * 24 * 60 * 60 * 1000); // 2 days ago
79 |
80 | ArrayList votes = new ArrayList<>();
81 | votes.add(new OfflineBungeeVote("player1", "uuid1", "service1", expiredTime, true, "text1"));
82 | cachedVotes.put("server1", votes);
83 |
84 | proxy.checkVoteCacheTime();
85 |
86 | assertTrue(cachedVotes.get("server1").isEmpty());
87 | }
88 |
89 | @Test
90 | void checkVoteCacheTime_doesNotRemoveNonExpiredVotesFromCachedVotes() {
91 | when(config.getVoteCacheTime()).thenReturn(1); // 1 day
92 | long currentTime = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
93 | long validTime = currentTime - (12 * 60 * 60 * 1000); // 12 hours ago
94 |
95 | ArrayList votes = new ArrayList<>();
96 | votes.add(new OfflineBungeeVote("player1", "uuid1", "service1", validTime, true, "text1"));
97 | cachedVotes.put("server1", votes);
98 |
99 | proxy.checkVoteCacheTime();
100 |
101 | assertFalse(cachedVotes.get("server1").isEmpty());
102 | }
103 | }
104 |
--------------------------------------------------------------------------------