Skip to content

Commit

Permalink
Add parseComponents to setTitle
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Nov 25, 2023
1 parent 8eb20f8 commit f7544ab
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
15 changes: 9 additions & 6 deletions src/main/java/net/citizensnpcs/api/gui/InventoryMenu.java
Expand Up @@ -362,10 +362,13 @@ public void onInventoryDrag(InventoryDragEvent event) {
}

private InventoryView openInventory(HumanEntity player, Inventory inventory, String title) {
if (inventory.getType() == InventoryType.ANVIL)
return CitizensAPI.getNMSHelper().openAnvilInventory((Player) player, inventory, title);
else
return player.openInventory(inventory);
InventoryView view;
if (inventory.getType() == InventoryType.ANVIL) {
view = CitizensAPI.getNMSHelper().openAnvilInventory((Player) player, inventory, title);
} else {
view = player.openInventory(inventory);
}
return view;
}

private InventoryMenuPattern parsePattern(int[] dim, List<InventoryMenuTransition> transitions,
Expand Down Expand Up @@ -587,9 +590,9 @@ private void transitionViewersToInventory(Inventory inventory) {
views = Lists.newArrayListWithExpectedSize(old.size());
for (InventoryView view : old) {
view.close();
if (!view.getPlayer().isValid() || inventory == null) {
if (!view.getPlayer().isValid() || inventory == null)
continue;
}

views.add(openInventory(view.getPlayer(), inventory, page.ctx.getTitle()));
}
transitioning = false;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/net/citizensnpcs/api/gui/MenuContext.java
Expand Up @@ -7,6 +7,8 @@

import com.google.common.collect.Maps;

import net.citizensnpcs.api.util.Messaging;

/**
* A context class passed into the constructor of a {@link Menu} instance.
*/
Expand Down Expand Up @@ -64,7 +66,7 @@ public String getTitle() {
}

public void setTitle(String title) {
this.title = title;
this.title = Messaging.parseComponents(title);
this.menu.updateTitle(title);
}
}
4 changes: 2 additions & 2 deletions src/main/java/net/citizensnpcs/api/npc/AbstractNPC.java
Expand Up @@ -384,10 +384,10 @@ public void removeTrait(Class<? extends Trait> traitClass) {

@Override
public boolean requiresNameHologram() {
return !data().has(NPC.Metadata.HOLOGRAM_FOR) && ((name.length() > 16 && getEntityType() == EntityType.PLAYER)
return (name.length() > 16 && getEntityType() == EntityType.PLAYER)
|| data().get(NPC.Metadata.ALWAYS_USE_NAME_HOLOGRAM, false)
|| (coloredNameStringCache != null && coloredNameStringCache.contains("§x"))
|| !Placeholders.replaceName(name, null, this).equals(name));
|| !Placeholders.replaceName(name, null, this).equals(name);
}

@Override
Expand Down

0 comments on commit f7544ab

Please sign in to comment.