mirror of
https://github.com/BentoBoxWorld/Limits.git
synced 2024-09-27 14:12:57 +02:00
Added chest/hopper placeholders, refactored getBlockCounts to be consistent, implemented getBlockCount
This commit is contained in:
parent
4c5fdd6390
commit
21986d3f2d
@ -3,6 +3,7 @@ package world.bentobox.limits;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.addons.Addon;
|
import world.bentobox.bentobox.api.addons.Addon;
|
||||||
@ -48,6 +49,7 @@ public class Limits extends Addon {
|
|||||||
// Register commands
|
// Register commands
|
||||||
gm.getAdminCommand().ifPresent(a -> new AdminCommand(this, a));
|
gm.getAdminCommand().ifPresent(a -> new AdminCommand(this, a));
|
||||||
gm.getPlayerCommand().ifPresent(a -> new PlayerCommand(this, a));
|
gm.getPlayerCommand().ifPresent(a -> new PlayerCommand(this, a));
|
||||||
|
registerPlaceholders(gm);
|
||||||
log("Limits will apply to " + gm.getDescription().getName());
|
log("Limits will apply to " + gm.getDescription().getName());
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -125,4 +127,29 @@ public class Limits extends Addon {
|
|||||||
return joinListener;
|
return joinListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void registerPlaceholders(GameModeAddon gm) {
|
||||||
|
if (getPlugin().getPlaceholdersManager() == null) return;
|
||||||
|
|
||||||
|
// Hopper count
|
||||||
|
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
|
||||||
|
gm.getDescription().getName().toLowerCase() + "_island_hopper_count",
|
||||||
|
user -> String.valueOf(getBlockLimitListener().getIsland(gm.getIslands().
|
||||||
|
getIsland(gm.getOverWorld(), user).getUniqueId()).getBlockCount(Material.HOPPER)));
|
||||||
|
// Hopper limit
|
||||||
|
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
|
||||||
|
gm.getDescription().getName().toLowerCase() + "_island_hopper_limit",
|
||||||
|
user -> String.valueOf(getBlockLimitListener().getIsland(gm.getIslands().
|
||||||
|
getIsland(gm.getOverWorld(), user).getUniqueId()).getBlockLimit(Material.HOPPER)));
|
||||||
|
// Chest count
|
||||||
|
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
|
||||||
|
gm.getDescription().getName().toLowerCase() + "_island_chest_count",
|
||||||
|
user -> String.valueOf(getBlockLimitListener().getIsland(gm.getIslands().
|
||||||
|
getIsland(gm.getOverWorld(), user).getUniqueId()).getBlockCount(Material.CHEST)));
|
||||||
|
// Chest limit
|
||||||
|
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
|
||||||
|
gm.getDescription().getName().toLowerCase() + "_island_chest_limit",
|
||||||
|
user -> String.valueOf(getBlockLimitListener().getIsland(gm.getIslands().
|
||||||
|
getIsland(gm.getOverWorld(), user).getUniqueId()).getBlockLimit(Material.CHEST)));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ public class LimitTab implements Tab {
|
|||||||
// Adjust icon
|
// Adjust icon
|
||||||
pib.icon(B2M.getOrDefault(en.getKey(), en.getKey()));
|
pib.icon(B2M.getOrDefault(en.getKey(), en.getKey()));
|
||||||
|
|
||||||
int count = ibc == null ? 0 : ibc.getBlockCount().getOrDefault(en.getKey(), 0);
|
int count = ibc == null ? 0 : ibc.getBlockCounts().getOrDefault(en.getKey(), 0);
|
||||||
String color = count >= en.getValue() ? user.getTranslation("island.limits.max-color") : user.getTranslation("island.limits.regular-color");
|
String color = count >= en.getValue() ? user.getTranslation("island.limits.max-color") : user.getTranslation("island.limits.regular-color");
|
||||||
pib.description(color
|
pib.description(color
|
||||||
+ user.getTranslation("island.limits.block-limit-syntax",
|
+ user.getTranslation("island.limits.block-limit-syntax",
|
||||||
|
@ -143,7 +143,7 @@ public class LimitsCalc {
|
|||||||
if (ibc == null) {
|
if (ibc == null) {
|
||||||
ibc = new IslandBlockCount();
|
ibc = new IslandBlockCount();
|
||||||
}
|
}
|
||||||
ibc.setBlockCount(blockCount.entrySet().stream()
|
ibc.setBlockCounts(blockCount.entrySet().stream()
|
||||||
.collect(Collectors.toMap(
|
.collect(Collectors.toMap(
|
||||||
Map.Entry::getKey,
|
Map.Entry::getKey,
|
||||||
entry -> entry.getValue().get())));
|
entry -> entry.getValue().get())));
|
||||||
|
@ -85,7 +85,7 @@ public class BlockLimitsListener implements Listener {
|
|||||||
handler.loadObjects().forEach(ibc -> {
|
handler.loadObjects().forEach(ibc -> {
|
||||||
// Clean up
|
// Clean up
|
||||||
if (addon.isCoveredGameMode(ibc.getGameMode())) {
|
if (addon.isCoveredGameMode(ibc.getGameMode())) {
|
||||||
ibc.getBlockCount().keySet().removeIf(DO_NOT_COUNT::contains);
|
ibc.getBlockCounts().keySet().removeIf(DO_NOT_COUNT::contains);
|
||||||
// Store
|
// Store
|
||||||
islandCountMap.put(ibc.getUniqueId(), ibc);
|
islandCountMap.put(ibc.getUniqueId(), ibc);
|
||||||
} else {
|
} else {
|
||||||
|
@ -26,7 +26,7 @@ public class IslandBlockCount implements DataObject {
|
|||||||
private String gameMode = "";
|
private String gameMode = "";
|
||||||
|
|
||||||
@Expose
|
@Expose
|
||||||
private Map<Material, Integer> blockCount = new EnumMap<>(Material.class);
|
private Map<Material, Integer> blockCounts = new EnumMap<>(Material.class);
|
||||||
|
|
||||||
private boolean changed;
|
private boolean changed;
|
||||||
|
|
||||||
@ -74,24 +74,33 @@ public class IslandBlockCount implements DataObject {
|
|||||||
/**
|
/**
|
||||||
* @return the blockCount
|
* @return the blockCount
|
||||||
*/
|
*/
|
||||||
public Map<Material, Integer> getBlockCount() {
|
public Map<Material, Integer> getBlockCounts() {
|
||||||
return blockCount;
|
return blockCounts;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param blockCount the blockCount to set
|
* @param blockCounts the blockCount to set
|
||||||
*/
|
*/
|
||||||
public void setBlockCount(Map<Material, Integer> blockCount) {
|
public void setBlockCounts(Map<Material, Integer> blockCounts) {
|
||||||
this.blockCount = blockCount;
|
this.blockCounts = blockCounts;
|
||||||
setChanged();
|
setChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the block count for this material for this island
|
||||||
|
* @param m - material
|
||||||
|
* @return count or -1 for unlimited
|
||||||
|
*/
|
||||||
|
public Integer getBlockCount(Material m) {
|
||||||
|
return blockCounts.getOrDefault(m, -1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a material to the count
|
* Add a material to the count
|
||||||
* @param material - material
|
* @param material - material
|
||||||
*/
|
*/
|
||||||
public void add(Material material) {
|
public void add(Material material) {
|
||||||
blockCount.merge(material, 1, Integer::sum);
|
blockCounts.merge(material, 1, Integer::sum);
|
||||||
setChanged();
|
setChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,8 +109,8 @@ public class IslandBlockCount implements DataObject {
|
|||||||
* @param material - material
|
* @param material - material
|
||||||
*/
|
*/
|
||||||
public void remove(Material material) {
|
public void remove(Material material) {
|
||||||
blockCount.put(material, blockCount.getOrDefault(material, 0) - 1);
|
blockCounts.put(material, blockCounts.getOrDefault(material, 0) - 1);
|
||||||
blockCount.values().removeIf(v -> v <= 0);
|
blockCounts.values().removeIf(v -> v <= 0);
|
||||||
setChanged();
|
setChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +121,7 @@ public class IslandBlockCount implements DataObject {
|
|||||||
* @return true if count is >= limit
|
* @return true if count is >= limit
|
||||||
*/
|
*/
|
||||||
public boolean isAtLimit(Material material, int limit) {
|
public boolean isAtLimit(Material material, int limit) {
|
||||||
return blockCount.getOrDefault(material, 0) >= limit;
|
return blockCounts.getOrDefault(material, 0) >= limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -122,7 +131,7 @@ public class IslandBlockCount implements DataObject {
|
|||||||
*/
|
*/
|
||||||
public boolean isAtLimit(Material m) {
|
public boolean isAtLimit(Material m) {
|
||||||
// Check island limits first
|
// Check island limits first
|
||||||
return blockLimits.containsKey(m) && blockCount.getOrDefault(m, 0) >= blockLimits.get(m);
|
return blockLimits.containsKey(m) && blockCounts.getOrDefault(m, 0) >= blockLimits.get(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBlockLimited(Material m) {
|
public boolean isBlockLimited(Material m) {
|
||||||
|
Loading…
Reference in New Issue
Block a user