Skip to content

Commit

Permalink
Add value command (#47)
Browse files Browse the repository at this point in the history
* Add value command
  • Loading branch information
poma123 authored and tastybento committed Feb 27, 2019
1 parent f4d7299 commit 8add41c
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/main/java/world/bentobox/level/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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;
Expand Down Expand Up @@ -128,6 +129,7 @@ public void onEnable() {
gm.getPlayerCommand().ifPresent(playerCmd -> {
new IslandLevelCommand(this, playerCmd);
new IslandTopCommand(this, playerCmd);
new IslandValueCommand(this, playerCmd);
});
// Register placeholders
if (getPlugin().getPlaceholdersManager() != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
12 changes: 12 additions & 0 deletions src/main/resources/addon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."

0 comments on commit 8add41c

Please sign in to comment.