1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-02-27 17:52:17 +01:00

Use the deprecated methods to set item name or lore to support CMI's gradient colors

This commit is contained in:
montlikadani 2021-05-06 20:45:39 +02:00
parent acbba56ee6
commit 327da4fa3e
10 changed files with 61 additions and 62 deletions

View File

@ -141,8 +141,8 @@ public class GuiManager {
ItemStack guiItem = job.getGuiItem(); ItemStack guiItem = job.getGuiItem();
ItemMeta meta = guiItem.getItemMeta(); ItemMeta meta = guiItem.getItemMeta();
plugin.getComplement().setDisplayName(meta, job.getJobDisplayName()); meta.setDisplayName(job.getJobDisplayName());
plugin.getComplement().setLore(meta, lore); meta.setLore(lore);
if (Jobs.getGCManager().hideItemAttributes) { if (Jobs.getGCManager().hideItemAttributes) {
meta.addItemFlags(org.bukkit.inventory.ItemFlag.HIDE_ATTRIBUTES, org.bukkit.inventory.ItemFlag.HIDE_ENCHANTS); meta.addItemFlags(org.bukkit.inventory.ItemFlag.HIDE_ATTRIBUTES, org.bukkit.inventory.ItemFlag.HIDE_ENCHANTS);
@ -275,8 +275,8 @@ public class GuiManager {
continue; continue;
ItemMeta meta = guiItem.getItemMeta(); ItemMeta meta = guiItem.getItemMeta();
plugin.getComplement().setDisplayName(meta, job.getJobDisplayName()); meta.setDisplayName(job.getJobDisplayName());
plugin.getComplement().setLore(meta, lore); meta.setLore(lore);
guiItem.setItemMeta(meta); guiItem.setItemMeta(meta);
tempInv.setItem(i, guiItem.clone()); tempInv.setItem(i, guiItem.clone());
@ -295,8 +295,8 @@ public class GuiManager {
} }
ItemMeta meta = guiItem.getItemMeta(); ItemMeta meta = guiItem.getItemMeta();
plugin.getComplement().setDisplayName(meta, job.getJobDisplayName()); meta.setDisplayName(job.getJobDisplayName());
plugin.getComplement().setLore(meta, lore); meta.setLore(lore);
guiItem.setItemMeta(meta); guiItem.setItemMeta(meta);
tempInv.setItem(i, guiItem.clone()); tempInv.setItem(i, guiItem.clone());
i++; i++;
@ -327,7 +327,7 @@ public class GuiManager {
ItemStack back = Jobs.getGCManager().guiBackButton; ItemStack back = Jobs.getGCManager().guiBackButton;
ItemMeta meta = back.getItemMeta(); ItemMeta meta = back.getItemMeta();
plugin.getComplement().setDisplayName(meta, Jobs.getLanguage().getMessage("command.info.gui.back")); meta.setDisplayName(Jobs.getLanguage().getMessage("command.info.gui.back"));
back.setItemMeta(meta); back.setItemMeta(meta);
gui.addButton(new CMIGuiButton(backButton, back) { gui.addButton(new CMIGuiButton(backButton, back) {
@ -342,7 +342,7 @@ public class GuiManager {
ItemStack next = Jobs.getGCManager().guiNextButton; ItemStack next = Jobs.getGCManager().guiNextButton;
ItemMeta meta = next.getItemMeta(); ItemMeta meta = next.getItemMeta();
plugin.getComplement().setDisplayName(meta, Jobs.getLanguage().getMessage("command.info.gui.next")); meta.setDisplayName(Jobs.getLanguage().getMessage("command.info.gui.next"));
next.setItemMeta(meta); next.setItemMeta(meta);
gui.addButton(new CMIGuiButton(nextButton, next) { gui.addButton(new CMIGuiButton(nextButton, next) {
@ -426,8 +426,8 @@ public class GuiManager {
} }
ItemMeta meta = guiItem.getItemMeta(); ItemMeta meta = guiItem.getItemMeta();
plugin.getComplement().setDisplayName(meta, job.getJobDisplayName()); meta.setDisplayName(job.getJobDisplayName());
plugin.getComplement().setLore(meta, lore); meta.setLore(lore);
guiItem.setItemMeta(meta); guiItem.setItemMeta(meta);
tempInv.setItem(i, guiItem.clone()); tempInv.setItem(i, guiItem.clone());
@ -445,8 +445,8 @@ public class GuiManager {
} }
ItemMeta meta = guiItem.getItemMeta(); ItemMeta meta = guiItem.getItemMeta();
plugin.getComplement().setDisplayName(meta, job.getJobDisplayName()); meta.setDisplayName(job.getJobDisplayName());
plugin.getComplement().setLore(meta, lore); meta.setLore(lore);
guiItem.setItemMeta(meta); guiItem.setItemMeta(meta);
tempInv.setItem(i, guiItem.clone()); tempInv.setItem(i, guiItem.clone());
i++; i++;
@ -477,7 +477,7 @@ public class GuiManager {
ItemStack skull = Jobs.getGCManager().guiBackButton; ItemStack skull = Jobs.getGCManager().guiBackButton;
ItemMeta skullMeta = skull.getItemMeta(); ItemMeta skullMeta = skull.getItemMeta();
plugin.getComplement().setDisplayName(skullMeta, Jobs.getLanguage().getMessage("command.info.gui.back")); skullMeta.setDisplayName(Jobs.getLanguage().getMessage("command.info.gui.back"));
skull.setItemMeta(skullMeta); skull.setItemMeta(skullMeta);
gui.addButton(new CMIGuiButton(backButton, skull) { gui.addButton(new CMIGuiButton(backButton, skull) {

View File

@ -97,6 +97,8 @@ public class Jobs extends JavaPlugin {
private final Set<BlockOwnerShip> blockOwnerShips = new HashSet<>(); private final Set<BlockOwnerShip> blockOwnerShips = new HashSet<>();
private boolean kyoriSupported = false;
private CMIScoreboardManager cmiScoreboardManager; private CMIScoreboardManager cmiScoreboardManager;
private Complement complement; private Complement complement;
private GuiManager guiManager; private GuiManager guiManager;
@ -122,6 +124,10 @@ public class Jobs extends JavaPlugin {
return complement; return complement;
} }
public boolean isKyoriSupported() {
return kyoriSupported;
}
/** /**
* Returns the block owner ship for specific {@link CMIMaterial} type. * Returns the block owner ship for specific {@link CMIMaterial} type.
* *
@ -246,7 +252,7 @@ public class Jobs extends JavaPlugin {
public static ShopManager getShopManager() { public static ShopManager getShopManager() {
if (shopManager == null) { if (shopManager == null) {
shopManager = new ShopManager(instance); shopManager = new ShopManager();
} }
return shopManager; return shopManager;
} }
@ -693,6 +699,12 @@ public class Jobs extends JavaPlugin {
return; return;
} }
try {
Class.forName("net.kyori.adventure.text.Component");
kyoriSupported = true;
} catch (ClassNotFoundException e) {
}
placeholderAPIEnabled = setupPlaceHolderAPI(); placeholderAPIEnabled = setupPlaceHolderAPI();
try { try {
@ -729,13 +741,6 @@ public class Jobs extends JavaPlugin {
getServer().getPluginManager().registerEvents(new PistonProtectionListener(), this); getServer().getPluginManager().registerEvents(new PistonProtectionListener(), this);
} }
boolean kyoriSupported = false;
try {
Class.forName("net.kyori.adventure.text.serializer.plain.PlainComponentSerializer");
kyoriSupported = true;
} catch (ClassNotFoundException e) {
}
if (Version.isCurrentEqualOrHigher(Version.v1_16_R3) && kyoriSupported) { if (Version.isCurrentEqualOrHigher(Version.v1_16_R3) && kyoriSupported) {
complement = new Complement2(); complement = new Complement2();
//getServer().getPluginManager().registerEvents(new KyoriChatEvent(this), this); //getServer().getPluginManager().registerEvents(new KyoriChatEvent(this), this);

View File

@ -263,7 +263,7 @@ public class SignUtil {
} }
if (!line.isEmpty()) if (!line.isEmpty())
plugin.getComplement().setLine(sign, i, line); sign.setLine(i, line);
} }
sign.update(); sign.update();
if (!updateHead(sign, playerList.get(0).getPlayerInfo().getName(), timelapse)) { if (!updateHead(sign, playerList.get(0).getPlayerInfo().getName(), timelapse)) {
@ -280,22 +280,22 @@ public class SignUtil {
} }
int no = jSign.getNumber() + number + 1; int no = jSign.getNumber() + number + 1;
plugin.getComplement().setLine(sign, 0, translateSignLine("signs.SpecialList.p" + jSign.getNumber(), no, playerName, pl.getLevel(), signJobName)); sign.setLine(0, translateSignLine("signs.SpecialList.p" + jSign.getNumber(), no, playerName, pl.getLevel(), signJobName));
plugin.getComplement().setLine(sign, 1, translateSignLine("signs.SpecialList.name", no, playerName, pl.getLevel(), signJobName)); sign.setLine(1, translateSignLine("signs.SpecialList.name", no, playerName, pl.getLevel(), signJobName));
switch (type) { switch (type) {
case toplist: case toplist:
case gtoplist: case gtoplist:
plugin.getComplement().setLine(sign, 2, translateSignLine("signs.SpecialList.level", no, playerName, pl.getLevel(), signJobName)); sign.setLine(2, translateSignLine("signs.SpecialList.level", no, playerName, pl.getLevel(), signJobName));
break; break;
case questtoplist: case questtoplist:
plugin.getComplement().setLine(sign, 2, Jobs.getLanguage().getMessage("signs.SpecialList.quests", "[number]", no, "[player]", playerName, "[quests]", pl.getLevel(), "[job]", signJobName)); sign.setLine(2, Jobs.getLanguage().getMessage("signs.SpecialList.quests", "[number]", no, "[player]", playerName, "[quests]", pl.getLevel(), "[job]", signJobName));
break; break;
default: default:
break; break;
} }
plugin.getComplement().setLine(sign, 3, translateSignLine("signs.SpecialList.bottom", no, playerName, pl.getLevel(), signJobName)); sign.setLine(3, translateSignLine("signs.SpecialList.bottom", no, playerName, pl.getLevel(), signJobName));
sign.update(); sign.update();
if (!updateHead(sign, pl.getPlayerInfo().getName(), timelapse)) { if (!updateHead(sign, pl.getPlayerInfo().getName(), timelapse)) {
timelapse--; timelapse--;

View File

@ -41,14 +41,8 @@ import com.gamingmesh.jobs.stuff.GiveItem;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class ShopManager { public class ShopManager {
private Jobs plugin;
private final List<ShopItem> list = new ArrayList<>(); private final List<ShopItem> list = new ArrayList<>();
public ShopManager(Jobs plugin) {
this.plugin = plugin;
}
public List<ShopItem> getShopItemList() { public List<ShopItem> getShopItemList() {
return list; return list;
} }
@ -144,7 +138,7 @@ public class ShopManager {
guiItem.setAmount(item.getIconAmount()); guiItem.setAmount(item.getIconAmount());
if (item.getIconName() != null) if (item.getIconName() != null)
plugin.getComplement().setDisplayName(meta, item.getIconName()); meta.setDisplayName(item.getIconName());
lore.addAll(item.getIconLore()); lore.addAll(item.getIconLore());
@ -183,17 +177,19 @@ public class ShopManager {
? Jobs.getLanguage().getMessage("command.shop.info.reqTotalLevelColor") : "") + item.getRequiredTotalLevels())); ? Jobs.getLanguage().getMessage("command.shop.info.reqTotalLevelColor") : "") + item.getRequiredTotalLevels()));
} }
plugin.getComplement().setLore(meta, lore); meta.setLore(lore);
if (item.getCustomHead() != null) { if (item.getCustomHead() != null) {
guiItem = CMIMaterial.PLAYER_HEAD.newItemStack(); guiItem = CMIMaterial.PLAYER_HEAD.newItemStack(item.getIconAmount());
SkullMeta skullMeta = (SkullMeta) guiItem.getItemMeta(); SkullMeta skullMeta = (SkullMeta) guiItem.getItemMeta();
if (skullMeta == null) if (skullMeta == null)
continue; continue;
plugin.getComplement().setDisplayName(skullMeta, item.getIconName()); if (item.getIconName() != null)
plugin.getComplement().setLore(skullMeta, lore); skullMeta.setDisplayName(item.getIconName());
skullMeta.setLore(lore);
if (item.isHeadOwner()) { if (item.isHeadOwner()) {
Jobs.getNms().setSkullOwner(skullMeta, jPlayer.getPlayer()); Jobs.getNms().setSkullOwner(skullMeta, jPlayer.getPlayer());
@ -277,7 +273,7 @@ public class ShopManager {
int prevSlot = getPrevButtonSlot(guiSize.getFields(), page); int prevSlot = getPrevButtonSlot(guiSize.getFields(), page);
if (prevSlot != -1 && page > 1) { if (prevSlot != -1 && page > 1) {
plugin.getComplement().setDisplayName(meta, Jobs.getLanguage().getMessage("command.help.output.prevPage")); meta.setDisplayName(Jobs.getLanguage().getMessage("command.help.output.prevPage"));
item.setItemMeta(meta); item.setItemMeta(meta);
gui.addButton(new CMIGuiButton(prevSlot, item) { gui.addButton(new CMIGuiButton(prevSlot, item) {
@ -290,7 +286,7 @@ public class ShopManager {
int nextSlot = getNextButtonSlot(guiSize.getFields(), page); int nextSlot = getNextButtonSlot(guiSize.getFields(), page);
if (nextSlot != -1 && !getItemsByPage(page + 1).isEmpty()) { if (nextSlot != -1 && !getItemsByPage(page + 1).isEmpty()) {
plugin.getComplement().setDisplayName(meta, Jobs.getLanguage().getMessage("command.help.output.nextPage")); meta.setDisplayName(Jobs.getLanguage().getMessage("command.help.output.nextPage"));
item.setItemMeta(meta); item.setItemMeta(meta);
gui.addButton(new CMIGuiButton(nextSlot, item) { gui.addButton(new CMIGuiButton(nextSlot, item) {
@Override @Override
@ -342,8 +338,6 @@ public class ShopManager {
} }
sItem.setIconAmount(nameSection.getInt("Icon.Amount", 1)); sItem.setIconAmount(nameSection.getInt("Icon.Amount", 1));
if (nameSection.isString("Icon.Name"))
sItem.setIconName(CMIChatColor.translate(nameSection.getString("Icon.Name"))); sItem.setIconName(CMIChatColor.translate(nameSection.getString("Icon.Name")));
List<String> lore = nameSection.getStringList("Icon.Lore"); List<String> lore = nameSection.getStringList("Icon.Lore");

View File

@ -68,7 +68,7 @@ public class JobLimitedItems {
Jobs plugin = org.bukkit.plugin.java.JavaPlugin.getPlugin(Jobs.class); Jobs plugin = org.bukkit.plugin.java.JavaPlugin.getPlugin(Jobs.class);
if (name != null) if (name != null)
plugin.getComplement().setDisplayName(meta, CMIChatColor.translate(name)); meta.setDisplayName(CMIChatColor.translate(name));
if (lore != null && !lore.isEmpty()) { if (lore != null && !lore.isEmpty()) {
List<String> translatedLore = new ArrayList<>(); List<String> translatedLore = new ArrayList<>();
@ -76,7 +76,7 @@ public class JobLimitedItems {
translatedLore.add(CMIChatColor.translate(oneLore.replace("[player]", player.getName()))); translatedLore.add(CMIChatColor.translate(oneLore.replace("[player]", player.getName())));
} }
plugin.getComplement().setLore(meta, translatedLore); meta.setLore(translatedLore);
} }
if (enchants != null) if (enchants != null)

View File

@ -11,7 +11,7 @@ public class ShopItem {
private int slot = -1, page = -1, iconAmount = 1; private int slot = -1, page = -1, iconAmount = 1;
private String nodeName = null, iconMaterial = null, iconName = null; private String nodeName, iconMaterial, iconName;
private boolean hideWithoutPerm = false; private boolean hideWithoutPerm = false;
private boolean hideNoEnoughPoint = false; private boolean hideNoEnoughPoint = false;

View File

@ -307,10 +307,11 @@ public class JobsListener implements Listener {
if (!Jobs.getGCManager().SignsEnabled) if (!Jobs.getGCManager().SignsEnabled)
return; return;
String line1 = CMIChatColor.stripColor(plugin.getComplement().getLine(event, 1));
if (CMIChatColor.stripColor(plugin.getComplement().getLine(event, 0)) if (CMIChatColor.stripColor(plugin.getComplement().getLine(event, 0))
.equalsIgnoreCase(CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.topline"))) && !CMIChatColor.stripColor( .equalsIgnoreCase(CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.topline"))) && !line1.equalsIgnoreCase("toplist"))
plugin.getComplement().getLine(event, 1)).equalsIgnoreCase("toplist")) event.setLine(0, convert(Jobs.getLanguage().getMessage("signs.topline")));
plugin.getComplement().setLine(event, 0, convert(Jobs.getLanguage().getMessage("signs.topline")));
else else
return; return;
@ -320,11 +321,11 @@ public class JobsListener implements Listener {
return; return;
} }
String command = CMIChatColor.stripColor(plugin.getComplement().getLine(event, 1)).toLowerCase();
for (String key : Jobs.getLanguageManager().signKeys) { for (String key : Jobs.getLanguageManager().signKeys) {
String secondLine = Jobs.getLanguage().getMessage("signs.secondline." + key); String secondLine = Jobs.getLanguage().getMessage("signs.secondline." + key);
if (command.equalsIgnoreCase(CMIChatColor.stripColor(secondLine))) {
plugin.getComplement().setLine(event, 1, convert(secondLine)); if (line1.equalsIgnoreCase(CMIChatColor.stripColor(secondLine))) {
event.setLine(1, convert(secondLine));
break; break;
} }
} }
@ -334,7 +335,7 @@ public class JobsListener implements Listener {
return; return;
String color = Jobs.getGCManager().SignsColorizeJobName ? job.getChatColor().toString() : ""; String color = Jobs.getGCManager().SignsColorizeJobName ? job.getChatColor().toString() : "";
plugin.getComplement().setLine(event, 2, convert(color + job.getName())); event.setLine(2, convert(color + job.getName()));
} }
private final Pattern pattern = Pattern.compile("&([0-9a-fk-or])"); private final Pattern pattern = Pattern.compile("&([0-9a-fk-or])");

View File

@ -9,9 +9,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMILib.CMIChatColor; import com.gamingmesh.jobs.CMILib.CMIChatColor;
import com.gamingmesh.jobs.CMILib.CMIMaterial; import com.gamingmesh.jobs.CMILib.CMIMaterial;
@ -26,15 +24,13 @@ public class GiveItem {
return; return;
} }
Jobs plugin = JavaPlugin.getPlugin(Jobs.class);
if (lore != null && !lore.isEmpty()) { if (lore != null && !lore.isEmpty()) {
List<String> translatedLore = new ArrayList<>(); List<String> translatedLore = new ArrayList<>();
for (String oneLore : lore) { for (String oneLore : lore) {
translatedLore.add(CMIChatColor.translate(oneLore.replace("[player]", player.getName()))); translatedLore.add(CMIChatColor.translate(oneLore.replace("[player]", player.getName())));
} }
plugin.getComplement().setLore(itemMeta, translatedLore); itemMeta.setLore(translatedLore);
} }
if (enchants != null) { if (enchants != null) {
@ -51,7 +47,7 @@ public class GiveItem {
} }
if (name != null) if (name != null)
plugin.getComplement().setDisplayName(itemMeta, CMIChatColor.translate(name)); itemMeta.setDisplayName(CMIChatColor.translate(name));
itemStack.setItemMeta(itemMeta); itemStack.setItemMeta(itemMeta);
giveItemForPlayer(player, itemStack); giveItemForPlayer(player, itemStack);

View File

@ -12,6 +12,7 @@ import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
public class Complement2 implements Complement { public class Complement2 implements Complement {
@ -20,13 +21,14 @@ public class Complement2 implements Complement {
return LegacyComponentSerializer.legacyAmpersand().serialize(component); return LegacyComponentSerializer.legacyAmpersand().serialize(component);
} }
protected Component deserialize(String t) { protected TextComponent deserialize(String t) {
return Component.text(t); return LegacyComponentSerializer.legacyAmpersand().deserialize(t);
} }
@Override @Override
public String getDisplayName(ItemMeta meta) { public String getDisplayName(ItemMeta meta) {
Component dName = null; Component dName = null;
try { try {
dName = meta.displayName(); dName = meta.displayName();
} catch (NoSuchMethodError e) { } catch (NoSuchMethodError e) {

View File

@ -20,8 +20,9 @@ Items:
HideIfThereIsNoEnoughPoints: false HideIfThereIsNoEnoughPoints: false
# (Optional) When you want to use Player Head material with skin then use this # (Optional) When you want to use Player Head material with skin then use this
#CustomHead: #CustomHead:
# PlayerName: playerName # You can specify here valid player name or uuid.
# Using the current player (if have job) who opened the gui. The PlayerName string is ignoring if this exist. # PlayerName: playerNameOrUUID
# Use the current player who opened the gui, so the head skin will be this player who opened.
# UseCurrentPlayer: true # UseCurrentPlayer: true
# (Optional) List of permissions required to buy this item # (Optional) List of permissions required to buy this item
RequiredPermission: RequiredPermission: