Skip to content

Commit

Permalink
Remove warning for paper
Browse files Browse the repository at this point in the history
  • Loading branch information
Elikill58 committed Apr 25, 2024
1 parent fcef124 commit f502cfa
Show file tree
Hide file tree
Showing 26 changed files with 257 additions and 116 deletions.
15 changes: 11 additions & 4 deletions src/main/java/me/dadus33/chatitem/ChatItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.StringJoiner;
import java.util.concurrent.CompletableFuture;

import org.bukkit.ChatColor;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
Expand All @@ -34,7 +33,11 @@
import me.dadus33.chatitem.listeners.InventoryListener;
import me.dadus33.chatitem.listeners.JoinListener;
import me.dadus33.chatitem.listeners.TranslationInventoryListener;
import me.dadus33.chatitem.platform.IPlatform;
import me.dadus33.chatitem.platform.hook.PaperPlatform;
import me.dadus33.chatitem.platform.hook.SpigotPlatform;
import me.dadus33.chatitem.playernamer.PlayerNamerManager;
import me.dadus33.chatitem.utils.Colors;
import me.dadus33.chatitem.utils.PacketUtils;
import me.dadus33.chatitem.utils.ReflectionUtils;
import me.dadus33.chatitem.utils.SemVer;
Expand All @@ -43,6 +46,10 @@

public class ChatItem extends JavaPlugin {

private static final IPlatform platform = PacketUtils.IS_PAPER ? new PaperPlatform() : new SpigotPlatform();
public static IPlatform getPlatform() {
return platform;
}
public final static int CFG_VER = 13;
public static boolean discordSrvSupport = false, hasNewVersion = false;
private static ChatItem instance;
Expand All @@ -64,7 +71,7 @@ public static void reload(CommandSender sender) {
if (!pl.storage.messageReload.isEmpty())
sender.sendMessage(pl.storage.messageReload);
if (!oldChatManager.equalsIgnoreCase(pl.storage.manager))
sender.sendMessage(ChatColor.GOLD + "Changing the manager with command reloading CAN produce issue. It's mostly suggested to restart after finding the better manager for you.");
sender.sendMessage(Colors.GOLD + "Changing the manager with command reloading CAN produce issue. It's mostly suggested to restart after finding the better manager for you.");
}
}

