Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.bukkit.Nameable;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
Expand All @@ -54,8 +55,7 @@ public boolean onCommand(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String label,
@NotNull String[] args
) {
@NotNull String[] args) {
if (!(sender instanceof Player senderPlayer)) {
lang.sendMessage(sender, "messages.error.consoleUnsupported");
return true;
Expand All @@ -72,8 +72,7 @@ public boolean onCommand(
lang.sendMessage(
sender,
"messages.error.invalidMaterial",
new Replacement("%target%", args[0])
);
new Replacement("%target%", args[0]));
return false;
}

Expand All @@ -95,6 +94,7 @@ public boolean onCommand(
World world = senderPlayer.getWorld();
Chunk centerChunk = senderPlayer.getLocation().getChunk();
StringBuilder locations = new StringBuilder();
locations.append("\n");

for (int dX = -radius; dX <= radius; ++dX) {
for (int dZ = -radius; dZ <= radius; ++dZ) {
Expand All @@ -109,31 +109,32 @@ public boolean onCommand(
if (!SearchHelper.findMatch(holder.getInventory(), itemStack -> itemStack.getType() == material)) {
continue;
}
locations.append(holder.getInventory().getType().name().toLowerCase(Locale.ENGLISH)).append(" (")
.append(tileEntity.getX()).append(',').append(tileEntity.getY()).append(',')
.append(tileEntity.getZ()).append("), ");
locations.append(holder.getInventory().getType().name().toLowerCase(Locale.ENGLISH)).append(": ");
if (holder instanceof Nameable named) {
String customName = named.getCustomName();
if (customName != null) {
locations.append(customName.toLowerCase(Locale.ENGLISH).strip()).append(" - ");
}
}
locations.append(" (").append(tileEntity.getX()).append(',').append(tileEntity.getY()).append(',')
.append(tileEntity.getZ()).append(")\n");
}
}
}

// Matches found, delete trailing comma and space
if (!locations.isEmpty()) {
locations.delete(locations.length() - 2, locations.length());
} else {
if (locations.length() < 2) {
lang.sendMessage(
sender,
"messages.info.container.noMatches",
new Replacement("%target%", material.name())
);
new Replacement("%target%", material.name()));
return true;
}

lang.sendMessage(
sender,
"messages.info.container.matches",
new Replacement("%target%", material.name()),
new Replacement("%detail%", locations.toString())
);
new Replacement("%detail%", locations.toString()));
return true;
}

Expand All @@ -142,8 +143,7 @@ public List<String> onTabComplete(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String label,
String[] args
) {
String[] args) {
if (args.length < 1 || args.length > 2 || !command.testPermissionSilent(sender)) {
return Collections.emptyList();
}
Expand Down