mirror of
https://github.com/BenCodez/VotingPlugin.git
synced 2026-11-04 09:02:00 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe401f1988 | ||
|
|
14feedf4f0 | ||
|
|
1aa360d844 | ||
|
|
4b899c2175 | ||
|
|
8bea5b70ec | ||
|
|
6e986f0e3a | ||
|
|
09fcb7f926 | ||
|
|
920e243fc4 | ||
|
|
02b8d013ab | ||
|
|
2193fa4e1a | ||
|
|
6e6986a373 | ||
|
|
121cca6a97 | ||
|
|
c633baa12b | ||
|
|
b3aec70ebc | ||
|
|
bf08a03059 | ||
|
|
b6542debaf | ||
|
|
549686fd37 | ||
|
|
1166db03ec | ||
|
|
e4bbd982a2 | ||
|
|
3112e76227 | ||
|
|
e3088f5e70 | ||
|
|
7137de2ce3 | ||
|
|
2c97bc171f | ||
|
|
df950984c3 | ||
|
|
11f54ef959 | ||
|
|
213623835d | ||
|
|
2dc6af10b1 | ||
|
|
8e8c10c7a2 | ||
|
|
35dc993bf1 | ||
|
|
425374a757 | ||
|
|
a74a7e35b8 | ||
|
|
49d8020fd1 | ||
|
|
4db6239653 | ||
|
|
71f3894a5d | ||
|
|
ded0b93880 | ||
|
|
dcb29e3cca | ||
|
|
6c24ae9397 | ||
|
|
285a19c422 | ||
|
|
55fc3dc0b1 | ||
|
|
0516a4f679 | ||
|
|
b73a82cba9 | ||
|
|
f89ad455cb | ||
|
|
5cc9650728 | ||
|
|
14f0197bc3 | ||
|
|
13e59f3c6b | ||
|
|
8f5ed0c95e | ||
|
|
1a6da05234 | ||
|
|
8193c255c2 | ||
|
|
3b664e7fa7 | ||
|
|
11439f16da | ||
|
|
57ff828998 | ||
|
|
8bb0fec810 | ||
|
|
de18c48c5f | ||
|
|
79f41ec605 | ||
|
|
796978fbf2 | ||
|
|
bbd77d1686 | ||
|
|
00da2b575d | ||
|
|
261187abc4 | ||
|
|
671b7c7add | ||
|
|
279b71c4b5 | ||
|
|
cd6289ab47 | ||
|
|
bdb520af09 | ||
|
|
6891a79c66 | ||
|
|
0e91c94cc8 | ||
|
|
f3d914e60c | ||
|
|
a5758435f9 | ||
|
|
e35bb0fe74 | ||
|
|
1b96deb150 | ||
|
|
1fe998afaf | ||
|
|
4ea6abcd1a | ||
|
|
c49d040473 | ||
|
|
3cd181636b | ||
|
|
43494bef1d | ||
|
|
6fe027223b | ||
|
|
d7dbcb4f44 | ||
|
|
f37a0671c7 | ||
|
|
47bdadfe27 | ||
|
|
10842a8d51 | ||
|
|
8e1d0024db | ||
|
|
bd119f3ac1 | ||
|
|
d0a207606e | ||
|
|
e594b42000 | ||
|
|
f59b4cc0f1 | ||
|
|
1aefbf77f5 | ||
|
|
b84658d130 | ||
|
|
72348add0c | ||
|
|
b3c631db9c | ||
|
|
46eb737296 | ||
|
|
64c335bd3b | ||
|
|
bde1f74223 | ||
|
|
42af35ae43 | ||
|
|
ffa9234bf2 | ||
|
|
398318d25f | ||
|
|
498c323ce7 | ||
|
|
eb73987ff0 | ||
|
|
0d7134e0e7 | ||
|
|
61ca4776e7 | ||
|
|
0a5c731b55 | ||
|
|
eb6faba7a5 |
No files matched your search
@@ -22,10 +22,10 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up JDK 17
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: '17'
|
||||
java-version: '21'
|
||||
distribution: 'temurin'
|
||||
cache: maven
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@ jobs:
|
||||
with:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
javadoc-branch: gh-pages
|
||||
java-version: 17
|
||||
java-version: 21
|
||||
target-folder: ''
|
||||
project: maven # or gradle
|
||||
# subdirectories: moduleA moduleB #for subdirectories support, needs to be run with custom command
|
||||
custom-command: mvn -f VotingPlugin/pom.xml deploy -P javadoc javadoc:aggregate
|
||||
javadoc-source-folder: 'VotingPlugin/target/apidocs'
|
||||
javadoc-source-folder: 'VotingPlugin/target/reports/apidocs'
|
||||
+34
-52
@@ -4,16 +4,17 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.bencodez</groupId>
|
||||
<artifactId>votingplugin</artifactId>
|
||||
<version>7.0</version>
|
||||
<version>7.1</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>VotingPlugin</name>
|
||||
<properties>
|
||||
<github.global.server>github</github.global.server>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<build.number>NOTSET</build.number>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<maven.compiler.release>8</maven.compiler.release>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<maven.compiler.release>21</maven.compiler.release>
|
||||
<velocity.version>3.4.0</velocity.version>
|
||||
</properties>
|
||||
<build>
|
||||
<resources>
|
||||
@@ -68,28 +69,29 @@
|
||||
</pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok-maven-plugin</artifactId>
|
||||
<version>1.18.20.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>delombok</id>
|
||||
<phase>deploy</phase>
|
||||
<goals>
|
||||
<goal>delombok</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<addOutputDirectory>false</addOutputDirectory>
|
||||
<outputDirectory>${project.basedir}/target/delombok</outputDirectory>
|
||||
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.13.0</version>
|
||||
<configuration>
|
||||
<release>21</release>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.42</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>com.velocitypowered</groupId>
|
||||
<artifactId>velocity-api</artifactId>
|
||||
<version>${velocity.version}</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.6.1</version>
|
||||
<version>3.6.2</version>
|
||||
<configuration>
|
||||
<shadedArtifactAttached>false</shadedArtifactAttached>
|
||||
<minimizeJar>false</minimizeJar>
|
||||
@@ -235,7 +237,7 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.21.11-R0.1-SNAPSHOT</version>
|
||||
<version>26.1.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -265,25 +267,25 @@
|
||||
<dependency>
|
||||
<groupId>com.velocitypowered</groupId>
|
||||
<artifactId>velocity-api</artifactId>
|
||||
<version>3.4.0</version>
|
||||
<version>${velocity.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-velocity</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.2.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.11.6</version>
|
||||
<version>2.12.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.bencodez</groupId>
|
||||
<artifactId>advancedcore</artifactId>
|
||||
<version>3.8</version>
|
||||
<version>3.8.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -307,7 +309,7 @@
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-junit-jupiter</artifactId>
|
||||
<version>5.15.2</version>
|
||||
<version>5.23.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -319,17 +321,17 @@
|
||||
<dependency>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
<artifactId>configurate-core</artifactId>
|
||||
<version>4.1.2</version>
|
||||
<version>4.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
<artifactId>configurate-yaml</artifactId>
|
||||
<version>4.1.2</version>
|
||||
<version>4.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
<artifactId>configurate-gson</artifactId>
|
||||
<version>4.1.2</version>
|
||||
<version>4.2.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<profiles>
|
||||
@@ -387,29 +389,9 @@
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
<finalName>
|
||||
${project.name}</finalName>
|
||||
${project.name}-${build.number}</finalName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.coderplus.maven.plugins</groupId>
|
||||
<artifactId>copy-rename-maven-plugin</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-file</id>
|
||||
<phase>install</phase>
|
||||
<goals>
|
||||
<goal>copy</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceFile>
|
||||
${project.basedir}/target/${project.name}.jar</sourceFile>
|
||||
<destinationFile>
|
||||
${project.basedir}/target/${project.name}-${build.number}.jar</destinationFile>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
|
||||
@@ -47,6 +47,9 @@ import com.bencodez.votingplugin.votesites.VoteSite;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Handler for Bungee/proxy server integration.
|
||||
*/
|
||||
public class BungeeHandler implements Listener {
|
||||
@Getter
|
||||
private ClientHandler clientHandler;
|
||||
@@ -86,10 +89,18 @@ public class BungeeHandler implements Listener {
|
||||
@Getter
|
||||
private MqttHandler mqttHandler;
|
||||
|
||||
/**
|
||||
* Constructs a new BungeeHandler.
|
||||
*
|
||||
* @param plugin the main plugin instance
|
||||
*/
|
||||
public BungeeHandler(VotingPluginMain plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks and processes global data from the global data handler.
|
||||
*/
|
||||
public void checkGlobalData() {
|
||||
HashMap<String, DataValue> data = globalDataHandler.getExact(plugin.getBungeeSettings().getServer());
|
||||
|
||||
@@ -126,6 +137,13 @@ public class BungeeHandler implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks global data for a time type change.
|
||||
*
|
||||
* @param type the time type to check
|
||||
* @param data the global data map
|
||||
* @return true if currently processing a time change
|
||||
*/
|
||||
public boolean checkGlobalDataTime(TimeType type, HashMap<String, DataValue> data) {
|
||||
boolean isProcessing = false;
|
||||
if (data.containsKey(type.toString())) {
|
||||
@@ -157,6 +175,12 @@ public class BungeeHandler implements Listener {
|
||||
return isProcessing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks and extracts the boolean value from a DataValue.
|
||||
*
|
||||
* @param data the data value
|
||||
* @return the boolean value
|
||||
*/
|
||||
public boolean checkGlobalDataTimeValue(DataValue data) {
|
||||
if (data.isBoolean()) {
|
||||
return data.getBoolean();
|
||||
@@ -164,6 +188,9 @@ public class BungeeHandler implements Listener {
|
||||
return Boolean.valueOf(data.getString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes and cleans up all handlers and connections.
|
||||
*/
|
||||
public void close() {
|
||||
if (backendMysqlMessenger != null) {
|
||||
backendMysqlMessenger.shutdown();
|
||||
@@ -182,6 +209,9 @@ public class BungeeHandler implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads and initializes the bungee handler with the configured method.
|
||||
*/
|
||||
public void load() {
|
||||
plugin.debug("Loading bungee handler");
|
||||
|
||||
@@ -247,23 +277,25 @@ public class BungeeHandler implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.debug("pluginmessaging voteupdate received for " + playerUuid);
|
||||
plugin.debug("pluginmessaging voteupdate received for " + playerUuid + ": " + v.votePartyCurrent + "/"
|
||||
+ v.votePartyRequired + " on " + v.service);
|
||||
|
||||
// Vote party cache update
|
||||
if (v.votePartyCurrent >= 0 || bungeeVotePartyCurrent == -2) {
|
||||
bungeeVotePartyCurrent = v.votePartyCurrent;
|
||||
}
|
||||
if (v.votePartyRequired >= 0 || bungeeVotePartyRequired == -2) {
|
||||
bungeeVotePartyRequired = v.votePartyRequired;
|
||||
}
|
||||
plugin.getServerData().setBungeeVotePartyCurrent(bungeeVotePartyCurrent);
|
||||
plugin.getServerData().setBungeeVotePartyRequired(bungeeVotePartyRequired);
|
||||
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager()
|
||||
.getVotingPluginUser(UUID.fromString(playerUuid));
|
||||
user.cache();
|
||||
|
||||
user.offVote();
|
||||
|
||||
// Vote party cache update
|
||||
if (v.votePartyCurrent != 0 || bungeeVotePartyCurrent == -2) {
|
||||
bungeeVotePartyCurrent = v.votePartyCurrent;
|
||||
}
|
||||
if (v.votePartyRequired != 0 || bungeeVotePartyRequired == -2) {
|
||||
bungeeVotePartyRequired = v.votePartyRequired;
|
||||
}
|
||||
plugin.getServerData().setBungeeVotePartyCurrent(bungeeVotePartyCurrent);
|
||||
plugin.getServerData().setBungeeVotePartyRequired(bungeeVotePartyRequired);
|
||||
|
||||
// Optional: update last vote time for a service
|
||||
String service = v.service;
|
||||
long time = v.time;
|
||||
@@ -550,7 +582,6 @@ public class BungeeHandler implements Listener {
|
||||
|
||||
bungeeVotePartyCurrent = text.getVotePartyCurrent();
|
||||
bungeeVotePartyRequired = text.getVotePartyRequired();
|
||||
plugin.getPlaceholders().onBungeeVotePartyUpdate();
|
||||
plugin.getServerData().setBungeeVotePartyCurrent(bungeeVotePartyCurrent);
|
||||
plugin.getServerData().setBungeeVotePartyRequired(bungeeVotePartyRequired);
|
||||
|
||||
@@ -576,6 +607,9 @@ public class BungeeHandler implements Listener {
|
||||
int _ignored = v.numberOfVotes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the global MySQL handler for cross-server data synchronization.
|
||||
*/
|
||||
public void loadGlobalMysql() {
|
||||
if (plugin.getBungeeSettings().isGloblalDataEnabled()) {
|
||||
if (timer != null) {
|
||||
|
||||
@@ -88,8 +88,10 @@ import com.bencodez.votingplugin.listeners.VotingPluginUpdateEvent;
|
||||
import com.bencodez.votingplugin.placeholders.MVdWPlaceholders;
|
||||
import com.bencodez.votingplugin.placeholders.PlaceHolders;
|
||||
import com.bencodez.votingplugin.placeholders.VotingPluginExpansion;
|
||||
import com.bencodez.votingplugin.presets.VoteSitePresetSetupHandler;
|
||||
import com.bencodez.votingplugin.servicesites.ServiceSiteHandler;
|
||||
import com.bencodez.votingplugin.signs.Signs;
|
||||
import com.bencodez.votingplugin.specialrewards.NameMCLikeCheckerTask;
|
||||
import com.bencodez.votingplugin.specialrewards.SpecialRewards;
|
||||
import com.bencodez.votingplugin.specialrewards.votemilestones.VoteMilestonesManager;
|
||||
import com.bencodez.votingplugin.specialrewards.voteparty.VoteParty;
|
||||
@@ -111,6 +113,7 @@ import com.bencodez.votingplugin.votereminding.VoteRemindersLegacyMigrator;
|
||||
import com.bencodez.votingplugin.votereminding.VoteRemindersListener;
|
||||
import com.bencodez.votingplugin.votereminding.VoteRemindersManager;
|
||||
import com.bencodez.votingplugin.votereminding.store.UserDataVoteReminderCooldownStore;
|
||||
import com.bencodez.votingplugin.voteshop.VoteShopManager;
|
||||
import com.bencodez.votingplugin.votesites.VoteSite;
|
||||
import com.bencodez.votingplugin.votesites.VoteSiteManager;
|
||||
import com.bencodez.votingplugin.webhook.VotingPluginWebhooks;
|
||||
@@ -150,6 +153,9 @@ public class VotingPluginMain extends AdvancedCorePlugin {
|
||||
@Getter
|
||||
private CommandLoader commandLoader;
|
||||
|
||||
@Getter
|
||||
private NameMCLikeCheckerTask nameMCLikeCheckerTask;
|
||||
|
||||
@Getter
|
||||
private Config configFile;
|
||||
|
||||
@@ -221,6 +227,10 @@ public class VotingPluginMain extends AdvancedCorePlugin {
|
||||
@Getter
|
||||
private boolean updateStarted = false;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private VoteShopManager voteShopManager;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private ArrayList<CommandHandler> voteCommand;
|
||||
@@ -260,6 +270,10 @@ public class VotingPluginMain extends AdvancedCorePlugin {
|
||||
|
||||
private boolean firstTimeLoaded = false;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private VoteSitePresetSetupHandler presetHandler;
|
||||
|
||||
@Getter
|
||||
private DiscordHandler discordHandler;
|
||||
|
||||
@@ -332,6 +346,10 @@ public class VotingPluginMain extends AdvancedCorePlugin {
|
||||
}
|
||||
}
|
||||
|
||||
public void loadVoteShopManager() {
|
||||
voteShopManager = new VoteShopManager(this);
|
||||
}
|
||||
|
||||
public ArrayList<TopVoterPlayer> convertSet(Set<TopVoterPlayer> set) {
|
||||
return new ArrayList<>(set);
|
||||
}
|
||||
@@ -430,6 +448,36 @@ public class VotingPluginMain extends AdvancedCorePlugin {
|
||||
@Getter
|
||||
private VoteStreakHandler voteStreakHandler;
|
||||
|
||||
/**
|
||||
* Registers a directly editable rewards path from SpecialRewards.yml.
|
||||
*
|
||||
* @param rewardPath full configuration path to the rewards section
|
||||
*/
|
||||
private void addSpecialRewardsEditorPath(String rewardPath) {
|
||||
addDirectlyDefinedRewards(new DirectlyDefinedReward(rewardPath) {
|
||||
|
||||
@Override
|
||||
public void setData(String path, Object value) {
|
||||
plugin.getSpecialRewardsConfig().getData().set(path, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createSection(String key) {
|
||||
plugin.getSpecialRewardsConfig().getData().createSection(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurationSection getFileData() {
|
||||
return plugin.getSpecialRewardsConfig().getData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
plugin.getSpecialRewardsConfig().saveData();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void loadDirectlyDefined() {
|
||||
getRewardHandler().getDirectlyDefinedRewards().clear();
|
||||
|
||||
@@ -857,37 +905,64 @@ public class VotingPluginMain extends AdvancedCorePlugin {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// VoteMilestones (NEW system)
|
||||
|
||||
ConfigurationSection voteMilestonesSection = plugin.getSpecialRewardsConfig().getData()
|
||||
.getConfigurationSection("VoteMilestones");
|
||||
|
||||
if (voteMilestonesSection != null) {
|
||||
for (String milestoneId : voteMilestonesSection.getKeys(false)) {
|
||||
addSpecialRewardsEditorPath("VoteMilestones." + milestoneId + ".Rewards");
|
||||
}
|
||||
}
|
||||
|
||||
// VoteStreak rewards
|
||||
ConfigurationSection voteStreaksSection = plugin.getSpecialRewardsConfig().getData()
|
||||
.getConfigurationSection("VoteStreaks");
|
||||
|
||||
// Direct edit path: VoteMilestones.<id>.Rewards
|
||||
addDirectlyDefinedRewards(new DirectlyDefinedReward("VoteMilestones." + milestoneId + ".Rewards") {
|
||||
if (voteStreaksSection != null) {
|
||||
for (String streakId : voteStreaksSection.getKeys(false)) {
|
||||
if ("ProgressGroups".equalsIgnoreCase(streakId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(String path, Object value) {
|
||||
plugin.getSpecialRewardsConfig().getData().set(path, value);
|
||||
ConfigurationSection streakSection = voteStreaksSection.getConfigurationSection(streakId);
|
||||
if (streakSection == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
addSpecialRewardsEditorPath("VoteStreaks." + streakId + ".Rewards");
|
||||
}
|
||||
|
||||
ConfigurationSection progressGroupsSection = voteStreaksSection.getConfigurationSection("ProgressGroups");
|
||||
|
||||
if (progressGroupsSection != null) {
|
||||
for (String groupId : progressGroupsSection.getKeys(false)) {
|
||||
ConfigurationSection groupSection = progressGroupsSection.getConfigurationSection(groupId);
|
||||
if (groupSection == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createSection(String key) {
|
||||
plugin.getSpecialRewardsConfig().getData().createSection(key);
|
||||
addSpecialRewardsEditorPath(
|
||||
"VoteStreaks.ProgressGroups." + groupId + ".LostRewards");
|
||||
|
||||
ConfigurationSection milestonesSection = groupSection.getConfigurationSection("Milestones");
|
||||
if (milestonesSection == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurationSection getFileData() {
|
||||
return plugin.getSpecialRewardsConfig().getData();
|
||||
}
|
||||
for (String milestoneId : milestonesSection.getKeys(false)) {
|
||||
ConfigurationSection milestoneSection = milestonesSection
|
||||
.getConfigurationSection(milestoneId);
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
plugin.getSpecialRewardsConfig().saveData();
|
||||
if (milestoneSection == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
addSpecialRewardsEditorPath(
|
||||
"VoteStreaks.ProgressGroups." + groupId
|
||||
+ ".Milestones." + milestoneId + ".Rewards");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1023,6 +1098,64 @@ public class VotingPluginMain extends AdvancedCorePlugin {
|
||||
});
|
||||
}
|
||||
|
||||
ConfigurationSection categoriesSection = plugin.getShopFile().getCategoriesSection();
|
||||
if (categoriesSection != null) {
|
||||
for (String categoryShop : categoriesSection.getKeys(false)) {
|
||||
if (plugin.getShopFile().getCategoryShopSection(categoryShop) != null) {
|
||||
for (String categoryShopItems : plugin.getShopFile().getCategoryShopSection(categoryShop)
|
||||
.getKeys(false)) {
|
||||
addDirectlyDefinedRewards(new DirectlyDefinedReward(
|
||||
"Categories." + categoryShop + "." + categoryShopItems + ".Rewards") {
|
||||
|
||||
@Override
|
||||
public void createSection(String key) {
|
||||
getShopFile().createSection(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurationSection getFileData() {
|
||||
return getShopFile().getData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
getShopFile().saveData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(String path, Object value) {
|
||||
getShopFile().setValue(path, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NameMC like reward
|
||||
addDirectlyDefinedRewards(new DirectlyDefinedReward("NameMCLikeReward.Rewards") {
|
||||
|
||||
@Override
|
||||
public void createSection(String key) {
|
||||
getSpecialRewardsConfig().createSection(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurationSection getFileData() {
|
||||
return getSpecialRewardsConfig().getData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
getSpecialRewardsConfig().saveData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(String path, Object value) {
|
||||
getSpecialRewardsConfig().setValue(path, value);
|
||||
}
|
||||
});
|
||||
|
||||
addDirectlyDefinedRewards(new DirectlyDefinedReward("BungeeVotePartyRewards") {
|
||||
|
||||
@Override
|
||||
@@ -1167,6 +1300,8 @@ public class VotingPluginMain extends AdvancedCorePlugin {
|
||||
|
||||
loadVoteBroadcast();
|
||||
|
||||
loadVoteShopManager();
|
||||
|
||||
loadDirectlyDefined();
|
||||
checkUpdate = new CheckUpdate(this);
|
||||
checkUpdate.startUp();
|
||||
@@ -1250,6 +1385,14 @@ public class VotingPluginMain extends AdvancedCorePlugin {
|
||||
webhooks = new VotingPluginWebhooks(this);
|
||||
webhooks.reload(getConfig().getConfigurationSection("Webhooks"));
|
||||
|
||||
if (getSpecialRewardsConfig().isNameMCLikeRewardEnabled()) {
|
||||
nameMCLikeCheckerTask = new NameMCLikeCheckerTask(this);
|
||||
|
||||
long interval = Math.max(1, getSpecialRewardsConfig().getNameMCLikeRewardCheckIntervalMinutes()) * 60L
|
||||
* 20L;
|
||||
nameMCLikeCheckerTask.runTaskTimerAsynchronously(this, 20L, interval);
|
||||
}
|
||||
|
||||
// Add rewards
|
||||
getRewardHandler().addInjectedReward(new RewardInjectInt("Points", 0) {
|
||||
|
||||
@@ -1706,6 +1849,8 @@ public class VotingPluginMain extends AdvancedCorePlugin {
|
||||
|
||||
loadVoteBroadcast();
|
||||
|
||||
voteShopManager.reload();
|
||||
|
||||
loadDirectlyDefined();
|
||||
|
||||
setUpdate(true);
|
||||
|
||||
@@ -31,16 +31,40 @@ public final class BroadcastFormat {
|
||||
private final String header;
|
||||
private final String listLine;
|
||||
|
||||
/**
|
||||
* Constructor for BroadcastFormat.
|
||||
*
|
||||
* @param broadcastMsg the broadcast message template
|
||||
* @param header the header template
|
||||
* @param listLine the list line template
|
||||
*/
|
||||
public BroadcastFormat(String broadcastMsg, String header, String listLine) {
|
||||
this.broadcastMsg = broadcastMsg == null ? "" : broadcastMsg;
|
||||
this.header = header == null ? "" : header;
|
||||
this.listLine = listLine == null ? "" : listLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the broadcast with player name, items, and reason.
|
||||
*
|
||||
* @param playerName the player name
|
||||
* @param items the list of items
|
||||
* @param reason the reason string
|
||||
* @return the rendered list of strings
|
||||
*/
|
||||
public List<String> render(String playerName, List<String> items, String reason) {
|
||||
return render(playerName, items, reason, Collections.<String, String>emptyMap());
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the broadcast with player name, items, reason, and context.
|
||||
*
|
||||
* @param playerName the player name
|
||||
* @param items the list of items
|
||||
* @param reason the reason string
|
||||
* @param context additional context placeholders
|
||||
* @return the rendered list of strings
|
||||
*/
|
||||
public List<String> render(String playerName, List<String> items, String reason, Map<String, String> context) {
|
||||
List<String> output = new ArrayList<String>();
|
||||
int count = items == null ? 0 : items.size();
|
||||
|
||||
@@ -58,6 +58,13 @@ public final class BroadcastHandler {
|
||||
private final ConcurrentHashMap<UUID, LinkedHashSet<String>> intervalSites = new ConcurrentHashMap<UUID, LinkedHashSet<String>>();
|
||||
private volatile BukkitTask intervalTask;
|
||||
|
||||
/**
|
||||
* Constructs a new BroadcastHandler.
|
||||
*
|
||||
* @param plugin the main plugin instance
|
||||
* @param settings the broadcast settings
|
||||
* @param zoneId the time zone ID, or null to use system default
|
||||
*/
|
||||
public BroadcastHandler(VotingPluginMain plugin, BroadcastSettings settings, ZoneId zoneId) {
|
||||
this.plugin = plugin;
|
||||
this.settings = settings;
|
||||
@@ -66,6 +73,11 @@ public final class BroadcastHandler {
|
||||
rescheduleIntervalIfNeeded();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the broadcast settings and reschedules interval task if needed.
|
||||
*
|
||||
* @param settings the new broadcast settings
|
||||
*/
|
||||
public void setSettings(BroadcastSettings settings) {
|
||||
this.settings = settings;
|
||||
rescheduleIntervalIfNeeded();
|
||||
@@ -77,6 +89,7 @@ public final class BroadcastHandler {
|
||||
* @param uuid player's uuid
|
||||
* @param playerName player name (optional; if null/empty, resolved from Bukkit)
|
||||
* @param siteName vote site name (display name)
|
||||
* @param wasOnline whether the player was online when the vote was received
|
||||
*/
|
||||
public void broadcastVote(UUID uuid, String playerName, String siteName, boolean wasOnline) {
|
||||
BroadcastSettings s = settings;
|
||||
|
||||
@@ -18,6 +18,14 @@ public final class BroadcastSettings {
|
||||
private final int maxSitesListed;
|
||||
private final BroadcastFormat format;
|
||||
|
||||
/**
|
||||
* Constructs a BroadcastSettings with the specified parameters.
|
||||
*
|
||||
* @param type the broadcast type
|
||||
* @param duration the broadcast duration
|
||||
* @param maxSitesListed the maximum number of sites to list
|
||||
* @param format the broadcast format
|
||||
*/
|
||||
public BroadcastSettings(VoteBroadcastType type, ParsedDuration duration, int maxSitesListed,
|
||||
BroadcastFormat format) {
|
||||
this.type = type == null ? VoteBroadcastType.NONE : type;
|
||||
@@ -26,22 +34,47 @@ public final class BroadcastSettings {
|
||||
this.format = format == null ? new BroadcastFormat("", "", "") : format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the broadcast type.
|
||||
*
|
||||
* @return the broadcast type
|
||||
*/
|
||||
public VoteBroadcastType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the broadcast duration.
|
||||
*
|
||||
* @return the broadcast duration
|
||||
*/
|
||||
public ParsedDuration getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum number of sites to list.
|
||||
*
|
||||
* @return the maximum number of sites to list
|
||||
*/
|
||||
public int getMaxSitesListed() {
|
||||
return maxSitesListed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the broadcast format.
|
||||
*
|
||||
* @return the broadcast format
|
||||
*/
|
||||
public BroadcastFormat getFormat() {
|
||||
return format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether broadcasting is disabled.
|
||||
*
|
||||
* @return true if broadcasting is disabled
|
||||
*/
|
||||
public boolean isDisabled() {
|
||||
return type == VoteBroadcastType.NONE;
|
||||
}
|
||||
@@ -51,6 +84,9 @@ public final class BroadcastSettings {
|
||||
*
|
||||
* Expected structure: VoteBroadcast: Type: EVERY_VOTE Duration: 2m
|
||||
* MaxSitesListed: 0 Format: BroadcastMsg: '...' Header: '...' ListLine: '...'
|
||||
*
|
||||
* @param sec the configuration section to load from
|
||||
* @return the loaded broadcast settings
|
||||
*/
|
||||
public static BroadcastSettings load(ConfigurationSection sec) {
|
||||
VoteBroadcastType type = VoteBroadcastType.parse(sec == null ? null : sec.getString("Type"),
|
||||
|
||||
@@ -9,6 +9,9 @@ import java.util.Locale;
|
||||
*/
|
||||
public enum VoteBroadcastType {
|
||||
|
||||
/**
|
||||
* No vote broadcasting.
|
||||
*/
|
||||
NONE,
|
||||
|
||||
/**
|
||||
@@ -47,6 +50,12 @@ public enum VoteBroadcastType {
|
||||
*/
|
||||
INTERVAL_SUMMARY_GLOBAL;
|
||||
|
||||
/**
|
||||
* Parses a vote broadcast type from a string.
|
||||
* @param s the string to parse
|
||||
* @param def the default value if parsing fails
|
||||
* @return the parsed broadcast type or default
|
||||
*/
|
||||
public static VoteBroadcastType parse(String s, VoteBroadcastType def) {
|
||||
if (s == null || s.trim().isEmpty()) {
|
||||
return def;
|
||||
|
||||
+551
-130
@@ -1,5 +1,6 @@
|
||||
package com.bencodez.votingplugin.commands;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -37,8 +38,6 @@ import com.bencodez.advancedcore.api.rewards.RewardOptions;
|
||||
import com.bencodez.advancedcore.api.user.AdvancedCoreUser;
|
||||
import com.bencodez.advancedcore.api.user.UserDataFetchMode;
|
||||
import com.bencodez.advancedcore.api.user.UserStorage;
|
||||
import com.bencodez.advancedcore.api.valuerequest.ValueRequest;
|
||||
import com.bencodez.advancedcore.api.valuerequest.listeners.StringListener;
|
||||
import com.bencodez.advancedcore.api.yml.editor.ConfigEditor;
|
||||
import com.bencodez.advancedcore.command.gui.UserGUI;
|
||||
import com.bencodez.simpleapi.array.ArrayUtils;
|
||||
@@ -49,6 +48,9 @@ import com.bencodez.simpleapi.messages.MessageAPI;
|
||||
import com.bencodez.simpleapi.sql.Column;
|
||||
import com.bencodez.simpleapi.sql.DataType;
|
||||
import com.bencodez.simpleapi.updater.Updater;
|
||||
import com.bencodez.simpleapi.valuerequest.InputMethod;
|
||||
import com.bencodez.simpleapi.valuerequest.StringListener;
|
||||
import com.bencodez.simpleapi.valuerequest.ValueRequest;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.commands.executers.CommandAliases;
|
||||
import com.bencodez.votingplugin.commands.gui.AdminGUI;
|
||||
@@ -79,7 +81,11 @@ import com.bencodez.votingplugin.commands.gui.player.VoteURLVoteSite;
|
||||
import com.bencodez.votingplugin.commands.tabcompleter.AliasesTabCompleter;
|
||||
import com.bencodez.votingplugin.events.PlayerVoteEvent;
|
||||
import com.bencodez.votingplugin.events.PlayerVoteSiteCoolDownEndEvent;
|
||||
import com.bencodez.votingplugin.presets.VoteSitePreset;
|
||||
import com.bencodez.votingplugin.presets.VoteSitePresetSetupHandler;
|
||||
import com.bencodez.votingplugin.specialrewards.votemilestones.VoteMilestonesManager;
|
||||
import com.bencodez.votingplugin.specialrewards.votestreak.VoteStreakDefinition;
|
||||
import com.bencodez.votingplugin.specialrewards.votestreak.VoteStreakType;
|
||||
import com.bencodez.votingplugin.topvoter.TopVoter;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
import com.bencodez.votingplugin.votesites.VoteSite;
|
||||
@@ -101,6 +107,11 @@ public class CommandLoader {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Constructs a new CommandLoader.
|
||||
*
|
||||
* @param plugin the main plugin instance
|
||||
*/
|
||||
public CommandLoader(VotingPluginMain plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@@ -112,6 +123,12 @@ public class CommandLoader {
|
||||
return adminPerm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the back button for inventory navigation.
|
||||
*
|
||||
* @param user the voting plugin user
|
||||
* @return the back button
|
||||
*/
|
||||
public BInventoryButton getBackButton(VotingPluginUser user) {
|
||||
ConfigurationSection sec = plugin.getGui().getCHESTBackButton();
|
||||
boolean a = false;
|
||||
@@ -181,6 +198,13 @@ public class CommandLoader {
|
||||
return playerPerm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a player has permission for a command.
|
||||
*
|
||||
* @param player the player
|
||||
* @param cmd the command
|
||||
* @return true if player has permission
|
||||
*/
|
||||
public boolean hasPermission(Player player, String cmd) {
|
||||
if (cmd.startsWith("votingplugin:")) {
|
||||
cmd = cmd.substring("votingplugin:".length());
|
||||
@@ -230,6 +254,13 @@ public class CommandLoader {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a command belongs to the VotingPlugin.
|
||||
*
|
||||
* @param player the player
|
||||
* @param cmd the command
|
||||
* @return true if it's a VotingPlugin command
|
||||
*/
|
||||
public boolean isVotingPluginCommand(Player player, String cmd) {
|
||||
if (plugin.getCommand(cmd) != null || cmd.startsWith("votingplugin")) {
|
||||
return true;
|
||||
@@ -838,41 +869,237 @@ public class CommandLoader {
|
||||
});
|
||||
|
||||
plugin.getAdminVoteCommand()
|
||||
.add(new CommandHandler(plugin, new String[] { "User", "(player)", "SetVoteStreak", "DAY", "(number)" },
|
||||
"VotingPlugin.Commands.AdminVote.SetVoteStreak.Day|" + adminPerm, "Set votestreak for player") {
|
||||
.add(new CommandHandler(plugin,
|
||||
new String[] { "User", "(player)", "VoteStreaks", "SetLegacy", "DAY", "(number)" },
|
||||
"VotingPlugin.Commands.AdminVote.VoteStreaks.SetLegacy|" + adminPerm,
|
||||
"Set the legacy daily vote streak amount") {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
plugin.getVotingPluginUserManager().getVotingPluginUser(args[1])
|
||||
.setDayVoteStreak(Integer.parseInt(args[4]));
|
||||
sender.sendMessage(
|
||||
MessageAPI.colorize("&cSet votestreak day for '" + args[1] + "' to " + args[4]));
|
||||
.setDayVoteStreak(Integer.parseInt(args[5]));
|
||||
sendMessage(sender, "&aSet legacy daily VoteStreak for &e" + args[1] + " &ato &e" + args[5]);
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getAdminVoteCommand().add(new CommandHandler(plugin,
|
||||
new String[] { "User", "(player)", "SetVoteStreak", "WEEK", "(number)" },
|
||||
"VotingPlugin.Commands.AdminVote.SetVoteStreak.Week|" + adminPerm, "Set votestreak for player") {
|
||||
plugin.getAdminVoteCommand()
|
||||
.add(new CommandHandler(plugin,
|
||||
new String[] { "User", "(player)", "VoteStreaks", "SetLegacy", "WEEK", "(number)" },
|
||||
"VotingPlugin.Commands.AdminVote.VoteStreaks.SetLegacy|" + adminPerm,
|
||||
"Set the legacy weekly vote streak amount") {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
plugin.getVotingPluginUserManager().getVotingPluginUser(args[1])
|
||||
.setWeekVoteStreak(Integer.parseInt(args[4]));
|
||||
sender.sendMessage(MessageAPI.colorize("&cSet votestreak week for '" + args[1] + "' to " + args[4]));
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
plugin.getVotingPluginUserManager().getVotingPluginUser(args[1])
|
||||
.setWeekVoteStreak(Integer.parseInt(args[5]));
|
||||
sendMessage(sender, "&aSet legacy weekly VoteStreak for &e" + args[1] + " &ato &e" + args[5]);
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getAdminVoteCommand().add(new CommandHandler(plugin,
|
||||
new String[] { "User", "(player)", "SetVoteStreak", "MONTH", "(number)" },
|
||||
"VotingPlugin.Commands.AdminVote.SetVoteStreak.Month|" + adminPerm, "Set votestreak for player") {
|
||||
plugin.getAdminVoteCommand()
|
||||
.add(new CommandHandler(plugin,
|
||||
new String[] { "User", "(player)", "VoteStreaks", "SetLegacy", "MONTH", "(number)" },
|
||||
"VotingPlugin.Commands.AdminVote.VoteStreaks.SetLegacy|" + adminPerm,
|
||||
"Set the legacy monthly vote streak amount") {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
plugin.getVotingPluginUserManager().getVotingPluginUser(args[1])
|
||||
.setMonthVoteStreak(Integer.parseInt(args[4]));
|
||||
sender.sendMessage(MessageAPI.colorize("&cSet votestreak month for '" + args[1] + "' to " + args[4]));
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
plugin.getVotingPluginUserManager().getVotingPluginUser(args[1])
|
||||
.setMonthVoteStreak(Integer.parseInt(args[5]));
|
||||
sendMessage(sender, "&aSet legacy monthly VoteStreak for &e" + args[1] + " &ato &e" + args[5]);
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getAdminVoteCommand()
|
||||
.add(new CommandHandler(plugin,
|
||||
new String[] { "User", "(player)", "VoteStreaks", "Advance", "(votestreakstate)" },
|
||||
"VotingPlugin.Commands.AdminVote.VoteStreaks.Advance|" + adminPerm,
|
||||
"Advance a configured VoteStreak by one and give crossed rewards") {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(args[1]);
|
||||
int result = plugin.getVoteStreakHandler().advanceVoteStreak(user, args[4], 1, UUID.randomUUID());
|
||||
if (result >= 0) {
|
||||
sendMessage(sender, "&aAdvanced VoteStreak &e" + args[4] + " &afor &e" + args[1]
|
||||
+ "&a. New amount: &e" + result);
|
||||
} else {
|
||||
sendMessage(sender, "&cVoteStreak or progress group not found: &e" + args[4]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getAdminVoteCommand()
|
||||
.add(new CommandHandler(plugin,
|
||||
new String[] { "User", "(player)", "VoteStreaks", "Advance", "(votestreakstate)", "(number)" },
|
||||
"VotingPlugin.Commands.AdminVote.VoteStreaks.Advance|" + adminPerm,
|
||||
"Advance a configured VoteStreak and give crossed rewards") {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
int amount = Integer.parseInt(args[5]);
|
||||
if (amount <= 0) {
|
||||
sendMessage(sender, "&cAdvance amount must be greater than zero");
|
||||
return;
|
||||
}
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(args[1]);
|
||||
int result = plugin.getVoteStreakHandler().advanceVoteStreak(user, args[4], amount, UUID.randomUUID());
|
||||
if (result >= 0) {
|
||||
sendMessage(sender, "&aAdvanced VoteStreak &e" + args[4] + " &aby &e" + amount + " &afor &e"
|
||||
+ args[1] + "&a. New amount: &e" + result);
|
||||
} else {
|
||||
sendMessage(sender, "&cVoteStreak or progress group not found: &e" + args[4]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getAdminVoteCommand()
|
||||
.add(new CommandHandler(plugin,
|
||||
new String[] { "User", "(player)", "VoteStreaks", "SetAmount", "(votestreakstate)", "(number)" },
|
||||
"VotingPlugin.Commands.AdminVote.VoteStreaks.SetAmount|" + adminPerm,
|
||||
"Set a configured VoteStreak amount without giving rewards") {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(args[1]);
|
||||
int amount = Math.max(0, Integer.parseInt(args[5]));
|
||||
if (plugin.getVoteStreakHandler().setVoteStreakAmount(user, args[4], amount)) {
|
||||
sendMessage(sender, "&aSet VoteStreak &e" + args[4] + " &aamount for &e" + args[1]
|
||||
+ " &ato &e" + amount);
|
||||
} else {
|
||||
sendMessage(sender, "&cVoteStreak or progress group not found: &e" + args[4]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getAdminVoteCommand()
|
||||
.add(new CommandHandler(plugin,
|
||||
new String[] { "User", "(player)", "VoteStreaks", "AddAmount", "(votestreakstate)", "(number)" },
|
||||
"VotingPlugin.Commands.AdminVote.VoteStreaks.AddAmount|" + adminPerm,
|
||||
"Add to a configured VoteStreak amount without giving rewards") {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(args[1]);
|
||||
int change = Integer.parseInt(args[5]);
|
||||
int result = plugin.getVoteStreakHandler().addVoteStreakAmount(user, args[4], change);
|
||||
if (result >= 0) {
|
||||
sendMessage(sender, "&aChanged VoteStreak &e" + args[4] + " &aamount by &e" + change
|
||||
+ " &afor &e" + args[1] + "&a. New amount: &e" + result);
|
||||
} else {
|
||||
sendMessage(sender, "&cVoteStreak or progress group not found: &e" + args[4]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getAdminVoteCommand()
|
||||
.add(new CommandHandler(plugin,
|
||||
new String[] { "User", "(player)", "VoteStreaks", "SetLastUpdate", "(votestreakstate)", "(text)" },
|
||||
"VotingPlugin.Commands.AdminVote.VoteStreaks.SetLastUpdate|" + adminPerm,
|
||||
"Set the last update date for a configured VoteStreak using yyyy-MM-dd") {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(args[1]);
|
||||
String periodKey = plugin.getVoteStreakHandler().setVoteStreakLastUpdateDate(user, args[4], args[5]);
|
||||
if (periodKey != null) {
|
||||
sendMessage(sender, "&aSet the last update date for VoteStreak &e" + args[4] + " &afor &e"
|
||||
+ args[1] + " &ato &e" + args[5] + "&a. Stored period: &e" + periodKey);
|
||||
} else {
|
||||
sendMessage(sender, "&cInvalid VoteStreak, progress group, or date. Use yyyy-MM-dd.");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getAdminVoteCommand()
|
||||
.add(new CommandHandler(plugin,
|
||||
new String[] { "User", "(player)", "VoteStreaks", "SetVotes", "(votestreakstate)", "(number)" },
|
||||
"VotingPlugin.Commands.AdminVote.VoteStreaks.SetVotes|" + adminPerm,
|
||||
"Set votes recorded in the current VoteStreak period") {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(args[1]);
|
||||
int votes = Math.max(0, Integer.parseInt(args[5]));
|
||||
if (plugin.getVoteStreakHandler().setVoteStreakVotesThisPeriod(user, args[4], votes)) {
|
||||
sendMessage(sender, "&aSet current-period votes for VoteStreak &e" + args[4] + " &afor &e"
|
||||
+ args[1] + " &ato &e" + votes);
|
||||
} else {
|
||||
sendMessage(sender, "&cVoteStreak or progress group not found: &e" + args[4]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getAdminVoteCommand()
|
||||
.add(new CommandHandler(plugin,
|
||||
new String[] { "User", "(player)", "VoteStreaks", "SetSatisfied", "(votestreakstate)", "(boolean)" },
|
||||
"VotingPlugin.Commands.AdminVote.VoteStreaks.SetSatisfied|" + adminPerm,
|
||||
"Set whether the current VoteStreak period is satisfied") {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(args[1]);
|
||||
boolean satisfied = Boolean.parseBoolean(args[5]);
|
||||
if (plugin.getVoteStreakHandler().setVoteStreakPeriodSatisfied(user, args[4], satisfied)) {
|
||||
sendMessage(sender, "&aSet current-period satisfied state for VoteStreak &e" + args[4]
|
||||
+ " &afor &e" + args[1] + " &ato &e" + satisfied);
|
||||
} else {
|
||||
sendMessage(sender, "&cVoteStreak or progress group not found: &e" + args[4]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getAdminVoteCommand()
|
||||
.add(new CommandHandler(plugin,
|
||||
new String[] { "User", "(player)", "VoteStreaks", "Status", "(votestreakstate)" },
|
||||
"VotingPlugin.Commands.AdminVote.VoteStreaks.Status|" + adminPerm,
|
||||
"Show the stored state for a configured VoteStreak") {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(args[1]);
|
||||
List<String> status = plugin.getVoteStreakHandler().getVoteStreakStatus(user, args[4]);
|
||||
if (status.isEmpty()) {
|
||||
sendMessage(sender, "&cVoteStreak or progress group not found: &e" + args[4]);
|
||||
return;
|
||||
}
|
||||
sendMessage(sender, "&aVoteStreak state for &e" + args[1] + "&a:");
|
||||
for (String line : status) {
|
||||
sendMessage(sender, "&7- &f" + line);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getAdminVoteCommand()
|
||||
.add(new CommandHandler(plugin,
|
||||
new String[] { "User", "(player)", "VoteStreaks", "Reset", "(votestreakreset)" },
|
||||
"VotingPlugin.Commands.AdminVote.VoteStreaks.Reset|" + adminPerm,
|
||||
"Reset VoteStreak state by id, progress group, type, or ALL") {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(args[1]);
|
||||
String target = args[4];
|
||||
if (target.equalsIgnoreCase("ALL")) {
|
||||
int reset = plugin.getVoteStreakHandler().resetVoteStreaks(user);
|
||||
sendMessage(sender, "&aReset &e" + reset + " &aVoteStreak states for &e" + args[1]);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
VoteStreakType type = VoteStreakType.from(target);
|
||||
int reset = plugin.getVoteStreakHandler().resetVoteStreaks(user, type);
|
||||
sendMessage(sender, "&aReset &e" + reset + " " + type.name() + " &aVoteStreak states for &e"
|
||||
+ args[1]);
|
||||
return;
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
if (plugin.getVoteStreakHandler().resetVoteStreak(user, target)) {
|
||||
sendMessage(sender, "&aReset VoteStreak state &e" + target + " &afor &e" + args[1]);
|
||||
} else {
|
||||
sendMessage(sender, "&cVoteStreak or progress group not found: &e" + target);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for (final TopVoter top : TopVoter.values()) {
|
||||
plugin.getAdminVoteCommand()
|
||||
@@ -1516,20 +1743,20 @@ public class CommandLoader {
|
||||
|
||||
plugin.getAdminVoteCommand()
|
||||
.add(new CommandHandler(plugin,
|
||||
new String[] { "User", "(player)", "ForceVoteStreak", str, "(Text)" },
|
||||
new String[] { "User", "(player)", "VoteStreaks", "ForceLegacy", str, "(Text)" },
|
||||
"VotingPlugin.Commands.AdminVote.ForceVoteStreak|" + adminPerm,
|
||||
"Force a votestreak reward for " + str) {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
String num = args[4];
|
||||
String num = args[5];
|
||||
if (num.contains("-")) {
|
||||
num = num.replaceAll("-", "");
|
||||
}
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(args[1]);
|
||||
plugin.getSpecialRewards().giveVoteStreakReward(null, user, user.isOnline(), str, args[4],
|
||||
plugin.getSpecialRewards().giveVoteStreakReward(null, user, user.isOnline(), str, args[5],
|
||||
parseInt(num), plugin.getBungeeSettings().isUseBungeecoord());
|
||||
sendMessage(sender, "&cVoteStreak " + str + " " + args[4] + " forced");
|
||||
sendMessage(sender, "&cVoteStreak " + str + " " + args[5] + " forced");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -2268,6 +2495,19 @@ public class CommandLoader {
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getAdminVoteCommand()
|
||||
.add(new CommandHandler(plugin, new String[] { "MigrateVoteStreaks" },
|
||||
"VotingPlugin.Commands.AdminVote.MigrateVoteStreaks|" + adminPerm,
|
||||
"Migrate legacy VoteStreak config to VoteStreaks") {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
int loaded = plugin.getVoteStreakHandler().migrateLegacyConfigManually();
|
||||
plugin.getVoteStreakHandler().reload();
|
||||
sendMessage(sender, "&aLegacy VoteStreak migration complete. Loaded definitions: " + loaded);
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getAdminVoteCommand()
|
||||
.add(new CommandHandler(plugin, new String[] { "ClearDiscordMessageID", "(topvoter)" },
|
||||
"VotingPlugin.Commands.AdminVote.ClearDiscordMessageID",
|
||||
@@ -2292,6 +2532,91 @@ public class CommandLoader {
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getAdminVoteCommand().add(new CommandHandler(plugin, new String[] { "VotePresets" },
|
||||
"VotingPlugin.Commands.AdminVote.VotePresets|" + adminPerm, "Open vote presets menu", false) {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (plugin.getPresetHandler() == null) {
|
||||
plugin.setPresetHandler(new VoteSitePresetSetupHandler(plugin));
|
||||
}
|
||||
|
||||
plugin.getPresetHandler().startSetup((Player) sender);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getAdminVoteCommand().add(new CommandHandler(plugin, new String[] { "VotePresets", "(Text)" },
|
||||
"VotingPlugin.Commands.AdminVote.VotePresets|" + adminPerm, "Find vote preset from url", false) {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (plugin.getPresetHandler() == null) {
|
||||
plugin.setPresetHandler(new VoteSitePresetSetupHandler(plugin));
|
||||
}
|
||||
|
||||
try {
|
||||
VoteSitePreset preset = plugin.getPresetHandler().getLoader().findVoteSitePresetForURL(args[1]);
|
||||
|
||||
if (preset == null) {
|
||||
sender.sendMessage("No vote preset matches that URL.");
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getPresetHandler().promptPlaceholders((Player) sender, preset);
|
||||
} catch (IOException | InterruptedException e) {
|
||||
plugin.getLogger().warning("Failed to search presets: " + e.getMessage());
|
||||
sender.sendMessage("Could not determine a preset for that URL.");
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getAdminVoteCommand()
|
||||
.add(new CommandHandler(plugin, new String[] { "User", "(player)", "VoteStreaks", "Force", "(votestreak)" },
|
||||
"VotingPlugin.Commands.AdminVote.ForceVoteStreak|" + adminPerm,
|
||||
"Force a configured VoteStreaks reward by id") {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(args[1]);
|
||||
String id = args[4];
|
||||
|
||||
boolean forced = plugin.getVoteStreakHandler().forceVoteStreakReward(user, id, 1,
|
||||
UUID.randomUUID());
|
||||
|
||||
if (forced) {
|
||||
sendMessage(sender, "&aVoteStreak &e" + id + " &aforced for &e" + args[1]);
|
||||
} else {
|
||||
sendMessage(sender, "&cVoteStreak not found: &e" + id);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getAdminVoteCommand()
|
||||
.add(new CommandHandler(plugin,
|
||||
new String[] { "User", "(player)", "VoteStreaks", "Force", "(votestreak)", "(number)" },
|
||||
"VotingPlugin.Commands.AdminVote.ForceVoteStreak|" + adminPerm,
|
||||
"Force a configured VoteStreaks reward by id with a streak amount") {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(args[1]);
|
||||
String id = args[4];
|
||||
int streakCount = parseInt(args[5]);
|
||||
|
||||
boolean forced = plugin.getVoteStreakHandler().forceVoteStreakReward(user, id, streakCount,
|
||||
UUID.randomUUID());
|
||||
|
||||
if (forced) {
|
||||
sendMessage(sender, "&aVoteStreak &e" + id + " &aforced for &e" + args[1]
|
||||
+ " &awith amount &e" + streakCount);
|
||||
} else {
|
||||
sendMessage(sender, "&cVoteStreak not found: &e" + id);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getAdminVoteCommand().add(new CommandHandler(plugin, new String[] { "VoteLog", "(Number)" },
|
||||
"VotingPlugin.Commands.AdminVote.VoteLog|" + adminPerm, "See vote logs") {
|
||||
|
||||
@@ -2321,6 +2646,11 @@ public class CommandLoader {
|
||||
|
||||
private final Set<String> aliasCommandNames = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Gets the set of alias command names.
|
||||
*
|
||||
* @return set of alias command names
|
||||
*/
|
||||
public Set<String> getAliasCommandNames() {
|
||||
return aliasCommandNames;
|
||||
}
|
||||
@@ -2508,27 +2838,30 @@ public class CommandLoader {
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
Player player = clickEvent.getPlayer();
|
||||
ArrayList<String> voteSites = new ArrayList<>();
|
||||
ArrayList<String> voteSites = new ArrayList<String>();
|
||||
for (VoteSite voteSite : plugin.getVoteSiteManager().getVoteSitesEnabled()) {
|
||||
voteSites.add(voteSite.getKey());
|
||||
}
|
||||
new ValueRequest().requestString(player, "", ArrayUtils.convert(voteSites), true,
|
||||
new StringListener() {
|
||||
|
||||
@Override
|
||||
public void onInput(Player player, String value) {
|
||||
PlayerVoteEvent voteEvent = new PlayerVoteEvent(
|
||||
plugin.getVoteSiteManager().getVoteSite(value, true),
|
||||
UserGUI.getInstance().getCurrentPlayer(player),
|
||||
plugin.getVoteSiteManager().getVoteSiteServiceSite(value),
|
||||
false);
|
||||
plugin.getServer().getPluginManager().callEvent(voteEvent);
|
||||
new ValueRequest(plugin, plugin.getDialogService(), InputMethod.INVENTORY)
|
||||
.requestString(player, "", voteSites, true, "Select vote site",
|
||||
new StringListener() {
|
||||
|
||||
player.sendMessage("Forced vote for "
|
||||
+ UserGUI.getInstance().getCurrentPlayer(player) + " on "
|
||||
+ value);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onInput(Player player, String value) {
|
||||
PlayerVoteEvent voteEvent = new PlayerVoteEvent(
|
||||
plugin.getVoteSiteManager().getVoteSite(value, true),
|
||||
UserGUI.getInstance().getCurrentPlayer(player),
|
||||
plugin.getVoteSiteManager()
|
||||
.getVoteSiteServiceSite(value),
|
||||
false);
|
||||
plugin.getServer().getPluginManager().callEvent(voteEvent);
|
||||
|
||||
player.sendMessage("Forced vote for "
|
||||
+ UserGUI.getInstance().getCurrentPlayer(player)
|
||||
+ " on " + value);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
@@ -2640,6 +2973,85 @@ public class CommandLoader {
|
||||
setReplace(milestoneGroups);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateReplacements() {
|
||||
}
|
||||
});
|
||||
|
||||
ArrayList<String> voteStreaks = new ArrayList<>();
|
||||
for (VoteStreakDefinition def : plugin.getVoteStreakHandler().getDefinitions()) {
|
||||
voteStreaks.add(def.getId());
|
||||
}
|
||||
|
||||
TabCompleteHandler.getInstance().addTabCompleteOption(new TabCompleteHandle("(votestreak)", voteStreaks) {
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
ArrayList<String> voteStreaks = new ArrayList<>();
|
||||
for (VoteStreakDefinition def : plugin.getVoteStreakHandler().getDefinitions()) {
|
||||
voteStreaks.add(def.getId());
|
||||
}
|
||||
setReplace(voteStreaks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateReplacements() {
|
||||
}
|
||||
});
|
||||
|
||||
ArrayList<String> voteStreakStates = new ArrayList<>();
|
||||
for (VoteStreakDefinition def : plugin.getVoteStreakHandler().getDefinitions()) {
|
||||
if (def.getProgressGroup() == null || def.getProgressGroup().isEmpty()) {
|
||||
voteStreakStates.add(def.getId());
|
||||
}
|
||||
}
|
||||
voteStreakStates.addAll(plugin.getVoteStreakHandler().getProgressGroups());
|
||||
|
||||
TabCompleteHandler.getInstance()
|
||||
.addTabCompleteOption(new TabCompleteHandle("(votestreakstate)", voteStreakStates) {
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
ArrayList<String> voteStreakStates = new ArrayList<>();
|
||||
for (VoteStreakDefinition def : plugin.getVoteStreakHandler().getDefinitions()) {
|
||||
if (def.getProgressGroup() == null || def.getProgressGroup().isEmpty()) {
|
||||
voteStreakStates.add(def.getId());
|
||||
}
|
||||
}
|
||||
voteStreakStates.addAll(plugin.getVoteStreakHandler().getProgressGroups());
|
||||
setReplace(voteStreakStates);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateReplacements() {
|
||||
}
|
||||
});
|
||||
|
||||
ArrayList<String> voteStreakResetTargets = new ArrayList<>(voteStreakStates);
|
||||
voteStreakResetTargets.add("ALL");
|
||||
voteStreakResetTargets.add("DAILY");
|
||||
voteStreakResetTargets.add("WEEKLY");
|
||||
voteStreakResetTargets.add("MONTHLY");
|
||||
|
||||
TabCompleteHandler.getInstance()
|
||||
.addTabCompleteOption(new TabCompleteHandle("(votestreakreset)", voteStreakResetTargets) {
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
ArrayList<String> voteStreakResetTargets = new ArrayList<>();
|
||||
for (VoteStreakDefinition def : plugin.getVoteStreakHandler().getDefinitions()) {
|
||||
if (def.getProgressGroup() == null || def.getProgressGroup().isEmpty()) {
|
||||
voteStreakResetTargets.add(def.getId());
|
||||
}
|
||||
}
|
||||
voteStreakResetTargets.addAll(plugin.getVoteStreakHandler().getProgressGroups());
|
||||
voteStreakResetTargets.add("ALL");
|
||||
voteStreakResetTargets.add("DAILY");
|
||||
voteStreakResetTargets.add("WEEKLY");
|
||||
voteStreakResetTargets.add("MONTHLY");
|
||||
setReplace(voteStreakResetTargets);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateReplacements() {
|
||||
}
|
||||
@@ -2669,97 +3081,99 @@ public class CommandLoader {
|
||||
}
|
||||
});
|
||||
|
||||
if (plugin.getShopFile().isVoteShopEnabled()) {
|
||||
plugin.getVoteCommand().add(new CommandHandler(plugin, new String[] { "Shop" },
|
||||
"VotingPlugin.Commands.Vote.Shop|" + playerPerm, "Open VoteShop GUI", false) {
|
||||
plugin.getVoteCommand().add(new CommandHandler(plugin, new String[] { "Shop" },
|
||||
"VotingPlugin.Commands.Vote.Shop|" + playerPerm, "Open VoteShop GUI", false) {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
new VoteShop(plugin, sender,
|
||||
plugin.getVotingPluginUserManager().getVotingPluginUser((Player) sender)).open();
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (!plugin.getShopFile().isVoteShopEnabled()) {
|
||||
sender.sendMessage(MessageAPI.colorize("&cVote shop disabled"));
|
||||
return;
|
||||
}
|
||||
});
|
||||
plugin.getVoteCommand().add(new CommandHandler(plugin, new String[] { "Shop", "(Text)" },
|
||||
"VotingPlugin.Commands.Vote.Shop|" + playerPerm, "Open VoteShop GUI", false) {
|
||||
new VoteShop(plugin, sender, plugin.getVotingPluginUserManager().getVotingPluginUser((Player) sender))
|
||||
.open();
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (!plugin.getShopFile().isVoteShopEnabled()) {
|
||||
sender.sendMessage(MessageAPI.colorize("&cVote shop disabled"));
|
||||
return;
|
||||
}
|
||||
});
|
||||
plugin.getVoteCommand().add(new CommandHandler(plugin, new String[] { "Shop", "(Text)" },
|
||||
"VotingPlugin.Commands.Vote.Shop|" + playerPerm, "Open VoteShop GUI", false) {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (!plugin.getShopFile().isVoteShopEnabled()) {
|
||||
sender.sendMessage(MessageAPI.colorize("&cVote shop disabled"));
|
||||
return;
|
||||
}
|
||||
|
||||
String identifier = args[1];
|
||||
Set<String> identifiers = plugin.getShopFile().getShopIdentifiers();
|
||||
if (ArrayUtils.containsIgnoreCase(identifiers, identifier)) {
|
||||
for (String ident : identifiers) {
|
||||
if (ident.equalsIgnoreCase(args[1])) {
|
||||
identifier = ident;
|
||||
}
|
||||
}
|
||||
|
||||
String identifier = args[1];
|
||||
Set<String> identifiers = plugin.getShopFile().getShopIdentifiers();
|
||||
if (ArrayUtils.containsIgnoreCase(identifiers, identifier)) {
|
||||
for (String ident : identifiers) {
|
||||
if (ident.equalsIgnoreCase(args[1])) {
|
||||
identifier = ident;
|
||||
String perm = plugin.getShopFile().getVoteShopPermission(identifier);
|
||||
boolean hasPerm = false;
|
||||
if (perm.isEmpty()) {
|
||||
hasPerm = true;
|
||||
} else {
|
||||
hasPerm = sender.hasPermission(perm);
|
||||
}
|
||||
|
||||
int limit = plugin.getShopFile().getShopIdentifierLimit(identifier);
|
||||
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(sender.getName());
|
||||
boolean limitPass = true;
|
||||
if (limit > 0) {
|
||||
|
||||
if (user.getVoteShopIdentifierLimit(identifier) >= limit) {
|
||||
limitPass = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!plugin.getShopFile().getVoteShopNotBuyable(identifier)) {
|
||||
if (hasPerm) {
|
||||
if (plugin.getConfigFile().isExtraVoteShopCheck()) {
|
||||
user.cache();
|
||||
}
|
||||
}
|
||||
int points = plugin.getShopFile().getShopIdentifierCost(identifier);
|
||||
if (identifier != null) {
|
||||
|
||||
String perm = plugin.getShopFile().getVoteShopPermission(identifier);
|
||||
boolean hasPerm = false;
|
||||
if (perm.isEmpty()) {
|
||||
hasPerm = true;
|
||||
} else {
|
||||
hasPerm = sender.hasPermission(perm);
|
||||
}
|
||||
if (limitPass) {
|
||||
HashMap<String, String> placeholders = new HashMap<>();
|
||||
placeholders.put("identifier", identifier);
|
||||
placeholders.put("points", "" + points);
|
||||
placeholders.put("limit", "" + limit);
|
||||
if (user.removePoints(points, true)) {
|
||||
|
||||
int limit = plugin.getShopFile().getShopIdentifierLimit(identifier);
|
||||
plugin.getRewardHandler().giveReward(user, plugin.getShopFile().getData(),
|
||||
plugin.getShopFile().getShopIdentifierRewardsPath(identifier),
|
||||
new RewardOptions().setPlaceholders(placeholders));
|
||||
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager()
|
||||
.getVotingPluginUser(sender.getName());
|
||||
boolean limitPass = true;
|
||||
if (limit > 0) {
|
||||
|
||||
if (user.getVoteShopIdentifierLimit(identifier) >= limit) {
|
||||
limitPass = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!plugin.getShopFile().getVoteShopNotBuyable(identifier)) {
|
||||
if (hasPerm) {
|
||||
if (plugin.getConfigFile().isExtraVoteShopCheck()) {
|
||||
user.cache();
|
||||
}
|
||||
int points = plugin.getShopFile().getShopIdentifierCost(identifier);
|
||||
if (identifier != null) {
|
||||
|
||||
if (limitPass) {
|
||||
HashMap<String, String> placeholders = new HashMap<>();
|
||||
placeholders.put("identifier", identifier);
|
||||
placeholders.put("points", "" + points);
|
||||
placeholders.put("limit", "" + limit);
|
||||
if (user.removePoints(points, true)) {
|
||||
|
||||
plugin.getRewardHandler().giveReward(user, plugin.getShopFile().getData(),
|
||||
plugin.getShopFile().getShopIdentifierRewardsPath(identifier),
|
||||
new RewardOptions().setPlaceholders(placeholders));
|
||||
|
||||
user.sendMessage(PlaceholderUtils.replacePlaceHolder(
|
||||
plugin.getConfigFile().getFormatShopPurchaseMsg(), placeholders));
|
||||
if (limit > 0) {
|
||||
user.setVoteShopIdentifierLimit(identifier,
|
||||
user.getVoteShopIdentifierLimit(identifier) + 1);
|
||||
}
|
||||
} else {
|
||||
user.sendMessage(PlaceholderUtils.replacePlaceHolder(
|
||||
plugin.getConfigFile().getFormatShopFailedMsg(), placeholders));
|
||||
user.sendMessage(PlaceholderUtils.replacePlaceHolder(
|
||||
plugin.getConfigFile().getFormatShopPurchaseMsg(), placeholders));
|
||||
if (limit > 0) {
|
||||
user.setVoteShopIdentifierLimit(identifier,
|
||||
user.getVoteShopIdentifierLimit(identifier) + 1);
|
||||
}
|
||||
} else {
|
||||
user.sendMessage(plugin.getShopFile().getVoteShopLimitReached());
|
||||
user.sendMessage(PlaceholderUtils.replacePlaceHolder(
|
||||
plugin.getConfigFile().getFormatShopFailedMsg(), placeholders));
|
||||
}
|
||||
} else {
|
||||
user.sendMessage(plugin.getShopFile().getVoteShopLimitReached());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
sendMessage(sender, "&cWrong voteshop item");
|
||||
}
|
||||
} else {
|
||||
sendMessage(sender, "&cWrong voteshop item");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getVoteCommand().add(new CommandHandler(plugin, new String[] { "URL", "(SiteName)" },
|
||||
"VotingPlugin.Commands.Vote.URL.VoteSite", "Open VoteURL GUI for VoteSite", false) {
|
||||
@@ -3300,29 +3714,36 @@ public class CommandLoader {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a slot click action from a GUI.
|
||||
*
|
||||
* @param player the player
|
||||
* @param user the voting plugin user
|
||||
* @param slot the slot identifier
|
||||
*/
|
||||
public void processSlotClick(Player player, VotingPluginUser user, String slot) {
|
||||
if (MessageAPI.startsWithIgnoreCase(slot, "url")) {
|
||||
new VoteURL(plugin, player, user, true).open();
|
||||
} else if (MessageAPI.startsWithIgnoreCase(slot, "next")) {
|
||||
new VoteNext(plugin, player, user).open(GUIMethod.CHEST);
|
||||
new VoteNext(plugin, player, user).open();
|
||||
} else if (MessageAPI.startsWithIgnoreCase(slot, "last")) {
|
||||
new VoteLast(plugin, player, user).open(GUIMethod.CHEST);
|
||||
new VoteLast(plugin, player, user).open();
|
||||
} else if (MessageAPI.startsWithIgnoreCase(slot, "total")) {
|
||||
new VoteTotal(plugin, player, user).open(GUIMethod.CHEST);
|
||||
new VoteTotal(plugin, player, user).open();
|
||||
} else if (MessageAPI.startsWithIgnoreCase(slot, "top")) {
|
||||
new VoteTopVoter(plugin, player, user, TopVoter.getDefault(), 1).open(GUIMethod.CHEST);
|
||||
new VoteTopVoter(plugin, player, user, TopVoter.getDefault(), 1).open();
|
||||
} else if (MessageAPI.startsWithIgnoreCase(slot, "today")) {
|
||||
new VoteToday(plugin, player, user, 1).open(GUIMethod.CHEST);
|
||||
new VoteToday(plugin, player, user, 1).open();
|
||||
} else if (MessageAPI.startsWithIgnoreCase(slot, "help")) {
|
||||
player.performCommand("vote help");
|
||||
} else if (MessageAPI.startsWithIgnoreCase(slot, "shop")) {
|
||||
new VoteShop(plugin, player, user).open(GUIMethod.CHEST);
|
||||
new VoteShop(plugin, player, user).open();
|
||||
} else if (MessageAPI.startsWithIgnoreCase(slot, "lastmonth")) {
|
||||
new VoteTopVoterLastMonth(plugin, player, user).open(GUIMethod.CHEST);
|
||||
new VoteTopVoterLastMonth(plugin, player, user).open();
|
||||
} else if (MessageAPI.startsWithIgnoreCase(slot, "best")) {
|
||||
new VoteBest(plugin, player, user).open(GUIMethod.CHEST);
|
||||
new VoteBest(plugin, player, user).open();
|
||||
} else if (MessageAPI.startsWithIgnoreCase(slot, "streak")) {
|
||||
new VoteStreak(plugin, player, user).open(GUIMethod.CHEST);
|
||||
new VoteStreak(plugin, player, user).open();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
@@ -16,6 +16,11 @@ public class CommandAdminVote implements CommandExecutor {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Constructs a new CommandAdminVote instance.
|
||||
*
|
||||
* @param plugin the main plugin instance
|
||||
*/
|
||||
public CommandAdminVote(VotingPluginMain plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
+6
@@ -25,6 +25,12 @@ public class CommandAliases implements CommandExecutor {
|
||||
/** The plugin. */
|
||||
private VotingPluginMain plugin = VotingPluginMain.plugin;
|
||||
|
||||
/**
|
||||
* Constructs a new CommandAliases instance.
|
||||
*
|
||||
* @param cmdHandle the command handler
|
||||
* @param adminCommand whether this is an admin command
|
||||
*/
|
||||
public CommandAliases(CommandHandler cmdHandle, boolean adminCommand) {
|
||||
this.cmdHandle = cmdHandle;
|
||||
this.adminCommand = adminCommand;
|
||||
|
||||
@@ -19,10 +19,9 @@ import com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueLi
|
||||
import com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueNumber;
|
||||
import com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueString;
|
||||
import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.advancedcore.api.valuerequest.InputMethod;
|
||||
import com.bencodez.advancedcore.api.valuerequest.ValueRequest;
|
||||
import com.bencodez.advancedcore.api.valuerequest.ValueRequestBuilder;
|
||||
import com.bencodez.advancedcore.api.valuerequest.listeners.StringListener;
|
||||
import com.bencodez.simpleapi.valuerequest.InputMethod;
|
||||
import com.bencodez.simpleapi.valuerequest.StringListener;
|
||||
import com.bencodez.simpleapi.valuerequest.ValueRequest;
|
||||
import com.bencodez.advancedcore.api.yml.editor.ConfigEditor;
|
||||
import com.bencodez.advancedcore.command.gui.RewardEditGUI;
|
||||
import com.bencodez.simpleapi.array.ArrayUtils;
|
||||
@@ -34,10 +33,18 @@ import com.bencodez.votingplugin.commands.gui.admin.voteshop.AdminVoteVoteShop;
|
||||
import com.bencodez.votingplugin.events.PlayerVoteEvent;
|
||||
import com.bencodez.votingplugin.votesites.VoteSite;
|
||||
|
||||
/**
|
||||
* Admin GUI handler for the voting plugin.
|
||||
*/
|
||||
public class AdminGUI {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Constructor for AdminGUI.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
*/
|
||||
public AdminGUI(VotingPluginMain plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@@ -57,7 +64,7 @@ public class AdminGUI {
|
||||
public void onClick(ClickEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (event.getClick().equals(ClickType.MIDDLE)) {
|
||||
new ValueRequest().requestString(player, new StringListener() {
|
||||
new ValueRequest(plugin, plugin.getDialogService(), null).requestString(player, "", null, true, "Enter vote site", new StringListener() {
|
||||
|
||||
@Override
|
||||
public void onInput(Player player, String value) {
|
||||
@@ -217,6 +224,9 @@ public class AdminGUI {
|
||||
return buttons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load hook to add admin GUI buttons.
|
||||
*/
|
||||
public void loadHook() {
|
||||
for (BInventoryButton b : adminGUIButtons()) {
|
||||
com.bencodez.advancedcore.command.gui.AdminGUI.getInstance().addButton(b);
|
||||
@@ -275,25 +285,25 @@ public class AdminGUI {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
playerNames.add(p.getName());
|
||||
}
|
||||
new ValueRequestBuilder(new StringListener() {
|
||||
new ValueRequest(plugin, plugin.getDialogService(), InputMethod.INVENTORY).requestString(
|
||||
event.getWhoClicked(), "", playerNames, true, "Select player", new StringListener() {
|
||||
|
||||
@Override
|
||||
public void onInput(Player player, String value) {
|
||||
Object ob = PlayerUtils.getPlayerMeta(plugin, player, "VoteSite");
|
||||
if (ob != null) {
|
||||
VoteSite site = (VoteSite) ob;
|
||||
PlayerVoteEvent voteEvent = new PlayerVoteEvent(site, value, site.getServiceSite(), false);
|
||||
plugin.getVoteTimer().submit(new Runnable() {
|
||||
@Override
|
||||
public void onInput(Player player, String value) {
|
||||
Object ob = PlayerUtils.getPlayerMeta(plugin, player, "VoteSite");
|
||||
if (ob != null) {
|
||||
VoteSite site = (VoteSite) ob;
|
||||
PlayerVoteEvent voteEvent = new PlayerVoteEvent(site, value, site.getServiceSite(), false);
|
||||
plugin.getVoteTimer().submit(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
plugin.getServer().getPluginManager().callEvent(voteEvent);
|
||||
@Override
|
||||
public void run() {
|
||||
plugin.getServer().getPluginManager().callEvent(voteEvent);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}, ArrayUtils.convert(playerNames)).usingMethod(InputMethod.INVENTORY).allowCustomOption(true)
|
||||
.request(event.getWhoClicked());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -442,4 +452,4 @@ public class AdminGUI {
|
||||
|
||||
inv.openInventory(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
+25
@@ -14,12 +14,22 @@ import com.bencodez.advancedcore.api.inventory.BInventoryButton;
|
||||
import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
/**
|
||||
* Abstract class for admin vote confirmation dialogs.
|
||||
*/
|
||||
public abstract class AdminVoteConfirmation extends GUIHandler {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private VotingPluginMain plugin;
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteConfirmation.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param player the command sender
|
||||
* @param title the title of the confirmation dialog
|
||||
*/
|
||||
public AdminVoteConfirmation(VotingPluginMain plugin, CommandSender player, String title) {
|
||||
super(plugin, player);
|
||||
this.plugin = plugin;
|
||||
@@ -31,6 +41,11 @@ public abstract class AdminVoteConfirmation extends GUIHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
}
|
||||
@@ -60,8 +75,18 @@ public abstract class AdminVoteConfirmation extends GUIHandler {
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the user confirms the action.
|
||||
*
|
||||
* @param p the player who confirmed
|
||||
*/
|
||||
public abstract void onConfirm(Player p);
|
||||
|
||||
/**
|
||||
* Called when the user denies the action.
|
||||
*
|
||||
* @param p the player who denied
|
||||
*/
|
||||
public abstract void onDeny(Player p);
|
||||
|
||||
@Override
|
||||
|
||||
+15
@@ -15,11 +15,21 @@ import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
/**
|
||||
* Admin help GUI handler.
|
||||
*/
|
||||
public class AdminVoteHelp extends GUIHandler {
|
||||
|
||||
private int page;
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteHelp.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param player the command sender
|
||||
* @param page the page number to display
|
||||
*/
|
||||
public AdminVoteHelp(VotingPluginMain plugin, CommandSender player, int page) {
|
||||
super(plugin, player);
|
||||
this.plugin = plugin;
|
||||
@@ -54,6 +64,11 @@ public class AdminVoteHelp extends GUIHandler {
|
||||
return msg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin help text.
|
||||
*
|
||||
|
||||
+43
@@ -15,18 +15,36 @@ import com.bencodez.advancedcore.api.gui.GUIMethod;
|
||||
import com.bencodez.simpleapi.array.ArrayUtils;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
/**
|
||||
* Admin permissions GUI handler.
|
||||
*/
|
||||
public class AdminVotePerms extends GUIHandler {
|
||||
|
||||
private int page;
|
||||
private String playerName;
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVotePerms.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param player the command sender
|
||||
* @param page the page number
|
||||
*/
|
||||
public AdminVotePerms(VotingPluginMain plugin, CommandSender player, int page) {
|
||||
super(plugin, player);
|
||||
this.plugin = plugin;
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for AdminVotePerms with player name.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param player the command sender
|
||||
* @param page the page number
|
||||
* @param playerName the player name to check
|
||||
*/
|
||||
public AdminVotePerms(VotingPluginMain plugin, CommandSender player, int page, String playerName) {
|
||||
super(plugin, player);
|
||||
this.plugin = plugin;
|
||||
@@ -39,6 +57,17 @@ public class AdminVotePerms extends GUIHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* List permissions for a sender.
|
||||
*
|
||||
* @param sender the command sender
|
||||
* @return array of permission strings
|
||||
*/
|
||||
public String[] listPerms(CommandSender sender) {
|
||||
ArrayList<String> msg = new ArrayList<>();
|
||||
|
||||
@@ -113,6 +142,14 @@ public class AdminVotePerms extends GUIHandler {
|
||||
return ArrayUtils.convert(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* List permissions for a specific player.
|
||||
*
|
||||
* @param sender the command sender
|
||||
* @param player the player name
|
||||
* @param page the page number
|
||||
* @return list of permission strings
|
||||
*/
|
||||
public ArrayList<String> listPerms(CommandSender sender, String player, int page) {
|
||||
Player p = Bukkit.getPlayer(player);
|
||||
ArrayList<String> text = new ArrayList<>();
|
||||
@@ -179,6 +216,12 @@ public class AdminVotePerms extends GUIHandler {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* List permissions in developer format.
|
||||
*
|
||||
* @param sender the command sender
|
||||
* @return array of permission strings in developer format
|
||||
*/
|
||||
public String[] listPermsDev(CommandSender sender) {
|
||||
ArrayList<String> msg = new ArrayList<>();
|
||||
msg.add("Command");
|
||||
|
||||
+14
@@ -18,10 +18,19 @@ import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
import xyz.upperlevel.spigot.book.BookUtil;
|
||||
|
||||
/**
|
||||
* Admin placeholders GUI handler.
|
||||
*/
|
||||
public class AdminVotePlaceholders extends GUIHandler {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVotePlaceholders.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param player the command sender
|
||||
*/
|
||||
public AdminVotePlaceholders(VotingPluginMain plugin, CommandSender player) {
|
||||
super(plugin, player);
|
||||
this.plugin = plugin;
|
||||
@@ -32,6 +41,11 @@ public class AdminVotePlaceholders extends GUIHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
BookWrapper book = new BookWrapper("Placeholders");
|
||||
|
||||
+15
@@ -18,11 +18,21 @@ import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
import xyz.upperlevel.spigot.book.BookUtil;
|
||||
|
||||
/**
|
||||
* Admin placeholders player GUI handler.
|
||||
*/
|
||||
public class AdminVotePlaceholdersPlayer extends GUIHandler {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
private VotingPluginUser user;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVotePlaceholdersPlayer.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param player the command sender
|
||||
* @param user the voting plugin user
|
||||
*/
|
||||
public AdminVotePlaceholdersPlayer(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) {
|
||||
super(plugin, player);
|
||||
this.plugin = plugin;
|
||||
@@ -34,6 +44,11 @@ public class AdminVotePlaceholdersPlayer extends GUIHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
BookWrapper book = new BookWrapper("Placeholders");
|
||||
|
||||
+16
@@ -27,6 +27,9 @@ import com.bencodez.votingplugin.commands.gui.player.VoteGUI;
|
||||
import com.bencodez.votingplugin.topvoter.TopVoterPlayer;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
/**
|
||||
* Admin top points GUI handler.
|
||||
*/
|
||||
public class AdminVoteTopPoints extends GUIHandler {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@@ -34,6 +37,14 @@ public class AdminVoteTopPoints extends GUIHandler {
|
||||
private VotingPluginMain plugin;
|
||||
private VotingPluginUser user;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteTopPoints.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param player the command sender
|
||||
* @param user the voting plugin user
|
||||
* @param page the page number
|
||||
*/
|
||||
public AdminVoteTopPoints(VotingPluginMain plugin, CommandSender player, VotingPluginUser user, int page) {
|
||||
super(plugin, player);
|
||||
this.plugin = plugin;
|
||||
@@ -46,6 +57,11 @@ public class AdminVoteTopPoints extends GUIHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
}
|
||||
|
||||
+32
-14
@@ -17,15 +17,25 @@ import com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueLi
|
||||
import com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueNumber;
|
||||
import com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueString;
|
||||
import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.advancedcore.api.valuerequest.ValueRequestBuilder;
|
||||
import com.bencodez.advancedcore.api.valuerequest.listeners.NumberListener;
|
||||
import com.bencodez.advancedcore.command.gui.RewardEditGUI;
|
||||
import com.bencodez.simpleapi.valuerequest.InputMethod;
|
||||
import com.bencodez.simpleapi.valuerequest.NumberListener;
|
||||
import com.bencodez.simpleapi.valuerequest.ValueRequest;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
/**
|
||||
* Admin vote party GUI handler.
|
||||
*/
|
||||
public class AdminVoteVoteParty extends GUIHandler {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteVoteParty.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param player the command sender
|
||||
*/
|
||||
public AdminVoteVoteParty(VotingPluginMain plugin, CommandSender player) {
|
||||
super(plugin, player);
|
||||
this.plugin = plugin;
|
||||
@@ -45,12 +55,16 @@ public class AdminVoteVoteParty extends GUIHandler {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
EditGUI inv = new EditGUI("Edit VoteParty");
|
||||
inv.requirePermission("VotingPlugin.Commands.AdminVote.Edit.VoteParty");
|
||||
|
||||
// to add
|
||||
inv.addButton(new EditGUIButton(new ItemBuilder(Material.PAPER, 1),
|
||||
new EditGUIValueBoolean("Enabled", plugin.getSpecialRewardsConfig().isVotePartyEnabled()) {
|
||||
|
||||
@@ -83,15 +97,21 @@ public class AdminVoteVoteParty extends GUIHandler {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
new ValueRequestBuilder(new NumberListener() {
|
||||
ArrayList<Number> options = new ArrayList<Number>();
|
||||
options.add(Integer.valueOf(0));
|
||||
options.add(Integer.valueOf(10));
|
||||
options.add(Integer.valueOf(50));
|
||||
options.add(Integer.valueOf(100));
|
||||
|
||||
@Override
|
||||
public void onInput(Player player, Number value) {
|
||||
plugin.getServerData().setVotePartyExtraRequired(value.intValue());
|
||||
}
|
||||
}, new Number[] { 0, 10, 50, 100 })
|
||||
.currentValue("" + plugin.getServerData().getVotePartyExtraRequired()).allowCustomOption(true)
|
||||
.request(clickEvent.getPlayer());
|
||||
new ValueRequest(plugin, plugin.getDialogService(), InputMethod.INVENTORY).requestNumber(
|
||||
clickEvent.getPlayer(), Integer.valueOf(plugin.getServerData().getVotePartyExtraRequired()),
|
||||
options, true, "Set extra votes", new NumberListener() {
|
||||
|
||||
@Override
|
||||
public void onInput(Player player, Number value) {
|
||||
plugin.getServerData().setVotePartyExtraRequired(value.intValue());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
@@ -215,8 +235,6 @@ public class AdminVoteVoteParty extends GUIHandler {
|
||||
}
|
||||
});
|
||||
|
||||
// implement item reward?
|
||||
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
@@ -231,4 +249,4 @@ public class AdminVoteVoteParty extends GUIHandler {
|
||||
plugin.reload();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+15
@@ -14,11 +14,21 @@ import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.events.PlayerVoteEvent;
|
||||
import com.bencodez.votingplugin.votesites.VoteSite;
|
||||
|
||||
/**
|
||||
* Admin vote player GUI handler.
|
||||
*/
|
||||
public class AdminVoteVotePlayer extends GUIHandler {
|
||||
|
||||
private String playerName;
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteVotePlayer.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param player the command sender
|
||||
* @param playerName the player name
|
||||
*/
|
||||
public AdminVoteVotePlayer(VotingPluginMain plugin, CommandSender player, String playerName) {
|
||||
super(plugin, player);
|
||||
this.plugin = plugin;
|
||||
@@ -71,6 +81,11 @@ public class AdminVoteVotePlayer extends GUIHandler {
|
||||
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
|
||||
+14
@@ -15,10 +15,19 @@ import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.commands.gui.admin.AdminVoteConfirmation;
|
||||
|
||||
/**
|
||||
* Admin vote milestone remove GUI handler.
|
||||
*/
|
||||
public class AdminVoteVoteMilestoneRemove extends GUIHandler {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteVoteMilestoneRemove.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param player the command sender
|
||||
*/
|
||||
public AdminVoteVoteMilestoneRemove(VotingPluginMain plugin, CommandSender player) {
|
||||
super(plugin, player);
|
||||
this.plugin = plugin;
|
||||
@@ -38,6 +47,11 @@ public class AdminVoteVoteMilestoneRemove extends GUIHandler {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
BInventory inv = new BInventory("Remove VoteMilestones");
|
||||
|
||||
+38
-24
@@ -13,19 +13,26 @@ import com.bencodez.advancedcore.api.inventory.BInventory;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventoryButton;
|
||||
import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.advancedcore.api.valuerequest.InputMethod;
|
||||
import com.bencodez.advancedcore.api.valuerequest.ValueRequest;
|
||||
import com.bencodez.advancedcore.api.valuerequest.ValueRequestBuilder;
|
||||
import com.bencodez.advancedcore.api.valuerequest.listeners.NumberListener;
|
||||
import com.bencodez.advancedcore.api.valuerequest.listeners.StringListener;
|
||||
import com.bencodez.advancedcore.command.gui.RewardEditGUI;
|
||||
import com.bencodez.simpleapi.array.ArrayUtils;
|
||||
import com.bencodez.simpleapi.valuerequest.InputMethod;
|
||||
import com.bencodez.simpleapi.valuerequest.NumberListener;
|
||||
import com.bencodez.simpleapi.valuerequest.StringListener;
|
||||
import com.bencodez.simpleapi.valuerequest.ValueRequest;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
/**
|
||||
* Admin vote milestones GUI handler.
|
||||
*/
|
||||
public class AdminVoteVoteMilestones extends GUIHandler {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteVoteMilestones.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param player the command sender
|
||||
*/
|
||||
public AdminVoteVoteMilestones(VotingPluginMain plugin, CommandSender player) {
|
||||
super(plugin, player);
|
||||
this.plugin = plugin;
|
||||
@@ -45,6 +52,11 @@ public class AdminVoteVoteMilestones extends GUIHandler {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
BInventory inv = new BInventory("Edit VoteMilestones");
|
||||
@@ -55,21 +67,22 @@ public class AdminVoteVoteMilestones extends GUIHandler {
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
Set<String> keys = plugin.getVoteMilestonesManager().getConfig().getMilestones().keySet();
|
||||
ArrayList<String> milestoneKeys = new ArrayList<String>();
|
||||
for (String key : keys) {
|
||||
if (key.startsWith("Legacy_")) {
|
||||
keys.remove(key);
|
||||
if (!key.startsWith("Legacy_")) {
|
||||
milestoneKeys.add(key);
|
||||
}
|
||||
}
|
||||
new ValueRequestBuilder(new StringListener() {
|
||||
|
||||
@Override
|
||||
public void onInput(Player player, String value) {
|
||||
RewardEditGUI.getInstance().openRewardGUI(clickEvent.getPlayer(),
|
||||
plugin.getRewardHandler().getDirectlyDefined("VoteMilestones." + value + ".Rewards"));
|
||||
}
|
||||
}, ArrayUtils.convertSet(keys)).allowCustomOption(false).usingMethod(InputMethod.INVENTORY)
|
||||
.request(clickEvent.getPlayer());
|
||||
new ValueRequest(plugin, plugin.getDialogService(), InputMethod.INVENTORY).requestString(
|
||||
clickEvent.getPlayer(), "", milestoneKeys, false, "Select milestone", new StringListener() {
|
||||
|
||||
@Override
|
||||
public void onInput(Player player, String value) {
|
||||
RewardEditGUI.getInstance().openRewardGUI(clickEvent.getPlayer(),
|
||||
plugin.getRewardHandler().getDirectlyDefined("VoteMilestones." + value + ".Rewards"));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -77,14 +90,15 @@ public class AdminVoteVoteMilestones extends GUIHandler {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
new ValueRequest().requestNumber(player, new NumberListener() {
|
||||
new ValueRequest(plugin, plugin.getDialogService(), null).requestNumber(player, 0, null, true,
|
||||
"Enter milestone", new NumberListener() {
|
||||
|
||||
@Override
|
||||
public void onInput(Player player, Number value) {
|
||||
plugin.getSpecialRewardsConfig().setVoteMilestone(value.intValue());
|
||||
plugin.reload();
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onInput(Player player, Number value) {
|
||||
plugin.getSpecialRewardsConfig().setVoteMilestone(value.intValue());
|
||||
plugin.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -103,4 +117,4 @@ public class AdminVoteVoteMilestones extends GUIHandler {
|
||||
open(GUIMethod.CHEST);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+24
@@ -32,11 +32,35 @@ public class AdminVoteLogEventSelect extends GUIHandler {
|
||||
|
||||
private static final int PAGE_SIZE = 45;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteLogEventSelect.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param sender the command sender
|
||||
* @param table the vote log table
|
||||
* @param user the voting plugin user
|
||||
* @param days the number of days to filter
|
||||
*/
|
||||
public AdminVoteLogEventSelect(VotingPluginMain plugin, CommandSender sender, VoteLogMysqlTable table,
|
||||
VotingPluginUser user, int days) {
|
||||
this(plugin, sender, table, user, days, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteLogEventSelect with page.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param sender the command sender
|
||||
* @param table the vote log table
|
||||
* @param user the voting plugin user
|
||||
* @param days the number of days to filter
|
||||
* @param page the page number
|
||||
*/
|
||||
public AdminVoteLogEventSelect(VotingPluginMain plugin, CommandSender sender, VoteLogMysqlTable table,
|
||||
VotingPluginUser user, int days, int page) {
|
||||
super(plugin, sender);
|
||||
|
||||
+40
@@ -7,7 +7,17 @@ import org.bukkit.Material;
|
||||
|
||||
import com.bencodez.votingplugin.votelog.VoteLogMysqlTable;
|
||||
|
||||
/**
|
||||
* Helper class for admin vote log GUI operations.
|
||||
*/
|
||||
public class AdminVoteLogHelpers {
|
||||
/**
|
||||
* Get the material icon for a vote log event.
|
||||
*
|
||||
* @param event the vote log event
|
||||
* @param status the status of the vote
|
||||
* @return the material to use for the icon
|
||||
*/
|
||||
public static Material getMaterialForEvent(VoteLogMysqlTable.VoteLogEvent event, String status) {
|
||||
// Cached entries still override to chest (keeps your current behavior)
|
||||
if ("CACHED".equalsIgnoreCase(status)) {
|
||||
@@ -36,6 +46,12 @@ public class AdminVoteLogHelpers {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color code for a vote log event.
|
||||
*
|
||||
* @param event the vote log event
|
||||
* @return the color code string
|
||||
*/
|
||||
public static String getEventColor(VoteLogMysqlTable.VoteLogEvent event) {
|
||||
if (event == null) {
|
||||
return "&7";
|
||||
@@ -58,14 +74,32 @@ public class AdminVoteLogHelpers {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a safe string, converting null to empty string.
|
||||
*
|
||||
* @param s the string to check
|
||||
* @return the string or empty string if null
|
||||
*/
|
||||
public static String safe(String s) {
|
||||
return s == null ? "" : s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a string is not null and not empty.
|
||||
*
|
||||
* @param s the string to check
|
||||
* @return true if the string is not empty
|
||||
*/
|
||||
public static boolean notEmpty(String s) {
|
||||
return s != null && !s.trim().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a timestamp in milliseconds to a readable date string.
|
||||
*
|
||||
* @param millis the timestamp in milliseconds
|
||||
* @return the formatted date string
|
||||
*/
|
||||
public static String formatTime(long millis) {
|
||||
try {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
@@ -75,6 +109,12 @@ public class AdminVoteLogHelpers {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a shortened version of a UUID string.
|
||||
*
|
||||
* @param uuid the UUID string
|
||||
* @return the first 8 characters of the UUID or "unknown"
|
||||
*/
|
||||
public static String shortUuid(String uuid) {
|
||||
if (uuid == null || uuid.isEmpty()) {
|
||||
return "unknown";
|
||||
|
||||
+30
-10
@@ -16,6 +16,9 @@ import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
import com.bencodez.votingplugin.votelog.VoteLogMysqlTable;
|
||||
|
||||
/**
|
||||
* Admin vote log menu GUI handler.
|
||||
*/
|
||||
public class AdminVoteLogMenu extends GUIHandler {
|
||||
|
||||
private final VotingPluginMain plugin;
|
||||
@@ -27,10 +30,32 @@ public class AdminVoteLogMenu extends GUIHandler {
|
||||
// Default to "voting" (Vote received)
|
||||
private final VoteLogMysqlTable.VoteLogEvent defaultEvent = VoteLogMysqlTable.VoteLogEvent.VOTE_RECEIVED;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteLogMenu.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param sender the command sender
|
||||
* @param table the vote log table
|
||||
* @param days the number of days to filter
|
||||
*/
|
||||
public AdminVoteLogMenu(VotingPluginMain plugin, CommandSender sender, VoteLogMysqlTable table, int days) {
|
||||
this(plugin, sender, table, null, days);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteLogMenu with user.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param sender the command sender
|
||||
* @param table the vote log table
|
||||
* @param user the voting plugin user
|
||||
* @param days the number of days to filter
|
||||
*/
|
||||
public AdminVoteLogMenu(VotingPluginMain plugin, CommandSender sender, VoteLogMysqlTable table,
|
||||
VotingPluginUser user, int days) {
|
||||
super(plugin, sender);
|
||||
@@ -86,8 +111,7 @@ public class AdminVoteLogMenu extends GUIHandler {
|
||||
}
|
||||
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(Material.NAME_TAG).setName("&aVotes by Player")
|
||||
.addLoreLine("&7List stored player names")
|
||||
.addLoreLine("&7Click a player to view their votelog")) {
|
||||
.addLoreLine("&7List stored player names").addLoreLine("&7Click a player to view their votelog")) {
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
new AdminVoteLogPlayerSelect(plugin, clickEvent.getPlayer(), table, user, days, 0).open();
|
||||
@@ -95,8 +119,7 @@ public class AdminVoteLogMenu extends GUIHandler {
|
||||
});
|
||||
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(Material.NAME_TAG).setName("&aVotes by Player (Online)")
|
||||
.addLoreLine("&7List online players")
|
||||
.addLoreLine("&7Click a player to view their votelog")) {
|
||||
.addLoreLine("&7List online players").addLoreLine("&7Click a player to view their votelog")) {
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
new AdminVoteLogPlayerSelectOnline(plugin, clickEvent.getPlayer(), table, user, days, 0).open();
|
||||
@@ -104,8 +127,7 @@ public class AdminVoteLogMenu extends GUIHandler {
|
||||
});
|
||||
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(Material.PAPER).setName("&aVotes by Service")
|
||||
.addLoreLine("&7List all services found")
|
||||
.addLoreLine("&7Click a service to view votelog")) {
|
||||
.addLoreLine("&7List all services found").addLoreLine("&7Click a service to view votelog")) {
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
new AdminVoteLogServiceSelect(plugin, clickEvent.getPlayer(), table, user, days, 0).open();
|
||||
@@ -114,8 +136,7 @@ public class AdminVoteLogMenu extends GUIHandler {
|
||||
|
||||
// NEW: Votes by Server
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(Material.COMPASS).setName("&aVotes by Server")
|
||||
.addLoreLine("&7List all servers found")
|
||||
.addLoreLine("&7Click a server to view votelog")) {
|
||||
.addLoreLine("&7List all servers found").addLoreLine("&7Click a server to view votelog")) {
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
new AdminVoteLogServerSelect(plugin, clickEvent.getPlayer(), table, user, days, 0).open();
|
||||
@@ -132,8 +153,7 @@ public class AdminVoteLogMenu extends GUIHandler {
|
||||
});
|
||||
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(Material.CLOCK).setName("&aRecent Logs")
|
||||
.addLoreLine("&7Recent logs filtered by event")
|
||||
.addLoreLine("&7Default: &f" + defaultEvent.name())
|
||||
.addLoreLine("&7Recent logs filtered by event").addLoreLine("&7Default: &f" + defaultEvent.name())
|
||||
.addLoreLine("&8(Use bottom buttons to switch event)")) {
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
+15
@@ -36,6 +36,16 @@ public class AdminVoteLogPlayer extends GUIHandler {
|
||||
|
||||
private static final int PAGE_SIZE = 45;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteLogPlayer.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param sender the command sender
|
||||
* @param table the vote log table
|
||||
* @param playerName the player name or UUID
|
||||
* @param days the number of days to filter
|
||||
* @param page the page number
|
||||
*/
|
||||
public AdminVoteLogPlayer(VotingPluginMain plugin, CommandSender sender, VoteLogMysqlTable table, String playerName,
|
||||
int days, int page) {
|
||||
super(plugin, sender);
|
||||
@@ -47,6 +57,11 @@ public class AdminVoteLogPlayer extends GUIHandler {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender sender) {
|
||||
return null;
|
||||
|
||||
+15
@@ -32,6 +32,16 @@ public class AdminVoteLogPlayerSelect extends GUIHandler {
|
||||
|
||||
private static final int PAGE_SIZE = 45;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteLogPlayerSelect.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param sender the command sender
|
||||
* @param table the vote log table
|
||||
* @param user the voting plugin user
|
||||
* @param days the number of days to filter
|
||||
* @param page the page number
|
||||
*/
|
||||
public AdminVoteLogPlayerSelect(VotingPluginMain plugin, CommandSender sender, VoteLogMysqlTable table,
|
||||
VotingPluginUser user, int days, int page) {
|
||||
super(plugin, sender);
|
||||
@@ -51,6 +61,11 @@ public class AdminVoteLogPlayerSelect extends GUIHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
}
|
||||
|
||||
+15
@@ -32,6 +32,16 @@ public class AdminVoteLogPlayerSelectOnline extends GUIHandler {
|
||||
|
||||
private static final int PAGE_SIZE = 45;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteLogPlayerSelectOnline.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param sender the command sender
|
||||
* @param table the vote log table
|
||||
* @param user the voting plugin user
|
||||
* @param days the number of days to filter
|
||||
* @param page the page number
|
||||
*/
|
||||
public AdminVoteLogPlayerSelectOnline(VotingPluginMain plugin, CommandSender sender, VoteLogMysqlTable table,
|
||||
VotingPluginUser user, int days, int page) {
|
||||
super(plugin, sender);
|
||||
@@ -46,6 +56,11 @@ public class AdminVoteLogPlayerSelectOnline extends GUIHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender sender) {
|
||||
return null;
|
||||
|
||||
+33
@@ -35,15 +35,43 @@ public class AdminVoteLogRecent extends GUIHandler {
|
||||
|
||||
private static final int PAGE_SIZE = 45;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteLogRecent.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param sender the command sender
|
||||
* @param table the vote log table
|
||||
* @param page the page number
|
||||
*/
|
||||
public AdminVoteLogRecent(VotingPluginMain plugin, CommandSender sender, VoteLogMysqlTable table, int page) {
|
||||
this(plugin, sender, table, null, page, 0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteLogRecent with user.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param sender the command sender
|
||||
* @param table the vote log table
|
||||
* @param user the voting plugin user
|
||||
* @param page the page number
|
||||
*/
|
||||
public AdminVoteLogRecent(VotingPluginMain plugin, CommandSender sender, VoteLogMysqlTable table,
|
||||
VotingPluginUser user, int page) {
|
||||
this(plugin, sender, table, user, page, 0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteLogRecent with full parameters.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param sender the command sender
|
||||
* @param table the vote log table
|
||||
* @param user the voting plugin user
|
||||
* @param page the page number
|
||||
* @param days the number of days to filter
|
||||
* @param event the event type to filter
|
||||
*/
|
||||
// NEW constructor used by Menu/EventSelect
|
||||
public AdminVoteLogRecent(VotingPluginMain plugin, CommandSender sender, VoteLogMysqlTable table,
|
||||
VotingPluginUser user, int page, int days, VoteLogMysqlTable.VoteLogEvent event) {
|
||||
@@ -72,6 +100,11 @@ public class AdminVoteLogRecent extends GUIHandler {
|
||||
public void onChat(CommandSender sender) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
try {
|
||||
|
||||
+28
-2
@@ -34,6 +34,16 @@ public class AdminVoteLogServer extends GUIHandler {
|
||||
|
||||
private static final int PAGE_SIZE = 45;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteLogServer.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param sender the command sender
|
||||
* @param table the vote log table
|
||||
* @param server the server name
|
||||
* @param days the number of days to filter
|
||||
* @param page the page number
|
||||
*/
|
||||
public AdminVoteLogServer(VotingPluginMain plugin, CommandSender sender, VoteLogMysqlTable table, String server,
|
||||
int days, int page) {
|
||||
super(plugin, sender);
|
||||
@@ -48,6 +58,17 @@ public class AdminVoteLogServer extends GUIHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteLogServer with user.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param sender the command sender
|
||||
* @param table the vote log table
|
||||
* @param user the voting plugin user
|
||||
* @param server the server name
|
||||
* @param days the number of days to filter
|
||||
* @param page the page number
|
||||
*/
|
||||
public AdminVoteLogServer(VotingPluginMain plugin, CommandSender sender, VoteLogMysqlTable table,
|
||||
VotingPluginUser user, String server, int days, int page) {
|
||||
this(plugin, sender, table, server, days, page);
|
||||
@@ -70,6 +91,11 @@ public class AdminVoteLogServer extends GUIHandler {
|
||||
public void onChat(CommandSender sender) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
try {
|
||||
@@ -124,8 +150,8 @@ public class AdminVoteLogServer extends GUIHandler {
|
||||
}
|
||||
|
||||
private BInventoryButton makeEntryButton(final VoteLogMysqlTable.VoteLogEntry entry) {
|
||||
VoteLogMysqlTable.VoteLogEvent event =
|
||||
entry.event != null ? VoteLogMysqlTable.VoteLogEvent.valueOf(entry.event) : null;
|
||||
VoteLogMysqlTable.VoteLogEvent event = entry.event != null ? VoteLogMysqlTable.VoteLogEvent.valueOf(entry.event)
|
||||
: null;
|
||||
|
||||
Material mat = AdminVoteLogHelpers.getMaterialForEvent(event, entry.status);
|
||||
String eventColor = AdminVoteLogHelpers.getEventColor(event);
|
||||
|
||||
+15
@@ -31,6 +31,16 @@ public class AdminVoteLogServerSelect extends GUIHandler {
|
||||
|
||||
private static final int PAGE_SIZE = 45;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteLogServerSelect.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param sender the command sender
|
||||
* @param table the vote log table
|
||||
* @param user the voting plugin user
|
||||
* @param days the number of days to filter
|
||||
* @param page the page number
|
||||
*/
|
||||
public AdminVoteLogServerSelect(VotingPluginMain plugin, CommandSender sender, VoteLogMysqlTable table,
|
||||
VotingPluginUser user, int days, int page) {
|
||||
super(plugin, sender);
|
||||
@@ -50,6 +60,11 @@ public class AdminVoteLogServerSelect extends GUIHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
}
|
||||
|
||||
+28
-2
@@ -34,6 +34,16 @@ public class AdminVoteLogService extends GUIHandler {
|
||||
|
||||
private static final int PAGE_SIZE = 45;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteLogService.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param sender the command sender
|
||||
* @param table the vote log table
|
||||
* @param service the service name
|
||||
* @param days the number of days to filter
|
||||
* @param page the page number
|
||||
*/
|
||||
public AdminVoteLogService(VotingPluginMain plugin, CommandSender sender, VoteLogMysqlTable table, String service,
|
||||
int days, int page) {
|
||||
super(plugin, sender);
|
||||
@@ -48,6 +58,17 @@ public class AdminVoteLogService extends GUIHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteLogService with user.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param sender the command sender
|
||||
* @param table the vote log table
|
||||
* @param user the voting plugin user
|
||||
* @param service the service name
|
||||
* @param days the number of days to filter
|
||||
* @param page the page number
|
||||
*/
|
||||
public AdminVoteLogService(VotingPluginMain plugin, CommandSender sender, VoteLogMysqlTable table,
|
||||
VotingPluginUser user, String service, int days, int page) {
|
||||
this(plugin, sender, table, service, days, page);
|
||||
@@ -70,6 +91,11 @@ public class AdminVoteLogService extends GUIHandler {
|
||||
public void onChat(CommandSender sender) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
try {
|
||||
@@ -126,8 +152,8 @@ public class AdminVoteLogService extends GUIHandler {
|
||||
}
|
||||
|
||||
private BInventoryButton makeEntryButton(final VoteLogMysqlTable.VoteLogEntry entry) {
|
||||
VoteLogMysqlTable.VoteLogEvent event =
|
||||
entry.event != null ? VoteLogMysqlTable.VoteLogEvent.valueOf(entry.event) : null;
|
||||
VoteLogMysqlTable.VoteLogEvent event = entry.event != null ? VoteLogMysqlTable.VoteLogEvent.valueOf(entry.event)
|
||||
: null;
|
||||
|
||||
Material mat = AdminVoteLogHelpers.getMaterialForEvent(event, entry.status);
|
||||
|
||||
|
||||
+15
@@ -31,6 +31,16 @@ public class AdminVoteLogServiceSelect extends GUIHandler {
|
||||
|
||||
private static final int PAGE_SIZE = 45;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteLogServiceSelect.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param sender the command sender
|
||||
* @param table the vote log table
|
||||
* @param user the voting plugin user
|
||||
* @param days the number of days to filter
|
||||
* @param page the page number
|
||||
*/
|
||||
public AdminVoteLogServiceSelect(VotingPluginMain plugin, CommandSender sender, VoteLogMysqlTable table,
|
||||
VotingPluginUser user, int days, int page) {
|
||||
super(plugin, sender);
|
||||
@@ -58,6 +68,11 @@ public class AdminVoteLogServiceSelect extends GUIHandler {
|
||||
public void onChat(CommandSender sender) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
try {
|
||||
|
||||
+15
@@ -32,6 +32,16 @@ public class AdminVoteLogServiceSelectAll extends GUIHandler {
|
||||
|
||||
private static final int PAGE_SIZE = 45;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteLogServiceSelectAll.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param sender the command sender
|
||||
* @param table the vote log table
|
||||
* @param user the voting plugin user
|
||||
* @param days the number of days to filter
|
||||
* @param page the page number
|
||||
*/
|
||||
public AdminVoteLogServiceSelectAll(VotingPluginMain plugin, CommandSender sender, VoteLogMysqlTable table,
|
||||
VotingPluginUser user, int days, int page) {
|
||||
super(plugin, sender);
|
||||
@@ -59,6 +69,11 @@ public class AdminVoteLogServiceSelectAll extends GUIHandler {
|
||||
public void onChat(CommandSender sender) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
try {
|
||||
|
||||
+39
-11
@@ -21,11 +21,8 @@ import com.bencodez.votingplugin.votelog.VoteLogMysqlTable;
|
||||
*
|
||||
* Uses VoteLogMysqlTable instance passed in from CommandLoader.
|
||||
*
|
||||
* Shows:
|
||||
* - total / immediate / cached counts (VoteLogCounts)
|
||||
* - unique voters
|
||||
* - top services
|
||||
* - top servers
|
||||
* Shows: - total / immediate / cached counts (VoteLogCounts) - unique voters -
|
||||
* top services - top servers
|
||||
*/
|
||||
public class AdminVoteLogStats extends GUIHandler {
|
||||
|
||||
@@ -38,15 +35,44 @@ public class AdminVoteLogStats extends GUIHandler {
|
||||
private final int topServicesLimit;
|
||||
private final int topServersLimit;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteLogStats.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param sender the command sender
|
||||
* @param table the vote log table
|
||||
* @param days the number of days to filter
|
||||
*/
|
||||
public AdminVoteLogStats(VotingPluginMain plugin, CommandSender sender, VoteLogMysqlTable table, int days) {
|
||||
this(plugin, sender, table, null, days, 10, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteLogStats with user and top services limit.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param sender the command sender
|
||||
* @param table the vote log table
|
||||
* @param user the voting plugin user
|
||||
* @param days the number of days to filter
|
||||
* @param topServicesLimit the maximum number of top services to display
|
||||
*/
|
||||
public AdminVoteLogStats(VotingPluginMain plugin, CommandSender sender, VoteLogMysqlTable table,
|
||||
VotingPluginUser user, int days, int topServicesLimit) {
|
||||
this(plugin, sender, table, user, days, topServicesLimit, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteLogStats with full parameters.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param sender the command sender
|
||||
* @param table the vote log table
|
||||
* @param user the voting plugin user
|
||||
* @param days the number of days to filter
|
||||
* @param topServicesLimit the maximum number of top services to display
|
||||
* @param topServersLimit the maximum number of top servers to display
|
||||
*/
|
||||
public AdminVoteLogStats(VotingPluginMain plugin, CommandSender sender, VoteLogMysqlTable table,
|
||||
VotingPluginUser user, int days, int topServicesLimit, int topServersLimit) {
|
||||
super(plugin, sender);
|
||||
@@ -74,6 +100,11 @@ public class AdminVoteLogStats extends GUIHandler {
|
||||
public void onChat(CommandSender sender) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
try {
|
||||
@@ -110,10 +141,8 @@ public class AdminVoteLogStats extends GUIHandler {
|
||||
long uniques = table.getUniqueVoters(days);
|
||||
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(Material.BOOK).setName("&aOverview")
|
||||
.addLoreLine("&7Total Votes: &f" + counts.total)
|
||||
.addLoreLine("&7Immediate: &f" + counts.immediate)
|
||||
.addLoreLine("&7Cached: &f" + counts.cached)
|
||||
.addLoreLine("&7Unique Voters: &f" + uniques)
|
||||
.addLoreLine("&7Total Votes: &f" + counts.total).addLoreLine("&7Immediate: &f" + counts.immediate)
|
||||
.addLoreLine("&7Cached: &f" + counts.cached).addLoreLine("&7Unique Voters: &f" + uniques)
|
||||
.addLoreLine(days > 0 ? "&7Window: &fLast " + days + " days" : "&7Window: &fAll time")) {
|
||||
|
||||
@Override
|
||||
@@ -161,8 +190,7 @@ public class AdminVoteLogStats extends GUIHandler {
|
||||
|
||||
// top servers header
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(Material.COMPASS).setName("&aTop Servers")
|
||||
.addLoreLine("&7Top " + topServersLimit + " servers:")
|
||||
.addLoreLine("&8(Click does nothing)")) {
|
||||
.addLoreLine("&7Top " + topServersLimit + " servers:").addLoreLine("&8(Click does nothing)")) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
|
||||
+26
@@ -36,6 +36,16 @@ public class AdminVoteLogVoteId extends GUIHandler {
|
||||
|
||||
private static final int PAGE_SIZE = 45;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteLogVoteId.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param sender the command sender
|
||||
* @param table the vote log table
|
||||
* @param voteId the vote ID to filter
|
||||
* @param days the number of days to filter
|
||||
* @param page the page number
|
||||
*/
|
||||
public AdminVoteLogVoteId(VotingPluginMain plugin, CommandSender sender, VoteLogMysqlTable table, String voteId,
|
||||
int days, int page) {
|
||||
super(plugin, sender);
|
||||
@@ -50,6 +60,17 @@ public class AdminVoteLogVoteId extends GUIHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteLogVoteId with user.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param sender the command sender
|
||||
* @param table the vote log table
|
||||
* @param user the voting plugin user
|
||||
* @param voteId the vote ID to filter
|
||||
* @param days the number of days to filter
|
||||
* @param page the page number
|
||||
*/
|
||||
public AdminVoteLogVoteId(VotingPluginMain plugin, CommandSender sender, VoteLogMysqlTable table,
|
||||
VotingPluginUser user, String voteId, int days, int page) {
|
||||
this(plugin, sender, table, voteId, days, page);
|
||||
@@ -72,6 +93,11 @@ public class AdminVoteLogVoteId extends GUIHandler {
|
||||
public void onChat(CommandSender sender) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
try {
|
||||
|
||||
+25
-10
@@ -12,14 +12,23 @@ import com.bencodez.advancedcore.api.inventory.BInventory;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventoryButton;
|
||||
import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.advancedcore.api.valuerequest.ValueRequest;
|
||||
import com.bencodez.advancedcore.api.valuerequest.listeners.StringListener;
|
||||
import com.bencodez.simpleapi.valuerequest.StringListener;
|
||||
import com.bencodez.simpleapi.valuerequest.ValueRequest;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
/**
|
||||
* Admin vote shop GUI handler.
|
||||
*/
|
||||
public class AdminVoteVoteShop extends GUIHandler {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteVoteShop.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param player the command sender
|
||||
*/
|
||||
public AdminVoteVoteShop(VotingPluginMain plugin, CommandSender player) {
|
||||
super(plugin, player);
|
||||
this.plugin = plugin;
|
||||
@@ -30,6 +39,11 @@ public class AdminVoteVoteShop extends GUIHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
}
|
||||
@@ -55,14 +69,15 @@ public class AdminVoteVoteShop extends GUIHandler {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
new ValueRequest().requestString(player, new StringListener() {
|
||||
new ValueRequest(plugin, plugin.getDialogService(), null).requestString(player, "", null, true,
|
||||
"Enter item name", new StringListener() {
|
||||
|
||||
@Override
|
||||
public void onInput(Player player, String value) {
|
||||
plugin.getShopFile().createShop(value);
|
||||
plugin.reload();
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onInput(Player player, String value) {
|
||||
plugin.getShopFile().createShop(value);
|
||||
plugin.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -81,4 +96,4 @@ public class AdminVoteVoteShop extends GUIHandler {
|
||||
open(GUIMethod.CHEST);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+15
@@ -22,17 +22,32 @@ import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.advancedcore.command.gui.RewardEditGUI;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
/**
|
||||
* Admin vote shop item GUI handler.
|
||||
*/
|
||||
public class AdminVoteVoteShopItem extends GUIHandler {
|
||||
|
||||
private String identifier;
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteVoteShopItem.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param player the command sender
|
||||
* @param identifier the item identifier
|
||||
*/
|
||||
public AdminVoteVoteShopItem(VotingPluginMain plugin, CommandSender player, String identifier) {
|
||||
super(plugin, player);
|
||||
this.plugin = plugin;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender sender) {
|
||||
return null;
|
||||
|
||||
+14
@@ -14,15 +14,29 @@ import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.commands.gui.admin.AdminVoteConfirmation;
|
||||
|
||||
/**
|
||||
* Admin vote shop item remove GUI handler.
|
||||
*/
|
||||
public class AdminVoteVoteShopItemRemove extends GUIHandler {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteVoteShopItemRemove.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param player the command sender
|
||||
*/
|
||||
public AdminVoteVoteShopItemRemove(VotingPluginMain plugin, CommandSender player) {
|
||||
super(plugin, player);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender sender) {
|
||||
return null;
|
||||
|
||||
+14
@@ -13,15 +13,29 @@ import com.bencodez.advancedcore.api.inventory.BInventoryButton;
|
||||
import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
/**
|
||||
* Admin vote shop items GUI handler.
|
||||
*/
|
||||
public class AdminVoteVoteShopItems extends GUIHandler {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Constructor for AdminVoteVoteShopItems.
|
||||
*
|
||||
* @param plugin the VotingPluginMain instance
|
||||
* @param player the command sender
|
||||
*/
|
||||
public AdminVoteVoteShopItems(VotingPluginMain plugin, CommandSender player) {
|
||||
super(plugin, player);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender sender) {
|
||||
return null;
|
||||
|
||||
+45
@@ -18,11 +18,21 @@ import com.bencodez.simpleapi.array.ArrayUtils;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
/**
|
||||
* GUI handler for vote best/streak display.
|
||||
*/
|
||||
public class VoteBest extends GUIHandler {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
private VotingPluginUser user;
|
||||
|
||||
/**
|
||||
* Constructs a new vote best GUI.
|
||||
*
|
||||
* @param plugin the plugin instance
|
||||
* @param player the command sender
|
||||
* @param user the voting plugin user
|
||||
*/
|
||||
public VoteBest(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) {
|
||||
super(plugin, player);
|
||||
this.plugin = plugin;
|
||||
@@ -47,6 +57,41 @@ public class VoteBest extends GUIHandler {
|
||||
return ArrayUtils.colorize(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
plugin.getDialogService().multiAction(player)
|
||||
.placeholder("player", user.getPlayerName())
|
||||
.placeholder("HighestDailyTotal", "" + user.getHighestDailyTotal())
|
||||
.placeholder("HighestWeeklyTotal", "" + user.getHighestWeeklyTotal())
|
||||
.placeholder("HighestMonthlyTotal", "" + user.getHighestMonthlyTotal())
|
||||
.title(plugin.getGui().getChestVoteBestName())
|
||||
.body(plugin.getConfigFile().getFormatCommandsVoteBestTitle())
|
||||
.columns(2)
|
||||
.button(plugin.getGui().getChestVoteBestDayBestItem().getName(),
|
||||
"&7Best daily total: &e%HighestDailyTotal%",
|
||||
payload -> {
|
||||
})
|
||||
.button(plugin.getGui().getChestVoteBestWeekBestItem().getName(),
|
||||
"&7Best weekly total: &e%HighestWeeklyTotal%",
|
||||
payload -> {
|
||||
})
|
||||
.button(plugin.getGui().getChestVoteBestMonthBestItem().getName(),
|
||||
"&7Best monthly total: &e%HighestMonthlyTotal%",
|
||||
payload -> {
|
||||
})
|
||||
.button(plugin.getGui().isChestVoteBestBackButton() ? "&eBack" : "",
|
||||
plugin.getGui().isChestVoteBestBackButton() ? "&7Return to previous menu" : "",
|
||||
payload -> {
|
||||
if (plugin.getGui().isChestVoteBestBackButton()) {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
if (clicked != null) {
|
||||
new VoteGUI(plugin, clicked, user).open();
|
||||
}
|
||||
}
|
||||
})
|
||||
.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
// TODO
|
||||
|
||||
@@ -19,11 +19,21 @@ import com.bencodez.simpleapi.messages.MessageAPI;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
|
||||
/**
|
||||
* GUI handler for vote interface.
|
||||
*/
|
||||
public class VoteGUI extends GUIHandler {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
private VotingPluginUser user;
|
||||
|
||||
/**
|
||||
* Constructs a new vote GUI.
|
||||
*
|
||||
* @param plugin the plugin instance
|
||||
* @param player the command sender
|
||||
* @param user the voting plugin user
|
||||
*/
|
||||
public VoteGUI(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) {
|
||||
super(plugin, player);
|
||||
this.plugin = plugin;
|
||||
@@ -35,6 +45,58 @@ public class VoteGUI extends GUIHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
if (this.user == null) {
|
||||
user = plugin.getVotingPluginUserManager().getVotingPluginUser(player);
|
||||
}
|
||||
|
||||
com.bencodez.simpleapi.dialog.MultiActionDialogBuilder dialog = plugin.getDialogService().multiAction(player)
|
||||
.placeholder("points", "" + user.getPoints()).placeholder("player", user.getPlayerName())
|
||||
.placeholder("top", plugin.getConfigFile().getVoteTopDefault())
|
||||
.placeholder("sitesavailable", "" + user.getSitesNotVotedOn())
|
||||
.title(plugin.getGui().getChestVoteGUIName()).body("&7Select an option").columns(2);
|
||||
|
||||
for (final String slot : plugin.getGui().getChestVoteGUISlots()) {
|
||||
ItemBuilder builder = getItemSlot(slot, player);
|
||||
|
||||
String buttonText = builder.getName();
|
||||
String tooltip = "";
|
||||
|
||||
if (builder.getLore() != null && !builder.getLore().isEmpty()) {
|
||||
tooltip = builder.getLore().get(0);
|
||||
}
|
||||
|
||||
dialog.button(buttonText, tooltip, payload -> {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
if (clicked == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String cmd = plugin.getGui().getChestVoteGUISlotCommand(slot);
|
||||
|
||||
if (cmd.equalsIgnoreCase("none")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!cmd.equals("")) {
|
||||
clicked.performCommand(cmd);
|
||||
} else {
|
||||
plugin.getCommandLoader().processSlotClick(clicked, user, slot);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
dialog.open();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the item for a specific GUI slot.
|
||||
*
|
||||
* @param slot the slot name
|
||||
* @param player the player
|
||||
* @return the item builder for the slot
|
||||
*/
|
||||
private ItemBuilder getItemSlot(String slot, Player player) {
|
||||
ItemBuilder builder = new ItemBuilder(plugin.getGui().getChestVoteGUISlotSection(slot));
|
||||
|
||||
@@ -207,6 +269,7 @@ public class VoteGUI extends GUIHandler {
|
||||
.setGiveOffline(false).send(clickEvent.getPlayer());
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+34
-6
@@ -11,17 +11,26 @@ import com.bencodez.advancedcore.api.command.CommandHandler;
|
||||
import com.bencodez.advancedcore.api.gui.GUIHandler;
|
||||
import com.bencodez.advancedcore.api.gui.GUIMethod;
|
||||
import com.bencodez.simpleapi.messages.MessageAPI;
|
||||
import com.bencodez.simpleapi.nms.NMSManager;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
/**
|
||||
* GUI handler for vote help display.
|
||||
*/
|
||||
public class VoteHelp extends GUIHandler {
|
||||
|
||||
private int page;
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Constructs a new vote help GUI.
|
||||
*
|
||||
* @param plugin the plugin instance
|
||||
* @param player the command sender
|
||||
* @param page the page number
|
||||
*/
|
||||
public VoteHelp(VotingPluginMain plugin, CommandSender player, int page) {
|
||||
super(plugin, player);
|
||||
this.plugin = plugin;
|
||||
@@ -33,6 +42,17 @@ public class VoteHelp extends GUIHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates help text with hover support.
|
||||
*
|
||||
* @param sender the command sender
|
||||
* @return list of text components for help
|
||||
*/
|
||||
public ArrayList<TextComponent> helpText(CommandSender sender) {
|
||||
ArrayList<TextComponent> msg = new ArrayList<>();
|
||||
HashMap<String, TextComponent> unsorted = new HashMap<>();
|
||||
@@ -64,6 +84,12 @@ public class VoteHelp extends GUIHandler {
|
||||
return msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates legacy help text without hover support.
|
||||
*
|
||||
* @param sender the command sender
|
||||
* @return list of text components for help
|
||||
*/
|
||||
public ArrayList<TextComponent> helpTextLegacy(CommandSender sender) {
|
||||
ArrayList<TextComponent> msg = new ArrayList<>();
|
||||
HashMap<String, TextComponent> unsorted = new HashMap<>();
|
||||
@@ -106,15 +132,17 @@ public class VoteHelp extends GUIHandler {
|
||||
open(GUIMethod.CHAT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates vote help text with pagination.
|
||||
*
|
||||
* @param sender the command sender
|
||||
* @return list of text components for help
|
||||
*/
|
||||
public ArrayList<TextComponent> voteHelpText(CommandSender sender) {
|
||||
int pagesize = plugin.getConfigFile().getFormatPageSize();
|
||||
ArrayList<TextComponent> msg = new ArrayList<>();
|
||||
ArrayList<TextComponent> text = new ArrayList<>();
|
||||
if (NMSManager.getInstance().isVersion("1.12")) {
|
||||
text = helpTextLegacy(sender);
|
||||
} else {
|
||||
text = helpText(sender);
|
||||
}
|
||||
text = helpText(sender);
|
||||
|
||||
int maxPage = text.size() / pagesize;
|
||||
if ((text.size() % pagesize) != 0) {
|
||||
|
||||
+55
@@ -1,6 +1,7 @@
|
||||
package com.bencodez.votingplugin.commands.gui.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -20,11 +21,21 @@ import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
import com.bencodez.votingplugin.votesites.VoteSite;
|
||||
|
||||
/**
|
||||
* GUI handler for displaying last vote information.
|
||||
*/
|
||||
public class VoteLast extends GUIHandler {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
private VotingPluginUser user;
|
||||
|
||||
/**
|
||||
* Constructs a new VoteLast GUI handler.
|
||||
*
|
||||
* @param plugin the main plugin instance
|
||||
* @param player the command sender
|
||||
* @param user the voting plugin user
|
||||
*/
|
||||
public VoteLast(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) {
|
||||
super(plugin, player);
|
||||
this.plugin = plugin;
|
||||
@@ -49,6 +60,50 @@ public class VoteLast extends GUIHandler {
|
||||
return ArrayUtils.colorize(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
com.bencodez.simpleapi.dialog.MultiActionDialogBuilder dialog = plugin.getDialogService().multiAction(player)
|
||||
.placeholder("player", user.getPlayerName()).title(plugin.getGui().getChestVoteLastName())
|
||||
.body(plugin.getConfigFile().getFormatCommandsVoteLastTitle()).columns(2);
|
||||
|
||||
for (VoteSite site : plugin.getVoteSiteManager().getVoteSitesEnabled()) {
|
||||
if (site.isHidden()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
dialog.placeholder("sitename", site.getDisplayName()).button(site.getDisplayName(),
|
||||
user.voteCommandLastLine(site), payload -> {
|
||||
|
||||
if (plugin.getGui().isChestVoteLastClickableLinks()) {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
|
||||
if (clicked != null) {
|
||||
VotingPluginUser clickedUser = plugin.getVotingPluginUserManager()
|
||||
.getVotingPluginUser(clicked);
|
||||
|
||||
HashMap<String, String> placeholders = new HashMap<String, String>();
|
||||
placeholders.put("voteurl", site.getVoteURL());
|
||||
placeholders.put("sitename", site.getDisplayName());
|
||||
placeholders.put("player", clicked.getName());
|
||||
|
||||
clickedUser.sendMessage(plugin.getGui().getChestVoteURLURLText(), placeholders);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (plugin.getGui().isChestVoteLastBackButton()) {
|
||||
dialog.button("&eBack", "&7Return to previous menu", payload -> {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
if (clicked != null) {
|
||||
new VoteGUI(plugin, clicked, user).open();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
dialog.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
// TODO
|
||||
|
||||
+51
@@ -24,11 +24,21 @@ import com.bencodez.votingplugin.votesites.VoteSite;
|
||||
|
||||
import xyz.upperlevel.spigot.book.BookUtil;
|
||||
|
||||
/**
|
||||
* GUI handler for displaying next vote information.
|
||||
*/
|
||||
public class VoteNext extends GUIHandler {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
private VotingPluginUser user;
|
||||
|
||||
/**
|
||||
* Constructs a new VoteNext GUI handler.
|
||||
*
|
||||
* @param plugin the main plugin instance
|
||||
* @param player the command sender
|
||||
* @param user the voting plugin user
|
||||
*/
|
||||
public VoteNext(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) {
|
||||
super(plugin, player);
|
||||
this.plugin = plugin;
|
||||
@@ -57,6 +67,47 @@ public class VoteNext extends GUIHandler {
|
||||
return msg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
com.bencodez.simpleapi.dialog.MultiActionDialogBuilder dialog = plugin.getDialogService().multiAction(player)
|
||||
.placeholder("player", user.getPlayerName()).title(plugin.getGui().getChestVoteNextName())
|
||||
.body(plugin.getConfigFile().getFormatCommandsVoteNextTitle()).columns(2);
|
||||
|
||||
for (VoteSite site : plugin.getVoteSiteManager().getVoteSitesEnabled()) {
|
||||
if (site.isHidden()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String siteNameDisplay = plugin.getGui().getChestVoteNextCustomSiteNamesDisplays(site.getKey());
|
||||
|
||||
if (siteNameDisplay.isEmpty()) {
|
||||
siteNameDisplay = site.getDisplayName();
|
||||
}
|
||||
|
||||
dialog.placeholder("sitename", site.getDisplayName()).placeholder("SiteName", site.getDisplayName())
|
||||
.placeholder("info", user.voteCommandNextInfo(site))
|
||||
.button(siteNameDisplay, user.voteCommandNextInfo(site), payload -> {
|
||||
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
|
||||
if (clicked != null) {
|
||||
clicked.sendMessage(user.voteCommandNextInfo(site));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (plugin.getGui().isChestVoteNextBackButton()) {
|
||||
dialog.button("&eBack", "&7Return to previous menu", payload -> {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
if (clicked != null) {
|
||||
new VoteGUI(plugin, clicked, user).open();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
dialog.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
BookWrapper book = new BookWrapper(plugin.getGui().getBookVoteURLBookGUITitle());
|
||||
|
||||
+197
-162
@@ -1,9 +1,7 @@
|
||||
package com.bencodez.votingplugin.commands.gui.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -13,19 +11,35 @@ import com.bencodez.advancedcore.api.inventory.BInventory;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventoryButton;
|
||||
import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.advancedcore.api.messages.PlaceholderUtils;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardBuilder;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardOptions;
|
||||
import com.bencodez.simpleapi.messages.MessageAPI;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.events.VoteShopPurchaseEvent;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
import com.bencodez.votingplugin.voteshop.VoteShopManager;
|
||||
import com.bencodez.votingplugin.voteshop.service.VoteShopPurchaseResult;
|
||||
import com.bencodez.votingplugin.voteshop.shop.VoteShopCategory;
|
||||
import com.bencodez.votingplugin.voteshop.shop.VoteShopCategoryButton;
|
||||
import com.bencodez.votingplugin.voteshop.shop.VoteShopDefinition;
|
||||
import com.bencodez.votingplugin.voteshop.shop.VoteShopEntry;
|
||||
import com.bencodez.votingplugin.voteshop.shop.VoteShopExtraItem;
|
||||
import com.bencodez.votingplugin.voteshop.shop.VoteShopItem;
|
||||
|
||||
/**
|
||||
* Main vote shop GUI.
|
||||
*/
|
||||
public class VoteShop extends GUIHandler {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
private VotingPluginUser user;
|
||||
|
||||
/**
|
||||
* Creates the GUI.
|
||||
*
|
||||
* @param plugin the plugin
|
||||
* @param player the sender
|
||||
* @param user the user
|
||||
*/
|
||||
public VoteShop(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) {
|
||||
super(plugin, player);
|
||||
this.plugin = plugin;
|
||||
@@ -33,7 +47,7 @@ public class VoteShop extends GUIHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender arg0) {
|
||||
public ArrayList<String> getChat(CommandSender sender) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -43,183 +57,204 @@ public class VoteShop extends GUIHandler {
|
||||
|
||||
@Override
|
||||
public void onChat(CommandSender sender) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
if (!plugin.getShopFile().isVoteShopEnabled()) {
|
||||
player.sendMessage(MessageAPI.colorize(plugin.getShopFile().getVoteShopDisabled()));
|
||||
VoteShopManager manager = plugin.getVoteShopManager();
|
||||
VoteShopDefinition definition = manager.getDefinition();
|
||||
|
||||
if (!definition.isEnabled()) {
|
||||
player.sendMessage(MessageAPI.colorize(definition.getDisabledMessage()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.user == null) {
|
||||
user = plugin.getVotingPluginUserManager().getVotingPluginUser(player);
|
||||
}
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(player);
|
||||
/*
|
||||
* if (!plugin.getConfigFile().isExtraVoteShopCheck()) { user.cacheAsync(); }
|
||||
*/
|
||||
BInventory inv = new BInventory(plugin.getShopFile().getVoteShopName());
|
||||
inv.addPlaceholder("points", "" + user.getPoints());
|
||||
inv.addPlaceholder("sitesavailable", "" + user.getSitesNotVotedOn());
|
||||
VotingPluginUser currentUser = getUser(player);
|
||||
BInventory inv = new BInventory(definition.getTitle());
|
||||
inv.addPlaceholder("points", String.valueOf(currentUser.getPoints()));
|
||||
inv.addPlaceholder("sitesavailable", String.valueOf(currentUser.getSitesNotVotedOn()));
|
||||
inv.dontClose();
|
||||
|
||||
for (final String identifier : plugin.getShopFile().getShopIdentifiers()) {
|
||||
|
||||
String perm = plugin.getShopFile().getVoteShopPermission(identifier);
|
||||
boolean hasPerm = false;
|
||||
if (perm.isEmpty()) {
|
||||
hasPerm = true;
|
||||
} else {
|
||||
String p = "";
|
||||
if (perm.startsWith("!")) {
|
||||
p = PlaceholderUtils.replacePlaceHolders(player, perm.substring(1));
|
||||
hasPerm = !player.hasPermission(p);
|
||||
} else {
|
||||
p = PlaceholderUtils.replacePlaceHolders(player, perm);
|
||||
hasPerm = player.hasPermission(p);
|
||||
}
|
||||
if (!hasPerm) {
|
||||
plugin.extraDebug("VoteShop: " + player.getName() + "/" + player.getUniqueId()
|
||||
+ " does not have permission `" + p + "` for " + identifier);
|
||||
}
|
||||
}
|
||||
|
||||
int limit = plugin.getShopFile().getShopIdentifierLimit(identifier);
|
||||
|
||||
boolean limitPass = true;
|
||||
if (limit > 0) {
|
||||
if (user.getVoteShopIdentifierLimit(identifier) >= limit) {
|
||||
limitPass = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!plugin.getShopFile().getVoteShopNotBuyable(identifier)) {
|
||||
if ((hasPerm || !plugin.getShopFile().getVoteShopHideOnNoPermission(identifier))
|
||||
&& (limitPass || !plugin.getShopFile().isVoteShopHideLimitedReached())) {
|
||||
ItemBuilder builder = new ItemBuilder(plugin.getShopFile().getShopIdentifierSection(identifier));
|
||||
|
||||
inv.addButton(new BInventoryButton(builder) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
Player player = event.getWhoClicked();
|
||||
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(player);
|
||||
if (plugin.getConfigFile().isExtraVoteShopCheck()) {
|
||||
user.cache();
|
||||
}
|
||||
|
||||
String identifier = (String) getData("identifier");
|
||||
int limit = (int) getData("Limit");
|
||||
int points = plugin.getShopFile().getShopIdentifierCost(identifier);
|
||||
if (identifier != null) {
|
||||
// if (plugin.getGui().getChestVoteShopCloseGUI(identifier)) {
|
||||
// event.closeInventory();
|
||||
// }
|
||||
|
||||
// limit fail-safe, should never be needed, except in rare cases
|
||||
boolean limitPass = true;
|
||||
if (limit > 0) {
|
||||
if (user.getVoteShopIdentifierLimit(identifier) >= limit) {
|
||||
limitPass = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (limitPass) {
|
||||
if (!plugin.getShopFile().isVoteShopRequireConfirmation(identifier)) {
|
||||
HashMap<String, String> placeholders = new HashMap<>();
|
||||
placeholders.put("identifier",
|
||||
plugin.getShopFile().getShopIdentifierIdentifierName(identifier));
|
||||
placeholders.put("points", "" + points);
|
||||
placeholders.put("limit", "" + limit);
|
||||
if (user.removePoints(points, true)) {
|
||||
plugin.getLogger().info("VoteShop: " + user.getPlayerName() + "/"
|
||||
+ user.getUUID() + " bought " + identifier + " for " + points);
|
||||
|
||||
plugin.getRewardHandler().giveReward(user, plugin.getShopFile().getData(),
|
||||
plugin.getShopFile().getShopIdentifierRewardsPath(identifier),
|
||||
new RewardOptions().setPlaceholders(placeholders));
|
||||
|
||||
user.sendMessage(PlaceholderUtils.replacePlaceHolder(
|
||||
plugin.getShopFile().getVoteShopPurchase(identifier),
|
||||
placeholders));
|
||||
|
||||
VoteShopPurchaseEvent purcahseEvent = new VoteShopPurchaseEvent(
|
||||
player.getUniqueId(), player.getName(), user, identifier, points);
|
||||
|
||||
Bukkit.getPluginManager().callEvent(purcahseEvent);
|
||||
|
||||
if (limit > 0) {
|
||||
user.setVoteShopIdentifierLimit(identifier,
|
||||
user.getVoteShopIdentifierLimit(identifier) + 1);
|
||||
}
|
||||
} else {
|
||||
user.sendMessage(PlaceholderUtils.replacePlaceHolder(
|
||||
plugin.getConfigFile().getFormatShopFailedMsg(), placeholders));
|
||||
}
|
||||
} else {
|
||||
plugin.getBukkitScheduler().runTask(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
new VoteShopConfirm(plugin, player, user, identifier)
|
||||
.open(GUIMethod.CHEST);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
} else {
|
||||
user.sendMessage(plugin.getShopFile().getVoteShopLimitReached());
|
||||
}
|
||||
plugin.getCommandLoader().processSlotClick(player, user, identifier);
|
||||
if (plugin.getShopFile().isVoteShopReopenGUIOnPurchase()) {
|
||||
plugin.getCommandLoader().processSlotClick(player, user, "shop");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}.addData("identifier", identifier).addData("Limit", limit));
|
||||
}
|
||||
} else {
|
||||
if (hasPerm) {
|
||||
ItemBuilder builder = new ItemBuilder(plugin.getShopFile().getShopIdentifierSection(identifier));
|
||||
inv.addButton(new BInventoryButton(builder) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
user.sendMessage(plugin.getConfigFile().getFormatShopNotPurchasable());
|
||||
}
|
||||
|
||||
}.addData("identifier", identifier).addData("Limit", limit));
|
||||
}
|
||||
for (VoteShopEntry entry : definition.getMainEntries().values()) {
|
||||
if (entry instanceof VoteShopItem) {
|
||||
addItemButton(inv, player, currentUser, (VoteShopItem) entry, null);
|
||||
} else if (entry instanceof VoteShopCategoryButton) {
|
||||
addCategoryButton(inv, player, currentUser, (VoteShopCategoryButton) entry);
|
||||
}
|
||||
}
|
||||
|
||||
for (final String str : plugin.getShopFile().getVoteShopExtraItems()) {
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getShopFile().getGUIVoteShopExtraItems(str))) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
plugin.getCommandLoader().processSlotClick(player, user, str);
|
||||
new RewardBuilder(plugin.getShopFile().getData(),
|
||||
"ExtraItems." + str + "." + clickEvent.getButton().getLastRewardsPath(player))
|
||||
.setGiveOffline(false).send(clickEvent.getPlayer());
|
||||
}
|
||||
});
|
||||
for (VoteShopExtraItem extraItem : definition.getExtraItems().values()) {
|
||||
addExtraItemButton(inv, player, currentUser, extraItem);
|
||||
}
|
||||
|
||||
if (plugin.getShopFile().isVoteShopBackButton()) {
|
||||
inv.addButton(plugin.getCommandLoader().getBackButton(user));
|
||||
if (definition.isBackButton()) {
|
||||
inv.addButton(plugin.getCommandLoader().getBackButton(currentUser));
|
||||
}
|
||||
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an item button.
|
||||
*
|
||||
* @param inv the inventory
|
||||
* @param player the player
|
||||
* @param currentUser the user
|
||||
* @param item the item
|
||||
* @param category the category, null for main shop
|
||||
*/
|
||||
protected void addItemButton(BInventory inv, final Player player, final VotingPluginUser currentUser,
|
||||
final VoteShopItem item, final VoteShopCategory category) {
|
||||
VoteShopPurchaseResult validation = plugin.getVoteShopManager().getPurchaseService().validatePurchase(player,
|
||||
currentUser, item);
|
||||
boolean hasPermission = plugin.getVoteShopManager().getPurchaseService().hasPermission(player,
|
||||
item.getPermission());
|
||||
|
||||
if ((!hasPermission && item.isHideOnNoPermission()) || (validation == VoteShopPurchaseResult.LIMIT_REACHED
|
||||
&& plugin.getVoteShopManager().getDefinition().isHideLimitedReached())) {
|
||||
return;
|
||||
}
|
||||
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(item.getDisplaySection())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
VotingPluginUser clickedUser = getUser(event.getPlayer());
|
||||
if (plugin.getConfigFile().isExtraVoteShopCheck()) {
|
||||
clickedUser.cache();
|
||||
}
|
||||
|
||||
if (item.isNotBuyable()) {
|
||||
clickedUser.sendMessage(plugin.getConfigFile().getFormatShopNotPurchasable());
|
||||
return;
|
||||
}
|
||||
|
||||
VoteShopPurchaseResult clickValidation = plugin.getVoteShopManager().getPurchaseService()
|
||||
.validatePurchase(event.getPlayer(), clickedUser, item);
|
||||
if (clickValidation != VoteShopPurchaseResult.SUCCESS) {
|
||||
plugin.getVoteShopManager().getPurchaseService().sendFailureMessage(event.getPlayer(), clickedUser,
|
||||
item, clickValidation);
|
||||
return;
|
||||
}
|
||||
|
||||
if (item.isRequireConfirmation()) {
|
||||
if (plugin.getShopFile().isShopConfirmPurchaseUseDialog()) {
|
||||
new VoteShopConfirm(plugin, event.getPlayer(), clickedUser, item, category)
|
||||
.open(GUIMethod.DIALOG);
|
||||
return;
|
||||
} else {
|
||||
new VoteShopConfirm(plugin, event.getPlayer(), clickedUser, item, category)
|
||||
.open(GUIMethod.CHEST);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
handlePurchase(event.getPlayer(), clickedUser, item, category);
|
||||
}
|
||||
}.addData("identifier", item.getIdentifier()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a category button.
|
||||
*
|
||||
* @param inv the inventory
|
||||
* @param player the player
|
||||
* @param currentUser the user
|
||||
* @param button the button
|
||||
*/
|
||||
protected void addCategoryButton(BInventory inv, final Player player, final VotingPluginUser currentUser,
|
||||
final VoteShopCategoryButton button) {
|
||||
boolean hasPermission = plugin.getVoteShopManager().getPurchaseService().hasPermission(player,
|
||||
button.getPermission());
|
||||
if (!hasPermission && button.isHideOnNoPermission()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final VoteShopCategory category = plugin.getVoteShopManager().getCategory(button.getCategoryId());
|
||||
if (category == null) {
|
||||
plugin.extraDebug(
|
||||
"VoteShop: missing category '" + button.getCategoryId() + "' for entry " + button.getIdentifier());
|
||||
return;
|
||||
}
|
||||
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(button.getDisplaySection())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
new VoteShopCategoryMenu(plugin, event.getPlayer(), currentUser, category).open(GUIMethod.CHEST);
|
||||
}
|
||||
}.addData("identifier", button.getIdentifier()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an extra item button.
|
||||
*
|
||||
* @param inv the inventory
|
||||
* @param player the player
|
||||
* @param currentUser the user
|
||||
* @param extraItem the extra item
|
||||
*/
|
||||
protected void addExtraItemButton(BInventory inv, final Player player, final VotingPluginUser currentUser,
|
||||
final VoteShopExtraItem extraItem) {
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(extraItem.getDisplaySection())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
plugin.getCommandLoader().processSlotClick(player, currentUser, extraItem.getIdentifier());
|
||||
new RewardBuilder(plugin.getShopFile().getData(),
|
||||
"ExtraItems." + extraItem.getIdentifier() + "."
|
||||
+ clickEvent.getButton().getLastRewardsPath(player))
|
||||
.setGiveOffline(false).send(clickEvent.getPlayer());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a completed purchase.
|
||||
*
|
||||
* @param player the player
|
||||
* @param currentUser the user
|
||||
* @param item the item
|
||||
* @param category the category or null
|
||||
*/
|
||||
protected void handlePurchase(Player player, VotingPluginUser currentUser, VoteShopItem item,
|
||||
VoteShopCategory category) {
|
||||
VoteShopPurchaseResult result = plugin.getVoteShopManager().purchase(player, currentUser, item);
|
||||
if (result != VoteShopPurchaseResult.SUCCESS) {
|
||||
plugin.getVoteShopManager().getPurchaseService().sendFailureMessage(player, currentUser, item, result);
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getCommandLoader().processSlotClick(player, currentUser, item.getIdentifier());
|
||||
if (plugin.getVoteShopManager().getDefinition().isReopenGuiOnPurchase()) {
|
||||
if (category != null) {
|
||||
new VoteShopCategoryMenu(plugin, player, currentUser, category).open(GUIMethod.CHEST);
|
||||
} else {
|
||||
plugin.getCommandLoader().processSlotClick(player, currentUser, "shop");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current user.
|
||||
*
|
||||
* @param player the player
|
||||
* @return the user
|
||||
*/
|
||||
protected VotingPluginUser getUser(Player player) {
|
||||
if (user == null) {
|
||||
user = plugin.getVotingPluginUserManager().getVotingPluginUser(player);
|
||||
}
|
||||
return plugin.getVotingPluginUserManager().getVotingPluginUser(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
open(GUIMethod.CHEST);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
package com.bencodez.votingplugin.commands.gui.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.bencodez.advancedcore.api.gui.GUIHandler;
|
||||
import com.bencodez.advancedcore.api.gui.GUIMethod;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventoryButton;
|
||||
import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.simpleapi.messages.MessageAPI;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
import com.bencodez.votingplugin.voteshop.shop.VoteShopCategory;
|
||||
import com.bencodez.votingplugin.voteshop.shop.VoteShopCategoryButton;
|
||||
import com.bencodez.votingplugin.voteshop.shop.VoteShopEntry;
|
||||
import com.bencodez.votingplugin.voteshop.shop.VoteShopItem;
|
||||
|
||||
/**
|
||||
* Vote shop category GUI.
|
||||
*/
|
||||
public class VoteShopCategoryMenu extends GUIHandler {
|
||||
|
||||
private VoteShopCategory category;
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private VotingPluginUser user;
|
||||
|
||||
/**
|
||||
* Creates the GUI.
|
||||
*
|
||||
* @param plugin the plugin
|
||||
* @param player the sender
|
||||
* @param user the user
|
||||
* @param category the category
|
||||
*/
|
||||
public VoteShopCategoryMenu(VotingPluginMain plugin, CommandSender player, VotingPluginUser user,
|
||||
VoteShopCategory category) {
|
||||
super(plugin, player);
|
||||
this.plugin = plugin;
|
||||
this.user = user;
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender sender) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBook(Player player) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChat(CommandSender sender) {
|
||||
}
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
if (!plugin.getVoteShopManager().getDefinition().isEnabled()) {
|
||||
player.sendMessage(MessageAPI.colorize(plugin.getVoteShopManager().getDefinition().getDisabledMessage()));
|
||||
return;
|
||||
}
|
||||
|
||||
VotingPluginUser currentUser = plugin.getVotingPluginUserManager().getVotingPluginUser(player);
|
||||
BInventory inv = new BInventory(category.getName());
|
||||
inv.addPlaceholder("points", String.valueOf(currentUser.getPoints()));
|
||||
inv.addPlaceholder("sitesavailable", String.valueOf(currentUser.getSitesNotVotedOn()));
|
||||
inv.dontClose();
|
||||
|
||||
for (VoteShopEntry entry : category.getEntries().values()) {
|
||||
if (entry instanceof VoteShopItem) {
|
||||
addItemButton(inv, player, currentUser, (VoteShopItem) entry);
|
||||
} else if (entry instanceof VoteShopCategoryButton) {
|
||||
addCategoryButton(inv, player, currentUser, (VoteShopCategoryButton) entry);
|
||||
}
|
||||
}
|
||||
|
||||
if (category.isBackButton()) {
|
||||
addBackButton(inv, player, currentUser, category.getId());
|
||||
}
|
||||
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
private void addBackButton(BInventory inv, Player player, VotingPluginUser user, String category) {
|
||||
|
||||
if (!plugin.getShopFile().isCategoryBackButtonEnabled(category)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ConfigurationSection section = plugin.getShopFile().getCategoryBackButtonItem(category);
|
||||
|
||||
if (section == null) {
|
||||
section = plugin.getShopFile().getDefaultBackButtonItem();
|
||||
}
|
||||
|
||||
ItemBuilder builder;
|
||||
|
||||
if (section != null) {
|
||||
builder = new ItemBuilder(section);
|
||||
} else {
|
||||
builder = new ItemBuilder(Material.ARROW);
|
||||
builder.setName("&cBack");
|
||||
}
|
||||
|
||||
inv.addButton(new BInventoryButton(builder) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
new VoteShop(plugin, player, user).open();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an item button.
|
||||
*
|
||||
* @param inv the inventory
|
||||
* @param player the player
|
||||
* @param currentUser the user
|
||||
* @param item the item
|
||||
*/
|
||||
protected void addItemButton(BInventory inv, final Player player, final VotingPluginUser currentUser,
|
||||
final VoteShopItem item) {
|
||||
new VoteShop(plugin, player, currentUser).addItemButton(inv, player, currentUser, item, category);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a category button.
|
||||
*
|
||||
* @param inv the inventory
|
||||
* @param player the player
|
||||
* @param currentUser the user
|
||||
* @param button the button
|
||||
*/
|
||||
protected void addCategoryButton(BInventory inv, final Player player, final VotingPluginUser currentUser,
|
||||
final VoteShopCategoryButton button) {
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(button.getDisplaySection())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
VoteShopCategory target = plugin.getVoteShopManager().getCategory(button.getCategoryId());
|
||||
if (target != null) {
|
||||
new VoteShopCategoryMenu(plugin, event.getPlayer(), currentUser, target).open(GUIMethod.CHEST);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
open(GUIMethod.CHEST);
|
||||
}
|
||||
}
|
||||
+92
-48
@@ -1,9 +1,7 @@
|
||||
package com.bencodez.votingplugin.commands.gui.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -13,28 +11,46 @@ import com.bencodez.advancedcore.api.inventory.BInventory;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent;
|
||||
import com.bencodez.advancedcore.api.inventory.BInventoryButton;
|
||||
import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.advancedcore.api.messages.PlaceholderUtils;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardOptions;
|
||||
import com.bencodez.simpleapi.player.PlayerUtils;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.events.VoteShopPurchaseEvent;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
import com.bencodez.votingplugin.voteshop.service.VoteShopPurchaseResult;
|
||||
import com.bencodez.votingplugin.voteshop.shop.VoteShopCategory;
|
||||
import com.bencodez.votingplugin.voteshop.shop.VoteShopItem;
|
||||
|
||||
/**
|
||||
* Confirmation GUI for vote shop purchases.
|
||||
*/
|
||||
public class VoteShopConfirm extends GUIHandler {
|
||||
|
||||
private String identifier;
|
||||
private VoteShopCategory category;
|
||||
|
||||
private VoteShopItem item;
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
private VotingPluginUser user;
|
||||
|
||||
public VoteShopConfirm(VotingPluginMain plugin, CommandSender player, VotingPluginUser user, String identifier) {
|
||||
/**
|
||||
* Creates the GUI.
|
||||
*
|
||||
* @param plugin the plugin
|
||||
* @param player the sender
|
||||
* @param user the user
|
||||
* @param item the item
|
||||
* @param category the category or null
|
||||
*/
|
||||
public VoteShopConfirm(VotingPluginMain plugin, CommandSender player, VotingPluginUser user, VoteShopItem item,
|
||||
VoteShopCategory category) {
|
||||
super(plugin, player);
|
||||
this.plugin = plugin;
|
||||
this.user = user;
|
||||
this.identifier = identifier;
|
||||
this.item = item;
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender arg0) {
|
||||
public ArrayList<String> getChat(CommandSender sender) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -47,8 +63,8 @@ public class VoteShopConfirm extends GUIHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChest(Player player) {
|
||||
PlayerUtils.setPlayerMeta(plugin, player, "ident", identifier);
|
||||
public void onChest(final Player player) {
|
||||
PlayerUtils.setPlayerMeta(plugin, player, "ident", item.getIdentifier());
|
||||
BInventory inv = new BInventory(plugin.getShopFile().getShopConfirmPurchaseTitle());
|
||||
inv.dontClose();
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getShopFile().getShopConfirmPurchaseYesItem())) {
|
||||
@@ -56,59 +72,87 @@ public class VoteShopConfirm extends GUIHandler {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
user.cache();
|
||||
int points = plugin.getShopFile().getShopIdentifierCost(identifier);
|
||||
int limit = plugin.getShopFile().getShopIdentifierLimit(identifier);
|
||||
HashMap<String, String> placeholders = new HashMap<>();
|
||||
placeholders.put("identifier", identifier);
|
||||
placeholders.put("points", "" + points);
|
||||
placeholders.put("limit", "" + limit);
|
||||
if (user.removePoints(points, true)) {
|
||||
plugin.getLogger().info("VoteShop: " + user.getPlayerName() + "/" + user.getUUID() + " bought "
|
||||
+ identifier + " for " + points);
|
||||
|
||||
plugin.getRewardHandler().giveReward(user, plugin.getShopFile().getData(),
|
||||
plugin.getShopFile().getShopIdentifierRewardsPath(identifier),
|
||||
new RewardOptions().setPlaceholders(placeholders));
|
||||
|
||||
user.sendMessage(PlaceholderUtils
|
||||
.replacePlaceHolder(plugin.getShopFile().getVoteShopPurchase(identifier), placeholders));
|
||||
|
||||
VoteShopPurchaseEvent purcahseEvent = new VoteShopPurchaseEvent(player.getUniqueId(),
|
||||
player.getName(), user, identifier, points);
|
||||
|
||||
Bukkit.getPluginManager().callEvent(purcahseEvent);
|
||||
if (limit > 0) {
|
||||
user.setVoteShopIdentifierLimit(identifier, user.getVoteShopIdentifierLimit(identifier) + 1);
|
||||
}
|
||||
} else {
|
||||
user.sendMessage(PlaceholderUtils
|
||||
.replacePlaceHolder(plugin.getConfigFile().getFormatShopFailedMsg(), placeholders));
|
||||
}
|
||||
if (plugin.getShopFile().getVoteShopCloseGUI(identifier)) {
|
||||
event.getButton().getInv().closeInv(player, null);
|
||||
} else {
|
||||
new VoteShop(plugin, event.getPlayer(), user).open();
|
||||
VoteShopPurchaseResult result = plugin.getVoteShopManager().purchase(player, user, item);
|
||||
if (result != VoteShopPurchaseResult.SUCCESS) {
|
||||
plugin.getVoteShopManager().getPurchaseService().sendFailureMessage(player, user, item, result);
|
||||
returnToPrevious(event.getPlayer());
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getCommandLoader().processSlotClick(player, user, item.getIdentifier());
|
||||
if (item.isCloseGUI()) {
|
||||
event.closeInventory();
|
||||
} else {
|
||||
returnToPrevious(event.getPlayer());
|
||||
}
|
||||
}
|
||||
});
|
||||
inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getShopFile().getShopConfirmPurchaseNoItem())) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
if (plugin.getShopFile().getVoteShopCloseGUI(identifier)) {
|
||||
event.getButton().getInv().closeInv(player, null);
|
||||
if (item.isCloseGUI()) {
|
||||
event.closeInventory();
|
||||
} else {
|
||||
new VoteShop(plugin, event.getPlayer(), user).open();
|
||||
returnToPrevious(event.getPlayer());
|
||||
}
|
||||
}
|
||||
});
|
||||
inv.openInventory(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
PlayerUtils.setPlayerMeta(plugin, player, "ident", item.getIdentifier());
|
||||
|
||||
plugin.getDialogService().confirmation(player).placeholder("player", user.getPlayerName())
|
||||
.placeholder("identifier", item.getIdentifier())
|
||||
.title(plugin.getShopFile().getShopConfirmPurchaseTitle())
|
||||
.body("&7Confirm purchase of &e%identifier%&7?")
|
||||
.yesText(new ItemBuilder(plugin.getShopFile().getShopConfirmPurchaseYesItem()).getName())
|
||||
.noText(new ItemBuilder(plugin.getShopFile().getShopConfirmPurchaseNoItem()).getName())
|
||||
.onYes(payload -> {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
if (clicked == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
user.cache();
|
||||
VoteShopPurchaseResult result = plugin.getVoteShopManager().purchase(clicked, user, item);
|
||||
if (result != VoteShopPurchaseResult.SUCCESS) {
|
||||
plugin.getVoteShopManager().getPurchaseService().sendFailureMessage(clicked, user, item,
|
||||
result);
|
||||
returnToPrevious(clicked);
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getCommandLoader().processSlotClick(clicked, user, item.getIdentifier());
|
||||
if (!item.isCloseGUI()) {
|
||||
returnToPrevious(clicked);
|
||||
}
|
||||
}).onNo(payload -> {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
if (clicked != null) {
|
||||
returnToPrevious(clicked);
|
||||
}
|
||||
}).open();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns to the previous GUI.
|
||||
*
|
||||
* @param player the player
|
||||
*/
|
||||
protected void returnToPrevious(Player player) {
|
||||
if (category != null) {
|
||||
new VoteShopCategoryMenu(plugin, player, user, category).open(GUIMethod.CHEST);
|
||||
} else {
|
||||
new VoteShop(plugin, player, user).open(GUIMethod.CHEST);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
open(GUIMethod.CHEST);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+51
@@ -29,6 +29,57 @@ public class VoteStreak extends GUIHandler {
|
||||
this.plugin = plugin;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
com.bencodez.simpleapi.dialog.MultiActionDialogBuilder dialog = plugin.getDialogService().multiAction(player)
|
||||
.placeholder("player", user.getPlayerName())
|
||||
.placeholder("DailyStreak", "" + user.getDayVoteStreak())
|
||||
.placeholder("WeeklyStreak", "" + user.getWeekVoteStreak())
|
||||
.placeholder("MonthlyStreak", "" + user.getMonthVoteStreak())
|
||||
.placeholder("BestDailyStreak", "" + user.getBestDayVoteStreak())
|
||||
.placeholder("BestWeeklyStreak", "" + user.getBestWeekVoteStreak())
|
||||
.placeholder("BestMonthlyStreak", "" + user.getBestMonthVoteStreak())
|
||||
.title(plugin.getGui().getChestVoteStreakName())
|
||||
.body(plugin.getConfigFile().getFormatCommandsVoteStreakTitle())
|
||||
.columns(2);
|
||||
|
||||
dialog.button(plugin.getGui().getChestVoteStreakCurrentDayStreakItem().getName(),
|
||||
"&7Current daily streak: &e%DailyStreak%",
|
||||
payload -> {
|
||||
});
|
||||
dialog.button(plugin.getGui().getChestVoteStreakCurrentWeekStreakItem().getName(),
|
||||
"&7Current weekly streak: &e%WeeklyStreak%",
|
||||
payload -> {
|
||||
});
|
||||
dialog.button(plugin.getGui().getChestVoteStreakCurrentMonthStreakItem().getName(),
|
||||
"&7Current monthly streak: &e%MonthlyStreak%",
|
||||
payload -> {
|
||||
});
|
||||
dialog.button(plugin.getGui().getChestVoteStreakHighestDayStreakItem().getName(),
|
||||
"&7Best daily streak: &e%BestDailyStreak%",
|
||||
payload -> {
|
||||
});
|
||||
dialog.button(plugin.getGui().getChestVoteStreakHighestWeekStreakItem().getName(),
|
||||
"&7Best weekly streak: &e%BestWeeklyStreak%",
|
||||
payload -> {
|
||||
});
|
||||
dialog.button(plugin.getGui().getChestVoteStreakHighestMonthStreakItem().getName(),
|
||||
"&7Best monthly streak: &e%BestMonthlyStreak%",
|
||||
payload -> {
|
||||
});
|
||||
|
||||
if (plugin.getGui().isChestVoteStreakBackButton()) {
|
||||
dialog.button("&eBack", "&7Return to previous menu", payload -> {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
if (clicked != null) {
|
||||
new VoteGUI(plugin, clicked, user).open();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
dialog.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender sender) {
|
||||
|
||||
+64
-15
@@ -19,7 +19,6 @@ import com.bencodez.advancedcore.api.item.ItemBuilder;
|
||||
import com.bencodez.advancedcore.api.messages.PlaceholderUtils;
|
||||
import com.bencodez.advancedcore.api.rewards.RewardBuilder;
|
||||
import com.bencodez.simpleapi.array.ArrayUtils;
|
||||
import com.bencodez.simpleapi.nms.NMSManager;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.topvoter.TopVoterPlayer;
|
||||
import com.bencodez.votingplugin.user.VotingPluginUser;
|
||||
@@ -38,6 +37,49 @@ public class VoteToday extends GUIHandler {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
com.bencodez.simpleapi.dialog.MultiActionDialogBuilder dialog = plugin.getDialogService().multiAction(player)
|
||||
.placeholder("player", user.getPlayerName()).placeholder("page", "" + page)
|
||||
.title(plugin.getGui().getChestVoteTodayName())
|
||||
.body(String.join("\n", plugin.getConfigFile().getFormatCommandsVoteTodayTitle())).columns(2);
|
||||
|
||||
for (TopVoterPlayer topPlayer : plugin.getVoteToday().keySet()) {
|
||||
for (VoteSite voteSite : plugin.getVoteToday().get(topPlayer).keySet()) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(plugin.getConfigFile().getFormatTimeFormat());
|
||||
String timeString = plugin.getVoteToday().get(topPlayer).get(voteSite).format(formatter);
|
||||
|
||||
final UUID uuid = topPlayer.getUuid();
|
||||
|
||||
dialog.placeholder("player", topPlayer.getPlayerName()).placeholder("votesite", voteSite.getKey())
|
||||
.placeholder("sitename", voteSite.getDisplayName())
|
||||
.placeholder("SiteName", voteSite.getDisplayName())
|
||||
.placeholder("VoteSite", voteSite.getDisplayName()).placeholder("time", timeString)
|
||||
.placeholder("Time", timeString).button("&e" + topPlayer.getPlayerName(),
|
||||
plugin.getConfigFile().getFormatCommandsVoteTodayLine(), payload -> {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
if (clicked != null) {
|
||||
VotingPluginUser clickedUser = plugin.getVotingPluginUserManager()
|
||||
.getVotingPluginUser(uuid);
|
||||
new VoteGUI(plugin, clicked, clickedUser).open(
|
||||
GUIMethod.valueOf(plugin.getGui().getGuiMethodGUI().toUpperCase()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (plugin.getGui().isChestVoteTodayBackButton()) {
|
||||
dialog.button("&eBack", "&7Return to previous menu", payload -> {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
if (clicked != null) {
|
||||
new VoteGUI(plugin, clicked, user).open();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
dialog.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender arg0) {
|
||||
int pagesize = plugin.getConfigFile().getFormatPageSize();
|
||||
@@ -85,28 +127,38 @@ public class VoteToday extends GUIHandler {
|
||||
if (!plugin.getConfigFile().isAlwaysCloseInventory()) {
|
||||
inv.dontClose();
|
||||
}
|
||||
for (TopVoterPlayer user : plugin.getVoteToday().keySet()) {
|
||||
|
||||
for (TopVoterPlayer user : plugin.getVoteToday().keySet()) {
|
||||
for (VoteSite voteSite : plugin.getVoteToday().get(user).keySet()) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(plugin.getConfigFile().getFormatTimeFormat());
|
||||
String timeString = plugin.getVoteToday().get(user).get(voteSite).format(formatter);
|
||||
String msg = plugin.getGui().getChestVoteTodayLine();
|
||||
|
||||
HashMap<String, String> placeholders = new HashMap<>();
|
||||
placeholders.put("player", user.getPlayerName());
|
||||
placeholders.put("votesite", voteSite.getKey());
|
||||
placeholders.put("sitename", voteSite.getDisplayName());
|
||||
placeholders.put("SiteName", voteSite.getDisplayName());
|
||||
placeholders.put("VoteSite", voteSite.getDisplayName());
|
||||
placeholders.put("time", timeString);
|
||||
placeholders.put("Time", timeString);
|
||||
msg = PlaceholderUtils.replacePlaceHolder(msg, placeholders);
|
||||
ItemBuilder item = null;
|
||||
if (plugin.getGui().isChestVoteTodayUseSkull() && !NMSManager.getInstance().isVersion("1.12")) {
|
||||
|
||||
ItemBuilder item;
|
||||
if (plugin.getGui().isChestVoteTodayUseSkull()) {
|
||||
item = new ItemBuilder(user.getPlayerHead());
|
||||
} else {
|
||||
item = new ItemBuilder(plugin.getGui().getChestVoteTodayPlayerItem());
|
||||
}
|
||||
item.setName(PlaceholderUtils.replacePlaceHolder(plugin.getGui().getChestVoteTodayIconTitle(), "player",
|
||||
user.getPlayerName()));
|
||||
item.setLore(msg);
|
||||
|
||||
String title = PlaceholderUtils.replacePlaceHolder(plugin.getGui().getChestVoteTodayIconTitle(),
|
||||
placeholders);
|
||||
String lore = PlaceholderUtils.replacePlaceHolder(plugin.getGui().getChestVoteTodayLine(),
|
||||
placeholders);
|
||||
|
||||
item.setName(title);
|
||||
item.setLore(lore);
|
||||
|
||||
final UUID uuid = user.getUuid();
|
||||
inv.addButton(inv.getNextSlot(), new BInventoryButton(item) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(uuid);
|
||||
@@ -121,16 +173,13 @@ public class VoteToday extends GUIHandler {
|
||||
for (final String str : plugin.getGui().getChestGUIExtraItems(guiPath)) {
|
||||
inv.addButton(
|
||||
new BInventoryButton(new ItemBuilder(plugin.getGui().getChestGUIExtraItemsItem(guiPath, str))) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent clickEvent) {
|
||||
new RewardBuilder(plugin.getGui().getData(),
|
||||
"CHEST." + guiPath + ".ExtraItems." + str + "."
|
||||
+ clickEvent.getButton().getLastRewardsPath(player))
|
||||
.setGiveOffline(false).send(clickEvent.getPlayer());
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -155,7 +204,7 @@ public class VoteToday extends GUIHandler {
|
||||
HashMap<String, String> placeholders = new HashMap<>();
|
||||
placeholders.put("player", user.getPlayerName());
|
||||
placeholders.put("votesite", voteSite.getKey());
|
||||
placeholders.put("sitename", voteSite.getDisplayName());
|
||||
placeholders.put("sitename", voteSite.getDisplayName());
|
||||
placeholders.put("time", timeString);
|
||||
msg.add(PlaceholderUtils.replacePlaceHolder(plugin.getConfigFile().getFormatCommandsVoteTodayLine(),
|
||||
placeholders));
|
||||
@@ -185,7 +234,7 @@ public class VoteToday extends GUIHandler {
|
||||
HashMap<String, String> placeholders = new HashMap<>();
|
||||
placeholders.put("player", user.getPlayerName());
|
||||
placeholders.put("votesite", mostRecentSite.getKey());
|
||||
placeholders.put("sitename", mostRecentSite.getDisplayName());
|
||||
placeholders.put("sitename", mostRecentSite.getDisplayName());
|
||||
placeholders.put("time", timeString);
|
||||
msg.add(PlaceholderUtils.replacePlaceHolder(plugin.getConfigFile().getFormatCommandsVoteTodayLine(),
|
||||
placeholders));
|
||||
|
||||
+68
@@ -41,6 +41,74 @@ public class VoteTopVoter extends GUIHandler {
|
||||
this.top = top;
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
if (top == null) {
|
||||
top = TopVoter.getDefault();
|
||||
}
|
||||
|
||||
String topVoter = top.getName();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
LinkedHashMap<TopVoterPlayer, Integer> topVotes = (LinkedHashMap<TopVoterPlayer, Integer>) plugin.getTopVoter(top)
|
||||
.clone();
|
||||
|
||||
com.bencodez.simpleapi.dialog.MultiActionDialogBuilder dialog = plugin.getDialogService().multiAction(player)
|
||||
.placeholder("player", user.getPlayerName())
|
||||
.placeholder("topvoter", topVoter)
|
||||
.title(plugin.getGui().getChestVoteTopName())
|
||||
.body("&7Viewing &e%topvoter% &7top voters")
|
||||
.columns(2);
|
||||
|
||||
int pos = 1;
|
||||
for (Entry<TopVoterPlayer, Integer> entry : topVotes.entrySet()) {
|
||||
final TopVoterPlayer topPlayer = entry.getKey();
|
||||
final int votes = entry.getValue();
|
||||
final int position = pos;
|
||||
|
||||
dialog.placeholder("position", "" + position)
|
||||
.placeholder("player", topPlayer.getPlayerName())
|
||||
.placeholder("votes", "" + votes)
|
||||
.button(plugin.getGui().getChestVoteTopItemName(),
|
||||
plugin.getGui().getChestVoteTopItemLore(),
|
||||
payload -> {
|
||||
if (plugin.getGui().isChestVoteTopOpenMainGUIOnClick()) {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
if (clicked != null) {
|
||||
new VoteGUI(plugin, clicked, topPlayer.getUser()).open(
|
||||
GUIMethod.valueOf(plugin.getGui().getGuiMethodGUI().toUpperCase()));
|
||||
}
|
||||
}
|
||||
});
|
||||
pos++;
|
||||
}
|
||||
|
||||
dialog.button("&eNext", "&7View next top voter board", payload -> {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
if (clicked != null) {
|
||||
new VoteTopVoter(plugin, clicked, user, top.next(), 0).open(GUIMethod.DIALOG);
|
||||
}
|
||||
});
|
||||
|
||||
dialog.button("&ePrevious", "&7View previous top voter board", payload -> {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
if (clicked != null) {
|
||||
new VoteTopVoter(plugin, clicked, user, top.prev(), 0).open(GUIMethod.DIALOG);
|
||||
}
|
||||
});
|
||||
|
||||
if (plugin.getGui().isChestVoteTopBackButton()) {
|
||||
dialog.button("&eBack", "&7Return to previous menu", payload -> {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
if (clicked != null) {
|
||||
new VoteGUI(plugin, clicked, user).open();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
dialog.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender sender) {
|
||||
|
||||
+44
@@ -28,6 +28,50 @@ public class VoteTopVoterLastMonth extends GUIHandler {
|
||||
this.plugin = plugin;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
Set<Entry<TopVoterPlayer, Integer>> users = plugin.getLastMonthTopVoter().entrySet();
|
||||
|
||||
com.bencodez.simpleapi.dialog.MultiActionDialogBuilder dialog = plugin.getDialogService().multiAction(player)
|
||||
.placeholder("player", user.getPlayerName())
|
||||
.placeholder("topvoter", "Last Month")
|
||||
.title(plugin.getGui().getChestVoteTopName())
|
||||
.body("&7Viewing &eLast Month &7top voters")
|
||||
.columns(2);
|
||||
|
||||
int pos = 1;
|
||||
for (Entry<TopVoterPlayer, Integer> entry : users) {
|
||||
final TopVoterPlayer topPlayer = entry.getKey();
|
||||
final int votes = entry.getValue();
|
||||
final int position = pos;
|
||||
|
||||
dialog.placeholder("position", "" + position)
|
||||
.placeholder("player", topPlayer.getPlayerName())
|
||||
.placeholder("votes", "" + votes)
|
||||
.button(plugin.getGui().getChestVoteTopItemName(),
|
||||
plugin.getGui().getChestVoteTopItemLore(),
|
||||
payload -> {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
if (clicked != null) {
|
||||
new VoteGUI(plugin, clicked, topPlayer.getUser())
|
||||
.open(GUIMethod.valueOf(plugin.getGui().getGuiMethodGUI().toUpperCase()));
|
||||
}
|
||||
});
|
||||
pos++;
|
||||
}
|
||||
|
||||
if (plugin.getGui().isChestVoteTopBackButton()) {
|
||||
dialog.button("&eBack", "&7Return to previous menu", payload -> {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
if (clicked != null) {
|
||||
new VoteGUI(plugin, clicked, user).open();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
dialog.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender arg0) {
|
||||
|
||||
+78
@@ -37,6 +37,84 @@ public class VoteTopVoterPreviousMonths extends GUIHandler {
|
||||
this.user = user;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
Set<YearMonth> months = plugin.getPreviousMonthsTopVoters().keySet();
|
||||
List<YearMonth> yearMonthList = months.stream().sorted(Collections.reverseOrder()).collect(Collectors.toList());
|
||||
|
||||
if (index < 0 || yearMonthList.isEmpty()) {
|
||||
player.sendMessage(ChatColor.RED + "Can't open previous months, no data");
|
||||
return;
|
||||
}
|
||||
|
||||
if (yearMonthList.size() <= index) {
|
||||
player.sendMessage(ChatColor.RED + "Can't open previous months, no data for requested index");
|
||||
return;
|
||||
}
|
||||
|
||||
YearMonth yearMonth = yearMonthList.get(index);
|
||||
|
||||
if (!plugin.getPreviousMonthsTopVoters().containsKey(yearMonth)) {
|
||||
player.sendMessage(ChatColor.RED + "Can't open previous months, no data");
|
||||
return;
|
||||
}
|
||||
|
||||
Set<Entry<TopVoterPlayer, Integer>> users = plugin.getPreviousMonthsTopVoters().get(yearMonth).entrySet();
|
||||
|
||||
com.bencodez.simpleapi.dialog.MultiActionDialogBuilder dialog = plugin.getDialogService().multiAction(player)
|
||||
.placeholder("player", user.getPlayerName())
|
||||
.placeholder("topvoter", yearMonth.toString())
|
||||
.title(plugin.getGui().getChestVoteTopName())
|
||||
.body("&7Viewing &e%topvoter% &7top voters")
|
||||
.columns(2);
|
||||
|
||||
int pos = 1;
|
||||
for (Entry<TopVoterPlayer, Integer> entry : users) {
|
||||
final TopVoterPlayer topPlayer = entry.getKey();
|
||||
final int votes = entry.getValue();
|
||||
final int position = pos;
|
||||
|
||||
dialog.placeholder("position", "" + position)
|
||||
.placeholder("player", topPlayer.getPlayerName())
|
||||
.placeholder("votes", "" + votes)
|
||||
.button(plugin.getGui().getChestVoteTopItemName(),
|
||||
plugin.getGui().getChestVoteTopItemLore(),
|
||||
payload -> {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
if (clicked != null) {
|
||||
new VoteGUI(plugin, clicked, topPlayer.getUser())
|
||||
.open(GUIMethod.valueOf(plugin.getGui().getGuiMethodGUI().toUpperCase()));
|
||||
}
|
||||
});
|
||||
pos++;
|
||||
}
|
||||
|
||||
dialog.button("&eNext Month", "&7View older month", payload -> {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
if (clicked != null) {
|
||||
new VoteTopVoterPreviousMonths(plugin, clicked, user, index + 1).open(GUIMethod.DIALOG);
|
||||
}
|
||||
});
|
||||
|
||||
dialog.button("&ePrevious Month", "&7View newer month", payload -> {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
if (clicked != null) {
|
||||
new VoteTopVoterPreviousMonths(plugin, clicked, user, index - 1).open(GUIMethod.DIALOG);
|
||||
}
|
||||
});
|
||||
|
||||
if (plugin.getGui().isChestVoteTopBackButton()) {
|
||||
dialog.button("&eBack", "&7Return to previous menu", payload -> {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
if (clicked != null) {
|
||||
new VoteGUI(plugin, clicked, user).open();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
dialog.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender arg0) {
|
||||
|
||||
+36
@@ -30,6 +30,42 @@ public class VoteTotal extends GUIHandler {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
com.bencodez.simpleapi.dialog.MultiActionDialogBuilder dialog = plugin.getDialogService().multiAction(player)
|
||||
.placeholder("player", user.getPlayerName())
|
||||
.placeholder("DailyTotal", "" + user.getTotal(TopVoter.Daily))
|
||||
.placeholder("WeeklyTotal", "" + user.getTotal(TopVoter.Weekly))
|
||||
.placeholder("MonthlyTotal", "" + user.getTotal(TopVoter.Monthly))
|
||||
.placeholder("AllTimeTotal", "" + user.getTotal(TopVoter.AllTime))
|
||||
.title(plugin.getGui().getChestVoteTotalName()).body("&7Vote totals for %player%").columns(2);
|
||||
|
||||
for (final TopVoter top : TopVoter.values()) {
|
||||
|
||||
dialog.placeholder("topvoter", top.getName()).placeholder("Total", "" + user.getTotal(top))
|
||||
.button("%topvoter%", "&7Total: &e%Total%", payload -> {
|
||||
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
|
||||
if (clicked != null) {
|
||||
clicked.sendMessage("&e" + top.getName() + ": &a" + user.getTotal(top));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (plugin.getGui().isChestVoteTotalBackButton()) {
|
||||
dialog.button("&eBack", "&7Return to previous menu", payload -> {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
if (clicked != null) {
|
||||
new VoteGUI(plugin, clicked, user).open();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
dialog.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getChat(CommandSender arg0) {
|
||||
ArrayList<String> msg = new ArrayList<>();
|
||||
|
||||
@@ -96,6 +96,93 @@ public class VoteURL extends GUIHandler {
|
||||
return ArrayUtils.colorize(sites);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
VotingPluginUser currentUser = this.user;
|
||||
|
||||
if (currentUser == null) {
|
||||
currentUser = plugin.getVotingPluginUserManager().getVotingPluginUser(player);
|
||||
}
|
||||
|
||||
String body = "&7Select a vote site";
|
||||
|
||||
if (plugin.getConfigFile().getFormatCommandsVoteText() != null
|
||||
&& !plugin.getConfigFile().getFormatCommandsVoteText().isEmpty()) {
|
||||
body = String.join("\n", plugin.getConfigFile().getFormatCommandsVoteText());
|
||||
}
|
||||
|
||||
final VotingPluginUser finalUser = currentUser;
|
||||
|
||||
com.bencodez.simpleapi.dialog.MultiActionDialogBuilder dialog = plugin.getDialogService().multiAction(player)
|
||||
.placeholder("player", finalUser.getPlayerName())
|
||||
.placeholder("DailyTotal", "" + finalUser.getTotal(TopVoter.Daily))
|
||||
.placeholder("WeekTotal", "" + finalUser.getTotal(TopVoter.Weekly))
|
||||
.placeholder("MonthTotal", "" + finalUser.getTotal(TopVoter.Monthly))
|
||||
.placeholder("Total", "" + finalUser.getTotal(TopVoter.AllTime))
|
||||
.title(plugin.getGui().getChestVoteURLName()).body(body).columns(2);
|
||||
|
||||
if (plugin.getGui().isChestVoteURLViewAllUrlsButtonEnabled()) {
|
||||
boolean canViewAll;
|
||||
if (plugin.getGui().isChestVoteURLAllUrlsButtonrequireAllSitesVoted()) {
|
||||
canViewAll = finalUser.canVoteAny();
|
||||
} else {
|
||||
canViewAll = finalUser.canVoteAll();
|
||||
}
|
||||
|
||||
String allColor = canViewAll ? "&a" : "&c";
|
||||
|
||||
dialog.button(allColor + "All Voting Sites", "&7Show all vote URLs", payload -> {
|
||||
VotingPluginUser payloadUser = plugin.getVotingPluginUserManager().getVotingPluginUser(player);
|
||||
json = true;
|
||||
payloadUser.sendMessage(getChat(player, false));
|
||||
});
|
||||
}
|
||||
|
||||
for (final VoteSite voteSite : plugin.getVoteSiteManager().getVoteSitesEnabled()) {
|
||||
if (voteSite.isHidden()) {
|
||||
continue;
|
||||
}
|
||||
if (!voteSite.getPermissionToView().isEmpty() && !player.hasPermission(voteSite.getPermissionToView())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean canVote = finalUser.canVoteSite(voteSite);
|
||||
String color = canVote ? "&a" : "&c";
|
||||
|
||||
dialog.placeholder("sitename", voteSite.getDisplayName())
|
||||
.placeholder("SiteName", voteSite.getDisplayName())
|
||||
.placeholder("servicesite", voteSite.getServiceSite())
|
||||
.placeholder("ServiceSite", voteSite.getServiceSite())
|
||||
.placeholder("VoteDelay", "" + voteSite.getVoteDelay())
|
||||
.placeholder("VoteHour", "" + voteSite.getVoteDelayDailyHour())
|
||||
.placeholder("Next", finalUser.voteCommandNextInfo(voteSite))
|
||||
.button(color + voteSite.getDisplayName(),
|
||||
canVote ? "&aClick to view vote link" : "&c" + finalUser.voteCommandNextInfo(voteSite),
|
||||
payload -> {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
if (clicked != null) {
|
||||
VotingPluginUser clickedUser = plugin.getVotingPluginUserManager()
|
||||
.getVotingPluginUser(clicked);
|
||||
HashMap<String, String> placeholders = new HashMap<String, String>();
|
||||
placeholders.put("voteurl", voteSite.getVoteURL());
|
||||
placeholders.put("sitename", voteSite.getDisplayName());
|
||||
placeholders.put("player", clicked.getName());
|
||||
placeholders.put("servicesite", voteSite.getServiceSite());
|
||||
placeholders.put("VoteDelay", "" + voteSite.getVoteDelay());
|
||||
placeholders.put("VoteHour", "" + voteSite.getVoteDelayDailyHour());
|
||||
clickedUser.sendMessage(plugin.getGui().getChestVoteURLURLText(), placeholders);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (plugin.getGui().isChestVoteURLBackButton()) {
|
||||
dialog.button("&eBack", "&7Return to previous menu", payload -> player.performCommand("vote gui"));
|
||||
}
|
||||
|
||||
dialog.open();
|
||||
}
|
||||
|
||||
private ItemBuilder getItemAll() {
|
||||
ItemBuilder builderAll = new ItemBuilder(plugin.getGui().getChestVoteURLAlreadyVotedAllUrlsButtonItemSection());
|
||||
if (plugin.getGui().isChestVoteURLAllUrlsButtonrequireAllSitesVoted()) {
|
||||
|
||||
+52
@@ -106,4 +106,56 @@ public class VoteURLVoteSite extends GUIHandler {
|
||||
open(GUIMethod.CHEST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Player player) {
|
||||
|
||||
if (!plugin.getVoteSiteManager().isVoteSite(voteSite)) {
|
||||
player.sendMessage("Not a valid votesite");
|
||||
return;
|
||||
}
|
||||
|
||||
VoteSite site = plugin.getVoteSiteManager().getVoteSite(voteSite, true);
|
||||
|
||||
com.bencodez.simpleapi.dialog.MultiActionDialogBuilder dialog = plugin.getDialogService().multiAction(player)
|
||||
.placeholder("player", user.getPlayerName()).placeholder("site", site.getDisplayName())
|
||||
.placeholder("sitename", site.getDisplayName()).placeholder("SiteName", site.getDisplayName())
|
||||
.placeholder("servicesite", site.getServiceSite()).placeholder("ServiceSite", site.getServiceSite())
|
||||
.placeholder("VoteDelay", "" + site.getVoteDelay())
|
||||
.placeholder("VoteHour", "" + site.getVoteDelayDailyHour())
|
||||
.placeholder("Next", user.voteCommandNextInfo(site)).placeholder("Last", user.voteCommandLastLine(site))
|
||||
.title(plugin.getGui().getChestVoteURLSiteName()).body("&7Site: &e%site%").columns(2);
|
||||
|
||||
dialog.button("&4URL", "&7Click to see URL", payload -> {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
if (clicked != null) {
|
||||
clicked.sendMessage(site.getVoteURL());
|
||||
}
|
||||
});
|
||||
|
||||
dialog.button("&4Next Vote", "%Next%", payload -> {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
if (clicked != null) {
|
||||
new VoteURL(plugin, clicked, user, true).open();
|
||||
}
|
||||
});
|
||||
|
||||
dialog.button("&4Last Vote", "%Last%", payload -> {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
if (clicked != null) {
|
||||
new VoteURL(plugin, clicked, user, true).open();
|
||||
}
|
||||
});
|
||||
|
||||
if (plugin.getGui().isChestVoteURLBackButton()) {
|
||||
dialog.button("&eBack", "&7Return to previous menu", payload -> {
|
||||
Player clicked = player.getServer().getPlayer(payload.owner());
|
||||
if (clicked != null) {
|
||||
new VoteURL(plugin, clicked, user, true).open();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
dialog.open();
|
||||
}
|
||||
|
||||
}
|
||||
+7
@@ -98,6 +98,13 @@ public class AliasesTabCompleter implements TabCompleter {
|
||||
return tab;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the command handler for this tab completer.
|
||||
*
|
||||
* @param cmd the command handler
|
||||
* @param adminCommand whether this is an admin command
|
||||
* @return this tab completer instance
|
||||
*/
|
||||
public AliasesTabCompleter setCMDHandle(CommandHandler cmd, boolean adminCommand) {
|
||||
cmdHandle = cmd;
|
||||
this.adminCommand = adminCommand;
|
||||
|
||||
@@ -13,6 +13,9 @@ import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Configuration file for Bungee/proxy settings.
|
||||
*/
|
||||
public class BungeeSettings extends YMLFile {
|
||||
|
||||
@ConfigDataBoolean(path = "BungeeDebug")
|
||||
@@ -135,11 +138,21 @@ public class BungeeSettings extends YMLFile {
|
||||
@Getter
|
||||
private ArrayList<String> bungeeVotePartyGlobalCommands = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Constructs a new BungeeSettings.
|
||||
*
|
||||
* @param plugin the main plugin instance
|
||||
*/
|
||||
public BungeeSettings(VotingPluginMain plugin) {
|
||||
super(plugin, new File(plugin.getDataFolder(), "BungeeSettings.yml"));
|
||||
setIgnoreCase(plugin.getConfigFile().isCaseInsensitiveYMLFiles());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the server name formatted for storage.
|
||||
*
|
||||
* @return the formatted server name
|
||||
*/
|
||||
public String getServerNameStorage() {
|
||||
return getServer().replace("-", "_");
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ public class Config extends YMLFile {
|
||||
@Getter
|
||||
private int limitVotePoints = -1;
|
||||
|
||||
/** Whether YAML files should be case insensitive. */
|
||||
@ConfigDataBoolean(path = "CaseInsensitiveYMLFiles")
|
||||
@Getter
|
||||
public boolean caseInsensitiveYMLFiles = false;
|
||||
@@ -169,6 +170,11 @@ public class Config extends YMLFile {
|
||||
@Getter
|
||||
private boolean voteLoggingUseMainMySQL = true;
|
||||
|
||||
/**
|
||||
* Gets the vote logging configuration section.
|
||||
*
|
||||
* @return the vote logging configuration section
|
||||
*/
|
||||
public ConfigurationSection getVoteLoggingSection() {
|
||||
if (!getData().isConfigurationSection("VoteLogging")) {
|
||||
getData().createSection("VoteLogging");
|
||||
@@ -176,6 +182,12 @@ public class Config extends YMLFile {
|
||||
return getData().getConfigurationSection("VoteLogging");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if DiscordSRV top voter is enabled.
|
||||
*
|
||||
* @param topVoter the top voter type
|
||||
* @return true if enabled
|
||||
*/
|
||||
public boolean isDiscordSRVTopVoterEnabled(TopVoter topVoter) {
|
||||
switch (topVoter) {
|
||||
case AllTime:
|
||||
@@ -191,6 +203,12 @@ public class Config extends YMLFile {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if DiscordSRV top voter should send a new message on update.
|
||||
*
|
||||
* @param topVoter the top voter type
|
||||
* @return true if new message should be sent
|
||||
*/
|
||||
public boolean isDiscordSRVTopVoterNewMessageOnUpdate(TopVoter topVoter) {
|
||||
switch (topVoter) {
|
||||
case AllTime:
|
||||
@@ -206,6 +224,12 @@ public class Config extends YMLFile {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the DiscordSRV top voter channel ID.
|
||||
*
|
||||
* @param topVoter the top voter type
|
||||
* @return the channel ID
|
||||
*/
|
||||
public long getDiscordSRVTopVoterChannel(TopVoter topVoter) {
|
||||
switch (topVoter) {
|
||||
case AllTime:
|
||||
@@ -221,6 +245,12 @@ public class Config extends YMLFile {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the DiscordSRV top voter title.
|
||||
*
|
||||
* @param topVoter the top voter type
|
||||
* @return the title
|
||||
*/
|
||||
public String getDiscordSRVTopVoterTitle(TopVoter topVoter) {
|
||||
switch (topVoter) {
|
||||
case AllTime:
|
||||
@@ -236,6 +266,12 @@ public class Config extends YMLFile {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the DiscordSRV top voter rank display format.
|
||||
*
|
||||
* @param topVoter the top voter type
|
||||
* @return the rank display format
|
||||
*/
|
||||
public String getDiscordSRVTopVoterRankDisplay(TopVoter topVoter) {
|
||||
switch (topVoter) {
|
||||
case AllTime:
|
||||
@@ -737,6 +773,11 @@ public class Config extends YMLFile {
|
||||
@Getter
|
||||
private boolean alwaysProcessAsyncPlaceholders = false;
|
||||
|
||||
/**
|
||||
* Constructs a new Config.
|
||||
*
|
||||
* @param plugin the main plugin instance
|
||||
*/
|
||||
public Config(VotingPluginMain plugin) {
|
||||
super(plugin, new File(plugin.getDataFolder(), "Config.yml"));
|
||||
setIgnoreCase(true);
|
||||
@@ -752,10 +793,22 @@ public class Config extends YMLFile {
|
||||
return (ArrayList<String>) getData().getList("BlackList", new ArrayList<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the custom commands configuration section.
|
||||
*
|
||||
* @param ident the command identifier
|
||||
* @return the configuration section
|
||||
*/
|
||||
public ConfigurationSection getCustomCommands(String ident) {
|
||||
return getData().getConfigurationSection("CustomCommands." + ident);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the custom placeholder return keys.
|
||||
*
|
||||
* @param placeholder the placeholder name
|
||||
* @return set of return keys
|
||||
*/
|
||||
public Set<String> getCustomPlaceholderReturns(String placeholder) {
|
||||
Set<String> str = getData().getConfigurationSection("CustomPlaceholderReturns." + placeholder).getKeys(false);
|
||||
if (str == null) {
|
||||
@@ -764,6 +817,13 @@ public class Config extends YMLFile {
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a custom placeholder return value.
|
||||
*
|
||||
* @param placeholder the placeholder name
|
||||
* @param returnString the return key
|
||||
* @return the return value
|
||||
*/
|
||||
public String getCustomPlaceholderReturns(String placeholder, String returnString) {
|
||||
return getData().getString("CustomPlaceholderReturns." + placeholder + "." + returnString, "");
|
||||
}
|
||||
@@ -781,6 +841,11 @@ public class Config extends YMLFile {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the vote streak lines format.
|
||||
*
|
||||
* @return list of format lines
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ArrayList<String> getFormatCommandsVoteStreakLines() {
|
||||
return (ArrayList<String>) getData().getList("Format.Commands.Vote.Streak.Lines", new ArrayList<>());
|
||||
@@ -798,6 +863,11 @@ public class Config extends YMLFile {
|
||||
return (ArrayList<String>) getData().getList("Format.Commands.Vote.Text", str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the vote total format lines.
|
||||
*
|
||||
* @return list of format lines
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ArrayList<String> getFormatCommandsVoteTotal() {
|
||||
ArrayList<String> list = (ArrayList<String>) getData().getList("Format.Commands.Vote.Total", new ArrayList<>());
|
||||
@@ -811,6 +881,11 @@ public class Config extends YMLFile {
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the vote total all format lines.
|
||||
*
|
||||
* @return list of format lines
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ArrayList<String> getFormatCommandsVoteTotalAll() {
|
||||
|
||||
@@ -836,6 +911,12 @@ public class Config extends YMLFile {
|
||||
return (ArrayList<String>) getData().getList("Format.Commands.Vote.Help.Lines", new ArrayList<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a top voter type should be loaded.
|
||||
*
|
||||
* @param top the top voter type
|
||||
* @return true if should be loaded
|
||||
*/
|
||||
public boolean getLoadTopVoter(TopVoter top) {
|
||||
switch (top) {
|
||||
case AllTime:
|
||||
@@ -851,6 +932,11 @@ public class Config extends YMLFile {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the placeholder cache level.
|
||||
*
|
||||
* @return the cache level
|
||||
*/
|
||||
public PlaceholderCacheLevel getPlaceholderCacheLevel() {
|
||||
return PlaceholderCacheLevel.getCache(getPlaceholderCacheLevelString());
|
||||
}
|
||||
|
||||
@@ -30,6 +30,11 @@ public class ConfigVoteSites extends YMLFile {
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Constructs a new ConfigVoteSites.
|
||||
*
|
||||
* @param plugin the plugin instance
|
||||
*/
|
||||
public ConfigVoteSites(VotingPluginMain plugin) {
|
||||
super(plugin, new File(plugin.getDataFolder(), "VoteSites.yml"));
|
||||
setIgnoreCase(plugin.getConfigFile().isCaseInsensitiveYMLFiles());
|
||||
@@ -44,7 +49,8 @@ public class ConfigVoteSites extends YMLFile {
|
||||
public void generateVoteSite(String siteName) {
|
||||
if (plugin.getConfigFile().isAutoCreateVoteSites()) {
|
||||
String org = siteName;
|
||||
siteName = siteName.replace(".", "_").replace(" ", "_");
|
||||
siteName = siteName.replaceAll("[\\.\\s]+", "_");
|
||||
|
||||
plugin.getLogger().warning("VoteSite " + siteName + " does not exist with the servicesite '" + org
|
||||
+ "', creating one, set AutoCreateVoteSites to false to prevent this");
|
||||
setEnabled(siteName, true);
|
||||
@@ -126,14 +132,31 @@ public class ConfigVoteSites extends YMLFile {
|
||||
return getData().getConfigurationSection("VoteSites." + siteName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the display name for a site.
|
||||
*
|
||||
* @param site the site name
|
||||
* @return the display name
|
||||
*/
|
||||
public String getDisplayName(String site) {
|
||||
return getData(site).getString("Name");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path to the every site reward.
|
||||
*
|
||||
* @return the every site reward path
|
||||
*/
|
||||
public String getEverySiteRewardPath() {
|
||||
return "EverySiteReward";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the item configuration for a site.
|
||||
*
|
||||
* @param site the site name
|
||||
* @return the item configuration
|
||||
*/
|
||||
public ConfigurationSection getItem(String site) {
|
||||
if (getData(site).isConfigurationSection("DisplayItem")) {
|
||||
return getData(site).getConfigurationSection("DisplayItem");
|
||||
@@ -141,6 +164,12 @@ public class ConfigVoteSites extends YMLFile {
|
||||
return getData(site).getConfigurationSection("Item");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the permission required to view a site.
|
||||
*
|
||||
* @param siteName the site name
|
||||
* @return the permission to view
|
||||
*/
|
||||
public String getPermissionToView(String siteName) {
|
||||
return getData(siteName).getString("PermissionToView", "");
|
||||
}
|
||||
@@ -175,6 +204,12 @@ public class ConfigVoteSites extends YMLFile {
|
||||
return getData(siteName).getString("ServiceSite");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the vote delay for a site.
|
||||
*
|
||||
* @param site the site name
|
||||
* @return the vote delay
|
||||
*/
|
||||
public ParsedDuration getVoteDelay(String site) {
|
||||
ConfigurationSection sec = getData(site);
|
||||
|
||||
@@ -192,6 +227,12 @@ public class ConfigVoteSites extends YMLFile {
|
||||
return ParsedDuration.ofMillis(millis);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the vote delay daily hour for a site.
|
||||
*
|
||||
* @param siteName the site name
|
||||
* @return the vote delay daily hour
|
||||
*/
|
||||
public int getVoteDelayDailyHour(String siteName) {
|
||||
return getData(siteName).getInt("VoteDelayDailyHour", 0);
|
||||
}
|
||||
@@ -227,18 +268,42 @@ public class ConfigVoteSites extends YMLFile {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether to give rewards offline for a site.
|
||||
*
|
||||
* @param site the site name
|
||||
* @return true if rewards should be given offline
|
||||
*/
|
||||
public boolean getVoteSiteGiveOffline(String site) {
|
||||
return getData(site).getBoolean("ForceOffline", getData(site).getBoolean("GiveOffline"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether a site is hidden.
|
||||
*
|
||||
* @param siteName the site name
|
||||
* @return true if the site is hidden
|
||||
*/
|
||||
public boolean getVoteSiteHidden(String siteName) {
|
||||
return getData(siteName).getBoolean("Hidden");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether to ignore can vote check for a site.
|
||||
*
|
||||
* @param siteName the site name
|
||||
* @return true if can vote check should be ignored
|
||||
*/
|
||||
public boolean getVoteSiteIgnoreCanVote(String siteName) {
|
||||
return getData(siteName).getBoolean("IgnoreCanVote");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether vote delay resets daily for a site.
|
||||
*
|
||||
* @param siteName the site name
|
||||
* @return true if vote delay resets daily
|
||||
*/
|
||||
public boolean getVoteSiteResetVoteDelayDaily(String siteName) {
|
||||
return getData(siteName).getBoolean("VoteDelayDaily");
|
||||
}
|
||||
@@ -285,24 +350,35 @@ public class ConfigVoteSites extends YMLFile {
|
||||
return voteSites;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the names of vote sites.
|
||||
*
|
||||
* @param checkEnabled whether to check if sites are enabled
|
||||
* @return the list of vote site names
|
||||
*/
|
||||
public ArrayList<String> getVoteSitesNames(boolean checkEnabled) {
|
||||
ArrayList<String> siteNames = new ArrayList<>();
|
||||
if (getData().isConfigurationSection("VoteSites")) {
|
||||
siteNames = ArrayUtils.convert(getData().getConfigurationSection("VoteSites").getKeys(false));
|
||||
|
||||
if (!getData().isConfigurationSection("VoteSites")) {
|
||||
return siteNames;
|
||||
}
|
||||
|
||||
siteNames = ArrayUtils.convert(getData().getConfigurationSection("VoteSites").getKeys(false));
|
||||
|
||||
for (int i = siteNames.size() - 1; i >= 0; i--) {
|
||||
// plugin.getLogger().info(siteNames.get(i));
|
||||
if (!getData().isConfigurationSection("VoteSites." + siteNames.get(i))) {
|
||||
plugin.getLogger()
|
||||
.warning("VoteSites." + siteNames.get(i) + " is not a configuration section, please remove");
|
||||
siteNames.remove(i);
|
||||
} else if (siteNames.get(i).equalsIgnoreCase("null")
|
||||
|| (!getVoteSiteEnabled(siteNames.get(i)) && checkEnabled) || !siteCheck(siteNames.get(i))) {
|
||||
// plugin.getLogger().info("Removed: " + siteNames.get(i));
|
||||
String site = siteNames.get(i);
|
||||
String path = "VoteSites." + site;
|
||||
|
||||
if (!getData().isConfigurationSection(path)) {
|
||||
plugin.getLogger().warning(path + " is not a configuration section, please remove");
|
||||
siteNames.remove(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (site.equalsIgnoreCase("null") || (!getVoteSiteEnabled(site) && checkEnabled) || !siteCheck(site)) {
|
||||
siteNames.remove(i);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return siteNames;
|
||||
@@ -318,6 +394,12 @@ public class ConfigVoteSites extends YMLFile {
|
||||
return getData(siteName).getString("VoteURL", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether to wait until vote delay for a site.
|
||||
*
|
||||
* @param siteName the site name
|
||||
* @return true if should wait until vote delay
|
||||
*/
|
||||
public boolean getWaitUntilVoteDelay(String siteName) {
|
||||
return getData(siteName).getBoolean("WaitUntilVoteDelay", false);
|
||||
}
|
||||
@@ -394,10 +476,22 @@ public class ConfigVoteSites extends YMLFile {
|
||||
set(siteName, "Cumulative.Rewards", value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cumulative votes for a site.
|
||||
*
|
||||
* @param siteName the site name
|
||||
* @param value the value
|
||||
*/
|
||||
public void setCumulativeVotes(String siteName, int value) {
|
||||
set(siteName, "Cumulative.Votes", value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the display name for a site.
|
||||
*
|
||||
* @param siteName the site name
|
||||
* @param value the value
|
||||
*/
|
||||
public void setDisplayName(String siteName, String value) {
|
||||
set(siteName, "Name", value);
|
||||
}
|
||||
@@ -412,6 +506,12 @@ public class ConfigVoteSites extends YMLFile {
|
||||
set(siteName, "Enabled", disabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to force offline for a site.
|
||||
*
|
||||
* @param siteName the site name
|
||||
* @param value the value
|
||||
*/
|
||||
public void setForceOffline(String siteName, boolean value) {
|
||||
set(siteName, "ForceOffline", value);
|
||||
|
||||
@@ -485,10 +585,22 @@ public class ConfigVoteSites extends YMLFile {
|
||||
return pass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the vote delay daily hour for a site.
|
||||
*
|
||||
* @param siteName the site name
|
||||
* @param intValue the value
|
||||
*/
|
||||
public void setVoteDelayDailyHour(String siteName, int intValue) {
|
||||
set(siteName, "VoteDelayDailyHour", intValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether vote delay is daily for a site.
|
||||
*
|
||||
* @param siteName the site name
|
||||
* @param value the value
|
||||
*/
|
||||
public void setVoteDelayDaily(String siteName, boolean value) {
|
||||
set(siteName, "VoteDelayDaily", value);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,9 @@ import com.bencodez.votingplugin.topvoter.TopVoter;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* GUI configuration.
|
||||
*/
|
||||
public class GUI extends YMLFile {
|
||||
|
||||
@ConfigDataString(path = "BOOK.VoteURLBookGUI.AlreadyVotedColor")
|
||||
@@ -88,42 +91,42 @@ public class GUI extends YMLFile {
|
||||
@Getter
|
||||
private boolean chestVoteURLAllUrlsButtonrequireAllSitesVoted = true;
|
||||
|
||||
@ConfigDataString(path = "GUIMethod.Best")
|
||||
@Getter
|
||||
private String guiMethodBest = "CHEST";
|
||||
|
||||
@ConfigDataString(path = "GUIMethod.GUI")
|
||||
@Getter
|
||||
private String guiMethodGUI = "CHEST";
|
||||
|
||||
@ConfigDataString(path = "GUIMethod.Last")
|
||||
@Getter
|
||||
private String guiMethodLast = "CHEST";
|
||||
|
||||
@ConfigDataString(path = "GUIMethod.Next")
|
||||
@Getter
|
||||
private String guiMethodNext = "CHEST";
|
||||
|
||||
@ConfigDataString(path = "GUIMethod.Streak")
|
||||
@Getter
|
||||
private String guiMethodStreak = "CHEST";
|
||||
|
||||
@ConfigDataString(path = "GUIMethod.Today")
|
||||
@ConfigDataString(path = "GUIMethod.Today", options = { "CHEST", "CHAT", "DIALOG" })
|
||||
@Getter
|
||||
private String guiMethodToday = "CHEST";
|
||||
|
||||
@ConfigDataString(path = "GUIMethod.TopVoter")
|
||||
@ConfigDataString(path = "GUIMethod.TopVoter", options = { "CHEST", "CHAT", "DIALOG" })
|
||||
@Getter
|
||||
private String guiMethodTopVoter = "CHEST";
|
||||
|
||||
@ConfigDataString(path = "GUIMethod.Total")
|
||||
@ConfigDataString(path = "GUIMethod.Last", options = { "CHEST", "CHAT", "DIALOG" })
|
||||
@Getter
|
||||
private String guiMethodLast = "CHEST";
|
||||
|
||||
@ConfigDataString(path = "GUIMethod.Next", options = { "CHEST", "CHAT", "BOOK", "DIALOG" })
|
||||
@Getter
|
||||
private String guiMethodNext = "CHEST";
|
||||
|
||||
@ConfigDataString(path = "GUIMethod.Total", options = { "CHEST", "CHAT", "DIALOG" })
|
||||
@Getter
|
||||
private String guiMethodTotal = "CHEST";
|
||||
|
||||
@ConfigDataString(path = "GUIMethod.URL")
|
||||
@ConfigDataString(path = "GUIMethod.URL", options = { "CHEST", "CHAT", "BOOK", "DIALOG" })
|
||||
@Getter
|
||||
private String guiMethodURL = "CHEST";
|
||||
|
||||
@ConfigDataString(path = "GUIMethod.Best", options = { "CHEST", "CHAT", "DIALOG" })
|
||||
@Getter
|
||||
private String guiMethodBest = "CHEST";
|
||||
|
||||
@ConfigDataString(path = "GUIMethod.Streak", options = { "CHEST", "CHAT", "DIALOG" })
|
||||
@Getter
|
||||
private String guiMethodStreak = "CHEST";
|
||||
|
||||
@ConfigDataString(path = "GUIMethod.GUI", options = { "CHEST", "DIALOG" })
|
||||
@Getter
|
||||
private String guiMethodGUI = "CHEST";
|
||||
|
||||
@ConfigDataBoolean(path = "LastMonthGUI")
|
||||
@Getter
|
||||
private boolean lastMonthGUI = false;
|
||||
@@ -358,12 +361,23 @@ public class GUI extends YMLFile {
|
||||
@Getter
|
||||
private boolean chestVoteURLViewAllUrlsButtonEnabled = false;
|
||||
|
||||
/**
|
||||
* Constructs a new GUI configuration.
|
||||
*
|
||||
* @param plugin the plugin instance
|
||||
*/
|
||||
public GUI(VotingPluginMain plugin) {
|
||||
super(plugin, new File(plugin.getDataFolder(), "GUI.yml"));
|
||||
setIgnoreCase(plugin.getConfigFile().isCaseInsensitiveYMLFiles());
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the extra items for a chest GUI.
|
||||
*
|
||||
* @param gui the GUI name
|
||||
* @return the extra items
|
||||
*/
|
||||
public Set<String> getChestGUIExtraItems(String gui) {
|
||||
if (getData().isConfigurationSection("CHEST." + gui + ".ExtraItems")) {
|
||||
return getData().getConfigurationSection("CHEST." + gui + ".ExtraItems").getKeys(false);
|
||||
@@ -371,6 +385,13 @@ public class GUI extends YMLFile {
|
||||
return new HashSet<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an extra item configuration for a chest GUI.
|
||||
*
|
||||
* @param gui the GUI name
|
||||
* @param item the item name
|
||||
* @return the item configuration
|
||||
*/
|
||||
public ConfigurationSection getChestGUIExtraItemsItem(String gui, String item) {
|
||||
return getData().getConfigurationSection("CHEST." + gui + ".ExtraItems." + item);
|
||||
}
|
||||
@@ -397,10 +418,23 @@ public class GUI extends YMLFile {
|
||||
return (ArrayList<String>) getData().getList("CHEST.VoteGUI." + slot + ".Item.Lore", new ArrayList<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the rewards path for a chest vote GUI slot.
|
||||
*
|
||||
* @param slot the slot
|
||||
* @param lastPath the last path segment
|
||||
* @return the rewards path
|
||||
*/
|
||||
public String getChestVoteGUISlotRewardsPath(String slot, String lastPath) {
|
||||
return "CHEST.VoteGUI." + slot + "." + lastPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the configuration section for a chest vote GUI slot.
|
||||
*
|
||||
* @param slot the slot
|
||||
* @return the configuration section
|
||||
*/
|
||||
public ConfigurationSection getChestVoteGUISlotSection(String slot) {
|
||||
return getData().getConfigurationSection("CHEST.VoteGUI." + slot + ".Item");
|
||||
}
|
||||
@@ -415,10 +449,22 @@ public class GUI extends YMLFile {
|
||||
return getData().getInt("CHEST.VoteGUI." + slot + ".Slot", -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the custom site name display for a vote next GUI.
|
||||
*
|
||||
* @param site the site name
|
||||
* @return the custom display name
|
||||
*/
|
||||
public String getChestVoteNextCustomSiteNamesDisplays(String site) {
|
||||
return getData().getString("CHEST.VoteNext.CustomSiteNamesDisplays." + site, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the total item configuration for a top voter.
|
||||
*
|
||||
* @param top the top voter
|
||||
* @return the item configuration
|
||||
*/
|
||||
public ConfigurationSection getChestVoteTotalItem(TopVoter top) {
|
||||
switch (top) {
|
||||
case AllTime:
|
||||
@@ -435,6 +481,12 @@ public class GUI extends YMLFile {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an extra item configuration for a vote URL GUI.
|
||||
*
|
||||
* @param item the item name
|
||||
* @return the item configuration
|
||||
*/
|
||||
public ConfigurationSection getChestVoteURLExtraItemsItem(String item) {
|
||||
return getData().getConfigurationSection("CHEST.VoteURL.ExtraItems." + item);
|
||||
}
|
||||
|
||||
@@ -15,67 +15,71 @@ import com.bencodez.simpleapi.file.annotation.ConfigDataString;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* The ShopFile class manages the vote shop configuration.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class ShopFile extends YMLFile {
|
||||
|
||||
@Getter
|
||||
@ConfigDataConfigurationSection(path = "ShopConfirmPurchase.NoItem")
|
||||
private ConfigurationSection shopConfirmPurchaseNoItem;
|
||||
|
||||
@Getter
|
||||
@ConfigDataBoolean(path = "ShopConfirmPurchase.UseDialog")
|
||||
private boolean shopConfirmPurchaseUseDialog = false;
|
||||
|
||||
@ConfigDataString(path = "ShopConfirmPurchase.Title")
|
||||
private String shopConfirmPurchaseTitle = "Confirm Purchase?";
|
||||
|
||||
@Getter
|
||||
@ConfigDataConfigurationSection(path = "ShopConfirmPurchase.YesItem")
|
||||
private ConfigurationSection shopConfirmPurchaseYesItem;
|
||||
|
||||
@Getter
|
||||
@ConfigDataString(path = "VoteShop.Disabled")
|
||||
private String voteShopDisabled = "&cVote shop disabled";
|
||||
|
||||
@ConfigDataBoolean(path = "VoteShop.HideLimitedReached")
|
||||
@Getter
|
||||
private boolean voteShopHideLimitedReached = true;
|
||||
|
||||
@ConfigDataString(path = "VoteShop.LimitReached")
|
||||
@Getter
|
||||
private String voteShopLimitReached = "&aYou reached your limit";
|
||||
|
||||
@ConfigDataBoolean(path = "VoteShop.RequireConfirmation")
|
||||
@Getter
|
||||
private boolean voteShopRequireConfirmation = false;
|
||||
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
@ConfigDataBoolean(path = "VoteShop.BackButton")
|
||||
@Getter
|
||||
private boolean voteShopBackButton = true;
|
||||
|
||||
@ConfigDataBoolean(path = "VoteShop.ReopenGUIOnPurchase")
|
||||
@Getter
|
||||
private boolean voteShopReopenGUIOnPurchase = true;
|
||||
private boolean voteShopReopenGuiOnPurchase = true;
|
||||
|
||||
@ConfigDataBoolean(path = "VoteShop.Enabled")
|
||||
@Getter
|
||||
private boolean voteShopEnabled = true;
|
||||
|
||||
@ConfigDataString(path = "VoteShop.Name")
|
||||
@Getter
|
||||
private String voteShopName = "VoteShop";
|
||||
|
||||
@ConfigDataKeys(path = "ExtraItems")
|
||||
@Getter
|
||||
private Set<String> voteShopExtraItems = new HashSet<>();
|
||||
private Set<String> voteShopExtraItems = new HashSet<String>();
|
||||
|
||||
/**
|
||||
* Constructs a new ShopFile.
|
||||
*
|
||||
* @param plugin the main plugin instance
|
||||
*/
|
||||
public ShopFile(VotingPluginMain plugin) {
|
||||
super(plugin, new File(plugin.getDataFolder(), "Shop.yml"));
|
||||
setIgnoreCase(plugin.getConfigFile().isCaseInsensitiveYMLFiles());
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts vote shop data from the GUI file to this shop file.
|
||||
*/
|
||||
public void convertFromGUIFile() {
|
||||
// booleans
|
||||
setValue("VoteShop.Enabled", plugin.getGui().getData().getBoolean("CHEST.VoteShopEnabled"));
|
||||
setValue("VoteShop.BackButton", plugin.getGui().getData().getBoolean("CHEST.VoteShopBackButton"));
|
||||
setValue("VoteShop.HideLimitReached", plugin.getGui().getData().getBoolean("CHEST.VoteShopHideLimitedReached"));
|
||||
@@ -83,20 +87,20 @@ public class ShopFile extends YMLFile {
|
||||
plugin.getGui().getData().getBoolean("CHEST.VoteShopRequireConfirmation"));
|
||||
setValue("VoteShop.ReopenGUIOnPurchase",
|
||||
plugin.getGui().getData().getBoolean("CHEST.VoteShopReopenGUIOnPurchase"));
|
||||
|
||||
// strings
|
||||
setValue("VoteShop.Name", plugin.getGui().getData().getString("CHEST.VoteShopName"));
|
||||
setValue("VoteShop.LimitReached", plugin.getGui().getData().getString("CHEST.VoteShopLimitReached"));
|
||||
setValue("VoteShop.Disabled", plugin.getGui().getData().getString("CHEST.VoteShopDisabled"));
|
||||
|
||||
// sections
|
||||
setValue("Shop", plugin.getGui().getData().getConfigurationSection("CHEST.Shop"));
|
||||
setValue("ExtraItems", plugin.getGui().getData().getConfigurationSection("CHEST.VoteShopExtraItems"));
|
||||
setValue("ShopConfirmPurchase", plugin.getGui().getData().getConfigurationSection("CHEST.ShopConfirmPurchase"));
|
||||
saveData();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new legacy shop item.
|
||||
*
|
||||
* @param value the identifier
|
||||
*/
|
||||
public void createShop(String value) {
|
||||
ConfigurationSection shopData = getData().createSection("Shop." + value);
|
||||
shopData.set("Identifier_Name", value);
|
||||
@@ -107,77 +111,264 @@ public class ShopFile extends YMLFile {
|
||||
shopData.set("Permission", "");
|
||||
shopData.set("CloseGUI", true);
|
||||
shopData.set("RequireConfirmation", false);
|
||||
|
||||
shopData.set("Rewards.Items.Item1.Material", "STONE");
|
||||
shopData.set("Rewards.Items.Item1.Amount", 1);
|
||||
saveData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the categories section.
|
||||
*
|
||||
* @return the categories section
|
||||
*/
|
||||
public ConfigurationSection getCategoriesSection() {
|
||||
return getData().getConfigurationSection("Categories");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a category section.
|
||||
*
|
||||
* @param categoryId the category id
|
||||
* @return the category section
|
||||
*/
|
||||
public ConfigurationSection getCategorySection(String categoryId) {
|
||||
return getData().getConfigurationSection("Categories." + categoryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a category shop section.
|
||||
*
|
||||
* @param categoryId the category id
|
||||
* @return the category shop section
|
||||
*/
|
||||
public ConfigurationSection getCategoryShopSection(String categoryId) {
|
||||
return getData().getConfigurationSection("Categories." + categoryId + ".Shop");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a category back button is enabled.
|
||||
*
|
||||
* @param category the category id
|
||||
* @return true if enabled
|
||||
*/
|
||||
public boolean isCategoryBackButtonEnabled(String category) {
|
||||
return getData().getBoolean("Categories." + category + ".BackButton", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the category back button item section.
|
||||
*
|
||||
* @param category the category id
|
||||
* @return configuration section or null
|
||||
*/
|
||||
public ConfigurationSection getCategoryBackButtonItem(String category) {
|
||||
String path = "Categories." + category + ".BackButtonItem";
|
||||
|
||||
if (getData().isConfigurationSection(path)) {
|
||||
return getData().getConfigurationSection(path);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default VoteShop back button item.
|
||||
*
|
||||
* @return configuration section or null
|
||||
*/
|
||||
public ConfigurationSection getDefaultBackButtonItem() {
|
||||
if (getData().isConfigurationSection("VoteShop.BackButtonItem")) {
|
||||
return getData().getConfigurationSection("VoteShop.BackButtonItem");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the display section for an entry, preferring DisplayItem when present.
|
||||
*
|
||||
* @param section the entry section
|
||||
* @return the display section
|
||||
*/
|
||||
public ConfigurationSection getDisplaySection(ConfigurationSection section) {
|
||||
if (section == null) {
|
||||
return null;
|
||||
}
|
||||
ConfigurationSection displaySection = section.getConfigurationSection("DisplayItem");
|
||||
if (displaySection != null) {
|
||||
return displaySection;
|
||||
}
|
||||
return section;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the configuration for a vote shop extra item.
|
||||
*
|
||||
* @param item the item identifier
|
||||
* @return the configuration section
|
||||
*/
|
||||
public ConfigurationSection getGUIVoteShopExtraItems(String item) {
|
||||
return getData().getConfigurationSection("ExtraItems." + item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cost of a shop item.
|
||||
*
|
||||
* @param identifier the shop identifier
|
||||
* @return the cost
|
||||
*/
|
||||
public int getShopIdentifierCost(String identifier) {
|
||||
return getData().getInt("Shop." + identifier + ".Cost");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the identifier name for a shop item.
|
||||
*
|
||||
* @param identifier the shop identifier
|
||||
* @return the identifier name
|
||||
*/
|
||||
public String getShopIdentifierIdentifierName(String identifier) {
|
||||
return getData().getString("Shop." + identifier + ".Identifier_Name", identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the purchase limit for a shop item.
|
||||
*
|
||||
* @param identifier the shop identifier
|
||||
* @return the purchase limit
|
||||
*/
|
||||
public int getShopIdentifierLimit(String identifier) {
|
||||
return getData().getInt("Shop." + identifier + ".Limit", -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the rewards path for a shop item.
|
||||
*
|
||||
* @param identifier the shop identifier
|
||||
* @return the rewards path
|
||||
*/
|
||||
public String getShopIdentifierRewardsPath(String identifier) {
|
||||
return "Shop." + identifier + ".Rewards";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all shop identifiers.
|
||||
*
|
||||
* @return the set of shop identifiers
|
||||
*/
|
||||
public Set<String> getShopIdentifiers() {
|
||||
ConfigurationSection shop = getData().getConfigurationSection("Shop");
|
||||
if (shop != null) {
|
||||
return shop.getKeys(false);
|
||||
}
|
||||
return new HashSet<>();
|
||||
return new HashSet<String>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the shop root section.
|
||||
*
|
||||
* @return the shop section
|
||||
*/
|
||||
public ConfigurationSection getShopSection() {
|
||||
return getData().getConfigurationSection("Shop");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the configuration section for a shop item.
|
||||
*
|
||||
* @param identifier the shop identifier
|
||||
* @return the configuration section
|
||||
*/
|
||||
public ConfigurationSection getShopIdentifierSection(String identifier) {
|
||||
return getData().getConfigurationSection("Shop." + identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the GUI should close on purchase.
|
||||
*
|
||||
* @param shop the shop identifier
|
||||
* @return true if GUI should close
|
||||
*/
|
||||
public boolean getVoteShopCloseGUI(String shop) {
|
||||
return getData().getBoolean("Shop." + shop + ".CloseGUI", true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the shop item should be hidden when player has no permission.
|
||||
*
|
||||
* @param shop the shop identifier
|
||||
* @return true if should hide
|
||||
*/
|
||||
public boolean getVoteShopHideOnNoPermission(String shop) {
|
||||
return getData().getBoolean("Shop." + shop + ".HideOnNoPermission", true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the shop item is not buyable.
|
||||
*
|
||||
* @param shop the shop identifier
|
||||
* @return true if not buyable
|
||||
*/
|
||||
public boolean getVoteShopNotBuyable(String shop) {
|
||||
return getData().getBoolean("Shop." + shop + ".NotBuyable", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the permission required for a shop item.
|
||||
*
|
||||
* @param ident the shop identifier
|
||||
* @return the permission
|
||||
*/
|
||||
public String getVoteShopPermission(String ident) {
|
||||
return getData().getString("Shop." + ident + ".Permission", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the purchase message for a shop item.
|
||||
*
|
||||
* @param identifier the shop identifier
|
||||
* @return the purchase message
|
||||
*/
|
||||
public String getVoteShopPurchase(String identifier) {
|
||||
return getData().getString("Shop." + identifier + ".PurchaseMessage",
|
||||
plugin.getConfigFile().getFormatShopPurchaseMsg());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the shop item resets daily.
|
||||
*
|
||||
* @param shop the shop identifier
|
||||
* @return true if resets daily
|
||||
*/
|
||||
public boolean getVoteShopResetDaily(String shop) {
|
||||
return getData().getBoolean("Shop." + shop + ".Reset.Daily", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the shop item resets monthly.
|
||||
*
|
||||
* @param shop the shop identifier
|
||||
* @return true if resets monthly
|
||||
*/
|
||||
public boolean getVoteShopResetMonthly(String shop) {
|
||||
return getData().getBoolean("Shop." + shop + ".Reset.Monthly", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the shop item resets weekly.
|
||||
*
|
||||
* @param shop the shop identifier
|
||||
* @return true if resets weekly
|
||||
*/
|
||||
public boolean getVoteShopResetWeekly(String shop) {
|
||||
return getData().getBoolean("Shop." + shop + ".Reset.Weekly", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the shop item requires purchase confirmation.
|
||||
*
|
||||
* @param identifier the shop identifier
|
||||
* @return true if requires confirmation
|
||||
*/
|
||||
public boolean isVoteShopRequireConfirmation(String identifier) {
|
||||
return getData().getBoolean("Shop." + identifier + ".RequireConfirmation", isVoteShopRequireConfirmation());
|
||||
}
|
||||
@@ -192,8 +383,13 @@ public class ShopFile extends YMLFile {
|
||||
plugin.saveResource("Shop.yml", true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a shop item.
|
||||
*
|
||||
* @param value the shop identifier
|
||||
*/
|
||||
public void removeShop(String value) {
|
||||
getData().set("Shop." + value, null);
|
||||
saveData();
|
||||
}
|
||||
}
|
||||
}
|
||||
+83
-2
@@ -18,6 +18,9 @@ import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* The SpecialRewardsConfig class manages special rewards configuration.
|
||||
*/
|
||||
public class SpecialRewardsConfig extends YMLFile {
|
||||
|
||||
@Getter
|
||||
@@ -54,14 +57,18 @@ public class SpecialRewardsConfig extends YMLFile {
|
||||
@Getter
|
||||
private boolean votePartyResetExtraVotesWeekly = false;
|
||||
|
||||
@ConfigDataString(path = "VoteParty.VoteReminderBroadcast")
|
||||
@ConfigDataString(path = "VoteParty.VoteReminder.Broadcast", secondPath = "VoteParty.VoteReminderBroadcast")
|
||||
@Getter
|
||||
private String votePartyVoteReminderBroadcast = "%votesrequired% left to go, go vote!";
|
||||
|
||||
@ConfigDataListInt(path = "VoteParty.VoteReminderAtVotes")
|
||||
@ConfigDataListInt(path = "VoteParty.VoteReminder.AtVotes", secondPath = "VoteParty.VoteReminderAtVotes")
|
||||
@Getter
|
||||
private ArrayList<Integer> votePartyVoteReminderAtVotes = new ArrayList<>();
|
||||
|
||||
@ConfigDataListString(path = "VoteParty.VoteReminder.Commands", secondPath = "VoteParty.VoteReminderCommands")
|
||||
@Getter
|
||||
private ArrayList<String> votePartyVoteReminderCommands = new ArrayList<>();
|
||||
|
||||
@ConfigDataListString(path = "VoteParty.GlobalRandomCommand")
|
||||
@Getter
|
||||
private ArrayList<String> votePartyGlobalRandomCommand = new ArrayList<>();
|
||||
@@ -153,16 +160,48 @@ public class SpecialRewardsConfig extends YMLFile {
|
||||
@Getter
|
||||
private Set<String> weeklyPossibleRewardPlaces = new HashSet<>();
|
||||
|
||||
@ConfigDataBoolean(path = "NameMCLikeReward.Enabled")
|
||||
@Getter
|
||||
private boolean nameMCLikeRewardEnabled = false;
|
||||
|
||||
@ConfigDataString(path = "NameMCLikeReward.Url")
|
||||
@Getter
|
||||
private String nameMCLikeRewardUrl = "";
|
||||
|
||||
@ConfigDataInt(path = "NameMCLikeReward.CheckIntervalMinutes")
|
||||
@Getter
|
||||
private int nameMCLikeRewardCheckIntervalMinutes = 10;
|
||||
|
||||
@Getter
|
||||
private final String nameMCLikeRewardPath = "NameMCLikeReward.Rewards";
|
||||
|
||||
/**
|
||||
* Constructs a new SpecialRewardsConfig.
|
||||
*
|
||||
* @param plugin the main plugin instance
|
||||
*/
|
||||
public SpecialRewardsConfig(VotingPluginMain plugin) {
|
||||
super(plugin, new File(plugin.getDataFolder(), "SpecialRewards.yml"));
|
||||
setIgnoreCase(plugin.getConfigFile().isCaseInsensitiveYMLFiles());
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the rewards path for a daily award.
|
||||
*
|
||||
* @param path the award path
|
||||
* @return the daily award rewards path
|
||||
*/
|
||||
public String getDailyAwardRewardsPath(String path) {
|
||||
return "DailyAwards." + path + ".Rewards";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the rewards path for a monthly award.
|
||||
*
|
||||
* @param path the award path
|
||||
* @return the monthly award rewards path
|
||||
*/
|
||||
public String getMonthlyAwardRewardsPath(String path) {
|
||||
return "MonthlyAwards." + path + ".Rewards";
|
||||
}
|
||||
@@ -180,6 +219,12 @@ public class SpecialRewardsConfig extends YMLFile {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the increase votes required with the old typo field.
|
||||
*
|
||||
* @return the increase votes required
|
||||
* @deprecated Use getVotePartyIncreaseVotesRequired instead
|
||||
*/
|
||||
public int getVotePartyIncreaseVotesRequiredWithTypo() {
|
||||
int increase = getVotePartyIncreaseVotesRequired();
|
||||
if (increase > 0) {
|
||||
@@ -188,14 +233,34 @@ public class SpecialRewardsConfig extends YMLFile {
|
||||
return getVotePartyIncreaseVotesRquired();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a vote streak reward is enabled.
|
||||
*
|
||||
* @param type the streak type
|
||||
* @param s the streak value
|
||||
* @return true if enabled
|
||||
*/
|
||||
public boolean getVoteStreakRewardEnabled(String type, String s) {
|
||||
return getData().getBoolean("VoteStreak." + type + "." + s + ".Enabled");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the rewards path for a vote streak.
|
||||
*
|
||||
* @param type the streak type
|
||||
* @param string the streak value
|
||||
* @return the vote streak rewards path
|
||||
*/
|
||||
public String getVoteStreakRewardsPath(String type, String string) {
|
||||
return "VoteStreak." + type + "." + string + ".Rewards";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all vote streak values for a type.
|
||||
*
|
||||
* @param type the streak type
|
||||
* @return the set of vote streak values
|
||||
*/
|
||||
public Set<String> getVoteStreakVotes(String type) {
|
||||
try {
|
||||
Set<String> set = getData().getConfigurationSection("VoteStreak." + type).getKeys(false);
|
||||
@@ -208,6 +273,12 @@ public class SpecialRewardsConfig extends YMLFile {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the rewards path for a weekly award.
|
||||
*
|
||||
* @param path the award path
|
||||
* @return the weekly award rewards path
|
||||
*/
|
||||
public String getWeeklyAwardRewardsPath(String path) {
|
||||
return "WeeklyAwards." + path + ".Rewards";
|
||||
}
|
||||
@@ -222,11 +293,21 @@ public class SpecialRewardsConfig extends YMLFile {
|
||||
plugin.saveResource("SpecialRewards.yml", true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a vote milestone.
|
||||
*
|
||||
* @param votes the milestone votes value
|
||||
*/
|
||||
public void removeVoteMilestone(String votes) {
|
||||
getData().set("VoteMilestones." + votes, null);
|
||||
saveData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a vote milestone with default values.
|
||||
*
|
||||
* @param intValue the milestone votes value
|
||||
*/
|
||||
public void setVoteMilestone(int intValue) {
|
||||
getData().set("VoteMilestones." + intValue + ".Enabled", true);
|
||||
getData().set("VoteMilestones." + intValue + ".Rewards.Messages.Player",
|
||||
|
||||
@@ -28,6 +28,9 @@ import com.bencodez.votingplugin.votesites.VoteSite;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Manages cooldown checks for vote rewards.
|
||||
*/
|
||||
public class CoolDownCheck implements Listener {
|
||||
|
||||
private final VotingPluginMain plugin;
|
||||
@@ -40,6 +43,11 @@ public class CoolDownCheck implements Listener {
|
||||
|
||||
private volatile boolean cooldownCheckEnabled = false;
|
||||
|
||||
/**
|
||||
* Constructs a new cooldown check manager.
|
||||
*
|
||||
* @param plugin the plugin instance
|
||||
*/
|
||||
public CoolDownCheck(VotingPluginMain plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
@@ -49,6 +57,11 @@ public class CoolDownCheck implements Listener {
|
||||
this.timer = exec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the cooldown for a player by UUID.
|
||||
*
|
||||
* @param uuid the player UUID
|
||||
*/
|
||||
public void check(UUID uuid) {
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(uuid);
|
||||
if (!user.isOnline()) {
|
||||
@@ -57,6 +70,9 @@ public class CoolDownCheck implements Listener {
|
||||
check(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shuts down the cooldown check timer.
|
||||
*/
|
||||
public void shutdown() {
|
||||
timer.shutdownNow();
|
||||
|
||||
@@ -75,6 +91,11 @@ public class CoolDownCheck implements Listener {
|
||||
allSiteTasks.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the cooldown for a user.
|
||||
*
|
||||
* @param user the voting plugin user
|
||||
*/
|
||||
public synchronized void check(VotingPluginUser user) {
|
||||
if (!user.getCoolDownCheck()) {
|
||||
return;
|
||||
@@ -99,6 +120,8 @@ public class CoolDownCheck implements Listener {
|
||||
|
||||
/**
|
||||
* Check ONLY a specific votesite for all users (uses streaming keys/cols).
|
||||
*
|
||||
* @param site the vote site to check
|
||||
*/
|
||||
public void checkAllVoteSite(VoteSite site) {
|
||||
if (site == null) {
|
||||
@@ -133,12 +156,20 @@ public class CoolDownCheck implements Listener {
|
||||
+ " (processed: " + count + ")"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if cooldown check is enabled.
|
||||
*/
|
||||
public void checkEnabled() {
|
||||
cooldownCheckEnabled = !plugin.getConfigFile().isDisableCoolDownCheck()
|
||||
&& plugin.getRewardHandler().hasRewards(plugin.getSpecialRewardsConfig().getData(),
|
||||
"VoteCoolDownEndedReward");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks per-site cooldown for a player by UUID.
|
||||
*
|
||||
* @param uuid the player UUID
|
||||
*/
|
||||
public void checkPerSite(UUID uuid) {
|
||||
VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(uuid);
|
||||
if (!user.isOnline()) {
|
||||
@@ -147,6 +178,11 @@ public class CoolDownCheck implements Listener {
|
||||
checkPerSite(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks per-site cooldown for a user.
|
||||
*
|
||||
* @param user the voting plugin user
|
||||
*/
|
||||
public synchronized void checkPerSite(VotingPluginUser user) {
|
||||
if (!plugin.getConfigFile().isPerSiteCoolDownEvents()) {
|
||||
return;
|
||||
@@ -203,6 +239,9 @@ public class CoolDownCheck implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the cooldown check system.
|
||||
*/
|
||||
public void load() {
|
||||
plugin.addUserStartup(new UserStartup() {
|
||||
|
||||
@@ -221,12 +260,22 @@ public class CoolDownCheck implements Listener {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the cooldown end event.
|
||||
*
|
||||
* @param event the cooldown end event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onCoolDownEnd(PlayerVoteCoolDownEndEvent event) {
|
||||
plugin.getRewardHandler().giveReward(event.getPlayer(), plugin.getSpecialRewardsConfig().getData(),
|
||||
"VoteCoolDownEndedReward", new RewardOptions());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the per-site cooldown end event.
|
||||
*
|
||||
* @param event the per-site cooldown end event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onCoolDownEnd(PlayerVoteSiteCoolDownEndEvent event) {
|
||||
plugin.getRewardHandler().giveReward(event.getPlayer(), event.getSite().getSiteData(), "CoolDownEndRewards",
|
||||
@@ -234,6 +283,12 @@ public class CoolDownCheck implements Listener {
|
||||
.addPlaceholder("url", event.getSite().getVoteURL(false)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a cooldown check for a user.
|
||||
*
|
||||
* @param user the voting plugin user
|
||||
* @param force whether to force the schedule
|
||||
*/
|
||||
public void schedule(VotingPluginUser user, boolean force) {
|
||||
if (user.getSitesVotedOn() <= 0 && !force) {
|
||||
return;
|
||||
@@ -262,6 +317,12 @@ public class CoolDownCheck implements Listener {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules per-site cooldown checks for a user.
|
||||
*
|
||||
* @param user the voting plugin user
|
||||
* @param force whether to force the schedule
|
||||
*/
|
||||
public void schedulePerSite(VotingPluginUser user, boolean force) {
|
||||
if (!plugin.getConfigFile().isPerSiteCoolDownEvents()) {
|
||||
return;
|
||||
@@ -303,6 +364,12 @@ public class CoolDownCheck implements Listener {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a vote event for cooldown scheduling.
|
||||
*
|
||||
* @param user the voting plugin user
|
||||
* @param site the vote site
|
||||
*/
|
||||
public void vote(VotingPluginUser user, VoteSite site) {
|
||||
if (cooldownCheckEnabled) {
|
||||
schedule(user, true);
|
||||
|
||||
@@ -26,10 +26,20 @@ public class ServerData {
|
||||
|
||||
private VotingPluginMain plugin = VotingPluginMain.plugin;
|
||||
|
||||
/**
|
||||
* Constructs a new ServerData.
|
||||
*
|
||||
* @param plugin the main plugin instance
|
||||
*/
|
||||
public ServerData(VotingPluginMain plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an auto-cached placeholder.
|
||||
*
|
||||
* @param placeholder the placeholder to add
|
||||
*/
|
||||
public void addAutoCachedPlaceholder(String placeholder) {
|
||||
List<String> p = getAutoCachedPlaceholder();
|
||||
|
||||
@@ -39,6 +49,11 @@ public class ServerData {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a service site to the list.
|
||||
*
|
||||
* @param site the service site to add
|
||||
*/
|
||||
public synchronized void addServiceSite(String site) {
|
||||
ArrayList<String> l = getServiceSites();
|
||||
if (!getServiceSites().contains(site)) {
|
||||
@@ -69,6 +84,12 @@ public class ServerData {
|
||||
getSignSkullLocation("" + count), getSignData("" + count), getSignPosition("" + count)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a timed vote to the cache.
|
||||
*
|
||||
* @param num the vote number
|
||||
* @param vote the vote time queue entry
|
||||
*/
|
||||
public void addTimeVoted(int num, VoteTimeQueue vote) {
|
||||
getData().set("TimedVoteCache." + num + ".Name", vote.getName());
|
||||
getData().set("TimedVoteCache." + num + ".Service", vote.getService());
|
||||
@@ -76,23 +97,46 @@ public class ServerData {
|
||||
saveData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a vote shop purchase for the specified identifier.
|
||||
*
|
||||
* @param ident the vote shop identifier
|
||||
*/
|
||||
public void addVoteShopPurchase(String ident) {
|
||||
setVoteShopPurchases(ident, (getVoteShopPurchases(ident) + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the timed vote cache.
|
||||
*/
|
||||
public void clearTimedVoteCache() {
|
||||
getData().set("TimedVoteCache", null);
|
||||
saveData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the auto cached placeholders.
|
||||
*
|
||||
* @return the auto cached placeholder list
|
||||
*/
|
||||
public List<String> getAutoCachedPlaceholder() {
|
||||
return getData().getStringList("AutoCachePlaceholders");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current bungee vote party count.
|
||||
*
|
||||
* @return the bungee vote party current count
|
||||
*/
|
||||
public int getBungeeVotePartyCurrent() {
|
||||
return getData().getInt("BungeeVotePartyCurrent");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the required votes for bungee vote party.
|
||||
*
|
||||
* @return the bungee vote party required votes
|
||||
*/
|
||||
public int getBungeeVotePartyRequired() {
|
||||
return getData().getInt("BungeeVotePartyRequired");
|
||||
}
|
||||
@@ -111,10 +155,20 @@ public class ServerData {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of disabled reminders.
|
||||
*
|
||||
* @return the disabled reminders
|
||||
*/
|
||||
public List<String> getDisabledReminders() {
|
||||
return getData().getStringList("DisabledReminders");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the service sites list.
|
||||
*
|
||||
* @return the service sites
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ArrayList<String> getServiceSites() {
|
||||
return (ArrayList<String>) getData().getList("ServiceSites", new ArrayList<>());
|
||||
@@ -180,6 +234,11 @@ public class ServerData {
|
||||
getData().getDouble("Signs." + sign + ".Skull.Z"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the timed vote cache keys.
|
||||
*
|
||||
* @return the timed vote cache keys
|
||||
*/
|
||||
public Set<String> getTimedVoteCacheKeys() {
|
||||
if (getData().isConfigurationSection("TimedVoteCache")) {
|
||||
return getData().getConfigurationSection("TimedVoteCache").getKeys(false);
|
||||
@@ -187,18 +246,40 @@ public class ServerData {
|
||||
return new HashSet<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the timed vote cache section for the given number.
|
||||
*
|
||||
* @param num the cache entry number
|
||||
* @return the timed vote cache section
|
||||
*/
|
||||
public ConfigurationSection getTimedVoteCacheSection(String num) {
|
||||
return getData().getConfigurationSection("TimedVoteCache." + num);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the extra required votes for vote party.
|
||||
*
|
||||
* @return the vote party extra required votes
|
||||
*/
|
||||
public int getVotePartyExtraRequired() {
|
||||
return getData().getInt("VotePartyExtraRequired", 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of purchases for a vote shop item.
|
||||
*
|
||||
* @param ident the vote shop identifier
|
||||
* @return the vote shop purchases
|
||||
*/
|
||||
public int getVoteShopPurchases(String ident) {
|
||||
return getData().getInt("VoteShopPurchases." + ident);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the last vote party was on the same day.
|
||||
*
|
||||
* @return true if same day
|
||||
*/
|
||||
public boolean isLastVotePartySameDay() {
|
||||
int num = getData().getInt("LastVoteParty", 0);
|
||||
if (num == plugin.getTimeChecker().getTime().getDayOfYear()) {
|
||||
@@ -207,6 +288,11 @@ public class ServerData {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the last vote party was in the same week.
|
||||
*
|
||||
* @return true if same week
|
||||
*/
|
||||
public boolean isLastVotePartySameWeek() {
|
||||
int num = getData().getInt("LastVotePartyWeek", -1);
|
||||
if (num == plugin.getTimeChecker().getTime().get(WeekFields.of(Locale.getDefault()).weekOfYear())
|
||||
@@ -216,6 +302,11 @@ public class ServerData {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the vote shop has been converted.
|
||||
*
|
||||
* @return true if converted
|
||||
*/
|
||||
public boolean isVoteShopConverted() {
|
||||
return getData().getBoolean("VoteShopConverted");
|
||||
}
|
||||
@@ -245,10 +336,22 @@ public class ServerData {
|
||||
plugin.getServerDataFile().reloadData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Discord message ID for the top voter.
|
||||
*
|
||||
* @param top the top voter type
|
||||
* @return the top voter message ID
|
||||
*/
|
||||
public long getTopVoterMessageId(TopVoter top) {
|
||||
return getData().getLong("DiscordSRV.TopVoterMessageId." + top.toString(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Discord message ID for the top voter.
|
||||
*
|
||||
* @param top the top voter type
|
||||
* @param messageId the message ID
|
||||
*/
|
||||
public void setTopVoterMessageId(TopVoter top, long messageId) {
|
||||
getData().set("DiscordSRV.TopVoterMessageId." + top.toString(), messageId);
|
||||
saveData();
|
||||
@@ -281,6 +384,11 @@ public class ServerData {
|
||||
plugin.getServerDataFile().saveData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the disabled reminders list.
|
||||
*
|
||||
* @param disabledReminders the list of UUIDs with disabled reminders
|
||||
*/
|
||||
public void saveDisabledReminders(ArrayList<UUID> disabledReminders) {
|
||||
ArrayList<String> uuids = new ArrayList<>();
|
||||
for (UUID uuid : disabledReminders) {
|
||||
@@ -290,31 +398,65 @@ public class ServerData {
|
||||
saveData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the auto cached placeholders.
|
||||
*
|
||||
* @param placeholders the list of placeholders
|
||||
*/
|
||||
public void setAutoCachedPlaceholder(List<String> placeholders) {
|
||||
getData().set("AutoCachePlaceholders", placeholders);
|
||||
saveData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current bungee vote party count.
|
||||
*
|
||||
* @param current the current vote count
|
||||
*/
|
||||
public void setBungeeVotePartyCurrent(int current) {
|
||||
getData().set("BungeeVotePartyCurrent", current);
|
||||
saveData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the required votes for bungee vote party.
|
||||
*
|
||||
* @param required the required vote count
|
||||
*/
|
||||
public void setBungeeVotePartyRequired(int required) {
|
||||
getData().set("BungeeVotePartyRequired", required);
|
||||
saveData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the service sites list.
|
||||
*
|
||||
* @param list the service sites list
|
||||
*/
|
||||
public void setServiceSites(ArrayList<String> list) {
|
||||
getData().set("ServiceSites", list);
|
||||
saveData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the vote shop converted status.
|
||||
*
|
||||
* @param value the converted status
|
||||
*/
|
||||
public void setShopConverted(boolean value) {
|
||||
getData().set("VoteShopConverted", value);
|
||||
saveData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets sign data.
|
||||
*
|
||||
* @param count the sign count
|
||||
* @param location the sign location
|
||||
* @param skullLocation the skull location
|
||||
* @param data the sign data
|
||||
* @param position the sign position
|
||||
*/
|
||||
public void setSign(String count, Location location, Location skullLocation, String data, int position) {
|
||||
|
||||
getData().set("Signs." + count + ".World", location.getWorld().getName());
|
||||
@@ -332,6 +474,12 @@ public class ServerData {
|
||||
saveData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the skull location for a sign.
|
||||
*
|
||||
* @param count the sign count
|
||||
* @param skullLocation the skull location
|
||||
*/
|
||||
public void setSkullLocation(String count, Location skullLocation) {
|
||||
if (skullLocation != null) {
|
||||
getData().set("Signs." + count + ".Skull.World", skullLocation.getWorld().getName());
|
||||
@@ -349,27 +497,47 @@ public class ServerData {
|
||||
saveData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the extra required votes for vote party.
|
||||
*
|
||||
* @param value the extra required votes
|
||||
*/
|
||||
public void setVotePartyExtraRequired(int value) {
|
||||
getData().set("VotePartyExtraRequired", value);
|
||||
saveData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the number of purchases for a vote shop item.
|
||||
*
|
||||
* @param ident the vote shop identifier
|
||||
* @param amount the purchase amount
|
||||
*/
|
||||
public void setVoteShopPurchases(String ident, int amount) {
|
||||
getData().set("VoteShopPurchases." + ident, amount);
|
||||
saveData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the last vote party timestamp to today.
|
||||
*/
|
||||
public void updateLastVoteParty() {
|
||||
getData().set("LastVoteParty", plugin.getTimeChecker().getTime().getDayOfYear());
|
||||
saveData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the last vote party week timestamp to this week.
|
||||
*/
|
||||
public void updateLastVotePartyWeek() {
|
||||
getData().set("LastVotePartyWeek",
|
||||
plugin.getTimeChecker().getTime().get(WeekFields.of(Locale.getDefault()).weekOfYear()));
|
||||
saveData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates placeholders to lowercase format.
|
||||
*/
|
||||
public void updatePlaceholders() {
|
||||
boolean data = getData().getBoolean("AutoCacheUpdated", false);
|
||||
if (!data) {
|
||||
|
||||
@@ -28,6 +28,9 @@ import github.scarsz.discordsrv.dependencies.jda.api.entities.TextChannel;
|
||||
import github.scarsz.discordsrv.util.DiscordUtil;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Handler for Discord integration.
|
||||
*/
|
||||
public class DiscordHandler {
|
||||
|
||||
private final VotingPluginMain plugin;
|
||||
@@ -35,6 +38,11 @@ public class DiscordHandler {
|
||||
private final HashMap<TopVoter, Long> topVoterMessageIds = new HashMap<TopVoter, Long>();
|
||||
private final AtomicBoolean discordReady = new AtomicBoolean(false);
|
||||
|
||||
/**
|
||||
* Constructs a new Discord handler.
|
||||
*
|
||||
* @param plugin the plugin instance
|
||||
*/
|
||||
public DiscordHandler(VotingPluginMain plugin) {
|
||||
this.plugin = plugin;
|
||||
for (TopVoter top : TopVoter.values()) {
|
||||
@@ -101,7 +109,11 @@ public class DiscordHandler {
|
||||
|
||||
}
|
||||
|
||||
/** Fired once JDA is fully initialized */
|
||||
/**
|
||||
* Fired once JDA is fully initialized.
|
||||
*
|
||||
* @param event the Discord ready event
|
||||
*/
|
||||
@Subscribe
|
||||
public void onDiscordReady(DiscordReadyEvent event) {
|
||||
discordReady.set(true);
|
||||
@@ -126,6 +138,11 @@ public class DiscordHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the top voter message ID for the specified top voter.
|
||||
*
|
||||
* @param top the top voter
|
||||
*/
|
||||
public void updateTopVoterMessageId(TopVoter top) {
|
||||
plugin.extraDebug("Updating Discord Top Voter message for: " + top);
|
||||
|
||||
@@ -188,6 +205,12 @@ public class DiscordHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a reward message to a Discord channel.
|
||||
*
|
||||
* @param message the message to send
|
||||
* @param channelId the Discord channel ID
|
||||
*/
|
||||
public void sendRewardMessage(String message, String channelId) {
|
||||
TextChannel channel = DiscordUtil.getJda().getTextChannelById(channelId);
|
||||
if (channel != null) {
|
||||
|
||||
@@ -81,6 +81,20 @@ public class PlayerPostVoteEvent extends Event {
|
||||
@Setter
|
||||
private UUID voteUUID;
|
||||
|
||||
/**
|
||||
* Constructs a new PlayerPostVoteEvent.
|
||||
*
|
||||
* @param voteSite the vote site
|
||||
* @param user the voting plugin user
|
||||
* @param realVote whether this is a real vote
|
||||
* @param forceBungee whether to force Bungee processing
|
||||
* @param voteTime the vote timestamp
|
||||
* @param cached whether the vote was cached
|
||||
* @param service the service name
|
||||
* @param uuid the player UUID
|
||||
* @param playerName the player name
|
||||
* @param voteUUID the vote UUID
|
||||
*/
|
||||
public PlayerPostVoteEvent(VoteSite voteSite, VotingPluginUser user, boolean realVote, boolean forceBungee,
|
||||
long voteTime, boolean cached, String service, UUID uuid, String playerName, UUID voteUUID) {
|
||||
super(true);
|
||||
|
||||
+6
@@ -42,6 +42,12 @@ public class PlayerReceivePointsEvent extends Event {
|
||||
@Setter
|
||||
private String serviceSite = "";
|
||||
|
||||
/**
|
||||
* Constructs a new PlayerReceivePointsEvent.
|
||||
*
|
||||
* @param user the voting plugin user
|
||||
* @param points the points received
|
||||
*/
|
||||
public PlayerReceivePointsEvent(VotingPluginUser user, int points) {
|
||||
super(true);
|
||||
this.player = user;
|
||||
|
||||
+7
@@ -44,6 +44,13 @@ public class PlayerSpecialRewardEvent extends Event {
|
||||
@Setter
|
||||
private UUID voteUUID;
|
||||
|
||||
/**
|
||||
* Constructs a new PlayerSpecialRewardEvent.
|
||||
*
|
||||
* @param user the voting plugin user
|
||||
* @param type the special reward type
|
||||
* @param voteUUID the vote UUID
|
||||
*/
|
||||
public PlayerSpecialRewardEvent(VotingPluginUser user, SpecialRewardType type, UUID voteUUID) {
|
||||
super(true);
|
||||
this.type = type;
|
||||
|
||||
+5
@@ -34,6 +34,11 @@ public class PlayerVoteCoolDownEndEvent extends Event {
|
||||
@Setter
|
||||
private VotingPluginUser player;
|
||||
|
||||
/**
|
||||
* Constructs a new PlayerVoteCoolDownEndEvent.
|
||||
*
|
||||
* @param user the voting plugin user
|
||||
*/
|
||||
public PlayerVoteCoolDownEndEvent(VotingPluginUser user) {
|
||||
super(true);
|
||||
player = user;
|
||||
|
||||
@@ -84,6 +84,14 @@ public class PlayerVoteEvent extends Event {
|
||||
@Setter
|
||||
private int voteNumber = 1;
|
||||
|
||||
/**
|
||||
* Constructs a new PlayerVoteEvent.
|
||||
*
|
||||
* @param voteSite the vote site
|
||||
* @param voteUsername the username of the voter
|
||||
* @param serviceSite the service site name
|
||||
* @param realVote whether this is a real vote
|
||||
*/
|
||||
public PlayerVoteEvent(VoteSite voteSite, String voteUsername, String serviceSite, boolean realVote) {
|
||||
super(true);
|
||||
this.player = voteUsername;
|
||||
|
||||
+6
@@ -39,6 +39,12 @@ public class PlayerVoteSiteCoolDownEndEvent extends Event {
|
||||
@Setter
|
||||
private VoteSite site;
|
||||
|
||||
/**
|
||||
* Constructs a new PlayerVoteSiteCoolDownEndEvent.
|
||||
*
|
||||
* @param user the voting plugin user
|
||||
* @param site the vote site
|
||||
*/
|
||||
public PlayerVoteSiteCoolDownEndEvent(VotingPluginUser user, VoteSite site) {
|
||||
super(true);
|
||||
player = user;
|
||||
|
||||
@@ -2,14 +2,34 @@ package com.bencodez.votingplugin.events;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Enumeration for different special reward types.
|
||||
*/
|
||||
public enum SpecialRewardType {
|
||||
/** @deprecated All site reward. */
|
||||
@Deprecated
|
||||
ALLSITE, @Deprecated
|
||||
CUMMULATIVE, @Deprecated
|
||||
FIRSTVOTE, @Deprecated
|
||||
FIRSTVOTETODAY, @Deprecated
|
||||
MILESTONE, VOTESTREAK, @Deprecated
|
||||
ALMOSTALLSITES, TOPVOTER, VOTESTREAKS;
|
||||
ALLSITE,
|
||||
/** @deprecated Cumulative reward. */
|
||||
@Deprecated
|
||||
CUMMULATIVE,
|
||||
/** @deprecated First vote reward. */
|
||||
@Deprecated
|
||||
FIRSTVOTE,
|
||||
/** @deprecated First vote today reward. */
|
||||
@Deprecated
|
||||
FIRSTVOTETODAY,
|
||||
/** @deprecated Milestone reward. */
|
||||
@Deprecated
|
||||
MILESTONE,
|
||||
/** Vote streak reward. */
|
||||
VOTESTREAK,
|
||||
/** @deprecated Almost all sites reward. */
|
||||
@Deprecated
|
||||
ALMOSTALLSITES,
|
||||
/** Top voter reward. */
|
||||
TOPVOTER,
|
||||
/** Vote streaks reward. */
|
||||
VOTESTREAKS;
|
||||
|
||||
@Getter
|
||||
private int amount = -1;
|
||||
@@ -17,11 +37,23 @@ public enum SpecialRewardType {
|
||||
@Getter
|
||||
private String type = "";
|
||||
|
||||
/**
|
||||
* Sets the amount for this special reward.
|
||||
*
|
||||
* @param num the amount
|
||||
* @return this special reward type
|
||||
*/
|
||||
public SpecialRewardType setAmount(int num) {
|
||||
amount = num;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type for this special reward.
|
||||
*
|
||||
* @param type the type
|
||||
* @return this special reward type
|
||||
*/
|
||||
public SpecialRewardType setType(String type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
|
||||
+50
@@ -62,38 +62,83 @@ public class VoteMilestoneRewardEvent extends Event {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the voting plugin user associated with this event.
|
||||
*
|
||||
* @return the voting plugin user
|
||||
*/
|
||||
public VotingPluginUser getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player UUID.
|
||||
*
|
||||
* @return the player UUID
|
||||
*/
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player name.
|
||||
*
|
||||
* @return the player name
|
||||
*/
|
||||
public String getPlayerName() {
|
||||
return playerName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the milestone that triggered this event.
|
||||
*
|
||||
* @return milestone instance
|
||||
*/
|
||||
public VoteMilestone getMilestone() {
|
||||
return milestone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the milestone ID.
|
||||
*
|
||||
* @return milestone id string
|
||||
*/
|
||||
public String getMilestoneId() {
|
||||
return milestone == null ? null : milestone.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value that triggered the milestone.
|
||||
*
|
||||
* @return the milestone value
|
||||
*/
|
||||
public long getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the group ID used for selection.
|
||||
*
|
||||
* @return group id string
|
||||
*/
|
||||
public String getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the configuration path for the rewards.
|
||||
*
|
||||
* @return the reward path
|
||||
*/
|
||||
public String getRewardPath() {
|
||||
return rewardPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the placeholders map for this milestone reward.
|
||||
*
|
||||
* @return map of placeholder names to values
|
||||
*/
|
||||
public Map<String, String> getPlaceholders() {
|
||||
return placeholders;
|
||||
}
|
||||
@@ -103,6 +148,11 @@ public class VoteMilestoneRewardEvent extends Event {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the handler list for this event.
|
||||
*
|
||||
* @return handler list
|
||||
*/
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,9 @@ public class VotePartyEvent extends Event {
|
||||
@Setter
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* Constructs a new VotePartyEvent.
|
||||
*/
|
||||
public VotePartyEvent() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
@@ -84,6 +84,11 @@ public class PlayerJoinEvent implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles player quit events.
|
||||
*
|
||||
* @param event the player quit event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
if (plugin == null || !plugin.isEnabled() || event == null) {
|
||||
|
||||
+30
-30
@@ -13,7 +13,7 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import com.bencodez.advancedcore.api.bedrock.BedrockNameResolver;
|
||||
import com.bencodez.advancedcore.api.misc.PlayerManager;
|
||||
import com.bencodez.advancedcore.api.user.validation.UserValidationResult;
|
||||
import com.bencodez.simpleapi.array.ArrayUtils;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.events.PlayerPostVoteEvent;
|
||||
@@ -56,28 +56,31 @@ public class PlayerVoteListener implements Listener {
|
||||
// check for name casing
|
||||
final String properName = plugin.getUserManager().getProperName(playerName);
|
||||
|
||||
// Resolve Bedrock/Java + add prefix only when appropriate
|
||||
// Validate BEFORE full bedrock/db-backed resolution
|
||||
boolean allowUnJoinedCheckServer = plugin.getConfigFile().isAllowUnJoinedCheckServer();
|
||||
UserValidationResult validationResult = plugin.getUserManager().getValidationService().validate(properName,
|
||||
allowUnJoinedCheckServer);
|
||||
|
||||
plugin.extraDebug("Vote validation result for " + properName + ": valid=" + validationResult.isValid()
|
||||
+ ", source=" + validationResult.getSource() + ", reason=" + validationResult.getReason()
|
||||
+ ", normalizedName=" + validationResult.getNormalizedName() + ", bedrock="
|
||||
+ validationResult.isBedrock());
|
||||
|
||||
if (!validationResult.isValid() && !plugin.getConfigFile().isAllowUnjoined()) {
|
||||
plugin.getLogger().warning("Player " + properName + " has not joined before, disregarding vote. "
|
||||
+ "Reason: " + validationResult.getReason() + ". Set AllowUnjoined to true to accept.");
|
||||
if (event.isBungee() && plugin.getBungeeSettings().isRemoveInvalidUsers()) {
|
||||
plugin.getVotingPluginUserManager().getVotingPluginUser(properName).remove();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Resolve Bedrock/Java + add prefix only when appropriate AFTER validation
|
||||
BedrockNameResolver.Result rn = plugin.getBedrockHandle().resolve(properName);
|
||||
String creditedName = rn.finalName;
|
||||
|
||||
plugin.debug("Vote name resolved: " + properName + " -> " + creditedName + " (" + rn.rationale + ")");
|
||||
|
||||
// Single validity check on the final name
|
||||
boolean allowUnJoinedCheckServer = plugin.getConfigFile().isAllowUnJoinedCheckServer();
|
||||
boolean isValid = PlayerManager.getInstance().isValidUser(creditedName, allowUnJoinedCheckServer);
|
||||
|
||||
// Handle not-valid the same way you did before
|
||||
if (!isValid) {
|
||||
if (!plugin.getConfigFile().isAllowUnjoined()) {
|
||||
plugin.getLogger().warning("Player " + creditedName + " has not joined before, disregarding vote. "
|
||||
+ "Set AllowUnjoined to true to accept.");
|
||||
if (event.isBungee() && plugin.getBungeeSettings().isRemoveInvalidUsers()) {
|
||||
plugin.getVotingPluginUserManager().getVotingPluginUser(creditedName).remove();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If we get here, use the resolved/possibly-prefixed name going forward
|
||||
playerName = creditedName;
|
||||
|
||||
@@ -91,7 +94,14 @@ public class PlayerVoteListener implements Listener {
|
||||
+ event.getBungeeTextTotals());
|
||||
|
||||
if (plugin.getBungeeSettings().isTriggerVotifierEvent()) {
|
||||
new BungeeVotifierEvent().send(plugin, event);
|
||||
try {
|
||||
new ProxyVotifierEvent().send(plugin, event);
|
||||
} catch (NoClassDefFoundError ex) {
|
||||
plugin.getLogger().severe(
|
||||
"Failed to trigger Votifier event for proxy vote. Either install votiifer or disable tirgger votiifer event");
|
||||
plugin.getLogger().severe("Error: " + ex.getMessage());
|
||||
plugin.debug(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,16 +261,6 @@ public class PlayerVoteListener implements Listener {
|
||||
plugin.getVoteMilestonesManager().handleVote(user, event.getBungeeTextTotals(), event.isForceBungee(), voteUUID,
|
||||
new HashMap<String, String>());
|
||||
|
||||
// other rewards
|
||||
// plugin.getSpecialRewards().checkAllSites(voteUUID, user,
|
||||
// event.isForceBungee());
|
||||
// plugin.getSpecialRewards().checkAlmostAllSites(voteUUID, user,
|
||||
// event.isForceBungee());
|
||||
// plugin.getSpecialRewards().checkCumualativeVotes(voteUUID, user,
|
||||
// event.getBungeeTextTotals(),
|
||||
// event.isForceBungee());
|
||||
// plugin.getSpecialRewards().checkMilestone(voteUUID, user,
|
||||
// event.getBungeeTextTotals(), event.isForceBungee());
|
||||
plugin.getCoolDownCheck().vote(user, voteSite);
|
||||
|
||||
plugin.getVoteStreakHandler().processVote(user, voteTime, voteUUID);
|
||||
@@ -282,4 +282,4 @@ public class PlayerVoteListener implements Listener {
|
||||
plugin.extraDebug("Finished vote processing: " + playerName + "/" + uuid);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+11
-2
@@ -5,9 +5,18 @@ import com.bencodez.votingplugin.events.PlayerVoteEvent;
|
||||
import com.vexsoftware.votifier.model.Vote;
|
||||
import com.vexsoftware.votifier.model.VotifierEvent;
|
||||
|
||||
public class BungeeVotifierEvent {
|
||||
/**
|
||||
* Handler for triggering Bungee Votifier events.
|
||||
*/
|
||||
public class ProxyVotifierEvent {
|
||||
/**
|
||||
* Sends a Votifier event for a player vote.
|
||||
*
|
||||
* @param plugin the main plugin instance
|
||||
* @param event the player vote event
|
||||
*/
|
||||
public void send(VotingPluginMain plugin, PlayerVoteEvent event) {
|
||||
plugin.debug("Triggering vote event");
|
||||
plugin.debug("Triggering proxy vote event");
|
||||
plugin.getBukkitScheduler().runTask(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.bencodez.votingplugin.listeners;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -13,13 +11,11 @@ import com.bencodez.votingplugin.proxy.BungeeMethod;
|
||||
import com.vexsoftware.votifier.model.Vote;
|
||||
import com.vexsoftware.votifier.model.VotifierEvent;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class VotiferEvent.
|
||||
*/
|
||||
public class VotiferEvent implements Listener {
|
||||
|
||||
/** The plugin. */
|
||||
private VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
@@ -48,7 +44,6 @@ public class VotiferEvent implements Listener {
|
||||
final String IP = vote.getAddress();
|
||||
final String voteUsername = vote.getUsername().trim();
|
||||
if (IP.equals("VotingPlugin")) {
|
||||
// ignore own plugin calls of event
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -79,6 +74,7 @@ public class VotiferEvent implements Listener {
|
||||
"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");
|
||||
return;
|
||||
}
|
||||
|
||||
String matchSite = "";
|
||||
if (plugin.getConfigFile().isAdvancedServiceSiteHandling()) {
|
||||
if (plugin.getServiceSiteHandler() != null) {
|
||||
@@ -87,16 +83,7 @@ public class VotiferEvent implements Listener {
|
||||
}
|
||||
|
||||
String voteSiteNameStr = plugin.getVoteSiteManager().getVoteSiteName(false, voteSite, matchSite);
|
||||
|
||||
ArrayList<String> sites = plugin.getConfigVoteSites().getVoteSitesNames(false);
|
||||
boolean createSite = false;
|
||||
if (sites != null) {
|
||||
if (!ArrayUtils.containsIgnoreCase(sites, voteSiteNameStr)) {
|
||||
createSite = true;
|
||||
}
|
||||
} else {
|
||||
createSite = true;
|
||||
}
|
||||
boolean createSite = !plugin.getVoteSiteManager().hasVoteSite(voteSiteNameStr);
|
||||
|
||||
String serviceSite = voteSite;
|
||||
|
||||
@@ -111,17 +98,15 @@ public class VotiferEvent implements Listener {
|
||||
|
||||
if (plugin.getTimeChecker().isActiveProcessing()
|
||||
&& plugin.getConfigFile().isQueueVotesDuringTimeChange()) {
|
||||
// time change in progress
|
||||
plugin.debug("Adding vote to time queue " + voteUsername + "/" + voteSite);
|
||||
plugin.getTimeQueueHandler().addVote(voteUsername, voteSite);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
String voteSiteName = plugin.getVoteSiteManager().getVoteSiteName(true, serviceSite, matchSite);
|
||||
|
||||
PlayerVoteEvent voteEvent = new PlayerVoteEvent(plugin.getVoteSiteManager().getVoteSite(voteSiteName, true),
|
||||
voteUsername, voteSite, true);
|
||||
PlayerVoteEvent voteEvent = new PlayerVoteEvent(
|
||||
plugin.getVoteSiteManager().getVoteSite(voteSiteName, true), voteUsername, voteSite, true);
|
||||
plugin.getServer().getPluginManager().callEvent(voteEvent);
|
||||
|
||||
if (voteEvent.isCancelled()) {
|
||||
@@ -132,9 +117,7 @@ public class VotiferEvent implements Listener {
|
||||
plugin.getLogger().severe("Error occured during vote processing");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+3
@@ -29,6 +29,9 @@ public class MVdWPlaceholders {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads MVdW placeholders if the MVdWPlaceholderAPI plugin is enabled.
|
||||
*/
|
||||
public void loadMVdWPlaceholders() {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("MVdWPlaceholderAPI")) {
|
||||
// The plugin is enabled
|
||||
|
||||
+61
-11
@@ -57,11 +57,18 @@ public class PlaceHolders {
|
||||
@Getter
|
||||
private PlaceholderCacheLevel cacheLevel;
|
||||
|
||||
/**
|
||||
* Constructor for PlaceHolders.
|
||||
* @param plugin the voting plugin instance
|
||||
*/
|
||||
public PlaceHolders(VotingPluginMain plugin) {
|
||||
this.plugin = plugin;
|
||||
cacheLevel = plugin.getConfigFile().getPlaceholderCacheLevel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for placeholders that need caching.
|
||||
*/
|
||||
public void checkNonCachedPlaceholders() {
|
||||
while (!placeholdersToSetCacheOn.isEmpty()) {
|
||||
String toCache = placeholdersToSetCacheOn.poll().toLowerCase();
|
||||
@@ -89,10 +96,23 @@ public class PlaceHolders {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get placeholder value for offline player.
|
||||
* @param p the offline player
|
||||
* @param identifier the placeholder identifier
|
||||
* @return the placeholder value
|
||||
*/
|
||||
public String getPlaceHolder(OfflinePlayer p, String identifier) {
|
||||
return getPlaceHolder(p, identifier, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get placeholder value for offline player with javascript support.
|
||||
* @param p the offline player
|
||||
* @param identifier1 the placeholder identifier
|
||||
* @param javascript enable javascript processing
|
||||
* @return the placeholder value
|
||||
*/
|
||||
public String getPlaceHolder(OfflinePlayer p, String identifier1, boolean javascript) {
|
||||
boolean forceProcess = false;
|
||||
boolean useCache = true;
|
||||
@@ -128,6 +148,12 @@ public class PlaceHolders {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get placeholder value for online player.
|
||||
* @param p the player
|
||||
* @param identifier the placeholder identifier
|
||||
* @return the placeholder value
|
||||
*/
|
||||
public String getPlaceHolder(Player p, String identifier) {
|
||||
if (plugin.getConfigFile().isUseJavascriptPlaceholders()) {
|
||||
identifier = PlaceholderUtils.replaceJavascript(p, identifier);
|
||||
@@ -135,6 +161,15 @@ public class PlaceHolders {
|
||||
return getPlaceHolder(p, identifier, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get placeholder value with options.
|
||||
* @param p the offline player
|
||||
* @param identifier the placeholder identifier
|
||||
* @param javascript enable javascript processing
|
||||
* @param forceProcess force processing of placeholder
|
||||
* @param useCache use cached value if available
|
||||
* @return the placeholder value
|
||||
*/
|
||||
public String getPlaceholderValue(OfflinePlayer p, String identifier, boolean javascript, boolean forceProcess,
|
||||
boolean useCache) {
|
||||
if (plugin.getConfigFile().isUseJavascriptPlaceholders() && javascript && p != null) {
|
||||
@@ -264,6 +299,9 @@ public class PlaceHolders {
|
||||
return "Not a valid placeholder";
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all placeholders.
|
||||
*/
|
||||
public void load() {
|
||||
placeholders.clear();
|
||||
nonPlayerPlaceholders.clear();
|
||||
@@ -1167,17 +1205,11 @@ public class PlaceHolders {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onBungeeVotePartyUpdate() {
|
||||
/*
|
||||
* for (NonPlayerPlaceHolder<VotingPluginUser> placeholder :
|
||||
* nonPlayerPlaceholders) { if (placeholder.isUsesCache()) { if
|
||||
* (placeholder.getIdentifier().startsWith("BungeeVoteParty")) { for (String
|
||||
* ident : placeholder.getCache().keySet()) { placeholder.getCache().put(ident,
|
||||
* placeholder.placeholderRequest(ident)); } } } }
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle player logout.
|
||||
* @param user the voting plugin user
|
||||
*/
|
||||
public void onLogout(VotingPluginUser user) {
|
||||
if (plugin.getPlaceholders().getCacheLevel().onlineOnly()) {
|
||||
for (PlaceHolder<VotingPluginUser> placeholder : placeholders) {
|
||||
@@ -1188,6 +1220,9 @@ public class PlaceHolders {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all placeholders.
|
||||
*/
|
||||
public void onUpdate() {
|
||||
checkNonCachedPlaceholders();
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
@@ -1204,6 +1239,11 @@ public class PlaceHolders {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Update placeholders for specific user.
|
||||
* @param user the voting plugin user
|
||||
* @param login whether this is a login update
|
||||
*/
|
||||
public void onUpdate(VotingPluginUser user, boolean login) {
|
||||
for (PlaceHolder<VotingPluginUser> placeholder : placeholders) {
|
||||
if (placeholder.isUsesCache()) {
|
||||
@@ -1233,6 +1273,9 @@ public class PlaceHolders {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle vote party update.
|
||||
*/
|
||||
public void onVotePartyUpdate() {
|
||||
/*
|
||||
* for (NonPlayerPlaceHolder<VotingPluginUser> placeholder :
|
||||
@@ -1243,6 +1286,9 @@ public class PlaceHolders {
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload placeholders.
|
||||
*/
|
||||
public void reload() {
|
||||
cacheLevel = plugin.getConfigFile().getPlaceholderCacheLevel();
|
||||
onUpdate();
|
||||
@@ -1253,6 +1299,10 @@ public class PlaceHolders {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule placeholder check for user.
|
||||
* @param user the voting plugin user
|
||||
*/
|
||||
public void schedulePlaceholderCheck(VotingPluginUser user) {
|
||||
plugin.getTimer().execute(new Runnable() {
|
||||
|
||||
|
||||
+30
-1
@@ -1,8 +1,25 @@
|
||||
package com.bencodez.votingplugin.placeholders;
|
||||
|
||||
/**
|
||||
* Enum for placeholder cache levels.
|
||||
*/
|
||||
public enum PlaceholderCacheLevel {
|
||||
NONE, SPECIFIC, AUTO, AUTOALL, SPECIFICALL;
|
||||
/** No caching. */
|
||||
NONE,
|
||||
/** Specific placeholders cached. */
|
||||
SPECIFIC,
|
||||
/** Auto-cache for online players. */
|
||||
AUTO,
|
||||
/** Auto-cache for all players. */
|
||||
AUTOALL,
|
||||
/** Specific cache for all players. */
|
||||
SPECIFICALL;
|
||||
|
||||
/**
|
||||
* Get cache level from string.
|
||||
* @param str the string to parse
|
||||
* @return the cache level
|
||||
*/
|
||||
public static PlaceholderCacheLevel getCache(String str) {
|
||||
for (PlaceholderCacheLevel v : PlaceholderCacheLevel.values()) {
|
||||
if (v.toString().equalsIgnoreCase(str)) {
|
||||
@@ -12,6 +29,10 @@ public enum PlaceholderCacheLevel {
|
||||
return AUTO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if cache is for online players only.
|
||||
* @return true if online only
|
||||
*/
|
||||
public boolean onlineOnly() {
|
||||
if ((this == AUTOALL) || (this == SPECIFICALL)) {
|
||||
return false;
|
||||
@@ -19,6 +40,10 @@ public enum PlaceholderCacheLevel {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if caching should be enabled.
|
||||
* @return true if should cache
|
||||
*/
|
||||
public boolean shouldCache() {
|
||||
switch (this) {
|
||||
case AUTO:
|
||||
@@ -36,6 +61,10 @@ public enum PlaceholderCacheLevel {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if cache should always be used.
|
||||
* @return true if cache always
|
||||
*/
|
||||
public boolean isCacheAlways() {
|
||||
if ((this == AUTOALL) || (this == SPECIFICALL)) {
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.bencodez.votingplugin.presets;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Represents display information for a preset. Display information
|
||||
* includes a name and a description used to describe the preset to
|
||||
* users. This class is used when parsing meta JSON files.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class DisplayInfo {
|
||||
|
||||
/**
|
||||
* The human‑readable name of the preset. This name will appear in
|
||||
* preset selection UIs.
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* A brief description of the preset. This description helps users
|
||||
* understand what the preset is intended for.
|
||||
*/
|
||||
private String description;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.bencodez.votingplugin.presets;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Represents a fragment defined in a preset meta JSON file. A
|
||||
* fragment contains the path to a YAML file and a path indicating
|
||||
* where the fragment should be merged into when applying the preset.
|
||||
* In the context of using only values from JSON (without YAML
|
||||
* fragments), this class is unused but included for completeness.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class Fragment {
|
||||
|
||||
/**
|
||||
* The relative path to the fragment file. This file typically
|
||||
* contains a YAML snippet defining a portion of the configuration.
|
||||
*/
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* The dot‑separated path within the configuration to merge the
|
||||
* fragment into. For example, {@code VoteSites} indicates the
|
||||
* fragment should be merged into the {@code VoteSites} section of
|
||||
* {@code VoteSites.yml}.
|
||||
*/
|
||||
private String mergeInto;
|
||||
}
|
||||
+199
@@ -0,0 +1,199 @@
|
||||
package com.bencodez.votingplugin.presets;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpClient.Redirect;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
/**
|
||||
* Utility class for loading vote site presets from GitHub.
|
||||
*/
|
||||
public class GitHubVoteSitePresetLoader {
|
||||
|
||||
private final String owner;
|
||||
private final String repository;
|
||||
private final String branch;
|
||||
private final String token;
|
||||
private final Gson gson;
|
||||
|
||||
/**
|
||||
* Shared HTTP client.
|
||||
*/
|
||||
private final HttpClient httpClient = HttpClient.newBuilder()
|
||||
.followRedirects(Redirect.NORMAL)
|
||||
.connectTimeout(Duration.ofSeconds(5))
|
||||
.build();
|
||||
|
||||
public GitHubVoteSitePresetLoader(String owner, String repository, String branch) {
|
||||
this(owner, repository, branch, null);
|
||||
}
|
||||
|
||||
public GitHubVoteSitePresetLoader(String owner, String repository, String branch, String token) {
|
||||
this.owner = Objects.requireNonNull(owner);
|
||||
this.repository = Objects.requireNonNull(repository);
|
||||
this.branch = Objects.requireNonNull(branch);
|
||||
this.token = token;
|
||||
this.gson = new Gson();
|
||||
}
|
||||
|
||||
public List<String> listPresetPaths() throws IOException, InterruptedException {
|
||||
String apiUrl = String.format(
|
||||
"https://api.github.com/repos/%s/%s/contents/presets/votesites?ref=%s",
|
||||
owner, repository, branch);
|
||||
|
||||
HttpRequest.Builder builder = HttpRequest.newBuilder()
|
||||
.uri(URI.create(apiUrl))
|
||||
.GET()
|
||||
.timeout(Duration.ofSeconds(7))
|
||||
.header("User-Agent", "VotingPlugin-PresetLoader");
|
||||
|
||||
if (token != null && !token.isEmpty()) {
|
||||
builder.header("Authorization", "token " + token);
|
||||
}
|
||||
|
||||
HttpResponse<String> response = httpClient.send(builder.build(),
|
||||
HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
|
||||
|
||||
if (response.statusCode() != 200) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
JsonElement root = JsonParser.parseString(response.body());
|
||||
if (!root.isJsonArray()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
JsonArray array = root.getAsJsonArray();
|
||||
List<String> paths = new ArrayList<>();
|
||||
|
||||
for (JsonElement element : array) {
|
||||
if (!element.isJsonObject()) continue;
|
||||
|
||||
JsonObject obj = element.getAsJsonObject();
|
||||
String type = obj.has("type") ? obj.get("type").getAsString() : null;
|
||||
String path = obj.has("path") ? obj.get("path").getAsString() : null;
|
||||
|
||||
if ("file".equals(type) && path != null && path.endsWith(".meta.json")) {
|
||||
paths.add(path);
|
||||
}
|
||||
}
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
public VoteSitePreset loadPreset(String path) throws IOException, InterruptedException {
|
||||
Objects.requireNonNull(path, "path must not be null");
|
||||
|
||||
String rawUrl = String.format(
|
||||
"https://raw.githubusercontent.com/%s/%s/%s/%s",
|
||||
owner, repository, branch, path);
|
||||
|
||||
HttpRequest.Builder builder = HttpRequest.newBuilder()
|
||||
.uri(URI.create(rawUrl))
|
||||
.GET()
|
||||
.timeout(Duration.ofSeconds(7))
|
||||
.header("User-Agent", "VotingPlugin-PresetLoader");
|
||||
|
||||
if (token != null && !token.isEmpty()) {
|
||||
builder.header("Authorization", "token " + token);
|
||||
}
|
||||
|
||||
HttpResponse<String> response = httpClient.send(builder.build(),
|
||||
HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
|
||||
|
||||
if (response.statusCode() != 200) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try (Reader reader = new InputStreamReader(
|
||||
new java.io.ByteArrayInputStream(response.body().getBytes(StandardCharsets.UTF_8)),
|
||||
StandardCharsets.UTF_8)) {
|
||||
return gson.fromJson(reader, VoteSitePreset.class);
|
||||
}
|
||||
}
|
||||
|
||||
public List<VoteSitePreset> listAllVoteSitePresets() throws IOException, InterruptedException {
|
||||
List<String> paths = listPresetPaths();
|
||||
if (paths.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<VoteSitePreset> result = new ArrayList<>();
|
||||
|
||||
for (String path : paths) {
|
||||
try {
|
||||
VoteSitePreset preset = loadPreset(path);
|
||||
if (preset != null) {
|
||||
result.add(preset);
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public VoteSitePreset findVoteSitePresetForURL(String voteURL) throws IOException, InterruptedException {
|
||||
if (voteURL == null || voteURL.trim().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String host;
|
||||
try {
|
||||
java.net.URI uri = new java.net.URI(voteURL.trim());
|
||||
host = uri.getHost();
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (host == null || host.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
host = host.toLowerCase();
|
||||
if (host.startsWith("www.")) {
|
||||
host = host.substring(4);
|
||||
}
|
||||
|
||||
List<VoteSitePreset> presets = listAllVoteSitePresets();
|
||||
|
||||
for (VoteSitePreset preset : presets) {
|
||||
if (preset == null || preset.getMatch() == null || preset.getMatch().getDomains() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (String domain : preset.getMatch().getDomains()) {
|
||||
if (domain == null || domain.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String normalizedDomain = domain.toLowerCase();
|
||||
if (normalizedDomain.startsWith("www.")) {
|
||||
normalizedDomain = normalizedDomain.substring(4);
|
||||
}
|
||||
|
||||
if (host.equals(normalizedDomain) || host.endsWith("." + normalizedDomain)) {
|
||||
return preset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.bencodez.votingplugin.presets;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Represents matching information for a preset. Match information
|
||||
* identifies which domains or keywords should match this preset. This
|
||||
* class is used for deserializing preset meta JSON files but is
|
||||
* otherwise optional when programmatically applying the preset.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class MatchInfo {
|
||||
|
||||
/**
|
||||
* Domains associated with the preset. These are used by the preset
|
||||
* generator to automatically select a preset based on a vote site
|
||||
* hostname.
|
||||
*/
|
||||
private java.util.List<String> domains;
|
||||
|
||||
/**
|
||||
* Keywords associated with the preset. These can be used to search
|
||||
* presets in user interfaces.
|
||||
*/
|
||||
private java.util.List<String> keywords;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.bencodez.votingplugin.presets;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* Represents a placeholder definition loaded from a preset meta JSON file.
|
||||
*
|
||||
* The VotingPlugin presets define a set of placeholders that may be
|
||||
* substituted when creating vote site entries. Each placeholder has a
|
||||
* type (for example, {@code string}), a human‑readable label, and a
|
||||
* default value. This class is a simple container for these fields so
|
||||
* they can be deserialized via Gson and accessed via Lombok‑generated
|
||||
* getters and setters.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class PlaceholderDef {
|
||||
/**
|
||||
* The data type of this placeholder (e.g. {@code string}). The type
|
||||
* information is primarily for user interfaces and may be ignored when
|
||||
* programmatically applying the preset.
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* A human‑readable label describing the placeholder. This is used by
|
||||
* external tools (such as the web preset generator) to prompt for
|
||||
* values.
|
||||
*/
|
||||
private String label;
|
||||
|
||||
/**
|
||||
* The default value for the placeholder. If the user does not supply a
|
||||
* value when applying the preset, this value will be used instead.
|
||||
* <p>
|
||||
* The JSON meta files use the key {@code "default"} for this value. Because
|
||||
* {@code default} is a reserved keyword in Java, we cannot name this
|
||||
* field {@code default}. Instead, we annotate this field with
|
||||
* {@link SerializedName @SerializedName("default")} so that Gson
|
||||
* will map the {@code "default"} property in the JSON to this field.
|
||||
*/
|
||||
@SerializedName("default")
|
||||
private String defaultValue;
|
||||
}
|
||||
+234
@@ -0,0 +1,234 @@
|
||||
package com.bencodez.votingplugin.presets;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
import com.bencodez.votingplugin.config.ConfigVoteSites;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
/**
|
||||
* Manager responsible for loading vote site presets defined in JSON and
|
||||
* applying them to the VotingPlugin configuration. Unlike the web preset
|
||||
* generator, this manager ignores YAML fragments and relies solely on values
|
||||
* defined in the meta JSON file.
|
||||
*/
|
||||
public class VoteSiteJsonPresetManager {
|
||||
|
||||
/**
|
||||
* The main plugin instance used to access the configuration.
|
||||
*/
|
||||
private final VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Cached reference to the vote sites configuration helper.
|
||||
*/
|
||||
private final ConfigVoteSites configVoteSites;
|
||||
|
||||
/**
|
||||
* Constructs a new manager for applying vote site presets.
|
||||
*
|
||||
* @param plugin the main plugin instance
|
||||
*/
|
||||
public VoteSiteJsonPresetManager(VotingPluginMain plugin) {
|
||||
this.plugin = Objects.requireNonNull(plugin, "plugin must not be null");
|
||||
this.configVoteSites = plugin.getConfigVoteSites();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a vote site preset from the specified resource path.
|
||||
*
|
||||
* @param resourcePath the path to the meta JSON file within the JAR
|
||||
* @return the deserialized preset
|
||||
* @throws IOException if the resource cannot be read or parsed
|
||||
*/
|
||||
public VoteSitePreset loadPreset(String resourcePath) throws IOException {
|
||||
InputStream in = plugin.getResource(resourcePath);
|
||||
if (in == null) {
|
||||
throw new IOException("Preset resource not found: " + resourcePath);
|
||||
}
|
||||
try (Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8)) {
|
||||
Gson gson = new GsonBuilder().create();
|
||||
return gson.fromJson(reader, VoteSitePreset.class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the given vote site preset to the VotingPlugin configuration.
|
||||
* Placeholder values will be populated using the defaults defined in the
|
||||
* preset and overridden by any values provided in the {@code overrides} map.
|
||||
*
|
||||
* @param preset the preset to apply
|
||||
* @param overrides a map of placeholder names to override values
|
||||
*/
|
||||
public void applyPreset(VoteSitePreset preset, Map<String, Object> overrides) {
|
||||
if (preset == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Object> values = new HashMap<String, Object>();
|
||||
|
||||
if (preset.getPlaceholders() != null) {
|
||||
for (Map.Entry<String, PlaceholderDef> entry : preset.getPlaceholders().entrySet()) {
|
||||
PlaceholderDef def = entry.getValue();
|
||||
if ((def != null) && (def.getDefaultValue() != null)) {
|
||||
values.put(entry.getKey(), def.getDefaultValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (overrides != null) {
|
||||
for (Map.Entry<String, Object> entry : overrides.entrySet()) {
|
||||
if (entry.getValue() != null) {
|
||||
values.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String siteKey = getString(values.get("siteKey")).trim();
|
||||
String displayName = getString(values.get("displayName"));
|
||||
String serviceSite = getString(values.get("serviceSite"));
|
||||
String voteURL = getString(values.get("voteURL"));
|
||||
String voteDelay = getString(values.get("voteDelay"));
|
||||
|
||||
Boolean waitUntilDelay = getBoolean(values.get("WaitUnitVoteDelay"));
|
||||
if (waitUntilDelay == null) {
|
||||
waitUntilDelay = getBoolean(values.get("waitUntilVoteDelay"));
|
||||
}
|
||||
|
||||
Boolean voteDelayDaily = getBoolean(values.get("VoteDelayDaily"));
|
||||
if (voteDelayDaily == null) {
|
||||
voteDelayDaily = getBoolean(values.get("voteDelayDaily"));
|
||||
}
|
||||
|
||||
Integer voteDelayDailyHour = getInteger(values.get("voteDelayDailyHour"));
|
||||
if (voteDelayDailyHour == null) {
|
||||
voteDelayDailyHour = getInteger(values.get("VoteDelayDailyHour"));
|
||||
}
|
||||
|
||||
if (siteKey.isEmpty()) {
|
||||
plugin.getLogger().warning("Cannot apply preset: siteKey is missing");
|
||||
return;
|
||||
}
|
||||
|
||||
configVoteSites.setEnabled(siteKey, true);
|
||||
|
||||
if (!displayName.isEmpty()) {
|
||||
configVoteSites.setDisplayName(siteKey, displayName);
|
||||
}
|
||||
|
||||
if (!serviceSite.isEmpty()) {
|
||||
configVoteSites.setServiceSite(siteKey, serviceSite);
|
||||
}
|
||||
|
||||
if (!voteURL.isEmpty()) {
|
||||
configVoteSites.setVoteURL(siteKey, voteURL);
|
||||
}
|
||||
|
||||
if (!voteDelay.isEmpty()) {
|
||||
configVoteSites.setVoteDelay(siteKey, voteDelay);
|
||||
}
|
||||
|
||||
if (waitUntilDelay != null) {
|
||||
configVoteSites.set(siteKey, "WaitUntilVoteDelay", waitUntilDelay.booleanValue());
|
||||
}
|
||||
|
||||
if (voteDelayDaily != null) {
|
||||
configVoteSites.setVoteDelayDaily(siteKey, voteDelayDaily.booleanValue());
|
||||
}
|
||||
|
||||
if (voteDelayDailyHour != null) {
|
||||
configVoteSites.setVoteDelayDailyHour(siteKey, voteDelayDailyHour.intValue());
|
||||
}
|
||||
|
||||
if (configVoteSites.getItem(siteKey) == null) {
|
||||
configVoteSites.set(siteKey, "DisplayItem.Material", "STONE");
|
||||
configVoteSites.set(siteKey, "DisplayItem.Amount", 1);
|
||||
}
|
||||
|
||||
if (configVoteSites.getData(siteKey).getConfigurationSection("Rewards") == null) {
|
||||
configVoteSites.set(siteKey, "Rewards.Messages.Player", "&aThanks for voting on %ServiceSite%!");
|
||||
}
|
||||
|
||||
configVoteSites.saveData();
|
||||
plugin.loadVoteSites();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an object to a string.
|
||||
*
|
||||
* @param value the value
|
||||
* @return the string form, or an empty string if null
|
||||
*/
|
||||
private String getString(Object value) {
|
||||
return value != null ? String.valueOf(value) : "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an object to a boolean if possible.
|
||||
*
|
||||
* @param value the value
|
||||
* @return the parsed boolean, or null if not set
|
||||
*/
|
||||
private Boolean getBoolean(Object value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (value instanceof Boolean) {
|
||||
return (Boolean) value;
|
||||
}
|
||||
|
||||
String text = String.valueOf(value).trim().toLowerCase();
|
||||
|
||||
if (text.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (text.equals("true") || text.equals("yes") || text.equals("1")) {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
if (text.equals("false") || text.equals("no") || text.equals("0")) {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an object to an integer if possible.
|
||||
*
|
||||
* @param value the value
|
||||
* @return the parsed integer, or null if not set or invalid
|
||||
*/
|
||||
private Integer getInteger(Object value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (value instanceof Number) {
|
||||
return Integer.valueOf(((Number) value).intValue());
|
||||
}
|
||||
|
||||
String text = String.valueOf(value).trim();
|
||||
|
||||
if (text.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return Integer.valueOf(Integer.parseInt(text));
|
||||
} catch (NumberFormatException e) {
|
||||
plugin.getLogger().warning("Invalid integer value: " + text);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.bencodez.votingplugin.presets;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents a vote site preset as defined in a meta JSON file.
|
||||
*
|
||||
* The meta JSON file defines metadata about the preset such as display
|
||||
* information, matching criteria, placeholder definitions and optional YAML
|
||||
* fragments. This class provides a simple POJO for deserialization via
|
||||
* Gson. Only the {@code placeholders} field is strictly necessary when
|
||||
* applying the preset programmatically; the other fields are included
|
||||
* for completeness.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class VoteSitePreset {
|
||||
|
||||
/**
|
||||
* The schema version of the preset definition. This may be used to
|
||||
* handle future format changes.
|
||||
*/
|
||||
private int schemaVersion;
|
||||
|
||||
/**
|
||||
* The unique identifier of the preset (e.g. {@code votesite:generic}).
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* Human‑friendly display information for the preset.
|
||||
*/
|
||||
private DisplayInfo display;
|
||||
|
||||
/**
|
||||
* Matching information that can be used to automatically select a
|
||||
* preset based on domain or keywords. Optional when applying
|
||||
* programmatically.
|
||||
*/
|
||||
private MatchInfo match;
|
||||
|
||||
/**
|
||||
* Definitions of placeholders used by this preset. Each entry in
|
||||
* the map corresponds to a placeholder name and defines its type,
|
||||
* label and default value.
|
||||
*/
|
||||
private Map<String, PlaceholderDef> placeholders;
|
||||
|
||||
/**
|
||||
* A list of YAML fragments referenced by this preset. When not using
|
||||
* YAML, this field is unused but retained for completeness.
|
||||
*/
|
||||
private List<Fragment> fragments;
|
||||
|
||||
/**
|
||||
* Whether the preset has been verified by the project maintainers.
|
||||
*/
|
||||
private boolean verified;
|
||||
}
|
||||
+210
@@ -0,0 +1,210 @@
|
||||
package com.bencodez.votingplugin.presets;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.bencodez.simpleapi.valuerequest.MultiValueField;
|
||||
import com.bencodez.simpleapi.valuerequest.MultiValueField.FieldType;
|
||||
import com.bencodez.simpleapi.valuerequest.MultiValueListener;
|
||||
import com.bencodez.simpleapi.valuerequest.MultiValueResult;
|
||||
import com.bencodez.simpleapi.valuerequest.StringListener;
|
||||
import com.bencodez.simpleapi.valuerequest.ValueRequest;
|
||||
import com.bencodez.votingplugin.VotingPluginMain;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Handler class that guides a player through selecting a vote site preset and
|
||||
* configuring its placeholder values using the SimpleAPI {@link ValueRequest}
|
||||
* system.
|
||||
*/
|
||||
public class VoteSitePresetSetupHandler {
|
||||
|
||||
/**
|
||||
* Main plugin instance.
|
||||
*/
|
||||
private final VotingPluginMain plugin;
|
||||
|
||||
/**
|
||||
* Loader used to fetch vote site presets.
|
||||
*/
|
||||
@Getter
|
||||
private final GitHubVoteSitePresetLoader loader;
|
||||
|
||||
/**
|
||||
* Creates a new setup handler.
|
||||
*
|
||||
* @param plugin plugin instance
|
||||
*/
|
||||
public VoteSitePresetSetupHandler(VotingPluginMain plugin) {
|
||||
this.plugin = Objects.requireNonNull(plugin, "plugin must not be null");
|
||||
this.loader = new GitHubVoteSitePresetLoader("BenCodez", "VotingPlugin-Presets", "main");
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the preset setup process.
|
||||
*
|
||||
* @param player player running setup
|
||||
*/
|
||||
public void startSetup(Player player) {
|
||||
List<VoteSitePreset> presets;
|
||||
|
||||
try {
|
||||
presets = loader.listAllVoteSitePresets();
|
||||
} catch (Exception e) {
|
||||
player.sendMessage("§cUnable to load vote site presets.");
|
||||
plugin.getLogger().warning("Failed to load vote site presets: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (presets == null || presets.isEmpty()) {
|
||||
player.sendMessage("§cNo vote site presets are available.");
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> options = new ArrayList<String>();
|
||||
for (VoteSitePreset preset : presets) {
|
||||
options.add(preset.getId());
|
||||
}
|
||||
|
||||
ValueRequest request = new ValueRequest(plugin, plugin.getDialogService());
|
||||
|
||||
request.requestString(player, null, options, false, "Select a vote site preset", new StringListener() {
|
||||
@Override
|
||||
public void onInput(Player p, String value) {
|
||||
|
||||
VoteSitePreset selected = null;
|
||||
|
||||
for (VoteSitePreset preset : presets) {
|
||||
if (preset.getId() != null && preset.getId().equalsIgnoreCase(value)) {
|
||||
selected = preset;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (selected == null) {
|
||||
p.sendMessage("§cInvalid preset: " + value);
|
||||
return;
|
||||
}
|
||||
|
||||
promptPlaceholders(p, selected);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompts placeholder values using the multi-value request system.
|
||||
*
|
||||
* @param player player
|
||||
* @param preset preset
|
||||
*/
|
||||
public void promptPlaceholders(Player player, VoteSitePreset preset) {
|
||||
|
||||
Map<String, PlaceholderDef> defs = preset.getPlaceholders();
|
||||
|
||||
if (defs == null || defs.isEmpty()) {
|
||||
new VoteSiteJsonPresetManager(plugin).applyPreset(preset, new HashMap<String, Object>());
|
||||
player.sendMessage("§aPreset applied successfully.");
|
||||
return;
|
||||
}
|
||||
|
||||
List<MultiValueField> fields = new ArrayList<MultiValueField>();
|
||||
List<String> keys = new ArrayList<String>();
|
||||
|
||||
for (Map.Entry<String, PlaceholderDef> entry : defs.entrySet()) {
|
||||
|
||||
String key = entry.getKey();
|
||||
|
||||
if (key == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// skip auto values
|
||||
if (key.equalsIgnoreCase("siteKey") || key.equalsIgnoreCase("serviceSite")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
PlaceholderDef def = entry.getValue();
|
||||
|
||||
String label = def != null && def.getLabel() != null ? def.getLabel() : key;
|
||||
String defaultValue = def != null && def.getDefaultValue() != null ? def.getDefaultValue() : "";
|
||||
|
||||
MultiValueField field = createField(key, label, defaultValue);
|
||||
|
||||
fields.add(field);
|
||||
keys.add(key);
|
||||
}
|
||||
|
||||
if (fields.isEmpty()) {
|
||||
new VoteSiteJsonPresetManager(plugin).applyPreset(preset, new HashMap<String, Object>());
|
||||
player.sendMessage("§aPreset applied successfully.");
|
||||
return;
|
||||
}
|
||||
|
||||
ValueRequest request = new ValueRequest(plugin, plugin.getDialogService());
|
||||
|
||||
request.requestMultipleValues(player, fields, new MultiValueListener() {
|
||||
|
||||
@Override
|
||||
public void onInput(Player p, MultiValueResult result) {
|
||||
|
||||
Map<String, Object> overrides = new HashMap<String, Object>();
|
||||
|
||||
for (String key : keys) {
|
||||
|
||||
if (isBooleanField(key)) {
|
||||
Boolean value = result.getBoolean(key);
|
||||
overrides.put(key, value != null ? value : Boolean.FALSE);
|
||||
} else {
|
||||
String value = result.getString(key);
|
||||
overrides.put(key, value != null ? value : "");
|
||||
}
|
||||
}
|
||||
|
||||
new VoteSiteJsonPresetManager(plugin).applyPreset(preset, overrides);
|
||||
|
||||
p.sendMessage("§aVote site configured and preset applied.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a field based on placeholder key.
|
||||
*
|
||||
* @param key key
|
||||
* @param label label
|
||||
* @param defaultValue default value
|
||||
* @return field
|
||||
*/
|
||||
private MultiValueField createField(String key, String label, String defaultValue) {
|
||||
|
||||
if (isBooleanField(key)) {
|
||||
|
||||
boolean boolValue = Boolean.parseBoolean(defaultValue);
|
||||
|
||||
return new MultiValueField(key, label + " (default: " + boolValue + ")", FieldType.BOOLEAN)
|
||||
.booleanValue(Boolean.valueOf(boolValue))
|
||||
.required(false);
|
||||
}
|
||||
|
||||
return new MultiValueField(key, label + " (default: " + defaultValue + ")", FieldType.STRING)
|
||||
.stringValue(defaultValue)
|
||||
.required(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the placeholder should be treated as a boolean.
|
||||
*
|
||||
* @param key placeholder key
|
||||
* @return true if boolean field
|
||||
*/
|
||||
private boolean isBooleanField(String key) {
|
||||
return key.equalsIgnoreCase("WaitUntilVoteDelay")
|
||||
|| key.equalsIgnoreCase("VoteDelayDaily");
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,35 @@
|
||||
package com.bencodez.votingplugin.proxy;
|
||||
|
||||
/**
|
||||
* Enumeration of available Bungee connection methods.
|
||||
*/
|
||||
public enum BungeeMethod {
|
||||
MYSQL, PLUGINMESSAGING, SOCKETS, REDIS, MQTT;
|
||||
/** MySQL database connection. */
|
||||
MYSQL,
|
||||
/** Plugin messaging channel. */
|
||||
PLUGINMESSAGING,
|
||||
/** Socket connection. */
|
||||
SOCKETS,
|
||||
/** Redis connection. */
|
||||
REDIS,
|
||||
/** MQTT message broker. */
|
||||
MQTT;
|
||||
|
||||
/**
|
||||
* Checks if this method requires a player to be online.
|
||||
*
|
||||
* @return true if player must be online
|
||||
*/
|
||||
public boolean requiresPlayerOnline() {
|
||||
return this == PLUGINMESSAGING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a BungeeMethod by name.
|
||||
*
|
||||
* @param str the method name
|
||||
* @return the matching BungeeMethod, or PLUGINMESSAGING if not found
|
||||
*/
|
||||
public static BungeeMethod getByName(String str) {
|
||||
for (BungeeMethod method : values()) {
|
||||
if (method.toString().equalsIgnoreCase(str)) {
|
||||
|
||||
@@ -5,6 +5,9 @@ import java.util.UUID;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Represents an offline bungee vote.
|
||||
*/
|
||||
public class OfflineBungeeVote {
|
||||
|
||||
@Getter
|
||||
@@ -23,6 +26,16 @@ public class OfflineBungeeVote {
|
||||
@Getter
|
||||
private UUID voteId;
|
||||
|
||||
/**
|
||||
* Constructor with UUID voteId.
|
||||
* @param voteId the vote ID
|
||||
* @param playerName the player name
|
||||
* @param uuid the player UUID
|
||||
* @param service the vote service
|
||||
* @param time the vote time
|
||||
* @param realVote whether this is a real vote
|
||||
* @param text additional text
|
||||
*/
|
||||
public OfflineBungeeVote(UUID voteId, String playerName, String uuid, String service, long time, boolean realVote,
|
||||
String text) {
|
||||
this.playerName = playerName;
|
||||
@@ -34,6 +47,16 @@ public class OfflineBungeeVote {
|
||||
this.voteId = voteId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with String voteId.
|
||||
* @param voteId the vote ID as string
|
||||
* @param playerName the player name
|
||||
* @param uuid the player UUID
|
||||
* @param service the vote service
|
||||
* @param time the vote time
|
||||
* @param realVote whether this is a real vote
|
||||
* @param text additional text
|
||||
*/
|
||||
public OfflineBungeeVote(String voteId, String playerName, String uuid, String service, long time, boolean realVote,
|
||||
String text) {
|
||||
this.playerName = playerName;
|
||||
|
||||
@@ -22,6 +22,9 @@ import com.bencodez.simpleapi.sql.mysql.MySQL;
|
||||
import com.bencodez.simpleapi.sql.mysql.config.MysqlConfig;
|
||||
import com.bencodez.simpleapi.sql.mysql.queries.Query;
|
||||
|
||||
/**
|
||||
* Proxy MySQL user table for managing voting plugin user data.
|
||||
*/
|
||||
public abstract class ProxyMysqlUserTable extends AbstractSqlTable {
|
||||
|
||||
// Keep this so existing callers relying on getName() still work
|
||||
@@ -69,10 +72,20 @@ public abstract class ProxyMysqlUserTable extends AbstractSqlTable {
|
||||
|
||||
// Keep these existing abstract methods for compatibility with your old
|
||||
// subclasses
|
||||
/**
|
||||
* Debug log for SQL exceptions.
|
||||
* @param e the SQL exception
|
||||
*/
|
||||
public abstract void debug(SQLException e);
|
||||
|
||||
// ---- Constructors ----
|
||||
|
||||
/**
|
||||
* Constructor with new MySQL connection.
|
||||
* @param tableName the table name
|
||||
* @param config the MySQL configuration
|
||||
* @param debug enable debug mode
|
||||
*/
|
||||
public ProxyMysqlUserTable(String tableName, MysqlConfig config, boolean debug) {
|
||||
super(tableName, config, debug);
|
||||
|
||||
@@ -90,6 +103,9 @@ public abstract class ProxyMysqlUserTable extends AbstractSqlTable {
|
||||
|
||||
/**
|
||||
* Use an already-connected pool (shared).
|
||||
* @param tableName the table name
|
||||
* @param existingMysql existing MySQL connection
|
||||
* @param debug enable debug mode
|
||||
*/
|
||||
public ProxyMysqlUserTable(String tableName, MySQL existingMysql, boolean debug) {
|
||||
super(tableName, existingMysql, debug);
|
||||
@@ -102,12 +118,17 @@ public abstract class ProxyMysqlUserTable extends AbstractSqlTable {
|
||||
|
||||
// ---- Backwards-compatible API ----
|
||||
|
||||
/**
|
||||
* Get table name.
|
||||
* @return the table name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep old method name and behavior.
|
||||
* @return set of UUIDs
|
||||
*/
|
||||
public Set<String> getUuids() {
|
||||
return getPrimaryKeys();
|
||||
@@ -115,24 +136,37 @@ public abstract class ProxyMysqlUserTable extends AbstractSqlTable {
|
||||
|
||||
/**
|
||||
* Keep old behavior: query uuids fresh.
|
||||
* @return list of UUIDs from database
|
||||
*/
|
||||
public ArrayList<String> getUuidsQuery() {
|
||||
return new ArrayList<>(getPrimaryKeysQuery());
|
||||
}
|
||||
|
||||
/**
|
||||
* Load data from database.
|
||||
*/
|
||||
public void loadData() {
|
||||
// old name -> new behavior
|
||||
loadBasicCaches();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear cache.
|
||||
*/
|
||||
public void clearCache() {
|
||||
clearCacheBasic();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear basic cache.
|
||||
*/
|
||||
public void clearCacheBasic() {
|
||||
clearCaches();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shutdown and close connections.
|
||||
*/
|
||||
public void shutdown() {
|
||||
close();
|
||||
}
|
||||
@@ -144,10 +178,18 @@ public abstract class ProxyMysqlUserTable extends AbstractSqlTable {
|
||||
|
||||
// ---- Required old utility methods (kept) ----
|
||||
|
||||
/**
|
||||
* Get columns from query.
|
||||
* @return list of column names
|
||||
*/
|
||||
public ArrayList<String> getColumnsQueury() {
|
||||
return new ArrayList<>(getColumnsQuery());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get rows with player names from query.
|
||||
* @return list of columns with player names
|
||||
*/
|
||||
public ArrayList<Column> getRowsNameQuery() {
|
||||
ArrayList<Column> result = new ArrayList<>();
|
||||
checkColumn("PlayerName", DataType.STRING);
|
||||
@@ -166,6 +208,10 @@ public abstract class ProxyMysqlUserTable extends AbstractSqlTable {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get player names from query.
|
||||
* @return list of player names
|
||||
*/
|
||||
public ArrayList<String> getNamesQuery() {
|
||||
ArrayList<String> names = new ArrayList<>();
|
||||
checkColumn("PlayerName", DataType.STRING);
|
||||
@@ -184,6 +230,10 @@ public abstract class ProxyMysqlUserTable extends AbstractSqlTable {
|
||||
return names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all rows from query.
|
||||
* @return list of columns with UUID data
|
||||
*/
|
||||
public ArrayList<Column> getRowsQuery() {
|
||||
ArrayList<Column> result = new ArrayList<>();
|
||||
String sqlStr = "SELECT " + qi("uuid") + " FROM " + qi(getTableName()) + ";";
|
||||
@@ -202,6 +252,10 @@ public abstract class ProxyMysqlUserTable extends AbstractSqlTable {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get UUID to name mapping from query.
|
||||
* @return map of UUID to player name
|
||||
*/
|
||||
public ConcurrentHashMap<UUID, String> getRowsUUIDNameQuery() {
|
||||
ConcurrentHashMap<UUID, String> uuidNames = new ConcurrentHashMap<>();
|
||||
|
||||
@@ -230,6 +284,11 @@ public abstract class ProxyMysqlUserTable extends AbstractSqlTable {
|
||||
return uuidNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get UUID by player name.
|
||||
* @param playerName the player name
|
||||
* @return the UUID or null if not found
|
||||
*/
|
||||
public String getUUID(String playerName) {
|
||||
checkColumn("PlayerName", DataType.STRING);
|
||||
|
||||
@@ -255,6 +314,11 @@ public abstract class ProxyMysqlUserTable extends AbstractSqlTable {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get exact match query.
|
||||
* @param column the column to match
|
||||
* @return list of matching columns
|
||||
*/
|
||||
public ArrayList<Column> getExactQuery(Column column) {
|
||||
ArrayList<Column> result = new ArrayList<>();
|
||||
|
||||
@@ -298,16 +362,32 @@ public abstract class ProxyMysqlUserTable extends AbstractSqlTable {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if column is integer type.
|
||||
* @param key the column name
|
||||
* @return true if integer column
|
||||
*/
|
||||
public boolean isIntColumn(String key) {
|
||||
return intColumns.contains(key);
|
||||
}
|
||||
|
||||
// ---- INSERT/UPDATE/WIPE (kept similar to your existing behavior) ----
|
||||
|
||||
/**
|
||||
* Insert a value.
|
||||
* @param index the UUID
|
||||
* @param column the column name
|
||||
* @param value the value to insert
|
||||
*/
|
||||
public void insert(String index, String column, DataValue value) {
|
||||
insertQuery(index, Arrays.asList(new Column(column, value)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert multiple columns.
|
||||
* @param index the UUID
|
||||
* @param cols the columns to insert
|
||||
*/
|
||||
public void insertQuery(String index, List<Column> cols) {
|
||||
for (Column c : cols) {
|
||||
checkColumn(c.getName(), c.getDataType());
|
||||
@@ -380,6 +460,11 @@ public abstract class ProxyMysqlUserTable extends AbstractSqlTable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update multiple columns.
|
||||
* @param index the UUID
|
||||
* @param cols the columns to update
|
||||
*/
|
||||
public void update(String index, List<Column> cols) {
|
||||
for (Column col : cols) {
|
||||
checkColumn(col.getName(), col.getDataType());
|
||||
@@ -439,6 +524,12 @@ public abstract class ProxyMysqlUserTable extends AbstractSqlTable {
|
||||
ps.setString(index, v == null ? null : v.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a single column value.
|
||||
* @param index the UUID
|
||||
* @param column the column name
|
||||
* @param value the value to update
|
||||
*/
|
||||
public void update(String index, String column, DataValue value) {
|
||||
checkColumn(column, value.getType());
|
||||
|
||||
@@ -471,6 +562,11 @@ public abstract class ProxyMysqlUserTable extends AbstractSqlTable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wipe all data from a column.
|
||||
* @param columnName the column name
|
||||
* @param dataType the data type
|
||||
*/
|
||||
public void wipeColumnData(String columnName, DataType dataType) {
|
||||
checkColumn(columnName, dataType);
|
||||
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package com.bencodez.votingplugin.proxy;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
@@ -279,8 +280,8 @@ public abstract class VotingPluginProxy {
|
||||
*/
|
||||
public void loadMysql(MysqlConfig mysqlConfig, MysqlConfig globalDataMysqlConfig) {
|
||||
if (mysqlConfig.getHostName().isEmpty() || mysqlConfig.getDatabase().isEmpty()) {
|
||||
logSevere("MySQL is not configured correctly. " + "Missing host/database. host="
|
||||
+ mysqlConfig.getHostName() + " db=" + mysqlConfig.getDatabase());
|
||||
logSevere("MySQL is not configured correctly. " + "Missing host/database. host=" + mysqlConfig.getHostName()
|
||||
+ " db=" + mysqlConfig.getDatabase());
|
||||
setProxyMySQL(null);
|
||||
return;
|
||||
}
|
||||
@@ -606,26 +607,50 @@ public abstract class VotingPluginProxy {
|
||||
debug(message);
|
||||
}
|
||||
|
||||
public UUID fetchUUID(String playerName) throws Exception {
|
||||
/**
|
||||
* HTTP client used for Mojang API requests.
|
||||
*/
|
||||
private final HttpClient httpClient = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(5)).build();
|
||||
|
||||
/**
|
||||
* Fetches a player's UUID from the Mojang API.
|
||||
*
|
||||
* @param playerName player name
|
||||
* @return player UUID, or {@code null} if not found
|
||||
* @throws IOException if the request fails
|
||||
* @throws InterruptedException if interrupted while waiting for the response
|
||||
*/
|
||||
public UUID fetchUUID(String playerName) throws IOException, InterruptedException {
|
||||
if (playerName == null || playerName.equalsIgnoreCase("null")) {
|
||||
return null;
|
||||
}
|
||||
URL url = new URL("https://api.mojang.com/users/profiles/minecraft/" + playerName);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.connect();
|
||||
|
||||
if (connection.getResponseCode() == 400) {
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.mojang.com/users/profiles/minecraft/" + playerName)).GET()
|
||||
.timeout(Duration.ofSeconds(5)).build();
|
||||
|
||||
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
if (response.statusCode() == 400 || response.statusCode() == 404) {
|
||||
log("There is no player with the name \"" + playerName + "\"!");
|
||||
return null;
|
||||
}
|
||||
|
||||
InputStream inputStream = connection.getInputStream();
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
if (response.statusCode() < 200 || response.statusCode() >= 300) {
|
||||
throw new IOException("Failed to fetch UUID for " + playerName + ", HTTP " + response.statusCode());
|
||||
}
|
||||
|
||||
JsonElement element = JsonParser.parseString(response.body());
|
||||
if (element == null || !element.isJsonObject()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
JsonElement element = JsonParser.parseReader(bufferedReader);
|
||||
JsonObject object = element.getAsJsonObject();
|
||||
String uuidAsString = object.get("id").getAsString();
|
||||
if (!object.has("id") || object.get("id").isJsonNull()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String uuidAsString = object.get("id").getAsString();
|
||||
return parseUUIDFromString(uuidAsString);
|
||||
}
|
||||
|
||||
@@ -700,23 +725,22 @@ public abstract class VotingPluginProxy {
|
||||
public abstract MysqlConfig getNonVotedCacheMySQLConfig();
|
||||
|
||||
public abstract MysqlConfig getVoteLoggingMySQLConfig();
|
||||
|
||||
|
||||
/**
|
||||
* Shutdown MySQL-related resources safely.
|
||||
*/
|
||||
public void shutdownMySql() {
|
||||
if (getProxyMysqlMessenger() != null) {
|
||||
getProxyMysqlMessenger().shutdown();
|
||||
setProxyMysqlMessenger(null);
|
||||
}
|
||||
if (getProxyMysqlMessenger() != null) {
|
||||
getProxyMysqlMessenger().shutdown();
|
||||
setProxyMysqlMessenger(null);
|
||||
}
|
||||
|
||||
if (getProxyMySQL() != null) {
|
||||
getProxyMySQL().shutdown();
|
||||
setProxyMySQL(null);
|
||||
}
|
||||
if (getProxyMySQL() != null) {
|
||||
getProxyMySQL().shutdown();
|
||||
setProxyMySQL(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void load(IVoteCache jsonStorage, INonVotedPlayersStorage nonVotedCacheJson) {
|
||||
uuidPlayerNameCache = getProxyMySQL().getRowsUUIDNameQuery();
|
||||
|
||||
|
||||
+1
-1
@@ -88,7 +88,7 @@ public class VotingPluginProxyCommand {
|
||||
private String getHelpMessage() {
|
||||
StringBuilder helpBuilder = new StringBuilder("&aVotingPlugin Commands:\n");
|
||||
helpBuilder.append("/votingplugin reload - Reload the plugin\n");
|
||||
helpBuilder.append("/votingplugin reloadmysql - Reload the plugin including MySQL\n");
|
||||
helpBuilder.append("/votingplugin reloadall - Reload everything\n");
|
||||
helpBuilder.append("/votingplugin vote <player> <site> - Send a vote\n");
|
||||
helpBuilder.append("/votingplugin forcetimechange <TimeType> - Force a time change\n");
|
||||
helpBuilder.append("/votingplugin status - Check connection status\n");
|
||||
|
||||
+419
@@ -5,8 +5,16 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Configuration interface for proxy server integration.
|
||||
*/
|
||||
public interface VotingPluginProxyConfig {
|
||||
|
||||
/**
|
||||
* Gets whether proxy broadcast is enabled.
|
||||
*
|
||||
* @return true if proxy broadcast is enabled
|
||||
*/
|
||||
default boolean getProxyBroadcastEnabled() {
|
||||
return false;
|
||||
}
|
||||
@@ -15,6 +23,8 @@ public interface VotingPluginProxyConfig {
|
||||
* Routing scope mode.
|
||||
*
|
||||
* Expected values: PLAYER_SERVER | ALL_SERVERS | SERVERS | ALL_EXCEPT
|
||||
*
|
||||
* @return the scope mode
|
||||
*/
|
||||
default String getProxyBroadcastScopeMode() {
|
||||
return "ALL_SERVERS";
|
||||
@@ -22,6 +32,8 @@ public interface VotingPluginProxyConfig {
|
||||
|
||||
/**
|
||||
* Optional server list used by scope modes SERVERS and ALL_EXCEPT.
|
||||
*
|
||||
* @return the list of scope servers
|
||||
*/
|
||||
default List<String> getProxyBroadcastScopeServers() {
|
||||
return Collections.emptyList();
|
||||
@@ -31,6 +43,8 @@ public interface VotingPluginProxyConfig {
|
||||
* What to do when the voting player is offline and scope is PLAYER_SERVER.
|
||||
*
|
||||
* Expected values: NONE | QUEUE | FORWARD
|
||||
*
|
||||
* @return the offline mode
|
||||
*/
|
||||
default String getProxyBroadcastOfflineMode() {
|
||||
return "QUEUE";
|
||||
@@ -41,169 +55,574 @@ public interface VotingPluginProxyConfig {
|
||||
* PLAYER_SERVER.
|
||||
*
|
||||
* Ignored when Scope.Mode is ALL_SERVERS or ALL_EXCEPT.
|
||||
*
|
||||
* @return the list of offline forward servers
|
||||
*/
|
||||
default List<String> getProxyBroadcastOfflineForwardServers() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether unjoined players are allowed.
|
||||
*
|
||||
* @return true if unjoined players are allowed
|
||||
*/
|
||||
public boolean getAllowUnJoined();
|
||||
|
||||
/**
|
||||
* Gets the Bedrock player prefix.
|
||||
*
|
||||
* @return the Bedrock player prefix
|
||||
*/
|
||||
public String getBedrockPlayerPrefix();
|
||||
|
||||
/**
|
||||
* Gets the list of blocked servers.
|
||||
*
|
||||
* @return the list of blocked servers
|
||||
*/
|
||||
public List<String> getBlockedServers();
|
||||
|
||||
/**
|
||||
* Gets the Bungee host.
|
||||
*
|
||||
* @return the Bungee host
|
||||
*/
|
||||
public String getBungeeHost();
|
||||
|
||||
/**
|
||||
* Gets whether Bungee manages totals.
|
||||
*
|
||||
* @return true if Bungee manages totals
|
||||
*/
|
||||
public boolean getBungeeManageTotals();
|
||||
|
||||
/**
|
||||
* Gets the Bungee method.
|
||||
*
|
||||
* @return the Bungee method
|
||||
*/
|
||||
public String getBungeeMethod();
|
||||
|
||||
/**
|
||||
* Gets the Bungee port.
|
||||
*
|
||||
* @return the Bungee port
|
||||
*/
|
||||
public int getBungeePort();
|
||||
|
||||
/**
|
||||
* Gets the plugin message channel.
|
||||
*
|
||||
* @return the plugin message channel
|
||||
*/
|
||||
public String getPluginMessageChannel();
|
||||
|
||||
/**
|
||||
* Gets whether plugin message encryption is enabled.
|
||||
*
|
||||
* @return true if plugin message encryption is enabled
|
||||
*/
|
||||
public boolean getPluginMessageEncryption();
|
||||
|
||||
/**
|
||||
* Gets whether debug mode is enabled.
|
||||
*
|
||||
* @return true if debug mode is enabled
|
||||
*/
|
||||
public boolean getDebug();
|
||||
|
||||
/**
|
||||
* Gets whether vote cache uses MySQL.
|
||||
*
|
||||
* @return true if vote cache uses MySQL
|
||||
*/
|
||||
public boolean getVoteCacheUseMySQL();
|
||||
|
||||
/**
|
||||
* Gets whether vote cache uses main MySQL.
|
||||
*
|
||||
* @return true if vote cache uses main MySQL
|
||||
*/
|
||||
public boolean getVoteCacheUseMainMySQL();
|
||||
|
||||
/**
|
||||
* Gets whether non-voted cache uses MySQL.
|
||||
*
|
||||
* @return true if non-voted cache uses MySQL
|
||||
*/
|
||||
public boolean getNonVotedCacheUseMySQL();
|
||||
|
||||
/**
|
||||
* Gets whether non-voted cache uses main MySQL.
|
||||
*
|
||||
* @return true if non-voted cache uses main MySQL
|
||||
*/
|
||||
public boolean getNonVotedCacheUseMainMySQL();
|
||||
|
||||
/**
|
||||
* Gets the MQTT client ID.
|
||||
*
|
||||
* @return the MQTT client ID
|
||||
*/
|
||||
public String getMqttClientID();
|
||||
|
||||
/**
|
||||
* Gets the MQTT broker URL.
|
||||
*
|
||||
* @return the MQTT broker URL
|
||||
*/
|
||||
public String getMqttBrokerURL();
|
||||
|
||||
/**
|
||||
* Gets the MQTT username.
|
||||
*
|
||||
* @return the MQTT username
|
||||
*/
|
||||
public String getMqttUsername();
|
||||
|
||||
/**
|
||||
* Gets the MQTT password.
|
||||
*
|
||||
* @return the MQTT password
|
||||
*/
|
||||
public String getMqttPassword();
|
||||
|
||||
/**
|
||||
* Gets the MQTT prefix.
|
||||
*
|
||||
* @return the MQTT prefix
|
||||
*/
|
||||
public String getMqttPrefix();
|
||||
|
||||
/**
|
||||
* Gets the fallback server.
|
||||
*
|
||||
* @return the fallback server
|
||||
*/
|
||||
public String getFallBack();
|
||||
|
||||
/**
|
||||
* Gets whether global data is enabled.
|
||||
*
|
||||
* @return true if global data is enabled
|
||||
*/
|
||||
public boolean getGlobalDataEnabled();
|
||||
|
||||
/**
|
||||
* Gets whether global data uses main MySQL.
|
||||
*
|
||||
* @return true if global data uses main MySQL
|
||||
*/
|
||||
public boolean getGlobalDataUseMainMySQL();
|
||||
|
||||
/**
|
||||
* Gets the limit for vote points.
|
||||
*
|
||||
* @return the vote points limit
|
||||
*/
|
||||
public int getLimitVotePoints();
|
||||
|
||||
/**
|
||||
* Gets the maximum amount of votes per day.
|
||||
*
|
||||
* @return the maximum votes per day
|
||||
*/
|
||||
public int getMaxAmountOfVotesPerDay();
|
||||
|
||||
/**
|
||||
* Gets the multi-proxy method.
|
||||
*
|
||||
* @return the multi-proxy method
|
||||
*/
|
||||
public String getMultiProxyMethod();
|
||||
|
||||
/**
|
||||
* Gets whether multi-proxy uses one global reward.
|
||||
*
|
||||
* @return true if multi-proxy uses one global reward
|
||||
*/
|
||||
public boolean getMultiProxyOneGlobalReward();
|
||||
|
||||
/**
|
||||
* Gets the multi-proxy Redis host.
|
||||
*
|
||||
* @return the Redis host
|
||||
*/
|
||||
public String getMultiProxyRedisHost();
|
||||
|
||||
/**
|
||||
* Gets the multi-proxy Redis password.
|
||||
*
|
||||
* @return the Redis password
|
||||
*/
|
||||
public String getMultiProxyRedisPassword();
|
||||
|
||||
/**
|
||||
* Gets the multi-proxy Redis port.
|
||||
*
|
||||
* @return the Redis port
|
||||
*/
|
||||
public int getMultiProxyRedisPort();
|
||||
|
||||
/**
|
||||
* Gets whether multi-proxy Redis uses existing connection.
|
||||
*
|
||||
* @return true if using existing connection
|
||||
*/
|
||||
public boolean getMultiProxyRedisUseExistingConnection();
|
||||
|
||||
/**
|
||||
* Gets the multi-proxy Redis username.
|
||||
*
|
||||
* @return the Redis username
|
||||
*/
|
||||
public String getMultiProxyRedisUsername();
|
||||
|
||||
/**
|
||||
* Gets the collection of multi-proxy servers.
|
||||
*
|
||||
* @return the collection of server names
|
||||
*/
|
||||
public Collection<String> getMultiProxyServers();
|
||||
|
||||
/**
|
||||
* Gets the configuration for a specific multi-proxy server.
|
||||
*
|
||||
* @param s the server name
|
||||
* @return the server configuration as a map
|
||||
*/
|
||||
public Map<String, Object> getMultiProxyServersConfiguration(String s);
|
||||
|
||||
/**
|
||||
* Gets the multi-proxy socket host.
|
||||
*
|
||||
* @return the socket host
|
||||
*/
|
||||
public String getMultiProxySocketHostHost();
|
||||
|
||||
/**
|
||||
* Gets the multi-proxy socket host port.
|
||||
*
|
||||
* @return the socket port
|
||||
*/
|
||||
public int getMultiProxySocketHostPort();
|
||||
|
||||
/**
|
||||
* Gets whether multi-proxy support is enabled.
|
||||
*
|
||||
* @return true if multi-proxy support is enabled
|
||||
*/
|
||||
public boolean getMultiProxySupport();
|
||||
|
||||
/**
|
||||
* Gets whether online mode is enabled.
|
||||
*
|
||||
* @return true if online mode is enabled
|
||||
*/
|
||||
public boolean getOnlineMode();
|
||||
|
||||
/**
|
||||
* Gets the points awarded per vote.
|
||||
*
|
||||
* @return the points per vote
|
||||
*/
|
||||
public int getPointsOnVote();
|
||||
|
||||
/**
|
||||
* Gets whether this is the primary server.
|
||||
*
|
||||
* @return true if this is the primary server
|
||||
*/
|
||||
public boolean getPrimaryServer();
|
||||
|
||||
/**
|
||||
* Gets the proxy server name.
|
||||
*
|
||||
* @return the proxy server name
|
||||
*/
|
||||
public String getProxyServerName();
|
||||
|
||||
/**
|
||||
* Gets the list of proxy servers.
|
||||
*
|
||||
* @return the list of proxy servers
|
||||
*/
|
||||
public List<String> getProxyServers();
|
||||
|
||||
/**
|
||||
* Gets the Redis host.
|
||||
*
|
||||
* @return the Redis host
|
||||
*/
|
||||
public String getRedisHost();
|
||||
|
||||
/**
|
||||
* Gets the Redis password.
|
||||
*
|
||||
* @return the Redis password
|
||||
*/
|
||||
public String getRedisPassword();
|
||||
|
||||
/**
|
||||
* Gets the Redis port.
|
||||
*
|
||||
* @return the Redis port
|
||||
*/
|
||||
public int getRedisPort();
|
||||
|
||||
/**
|
||||
* Gets the Redis database index.
|
||||
*
|
||||
* @return the Redis database index
|
||||
*/
|
||||
public int getRedisDbIndex();
|
||||
|
||||
/**
|
||||
* Gets the Redis prefix.
|
||||
*
|
||||
* @return the Redis prefix
|
||||
*/
|
||||
public String getRedisPrefix();
|
||||
|
||||
/**
|
||||
* Gets the Redis username.
|
||||
*
|
||||
* @return the Redis username
|
||||
*/
|
||||
public String getRedisUsername();
|
||||
|
||||
/**
|
||||
* Gets whether votes should be sent to all servers.
|
||||
*
|
||||
* @return true if votes should be sent to all servers
|
||||
*/
|
||||
public boolean getSendVotesToAllServers();
|
||||
|
||||
/**
|
||||
* Gets the configuration for a specific Spigot server.
|
||||
*
|
||||
* @param s the server name
|
||||
* @return the server configuration as a map
|
||||
*/
|
||||
public Map<String, Object> getSpigotServerConfiguration(String s);
|
||||
|
||||
/**
|
||||
* Gets the collection of Spigot servers.
|
||||
*
|
||||
* @return the collection of server names
|
||||
*/
|
||||
public Collection<String> getSpigotServers();
|
||||
|
||||
/**
|
||||
* Gets whether to store month totals with date.
|
||||
*
|
||||
* @return true if month totals are stored with date
|
||||
*/
|
||||
public boolean getStoreMonthTotalsWithDate();
|
||||
|
||||
/**
|
||||
* Gets whether time change fail-safe bypass is enabled.
|
||||
*
|
||||
* @return true if time change fail-safe bypass is enabled
|
||||
*/
|
||||
public boolean getTimeChangeFailSafeBypass();
|
||||
|
||||
/**
|
||||
* Gets the time hour offset.
|
||||
*
|
||||
* @return the hour offset
|
||||
*/
|
||||
public int getTimeHourOffSet();
|
||||
|
||||
/**
|
||||
* Gets the time week offset.
|
||||
*
|
||||
* @return the week offset
|
||||
*/
|
||||
public int getTimeWeekOffSet();
|
||||
|
||||
/**
|
||||
* Gets the time zone.
|
||||
*
|
||||
* @return the time zone
|
||||
*/
|
||||
public String getTimeZone();
|
||||
|
||||
/**
|
||||
* Gets whether to use month date totals as primary total.
|
||||
*
|
||||
* @return true if month date totals are used as primary total
|
||||
*/
|
||||
public boolean getUseMonthDateTotalsAsPrimaryTotal();
|
||||
|
||||
/**
|
||||
* Gets whether UUID lookup is enabled.
|
||||
*
|
||||
* @return true if UUID lookup is enabled
|
||||
*/
|
||||
public boolean getUUIDLookup();
|
||||
|
||||
/**
|
||||
* Gets the vote cache time.
|
||||
*
|
||||
* @return the vote cache time
|
||||
*/
|
||||
public int getVoteCacheTime();
|
||||
|
||||
/**
|
||||
* Gets the vote party broadcast message.
|
||||
*
|
||||
* @return the vote party broadcast message
|
||||
*/
|
||||
public String getVotePartyBroadcast();
|
||||
|
||||
/**
|
||||
* Gets the list of vote party Bungee commands.
|
||||
*
|
||||
* @return the list of commands
|
||||
*/
|
||||
public List<String> getVotePartyBungeeCommands();
|
||||
|
||||
/**
|
||||
* Gets whether vote party is enabled.
|
||||
*
|
||||
* @return true if vote party is enabled
|
||||
*/
|
||||
public boolean getVotePartyEnabled();
|
||||
|
||||
/**
|
||||
* Gets the vote party increase votes required.
|
||||
*
|
||||
* @return the increase in votes required
|
||||
*/
|
||||
public int getVotePartyIncreaseVotesRequired();
|
||||
|
||||
/**
|
||||
* Gets whether to send vote party to all servers.
|
||||
*
|
||||
* @return true if vote party is sent to all servers
|
||||
*/
|
||||
public boolean getVotePartySendToAllServers();
|
||||
|
||||
/**
|
||||
* Gets the list of servers to send vote party to.
|
||||
*
|
||||
* @return the list of servers
|
||||
*/
|
||||
public List<String> getVotePartyServersToSend();
|
||||
|
||||
/**
|
||||
* Gets the number of votes required for vote party.
|
||||
*
|
||||
* @return the votes required
|
||||
*/
|
||||
public int getVotePartyVotesRequired();
|
||||
|
||||
/**
|
||||
* Gets whether to wait for user to be online.
|
||||
*
|
||||
* @return true if waiting for user to be online
|
||||
*/
|
||||
public boolean getWaitForUserOnline();
|
||||
|
||||
/**
|
||||
* Gets the list of whitelisted servers.
|
||||
*
|
||||
* @return the list of whitelisted servers
|
||||
*/
|
||||
public List<String> getWhiteListedServers();
|
||||
|
||||
/**
|
||||
* Gets the collection of sites with vote delay configured.
|
||||
*
|
||||
* @return the collection of site names
|
||||
*/
|
||||
public Collection<String> getWaitUntilVoteDelaySites();
|
||||
|
||||
/**
|
||||
* Gets the vote delay service for a specific site.
|
||||
*
|
||||
* @param site the site name
|
||||
* @return the service name
|
||||
*/
|
||||
public String getWaitUntilVoteDelayService(String site);
|
||||
|
||||
/**
|
||||
* Gets the vote delay in seconds for a specific site.
|
||||
*
|
||||
* @param site the site name
|
||||
* @return the vote delay in seconds
|
||||
*/
|
||||
public int getWaitUntilVoteDelayVoteDelay(String site);
|
||||
|
||||
/**
|
||||
* Gets the minimum vote delay for a specific site.
|
||||
*
|
||||
* @param site the site name
|
||||
* @return the minimum vote delay
|
||||
*/
|
||||
public int getWaitUntilVoteDelayVoteDelayMin(String site);
|
||||
|
||||
/**
|
||||
* Gets the hourly vote delay for a specific site.
|
||||
*
|
||||
* @param site the site name
|
||||
* @return the hourly vote delay
|
||||
*/
|
||||
public int getWaitUntilVoteDelayVoteDelayHour(String site);
|
||||
|
||||
/**
|
||||
* Gets whether the vote delay is daily for a specific site.
|
||||
*
|
||||
* @param site the site name
|
||||
* @return true if the delay is daily
|
||||
*/
|
||||
public boolean getWaitUntilVoteDelayVoteDelayDaily(String site);
|
||||
|
||||
/**
|
||||
* Loads the configuration.
|
||||
*/
|
||||
public void load();
|
||||
|
||||
/**
|
||||
* Saves the configuration.
|
||||
*/
|
||||
public void save();
|
||||
|
||||
/**
|
||||
* Gets whether vote logging is enabled.
|
||||
*
|
||||
* @return true if vote logging is enabled
|
||||
*/
|
||||
public boolean getVoteLoggingEnabled();
|
||||
|
||||
/**
|
||||
* Gets the number of days to keep vote logs.
|
||||
*
|
||||
* @return the purge days
|
||||
*/
|
||||
public int getVoteLoggingPurgeDays();
|
||||
|
||||
/**
|
||||
* Gets whether vote logging uses main MySQL.
|
||||
*
|
||||
* @return true if vote logging uses main MySQL
|
||||
*/
|
||||
public boolean getVoteLoggingUseMainMySQL();
|
||||
|
||||
/**
|
||||
* Gets whether a database is configured.
|
||||
*
|
||||
* @return true if a database is configured
|
||||
*/
|
||||
public boolean hasDatabaseConfigured();
|
||||
|
||||
/**
|
||||
* Gets the multi-proxy Redis database index.
|
||||
*
|
||||
* @return the database index
|
||||
*/
|
||||
public int getMultiProxyRedisDbIndex();
|
||||
|
||||
}
|
||||
+15
-1
@@ -2,9 +2,23 @@ package com.bencodez.votingplugin.proxy.broadcast;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Enum for offline broadcast modes.
|
||||
*/
|
||||
public enum OfflineMode {
|
||||
NONE, QUEUE, FORWARD;
|
||||
/** No offline handling. */
|
||||
NONE,
|
||||
/** Queue votes for offline players. */
|
||||
QUEUE,
|
||||
/** Forward to other servers. */
|
||||
FORWARD;
|
||||
|
||||
/**
|
||||
* Parse offline mode from string.
|
||||
* @param value the string to parse
|
||||
* @param def the default value
|
||||
* @return the offline mode
|
||||
*/
|
||||
public static OfflineMode parse(String value, OfflineMode def) {
|
||||
if (value == null)
|
||||
return def;
|
||||
|
||||
+11
@@ -25,6 +25,13 @@ public final class ProxyBroadcastDecider {
|
||||
private final Predicate<String> isServerValid;
|
||||
private final Predicate<String> isBlockedServer;
|
||||
|
||||
/**
|
||||
* Constructor for ProxyBroadcastDecider.
|
||||
* @param config configuration supplier
|
||||
* @param allServers all servers supplier
|
||||
* @param isServerValid server validation predicate
|
||||
* @param isBlockedServer blocked server predicate
|
||||
*/
|
||||
public ProxyBroadcastDecider(Supplier<VotingPluginProxyConfig> config,
|
||||
Supplier<Set<String>> allServers,
|
||||
Predicate<String> isServerValid,
|
||||
@@ -40,6 +47,7 @@ public final class ProxyBroadcastDecider {
|
||||
*
|
||||
* @param playerOnline whether the voting player is currently online
|
||||
* @param currentPlayerServer the server the player is on (only used when playerOnline=true)
|
||||
* @return set of target servers
|
||||
*/
|
||||
public Set<String> resolveTargets(boolean playerOnline, String currentPlayerServer) {
|
||||
VotingPluginProxyConfig cfg = config.get();
|
||||
@@ -89,6 +97,9 @@ public final class ProxyBroadcastDecider {
|
||||
|
||||
/**
|
||||
* Convenience check for "should this specific server broadcast?"
|
||||
* @param server the server name
|
||||
* @param targets the target servers
|
||||
* @return true if should broadcast
|
||||
*/
|
||||
public boolean shouldBroadcast(String server, Set<String> targets) {
|
||||
return targets != null && server != null && targets.contains(server);
|
||||
|
||||
@@ -26,6 +26,13 @@ public enum ScopeMode {
|
||||
*/
|
||||
ALL_EXCEPT;
|
||||
|
||||
/**
|
||||
* Parses a string value to a ScopeMode with a default fallback.
|
||||
*
|
||||
* @param value the string value to parse
|
||||
* @param def the default value if parsing fails
|
||||
* @return the parsed ScopeMode or the default
|
||||
*/
|
||||
public static ScopeMode parse(String value, ScopeMode def) {
|
||||
if (value == null) {
|
||||
return def;
|
||||
@@ -51,6 +58,12 @@ public enum ScopeMode {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a string value to a ScopeMode with ALL_SERVERS as default.
|
||||
*
|
||||
* @param value the string value to parse
|
||||
* @return the parsed ScopeMode or ALL_SERVERS
|
||||
*/
|
||||
public static ScopeMode parse(String value) {
|
||||
return parse(value, ALL_SERVERS);
|
||||
}
|
||||
|
||||
Loaded 100 of 186 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user