Improves the books in shelf description
All checks were successful
EpicKnarvik97/Books-Without-Borders/pipeline/head This commit looks good
All checks were successful
EpicKnarvik97/Books-Without-Borders/pipeline/head This commit looks good
This commit is contained in:
@@ -22,8 +22,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static net.knarcraft.bookswithoutborders.config.BooksWithoutBordersConfig.getSuccessColor;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A listener for bookshelf clicking
|
* A listener for bookshelf clicking
|
||||||
*/
|
*/
|
||||||
@@ -61,19 +59,30 @@ public class BookshelfListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
private String getBookshelfDescription(@NotNull ChiseledBookshelfInventory bookshelfInventory) {
|
private String getBookshelfDescription(@NotNull ChiseledBookshelfInventory bookshelfInventory) {
|
||||||
StringBuilder builder = new StringBuilder(getSuccessColor() + "Books in shelf:");
|
StringBuilder builder = new StringBuilder();
|
||||||
for (ItemStack itemStack : bookshelfInventory.getStorageContents()) {
|
builder.append(ChatColor.of("#FF5700")).append("Books in shelf:").append(ChatColor.RESET);
|
||||||
|
for (int i = 0; i < bookshelfInventory.getSize(); i++) {
|
||||||
|
int index = (i % 3) + 1;
|
||||||
|
if (i % 3 == 0) {
|
||||||
|
builder.append("\n ").append(ChatColor.of("#FF5700")).append(
|
||||||
|
i < 3 ? "Top Row:" : "Bottom Row:").append(ChatColor.RESET);
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.append("\n ").append(ChatColor.of("#ffd700")).append(index).append(". ").append(ChatColor.RESET);
|
||||||
|
|
||||||
|
ItemStack itemStack = bookshelfInventory.getItem(i);
|
||||||
if (itemStack == null) {
|
if (itemStack == null) {
|
||||||
|
builder.append(ChatColor.GRAY).append("<empty>");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ItemMeta meta = itemStack.getItemMeta();
|
ItemMeta meta = itemStack.getItemMeta();
|
||||||
builder.append("\n ").append(ChatColor.GRAY).append(" - ");
|
|
||||||
if (meta instanceof BookMeta bookMeta) {
|
if (meta instanceof BookMeta bookMeta) {
|
||||||
builder.append(getBookDescription(bookMeta));
|
builder.append(getBookDescription(bookMeta));
|
||||||
} else if (meta instanceof EnchantmentStorageMeta enchantmentStorageMeta) {
|
} else if (meta instanceof EnchantmentStorageMeta enchantmentStorageMeta) {
|
||||||
builder.append(getEnchantedBookDescription(enchantmentStorageMeta));
|
builder.append(getEnchantedBookDescription(enchantmentStorageMeta));
|
||||||
} else if (meta != null) {
|
} else if (meta != null) {
|
||||||
builder.append(getPlainBookDescription(meta));
|
builder.append(ChatColor.of("#A5682A")).append("[P]").append(ChatColor.RESET).append(getPlainBookDescription(meta));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
@@ -114,7 +123,7 @@ public class BookshelfListener implements Listener {
|
|||||||
} else {
|
} else {
|
||||||
author = bookMeta.getAuthor();
|
author = bookMeta.getAuthor();
|
||||||
}
|
}
|
||||||
return title + ChatColor.RESET + " by " + author;
|
return ChatColor.of("#686868") + "[Q]" + ChatColor.RESET + title + ChatColor.RESET + " by " + author;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -126,7 +135,7 @@ public class BookshelfListener implements Listener {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private String getEnchantedBookDescription(@NotNull EnchantmentStorageMeta enchantmentStorageMeta) {
|
private String getEnchantedBookDescription(@NotNull EnchantmentStorageMeta enchantmentStorageMeta) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append("Enchanted book (");
|
builder.append(ChatColor.of("#A64CFF")).append("[E]").append(ChatColor.RESET);
|
||||||
Map<Enchantment, Integer> enchantmentMap = enchantmentStorageMeta.getStoredEnchants();
|
Map<Enchantment, Integer> enchantmentMap = enchantmentStorageMeta.getStoredEnchants();
|
||||||
List<String> enchantments = new ArrayList<>(enchantmentMap.size());
|
List<String> enchantments = new ArrayList<>(enchantmentMap.size());
|
||||||
for (Map.Entry<Enchantment, Integer> enchantmentEntry : enchantmentMap.entrySet()) {
|
for (Map.Entry<Enchantment, Integer> enchantmentEntry : enchantmentMap.entrySet()) {
|
||||||
@@ -134,7 +143,6 @@ public class BookshelfListener implements Listener {
|
|||||||
IntegerToRomanConverter.getRomanNumber(enchantmentEntry.getValue()));
|
IntegerToRomanConverter.getRomanNumber(enchantmentEntry.getValue()));
|
||||||
}
|
}
|
||||||
builder.append(String.join(", ", enchantments));
|
builder.append(String.join(", ", enchantments));
|
||||||
builder.append(")");
|
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user