Implements better value command

Checks world value

Fixes https://github.com/BentoBoxWorld/Level/issues/148
This commit is contained in:
tastybento 2020-04-21 17:24:30 -07:00
parent 0a4b0af931
commit b92d412f0a
3 changed files with 36 additions and 21 deletions

View File

@ -219,17 +219,13 @@ public class CalcIslandLevel {
* @return value of a material
*/
private int getValue(Material md) {
// Check world settings
if (addon.getBlockConfig().getWorldBlockValues().containsKey(world) && addon.getBlockConfig().getWorldBlockValues().get(world).containsKey(md)) {
return addon.getBlockConfig().getWorldBlockValues().get(world).get(md);
Integer value = addon.getBlockConfig().getValue(world, md);
if (value == null) {
// Not in config
result.ncCount.add(md);
return 0;
}
// Check baseline
if (addon.getBlockConfig().getBlockValues().containsKey(md)) {
return addon.getBlockConfig().getBlockValues().get(md);
}
// Not in config
result.ncCount.add(md);
return 0;
return value;
}
/**

View File

@ -10,11 +10,11 @@ import world.bentobox.level.Level;
import java.util.List;
public class IslandValueCommand extends CompositeCommand {
private final Level plugin;
private final Level addon;
public IslandValueCommand(Level plugin, CompositeCommand parent) {
public IslandValueCommand(Level addon, CompositeCommand parent) {
super(parent, "value");
this.plugin = plugin;
this.addon = addon;
}
@Override
@ -30,14 +30,12 @@ public class IslandValueCommand extends CompositeCommand {
PlayerInventory inventory = player.getInventory();
if (!inventory.getItemInMainHand().getType().equals(Material.AIR)) {
Material material = inventory.getItemInMainHand().getType();
if (plugin.getConfig().get("blocks." + material.toString()) != null) {
int value = plugin.getConfig().getInt("blocks." + material.toString());
user.sendMessage("island.value.success", "[value]", value + "");
if (plugin.getConfig().get("underwater") != null) {
double underWater = plugin.getConfig().getDouble("underwater");
if (underWater > 1.0) {
user.sendMessage("island.value.success-underwater", "[value]", (underWater * value) + "");
}
Integer value = addon.getBlockConfig().getValue(getWorld(), material);
if (value != null) {
user.sendMessage("island.value.success", "[value]", String.valueOf(value));
double underWater = addon.getSettings().getUnderWaterMultiplier();
if (underWater > 1.0) {
user.sendMessage("island.value.success-underwater", "[value]", (underWater * value) + "");
}
} else {
user.sendMessage("island.value.no-value");
@ -47,4 +45,5 @@ public class IslandValueCommand extends CompositeCommand {
}
return true;
}
}

View File

@ -107,4 +107,24 @@ public class BlockConfig {
public Map<World, Map<Material, Integer>> getWorldBlockValues() {
return worldBlockValues;
}
/**
* Get the value of material in world
* @param world - world
* @param md - material
* @return value or null if not configured with a value
*/
public Integer getValue(World world, Material md) {
// Check world settings
if (getWorldBlockValues().containsKey(world) && getWorldBlockValues().get(world).containsKey(md)) {
return getWorldBlockValues().get(world).get(md);
}
// Check baseline
if (getBlockValues().containsKey(md)) {
return getBlockValues().get(md);
}
return null;
}
}