Skip to content

Commit

Permalink
fix(Items): 无法使用学识巨著
Browse files Browse the repository at this point in the history
  • Loading branch information
mcchampions committed Oct 4, 2024
1 parent e88516b commit faacb1d
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
import io.github.thebusybiscuit.slimefun4.core.services.sounds.SoundEffect;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;

import java.util.List;
import java.util.UUID;

import me.qscbm.slimefun4.message.QsTextComponentImpl;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Result;
Expand All @@ -28,7 +30,6 @@
* from one {@link Player} to another.
*
* @author TheBusyBiscuit
*
*/
public class KnowledgeTome extends SimpleSlimefunItem<ItemUseHandler> {
public KnowledgeTome(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
Expand All @@ -46,18 +47,20 @@ public ItemUseHandler getItemHandler() {
ItemMeta im = item.getItemMeta();
List<Component> lore = im.lore();

Component fc = lore.get(1);
Component fc = lore.get(0);

if (!(fc instanceof TextComponent firstComponent)) return;

if (firstComponent.content().isEmpty()) {
List<Component> list = firstComponent.children();
if (list.size() >= 2 && ((TextComponent) list.get(1)).content().equals("None")) {
lore.set(0, new QsTextComponentImpl("主人: ").color(NamedTextColor.GRAY)
.append(new QsTextComponentImpl(p.getName()).color(NamedTextColor.GRAY)));
lore.set(1, new QsTextComponentImpl(p.getUniqueId().toString()).color(NamedTextColor.BLACK));
im.lore(lore);
item.setItemMeta(im);
SoundEffect.TOME_OF_KNOWLEDGE_USE_SOUND.playFor(p);
} else {
UUID uuid = UUID.fromString(firstComponent.content());
UUID uuid = UUID.fromString(((TextComponent) lore.get(1)).content());

if (p.getUniqueId().equals(uuid)) {
Slimefun.getLocalization().sendMessage(p, "messages.no-tome-yourself");
Expand Down

0 comments on commit faacb1d

Please sign in to comment.