Skip to content

Commit

Permalink
add display item in mob entry inventory and get description item command
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenEarth-git authored Jun 7, 2024
1 parent 8193c22 commit 4fd738a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ public ItemStack getBestiaryItem(Player player) {
lore.add(Component.text(BestiarySoulInventory.formatWell(getId().getKey()), NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false));
lore.add(Component.text("Kills: " + BestiaryManager.getKillsForMob(player, this), NamedTextColor.DARK_RED).decoration(TextDecoration.ITALIC, false));
if (!mDescription.isEmpty()) {
lore.addAll(getDescription());
for (Component line : mDescription) {
lore.add(line.color(NamedTextColor.DARK_GRAY));
}
}
if (info.allowsAccessTo(InfoTier.STATS)) {
lore.add(Component.text("Click for more info!", NamedTextColor.LIGHT_PURPLE).decoration(TextDecoration.ITALIC, false));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.playmonumenta.libraryofsouls.bestiary;

import com.playmonumenta.libraryofsouls.LibraryOfSouls;
import com.playmonumenta.libraryofsouls.Soul;
import com.playmonumenta.libraryofsouls.SoulEntry;
import com.playmonumenta.libraryofsouls.SoulsDatabase;
import com.playmonumenta.libraryofsouls.commands.LibraryOfSoulsCommand;
Expand All @@ -10,17 +9,13 @@
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.EntitySelectorArgument;
import dev.jorel.commandapi.arguments.IntegerArgument;
import dev.jorel.commandapi.arguments.StringArgument;
import dev.jorel.commandapi.arguments.TextArgument;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Item;
Expand Down Expand Up @@ -142,6 +137,26 @@ public static void register() {
}
}
})))
.withSubcommand(new CommandAPICommand("description")
.withSubcommand(new CommandAPICommand("get")
.withPermission(CommandPermission.fromString("los.bestiary.description"))
.withArguments(LibraryOfSoulsCommand.mobLabelArg)
.executesPlayer((sender, args) -> {
String name = args.getByArgument(LibraryOfSoulsCommand.mobLabelArg);
SoulEntry soul = SoulsDatabase.getInstance().getSoul(name);
if (soul == null) {
throw CommandAPI.failWithString("Mob '" + name + "' not found");
} else {
ItemStack item = new ItemStack(Material.BLAZE_POWDER);
item.lore(soul.getDescription());
Location location = sender.getLocation();
if (!sender.getInventory().addItem(item).isEmpty()) {
Item droppedItem = location.getWorld().dropItem(location, item);
droppedItem.setPickupDelay(0);
droppedItem.setCanMobPickup(false);
}
}
})))
.register();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ public BestiarySoulInventory(Player player, SoulEntry soul, BestiaryArea parent,
effectItem = getEffectItem(effectItem);
ItemStack speedItem = getSpeedItem(entityNBT, speed, speedScalar, speedPercent);

ItemStack descriptionItem = getDescriptionItem(soul);
ItemStack loreItem = getLoreItem(soul);
ItemStack equipmentPageItem = new ItemStack(Material.LIME_STAINED_GLASS_PANE);
ItemMeta meta = equipmentPageItem.getItemMeta();
Expand All @@ -477,6 +478,9 @@ public BestiarySoulInventory(Player player, SoulEntry soul, BestiaryArea parent,
_inventory.setItem(11, healthItem);
_inventory.setItem(13, armorItem);
_inventory.setItem(15, damageItem);
if (!soul.getDescription().isEmpty()) {
_inventory.setItem(16, descriptionItem);
}
_inventory.setItem(22, equipmentPageItem);
if (!soul.getLore().isEmpty()) {
_inventory.setItem(29, speedItem);
Expand Down Expand Up @@ -758,6 +762,30 @@ public ItemStack getLoreItem(SoulEntry soul) {
return loreItem;
}

public ItemStack getDescriptionItem(SoulEntry soul) {
List<Component> description = soul.getDescription();
ItemStack descriptionItem = new ItemStack(Material.BLAZE_POWDER);
ItemMeta meta = descriptionItem.getItemMeta();
meta.displayName(Component.text("Description", NamedTextColor.WHITE, TextDecoration.BOLD).decoration(TextDecoration.ITALIC, false));

if (description == null || description.isEmpty()) {
List<Component> itemDescription = new ArrayList<>();
itemDescription.add(Component.text("This is a bug. Or at the very least, should be.", NamedTextColor.WHITE).decoration(TextDecoration.ITALIC, true));
meta.lore(itemDescription);
descriptionItem.setItemMeta(meta);
return descriptionItem;
}

List<Component> itemDescription = new ArrayList<>();
for (Component comp : description) {
itemDescription.add(comp.color(NamedTextColor.GRAY));
}

meta.lore(itemDescription);
descriptionItem.setItemMeta(meta);
return descriptionItem;
}

//Legacy function, will be edited once the new boss tags system is implemented
public static List<String> formatTags(String tag) {
List<String> ret = new ArrayList<>();
Expand Down

0 comments on commit 4fd738a

Please sign in to comment.