simplification
This commit is contained in:
+7
-3
@@ -4,7 +4,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group 'sh.okx'
|
group 'sh.okx'
|
||||||
version '3.4.2'
|
version '3.5-beta'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@@ -22,17 +22,21 @@ repositories {
|
|||||||
maven {
|
maven {
|
||||||
url 'https://raw.github.com/PyvesB/AdvancedAchievements/mvn-repo/'
|
url 'https://raw.github.com/PyvesB/AdvancedAchievements/mvn-repo/'
|
||||||
}
|
}
|
||||||
|
maven {
|
||||||
|
url 'https://jitpack.io'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||||
compile 'org.spigotmc:spigot-api:1.13.2-R0.1-SNAPSHOT'
|
compile 'org.spigotmc:spigot-api:1.13.2-R0.1-SNAPSHOT'
|
||||||
|
|
||||||
compile('net.milkbowl.vault:VaultAPI:1.6') {
|
compile('net.milkbowl.vault:VaultAPI:1.7') {
|
||||||
exclude group: 'org.bukkit'
|
exclude group: 'org.bukkit'
|
||||||
}
|
}
|
||||||
compile 'me.clip:placeholderapi:2.9.2'
|
compile 'me.clip:placeholderapi:2.9.2'
|
||||||
compile 'com.hm.achievement:advanced-achievements-api:1.1.0'
|
compile 'com.hm.achievement:advanced-achievements-api:1.1.0'
|
||||||
// if compiling this you will have to download and install mcMMO locally
|
// if compiling this you will have to download and install mcMMO locally
|
||||||
compile 'com.gmail.nossr50.mcMMO:mcMMO:2.1.17'
|
compile 'com.gmail.nossr50.mcMMO:mcMMO:2.1.+'
|
||||||
|
compile 'com.github.Ben12345rocks:VotingPlugin:5.18.2'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package sh.okx.rankup;
|
package sh.okx.rankup;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import net.milkbowl.vault.permission.Permission;
|
||||||
|
import org.apache.commons.lang3.Validate;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -53,11 +55,18 @@ public class RankList<T extends Rank> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public T getByName(String name) {
|
public T getByName(String name) {
|
||||||
|
if (name == null) {
|
||||||
|
System.out.println("n");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
for (T rank : ranks) {
|
for (T rank : ranks) {
|
||||||
if (rank.getRank().equalsIgnoreCase(name)) {
|
System.out.println(name + " <> " + rank.getNext());
|
||||||
|
if (name.equalsIgnoreCase(rank.getRank())) {
|
||||||
|
System.out.println("y");
|
||||||
return rank;
|
return rank;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
System.out.println("l");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,9 +81,25 @@ public class RankList<T extends Rank> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getLast() {
|
||||||
|
List<T> list = getOrderedList();
|
||||||
|
return list.get(list.size() - 1).getNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLast(Permission perms, Player player) {
|
||||||
|
String last = getLast();
|
||||||
|
String[] groups = perms.getPlayerGroups(null, player);
|
||||||
|
for (String group : groups) {
|
||||||
|
if (group.equalsIgnoreCase(last)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public T next(T rank) {
|
public T next(T rank) {
|
||||||
for (T nextRank : ranks) {
|
for (T nextRank : ranks) {
|
||||||
if (rank.getNext().equalsIgnoreCase(nextRank.getRank())) {
|
if (rank.getNext() != null && rank.getNext().equalsIgnoreCase(nextRank.getRank())) {
|
||||||
return nextRank;
|
return nextRank;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,11 @@ import org.bukkit.event.inventory.InventoryType;
|
|||||||
import org.bukkit.inventory.InventoryView;
|
import org.bukkit.inventory.InventoryView;
|
||||||
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.*;
|
import sh.okx.rankup.commands.InfoCommand;
|
||||||
|
import sh.okx.rankup.commands.PrestigeCommand;
|
||||||
|
import sh.okx.rankup.commands.PrestigesCommand;
|
||||||
|
import sh.okx.rankup.commands.RanksCommand;
|
||||||
|
import sh.okx.rankup.commands.RankupCommand;
|
||||||
import sh.okx.rankup.gui.Gui;
|
import sh.okx.rankup.gui.Gui;
|
||||||
import sh.okx.rankup.gui.GuiListener;
|
import sh.okx.rankup.gui.GuiListener;
|
||||||
import sh.okx.rankup.messages.EmptyMessageBuilder;
|
import sh.okx.rankup.messages.EmptyMessageBuilder;
|
||||||
@@ -29,8 +33,11 @@ import sh.okx.rankup.requirements.Requirement;
|
|||||||
import sh.okx.rankup.requirements.RequirementRegistry;
|
import sh.okx.rankup.requirements.RequirementRegistry;
|
||||||
import sh.okx.rankup.requirements.requirement.*;
|
import sh.okx.rankup.requirements.requirement.*;
|
||||||
import sh.okx.rankup.requirements.requirement.XpLevelRequirement;
|
import sh.okx.rankup.requirements.requirement.XpLevelRequirement;
|
||||||
import sh.okx.rankup.requirements.requirement.advancedachievements.*;
|
import sh.okx.rankup.requirements.requirement.advancedachievements.AdvancedAchievementsAchievementRequirement;
|
||||||
import sh.okx.rankup.requirements.requirement.mcmmo.*;
|
import sh.okx.rankup.requirements.requirement.advancedachievements.AdvancedAchievementsTotalRequirement;
|
||||||
|
import sh.okx.rankup.requirements.requirement.mcmmo.McMMOPowerLevelRequirement;
|
||||||
|
import sh.okx.rankup.requirements.requirement.mcmmo.McMMOSkillRequirement;
|
||||||
|
import sh.okx.rankup.requirements.requirement.mcmmo.McMMOSkillUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
@@ -125,7 +132,7 @@ public class Rankup extends JavaPlugin {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (config.getInt("version") < 3) {
|
if (config.getInt("version") < 4) {
|
||||||
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),");
|
||||||
@@ -183,7 +190,7 @@ public class Rankup extends JavaPlugin {
|
|||||||
|
|
||||||
private void saveLocales() {
|
private void saveLocales() {
|
||||||
saveLocale("en");
|
saveLocale("en");
|
||||||
saveLocale("pt-br");
|
saveLocale("pt-br");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveLocale(String locale) {
|
private void saveLocale(String locale) {
|
||||||
@@ -255,8 +262,7 @@ public class Rankup extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MessageBuilder getMessage(Rank rank, Message message) {
|
public MessageBuilder getMessage(Rank rank, Message message) {
|
||||||
ConfigurationSection messages = (rank instanceof Prestige ? prestiges : rankups).getConfig()
|
ConfigurationSection messages = rank.getSection();
|
||||||
.getConfigurationSection(rank.getRank());
|
|
||||||
if (messages == null || !messages.isSet(message.getName())) {
|
if (messages == null || !messages.isSet(message.getName())) {
|
||||||
messages = this.messages;
|
messages = this.messages;
|
||||||
}
|
}
|
||||||
@@ -277,7 +283,7 @@ public class Rankup extends JavaPlugin {
|
|||||||
long secondsLeft = (long) Math.ceil(timeLeft / 1000f);
|
long secondsLeft = (long) Math.ceil(timeLeft / 1000f);
|
||||||
getMessage(rank, secondsLeft > 1 ? Message.COOLDOWN_PLURAL : Message.COOLDOWN_SINGULAR)
|
getMessage(rank, secondsLeft > 1 ? Message.COOLDOWN_PLURAL : Message.COOLDOWN_SINGULAR)
|
||||||
.failIfEmpty()
|
.failIfEmpty()
|
||||||
.replaceRanks(player, rank)
|
.replaceRanks(player, rank.getRank())
|
||||||
.replaceFromTo(rank)
|
.replaceFromTo(rank)
|
||||||
.replace(Variable.SECONDS, cooldownSeconds)
|
.replace(Variable.SECONDS, cooldownSeconds)
|
||||||
.replace(Variable.SECONDS_LEFT, secondsLeft)
|
.replace(Variable.SECONDS_LEFT, secondsLeft)
|
||||||
@@ -302,23 +308,23 @@ public class Rankup extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Rank oldRank = rankups.getByPlayer(player);
|
Rank oldRank = rankups.getByPlayer(player);
|
||||||
Rank rank = rankups.next(oldRank);
|
String next = oldRank.getNext();
|
||||||
|
|
||||||
oldRank.applyRequirements(player);
|
oldRank.applyRequirements(player);
|
||||||
|
|
||||||
permissions.playerRemoveGroup(null, player, oldRank.getRank());
|
permissions.playerRemoveGroup(null, player, oldRank.getRank());
|
||||||
permissions.playerAddGroup(null, player, rank.getRank());
|
permissions.playerAddGroup(null, player, next);
|
||||||
|
|
||||||
getMessage(oldRank, Message.SUCCESS_PUBLIC)
|
getMessage(oldRank, Message.SUCCESS_PUBLIC)
|
||||||
.failIfEmpty()
|
.failIfEmpty()
|
||||||
.replaceRanks(player, oldRank, rank)
|
.replaceRanks(player, oldRank, next)
|
||||||
.broadcast();
|
.broadcast();
|
||||||
getMessage(oldRank, Message.SUCCESS_PRIVATE)
|
getMessage(oldRank, Message.SUCCESS_PRIVATE)
|
||||||
.failIfEmpty()
|
.failIfEmpty()
|
||||||
.replaceRanks(player, oldRank, rank)
|
.replaceRanks(player, oldRank, next)
|
||||||
.send(player);
|
.send(player);
|
||||||
|
|
||||||
oldRank.runCommands(player, rank);
|
oldRank.runCommands(player, next);
|
||||||
applyCooldown(player);
|
applyCooldown(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,23 +341,22 @@ public class Rankup extends JavaPlugin {
|
|||||||
*/
|
*/
|
||||||
public boolean checkRankup(Player player, boolean message) {
|
public boolean checkRankup(Player player, boolean message) {
|
||||||
Rank rank = rankups.getByPlayer(player);
|
Rank rank = rankups.getByPlayer(player);
|
||||||
if (rank == null) { // check if in ladder
|
if (rankups.isLast(permissions, player)) {
|
||||||
|
getMessage(prestiges == null ? Message.NO_RANKUP : prestiges.getByPlayer(player).isLast() ? Message.NO_RANKUP : Message.MUST_PRESTIGE)
|
||||||
|
.failIf(!message)
|
||||||
|
.replaceRanks(player, rankups.getLast())
|
||||||
|
.send(player);
|
||||||
|
return false;
|
||||||
|
} else if (rank == null) { // check if in ladder
|
||||||
getMessage(Message.NOT_IN_LADDER)
|
getMessage(Message.NOT_IN_LADDER)
|
||||||
.failIf(!message)
|
.failIf(!message)
|
||||||
.replace(Variable.PLAYER, player.getName())
|
.replace(Variable.PLAYER, player.getName())
|
||||||
.send(player);
|
.send(player);
|
||||||
return false;
|
return false;
|
||||||
} else if (rank.isLast()) { // check if they are at the highest rank
|
|
||||||
getMessage(rank, prestiges == null ? Message.NO_RANKUP : prestiges.getByPlayer(player).isLast() ? Message.NO_RANKUP : Message.MUST_PRESTIGE)
|
|
||||||
.failIf(!message)
|
|
||||||
.replaceRanks(player, rank)
|
|
||||||
.send(player);
|
|
||||||
return false;
|
|
||||||
} else if (!rank.hasRequirements(player)) { // check if they can afford it
|
} else if (!rank.hasRequirements(player)) { // check if they can afford it
|
||||||
if (message) {
|
if (message) {
|
||||||
replaceMoneyRequirements(getMessage(rank, Message.REQUIREMENTS_NOT_MET)
|
replaceMoneyRequirements(getMessage(rank, Message.REQUIREMENTS_NOT_MET)
|
||||||
.failIf(!message)
|
.replaceRanks(player, rank, rank.getNext()), player, rank)
|
||||||
.replaceRanks(player, rank, rankups.next(rank)), player, rank)
|
|
||||||
.send(player);
|
.send(player);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -381,16 +386,16 @@ public class Rankup extends JavaPlugin {
|
|||||||
|
|
||||||
getMessage(oldPrestige, Message.PRESTIGE_SUCCESS_PUBLIC)
|
getMessage(oldPrestige, Message.PRESTIGE_SUCCESS_PUBLIC)
|
||||||
.failIfEmpty()
|
.failIfEmpty()
|
||||||
.replaceRanks(player, oldPrestige, prestige)
|
.replaceRanks(player, oldPrestige, prestige.getRank())
|
||||||
.replaceFromTo(oldPrestige)
|
.replaceFromTo(oldPrestige)
|
||||||
.broadcast();
|
.broadcast();
|
||||||
getMessage(oldPrestige, Message.PRESTIGE_SUCCESS_PRIVATE)
|
getMessage(oldPrestige, Message.PRESTIGE_SUCCESS_PRIVATE)
|
||||||
.failIfEmpty()
|
.failIfEmpty()
|
||||||
.replaceRanks(player, oldPrestige, prestige)
|
.replaceRanks(player, oldPrestige, prestige.getRank())
|
||||||
.replaceFromTo(oldPrestige)
|
.replaceFromTo(oldPrestige)
|
||||||
.send(player);
|
.send(player);
|
||||||
|
|
||||||
oldPrestige.runCommands(player, prestige);
|
oldPrestige.runCommands(player, prestige.getRank());
|
||||||
applyCooldown(player);
|
applyCooldown(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,23 +405,24 @@ public class Rankup extends JavaPlugin {
|
|||||||
|
|
||||||
public boolean checkPrestige(Player player, boolean message) {
|
public boolean checkPrestige(Player player, boolean message) {
|
||||||
Prestige prestige = prestiges.getByPlayer(player);
|
Prestige prestige = prestiges.getByPlayer(player);
|
||||||
|
System.out.println(prestige.getNext() + " ..");
|
||||||
if (!prestige.isIn(player)) { // check if in ladder
|
if (!prestige.isIn(player)) { // check if in ladder
|
||||||
getMessage(Message.NOT_HIGH_ENOUGH)
|
getMessage(Message.NOT_HIGH_ENOUGH)
|
||||||
.failIf(!message)
|
.failIf(!message)
|
||||||
.replace(Variable.PLAYER, player.getName())
|
.replace(Variable.PLAYER, player.getName())
|
||||||
.send(player);
|
.send(player);
|
||||||
return false;
|
return false;
|
||||||
} else if (prestige.isLast()) { // check if they are at the highest rank
|
} else if (prestiges.getByName(prestige.getNext()) == null) { // check if they are at the highest rank
|
||||||
getMessage(prestige, Message.PRESTIGE_NO_PRESTIGE)
|
getMessage(prestige, Message.PRESTIGE_NO_PRESTIGE)
|
||||||
.failIf(!message)
|
.failIf(!message)
|
||||||
.replaceRanks(player, prestige)
|
.replaceRanks(player, prestige.getRank())
|
||||||
.replaceFromTo(prestige)
|
.replaceFromTo(prestige)
|
||||||
.send(player);
|
.send(player);
|
||||||
return false;
|
return false;
|
||||||
} else if (!prestige.hasRequirements(player)) { // check if they can afford it
|
} else if (!prestige.hasRequirements(player)) { // check if they can afford it
|
||||||
replaceMoneyRequirements(getMessage(prestige, Message.PRESTIGE_REQUIREMENTS_NOT_MET)
|
replaceMoneyRequirements(getMessage(prestige, Message.PRESTIGE_REQUIREMENTS_NOT_MET)
|
||||||
.failIf(!message)
|
.failIf(!message)
|
||||||
.replaceRanks(player, prestige, prestiges.next(prestige)), player, prestige)
|
.replaceRanks(player, prestige, prestiges.next(prestige).getRank()), player, prestige)
|
||||||
.replaceFromTo(prestige)
|
.replaceFromTo(prestige)
|
||||||
.send(player);
|
.send(player);
|
||||||
return false;
|
return false;
|
||||||
@@ -476,9 +482,9 @@ public class Rankup extends JavaPlugin {
|
|||||||
builder.replace(variable + " " + requirement.getName(), value.get());
|
builder.replace(variable + " " + requirement.getName(), value.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageBuilder getMessage(CommandSender player, Message message, Rank oldRank, Rank rank) {
|
public MessageBuilder getMessage(CommandSender player, Message message, Rank oldRank, String rankName) {
|
||||||
return replaceMoneyRequirements(getMessage(oldRank, message)
|
return replaceMoneyRequirements(getMessage(oldRank, message)
|
||||||
.replaceRanks(player, oldRank, rank), player, oldRank)
|
.replaceRanks(player, oldRank, rankName), player, oldRank)
|
||||||
.replaceFromTo(oldRank);
|
.replaceFromTo(oldRank);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -491,7 +497,7 @@ public class Rankup extends JavaPlugin {
|
|||||||
} else {
|
} else {
|
||||||
builder = getMessage(rank, type)
|
builder = getMessage(rank, type)
|
||||||
.failIfEmpty()
|
.failIfEmpty()
|
||||||
.replaceRanks(sender, rank)
|
.replaceRanks(sender, rank.getRank())
|
||||||
.replaceFromTo(rank);
|
.replaceFromTo(rank);
|
||||||
}
|
}
|
||||||
builder.send(sender);
|
builder.send(sender);
|
||||||
|
|||||||
@@ -48,12 +48,12 @@ public class PrestigeCommand implements CommandExecutor {
|
|||||||
case "text":
|
case "text":
|
||||||
confirming.put(player, System.currentTimeMillis());
|
confirming.put(player, System.currentTimeMillis());
|
||||||
plugin.replaceMoneyRequirements(plugin.getMessage(prestige, Message.PRESTIGE_CONFIRMATION)
|
plugin.replaceMoneyRequirements(plugin.getMessage(prestige, Message.PRESTIGE_CONFIRMATION)
|
||||||
.replaceRanks(player, prestige, prestiges.next(prestige)), player, prestige)
|
.replaceRanks(player, prestige, prestiges.next(prestige).getRank()), player, prestige)
|
||||||
.replaceFromTo(prestige)
|
.replaceFromTo(prestige)
|
||||||
.send(player);
|
.send(player);
|
||||||
break;
|
break;
|
||||||
case "gui":
|
case "gui":
|
||||||
Gui.of(player, prestige, prestiges.next(prestige), plugin).open(player);
|
Gui.of(player, prestige, prestige.getNext(), plugin).open(player);
|
||||||
break;
|
break;
|
||||||
case "none":
|
case "none":
|
||||||
plugin.prestige(player);
|
plugin.prestige(player);
|
||||||
|
|||||||
@@ -29,12 +29,12 @@ public class PrestigesCommand implements CommandExecutor {
|
|||||||
Prestige next;
|
Prestige next;
|
||||||
while ((next = prestiges.next(prestige)) != null) {
|
while ((next = prestiges.next(prestige)) != null) {
|
||||||
if (prestige.equals(playerRank)) {
|
if (prestige.equals(playerRank)) {
|
||||||
plugin.getMessage(sender, Message.PRESTIGES_CURRENT, prestige, next)
|
plugin.getMessage(sender, Message.PRESTIGES_CURRENT, prestige, next.getRank())
|
||||||
.replaceFirstPrestige(prestige, prestiges, prestige.getFrom())
|
.replaceFirstPrestige(prestige, prestiges, prestige.getFrom())
|
||||||
.send(sender);
|
.send(sender);
|
||||||
message = Message.PRESTIGES_INCOMPLETE;
|
message = Message.PRESTIGES_INCOMPLETE;
|
||||||
} else {
|
} else {
|
||||||
plugin.getMessage(sender, message, prestige, next)
|
plugin.getMessage(sender, message, prestige, next.getRank())
|
||||||
.replaceFirstPrestige(prestige, prestiges, prestige.getFrom())
|
.replaceFirstPrestige(prestige, prestiges, prestige.getFrom())
|
||||||
.send(sender);
|
.send(sender);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,15 +26,15 @@ public class RanksCommand implements CommandExecutor {
|
|||||||
|
|
||||||
Message message = playerRank == null ? Message.RANKS_INCOMPLETE : Message.RANKS_COMPLETE;
|
Message message = playerRank == null ? Message.RANKS_INCOMPLETE : Message.RANKS_COMPLETE;
|
||||||
Rank rank = rankups.getFirst();
|
Rank rank = rankups.getFirst();
|
||||||
Rank next;
|
while (rank != null) {
|
||||||
while ((next = rankups.next(rank)) != null) {
|
String name = rank.getNext();
|
||||||
if (rank.equals(playerRank)) {
|
if (rank.equals(playerRank)) {
|
||||||
plugin.getMessage(sender, Message.RANKS_CURRENT, rank, next).send(sender);
|
plugin.getMessage(sender, Message.RANKS_CURRENT, rank, name).send(sender);
|
||||||
message = Message.RANKS_INCOMPLETE;
|
message = Message.RANKS_INCOMPLETE;
|
||||||
} else {
|
} else {
|
||||||
plugin.getMessage(sender, message, rank, next).send(sender);
|
plugin.getMessage(sender, message, rank, name).send(sender);
|
||||||
}
|
}
|
||||||
rank = next;
|
rank = rankups.getByName(name);
|
||||||
}
|
}
|
||||||
plugin.sendHeaderFooter(sender, playerRank, Message.RANKS_FOOTER);
|
plugin.sendHeaderFooter(sender, playerRank, Message.RANKS_FOOTER);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -35,13 +35,14 @@ public class RankupCommand implements CommandExecutor {
|
|||||||
if (!plugin.checkRankup(player)) {
|
if (!plugin.checkRankup(player)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Rank next = rankups.next(rank);
|
/*Rank next = rankups.next(rank);
|
||||||
if (next == null) {
|
if (next == null) {
|
||||||
plugin.getLogger().severe("Rankup from " + rank.getRank() + " to " + rank.getNext() +
|
plugin.getLogger().severe("Rankup from " + rank.getRank() + " to " + rank.getNext() +
|
||||||
" is defined but " + rank.getNext() + " does not exist.");
|
" is defined but " + rank.getNext() + " does not exist.");
|
||||||
plugin.getMessage(Message.INVALID_RANKUP).failIfEmpty().send(player);
|
plugin.getMessage(Message.INVALID_RANKUP).failIfEmpty().send(player);
|
||||||
return true;
|
return true;
|
||||||
}
|
}*/
|
||||||
|
String next = rank.getNext();
|
||||||
|
|
||||||
FileConfiguration config = plugin.getConfig();
|
FileConfiguration config = plugin.getConfig();
|
||||||
String confirmationType = config.getString("confirmation-type").toLowerCase();
|
String confirmationType = config.getString("confirmation-type").toLowerCase();
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import sh.okx.rankup.prestige.Prestige;
|
|||||||
import sh.okx.rankup.ranks.Rank;
|
import sh.okx.rankup.ranks.Rank;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
@@ -32,7 +33,7 @@ public class Gui implements InventoryHolder {
|
|||||||
@Getter
|
@Getter
|
||||||
private boolean prestige;
|
private boolean prestige;
|
||||||
|
|
||||||
public static Gui of(Player player, Rank oldRank, Rank rank, Rankup plugin) {
|
public static Gui of(Player player, Rank oldRank, String rank, Rankup plugin) {
|
||||||
ConfigurationSection config = plugin.getConfig().getConfigurationSection("gui");
|
ConfigurationSection config = plugin.getConfig().getConfigurationSection("gui");
|
||||||
ItemStack[] items = new ItemStack[config.getInt("rows") * 9];
|
ItemStack[] items = new ItemStack[config.getInt("rows") * 9];
|
||||||
|
|
||||||
@@ -53,14 +54,14 @@ public class Gui implements InventoryHolder {
|
|||||||
plugin.replaceMoneyRequirements(
|
plugin.replaceMoneyRequirements(
|
||||||
plugin.getMessage(oldRank, gui.prestige ? Message.PRESTIGE_TITLE : Message.TITLE)
|
plugin.getMessage(oldRank, gui.prestige ? Message.PRESTIGE_TITLE : Message.TITLE)
|
||||||
.replaceRanks(player, oldRank, rank)
|
.replaceRanks(player, oldRank, rank)
|
||||||
.replaceFromTo(oldRank), player, rank).toString());
|
.replaceFromTo(oldRank), player, oldRank).toString());
|
||||||
inventory.setContents(items);
|
inventory.setContents(items);
|
||||||
gui.inventory = inventory;
|
gui.inventory = inventory;
|
||||||
return gui;
|
return gui;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
private static ItemStack getItem(Rankup plugin, String name, Player player, Rank oldRank, Rank rank) {
|
private static ItemStack getItem(Rankup plugin, String name, Player player, Rank oldRank, String rank) {
|
||||||
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();
|
||||||
@@ -99,13 +100,14 @@ public class Gui implements InventoryHolder {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String format(Rankup plugin, String message, Player player, Rank oldRank, Rank rank) {
|
private static String format(Rankup plugin, String message, Player player, Rank oldRank, String rank) {
|
||||||
return plugin.replaceMoneyRequirements(new MessageBuilder(ChatColor.translateAlternateColorCodes('&', message))
|
return plugin.replaceMoneyRequirements(new MessageBuilder(ChatColor.translateAlternateColorCodes('&', message))
|
||||||
.replaceRanks(player, oldRank, rank), player, oldRank)
|
.replaceRanks(player, oldRank, rank), player, oldRank)
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addItem(ItemStack[] items, ConfigurationSection section, ItemStack item) {
|
private static void addItem(ItemStack[] items, ConfigurationSection section, ItemStack item) {
|
||||||
|
Objects.requireNonNull(section, "GUI configuration section not found");
|
||||||
if (section.getName().equalsIgnoreCase("fill")) {
|
if (section.getName().equalsIgnoreCase("fill")) {
|
||||||
for (int i = 0; i < items.length; i++) {
|
for (int i = 0; i < items.length; i++) {
|
||||||
if (items[i] == null) {
|
if (items[i] == null) {
|
||||||
|
|||||||
@@ -50,26 +50,26 @@ public class MessageBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageBuilder replaceRanks(CommandSender player, Rank rank) {
|
public MessageBuilder replaceRanks(CommandSender player, String rankName) {
|
||||||
replace(Variable.PLAYER, player.getName());
|
replace(Variable.PLAYER, player.getName());
|
||||||
replaceRanks(rank);
|
replaceRanks(rankName);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageBuilder replaceRanks(CommandSender player, Rank oldRank, Rank rank) {
|
public MessageBuilder replaceRanks(CommandSender player, Rank oldRank, String rankName) {
|
||||||
replace(Variable.PLAYER, player.getName());
|
replace(Variable.PLAYER, player.getName());
|
||||||
replaceRanks(oldRank, rank);
|
replaceRanks(oldRank, rankName);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageBuilder replaceRanks(Rank rank) {
|
public MessageBuilder replaceRanks(String rankName) {
|
||||||
replace(Variable.RANK, rank.getRank());
|
replace(Variable.RANK, rankName);
|
||||||
replace(Variable.RANK_NAME, rank.getRank());
|
replace(Variable.RANK_NAME, rankName);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageBuilder replaceRanks(Rank oldRank, Rank rank) {
|
public MessageBuilder replaceRanks(Rank oldRank, String rankName) {
|
||||||
replaceRanks(rank);
|
replaceRanks(rankName);
|
||||||
replace(Variable.OLD_RANK, oldRank.getRank());
|
replace(Variable.OLD_RANK, oldRank.getRank());
|
||||||
replace(Variable.OLD_RANK_NAME, oldRank.getRank());
|
replace(Variable.OLD_RANK_NAME, oldRank.getRank());
|
||||||
return this;
|
return this;
|
||||||
@@ -104,7 +104,7 @@ public class MessageBuilder {
|
|||||||
|
|
||||||
public void send(CommandSender sender) {
|
public void send(CommandSender sender) {
|
||||||
String msg = message;
|
String msg = message;
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player && Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
|
||||||
msg = PlaceholderAPI.setPlaceholders((Player) sender, msg);
|
msg = PlaceholderAPI.setPlaceholders((Player) sender, msg);
|
||||||
}
|
}
|
||||||
sender.sendMessage(msg);
|
sender.sendMessage(msg);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package sh.okx.rankup.placeholders;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import sh.okx.rankup.Rankup;
|
import sh.okx.rankup.Rankup;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
|||||||
@@ -20,18 +20,17 @@ public class Prestige extends Rank {
|
|||||||
@Getter
|
@Getter
|
||||||
private final String to;
|
private final String to;
|
||||||
|
|
||||||
private Prestige(Rankup plugin, String next, String rank, Set<Requirement> requirements, List<String> commands, String from, String to) {
|
private Prestige(ConfigurationSection section, Rankup plugin, String next, String rank, Set<Requirement> requirements, List<String> commands, String from, String to) {
|
||||||
super(plugin, next, rank, requirements, commands);
|
super(section, plugin, next, rank, requirements, commands);
|
||||||
this.from = from;
|
this.from = from;
|
||||||
this.to = to;
|
this.to = to;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Prestige deserialize(Rankup plugin, ConfigurationSection section) {
|
public static Prestige deserialize(Rankup plugin, ConfigurationSection section) {
|
||||||
ConfigurationSection requirementsSection = section.getConfigurationSection("requirements");
|
List<String> requirementsList = section.getStringList("requirements");
|
||||||
Validate.notNull(requirementsSection, "No requirements defined for section " + section.getName());
|
Set<Requirement> requirements = plugin.getRequirementRegistry().getRequirements(requirementsList);
|
||||||
Set<Requirement> requirements = plugin.getRequirementRegistry().getRequirements(requirementsSection);
|
|
||||||
|
|
||||||
return new Prestige(plugin,
|
return new Prestige(section, plugin,
|
||||||
section.getString("next"),
|
section.getString("next"),
|
||||||
section.getString("rank"),
|
section.getString("rank"),
|
||||||
requirements,
|
requirements,
|
||||||
@@ -39,4 +38,28 @@ public class Prestige extends Rank {
|
|||||||
section.getString("from"),
|
section.getString("from"),
|
||||||
section.getString("to"));
|
section.getString("to"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isIn(Player player) {
|
||||||
|
|
||||||
|
String[] groups = plugin.getPermissions().getPlayerGroups(null, player);
|
||||||
|
for (String group : groups) {
|
||||||
|
if (group.equalsIgnoreCase(from) && rank == null) {
|
||||||
|
for (Prestige prestige : plugin.getPrestiges().getOrderedList()) {
|
||||||
|
if (prestige != this && prestige.isIn(player)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else if(group.equalsIgnoreCase(rank)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLast() {
|
||||||
|
return plugin.getPrestiges().getByName(next) == null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ public class Prestiges extends RankList<Prestige> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Prestige getByPlayer(Player player) {
|
public Prestige getFirst() {
|
||||||
Prestige prestige = super.getByPlayer(player);
|
for (Prestige prestige : ranks) {
|
||||||
if (prestige == null) {
|
if (prestige.getRank() == null) {
|
||||||
return getFirst();
|
return prestige;
|
||||||
} else {
|
}
|
||||||
return prestige;
|
|
||||||
}
|
}
|
||||||
|
throw new IllegalStateException("No prestige found for first prestige (first prestige is counted as a prestige without a rank set)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ import java.util.stream.Collectors;
|
|||||||
@EqualsAndHashCode
|
@EqualsAndHashCode
|
||||||
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
|
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
|
||||||
public class Rank {
|
public class Rank {
|
||||||
|
@Getter
|
||||||
|
protected final ConfigurationSection section;
|
||||||
protected final Rankup plugin;
|
protected final Rankup plugin;
|
||||||
@Getter
|
@Getter
|
||||||
protected final String next;
|
protected final String next;
|
||||||
@@ -32,11 +34,11 @@ public class Rank {
|
|||||||
protected final List<String> commands;
|
protected final List<String> commands;
|
||||||
|
|
||||||
public static Rank deserialize(Rankup plugin, ConfigurationSection section) {
|
public static Rank deserialize(Rankup plugin, ConfigurationSection section) {
|
||||||
ConfigurationSection requirementsSection = section.getConfigurationSection("requirements");
|
List<String> requirementsList = section.getStringList("requirements");
|
||||||
Validate.notNull(requirementsSection, "No requirements defined for section " + section.getName());
|
Validate.notEmpty(requirementsList, "No requirements defined for rankup section " + section.getName());
|
||||||
Set<Requirement> requirements = plugin.getRequirementRegistry().getRequirements(requirementsSection);
|
Set<Requirement> requirements = plugin.getRequirementRegistry().getRequirements(requirementsList);
|
||||||
|
|
||||||
return new Rank(plugin,
|
return new Rank(section, plugin,
|
||||||
section.getString("next"),
|
section.getString("next"),
|
||||||
section.getString("rank"),
|
section.getString("rank"),
|
||||||
requirements,
|
requirements,
|
||||||
@@ -83,10 +85,10 @@ public class Rank {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runCommands(Player player, Rank nextRank) {
|
public void runCommands(Player player, String next) {
|
||||||
for (String command : commands) {
|
for (String command : commands) {
|
||||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(),
|
Bukkit.dispatchCommand(Bukkit.getConsoleSender(),
|
||||||
new MessageBuilder(command).replaceRanks(player, this, nextRank).toString());
|
new MessageBuilder(command).replaceRanks(player, this, next).toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
package sh.okx.rankup.requirements;
|
package sh.okx.rankup.requirements;
|
||||||
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class RequirementRegistry {
|
public class RequirementRegistry {
|
||||||
@@ -24,18 +23,16 @@ public class RequirementRegistry {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Requirement> getRequirements(ConfigurationSection section) {
|
public Set<Requirement> getRequirements(List<String> list) {
|
||||||
Set<Requirement> requirements = new HashSet<>();
|
Set<Requirement> requirements = new HashSet<>();
|
||||||
|
|
||||||
for (Map.Entry<String, Object> entry : section.getValues(false).entrySet()) {
|
for (String req : list) {
|
||||||
String name = entry.getKey();
|
String[] parts = req.split(" ", 2);
|
||||||
String value = String.valueOf(entry.getValue());
|
String name = parts[0];
|
||||||
|
String value = parts[1];
|
||||||
Requirement requirement = newRequirement(name, value);
|
Requirement requirement = newRequirement(name, value);
|
||||||
if (requirement == null) {
|
Objects.requireNonNull(requirement, "Unknown requirement: " + name);
|
||||||
System.err.println("Unknown requirement: " + name);
|
requirements.add(requirement);
|
||||||
} else {
|
|
||||||
requirements.add(requirement);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return requirements;
|
return requirements;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import java.lang.reflect.Method;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Because mcMMO like changing the name of their skill types.
|
* Because mcMMO like changing the name of their skill types.
|
||||||
* Singleton (not thread safe!) class to access different mcMMO versions.
|
* Singleton class to access different mcMMO versions.
|
||||||
*/
|
*/
|
||||||
public class McMMOSkillUtil {
|
public class McMMOSkillUtil {
|
||||||
private static McMMOSkillUtil instance;
|
private static McMMOSkillUtil instance;
|
||||||
@@ -31,19 +31,19 @@ public class McMMOSkillUtil {
|
|||||||
try {
|
try {
|
||||||
skillTypeClass = Class.forName(pckg + "SkillType");
|
skillTypeClass = Class.forName(pckg + "SkillType");
|
||||||
} catch (ClassNotFoundException e2) {
|
} catch (ClassNotFoundException e2) {
|
||||||
throw new RuntimeException("mcMMO Skill Type class not found");
|
throw new UnsupportedOperationException("mcMMO Skill Type class not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
values = skillTypeClass.getMethod("values");
|
values = skillTypeClass.getMethod("values");
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
throw new RuntimeException("mcMMO " + skillTypeClass + ".values() not found");
|
throw new UnsupportedOperationException("mcMMO " + skillTypeClass + ".values() not found");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
valueOf = skillTypeClass.getMethod("valueOf", String.class);
|
valueOf = skillTypeClass.getMethod("valueOf", String.class);
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
throw new RuntimeException("mcMMO" + skillTypeClass + ".valueOf(String) not found");
|
throw new UnsupportedOperationException("mcMMO" + skillTypeClass + ".valueOf(String) not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*try {
|
/*try {
|
||||||
@@ -54,7 +54,7 @@ public class McMMOSkillUtil {
|
|||||||
try {
|
try {
|
||||||
getSkillLevel = McMMOPlayer.class.getMethod("getSkillLevel", skillTypeClass);
|
getSkillLevel = McMMOPlayer.class.getMethod("getSkillLevel", skillTypeClass);
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
throw new RuntimeException("mcMMO UserManager.getSkillLevel(" + skillTypeClass + ") not found");
|
throw new UnsupportedOperationException("mcMMO UserManager.getSkillLevel(" + skillTypeClass + ") not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# this is used for letting you know that you need to update/change your config file
|
# this is used for letting you know that you need to update/change your config file
|
||||||
version: 3
|
version: 4
|
||||||
|
|
||||||
# the locale to use for messages
|
# the locale to use for messages
|
||||||
# all messages can be customised but this allows you to
|
# all messages can be customised but this allows you to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: Rankup
|
name: Rankup
|
||||||
version: 3.4.2
|
version: 3.5-beta
|
||||||
main: sh.okx.rankup.Rankup
|
main: sh.okx.rankup.Rankup
|
||||||
author: Okx
|
author: Okx
|
||||||
depend: [Vault]
|
depend: [Vault]
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ Aexample:
|
|||||||
requirements:
|
requirements:
|
||||||
- 'money 1000'
|
- 'money 1000'
|
||||||
# the console will run these commands when a player ranks up
|
# the console will run these commands when a player ranks up
|
||||||
# the groups are automatically changed with vault
|
# nb: groups are automatically changed with vault
|
||||||
#commands:
|
#commands:
|
||||||
# this will run when a player ranks up from A to B.
|
# this will run when a player ranks up from A to B.
|
||||||
#- 'say {PLAYER} well done for ranking up from {OLD_RANK} to {RANK}!'
|
#- 'say {PLAYER} well done for ranking up from {OLD_RANK} to {RANK}!'
|
||||||
@@ -30,8 +30,7 @@ Cexample:
|
|||||||
- 'money 5000'
|
- 'money 5000'
|
||||||
- 'xp-level 2'
|
- 'xp-level 2'
|
||||||
# you can have a custom messages for each rank
|
# you can have a custom messages for each rank
|
||||||
# you can use this to list the requirements needed.
|
# the paths of these messages are the same as in the messages for your locale
|
||||||
# the paths of these messages are the exact same as in the messages for your locale
|
|
||||||
rankup:
|
rankup:
|
||||||
requirements-not-met: '&cYou need 5000 money and 2 levels of XP to rankup to D.'
|
requirements-not-met: '&cYou need 5000 money and 2 levels of XP to rankup to D.'
|
||||||
list:
|
list:
|
||||||
|
|||||||
Reference in New Issue
Block a user