Expand Down Expand Up @@ -198,12 +205,12 @@ public void onEnable() {
String content = Utils.getFromURL(urlName);
if (Strings.isNullOrEmpty(content))
return;
SemVer currentVersion = SemVer.parse(getDescription().getVersion());
SemVer currentVersion = SemVer.parse(getPlatform().getPluginVersion(this));
if (currentVersion == null)
return;
SemVer latestVersion = SemVer.parse(content);
if (latestVersion != null && latestVersion.isNewerThan(currentVersion)) {
hasNewVersion = !content.equalsIgnoreCase(getDescription().getVersion());
hasNewVersion = !content.equalsIgnoreCase(getPlatform().getPluginVersion(this));
if (hasNewVersion)
getLogger().info(storage.updateMessage);
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/me/dadus33/chatitem/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import java.util.List;
import java.util.stream.Collectors;

import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;

import me.dadus33.chatitem.utils.Colors;

public class Storage {

public String handName, nameFormat, amountFormat, commandFormat, manager, permissionName, buggedClientAction, language;
Expand Down Expand Up @@ -63,7 +64,7 @@ public Storage(FileConfiguration cnf) {
}

public static String color(String s) {
return s == null || s.isEmpty() ? s : ChatColor.translateAlternateColorCodes('&', s);
return s == null || s.isEmpty() ? s : Colors.translateAlternateColorCodes('&', s);
}

private static void colorStringList(List<String> input) {
Expand All @@ -76,10 +77,10 @@ private void checkConfigVersion() {
int latestVersion = ChatItem.CFG_VER;
if (latestVersion != configVersion) {
ChatItem pl = ChatItem.getInstance();
pl.getLogger().warning(ChatColor.RED + "ChatItem detected an older or invalid configuration file. Replacing it with the default config...");
pl.getLogger().warning("ChatItem detected an older or invalid configuration file. Replacing it with the default config...");
performOverwrite();
conf = pl.getConfig();
pl.getLogger().warning(ChatColor.RED + "Replacement complete!");
pl.getLogger().warning("Replacement complete!");
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/me/dadus33/chatitem/Translation.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

Expand Down Expand Up @@ -53,6 +54,11 @@ public static JsonObject getMessages() {
return messages;
}

public static String getMessage(String key) {
JsonElement result = messages.get(key);
return result == null ? "" : result.getAsString();
}

public static void loadLang(String lang) {
ChatItem pl = ChatItem.getInstance();
File langFile = new File(folder, lang + ".json");
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/me/dadus33/chatitem/chatmanager/ChatManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import javax.annotation.Nullable;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.ShulkerBox;
import org.bukkit.entity.Player;
Expand All @@ -26,10 +25,12 @@
import me.dadus33.chatitem.invsee.hook.EnderChestShower;
import me.dadus33.chatitem.invsee.hook.PlayerInventoryShower;
import me.dadus33.chatitem.itemnamer.NamerManager;
import me.dadus33.chatitem.utils.Colors;
import me.dadus33.chatitem.utils.ItemUtils;
import me.dadus33.chatitem.utils.Utils;
import me.dadus33.chatitem.utils.Version;

@SuppressWarnings("deprecation")
public abstract class ChatManager {

public static String inTest = null;
Expand Down Expand Up @@ -155,7 +156,7 @@ public static List<String> getMaxLinesFromItem(Player p, ItemStack item) {
lines.add(meta.hasDisplayName() ? meta.getDisplayName() : NamerManager.getName(p, item, ChatItem.getInstance().getStorage()));
if (meta.hasEnchants()) {
meta.getEnchants().forEach((enchant, lvl) -> {
lines.add(ChatColor.RESET + Utils.getEnchantName(enchant) + " " + Utils.toRoman(lvl));
lines.add(Colors.RESET + Utils.getEnchantName(enchant) + " " + Utils.toRoman(lvl));
});
}
if (meta.hasLore())
Expand Down Expand Up @@ -206,7 +207,7 @@ public static String getNameOfItem(Player p, ItemStack item, Storage c) {
if (c.handDisabled)
return ItemSlot.HAND.getPlaceholders().get(0);
else
return c.handName.replace("{name}", p.getName()).replace("{display-name}", p.getDisplayName());
return getHandName(p);
}
return styleItem(p, item, c);
}
Expand All @@ -218,12 +219,16 @@ public static String getNameForChatAction(Player p, ChatAction action, Storage c
if (c.handDisabled)
return ItemSlot.HAND.getPlaceholders().get(0);
else
return c.handName.replace("{name}", p.getName()).replace("{display-name}", p.getDisplayName());
return getHandName(p);
}
return styleItem(p, item, c);
}
return "";
}

public static String getHandName(Player p) {
return ChatItem.getInstance().getStorage().handName.replace("{name}", p.getName()).replace("{display-name}", p.getDisplayName());
}

public static String calculateTime(long seconds) {
Storage c = ChatItem.getInstance().getStorage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ default Object manageItem(Player p, Chat chat, ChatItemPacket packet, ItemStack
}

default Object manageEmpty(Player p, Chat chat, ChatItemPacket packet, String json, Storage c) {
String message = JSONManipulator.getInstance().parseEmpty(json, c.handName, c.tooltipHand, chat.getPlayer());
String message = JSONManipulator.getInstance().parseEmpty(json, ChatManager.getHandName(p), c.tooltipHand, chat.getPlayer());
if (message != null) {
ChatItem.debug("(v1) Writing empty message: " + message);
writeJson(packet, message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ public Object manageItem(Player p, Chat chat, ChatItemPacket packet, ItemStack i
public Object manageEmpty(Player p, Chat chat, ChatItemPacket packet, String json, Storage c) {
Component builder = Component.text("");
c.tooltipHand.forEach(s -> builder.append(Component.text(s)));
Player sender = chat.getPlayer();
ChatAction action = chat.getAction();
if (action.isItem()) {
String handName = c.handName.replace("{name}", sender.getName()).replace("{display-name}", sender.getDisplayName());
return manage(p, chat, packet, handName, HoverEvent.showText(builder), null);
return manage(p, chat, packet, ChatManager.getHandName(p), HoverEvent.showText(builder), null);
}
return manage(p, chat, packet, Messages.getMessage(action.getSlot().name().toLowerCase() + ".chat", "%cible%", chat.getPlayer().getName()),
HoverEvent.showText(Component.text(Messages.getMessage(action.getSlot().name().toLowerCase() + ".hover", "%cible%", chat.getPlayer().getName()))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,13 @@ public Object manageItem(Player p, Chat chat, ChatItemPacket packet, ItemStack i
public Object manageEmpty(Player p, Chat chat, ChatItemPacket packet, String json, Storage c) {
ComponentBuilder builder = new ComponentBuilder("");
c.tooltipHand.forEach(s -> builder.append(s));
Player sender = chat.getPlayer();
HoverEvent hover;
ClickEvent click;
String rep;
ChatAction action = chat.getAction();
if (action.isItem()) {
hover = Utils.createTextHover(builder.create());
rep = c.handName.replace("{name}", sender.getName()).replace("{display-name}", sender.getDisplayName());
rep = ChatManager.getHandName(p);
click = null;
} else {
hover = Utils.createTextHover(Messages.getMessage(action.getSlot().name().toLowerCase() + ".hover", "%cible%", chat.getPlayer().getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ else if (extraElement.isJsonObject())
return obj.toString();
}

@SuppressWarnings("deprecation")
public String parseEmpty(String json, String repl, List<String> tooltip, Player sender) {
JsonObject obj = JsonParser.parseString(json).getAsJsonObject();
JsonArray array = obj.has("extra") ? obj.getAsJsonArray("extra") : new JsonArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ private void tryRegister(IComponentManager getter) {
ChatItem.debug("Component " + getter.getClass().getSimpleName() + " doesn't answer conditions");
}

@SuppressWarnings("deprecation")
@Override
public void onSend(ChatItemPacket e) {
if (!e.hasPlayer() || !e.getPacketType().equals(PacketType.Server.CHAT))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.TextComponent;

@SuppressWarnings("deprecation")
public class ChatListener implements Listener {

private static Method saveMethod;
Expand Down
29 changes: 15 additions & 14 deletions src/main/java/me/dadus33/chatitem/commands/ChatItemCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.Locale;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand All @@ -23,11 +22,13 @@
import me.dadus33.chatitem.chatmanager.v2.ChatListener;
import me.dadus33.chatitem.invsee.InvShower;
import me.dadus33.chatitem.listeners.InventoryListener;
import me.dadus33.chatitem.utils.Colors;
import me.dadus33.chatitem.utils.Messages;
import me.dadus33.chatitem.utils.Utils;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;

@SuppressWarnings("deprecation")
public class ChatItemCommand implements CommandExecutor, TabExecutor {

private static final List<String> orders = Arrays.asList("packet", "chat", "both");
Expand Down Expand Up @@ -82,35 +83,35 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
p.spigot().sendMessage(text);
} else if (args[0].equalsIgnoreCase("select") && p.hasPermission("chatitem.reload")) {
if(args.length == 1) {
p.sendMessage(ChatColor.GRAY + "----------" + ChatColor.GOLD + " ChatItem - Setup " + ChatColor.GRAY + "----------");
p.sendMessage(ChatColor.AQUA + "Welcome in the help of setup." + ChatColor.YELLOW + " Please follow step by simply answer to test.");
p.sendMessage(Colors.GRAY + "----------" + Colors.GOLD + " ChatItem - Setup " + Colors.GRAY + "----------");
p.sendMessage(Colors.AQUA + "Welcome in the help of setup." + Colors.YELLOW + " Please follow step by simply answer to test.");
sendCheckSelectMessage(p, orders.get(0));
} else {
String tested = args[1];
if(!orders.contains(tested)) {
p.sendMessage(ChatColor.RED + "Unknow test for " + tested + ".");
p.sendMessage(Colors.RED + "Unknow test for " + tested + ".");
return false;
}
if(args.length == 2) {
p.sendMessage(ChatColor.RED + "Can't find if it works");
p.sendMessage(Colors.RED + "Can't find if it works");
return false;
}
if(args[2].equalsIgnoreCase("yes")) {
ChatManager.setTesting(null);
InventoryListener.setInConfig("manager", tested);
p.sendMessage(ChatColor.GREEN + "Perfect ! Updating config ...");
p.sendMessage(Colors.GREEN + "Perfect ! Updating config ...");
ChatItem.reload(p);
} else if(args[2].equalsIgnoreCase("no")) {
int index = orders.indexOf(tested);
if(orders.size() == (index + 1)) {
p.sendMessage(ChatColor.RED + "Sad. Sorry but nothing is available. I suggest you to come on discord for more help. Do '/chatitem link' for all links.");
p.sendMessage(Colors.RED + "Sad. Sorry but nothing is available. I suggest you to come on discord for more help. Do '/chatitem link' for all links.");
ChatManager.setTesting(null);
} else {
p.sendMessage(ChatColor.RED + "Sad. Checking for next manager ...");
p.sendMessage(Colors.RED + "Sad. Checking for next manager ...");
sendCheckSelectMessage(p, orders.get(index + 1));
}
} else {
p.sendMessage(ChatColor.RED + "Can't find if it works");
p.sendMessage(Colors.RED + "Can't find if it works");
}
}
} else if (args[0].equalsIgnoreCase("seeinv")) {
Expand All @@ -133,15 +134,15 @@ private void sendCheckSelectMessage(Player p, String testing) {
p.chat("Checking for " + testing + ": [i]");

Bukkit.getScheduler().runTaskLater(ChatItem.getInstance(), () -> {
TextComponent text = new TextComponent(ChatColor.GOLD + "Did it worked fine? ");
TextComponent agree = new TextComponent(ChatColor.GREEN + "Yes");
TextComponent text = new TextComponent(Colors.GOLD + "Did it worked fine? ");
TextComponent agree = new TextComponent(Colors.GREEN + "Yes");
agree.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/chatitem select " + testing + " yes"));
agree.setHoverEvent(Utils.createTextHover(ChatColor.GRAY + "Click to say it worked fine"));
agree.setHoverEvent(Utils.createTextHover(Colors.GRAY + "Click to say it worked fine"));
text.addExtra(agree);
text.addExtra(" ");
TextComponent decline = new TextComponent(ChatColor.RED + "No");
TextComponent decline = new TextComponent(Colors.RED + "No");
decline.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/chatitem select " + testing + " no"));
decline.setHoverEvent(Utils.createTextHover(ChatColor.GRAY + "Click to say it's not working as expected"));
decline.setHoverEvent(Utils.createTextHover(Colors.GRAY + "Click to say it's not working as expected"));
text.addExtra(decline);
p.spigot().sendMessage(text);
}, 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static boolean hasSupport() {
}

public static boolean load() {
String ver = Bukkit.getPluginManager().getPlugin("EcoEnchants").getDescription().getVersion();
String ver = ChatItem.getPlatform().getPluginVersion(Bukkit.getPluginManager().getPlugin("EcoEnchants"));
if(ver.startsWith("8."))
supportedVersion = 8;
else if(ver.startsWith("10."))
Expand All @@ -34,6 +34,7 @@ else if(ver.startsWith("12."))
return true;
}

@SuppressWarnings("deprecation")
public static ItemStack manageItem(ItemStack item) {
if(supportedVersion == 8) {
List<String> addLore = EcoEnchantsV8Support.getLores(item);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package me.dadus33.chatitem.invsee.hook;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import me.dadus33.chatitem.ChatItem;
import me.dadus33.chatitem.invsee.InvShower;
import me.dadus33.chatitem.listeners.holder.CustomInventoryHolder;
import me.dadus33.chatitem.utils.ItemUtils;
Expand All @@ -26,7 +26,7 @@ public EnderChestShower(Player cible) {

@Override
public void open(Player p) {
Inventory inv = Bukkit.createInventory(new CustomInventoryHolder(), items.length, Messages.getMessage("enderchest.name", "%cible%", name));
Inventory inv = ChatItem.getPlatform().createInventory(new CustomInventoryHolder(), items.length, Messages.getMessage("enderchest.name", "%cible%", name));

for(int i = 0; i < items.length; i++)
inv.setItem(i, items[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import java.util.HashMap;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;

import me.dadus33.chatitem.ChatItem;
import me.dadus33.chatitem.invsee.InvShower;
import me.dadus33.chatitem.listeners.holder.CustomInventoryHolder;
import me.dadus33.chatitem.utils.ItemUtils;
Expand All @@ -34,10 +34,10 @@ public PlayerInventoryShower(Player cible) {

@Override
public void open(Player p) {
Inventory inv = Bukkit.createInventory(new CustomInventoryHolder(), 54, Messages.getMessage("inventory.name", "%cible%", name));
Inventory inv = ChatItem.getPlatform().createInventory(new CustomInventoryHolder(), 54, Messages.getMessage("inventory.name", "%cible%", name));

for(int i = 0; i < 18; i++)
inv.setItem(i, ItemUtils.createItem(ItemUtils.getMaterialWithCompatibility("BROWN_STAINED_GLASS_PANE", "STAINED_GLASS_PANE"), ""));
inv.setItem(i, ItemUtils.ITEM_EMPTY_BROWN);

inv.setItem(2, new ItemStack(ItemUtils.getMaterialWithCompatibility("EXPERIENCE_BOTTLE", "EXP_BOTTLE"), level == 0 ? 1 : (level >= 64 ? 64 : level)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import me.dadus33.chatitem.Storage;
import me.dadus33.chatitem.itemnamer.INamer;

@SuppressWarnings("deprecation")
public class ItemDisplayNamer implements INamer {

@Override
Expand Down
Loading

0 comments on commit f502cfa

Please sign in to comment.