"Deprecated" current placeholders (their name need to be changed) and their implementation

This commit is contained in:
Florian CUNY 2019-11-23 14:43:24 +01:00
parent f97a252840
commit 8181fbc431
4 changed files with 17 additions and 2 deletions

View File

@ -143,6 +143,8 @@ public class Level extends Addon {
}); });
// Register placeholders // Register placeholders
if (getPlugin().getPlaceholdersManager() != null) { if (getPlugin().getPlaceholdersManager() != null) {
// DEPRECATED PLACEHOLDERS - remove in an upcoming version
getPlugin().getPlaceholdersManager().registerPlaceholder(this, gm.getDescription().getName().toLowerCase() + "-island-level", new LevelPlaceholder(this, gm)); getPlugin().getPlaceholdersManager().registerPlaceholder(this, gm.getDescription().getName().toLowerCase() + "-island-level", new LevelPlaceholder(this, gm));
// Top Ten // Top Ten
for (int i = 1; i < 11; i++) { for (int i = 1; i < 11; i++) {

View File

@ -8,7 +8,9 @@ import world.bentobox.level.Level;
/** /**
* @author tastybento * @author tastybento
* *
* @deprecated As of 1.9.0, for removal.
*/ */
@Deprecated
public class LevelPlaceholder implements PlaceholderReplacer { public class LevelPlaceholder implements PlaceholderReplacer {
private final Level addon; private final Level addon;
@ -29,6 +31,9 @@ public class LevelPlaceholder implements PlaceholderReplacer {
*/ */
@Override @Override
public String onReplace(User user) { public String onReplace(User user) {
addon.logWarning("You are using a deprecated placeholder.");
addon.log("Please replace any occurrence of 'Level_" + gm.getDescription().getName().toLowerCase() + "-island-level'");
addon.log("by 'Level_" + gm.getDescription().getName().toLowerCase() + "_island_level'");
return addon.getLevelPresenter().getLevelString(addon.getIslandLevel(gm.getOverWorld(), user.getUniqueId())); return addon.getLevelPresenter().getLevelString(addon.getIslandLevel(gm.getOverWorld(), user.getUniqueId()));
} }

View File

@ -10,8 +10,9 @@ import world.bentobox.level.Level;
/** /**
* @author tastybento * @author tastybento
* * @deprecated As of 1.9.0, for removal.
*/ */
@Deprecated
public class TopTenNamePlaceholder implements PlaceholderReplacer { public class TopTenNamePlaceholder implements PlaceholderReplacer {
private final Level level; private final Level level;
@ -29,6 +30,9 @@ public class TopTenNamePlaceholder implements PlaceholderReplacer {
*/ */
@Override @Override
public String onReplace(User user) { public String onReplace(User user) {
level.logWarning("You are using a deprecated placeholder.");
level.log("Please replace any occurrence of 'Level_" + gm.getDescription().getName().toLowerCase() + "-island-top-name-#'");
level.log("by 'Level_" + gm.getDescription().getName().toLowerCase() + "_island_top_name_#'");
Collection<UUID> values = level.getTopTen().getTopTenList(gm.getOverWorld()).getTopTen().keySet(); Collection<UUID> values = level.getTopTen().getTopTenList(gm.getOverWorld()).getTopTen().keySet();
return values.size() < i ? "" : level.getPlayers().getName(values.stream().skip(i).findFirst().orElse(null)); return values.size() < i ? "" : level.getPlayers().getName(values.stream().skip(i).findFirst().orElse(null));
} }

View File

@ -10,8 +10,9 @@ import world.bentobox.level.Level;
/** /**
* Provides the level values to placeholders * Provides the level values to placeholders
* @author tastybento * @author tastybento
* * @deprecated As of 1.9.0, for removal.
*/ */
@Deprecated
public class TopTenPlaceholder implements PlaceholderReplacer { public class TopTenPlaceholder implements PlaceholderReplacer {
private final Level level; private final Level level;
@ -29,6 +30,9 @@ public class TopTenPlaceholder implements PlaceholderReplacer {
*/ */
@Override @Override
public String onReplace(User user) { public String onReplace(User user) {
level.logWarning("You are using a deprecated placeholder.");
level.log("Please replace any occurrence of 'Level_" + gm.getDescription().getName().toLowerCase() + "-island-top-value-#'");
level.log("by 'Level_" + gm.getDescription().getName().toLowerCase() + "_island_top_value_#'");
Collection<Long> values = level.getTopTen().getTopTenList(gm.getOverWorld()).getTopTen().values(); Collection<Long> values = level.getTopTen().getTopTenList(gm.getOverWorld()).getTopTen().values();
return values.size() < i ? "" : values.stream().skip(i).findFirst().map(String::valueOf).orElse(""); return values.size() < i ? "" : values.stream().skip(i).findFirst().map(String::valueOf).orElse("");
} }