Option to hide tooltips from GUI items

This commit is contained in:
Jules 2024-07-24 19:15:13 -07:00
parent 6398872a9e
commit 94139bbe75
5 changed files with 39 additions and 10 deletions

View File

@ -15,6 +15,7 @@ import net.Indyuce.mmocore.party.AbstractParty;
import net.Indyuce.mmocore.skill.CastableSkill;
import net.Indyuce.mmocore.skill.ClassSkill;
import net.Indyuce.mmocore.skill.RegisteredSkill;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
@ -107,10 +108,14 @@ public class RPGPlaceholders extends PlaceholderExpansion {
final String attributeId = identifier.substring(23);
final PlayerAttributes.AttributeInstance attributeInstance = Objects.requireNonNull(playerData.getAttributes().getInstance(attributeId), "Could not find attribute with ID '" + attributeId + "'");
return String.valueOf(attributeInstance.getBase());
} else if (identifier.equals("level_percent")) {
}
else if (identifier.equals("level_percent")) {
double current = playerData.getExperience(), next = playerData.getLevelUpExperience();
return MythicLib.plugin.getMMOConfig().decimal.format(current / next * 100);
} else if (identifier.equals("health"))
}
else if (identifier.equals("health"))
return StatManager.format("MAX_HEALTH", player.getPlayer().getHealth());
else if (identifier.equals("max_health"))
@ -157,6 +162,21 @@ public class RPGPlaceholders extends PlaceholderExpansion {
return info == null ? "" : info.getSkill().getHandler().getId();
}
// Returns the casting slot taking into account the skill slot offset
else if (identifier.startsWith("cast_slot_offset_")) {
final Player online = player.getPlayer();
Validate.notNull(online, "Player is offline");
final int slot = Integer.parseInt(identifier.substring(17));
return String.valueOf(slot + (online.getInventory().getHeldItemSlot() < slot ? 1 : 0));
}
// Is there a passive skill bound to given slot
else if (identifier.startsWith("passive_bound_")) {
final int slot = Integer.parseInt(identifier.substring(14));
final ClassSkill skill = playerData.getBoundSkill(slot);
return String.valueOf(skill != null && skill.getSkill().getTrigger().isPassive());
}
// Returns the bound skill name
else if (identifier.startsWith("bound_")) {
final int slot = Math.max(1, Integer.parseInt(identifier.substring(6)));
@ -165,6 +185,7 @@ public class RPGPlaceholders extends PlaceholderExpansion {
return (playerData.getCooldownMap().isOnCooldown(skill) ? ChatColor.RED : ChatColor.GREEN) + skill.getSkill().getName();
}
// Returns cooldown of skill bound at given slot
else if (identifier.startsWith("cooldown_bound_")) {
int slot = Math.max(0, Integer.parseInt(identifier.substring(15)));
if (playerData.hasSkillBound(slot))

View File

@ -71,8 +71,8 @@ public class ClassSelect extends EditableInventory {
public ItemStack display(ProfessSelectionInventory inv, int n) {
ItemStack item = n == 0 ? playerClass.getIcon() : super.display(inv, n);
ItemMeta meta = item.getItemMeta();
if (hideFlags())
meta.addItemFlags(ItemFlag.values());
if (hideFlags()) meta.addItemFlags(ItemFlag.values());
if (hideTooltip()) meta.setHideTooltip(true);
meta.setDisplayName(MythicLib.plugin.parseColors(name).replace("{name}", playerClass.getName()));
List<String> lore = new ArrayList<>(this.lore);

View File

@ -62,8 +62,8 @@ public class SubclassSelect extends EditableInventory {
public ItemStack display(SubclassSelectionInventory inv, int n) {
ItemStack item = n == 0 ? playerClass.getIcon() : super.display(inv, n);
ItemMeta meta = item.getItemMeta();
if (hideFlags())
meta.addItemFlags(ItemFlag.values());
if (hideFlags()) meta.addItemFlags(ItemFlag.values());
if (hideTooltip()) meta.setHideTooltip(true);
meta.setDisplayName(MythicLib.plugin.parseColors(name).replace("{name}", playerClass.getName()));
List<String> lore = new ArrayList<>(this.lore);

View File

@ -152,6 +152,7 @@ public class WaypointViewer extends EditableInventory {
if (hasName()) meta.setDisplayName(placeholders.apply(effectivePlayer, getName()));
if (hideFlags()) meta.addItemFlags(ItemFlag.values());
if (hideTooltip()) meta.setHideTooltip(true);
// If a player can teleport to another waypoint given his location
Waypoint waypoint = inv.waypoints.get(inv.page * inv.getEditable().getByFunction("waypoint").getSlots().size() + n);

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmocore.gui.api.item;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods;
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
import org.bukkit.ChatColor;
@ -28,7 +29,7 @@ public abstract class InventoryItem<T extends GeneratedInventory> {
private final String name, texture;
private final List<String> lore;
private final int modelData;
private final boolean hideFlags;
private final boolean hideFlags, hideTooltip;
public InventoryItem(ConfigurationSection config) {
this((InventoryItem) null, config);
@ -51,6 +52,7 @@ public abstract class InventoryItem<T extends GeneratedInventory> {
this.name = config.getString("name");
this.lore = config.getStringList("lore");
this.hideFlags = config.getBoolean("hide-flags");
this.hideTooltip = config.getBoolean("hide-tooltip") && MythicLib.plugin.getVersion().isAbove(1, 20, 5);
this.texture = config.getString("texture");
this.modelData = config.getInt("custom-model-data");
@ -83,6 +85,10 @@ public abstract class InventoryItem<T extends GeneratedInventory> {
return hideFlags;
}
public boolean hideTooltip() {
return hideTooltip;
}
public boolean hasName() {
return name != null;
}
@ -152,6 +158,7 @@ public abstract class InventoryItem<T extends GeneratedInventory> {
if (hasName()) meta.setDisplayName(placeholders.apply(effectivePlayer, getName()));
if (hideFlags()) meta.addItemFlags(ItemFlag.values());
if (hideTooltip()) meta.setHideTooltip(true);
if (hasLore()) {
List<String> lore = new ArrayList<>();
@ -167,9 +174,9 @@ public abstract class InventoryItem<T extends GeneratedInventory> {
* @param inv Inventory being generated
* @param n Index of item being generated
* @return Player relative to which placeholders are computed when the item is
* being displayed in the inventory. Most of the time, it's just
* the player opening the inventory, but for friends or party members,
* being able to parse placeholders based on other players is great too.
* being displayed in the inventory. Most of the time, it's just
* the player opening the inventory, but for friends or party members,
* being able to parse placeholders based on other players is great too.
*/
@NotNull
public OfflinePlayer getEffectivePlayer(T inv, int n) {