3.1 prestiging improvements

This commit is contained in:
okx-code
2018-09-13 21:19:25 +01:00
parent cd17d169c4
commit f8ede913ef
12 changed files with 79 additions and 15 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ plugins {
}
group 'sh.okx'
version '3.0.2'
version '3.1'
repositories {
mavenCentral()
+1 -1
View File
@@ -16,7 +16,7 @@ public class RankList<T extends Rank> {
protected final FileConfiguration config;
protected final Set<T> ranks = new HashSet<>();
public RankList(Rankup plugin, FileConfiguration config, Function<ConfigurationSection, T> deserializer) {
public RankList(FileConfiguration config, Function<ConfigurationSection, T> deserializer) {
this.config = config;
for (Map.Entry<String, Object> entry : config.getValues(false).entrySet()) {
ConfigurationSection rankSection = (ConfigurationSection) entry.getValue();
+15 -7
View File
@@ -58,9 +58,9 @@ public class Rankup extends JavaPlugin {
* The registry for listing the requirements to /rankup.
*/
@Getter
private RequirementRegistry requirementRegistry = new RequirementRegistry();
private RequirementRegistry requirementRegistry;
@Getter
private OperationRegistry operationRegistry = new OperationRegistry();
private OperationRegistry operationRegistry;
@Getter
private FileConfiguration messages;
@Getter
@@ -78,7 +78,6 @@ public class Rankup extends JavaPlugin {
@Override
public void onEnable() {
registerRequirements();
setupPermissions();
setupEconomy();
reload();
@@ -121,10 +120,10 @@ public class Rankup extends JavaPlugin {
closeInventories();
loadConfigs();
if (config.getInt("version") != 0) {
if (config.getInt("version") < 1) {
getLogger().severe("You are using an outdated config!");
getLogger().severe("This means that some things might not work!");
getLogger().severe("To update, please rename 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.");
@@ -150,6 +149,11 @@ public class Rankup extends JavaPlugin {
private void loadConfigs() {
messages = loadConfig("messages.yml");
config = loadConfig("config.yml");
refreshRanks();
}
public void refreshRanks() {
registerRequirements();
rankups = new Rankups(this, loadConfig("rankups.yml"));
if(config.getBoolean("prestige")) {
prestiges = new Prestiges(this, loadConfig("prestiges.yml"));
@@ -165,16 +169,20 @@ public class Rankup extends JavaPlugin {
}
private void registerRequirements() {
requirementRegistry = new RequirementRegistry();
requirementRegistry.addRequirement(new MoneyRequirement(this));
requirementRegistry.addRequirement(new XpLevelRequirement(this));
requirementRegistry.addRequirement(new PlaytimeMinutesRequirement(this));
requirementRegistry.addRequirement(new GroupRequirement(this));
requirementRegistry.addRequirement(new PermissionRequirement(this));
operationRegistry = new OperationRegistry();
operationRegistry.addOperation("all", new AllOperation());
operationRegistry.addOperation("none", new NoneOperation());
operationRegistry.addOperation("one", new OneOperation());
operationRegistry.addOperation("any", new AnyOperation());
Bukkit.getPluginManager().callEvent(new RankupRegisterEvent(this));
}
private void setupPermissions() {
@@ -330,12 +338,12 @@ public class Rankup extends JavaPlugin {
}
permissions.playerAddGroup(null, player, prestige.getRank());
getMessage(oldPrestige, Message.SUCCESS_PUBLIC)
getMessage(oldPrestige, Message.PRESTIGE_SUCCESS_PUBLIC)
.failIfEmpty()
.replaceRanks(player, oldPrestige, prestige)
.replaceFromTo(oldPrestige)
.broadcast();
getMessage(oldPrestige, Message.SUCCESS_PRIVATE)
getMessage(oldPrestige, Message.PRESTIGE_SUCCESS_PRIVATE)
.failIfEmpty()
.replaceRanks(player, oldPrestige, prestige)
.replaceFromTo(oldPrestige)
@@ -0,0 +1,38 @@
package sh.okx.rankup;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import sh.okx.rankup.requirements.OperationRegistry;
import sh.okx.rankup.requirements.RequirementRegistry;
/**
* Called immediately before rankups and prestiges are registered,
* and immediately after the built-in requirements and operations are registered.
* This is used to register custom requirements.
* This is called when the plugin is enabled, and when it is reloaded from a command.
*/
@RequiredArgsConstructor
public class RankupRegisterEvent extends Event {
private static final HandlerList handlers = new HandlerList();
@Getter
private final Rankup plugin;
public RequirementRegistry getRequirementRegistry() {
return plugin.getRequirementRegistry();
}
public OperationRegistry getOperationRegistry() {
return plugin.getOperationRegistry();
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}
@@ -47,7 +47,7 @@ public class PrestigeCommand implements CommandExecutor {
switch (confirmationType) {
case "text":
confirming.put(player, System.currentTimeMillis());
plugin.replaceMoneyRequirements(plugin.getMessage(prestige, Message.CONFIRMATION)
plugin.replaceMoneyRequirements(plugin.getMessage(prestige, Message.PRESTIGE_CONFIRMATION)
.replaceRanks(player, prestige, prestiges.next(prestige)), player, prestige)
.replaceFromTo(prestige)
.send(player);
@@ -24,7 +24,10 @@ public enum Message {
COOLDOWN_SINGULAR("rankup.cooldown.singular"),
COOLDOWN_PLURAL("rankup.cooldown.plural"),
MUST_PRESTIGE("rankup.must-prestige"),
NOT_HIGH_ENOUGH("prestige.not-high-enough");
NOT_HIGH_ENOUGH("not-high-enough"),
PRESTIGE_SUCCESS_PUBLIC("prestige.success-public"),
PRESTIGE_SUCCESS_PRIVATE("prestige.success-private"),
PRESTIGE_CONFIRMATION("prestige.confirmation");
@Getter
private final String name;
@@ -57,6 +57,10 @@ public class RankupExpansion extends PlaceholderExpansion {
return orElsePlaceholder(nextPrestige, Prestige::getRank, "highest-rank");
case "next_prestige_name":
return orElsePlaceholder(nextPrestige, Prestige::getName, "highest-rank");
case "prestige_money":
return String.valueOf(simplify(orElse(prestige, r -> r.isEligable(player) ? r.getRequirement("money").getValueDouble() : 0, 0)));
case "prestige_money_formatted":
return plugin.formatMoney(orElse(prestige, r -> r.isEligable(player) ? r.getRequirement("money").getValueDouble() : 0, 0D));
case "current_rank":
return orElsePlaceholder(rank, Rank::getRank, "not-in-ladder");
case "current_rank_name":
@@ -7,7 +7,7 @@ import sh.okx.rankup.Rankup;
public class Prestiges extends RankList<Prestige> {
public Prestiges(Rankup plugin, FileConfiguration config) {
super(plugin, config, section -> Prestige.deserialize(plugin, section));
super(config, section -> Prestige.deserialize(plugin, section));
}
@Override
@@ -6,6 +6,6 @@ import sh.okx.rankup.Rankup;
public class Rankups extends RankList<Rank> {
public Rankups(Rankup plugin, FileConfiguration config) {
super(plugin, config, section -> Rank.deserialize(plugin, section));
super(config, section -> Rank.deserialize(plugin, section));
}
}
+5 -1
View File
@@ -1,13 +1,17 @@
# this is used for letting you know that you need to update/change your config file
version: 0
version: 1
# whether /ranks and /prestiges should be enabled (true) or disabled (false)
# /rankup3 reload will not do anything if this is changed,
# you will have to restart your server.
ranks: true
# in 1.13 you can negate the permission rankup.prestiges
# so the command will not autocomplete
prestiges: true
# whether or not /prestige and /prestiges should be enabled.
# in 1.13 you can negate the permission rankup.prestige
# so the command will not autocomplete
prestige: true
# how people should confirm ranking up
+7
View File
@@ -38,7 +38,14 @@ rankup:
plural: "&cYou must wait {SECONDS_LEFT} more seconds to rankup again."
# prestige messages can also be customised
prestige:
success-public: "&a{PLAYER} &ehas prestiged to: &d{RANK}"
success-private: "&aYou have prestiged to: &d{RANK}"
confirmation: |-
&eAre you sure you want to prestige to &a{RANK}&e?
&eType &c/prestige &eagain to confirm.
title: "Prestige to {RANK}"
list:
complete: "&7{OLD_RANK} &8\xbb &7{RANK}"
current: "&c{OLD_RANK} &e\xbb &c{RANK}"
+1 -1
View File
@@ -1,5 +1,5 @@
name: Rankup
version: 3.0.2
version: 3.1
main: sh.okx.rankup.Rankup
author: Okx
depend: [Vault]