-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This GUI shows value to all items in game. It also shows max limit of blocks, if it is set. Fixes of #192
- Loading branch information
Showing
9 changed files
with
1,262 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 113 additions & 21 deletions
134
src/main/java/world/bentobox/level/commands/IslandValueCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,142 @@ | ||
package world.bentobox.level.commands; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
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.bentobox.util.Util; | ||
import world.bentobox.level.Level; | ||
import world.bentobox.level.panels.ValuePanel; | ||
import world.bentobox.level.util.Utils; | ||
|
||
public class IslandValueCommand extends CompositeCommand { | ||
|
||
public class IslandValueCommand extends CompositeCommand | ||
{ | ||
private final Level addon; | ||
|
||
public IslandValueCommand(Level addon, CompositeCommand parent) { | ||
|
||
public IslandValueCommand(Level addon, CompositeCommand parent) | ||
{ | ||
super(parent, "value"); | ||
this.addon = addon; | ||
} | ||
|
||
|
||
@Override | ||
public void setup() { | ||
public void setup() | ||
{ | ||
this.setPermission("island.value"); | ||
this.setDescription("island.value.description"); | ||
this.setParametersHelp("level.commands.value.parameters"); | ||
this.setDescription("level.commands.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(); | ||
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"); | ||
public boolean execute(User user, String label, List<String> args) | ||
{ | ||
if (args.size() > 1) | ||
{ | ||
this.showHelp(this, user); | ||
return true; | ||
} | ||
|
||
if (args.isEmpty()) | ||
{ | ||
ValuePanel.openPanel(this.addon, this.getWorld(), user); | ||
} | ||
else if (args.get(0).equalsIgnoreCase("HAND")) | ||
{ | ||
Player player = user.getPlayer(); | ||
PlayerInventory inventory = player.getInventory(); | ||
|
||
if (!inventory.getItemInMainHand().getType().equals(Material.AIR)) | ||
{ | ||
this.printValue(user, inventory.getItemInMainHand().getType()); | ||
} | ||
else | ||
{ | ||
Utils.sendMessage(user, user.getTranslation("level.conversations.empty-hand")); | ||
} | ||
} | ||
else | ||
{ | ||
Material material = Material.matchMaterial(args.get(0)); | ||
|
||
if (material == null) | ||
{ | ||
Utils.sendMessage(user, | ||
user.getTranslation(this.getWorld(), "level.conversations.unknown-item", | ||
"[material]", args.get(0))); | ||
} | ||
else | ||
{ | ||
this.printValue(user, material); | ||
} | ||
} else { | ||
user.sendMessage("island.value.empty-hand"); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} | ||
|
||
/** | ||
* This method prints value of the given material in chat. | ||
* @param user User who receives the message. | ||
* @param material Material value. | ||
*/ | ||
private void printValue(User user, Material material) | ||
{ | ||
Integer value = this.addon.getBlockConfig().getValue(getWorld(), material); | ||
|
||
if (value != null) | ||
{ | ||
Utils.sendMessage(user, | ||
user.getTranslation(this.getWorld(), "level.conversations.value", | ||
"[value]", String.valueOf(value), | ||
"[material]", Utils.prettifyObject(material, user))); | ||
|
||
double underWater = this.addon.getSettings().getUnderWaterMultiplier(); | ||
|
||
if (underWater > 1.0) | ||
{ | ||
Utils.sendMessage(user, | ||
user.getTranslation(this.getWorld(),"level.conversations.success-underwater", | ||
"[value]", (underWater * value) + ""), | ||
"[material]", Utils.prettifyObject(material, user)); | ||
} | ||
} | ||
else | ||
{ | ||
Utils.sendMessage(user, | ||
user.getTranslation(this.getWorld(),"level.conversations.no-value")); | ||
} | ||
} | ||
|
||
|
||
@Override | ||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) | ||
{ | ||
String lastArg = !args.isEmpty() ? args.get(args.size() - 1) : ""; | ||
|
||
if (args.isEmpty()) | ||
{ | ||
// Don't show every player on the server. Require at least the first letter | ||
return Optional.empty(); | ||
} | ||
|
||
List<String> options = new ArrayList<>(Arrays.stream(Material.values()). | ||
filter(Material::isBlock). | ||
map(Material::name).toList()); | ||
|
||
options.add("HAND"); | ||
|
||
return Optional.of(Util.tabLimit(options, lastArg)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.