mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-10-13 17:48:20 +02:00
@@ -1,6 +1,6 @@
|
|||||||
package com.gmail.nossr50.config.skills.alchemy;
|
package com.gmail.nossr50.config.skills.alchemy;
|
||||||
|
|
||||||
import static com.gmail.nossr50.util.ItemUtils.setItemName;
|
import static com.gmail.nossr50.util.ItemUtils.customName;
|
||||||
import static com.gmail.nossr50.util.PotionUtil.matchPotionType;
|
import static com.gmail.nossr50.util.PotionUtil.matchPotionType;
|
||||||
import static com.gmail.nossr50.util.PotionUtil.setBasePotionType;
|
import static com.gmail.nossr50.util.PotionUtil.setBasePotionType;
|
||||||
import static com.gmail.nossr50.util.PotionUtil.setUpgradedAndExtendedProperties;
|
import static com.gmail.nossr50.util.PotionUtil.setUpgradedAndExtendedProperties;
|
||||||
@@ -15,6 +15,10 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.TextComponent;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import net.kyori.adventure.text.format.TextDecoration;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -369,7 +373,9 @@ public class PotionConfig extends LegacyConfigLoader {
|
|||||||
|
|
||||||
final String configuredName = section.getString("Name", null);
|
final String configuredName = section.getString("Name", null);
|
||||||
if (configuredName != null) {
|
if (configuredName != null) {
|
||||||
setItemName(potionMeta, configuredName);
|
final TextComponent textComponent = Component.text(configuredName)
|
||||||
|
.decoration(TextDecoration.ITALIC, false);
|
||||||
|
customName(potionMeta, textComponent, configuredName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -18,6 +18,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -35,20 +36,20 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public final class ItemUtils {
|
public final class ItemUtils {
|
||||||
// Reflection for setItemName only available in newer APIs
|
// Use custom name if available
|
||||||
private static final Method setItemName;
|
private static final Method customName;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
setItemName = getSetItemName();
|
customName = getCustomNameMethod();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemUtils() {
|
private ItemUtils() {
|
||||||
// private constructor
|
// private constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Method getSetItemName() {
|
private static Method getCustomNameMethod() {
|
||||||
try {
|
try {
|
||||||
return ItemMeta.class.getMethod("setItemName", String.class);
|
return ItemMeta.class.getMethod("customName", Component.class);
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -60,17 +61,17 @@ public final class ItemUtils {
|
|||||||
* @param itemMeta The item meta to set the name on
|
* @param itemMeta The item meta to set the name on
|
||||||
* @param name The name to set
|
* @param name The name to set
|
||||||
*/
|
*/
|
||||||
public static void setItemName(ItemMeta itemMeta, String name) {
|
public static void customName(ItemMeta itemMeta, Component name, String fallbackName) {
|
||||||
if (setItemName != null) {
|
if (customName != null) {
|
||||||
setItemNameModern(itemMeta, name);
|
setItemNameModern(itemMeta, name);
|
||||||
} else {
|
} else {
|
||||||
itemMeta.setDisplayName(ChatColor.RESET + name);
|
itemMeta.setDisplayName(ChatColor.RESET + fallbackName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setItemNameModern(ItemMeta itemMeta, String name) {
|
private static void setItemNameModern(ItemMeta itemMeta, Component name) {
|
||||||
try {
|
try {
|
||||||
setItemName.invoke(itemMeta, name);
|
customName.invoke(itemMeta, name);
|
||||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||||
mcMMO.p.getLogger().severe("Failed to set item name: " + e.getMessage());
|
mcMMO.p.getLogger().severe("Failed to set item name: " + e.getMessage());
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
Reference in New Issue
Block a user