Registers all blocks as placeholders
This commit is contained in:
parent
0a193ebd27
commit
f94a4ac0bb
|
@ -1,5 +1,6 @@
|
||||||
package world.bentobox.limits;
|
package world.bentobox.limits;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -132,9 +133,9 @@ public class Limits extends Addon {
|
||||||
|
|
||||||
private void registerPlaceholders(GameModeAddon gm) {
|
private void registerPlaceholders(GameModeAddon gm) {
|
||||||
if (getPlugin().getPlaceholdersManager() == null) return;
|
if (getPlugin().getPlaceholdersManager() == null) return;
|
||||||
|
Arrays.stream(Material.values())
|
||||||
registerCountAndLimitPlaceholders("HOPPER", gm);
|
.filter(m -> m.isBlock())
|
||||||
registerCountAndLimitPlaceholders("CHEST", gm);
|
.forEach(m -> registerCountAndLimitPlaceholders(m, gm));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,46 +148,46 @@ public class Limits extends Addon {
|
||||||
* "Limits_bskyblock_island_hopper_count"
|
* "Limits_bskyblock_island_hopper_count"
|
||||||
* "Limits_bskyblock_island_hopper_limit"
|
* "Limits_bskyblock_island_hopper_limit"
|
||||||
*
|
*
|
||||||
* @param materialName - All caps
|
* @param m
|
||||||
* @param gm
|
* @param gm
|
||||||
*/
|
*/
|
||||||
private void registerCountAndLimitPlaceholders(String materialName, GameModeAddon gm) {
|
private void registerCountAndLimitPlaceholders(Material m, GameModeAddon gm) {
|
||||||
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
|
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
|
||||||
gm.getDescription().getName().toLowerCase() + "_island_" + materialName.toLowerCase() + "_count",
|
gm.getDescription().getName().toLowerCase() + "_island_" + m.toString().toLowerCase() + "_count",
|
||||||
user -> String.valueOf(getCount(user, materialName, gm)));
|
user -> String.valueOf(getCount(user, m, gm)));
|
||||||
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
|
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
|
||||||
gm.getDescription().getName().toLowerCase() + "_island_" + materialName.toLowerCase() + "_limit",
|
gm.getDescription().getName().toLowerCase() + "_island_" + m.toString().toLowerCase() + "_limit",
|
||||||
user -> getLimit(user, materialName, gm));
|
user -> getLimit(user, m, gm));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param user - Used to identify the island the user belongs to
|
* @param user - Used to identify the island the user belongs to
|
||||||
* @param materialName - The material we are trying to count on the island
|
* @param m - The material we are trying to count on the island
|
||||||
* @param gm
|
* @param gm
|
||||||
* @return Number of blocks of the specified material on the given user's island
|
* @return Number of blocks of the specified material on the given user's island
|
||||||
*/
|
*/
|
||||||
private int getCount(@Nullable User user, String materialName, GameModeAddon gm) {
|
private int getCount(@Nullable User user, Material m, GameModeAddon gm) {
|
||||||
Island is = gm.getIslands().getIsland(gm.getOverWorld(), user);
|
Island is = gm.getIslands().getIsland(gm.getOverWorld(), user);
|
||||||
if (is == null) {
|
if (is == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return getBlockLimitListener().getIsland(gm.getIslands().getIsland(gm.getOverWorld(), user).getUniqueId()).
|
return getBlockLimitListener().getIsland(gm.getIslands().getIsland(gm.getOverWorld(), user).getUniqueId()).
|
||||||
getBlockCount(Material.getMaterial(materialName));
|
getBlockCount(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param user - Used to identify the island the user belongs to
|
* @param user - Used to identify the island the user belongs to
|
||||||
* @param materialName - The material whose limit we are querying
|
* @param m - The material whose limit we are querying
|
||||||
* @param gm
|
* @param gm
|
||||||
* @return The limit of the specified material on the given user's island
|
* @return The limit of the specified material on the given user's island
|
||||||
*/
|
*/
|
||||||
private String getLimit(@Nullable User user, String materialName, GameModeAddon gm) {
|
private String getLimit(@Nullable User user, Material m, GameModeAddon gm) {
|
||||||
Island is = gm.getIslands().getIsland(gm.getOverWorld(), user);
|
Island is = gm.getIslands().getIsland(gm.getOverWorld(), user);
|
||||||
if (is == null) {
|
if (is == null) {
|
||||||
return "Limit not set";
|
return "Limit not set";
|
||||||
}
|
}
|
||||||
int limit = getBlockLimitListener().getIsland(gm.getIslands().getIsland(gm.getOverWorld(), user).getUniqueId()).
|
int limit = getBlockLimitListener().getIsland(gm.getIslands().getIsland(gm.getOverWorld(), user).getUniqueId()).
|
||||||
getBlockLimit(Material.getMaterial(materialName));
|
getBlockLimit(m);
|
||||||
return limit == -1 ? "Limit not set" : String.valueOf(limit);
|
return limit == -1 ? "Limit not set" : String.valueOf(limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue