Add value command (#47)

* Add value command
This commit is contained in:
Poma123 2019-02-27 23:13:17 +01:00 committed by tastybento
parent f4d7299015
commit 8add41c140
4 changed files with 71 additions and 1 deletions

View File

@ -14,6 +14,7 @@ import world.bentobox.level.commands.admin.AdminLevelCommand;
import world.bentobox.level.commands.admin.AdminTopCommand;
import world.bentobox.level.commands.island.IslandLevelCommand;
import world.bentobox.level.commands.island.IslandTopCommand;
import world.bentobox.level.commands.island.IslandValueCommand;
import world.bentobox.level.config.Settings;
import world.bentobox.level.listeners.IslandTeamListeners;
import world.bentobox.level.listeners.JoinLeaveListener;
@ -128,6 +129,7 @@ public class Level extends Addon {
gm.getPlayerCommand().ifPresent(playerCmd -> {
new IslandLevelCommand(this, playerCmd);
new IslandTopCommand(this, playerCmd);
new IslandValueCommand(this, playerCmd);
});
// Register placeholders
if (getPlugin().getPlaceholdersManager() != null) {

View File

@ -0,0 +1,50 @@
package world.bentobox.level.commands.island;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.PlayerInventory;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.level.Level;
import java.util.List;
public class IslandValueCommand extends CompositeCommand {
private final Level plugin;
public IslandValueCommand(Level plugin, CompositeCommand parent) {
super(parent, "value");
this.plugin = plugin;
}
@Override
public void setup() {
this.setPermission("island.value");
this.setDescription("island.value.description");
this.setOnlyPlayer(true);
}
@Override
public boolean execute(User user, String label, List<String> args) {
Player player = user.getPlayer();
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) + "");
}
}
} else {
user.sendMessage("island.value.no-value");
}
} else {
user.sendMessage("island.value.empty-hand");
}
return true;
}
}

View File

@ -16,6 +16,9 @@ permissions:
bskyblock.island.top:
description: Player can use top ten command
default: true
bskyblock.island.value:
description: Player can use value command
default: true
bskyblock.admin.level:
description: Player can use admin level command
default: true
@ -32,6 +35,9 @@ permissions:
acidisland.island.top:
description: Player can use top ten command
default: true
acidisland.island.value:
description: Player can use value command
default: true
acidisland.admin.level:
description: Player can use admin level command
default: true
@ -48,6 +54,9 @@ permissions:
caveblock.island.top:
description: Player can use top ten command
default: true
caveblock.island.value:
description: Player can use value command
default: true
caveblock.admin.level:
description: Player can use admin level command
default: true
@ -64,6 +73,9 @@ permissions:
skygird.island.top:
description: Player can use top ten command
default: true
skygird.island.value:
description: Player can use value command
default: true
skygird.admin.level:
description: Player can use admin level command
default: true

View File

@ -28,4 +28,10 @@ island:
gui-heading: "&6[name]: &B[rank]"
island-level: "&BLevel [level]"
warp-to: "&AWarping to [name]'s island"
value:
description: "shows the value of any block"
success: "§7The value of this block is: §e[value]"
success-underwater: "§7The value of this block below sea-level: §e[value]"
empty-hand: "§cThere are no blocks in your hand"
no-value: "§cThat item has no value."