Add /maxrankup. Closes #2

This commit is contained in:
okx-code
2019-12-29 13:39:58 +00:00
parent 946a13731d
commit 52b73969fd
8 changed files with 97 additions and 23 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ plugins {
} }
group 'sh.okx' group 'sh.okx'
version '3.6-beta' version '3.6-beta.1'
repositories { repositories {
mavenCentral() mavenCentral()
+9 -3
View File
@@ -22,6 +22,7 @@ import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import sh.okx.rankup.commands.InfoCommand; import sh.okx.rankup.commands.InfoCommand;
import sh.okx.rankup.commands.MaxRankupCommand;
import sh.okx.rankup.commands.PrestigeCommand; import sh.okx.rankup.commands.PrestigeCommand;
import sh.okx.rankup.commands.PrestigesCommand; import sh.okx.rankup.commands.PrestigesCommand;
import sh.okx.rankup.commands.RanksCommand; import sh.okx.rankup.commands.RanksCommand;
@@ -126,6 +127,9 @@ public class Rankup extends JavaPlugin {
getCommand("prestiges").setExecutor(new PrestigesCommand(this)); getCommand("prestiges").setExecutor(new PrestigesCommand(this));
} }
} }
if (config.getBoolean("max-rankup.enabled")) {
getCommand("maxrankup").setExecutor(new MaxRankupCommand(this));
}
getCommand("rankup").setExecutor(new RankupCommand(this)); getCommand("rankup").setExecutor(new RankupCommand(this));
getCommand("rankup3").setExecutor(new InfoCommand(this, notifier)); getCommand("rankup3").setExecutor(new InfoCommand(this, notifier));
@@ -168,7 +172,8 @@ public class Rankup extends JavaPlugin {
if (config.getInt("version") < 5) { if (config.getInt("version") < 5) {
getLogger().severe("You are using an outdated config!"); getLogger().severe("You are using an outdated config!");
getLogger().severe("This means that some things might not work!"); getLogger().severe("This means that some things might not work!");
getLogger().severe("To update, please rename ALL your config files (or the folder they are in),"); getLogger()
.severe("To update, please rename ALL your config files (or the folder they are in),");
getLogger().severe("and run /rankup3 reload to generate a new config file."); getLogger().severe("and run /rankup3 reload to generate a new config file.");
getLogger().severe("If that does not work, restart your server."); getLogger().severe("If that does not work, restart your server.");
getLogger().severe("You may then copy in your config values from the old config."); getLogger().severe("You may then copy in your config values from the old config.");
@@ -193,7 +198,8 @@ public class Rankup extends JavaPlugin {
} }
if (sender instanceof Player) { if (sender instanceof Player) {
sender.sendMessage(ChatColor.RED + "Could not load Rankup, check console for more information."); sender.sendMessage(
ChatColor.RED + "Could not load Rankup, check console for more information.");
} else { } else {
getLogger().severe("Failed to load Rankup"); getLogger().severe("Failed to load Rankup");
} }
@@ -278,7 +284,7 @@ public class Rankup extends JavaPlugin {
String name = "locale/" + locale + ".yml"; String name = "locale/" + locale + ".yml";
File file = new File(getDataFolder(), name); File file = new File(getDataFolder(), name);
if (!file.exists()) { if (!file.exists()) {
saveResource("locale/" + locale + ".yml", false); saveResource(name, false);
} }
} }
@@ -0,0 +1,45 @@
package sh.okx.rankup.commands;
import lombok.RequiredArgsConstructor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import sh.okx.rankup.Rankup;
import sh.okx.rankup.RankupHelper;
import sh.okx.rankup.ranks.Rank;
@RequiredArgsConstructor
public class MaxRankupCommand implements CommandExecutor {
private final Rankup plugin;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
return false;
}
RankupHelper helper = plugin.getHelper();
Player player = (Player) sender;
if (!helper.checkRankup(player)) {
return true;
}
do {
Rank rank = plugin.getRankups().getByPlayer(player);
rank.applyRequirements(player);
helper.doRankup(player, rank);
// if the individual-messages setting is disabled, only send the "well done you ranked up"
// messages if they can't rank up any more.
if (plugin.getConfig().getBoolean("max-rankup.individual-messages")
|| !helper.checkRankup(player, false)) {
helper.sendRankupMessages(player, rank);
}
} while (helper.checkRankup(player, false));
return true;
}
}
+5 -4
View File
@@ -66,16 +66,17 @@ public class Gui implements InventoryHolder {
ConfigurationSection section = plugin.getConfig().getConfigurationSection("gui").getConfigurationSection(name); ConfigurationSection section = plugin.getConfig().getConfigurationSection("gui").getConfigurationSection(name);
String materialName = section.getString("material").toUpperCase(); String materialName = section.getString("material").toUpperCase();
// handle default material correctly on older versions
if (!ItemUtil.isServerFlattened() && materialName.equals("BLACK_STAINED_GLASS_PANE")) {
materialName = "STAINED_GLASS_PANE:15";
}
ItemStack item; ItemStack item;
if (ItemUtil.isServerFlattened()) { if (ItemUtil.isServerFlattened()) {
Material material = Material.valueOf(materialName); Material material = Material.valueOf(materialName);
item = new ItemStack(material); item = new ItemStack(material);
} else { } else {
// handle default material correctly on older vesions
if (materialName.equals("BLACK_STAINED_GLASS_PANE")) {
materialName = "STAINED_GLASS_PANE:15";
}
String[] parts = materialName.split(":"); String[] parts = materialName.split(":");
Material material = Material.valueOf(parts[0]); Material material = Material.valueOf(parts[0]);
@@ -40,7 +40,7 @@ public class UpdateNotifier {
@Override @Override
public void onFailure() { public void onFailure() {
if (!join) { if (!join) {
send(sender, join, ChatColor.RED + "Error while checking version."); send(sender, false, ChatColor.RED + "Error while checking version.");
} }
} }
}); });
@@ -25,6 +25,7 @@ public class VersionChecker {
/** /**
* Checks if the version checker has already made an asynchronous call to the web server to check * Checks if the version checker has already made an asynchronous call to the web server to check
* the version, so future checks will run instantly. * the version, so future checks will run instantly.
*
* @return true if the version checker already knows the latest version, false otherwise * @return true if the version checker already knows the latest version, false otherwise
*/ */
public boolean hasChecked() { public boolean hasChecked() {
@@ -38,21 +39,19 @@ public class VersionChecker {
} else { } else {
callback.onOutdatedVersion(currentVersion, latestVersion); callback.onOutdatedVersion(currentVersion, latestVersion);
} }
} else { } else if (currentVersion.contains("alpha")
Bukkit.getScheduler().runTaskAsynchronously(plugin,
() -> checkVersionSync(new SyncVersionCheckerCallback(plugin, callback)));
}
}
private void checkVersionSync(VersionCheckerCallback callback) {
if (currentVersion.contains("alpha")
|| currentVersion.contains("beta") || currentVersion.contains("beta")
|| currentVersion.contains("rc")) { || currentVersion.contains("rc")) {
checked = true; checked = true;
callback.onPreReleaseVersion(currentVersion); callback.onPreReleaseVersion(currentVersion);
return; } else {
Bukkit.getScheduler().runTaskAsynchronously(plugin,
// () -> checkVersionSync(new SyncVersionCheckerCallback(plugin, callback)));
() -> checkVersionSync(callback));
} }
}
private void checkVersionSync(VersionCheckerCallback callback) {
try { try {
latestVersion = getLatestVersion(); latestVersion = getLatestVersion();
checked = true; checked = true;
@@ -94,6 +93,7 @@ public class VersionChecker {
/** /**
* Called when the plugin is on a pre-release version and is exempt to the usual update system. * Called when the plugin is on a pre-release version and is exempt to the usual update system.
*
* @param version the current version of the plugin * @param version the current version of the plugin
*/ */
void onPreReleaseVersion(String version); void onPreReleaseVersion(String version);
@@ -106,9 +106,11 @@ public class VersionChecker {
/** /**
* An implementation of {@link VersionCheckerCallback} that is called asynchronously, and then * An implementation of {@link VersionCheckerCallback} that is called asynchronously, and then
* forwards the calls an underlying VersionCheckerCallback synchronously on the main Bukkit thread. * forwards the calls an underlying VersionCheckerCallback synchronously on the main Bukkit
* thread.
*/ */
class SyncVersionCheckerCallback implements VersionCheckerCallback { static class SyncVersionCheckerCallback implements VersionCheckerCallback {
private final Plugin plugin; private final Plugin plugin;
private final VersionCheckerCallback callback; private final VersionCheckerCallback callback;
+16 -2
View File
@@ -27,6 +27,7 @@ prestiges: true
# if you do not want this command to autocomplete, make sure # if you do not want this command to autocomplete, make sure
# you negate the permission rankup.prestige with your permissions plugin. # you negate the permission rankup.prestige with your permissions plugin.
# if enabled, a prestiges.yml file will be generated with some example prestiges # if enabled, a prestiges.yml file will be generated with some example prestiges
# You must restart your server when you change this for it to work!
prestige: false prestige: false
# if true, players with the permission rankup.notify will receive notifications when they join # if true, players with the permission rankup.notify will receive notifications when they join
@@ -41,6 +42,19 @@ confirmation-type: 'gui'
# set to 0 to disable. # set to 0 to disable.
cooldown: 1 cooldown: 1
# if enabled, players can run /maxrankup to rankup as many times as possible,
# before they fail the requirements for the next rank.
# the permission rankup.maxrankup is used for this command, but it is usually given by default.
# note that /maxrankup, if enabled, has no confirmation.
max-rankup:
# You must restart your server if you enable or disable /maxrankup!
enabled: false
# whether to send a message for each rankup a player does
# if set to true, the chat may be spammed for each rankup a player goes through with /maxrankup
# if set to false, only the last rankup will be shown (if a player starts on rank A, then does
# /maxrankup and ranks up to B and then C, it will just say "player has ranked up to C")
individual-messages: true
gui: gui:
rows: 1 rows: 1
rankup: rankup:
@@ -82,14 +96,14 @@ placeholders:
not-in-ladder: "None" not-in-ladder: "None"
# used in the current_prestige placeholders when a player hasn't prestiged yet # used in the current_prestige placeholders when a player hasn't prestiged yet
no-prestige: "None" no-prestige: "None"
# used in the next_rank and next_prestige placeholders when there is no rankup/prestige # used in the next_rank and next_prestige placeholders when a player is at the highest rank or prestige
highest-rank: "None" highest-rank: "None"
# what to shorten money by. # what to shorten money by.
# ie 1000 -> 1k # ie 1000 -> 1k
# set to an empty list to disable # set to an empty list to disable
# for each entry here, it counts as increasing by a factor of 1,000 # for each entry here, it counts as increasing by a factor of 1,000
# the first represents thousands (1000, 1e3) then millions (1000000, 1e6) then billions (1000000000, 1e9) etc. # the first represents thousands (1,000) then millions (1,000,000) then billions (1,000,000,000) etc.
shorten: shorten:
- 'k' - 'k'
- 'M' - 'M'
+7 -1
View File
@@ -24,6 +24,9 @@ commands:
prestiges: prestiges:
permission: rankup.prestiges permission: rankup.prestiges
description: List all the prestiges. description: List all the prestiges.
maxrankup:
permission: rankup.maxrankup
description: Rankup as much as possible.
permissions: permissions:
rankup.*: rankup.*:
children: children:
@@ -34,6 +37,7 @@ permissions:
rankup.prestige: true rankup.prestige: true
rankup.prestiges: true rankup.prestiges: true
rankup.auto: true rankup.auto: true
rankup.maxrankup: true
rankup.admin: rankup.admin:
children: children:
# if a player can see if the plugin needs updating when they run /pru # if a player can see if the plugin needs updating when they run /pru
@@ -42,7 +46,7 @@ permissions:
rankup.reload: true rankup.reload: true
# if a player can force rankup or prestige someone # if a player can force rankup or prestige someone
rankup.force: true rankup.force: true
# if a player receives notifications to update rankup when the log in. # if a player receives notifications to update rankup when they log in.
rankup.notify: true rankup.notify: true
default: op default: op
rankup.info: rankup.info:
@@ -56,4 +60,6 @@ permissions:
rankup.prestiges: rankup.prestiges:
default: true default: true
rankup.auto: rankup.auto:
default: true
rankup.maxrankup:
default: true default: true