1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 14:05:25 +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();
ItemMeta meta = guiItem.getItemMeta();
plugin.getComplement().setDisplayName(meta, job.getJobDisplayName());
plugin.getComplement().setLore(meta, lore);
meta.setDisplayName(job.getJobDisplayName());
meta.setLore(lore);
if (Jobs.getGCManager().hideItemAttributes) {
meta.addItemFlags(org.bukkit.inventory.ItemFlag.HIDE_ATTRIBUTES, org.bukkit.inventory.ItemFlag.HIDE_ENCHANTS);
@ -275,8 +275,8 @@ public class GuiManager {
continue;
ItemMeta meta = guiItem.getItemMeta();
plugin.getComplement().setDisplayName(meta, job.getJobDisplayName());
plugin.getComplement().setLore(meta, lore);
meta.setDisplayName(job.getJobDisplayName());
meta.setLore(lore);
guiItem.setItemMeta(meta);
tempInv.setItem(i, guiItem.clone());
@ -295,8 +295,8 @@ public class GuiManager {
}
ItemMeta meta = guiItem.getItemMeta();
plugin.getComplement().setDisplayName(meta, job.getJobDisplayName());
plugin.getComplement().setLore(meta, lore);
meta.setDisplayName(job.getJobDisplayName());
meta.setLore(lore);
guiItem.setItemMeta(meta);
tempInv.setItem(i, guiItem.clone());
i++;
@ -327,7 +327,7 @@ public class GuiManager {
ItemStack back = Jobs.getGCManager().guiBackButton;
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);
gui.addButton(new CMIGuiButton(backButton, back) {
@ -342,7 +342,7 @@ public class GuiManager {
ItemStack next = Jobs.getGCManager().guiNextButton;
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);
gui.addButton(new CMIGuiButton(nextButton, next) {
@ -426,8 +426,8 @@ public class GuiManager {
}
ItemMeta meta = guiItem.getItemMeta();
plugin.getComplement().setDisplayName(meta, job.getJobDisplayName());
plugin.getComplement().setLore(meta, lore);
meta.setDisplayName(job.getJobDisplayName());
meta.setLore(lore);
guiItem.setItemMeta(meta);
tempInv.setItem(i, guiItem.clone());
@ -445,8 +445,8 @@ public class GuiManager {
}
ItemMeta meta = guiItem.getItemMeta();
plugin.getComplement().setDisplayName(meta, job.getJobDisplayName());
plugin.getComplement().setLore(meta, lore);
meta.setDisplayName(job.getJobDisplayName());
meta.setLore(lore);
guiItem.setItemMeta(meta);
tempInv.setItem(i, guiItem.clone());
i++;
@ -477,7 +477,7 @@ public class GuiManager {
ItemStack skull = Jobs.getGCManager().guiBackButton;
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);
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 boolean kyoriSupported = false;
private CMIScoreboardManager cmiScoreboardManager;
private Complement complement;
private GuiManager guiManager;
@ -122,6 +124,10 @@ public class Jobs extends JavaPlugin {
return complement;
}
public boolean isKyoriSupported() {
return kyoriSupported;
}
/**
* Returns the block owner ship for specific {@link CMIMaterial} type.
*
@ -246,7 +252,7 @@ public class Jobs extends JavaPlugin {
public static ShopManager getShopManager() {
if (shopManager == null) {
shopManager = new ShopManager(instance);
shopManager = new ShopManager();
}
return shopManager;
}
@ -693,6 +699,12 @@ public class Jobs extends JavaPlugin {
return;
}
try {
Class.forName("net.kyori.adventure.text.Component");
kyoriSupported = true;
} catch (ClassNotFoundException e) {
}
placeholderAPIEnabled = setupPlaceHolderAPI();
try {
@ -729,13 +741,6 @@ public class Jobs extends JavaPlugin {
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) {
complement = new Complement2();
//getServer().getPluginManager().registerEvents(new KyoriChatEvent(this), this);

View File

@ -263,7 +263,7 @@ public class SignUtil {
}
if (!line.isEmpty())
plugin.getComplement().setLine(sign, i, line);
sign.setLine(i, line);
}
sign.update();
if (!updateHead(sign, playerList.get(0).getPlayerInfo().getName(), timelapse)) {
@ -280,22 +280,22 @@ public class SignUtil {
}
int no = jSign.getNumber() + number + 1;
plugin.getComplement().setLine(sign, 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(0, translateSignLine("signs.SpecialList.p" + jSign.getNumber(), no, playerName, pl.getLevel(), signJobName));
sign.setLine(1, translateSignLine("signs.SpecialList.name", no, playerName, pl.getLevel(), signJobName));
switch (type) {
case toplist:
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;
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;
default:
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();
if (!updateHead(sign, pl.getPlayerInfo().getName(), timelapse)) {
timelapse--;

View File

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

View File

@ -11,7 +11,7 @@ public class ShopItem {
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 hideNoEnoughPoint = false;

View File

@ -307,10 +307,11 @@ public class JobsListener implements Listener {
if (!Jobs.getGCManager().SignsEnabled)
return;
String line1 = CMIChatColor.stripColor(plugin.getComplement().getLine(event, 1));
if (CMIChatColor.stripColor(plugin.getComplement().getLine(event, 0))
.equalsIgnoreCase(CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.topline"))) && !CMIChatColor.stripColor(
plugin.getComplement().getLine(event, 1)).equalsIgnoreCase("toplist"))
plugin.getComplement().setLine(event, 0, convert(Jobs.getLanguage().getMessage("signs.topline")));
.equalsIgnoreCase(CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.topline"))) && !line1.equalsIgnoreCase("toplist"))
event.setLine(0, convert(Jobs.getLanguage().getMessage("signs.topline")));
else
return;
@ -320,11 +321,11 @@ public class JobsListener implements Listener {
return;
}
String command = CMIChatColor.stripColor(plugin.getComplement().getLine(event, 1)).toLowerCase();
for (String key : Jobs.getLanguageManager().signKeys) {
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;
}
}
@ -334,7 +335,7 @@ public class JobsListener implements Listener {
return;
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])");

View File

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

View File

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

View File

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