Add /maxrankup. Closes #2
This commit is contained in:
+1
-1
@@ -5,7 +5,7 @@ plugins {
|
||||
}
|
||||
|
||||
group 'sh.okx'
|
||||
version '3.6-beta'
|
||||
version '3.6-beta.1'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import sh.okx.rankup.commands.InfoCommand;
|
||||
import sh.okx.rankup.commands.MaxRankupCommand;
|
||||
import sh.okx.rankup.commands.PrestigeCommand;
|
||||
import sh.okx.rankup.commands.PrestigesCommand;
|
||||
import sh.okx.rankup.commands.RanksCommand;
|
||||
@@ -126,6 +127,9 @@ public class Rankup extends JavaPlugin {
|
||||
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("rankup3").setExecutor(new InfoCommand(this, notifier));
|
||||
@@ -168,7 +172,8 @@ public class Rankup extends JavaPlugin {
|
||||
if (config.getInt("version") < 5) {
|
||||
getLogger().severe("You are using an outdated config!");
|
||||
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("If that does not work, restart your server.");
|
||||
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) {
|
||||
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 {
|
||||
getLogger().severe("Failed to load Rankup");
|
||||
}
|
||||
@@ -278,7 +284,7 @@ public class Rankup extends JavaPlugin {
|
||||
String name = "locale/" + locale + ".yml";
|
||||
File file = new File(getDataFolder(), name);
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -66,16 +66,17 @@ public class Gui implements InventoryHolder {
|
||||
ConfigurationSection section = plugin.getConfig().getConfigurationSection("gui").getConfigurationSection(name);
|
||||
|
||||
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;
|
||||
if (ItemUtil.isServerFlattened()) {
|
||||
Material material = Material.valueOf(materialName);
|
||||
item = new ItemStack(material);
|
||||
} else {
|
||||
// handle default material correctly on older vesions
|
||||
if (materialName.equals("BLACK_STAINED_GLASS_PANE")) {
|
||||
materialName = "STAINED_GLASS_PANE:15";
|
||||
}
|
||||
|
||||
String[] parts = materialName.split(":");
|
||||
Material material = Material.valueOf(parts[0]);
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public class UpdateNotifier {
|
||||
@Override
|
||||
public void onFailure() {
|
||||
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
|
||||
* the version, so future checks will run instantly.
|
||||
*
|
||||
* @return true if the version checker already knows the latest version, false otherwise
|
||||
*/
|
||||
public boolean hasChecked() {
|
||||
@@ -38,21 +39,19 @@ public class VersionChecker {
|
||||
} else {
|
||||
callback.onOutdatedVersion(currentVersion, latestVersion);
|
||||
}
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin,
|
||||
() -> checkVersionSync(new SyncVersionCheckerCallback(plugin, callback)));
|
||||
}
|
||||
}
|
||||
|
||||
private void checkVersionSync(VersionCheckerCallback callback) {
|
||||
if (currentVersion.contains("alpha")
|
||||
} else if (currentVersion.contains("alpha")
|
||||
|| currentVersion.contains("beta")
|
||||
|| currentVersion.contains("rc")) {
|
||||
checked = true;
|
||||
callback.onPreReleaseVersion(currentVersion);
|
||||
return;
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin,
|
||||
// () -> checkVersionSync(new SyncVersionCheckerCallback(plugin, callback)));
|
||||
() -> checkVersionSync(callback));
|
||||
}
|
||||
}
|
||||
|
||||
private void checkVersionSync(VersionCheckerCallback callback) {
|
||||
try {
|
||||
latestVersion = getLatestVersion();
|
||||
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.
|
||||
*
|
||||
* @param version the current version of the plugin
|
||||
*/
|
||||
void onPreReleaseVersion(String version);
|
||||
@@ -106,9 +106,11 @@ public class VersionChecker {
|
||||
|
||||
/**
|
||||
* 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 VersionCheckerCallback callback;
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ prestiges: true
|
||||
# if you do not want this command to autocomplete, make sure
|
||||
# you negate the permission rankup.prestige with your permissions plugin.
|
||||
# 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
|
||||
|
||||
# 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.
|
||||
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:
|
||||
rows: 1
|
||||
rankup:
|
||||
@@ -82,14 +96,14 @@ placeholders:
|
||||
not-in-ladder: "None"
|
||||
# used in the current_prestige placeholders when a player hasn't prestiged yet
|
||||
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"
|
||||
|
||||
# what to shorten money by.
|
||||
# ie 1000 -> 1k
|
||||
# set to an empty list to disable
|
||||
# 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:
|
||||
- 'k'
|
||||
- 'M'
|
||||
|
||||
@@ -24,6 +24,9 @@ commands:
|
||||
prestiges:
|
||||
permission: rankup.prestiges
|
||||
description: List all the prestiges.
|
||||
maxrankup:
|
||||
permission: rankup.maxrankup
|
||||
description: Rankup as much as possible.
|
||||
permissions:
|
||||
rankup.*:
|
||||
children:
|
||||
@@ -34,6 +37,7 @@ permissions:
|
||||
rankup.prestige: true
|
||||
rankup.prestiges: true
|
||||
rankup.auto: true
|
||||
rankup.maxrankup: true
|
||||
rankup.admin:
|
||||
children:
|
||||
# if a player can see if the plugin needs updating when they run /pru
|
||||
@@ -42,7 +46,7 @@ permissions:
|
||||
rankup.reload: true
|
||||
# if a player can force rankup or prestige someone
|
||||
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
|
||||
default: op
|
||||
rankup.info:
|
||||
@@ -56,4 +60,6 @@ permissions:
|
||||
rankup.prestiges:
|
||||
default: true
|
||||
rankup.auto:
|
||||
default: true
|
||||
rankup.maxrankup:
|
||||
default: true
|
||||
Reference in New Issue
Block a user