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
+9 -3
View File
@@ -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;
}
}
+5 -4
View File
@@ -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;