diff --git a/pom.xml b/pom.xml index c193426..63d8856 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.t2code T2CodeLib - 11.8 + 11.9 jar T2CodeLib diff --git a/src/main/java/net/t2code/lib/Spigot/Lib/messages/HoverModule.java b/src/main/java/net/t2code/lib/Spigot/Lib/messages/HoverModule.java new file mode 100644 index 0000000..9da52d9 --- /dev/null +++ b/src/main/java/net/t2code/lib/Spigot/Lib/messages/HoverModule.java @@ -0,0 +1,39 @@ +package net.t2code.lib.Spigot.Lib.messages; + +import net.md_5.bungee.api.chat.ClickEvent; +import org.bukkit.entity.Player; + +public class HoverModule { + + public static void module(String text, String hover, String action, String actionValue, Player player) { + module((text != null ? text : "null") + "/*/" + (hover != null ? hover : "null") + "/*/" + (action != null ? action : "null") + + "/*/" + (actionValue != null ? actionValue : "null"), player); + } + + public static void module(String msg, Player player) { + if (!msg.contains("/*/")) { + player.sendMessage(msg); + return; + } + String[] split = msg.split("/\\*/"); + int i = split.length; + String text = null; + String hover = null; + String action = null; + String actionValue = null; + if (i > 0) text= split[0]; + if (i > 1) hover =split[1]; + if (i > 2)action = split[2]; + if (i > 3)actionValue = split[3]; + + TextBuilder textBuilder = new TextBuilder(text); + if (hover != null && !hover.equals("null")) { + textBuilder.addHover(hover); + } + + if (action != null && actionValue != null && !action.equals("null") && !actionValue.equals("null")) { + textBuilder.addClickEvent(ClickEvent.Action.valueOf(action.toUpperCase()), actionValue); + } + player.spigot().sendMessage(textBuilder.build()); + } +} diff --git a/src/main/java/net/t2code/lib/Spigot/Lib/messages/send.java b/src/main/java/net/t2code/lib/Spigot/Lib/messages/send.java index 54495e5..697e85d 100644 --- a/src/main/java/net/t2code/lib/Spigot/Lib/messages/send.java +++ b/src/main/java/net/t2code/lib/Spigot/Lib/messages/send.java @@ -20,7 +20,7 @@ public class send { public static void player(Player player, String msg) { if (msg == null || msg.contains("[empty]")) return; - player.sendMessage(msg); + HoverModule.module(msg,player); } public static void title(Player player, String msg, String msg2) { diff --git a/src/main/java/net/t2code/lib/Spigot/Lib/replace/Replace.java b/src/main/java/net/t2code/lib/Spigot/Lib/replace/Replace.java index 6e2fd20..f253e32 100644 --- a/src/main/java/net/t2code/lib/Spigot/Lib/replace/Replace.java +++ b/src/main/java/net/t2code/lib/Spigot/Lib/replace/Replace.java @@ -12,14 +12,14 @@ public class Replace { public static String replace(String prefix, String Text) { return Text.replace("[prefix]", prefix).replace("&", "§").replace("[ue]", "ü") .replace("[UE]", "Ü").replace("[oe]", "ö").replace("[OE]", "Ö") - .replace("[ae]", "ä").replace("[AE]", "Ä"); + .replace("[ae]", "ä").replace("[AE]", "Ä").replace("[nl]","\n"); } public static String replace(String prefix,Player player, String Text) { return PlaceholderAPI.setPlaceholders(player, Text.replace("[prefix]", prefix).replace("&", "§") .replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö") - .replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")); + .replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä").replace("[nl]","\n")); } @@ -28,7 +28,7 @@ public class Replace { for (String input : Text) { output.add(input.replace("[prefix]", prefix).replace("&", "§") .replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö") - .replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")); + .replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä").replace("[nl]","\n")); } return output; } @@ -45,7 +45,7 @@ public class Replace { for (String input : Text) { output.add(PlaceholderAPI.setPlaceholders(player, input.replace("[prefix]", prefix).replace("&", "§") .replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö") - .replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä"))); + .replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä").replace("[nl]","\n"))); } return output; } @@ -56,7 +56,7 @@ public class Replace { for (String s : Text) { rp.add(s.replace("[prefix]", prefix).replace("&", "§") .replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö") - .replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä") + .replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä").replace("[nl]","\n") .replace("[price]", String.valueOf(price))); } return rp; @@ -81,7 +81,7 @@ public class Replace { for (String s : Text) { rp.add(PlaceholderAPI.setPlaceholders(player, s.replace("[prefix]", prefix).replace("&", "§") .replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö") - .replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä") + .replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä").replace("[nl]","\n") .replace("[price]", String.valueOf(price)))); } return rp; @@ -89,7 +89,7 @@ public class Replace { public static String replacePrice(String prefix, String Text, String price) { return Text.replace("[prefix]", prefix).replace("&", "§").replace("[ue]", "ü") .replace("[UE]", "Ü").replace("[oe]", "ö").replace("[OE]", "Ö") - .replace("[ae]", "ä").replace("[AE]", "Ä").replace("[price]", String.valueOf(price)); + .replace("[ae]", "ä").replace("[AE]", "Ä").replace("[price]", String.valueOf(price)).replace("[nl]","\n"); } @@ -97,7 +97,7 @@ public class Replace { return PlaceholderAPI.setPlaceholders(player, Text.replace("[prefix]", prefix).replace("&", "§") .replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö") .replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä") - .replace("[price]", String.valueOf(price))); + .replace("[price]", String.valueOf(price)).replace("[nl]","\n")); } } diff --git a/src/main/java/net/t2code/lib/Spigot/Lib/update/UpdateAPI.java b/src/main/java/net/t2code/lib/Spigot/Lib/update/UpdateAPI.java index 86967bb..49edc9b 100644 --- a/src/main/java/net/t2code/lib/Spigot/Lib/update/UpdateAPI.java +++ b/src/main/java/net/t2code/lib/Spigot/Lib/update/UpdateAPI.java @@ -4,6 +4,7 @@ package net.t2code.lib.Spigot.Lib.update; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.TextComponent; +import net.t2code.lib.Spigot.Lib.messages.HoverModule; import net.t2code.lib.Spigot.Lib.messages.TextBuilder; import net.t2code.lib.Spigot.Lib.messages.send; import net.t2code.lib.Spigot.system.Main; @@ -85,31 +86,19 @@ public class UpdateAPI { send.player(player, Prefix); if (publicVersion.toLowerCase().contains("dev") || publicVersion.toLowerCase().contains("beta") || publicVersion.toLowerCase().contains("snapshot")) { if (publicVersion.toLowerCase().contains("dev")) { - TextComponent comp = new TextBuilder(Prefix + " §6A new §4DEV§6 version was found!") - .addHover("§6You can download it here: §e" + Spigot).addClickEvent(ClickEvent.Action.OPEN_URL, Spigot).build(); - player.spigot().sendMessage(comp); + HoverModule.module(Prefix + " §6A new §4DEV§6 version was found!", "§6You can download it here: §e" + Spigot, "OPEN_URL", Spigot, player); } if (publicVersion.toLowerCase().contains("beta")) { - TextComponent comp = new TextBuilder(Prefix + " §6A new §2BETA§6 version was found!") - .addHover("§6You can download it here: §e" + Spigot).addClickEvent(ClickEvent.Action.OPEN_URL, Spigot).build(); - player.spigot().sendMessage(comp); + HoverModule.module(Prefix + " §6A new §2BETA§6 version was found!", "§6You can download it here: §e" + Spigot, "OPEN_URL", Spigot, player); } if (publicVersion.toLowerCase().contains("snapshot")) { - TextComponent comp = new TextBuilder(Prefix + " §6A new §eSNAPSHOT§6 version was found!") - .addHover("§6You can download it here: §e" + Spigot).addClickEvent(ClickEvent.Action.OPEN_URL, Spigot).build(); - player.spigot().sendMessage(comp); + HoverModule.module(Prefix + " §6A new §eSNAPSHOT§6 version was found!", "§6You can download it here: §e" + Spigot, "OPEN_URL", Spigot, player); } } else { - TextComponent comp = new TextBuilder(Prefix + " §6A new version was found!") - .addHover("§6You can download it here: §e" + Spigot).addClickEvent(ClickEvent.Action.OPEN_URL, Spigot).build(); - player.spigot().sendMessage(comp); + HoverModule.module(Prefix + " §6A new version was found!", "§6You can download it here: §e" + Spigot, "OPEN_URL", Spigot, player); } - TextComponent comp1 = new TextBuilder(Prefix + " §c" + pluginVersion + " §7-> §a" + publicVersion) - .addHover("§6You can download it here: §e" + Spigot).addClickEvent(ClickEvent.Action.OPEN_URL, Spigot).build(); - player.spigot().sendMessage(comp1); - TextComponent comp2 = new TextBuilder(Prefix + " §6You can find more information on Discord.") - .addHover("§e" + Discord).addClickEvent(ClickEvent.Action.OPEN_URL, Discord).build(); - player.spigot().sendMessage(comp2); + HoverModule.module(Prefix + " §c" + pluginVersion + " §7-> §a" + publicVersion, "§6You can download it here: §e" + Spigot, "OPEN_URL", Spigot, player); + HoverModule.module(Prefix + " §6You can find more information on Discord.", "§e" + Discord, "OPEN_URL", Discord, player); send.player(player, Prefix); }