From 46ee8709e7e541218fd86eae0fc9aaad525299d2 Mon Sep 17 00:00:00 2001 From: Julian Weinelt Date: Tue, 27 May 2025 15:41:37 +0200 Subject: [PATCH 01/12] Moved API to package api --- .idea/dictionaries/project.xml | 7 + .idea/modules.xml | 8 - pom.xml | 18 +- .../codelib/AdvancedTabCompleter.java | 33 -- .../de/codeblocksmc/codelib/ChatUtil.java | 65 ---- .../codelib/EnchantmentWrapper.java | 57 ---- .../de/codeblocksmc/codelib/GuiBuilder.java | 167 ---------- .../de/codeblocksmc/codelib/ItemBuilder.java | 306 ------------------ .../de/codeblocksmc/codelib/ItemWrapper.java | 49 --- .../codeblocksmc/codelib/JSONFileHelper.java | 96 ------ .../codeblocksmc/codelib/MySQLTemplate.java | 89 ----- .../codelib/MySQLTemplateVelocity.java | 71 ---- .../codelib/PotionEffectWrapper.java | 28 -- .../codeblocksmc/codelib/ServerConnector.java | 121 ------- .../de/codeblocksmc/codelib/TimeUtil.java | 51 --- .../{ => api}/chat/AdvancedTabCompleter.java | 2 +- .../codelib/{ => api}/chat/ChatUtil.java | 2 +- .../codelib/api/databsae/DatabaseObject.java | 4 + .../{ => api}/databsae/MSSQLTemplate.java | 2 +- .../{ => api}/databsae/MySQLTemplate.java | 2 +- .../databsae/MySQLTemplateVelocity.java | 2 +- .../codelib/{ => api}/locations/LocUtil.java | 2 +- .../{ => api}/locations/LocationSection.java | 2 +- .../{ => api}/locations/LocationWrapper.java | 2 +- .../{ => api}/util/JSONFileHelper.java | 2 +- .../{ => api}/util/ServerConnector.java | 2 +- .../codelib/{ => api}/util/TimeUtil.java | 2 +- .../{ => api}/worldman/WorldManCmd.java | 4 +- .../{ => api}/worldman/WorldManCom.java | 4 +- .../{ => api}/worldman/WorldManager.java | 3 +- .../wrapping/EnchantmentWrapper.java | 2 +- .../{ => api}/wrapping/GuiBuilder.java | 2 +- .../{ => api}/wrapping/ItemBuilder.java | 2 +- .../{ => api}/wrapping/ItemWrapper.java | 2 +- .../wrapping/PotionEffectWrapper.java | 2 +- .../codelib/databsae/DatabaseObject.java | 4 - 36 files changed, 44 insertions(+), 1173 deletions(-) create mode 100644 .idea/dictionaries/project.xml delete mode 100644 .idea/modules.xml delete mode 100644 src/main/java/de/codeblocksmc/codelib/AdvancedTabCompleter.java delete mode 100644 src/main/java/de/codeblocksmc/codelib/ChatUtil.java delete mode 100644 src/main/java/de/codeblocksmc/codelib/EnchantmentWrapper.java delete mode 100644 src/main/java/de/codeblocksmc/codelib/GuiBuilder.java delete mode 100644 src/main/java/de/codeblocksmc/codelib/ItemBuilder.java delete mode 100644 src/main/java/de/codeblocksmc/codelib/ItemWrapper.java delete mode 100644 src/main/java/de/codeblocksmc/codelib/JSONFileHelper.java delete mode 100644 src/main/java/de/codeblocksmc/codelib/MySQLTemplate.java delete mode 100644 src/main/java/de/codeblocksmc/codelib/MySQLTemplateVelocity.java delete mode 100644 src/main/java/de/codeblocksmc/codelib/PotionEffectWrapper.java delete mode 100644 src/main/java/de/codeblocksmc/codelib/ServerConnector.java delete mode 100644 src/main/java/de/codeblocksmc/codelib/TimeUtil.java rename src/main/java/de/codeblocksmc/codelib/{ => api}/chat/AdvancedTabCompleter.java (95%) rename src/main/java/de/codeblocksmc/codelib/{ => api}/chat/ChatUtil.java (97%) create mode 100644 src/main/java/de/codeblocksmc/codelib/api/databsae/DatabaseObject.java rename src/main/java/de/codeblocksmc/codelib/{ => api}/databsae/MSSQLTemplate.java (97%) rename src/main/java/de/codeblocksmc/codelib/{ => api}/databsae/MySQLTemplate.java (98%) rename src/main/java/de/codeblocksmc/codelib/{ => api}/databsae/MySQLTemplateVelocity.java (97%) rename src/main/java/de/codeblocksmc/codelib/{ => api}/locations/LocUtil.java (99%) rename src/main/java/de/codeblocksmc/codelib/{ => api}/locations/LocationSection.java (98%) rename src/main/java/de/codeblocksmc/codelib/{ => api}/locations/LocationWrapper.java (98%) rename src/main/java/de/codeblocksmc/codelib/{ => api}/util/JSONFileHelper.java (98%) rename src/main/java/de/codeblocksmc/codelib/{ => api}/util/ServerConnector.java (99%) rename src/main/java/de/codeblocksmc/codelib/{ => api}/util/TimeUtil.java (97%) rename src/main/java/de/codeblocksmc/codelib/{ => api}/worldman/WorldManCmd.java (96%) rename src/main/java/de/codeblocksmc/codelib/{ => api}/worldman/WorldManCom.java (92%) rename src/main/java/de/codeblocksmc/codelib/{ => api}/worldman/WorldManager.java (93%) rename src/main/java/de/codeblocksmc/codelib/{ => api}/wrapping/EnchantmentWrapper.java (96%) rename src/main/java/de/codeblocksmc/codelib/{ => api}/wrapping/GuiBuilder.java (99%) rename src/main/java/de/codeblocksmc/codelib/{ => api}/wrapping/ItemBuilder.java (99%) rename src/main/java/de/codeblocksmc/codelib/{ => api}/wrapping/ItemWrapper.java (97%) rename src/main/java/de/codeblocksmc/codelib/{ => api}/wrapping/PotionEffectWrapper.java (94%) delete mode 100644 src/main/java/de/codeblocksmc/codelib/databsae/DatabaseObject.java diff --git a/.idea/dictionaries/project.xml b/.idea/dictionaries/project.xml new file mode 100644 index 0000000..aa71914 --- /dev/null +++ b/.idea/dictionaries/project.xml @@ -0,0 +1,7 @@ + + + + folia + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 463ea25..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/pom.xml b/pom.xml index 308409c..006d80f 100644 --- a/pom.xml +++ b/pom.xml @@ -70,6 +70,11 @@ simonsators-repo https://simonsator.de/repo/ + + unifiedvision-caesar + Unified Vision Repo + https://repo.codeblocksmc.de/caesar + @@ -79,11 +84,6 @@ 1.20.4-R0.1-SNAPSHOT provided - - io.github.leonardosnt - bungeechannelapi - 1.0.0-SNAPSHOT - fr.mrmicky fastboard @@ -107,5 +107,13 @@ 1.6.2-RELEASE provided + + + + de.julianweinelt.caesar + CaesarMC + 1.0.1 + provided + diff --git a/src/main/java/de/codeblocksmc/codelib/AdvancedTabCompleter.java b/src/main/java/de/codeblocksmc/codelib/AdvancedTabCompleter.java deleted file mode 100644 index b419c9b..0000000 --- a/src/main/java/de/codeblocksmc/codelib/AdvancedTabCompleter.java +++ /dev/null @@ -1,33 +0,0 @@ -package de.codeblocksmc.codelib; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import org.bukkit.util.StringUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Arrays; -import java.util.List; - -@Deprecated(forRemoval = true) -public class AdvancedTabCompleter implements TabCompleter { - @Override - public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - return List.of(); - } - - - public void complete(List list, String arg, String... completions) { - list.clear(); - StringUtil.copyPartialMatches(arg, Arrays.asList(completions), list); - } - public void complete(List list, String arg, List completions) { - list.clear(); - StringUtil.copyPartialMatches(arg, completions, list); - } - - public void completeEmpty(List list) { - list.clear(); - } -} diff --git a/src/main/java/de/codeblocksmc/codelib/ChatUtil.java b/src/main/java/de/codeblocksmc/codelib/ChatUtil.java deleted file mode 100644 index 698ec0b..0000000 --- a/src/main/java/de/codeblocksmc/codelib/ChatUtil.java +++ /dev/null @@ -1,65 +0,0 @@ -package de.codeblocksmc.codelib; - - -@Deprecated(forRemoval = true) -public class ChatUtil { - public static String getColorCode(int level) { - if (level < 10) return "§f"; - else if (level < 20) return "§2"; - else if (level < 30) return "§9"; - else if (level < 40) return "§5"; - else if (level < 50) return "§b"; - else if (level < 60) return "§a"; - else if (level < 70) return "§3"; - else if (level < 80) return "§d"; - else if (level < 90) return "§e"; - else if (level < 100) return "§c"; - else return "§4"; - } - - public static String getColorCodeHex(int level) { - return getHexForMC(getColorCode(level).replace("§", "")); - } - - private static String getHexForMC(String mc) { - switch (mc) { - case "f" -> { - return "FFFFFF"; - } - case "d" -> { - return "FF55FF"; - } - case "5" -> { - return "AA00AA"; - } - case "9" -> { - return "5555FF"; - } - case "b" -> { - return "55FFFF"; - } - case "3" -> { - return "00AAAA"; - } - case "a" -> { - return "55FF55"; - } - case "e" -> { - return "FFFF55"; - } - case "6" -> { - return "FFAA00"; - } - case "c" -> { - return "FF5555"; - } - case "4" -> { - return "AA0000"; - } - case "2" -> { - return "00AA00"; - } - } - return "FFFFFF"; - } -} \ No newline at end of file diff --git a/src/main/java/de/codeblocksmc/codelib/EnchantmentWrapper.java b/src/main/java/de/codeblocksmc/codelib/EnchantmentWrapper.java deleted file mode 100644 index 1f8f853..0000000 --- a/src/main/java/de/codeblocksmc/codelib/EnchantmentWrapper.java +++ /dev/null @@ -1,57 +0,0 @@ -package de.codeblocksmc.codelib; - -import lombok.Getter; - -@Getter -@Deprecated(forRemoval = true) -public class EnchantmentWrapper { - private final EnchantmentType type; - private final int level; - - public EnchantmentWrapper(EnchantmentType type, int level) { - this.type = type; - this.level = level; - } - - public enum EnchantmentType { - PROTECTION_ENVIRONMENTAL, - PROTECTION_FIRE, - PROTECTION_FALL, - PROTECTION_EXPLOSIONS, - PROTECTION_PROJECTILE, - OXYGEN, - WATER_WORKER, - THORNS, - DEPTH_STRIDER, - FROST_WALKER, - BINDING_CURSE, - DAMAGE_ALL, - DAMAGE_UNDEAD, - DAMAGE_ARTHROPODS, - KNOCKBACK, - FIRE_ASPECT, - LOOT_BONUS_MOBS, - SWEEPING_EDGE, - DIG_SPEED, - SILK_TOUCH, - DURABILITY, - LOOT_BONUS_BLOCKS, - ARROW_DAMAGE, - ARROW_KNOCKBACK, - ARROW_FIRE, - ARROW_INFINITE, - LUCK, - LURE, - LOYALTY, - IMPALING, - RIPTIDE, - CHANNELING, - MULTISHOT, - QUICK_CHARGE, - PIERCING, - MENDING, - VANISHING_CURSE, - SOUL_SPEED, - SWIFT_SNEAK - } -} diff --git a/src/main/java/de/codeblocksmc/codelib/GuiBuilder.java b/src/main/java/de/codeblocksmc/codelib/GuiBuilder.java deleted file mode 100644 index 590458d..0000000 --- a/src/main/java/de/codeblocksmc/codelib/GuiBuilder.java +++ /dev/null @@ -1,167 +0,0 @@ -package de.codeblocksmc.codelib; - -import net.kyori.adventure.text.Component; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryType; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; - -import java.util.Arrays; -import java.util.List; - -/** - * Utility class for creating GUIs. - * Provides flexibility for different inventory types and layouts. - * @author JustCody - * @version 1.1 - */ -@Deprecated(forRemoval = true) -public class GuiBuilder { - - private final Inventory inv; - - /** - * Creates a chest GUI with the specified title and rows. - * - * @param title Title of the inventory as a string. - * @param rows Number of rows (1-6, each row contains 9 slots). - * @throws IllegalArgumentException If rows are less than 1 or greater than 6. - */ - public GuiBuilder(String title, int rows) { - if (rows < 1 || rows > 6) { - throw new IllegalArgumentException("Rows must be between 1 and 6."); - } - this.inv = Bukkit.createInventory(null, rows * 9, Component.text(title)); - } - - /** - * Creates a chest GUI with the specified title and rows. - * - * @param title Title of the inventory as a {@link Component}. - * @param rows Number of rows (1-6, each row contains 9 slots). - * @throws IllegalArgumentException If rows are less than 1 or greater than 6. - */ - public GuiBuilder(Component title, int rows) { - if (rows < 1 || rows > 6) { - throw new IllegalArgumentException("Rows must be between 1 and 6."); - } - this.inv = Bukkit.createInventory(null, rows * 9, title); - } - - /** - * Creates a GUI with the specified {@link InventoryType} and title. - * - * @param type The inventory type. - * @param title The title of the inventory as a {@link String}. - * @throws IllegalArgumentException If the inventory type cannot be viewed. - */ - public GuiBuilder(InventoryType type, String title) { - if (type == null) { - throw new IllegalArgumentException("Inventory type cannot be null."); - } - this.inv = Bukkit.createInventory(null, type, Component.text(title)); - } - - /** - * Creates a GUI with the specified {@link InventoryType} and title. - * - * @param type The inventory type. - * @param title The title of the inventory as a {@link Component}. - * @throws IllegalArgumentException If the inventory type cannot be viewed. - */ - public GuiBuilder(InventoryType type, Component title) { - if (type == null) { - throw new IllegalArgumentException("Inventory type cannot be null."); - } - this.inv = Bukkit.createInventory(null, type, title); - } - - /** - * Sets an item in the specified slot. - * - * @param slot Slot index (0-based). - * @param stack The {@link ItemStack} to set. - * @throws IllegalArgumentException If the slot is out of bounds. - */ - public GuiBuilder slot(int slot, ItemStack stack) { - validateSlot(slot); - inv.setItem(slot, stack); - return this; - } - - /** - * Sets an item in the specified slot using an {@link ItemBuilder}. - * - * @param slot Slot index (0-based). - * @param item The {@link ItemBuilder} instance. - * @throws IllegalArgumentException If the slot is out of bounds. - */ - public GuiBuilder slot(int slot, ItemBuilder item) { - validateSlot(slot); - inv.setItem(slot, item.build()); - return this; - } - - /** - * Fills the specified slots with an item of the given {@link Material}. - * - * @param material The material to use. - * @param slots The slots to fill. - * @throws IllegalArgumentException If any slot is out of bounds. - */ - public GuiBuilder slots(Material material, int... slots) { - ItemStack filler = new ItemBuilder(material).displayname(" ").build(); - for (int slot : slots) { - validateSlot(slot); - inv.setItem(slot, filler); - } - return this; - } - - /** - * Fills the entire inventory with the specified material as a placeholder. - * - * @param material The placeholder material. - */ - public GuiBuilder fillerPlaceholder(Material material) { - ItemStack filler = new ItemBuilder(material).displayname(" ").build(); - for (int i = 0; i < inv.getSize(); i++) { - inv.setItem(i, filler); - } - return this; - } - - /** - * Opens the GUI for the specified player. - * - * @param player The player to open the inventory for. - * @return The built inventory. - */ - public Inventory openForPlayer(Player player) { - player.openInventory(inv); - return inv; - } - - /** - * Builds and returns the inventory. - * - * @return The built {@link Inventory}. - */ - public Inventory build() { - return inv; - } - - /** - * Validates a slot index. - * - * @param slot The slot index to validate. - * @throws IllegalArgumentException If the slot is out of bounds. - */ - private void validateSlot(int slot) { - if (slot < 0 || slot >= inv.getSize()) { - throw new IllegalArgumentException("Slot " + slot + " is out of bounds (0-" + (inv.getSize() - 1) + ")."); - } - } -} diff --git a/src/main/java/de/codeblocksmc/codelib/ItemBuilder.java b/src/main/java/de/codeblocksmc/codelib/ItemBuilder.java deleted file mode 100644 index 9617480..0000000 --- a/src/main/java/de/codeblocksmc/codelib/ItemBuilder.java +++ /dev/null @@ -1,306 +0,0 @@ -package de.codeblocksmc.codelib; - -import com.destroystokyo.paper.profile.PlayerProfile; -import net.kyori.adventure.text.Component; -import org.bukkit.Color; -import org.bukkit.Material; -import org.bukkit.MusicInstrument; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Axolotl; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.*; -import org.bukkit.inventory.meta.trim.ArmorTrim; -import org.bukkit.inventory.meta.trim.TrimMaterial; -import org.bukkit.inventory.meta.trim.TrimPattern; -import org.bukkit.potion.PotionEffect; - -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -/** - * A utility class for creating and modifying {@link ItemStack} instances with a fluent API. - * - *

This class allows easy configuration of items with custom properties such as display names, - * lore, enchantments, item flags, and more.

- * - * @author JustCody - * @version 1.1 - */ -@Deprecated(forRemoval = true) -public class ItemBuilder { - - private final ItemStack stack; - private ItemMeta meta; - - /** - * Constructs an {@link ItemBuilder} with the specified {@link Material}. - * - * @param material The {@link Material} for the item. - * @throws IllegalArgumentException If the material is null or AIR. - */ - public ItemBuilder(Material material) { - Objects.requireNonNull(material, "Material cannot be null."); - if (material == Material.AIR) { - throw new IllegalArgumentException("Cannot create an ItemBuilder with Material.AIR."); - } - this.stack = new ItemStack(material); - this.meta = stack.getItemMeta(); - } - - /** - * Sets the display name of the item. - * - * @param name The new display name. - * @return This builder instance. - */ - public ItemBuilder displayname(String name) { - meta.setDisplayName(name); - return this; - } - - /** - * Sets the item to be unbreakable. - * - * @param unbreakable Whether the item is unbreakable. - * @return This builder instance. - */ - public ItemBuilder unbreakable(boolean unbreakable) { - meta.setUnbreakable(unbreakable); - return this; - } - - /** - * Sets the lore of the item. - * - * @param lore The lore lines to set. - * @return This builder instance. - */ - public ItemBuilder lore(String... lore) { - meta.setLore(Arrays.asList(lore)); - return this; - } - - /** - * Sets the lore of the item. - * - * @param lore The lore lines as a list. - * @return This builder instance. - */ - public ItemBuilder lore(List lore) { - meta.setLore(lore); - return this; - } - - /** - * Sets custom model data for the item. - * - * @param data The custom model data. - * @return This builder instance. - */ - public ItemBuilder customModelData(int data) { - meta.setCustomModelData(data); - return this; - } - - /** - * Adds a single {@link ItemFlag} to the item. - * - * @param flag The flag to add. - * @return This builder instance. - */ - public ItemBuilder flag(ItemFlag flag) { - meta.addItemFlags(flag); - return this; - } - - /** - * Adds multiple {@link ItemFlag}s to the item. - * - * @param flags The flags to add. - * @return This builder instance. - */ - public ItemBuilder flags(ItemFlag... flags) { - meta.addItemFlags(flags); - return this; - } - - /** - * Adds an {@link Enchantment} to the item. - * - * @param enchantment The enchantment to add. - * @param level The level of the enchantment. - * @return This builder instance. - */ - public ItemBuilder enchant(Enchantment enchantment, int level) { - meta.addEnchant(enchantment, level, true); - return this; - } - - /** - * Sets the amount of the item stack. - * - * @param amount The new amount. - * @return This builder instance. - */ - public ItemBuilder amount(int amount) { - stack.setAmount(amount); - return this; - } - - /** - * Applies a player profile to the item (for player heads). - * - * @param profile The {@link PlayerProfile} to set. - * @return This builder instance. - */ - public ItemBuilder owner(PlayerProfile profile) { - if (meta instanceof SkullMeta skullMeta) { - skullMeta.setPlayerProfile(profile); - } - return this; - } - - /** - * Sets an armor trim for the item. - * - * @param trim The {@link ArmorTrim} to apply. - * @return This builder instance. - */ - public ItemBuilder armorTrim(ArmorTrim trim) { - if (meta instanceof ArmorMeta armorMeta) { - armorMeta.setTrim(trim); - } - return this; - } - - /** - * Sets a leather color for leather armor. - * - * @param color The {@link Color} to apply. - * @return This builder instance. - */ - public ItemBuilder leatherColor(Color color) { - if (meta instanceof LeatherArmorMeta leatherArmorMeta) { - leatherArmorMeta.setColor(color); - } - return this; - } - - /** - * Sets a color for potions. - * - * @param color The {@link Color} to apply. - * @return This builder instance. - */ - public ItemBuilder potionColor(Color color) { - if (meta instanceof PotionMeta potionMeta) { - potionMeta.setColor(color); - } - return this; - } - - /** - * Adds a potion effect to the item (if it's a potion). - * - * @param effect The {@link PotionEffect} to add. - * @return This builder instance. - */ - public ItemBuilder potionEffect(PotionEffect effect) { - if (meta instanceof PotionMeta potionMeta) { - potionMeta.addCustomEffect(effect, true); - } - return this; - } - - /** - * Adds multiple potion effects to the item (if it's a potion). - * - * @param effects The potion effects to add. - * @return This builder instance. - */ - public ItemBuilder potionEffects(PotionEffect... effects) { - if (meta instanceof PotionMeta potionMeta) { - for (PotionEffect effect : effects) { - potionMeta.addCustomEffect(effect, true); - } - } - return this; - } - - /** - * Sets the instrument for a goat horn. - * - * @param instrument The {@link MusicInstrument} to set. - * @return This builder instance. - */ - public ItemBuilder musicInstrument(MusicInstrument instrument) { - if (meta instanceof MusicInstrumentMeta musicMeta) { - musicMeta.setInstrument(instrument); - } - return this; - } - - /** - * Sets the title of a book. - * - * @param title The title to set. - * @return This builder instance. - */ - public ItemBuilder bookTitle(String title) { - if (meta instanceof BookMeta bookMeta) { - bookMeta.setTitle(title); - } - return this; - } - - /** - * Sets the author of a book. - * - * @param author The author to set. - * @return This builder instance. - */ - public ItemBuilder bookAuthor(String author) { - if (meta instanceof BookMeta bookMeta) { - bookMeta.setAuthor(author); - } - return this; - } - - /** - * Adds a page to a book. - * - * @param page The content of the page. - * @return This builder instance. - */ - public ItemBuilder bookPage(String page) { - if (meta instanceof BookMeta bookMeta) { - bookMeta.addPages(Component.text(page)); - } - return this; - } - - /** - * Sets the axolotl variant for axolotl buckets. - * - * @param variant The {@link Axolotl.Variant} to set. - * @return This builder instance. - */ - public ItemBuilder axolotl(Axolotl.Variant variant) { - if (meta instanceof AxolotlBucketMeta axolotlMeta) { - axolotlMeta.setVariant(variant); - } - return this; - } - - /** - * Builds the item and returns the {@link ItemStack}. - * - * @return The built {@link ItemStack}. - */ - public ItemStack build() { - stack.setItemMeta(meta); - return stack; - } -} diff --git a/src/main/java/de/codeblocksmc/codelib/ItemWrapper.java b/src/main/java/de/codeblocksmc/codelib/ItemWrapper.java deleted file mode 100644 index bd73d64..0000000 --- a/src/main/java/de/codeblocksmc/codelib/ItemWrapper.java +++ /dev/null @@ -1,49 +0,0 @@ -package de.codeblocksmc.codelib; - -import lombok.Getter; -import lombok.Setter; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; - -import java.util.ArrayList; -import java.util.List; - - -@Getter -@Setter -@Deprecated(forRemoval = true) -public class ItemWrapper { - private int amount; - private Material material; - private String displayName; - private List lore = new ArrayList<>(); - private List enchantments = new ArrayList<>(); - - public static ItemStack fromWrapper(ItemWrapper w) { - ItemBuilder b = new ItemBuilder(w.getMaterial()); - b.displayname(w.getDisplayName()); - w.getEnchantments().forEach(ew->{ - b.enchant(Enchantment.getByName(ew.getType().toString()), ew.getLevel()); - }); - b.lore(w.getLore()); - b.amount(w.getAmount()); - return b.build(); - } - - public static ItemWrapper fromBuilder(ItemBuilder b) { - return fromStack(b.build()); - } - - public static ItemWrapper fromStack(ItemStack stack) { - ItemWrapper w = new ItemWrapper(); - w.setAmount(stack.getAmount()); - w.setDisplayName(stack.getItemMeta().getDisplayName()); - w.setMaterial(stack.getType()); - w.setLore(stack.getItemMeta().getLore()); - stack.getEnchantments().keySet().forEach(e -> { - w.getEnchantments().add(new EnchantmentWrapper(EnchantmentWrapper.EnchantmentType.valueOf(e.getName()), stack.getEnchantmentLevel(e))); - }); - return w; - } -} diff --git a/src/main/java/de/codeblocksmc/codelib/JSONFileHelper.java b/src/main/java/de/codeblocksmc/codelib/JSONFileHelper.java deleted file mode 100644 index 475ac8f..0000000 --- a/src/main/java/de/codeblocksmc/codelib/JSONFileHelper.java +++ /dev/null @@ -1,96 +0,0 @@ -package de.codeblocksmc.codelib; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.reflect.TypeToken; -import org.jetbrains.annotations.Nullable; - -import java.io.*; -import java.lang.reflect.Type; -import java.nio.file.NoSuchFileException; -import java.util.logging.Logger; - -@Deprecated(forRemoval = true) -public class JSONFileHelper { - private final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); - private final Logger log; - - public JSONFileHelper(Logger log) { - this.log = log; - } - - /** - * Loads a JSON file from the specified file path and deserializes it into the specified type. - * - *

This method is generic and allows deserialization of any type, - * as long as a corresponding {@link java.lang.reflect.Type} is provided. - * It uses GSON to convert the JSON content into Java objects.

- * - * @param The type of the returned object. - * @param path The file path of the JSON file to be loaded. - * @param type The type of the object to be deserialized. This can be specified - * using a {@link com.google.gson.reflect.TypeToken}. - * @return The deserialized object of type {@code T}, or {@code null} - * if an error occurs while reading or deserializing the file. - * - * @throws NullPointerException if the specified file path is {@code null}. - * @throws NoSuchFileException if the specified file does not exist. - * - *

Example:

- *
{@code
-     * Type mapType = new TypeToken(){}.getType();
-     * Map myMap = loadMap("path/to/file.json", mapType);
-     *
-     * Type ticketListType = new TypeToken>(){}.getType();
-     * List tickets = loadMap("path/to/file.json", ticketListType);
-     * }
- * - *

This method is particularly useful when loading data from JSON files - * into complex or generic data types such as lists, maps, or custom classes.

- */ - @Nullable - public T loadObject(String path, Type type) throws NoSuchFileException { - if (!new File(path).exists()) { - throw new NoSuchFileException(path); - } - try (BufferedReader br = new BufferedReader(new FileReader(path))) { - StringBuilder jsonStringBuilder = new StringBuilder(); - String line; - while ((line = br.readLine()) != null) { - jsonStringBuilder.append(line); - } - - return GSON.fromJson(jsonStringBuilder.toString(), type); - } catch (IOException e) { - log.warning(e.getMessage()); - return null; - } - } - - - /** - * Saves the given object as a JSON file at the specified path. - * - *

This method serializes the provided object into a JSON file using GSON. - * The file will be saved with the given file name in the specified directory.

- * - * @param The type of the object to be saved. - * @param object The object to be serialized and saved. - * @param directory The directory where the JSON file should be saved. - * If the directory does not exist, it will be created. - * @param fileName The name of the JSON file (without the path). - * - * @throws NullPointerException if {@code object}, {@code directory}, or {@code fileName} is {@code null}. - */ - public void saveObject(T object, File directory, String fileName) { - if (directory.mkdirs()) { - log.info("Creating data folders..."); - } - try (FileWriter writer = new FileWriter(new File(directory, fileName + ".json"))) { - writer.write(GSON.toJson(object)); - } catch (IOException e) { - log.warning("Failed to save object: " + e.getMessage()); - } - } - -} diff --git a/src/main/java/de/codeblocksmc/codelib/MySQLTemplate.java b/src/main/java/de/codeblocksmc/codelib/MySQLTemplate.java deleted file mode 100644 index 108ccfe..0000000 --- a/src/main/java/de/codeblocksmc/codelib/MySQLTemplate.java +++ /dev/null @@ -1,89 +0,0 @@ -package de.codeblocksmc.codelib; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.util.logging.Logger; - - -/** - * Template class for creating MySQL connections. - * This class provides methods for connecting to a MySQL database and checking the connection status. - * It works in conjunction with {@link Logger} for logging any issues or errors during the connection process. - * This is commonly used in Bukkit and Paper plugins for logging database-related activities. - * - * @author JustCody - * @version 1.0 - */ -@Deprecated(forRemoval = true) -public class MySQLTemplate { - - // The connection object to the MySQL database - public Connection conn; - - // Logger for logging messages related to the connection - public final Logger log; - - // MySQL connection details - private final String host; - private final int port; - private final String database; - private final String user; - private final String password; - - /** - * Constructor for initializing the MySQL connection template. - * - * @param log {@link Logger} of the plugin, typically used to log connection issues. - * @param host Hostname of the MySQL server (e.g., "localhost"). - * @param port Port of the MySQL server. Default is 3306. - * @param database Name of the MySQL database to connect to. - * @param user Username to authenticate with the MySQL server. - * @param password Password for the given username. - */ - public MySQLTemplate(Logger log, String host, int port, String database, String user, String password) { - this.log = log; - this.host = host; - this.port = port; - this.database = database; - this.user = user; - this.password = password; - } - - /** - * Establishes a connection to the MySQL server and creates a {@link Connection} object. - * This method loads the MySQL JDBC driver, attempts to connect to the database, - * and logs any exceptions if the connection fails. - */ - public void connect() { - final String DB_NAME = "jdbc:mysql://"+host+":"+port+"/"+database+"?useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&autoReconnect=true"; - - try { - // Load MySQL JDBC driver class - Class.forName("com.mysql.cj.jdbc.Driver"); - - // Establish a connection using the provided connection details - conn = DriverManager.getConnection(DB_NAME, user, password); - - } catch (Exception ex) { - // Log any exception that occurs during the connection process - log.warning("MySQL connection failed: " + ex.getMessage()); - } - } - - /** - * Checks the current MySQL connection to verify if it is still open and valid. - * If the connection is closed or null, this method will attempt to reconnect using {@link MySQLTemplate#connect()}. - */ - public void checkConnection() { - try { - if (conn == null || conn.isClosed()) { - // Attempt to reconnect if the connection is null or closed - connect(); - } - } catch (SQLException e) { - // Log any exceptions encountered while checking the connection status - log.warning("MySQL connection check failed: " + e.getMessage()); - } - } -} diff --git a/src/main/java/de/codeblocksmc/codelib/MySQLTemplateVelocity.java b/src/main/java/de/codeblocksmc/codelib/MySQLTemplateVelocity.java deleted file mode 100644 index 557b7a2..0000000 --- a/src/main/java/de/codeblocksmc/codelib/MySQLTemplateVelocity.java +++ /dev/null @@ -1,71 +0,0 @@ -package de.codeblocksmc.codelib; - -import org.slf4j.Logger; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; - - -/** - * Template class for creating MySQL connections - */ -@Deprecated(forRemoval = true) -public class MySQLTemplateVelocity { - - public Connection conn; - public final Logger log; - - private final String host; - private final int port; - private final String database; - private final String user; - private final String password; - - /** - * - * @param log {@link Logger} of the Plugin - * @param host Hostname - * @param port Port of the server. Default: 3306 - * @param database Database name - * @param user Username - * @param password Password - */ - public MySQLTemplateVelocity(Logger log, String host, int port, String database, String user, String password) { - this.log = log; - this.host = host; - this.port = port; - this.database = database; - this.user = user; - this.password = password; - } - - /** - * Connects to the MySQL server and creates a {@link Connection} object - */ - public void connect() { - final String DB_NAME = "jdbc:mysql://"+host+":"+port+"/"+database+"?useJDBCCompliantTimezoneShift=true&useLeg" + - "acyDatetimeCode=false&serverTimezone=UTC&autoReconnect=true"; - - try { - Class.forName("com.mysql.cj.jdbc.Driver"); //Gets the driver class - - conn = DriverManager.getConnection(DB_NAME, user, password); //Gets a connection to the database using the details you provided. - - } - catch(Exception ex) { - log.warn(ex.getMessage()); - } - } - - /** - * Checks if the connection is ok, otherwise it will try to {@link MySQLTemplate#connect()} to the server - */ - public void checkConnection() { - try { - if (conn == null || conn.isClosed()) connect(); - } catch (SQLException e) { - log.warn(e.getMessage()); - } - } -} diff --git a/src/main/java/de/codeblocksmc/codelib/PotionEffectWrapper.java b/src/main/java/de/codeblocksmc/codelib/PotionEffectWrapper.java deleted file mode 100644 index 1eed5a8..0000000 --- a/src/main/java/de/codeblocksmc/codelib/PotionEffectWrapper.java +++ /dev/null @@ -1,28 +0,0 @@ -package de.codeblocksmc.codelib; - -import lombok.Getter; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; - -@Getter -@Deprecated(forRemoval = true) -public class PotionEffectWrapper { - private final String type; - private final int duration; - private final int amplifier; - - public PotionEffectWrapper(String type, int duration, int amplifier) { - this.type = type; - this.duration = duration; - this.amplifier = amplifier; - } - - - public static PotionEffect fromWrapper(PotionEffectWrapper w) { - return new PotionEffect(PotionEffectType.getByName(w.getType()), w.getDuration() * 20, w.getAmplifier()); - } - - public static PotionEffectWrapper fromBukkit(PotionEffect e) { - return new PotionEffectWrapper(e.getType().getKey().getKey(), e.getDuration() / 20, e.getAmplifier()); - } -} diff --git a/src/main/java/de/codeblocksmc/codelib/ServerConnector.java b/src/main/java/de/codeblocksmc/codelib/ServerConnector.java deleted file mode 100644 index a830db3..0000000 --- a/src/main/java/de/codeblocksmc/codelib/ServerConnector.java +++ /dev/null @@ -1,121 +0,0 @@ -package de.codeblocksmc.codelib; - -import de.simonsator.partyandfriends.spigot.api.pafplayers.PAFPlayerManager; -import de.simonsator.partyandfriends.spigot.api.party.PartyManager; -import io.github.leonardosnt.bungeechannelapi.BungeeChannelApi; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scheduler.BukkitRunnable; - -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * This class handles the connection of players to available servers, taking into account party-related restrictions. - * It ensures that players cannot join a game while being in a party, unless they are the party leader. - * The class communicates with BungeeCord via the {@link BungeeChannelApi} to search for available servers and connect players. - *

- * It also integrates with the PartyAndFriends plugin to check if the player is in a party and if they are the leader. - * If the player is in a party but not the leader, they will not be able to join the server. - *

- * This class operates asynchronously, querying the BungeeCord server list and checking for server availability. - * - * @author JustCody - * @version 1.0 - */ -@Deprecated(forRemoval = true) -public class ServerConnector { - - // Prefix that is used for messages sent to players - private final String prefix; - - // The plugin instance used for API calls and scheduling tasks - private final JavaPlugin plugin; - - /** - * Factory method for creating a new {@link ServerConnector} instance. - * - * @param plugin The plugin instance that will be used for task scheduling and API calls. - * @param prefix The prefix to be used in messages sent to players. - * @return A new {@link ServerConnector} instance. - */ - public static ServerConnector of(JavaPlugin plugin, String prefix) { - return new ServerConnector(plugin, prefix); - } - - /** - * Constructor for initializing the ServerConnector with a plugin and message prefix. - * - * @param plugin The plugin instance that will be used for task scheduling and API calls. - * @param prefix The prefix to be used in messages sent to players. - */ - protected ServerConnector(JavaPlugin plugin, String prefix) { - this.prefix = prefix; - this.plugin = plugin; - } - - /** - * Attempts to connect a player to a server, checking for available servers that match the provided server name. - * It checks if the player is in a party and ensures that they are the party leader before allowing the connection. - *

- * The method will search for a server that is less than 30 players, and if found, it will connect the player to it. - * - * @param player The player to be connected. - * @param servername The name of the server to connect to (partial match). - */ - public void connect(Player player, String servername) { - // Check if the player is in a party and not the leader - if (PartyManager.getInstance().getParty(PAFPlayerManager.getInstance().getPlayer(player.getUniqueId())) != null && - !PartyManager.getInstance().getParty(PAFPlayerManager.getInstance().getPlayer(player.getUniqueId())).getLeader().equals(PAFPlayerManager.getInstance().getPlayer(player.getUniqueId()))) { - player.sendMessage("§cSorry, you can't join a game while being in a party."); - return; - } - - // Notify the player that the search for a free server is starting - player.sendMessage(prefix + "§aLooking for free server in §e" + servername + "§a..."); - - // Get the BungeeChannelApi instance to interact with BungeeCord - BungeeChannelApi api = BungeeChannelApi.of(plugin); - - // Run the connection task asynchronously - new BukkitRunnable() { - - @Override - public void run() { - // Fetch the list of available servers - api.getServers().whenComplete((result, error) -> { - AtomicBoolean found = new AtomicBoolean(false); - - // Loop through the servers and check if one matches the specified servername - for (String server : result) { - if (!server.startsWith(servername)) continue; - - // Get the player count for the current server - api.getPlayerCount(server).whenComplete((count, err) -> { - // If the server has less than 30 players, connect the player - if (count < 30) { - api.connect(player, server); - found.set(true); - } - }); - } - - // Notify the player if no free server was found after the search - new BukkitRunnable() { - @Override - public void run() { - try { - if (!found.get()) { - player.sendMessage(prefix + "§7We could not find a free server. Sorry for the inconvenience!"); - } - } catch (Exception e) { - // Handle any errors when notifying the player - plugin.getLogger().warning(e.getMessage()); - } - } - }.runTaskLater(plugin, 5); // Delay to allow for the server search to complete - }); - } - - }.runTaskLater(plugin, 0); // Run the task immediately - } -} diff --git a/src/main/java/de/codeblocksmc/codelib/TimeUtil.java b/src/main/java/de/codeblocksmc/codelib/TimeUtil.java deleted file mode 100644 index aa5dfde..0000000 --- a/src/main/java/de/codeblocksmc/codelib/TimeUtil.java +++ /dev/null @@ -1,51 +0,0 @@ -package de.codeblocksmc.codelib; - -import java.time.LocalDateTime; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -@Deprecated(forRemoval = true) -public class TimeUtil { - public static LocalDateTime addTimeSpan(String timeSpan) { - LocalDateTime now = LocalDateTime.now(); - return addTimeSpan(now, timeSpan); - } - - public static LocalDateTime addTimeSpan(LocalDateTime dateTime, String timeSpan) { - Pattern pattern = Pattern.compile("(\\d+)([yMwdhms])"); - Matcher matcher = pattern.matcher(timeSpan); - - while (matcher.find()) { - int value = Integer.parseInt(matcher.group(1)); - char unit = matcher.group(2).charAt(0); - - switch (unit) { - case 'y': - dateTime = dateTime.plusYears(value); - break; - case 'M': - dateTime = dateTime.plusMonths(value); - break; - case 'w': - dateTime = dateTime.plusWeeks(value); // Wochen in Tage umrechnen - break; - case 'd': - dateTime = dateTime.plusDays(value); - break; - case 'h': - dateTime = dateTime.plusHours(value); - break; - case 'm': - dateTime = dateTime.plusMinutes(value); - break; - case 's': - dateTime = dateTime.plusSeconds(value); - break; - default: - throw new IllegalArgumentException("Ungültige Zeitspanne: " + unit); - } - } - - return dateTime; - } -} \ No newline at end of file diff --git a/src/main/java/de/codeblocksmc/codelib/chat/AdvancedTabCompleter.java b/src/main/java/de/codeblocksmc/codelib/api/chat/AdvancedTabCompleter.java similarity index 95% rename from src/main/java/de/codeblocksmc/codelib/chat/AdvancedTabCompleter.java rename to src/main/java/de/codeblocksmc/codelib/api/chat/AdvancedTabCompleter.java index 386efb8..253790b 100644 --- a/src/main/java/de/codeblocksmc/codelib/chat/AdvancedTabCompleter.java +++ b/src/main/java/de/codeblocksmc/codelib/api/chat/AdvancedTabCompleter.java @@ -1,4 +1,4 @@ -package de.codeblocksmc.codelib.chat; +package de.codeblocksmc.codelib.api.chat; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/src/main/java/de/codeblocksmc/codelib/chat/ChatUtil.java b/src/main/java/de/codeblocksmc/codelib/api/chat/ChatUtil.java similarity index 97% rename from src/main/java/de/codeblocksmc/codelib/chat/ChatUtil.java rename to src/main/java/de/codeblocksmc/codelib/api/chat/ChatUtil.java index e1af18a..cc6c64b 100644 --- a/src/main/java/de/codeblocksmc/codelib/chat/ChatUtil.java +++ b/src/main/java/de/codeblocksmc/codelib/api/chat/ChatUtil.java @@ -1,4 +1,4 @@ -package de.codeblocksmc.codelib.chat; +package de.codeblocksmc.codelib.api.chat; public class ChatUtil { public static String getColorCode(int level) { diff --git a/src/main/java/de/codeblocksmc/codelib/api/databsae/DatabaseObject.java b/src/main/java/de/codeblocksmc/codelib/api/databsae/DatabaseObject.java new file mode 100644 index 0000000..d32e7a3 --- /dev/null +++ b/src/main/java/de/codeblocksmc/codelib/api/databsae/DatabaseObject.java @@ -0,0 +1,4 @@ +package de.codeblocksmc.codelib.api.databsae; + +public class DatabaseObject { +} diff --git a/src/main/java/de/codeblocksmc/codelib/databsae/MSSQLTemplate.java b/src/main/java/de/codeblocksmc/codelib/api/databsae/MSSQLTemplate.java similarity index 97% rename from src/main/java/de/codeblocksmc/codelib/databsae/MSSQLTemplate.java rename to src/main/java/de/codeblocksmc/codelib/api/databsae/MSSQLTemplate.java index cc7b197..9eade1d 100644 --- a/src/main/java/de/codeblocksmc/codelib/databsae/MSSQLTemplate.java +++ b/src/main/java/de/codeblocksmc/codelib/api/databsae/MSSQLTemplate.java @@ -1,4 +1,4 @@ -package de.codeblocksmc.codelib.databsae; +package de.codeblocksmc.codelib.api.databsae; import lombok.Getter; diff --git a/src/main/java/de/codeblocksmc/codelib/databsae/MySQLTemplate.java b/src/main/java/de/codeblocksmc/codelib/api/databsae/MySQLTemplate.java similarity index 98% rename from src/main/java/de/codeblocksmc/codelib/databsae/MySQLTemplate.java rename to src/main/java/de/codeblocksmc/codelib/api/databsae/MySQLTemplate.java index 30e743f..e37d120 100644 --- a/src/main/java/de/codeblocksmc/codelib/databsae/MySQLTemplate.java +++ b/src/main/java/de/codeblocksmc/codelib/api/databsae/MySQLTemplate.java @@ -1,4 +1,4 @@ -package de.codeblocksmc.codelib.databsae; +package de.codeblocksmc.codelib.api.databsae; import java.sql.Connection; import java.sql.DriverManager; diff --git a/src/main/java/de/codeblocksmc/codelib/databsae/MySQLTemplateVelocity.java b/src/main/java/de/codeblocksmc/codelib/api/databsae/MySQLTemplateVelocity.java similarity index 97% rename from src/main/java/de/codeblocksmc/codelib/databsae/MySQLTemplateVelocity.java rename to src/main/java/de/codeblocksmc/codelib/api/databsae/MySQLTemplateVelocity.java index c61c630..18032ed 100644 --- a/src/main/java/de/codeblocksmc/codelib/databsae/MySQLTemplateVelocity.java +++ b/src/main/java/de/codeblocksmc/codelib/api/databsae/MySQLTemplateVelocity.java @@ -1,4 +1,4 @@ -package de.codeblocksmc.codelib.databsae; +package de.codeblocksmc.codelib.api.databsae; import org.slf4j.Logger; diff --git a/src/main/java/de/codeblocksmc/codelib/locations/LocUtil.java b/src/main/java/de/codeblocksmc/codelib/api/locations/LocUtil.java similarity index 99% rename from src/main/java/de/codeblocksmc/codelib/locations/LocUtil.java rename to src/main/java/de/codeblocksmc/codelib/api/locations/LocUtil.java index ac11eb5..0a9baee 100644 --- a/src/main/java/de/codeblocksmc/codelib/locations/LocUtil.java +++ b/src/main/java/de/codeblocksmc/codelib/api/locations/LocUtil.java @@ -1,4 +1,4 @@ -package de.codeblocksmc.codelib.locations; +package de.codeblocksmc.codelib.api.locations; import org.bukkit.Bukkit; import org.bukkit.Location; diff --git a/src/main/java/de/codeblocksmc/codelib/locations/LocationSection.java b/src/main/java/de/codeblocksmc/codelib/api/locations/LocationSection.java similarity index 98% rename from src/main/java/de/codeblocksmc/codelib/locations/LocationSection.java rename to src/main/java/de/codeblocksmc/codelib/api/locations/LocationSection.java index 5e86950..47e691e 100644 --- a/src/main/java/de/codeblocksmc/codelib/locations/LocationSection.java +++ b/src/main/java/de/codeblocksmc/codelib/api/locations/LocationSection.java @@ -1,4 +1,4 @@ -package de.codeblocksmc.codelib.locations; +package de.codeblocksmc.codelib.api.locations; import lombok.Getter; import org.bukkit.Location; diff --git a/src/main/java/de/codeblocksmc/codelib/locations/LocationWrapper.java b/src/main/java/de/codeblocksmc/codelib/api/locations/LocationWrapper.java similarity index 98% rename from src/main/java/de/codeblocksmc/codelib/locations/LocationWrapper.java rename to src/main/java/de/codeblocksmc/codelib/api/locations/LocationWrapper.java index d161785..b2733c7 100644 --- a/src/main/java/de/codeblocksmc/codelib/locations/LocationWrapper.java +++ b/src/main/java/de/codeblocksmc/codelib/api/locations/LocationWrapper.java @@ -1,4 +1,4 @@ -package de.codeblocksmc.codelib.locations; +package de.codeblocksmc.codelib.api.locations; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/de/codeblocksmc/codelib/util/JSONFileHelper.java b/src/main/java/de/codeblocksmc/codelib/api/util/JSONFileHelper.java similarity index 98% rename from src/main/java/de/codeblocksmc/codelib/util/JSONFileHelper.java rename to src/main/java/de/codeblocksmc/codelib/api/util/JSONFileHelper.java index a0509ae..bde66f9 100644 --- a/src/main/java/de/codeblocksmc/codelib/util/JSONFileHelper.java +++ b/src/main/java/de/codeblocksmc/codelib/api/util/JSONFileHelper.java @@ -1,4 +1,4 @@ -package de.codeblocksmc.codelib.util; +package de.codeblocksmc.codelib.api.util; import com.google.gson.Gson; import com.google.gson.GsonBuilder; diff --git a/src/main/java/de/codeblocksmc/codelib/util/ServerConnector.java b/src/main/java/de/codeblocksmc/codelib/api/util/ServerConnector.java similarity index 99% rename from src/main/java/de/codeblocksmc/codelib/util/ServerConnector.java rename to src/main/java/de/codeblocksmc/codelib/api/util/ServerConnector.java index 217cbc2..c52d223 100644 --- a/src/main/java/de/codeblocksmc/codelib/util/ServerConnector.java +++ b/src/main/java/de/codeblocksmc/codelib/api/util/ServerConnector.java @@ -1,4 +1,4 @@ -package de.codeblocksmc.codelib.util; +package de.codeblocksmc.codelib.api.util; import de.simonsator.partyandfriends.spigot.api.pafplayers.PAFPlayerManager; import de.simonsator.partyandfriends.spigot.api.party.PartyManager; diff --git a/src/main/java/de/codeblocksmc/codelib/util/TimeUtil.java b/src/main/java/de/codeblocksmc/codelib/api/util/TimeUtil.java similarity index 97% rename from src/main/java/de/codeblocksmc/codelib/util/TimeUtil.java rename to src/main/java/de/codeblocksmc/codelib/api/util/TimeUtil.java index 9ad1a69..9a4a2da 100644 --- a/src/main/java/de/codeblocksmc/codelib/util/TimeUtil.java +++ b/src/main/java/de/codeblocksmc/codelib/api/util/TimeUtil.java @@ -1,4 +1,4 @@ -package de.codeblocksmc.codelib.util; +package de.codeblocksmc.codelib.api.util; import java.time.LocalDateTime; import java.util.regex.Matcher; diff --git a/src/main/java/de/codeblocksmc/codelib/worldman/WorldManCmd.java b/src/main/java/de/codeblocksmc/codelib/api/worldman/WorldManCmd.java similarity index 96% rename from src/main/java/de/codeblocksmc/codelib/worldman/WorldManCmd.java rename to src/main/java/de/codeblocksmc/codelib/api/worldman/WorldManCmd.java index c795f48..d812c44 100644 --- a/src/main/java/de/codeblocksmc/codelib/worldman/WorldManCmd.java +++ b/src/main/java/de/codeblocksmc/codelib/api/worldman/WorldManCmd.java @@ -1,8 +1,6 @@ -package de.codeblocksmc.codelib.worldman; +package de.codeblocksmc.codelib.api.worldman; import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.block.data.type.TNT; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; diff --git a/src/main/java/de/codeblocksmc/codelib/worldman/WorldManCom.java b/src/main/java/de/codeblocksmc/codelib/api/worldman/WorldManCom.java similarity index 92% rename from src/main/java/de/codeblocksmc/codelib/worldman/WorldManCom.java rename to src/main/java/de/codeblocksmc/codelib/api/worldman/WorldManCom.java index 29b4b13..1e3833f 100644 --- a/src/main/java/de/codeblocksmc/codelib/worldman/WorldManCom.java +++ b/src/main/java/de/codeblocksmc/codelib/api/worldman/WorldManCom.java @@ -1,6 +1,6 @@ -package de.codeblocksmc.codelib.worldman; +package de.codeblocksmc.codelib.api.worldman; -import de.codeblocksmc.codelib.AdvancedTabCompleter; +import de.codeblocksmc.codelib.api.chat.AdvancedTabCompleter; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; diff --git a/src/main/java/de/codeblocksmc/codelib/worldman/WorldManager.java b/src/main/java/de/codeblocksmc/codelib/api/worldman/WorldManager.java similarity index 93% rename from src/main/java/de/codeblocksmc/codelib/worldman/WorldManager.java rename to src/main/java/de/codeblocksmc/codelib/api/worldman/WorldManager.java index b9935a2..dc8dbf1 100644 --- a/src/main/java/de/codeblocksmc/codelib/worldman/WorldManager.java +++ b/src/main/java/de/codeblocksmc/codelib/api/worldman/WorldManager.java @@ -1,6 +1,5 @@ -package de.codeblocksmc.codelib.worldman; +package de.codeblocksmc.codelib.api.worldman; -import de.codeblocksmc.codelib.locations.LocationWrapper; import lombok.Getter; import org.bukkit.*; import org.bukkit.permissions.Permission; diff --git a/src/main/java/de/codeblocksmc/codelib/wrapping/EnchantmentWrapper.java b/src/main/java/de/codeblocksmc/codelib/api/wrapping/EnchantmentWrapper.java similarity index 96% rename from src/main/java/de/codeblocksmc/codelib/wrapping/EnchantmentWrapper.java rename to src/main/java/de/codeblocksmc/codelib/api/wrapping/EnchantmentWrapper.java index d1b9c0c..cc47985 100644 --- a/src/main/java/de/codeblocksmc/codelib/wrapping/EnchantmentWrapper.java +++ b/src/main/java/de/codeblocksmc/codelib/api/wrapping/EnchantmentWrapper.java @@ -1,4 +1,4 @@ -package de.codeblocksmc.codelib.wrapping; +package de.codeblocksmc.codelib.api.wrapping; import lombok.Getter; diff --git a/src/main/java/de/codeblocksmc/codelib/wrapping/GuiBuilder.java b/src/main/java/de/codeblocksmc/codelib/api/wrapping/GuiBuilder.java similarity index 99% rename from src/main/java/de/codeblocksmc/codelib/wrapping/GuiBuilder.java rename to src/main/java/de/codeblocksmc/codelib/api/wrapping/GuiBuilder.java index 05f0244..a799135 100644 --- a/src/main/java/de/codeblocksmc/codelib/wrapping/GuiBuilder.java +++ b/src/main/java/de/codeblocksmc/codelib/api/wrapping/GuiBuilder.java @@ -1,4 +1,4 @@ -package de.codeblocksmc.codelib.wrapping; +package de.codeblocksmc.codelib.api.wrapping; import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; diff --git a/src/main/java/de/codeblocksmc/codelib/wrapping/ItemBuilder.java b/src/main/java/de/codeblocksmc/codelib/api/wrapping/ItemBuilder.java similarity index 99% rename from src/main/java/de/codeblocksmc/codelib/wrapping/ItemBuilder.java rename to src/main/java/de/codeblocksmc/codelib/api/wrapping/ItemBuilder.java index 9ced3f4..3ecfd22 100644 --- a/src/main/java/de/codeblocksmc/codelib/wrapping/ItemBuilder.java +++ b/src/main/java/de/codeblocksmc/codelib/api/wrapping/ItemBuilder.java @@ -1,4 +1,4 @@ -package de.codeblocksmc.codelib.wrapping; +package de.codeblocksmc.codelib.api.wrapping; import com.destroystokyo.paper.profile.PlayerProfile; import net.kyori.adventure.text.Component; diff --git a/src/main/java/de/codeblocksmc/codelib/wrapping/ItemWrapper.java b/src/main/java/de/codeblocksmc/codelib/api/wrapping/ItemWrapper.java similarity index 97% rename from src/main/java/de/codeblocksmc/codelib/wrapping/ItemWrapper.java rename to src/main/java/de/codeblocksmc/codelib/api/wrapping/ItemWrapper.java index ec12408..2e23d45 100644 --- a/src/main/java/de/codeblocksmc/codelib/wrapping/ItemWrapper.java +++ b/src/main/java/de/codeblocksmc/codelib/api/wrapping/ItemWrapper.java @@ -1,4 +1,4 @@ -package de.codeblocksmc.codelib.wrapping; +package de.codeblocksmc.codelib.api.wrapping; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/de/codeblocksmc/codelib/wrapping/PotionEffectWrapper.java b/src/main/java/de/codeblocksmc/codelib/api/wrapping/PotionEffectWrapper.java similarity index 94% rename from src/main/java/de/codeblocksmc/codelib/wrapping/PotionEffectWrapper.java rename to src/main/java/de/codeblocksmc/codelib/api/wrapping/PotionEffectWrapper.java index 51428b2..4e4fbbf 100644 --- a/src/main/java/de/codeblocksmc/codelib/wrapping/PotionEffectWrapper.java +++ b/src/main/java/de/codeblocksmc/codelib/api/wrapping/PotionEffectWrapper.java @@ -1,4 +1,4 @@ -package de.codeblocksmc.codelib.wrapping; +package de.codeblocksmc.codelib.api.wrapping; import lombok.Getter; import org.bukkit.potion.PotionEffect; diff --git a/src/main/java/de/codeblocksmc/codelib/databsae/DatabaseObject.java b/src/main/java/de/codeblocksmc/codelib/databsae/DatabaseObject.java deleted file mode 100644 index eb40cc9..0000000 --- a/src/main/java/de/codeblocksmc/codelib/databsae/DatabaseObject.java +++ /dev/null @@ -1,4 +0,0 @@ -package de.codeblocksmc.codelib.databsae; - -public class DatabaseObject { -} From d44f40ac14e4b3d3648acebc2dce825c7809f9e6 Mon Sep 17 00:00:00 2001 From: Julian Weinelt Date: Tue, 27 May 2025 15:41:56 +0200 Subject: [PATCH 02/12] Directly implemented BungeeChannelApi --- .../codelib/api/util/BungeeChannelApi.java | 545 ++++++++++++++++++ 1 file changed, 545 insertions(+) create mode 100644 src/main/java/de/codeblocksmc/codelib/api/util/BungeeChannelApi.java diff --git a/src/main/java/de/codeblocksmc/codelib/api/util/BungeeChannelApi.java b/src/main/java/de/codeblocksmc/codelib/api/util/BungeeChannelApi.java new file mode 100644 index 0000000..0a719a9 --- /dev/null +++ b/src/main/java/de/codeblocksmc/codelib/api/util/BungeeChannelApi.java @@ -0,0 +1,545 @@ +/** + * https://github.com/leonardosnt/bungeechannelapi + * + * Copyright (C) 2017 leonardosnt + * Licensed under the MIT License. See LICENSE file in the project root for full license information. + */ + +package de.codeblocksmc.codelib.api.util; + +import java.net.InetSocketAddress; +import java.util.ArrayDeque; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Queue; +import java.util.WeakHashMap; +import java.util.concurrent.CompletableFuture; +import java.util.function.BiFunction; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.messaging.Messenger; +import org.bukkit.plugin.messaging.PluginMessageListener; + +import com.google.common.collect.Iterables; +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; + +/** + * Documentation copied from https://www.spigotmc.org/wiki/bukkit-bungee-plugin-messaging-channel/ + * + * @author leonardosnt (leonrdsnt@gmail.com) + * @see https://www.spigotmc.org/wiki/bukkit-bungee-plugin-messaging-channel/ + */ +public class BungeeChannelApi { + + private static WeakHashMap registeredInstances = new WeakHashMap<>(); + + private final PluginMessageListener messageListener; + private final Plugin plugin; + private final Map>> callbackMap; + + private Map forwardListeners; + private ForwardConsumer globalForwardListener; + + /** + * Get or create new BungeeChannelApi instance + * + * @param plugin the plugin instance. + * @return the BungeeChannelApi instance for the {@code plugin} + * @throws NullPointerException if the {@code plugin} is {@code null} + */ + public synchronized static BungeeChannelApi of(Plugin plugin) { + return registeredInstances.compute(plugin, (k, v) -> { + if (v == null) v = new BungeeChannelApi(plugin); + return v; + }); + } + + public BungeeChannelApi(Plugin plugin) { + this.plugin = Objects.requireNonNull(plugin, "plugin cannot be null"); + this.callbackMap = new HashMap<>(); + + // Prevent dev's from registering multiple channel listeners, + // by unregistering the old instance. + synchronized (registeredInstances) { + registeredInstances.compute(plugin, (k, oldInstance) -> { + if (oldInstance != null) oldInstance.unregister(); + return this; + }); + } + + this.messageListener = this::onPluginMessageReceived; + + Messenger messenger = Bukkit.getServer().getMessenger(); + messenger.registerOutgoingPluginChannel(plugin, "BungeeCord"); + messenger.registerIncomingPluginChannel(plugin, "BungeeCord", messageListener); + } + + /** + * Set a global listener for all 'forwarded' messages. + * + * @param globalListener the listener + * @see https://www.spigotmc.org/wiki/bukkit-bungee-plugin-messaging-channel/#forward + */ + public void registerForwardListener(ForwardConsumer globalListener) { + this.globalForwardListener = globalListener; + } + + /** + * Set a listener for all 'forwarded' messages in a specific subchannel. + * + * @param channelName the subchannel name + * @param listener the listener + * @see https://www.spigotmc.org/wiki/bukkit-bungee-plugin-messaging-channel/#forward + */ + public void registerForwardListener(String channelName, ForwardConsumer listener) { + if (forwardListeners == null) { + forwardListeners = new HashMap<>(); + } + synchronized (forwardListeners) { + forwardListeners.put(channelName, listener); + } + } + + /** + * Get the amount of players on a certain server, or on ALL the servers. + * + * @param serverName the server name of the server to get the player count of, or ALL to get the global player count + * @return A {@link CompletableFuture} that, when completed, will return + * the amount of players on a certain server, or on ALL the servers. + * @throws IllegalArgumentException if there is no players online. + */ + public CompletableFuture getPlayerCount(String serverName) { + Player player = getFirstPlayer(); + CompletableFuture future = new CompletableFuture<>(); + + synchronized (callbackMap) { + callbackMap.compute("PlayerCount-" + serverName, this.computeQueueValue(future)); + } + + ByteArrayDataOutput output = ByteStreams.newDataOutput(); + output.writeUTF("PlayerCount"); + output.writeUTF(serverName); + player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray()); + return future; + } + + /** + * Get a list of players connected on a certain server, or on ALL the servers. + * + * @param serverName the name of the server to get the list of connected players, or ALL for global online player list + * @return A {@link CompletableFuture} that, when completed, will return a + * list of players connected on a certain server, or on ALL the servers. + * @throws IllegalArgumentException if there is no players online. + */ + public CompletableFuture> getPlayerList(String serverName) { + Player player = getFirstPlayer(); + CompletableFuture> future = new CompletableFuture<>(); + + synchronized (callbackMap) { + callbackMap.compute("PlayerList-" + serverName, this.computeQueueValue(future)); + } + + ByteArrayDataOutput output = ByteStreams.newDataOutput(); + output.writeUTF("PlayerList"); + output.writeUTF(serverName); + player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray()); + return future; + } + + /** + * Get a list of server name strings, as defined in BungeeCord's config.yml. + * + * @return A {@link CompletableFuture} that, when completed, will return a + * list of server name strings, as defined in BungeeCord's config.yml. + * @throws IllegalArgumentException if there is no players online. + */ + public CompletableFuture> getServers() { + Player player = getFirstPlayer(); + CompletableFuture> future = new CompletableFuture<>(); + + synchronized (callbackMap) { + callbackMap.compute("GetServers", this.computeQueueValue(future)); + } + + ByteArrayDataOutput output = ByteStreams.newDataOutput(); + output.writeUTF("GetServers"); + player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray()); + return future; + } + + /** + * Connects a player to said subserver. + * + * @param player the player you want to teleport. + * @param serverName the name of server to connect to, as defined in BungeeCord config.yml. + */ + public void connect(Player player, String serverName) { + ByteArrayDataOutput output = ByteStreams.newDataOutput(); + output.writeUTF("Connect"); + output.writeUTF(serverName); + player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray()); + } + + /** + * Connect a named player to said subserver. + * + * @param playerName name of the player to teleport. + * @param server name of server to connect to, as defined in BungeeCord config.yml. + * @throws IllegalArgumentException if there is no players online. + */ + public void connectOther(String playerName, String server) { + Player player = getFirstPlayer(); + ByteArrayDataOutput output = ByteStreams.newDataOutput(); + + output.writeUTF("ConnectOther"); + output.writeUTF(playerName); + output.writeUTF(server); + + player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray()); + } + + /** + * Get the (real) IP of a player. + * + * @param player The player you wish to get the IP of. + * @return A {@link CompletableFuture} that, when completed, will return the (real) IP of {@code player}. + */ + public CompletableFuture getIp(Player player) { + CompletableFuture future = new CompletableFuture<>(); + + synchronized (callbackMap) { + callbackMap.compute("IP", this.computeQueueValue(future)); + } + + ByteArrayDataOutput output = ByteStreams.newDataOutput(); + output.writeUTF("IP"); + player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray()); + return future; + } + + /** + * Send a message (as in, a chat message) to the specified player. + * + * @param playerName the name of the player to send the chat message. + * @param message the message to send to the player. + * @throws IllegalArgumentException if there is no players online. + */ + public void sendMessage(String playerName, String message) { + Player player = getFirstPlayer(); + ByteArrayDataOutput output = ByteStreams.newDataOutput(); + + output.writeUTF("Message"); + output.writeUTF(playerName); + output.writeUTF(message); + player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray()); + } + + /** + * Get this server's name, as defined in BungeeCord's config.yml + * + * @return A {@link CompletableFuture} that, when completed, will return + * the {@code server's} name, as defined in BungeeCord's config.yml. + * @throws IllegalArgumentException if there is no players online. + */ + public CompletableFuture getServer() { + Player player = getFirstPlayer(); + CompletableFuture future = new CompletableFuture<>(); + + synchronized (callbackMap) { + callbackMap.compute("GetServer", this.computeQueueValue(future)); + } + + ByteArrayDataOutput output = ByteStreams.newDataOutput(); + output.writeUTF("GetServer"); + player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray()); + return future; + } + + /** + * Request the UUID of this player. + * + * @param player The player whose UUID you requested. + * @return A {@link CompletableFuture} that, when completed, will return the UUID of {@code player}. + */ + public CompletableFuture getUUID(Player player) { + CompletableFuture future = new CompletableFuture<>(); + + synchronized (callbackMap) { + callbackMap.compute("UUID", this.computeQueueValue(future)); + } + + ByteArrayDataOutput output = ByteStreams.newDataOutput(); + output.writeUTF("UUID"); + player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray()); + return future; + } + + /** + * Request the UUID of any player connected to the BungeeCord proxy. + * + * @param playerName the name of the player whose UUID you would like. + * @return A {@link CompletableFuture} that, when completed, will return the UUID of {@code playerName}. + * @throws IllegalArgumentException if there is no players online. + */ + public CompletableFuture getUUID(String playerName) { + Player player = getFirstPlayer(); + CompletableFuture future = new CompletableFuture<>(); + + synchronized (callbackMap) { + callbackMap.compute("UUIDOther-" + playerName, this.computeQueueValue(future)); + } + + ByteArrayDataOutput output = ByteStreams.newDataOutput(); + output.writeUTF("UUIDOther"); + output.writeUTF(playerName); + player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray()); + return future; + } + + /** + * Request the IP of any server on this proxy. + * + * @param serverName the name of the server. + * @return A {@link CompletableFuture} that, when completed, will return the requested ip. + * @throws IllegalArgumentException if there is no players online. + */ + public CompletableFuture getServerIp(String serverName) { + Player player = getFirstPlayer(); + CompletableFuture future = new CompletableFuture<>(); + + synchronized (callbackMap) { + callbackMap.compute("ServerIP-" + serverName, this.computeQueueValue(future)); + } + + ByteArrayDataOutput output = ByteStreams.newDataOutput(); + output.writeUTF("ServerIP"); + output.writeUTF(serverName); + player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray()); + return future; + } + + /** + * Kick any player on this proxy. + * + * @param playerName the name of the player. + * @param kickMessage the reason the player is kicked with. + * @throws IllegalArgumentException if there is no players online. + */ + public void kickPlayer(String playerName, String kickMessage) { + Player player = getFirstPlayer(); + CompletableFuture future = new CompletableFuture<>(); + + synchronized (callbackMap) { + callbackMap.compute("KickPlayer", this.computeQueueValue(future)); + } + + ByteArrayDataOutput output = ByteStreams.newDataOutput(); + output.writeUTF("KickPlayer"); + output.writeUTF(playerName); + output.writeUTF(kickMessage); + player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray()); + } + + /** + * Send a custom plugin message to said server. This is one of the most useful channels ever. + * Remember, the sending and receiving server(s) need to have a player online. + * + * @param server the name of the server to send to, + * ALL to send to every server (except the one sending the plugin message), + * or ONLINE to send to every server that's online (except the one sending the plugin message). + * + * @param channelName Subchannel for plugin usage. + * @param data data to send. + * @throws IllegalArgumentException if there is no players online. + */ + public void forward(String server, String channelName, byte[] data) { + Player player = getFirstPlayer(); + + ByteArrayDataOutput output = ByteStreams.newDataOutput(); + output.writeUTF("Forward"); + output.writeUTF(server); + output.writeUTF(channelName); + output.writeShort(data.length); + output.write(data); + player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray()); + } + + /** + * Send a custom plugin message to specific player. + * + * @param playerName the name of the player to send to. + * @param channelName Subchannel for plugin usage. + * @param data data to send. + * @throws IllegalArgumentException if there is no players online. + */ + public void forwardToPlayer(String playerName, String channelName, byte[] data) { + Player player = getFirstPlayer(); + + ByteArrayDataOutput output = ByteStreams.newDataOutput(); + output.writeUTF("ForwardToPlayer"); + output.writeUTF(playerName); + output.writeUTF(channelName); + output.writeShort(data.length); + output.write(data); + player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray()); + } + + @SuppressWarnings("unchecked") + private void onPluginMessageReceived(String channel, Player player, byte[] message) { + if (!channel.equalsIgnoreCase("BungeeCord")) return; + + ByteArrayDataInput input = ByteStreams.newDataInput(message); + String subchannel = input.readUTF(); + + synchronized (callbackMap) { + Queue> callbacks; + + if (subchannel.equals("PlayerCount") || subchannel.equals("PlayerList") || + subchannel.equals("UUIDOther") || subchannel.equals("ServerIP")) { + String identifier = input.readUTF(); // Server/player name + callbacks = callbackMap.get(subchannel + "-" + identifier); + + if (callbacks == null || callbacks.isEmpty()) { + return; + } + + CompletableFuture callback = callbacks.poll(); + + try { + switch (subchannel) { + case "PlayerCount": + ((CompletableFuture) callback).complete(Integer.valueOf(input.readInt())); + break; + + case "PlayerList": + ((CompletableFuture>) callback).complete(Arrays.asList(input.readUTF().split(", "))); + break; + + case "UUIDOther": + ((CompletableFuture) callback).complete(input.readUTF()); + break; + + case "ServerIP": { + String ip = input.readUTF(); + int port = input.readUnsignedShort(); + ((CompletableFuture) callback).complete(new InetSocketAddress(ip, port)); + break; + } + } + } catch(Exception ex) { + callback.completeExceptionally(ex); + } + + return; + } + + callbacks = callbackMap.get(subchannel); + + if (callbacks == null) { + short dataLength = input.readShort(); + byte[] data = new byte[dataLength]; + input.readFully(data); + + if (globalForwardListener != null) { + globalForwardListener.accept(subchannel, player, data); + } + + if (forwardListeners != null) { + synchronized (forwardListeners) { + ForwardConsumer listener = forwardListeners.get(subchannel); + if (listener != null) { + listener.accept(subchannel, player, data); + } + } + } + + return; + } + + if (callbacks.isEmpty()) { + return; + } + + final CompletableFuture callback = callbacks.poll(); + + try { + switch (subchannel) { + case "GetServers": + ((CompletableFuture>) callback).complete(Arrays.asList(input.readUTF().split(", "))); + break; + + case "GetServer": + case "UUID": + ((CompletableFuture) callback).complete(input.readUTF()); + break; + + case "IP": { + String ip = input.readUTF(); + int port = input.readInt(); + ((CompletableFuture) callback).complete(new InetSocketAddress(ip, port)); + break; + } + + default: + break; + } + } catch(Exception ex) { + callback.completeExceptionally(ex); + } + } + } + + /** + * Unregister message channels. + */ + public void unregister() { + Messenger messenger = Bukkit.getServer().getMessenger(); + messenger.unregisterIncomingPluginChannel(plugin, "BungeeCord", messageListener); + messenger.unregisterOutgoingPluginChannel(plugin); + callbackMap.clear(); + } + + private BiFunction>, Queue>> computeQueueValue(CompletableFuture queueValue) { + return (key, value) -> { + if (value == null) value = new ArrayDeque>(); + value.add(queueValue); + return value; + }; + } + + private Player getFirstPlayer() { + /** + * if Bukkit Version < 1.7.10 then Bukkit.getOnlinePlayers() will return + * a Player[] otherwise it'll return a Collection. + */ + Player firstPlayer = getFirstPlayer0(Bukkit.getOnlinePlayers()); + + if (firstPlayer == null) { + throw new IllegalArgumentException("Bungee Messaging Api requires at least one player to be online."); + } + + return firstPlayer; + } + + @SuppressWarnings("unused") + private Player getFirstPlayer0(Player[] playerArray) { + return playerArray.length > 0 ? playerArray[0] : null; + } + + private Player getFirstPlayer0(Collection playerCollection) { + return Iterables.getFirst(playerCollection, null); + } + + @FunctionalInterface + public interface ForwardConsumer { + void accept(String channel, Player player, byte[] data); + } +} \ No newline at end of file From 144be7ee67ed50e1293cf66166ac58d16e17001e Mon Sep 17 00:00:00 2001 From: Julian Weinelt Date: Tue, 27 May 2025 15:42:13 +0200 Subject: [PATCH 03/12] feat(minecraft plugin) --- .../java/de/codeblocksmc/codelib/CodeLib.java | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/main/java/de/codeblocksmc/codelib/CodeLib.java diff --git a/src/main/java/de/codeblocksmc/codelib/CodeLib.java b/src/main/java/de/codeblocksmc/codelib/CodeLib.java new file mode 100644 index 0000000..316e9a4 --- /dev/null +++ b/src/main/java/de/codeblocksmc/codelib/CodeLib.java @@ -0,0 +1,90 @@ +package de.codeblocksmc.codelib; + +import lombok.Getter; +import org.bukkit.Bukkit; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.logging.Logger; + +public class CodeLib extends JavaPlugin { + @Getter + private static final String version = "4.0.0"; + + @Getter + private static CodeLib instance; + + @Getter + private Logger log; + private PluginManager pluginManager; + + @Override + public void onLoad() { + instance = this; + } + + @Override + public void onEnable() { + log.info(""" + ____ _ _ _ _ \s + / ___|___ __| | ___| | (_) |__ \s + | | / _ \\ / _` |/ _ \\ | | | '_ \\\s + | |__| (_) | (_| | __/ |___| | |_) | + \\____\\___/ \\__,_|\\___|_____|_|_.__/\s + \ + """); + log.info("Starting CodeLib v" + version); + checkServerVersion(); + checkForCaesar(); + + } + + @Override + public void onDisable() { + + } + + private void checkServerVersion() { + String version = Bukkit.getVersion().toLowerCase(); + + if (version.contains("paper")) { + log.info("Running on Paper v" + getServer().getMinecraftVersion()); + } else if (version.contains("spigot")) { + log.info("Running on Spigot v" + getServer().getMinecraftVersion()); + log.warning("WARNING: _____________________________________________"); + log.warning(" | |"); + log.warning(" | This server seems to be running SpigotMC! |"); + log.warning(" | Some features may not work properly! |"); + log.warning(" | Please use PAPER or PURPUR for the best |"); + log.warning(" | Experience!!! |"); + log.warning(" | ___________________________________________ |"); + } else if (version.contains("purpur")) { + log.info("Running on Purpur v" + getServer().getMinecraftVersion()); + } else if (version.contains("folia")) { + log.info("Running on Folia v" + getServer().getMinecraftVersion()); + } else { + log.warning(""" + _____ \s + / / \\ \\ \s + / /| |\\ \\ \s + / / |_| \\ \\\s + /_/__(_)__\\_\\ + + """); + log.warning("WARNING: _____________________________________________"); + log.warning(" | |"); + log.warning(" | This server is running an unknown software! |"); + log.warning(" | Expect broken features and bugs. |"); + log.warning(" | Please use PAPER or PURPUR for the best |"); + log.warning(" | Experience!!! |"); + log.warning(" | ___________________________________________ |"); + } + } + + private void checkForCaesar() { + log.info("Checking availability of Caesar..."); + if (pluginManager.getPlugin("CaesarConnector") != null) { + log.info("Caesar has been detected. Registering internal expansions..."); + } + } +} \ No newline at end of file From 5a70e424f7f4e0c0ea46ac4466ee2c5aa8a239cc Mon Sep 17 00:00:00 2001 From: Julian Weinelt Date: Tue, 27 May 2025 15:42:24 +0200 Subject: [PATCH 04/12] feat(nick system) --- .../de/codeblocksmc/codelib/api/CodeNick.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/de/codeblocksmc/codelib/api/CodeNick.java diff --git a/src/main/java/de/codeblocksmc/codelib/api/CodeNick.java b/src/main/java/de/codeblocksmc/codelib/api/CodeNick.java new file mode 100644 index 0000000..561676c --- /dev/null +++ b/src/main/java/de/codeblocksmc/codelib/api/CodeNick.java @@ -0,0 +1,20 @@ +package de.codeblocksmc.codelib.api; + +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +import java.util.WeakHashMap; + +public class CodeNick { + private static final WeakHashMap instances = new WeakHashMap<>(); + + public synchronized static CodeNick of(Plugin plugin) { + CodeNick c = new CodeNick(); + instances.put(plugin, c); + return c; + } + + public void nickPlayer(Player player) { + + } +} From 2e120b6f1351d1ad575206c3600af437176a0a6a Mon Sep 17 00:00:00 2001 From: Julian Weinelt Date: Tue, 27 May 2025 15:42:40 +0200 Subject: [PATCH 05/12] Overview of server implementations --- .../codeblocksmc/codelib/feature/ServerSoftware.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/main/java/de/codeblocksmc/codelib/feature/ServerSoftware.java diff --git a/src/main/java/de/codeblocksmc/codelib/feature/ServerSoftware.java b/src/main/java/de/codeblocksmc/codelib/feature/ServerSoftware.java new file mode 100644 index 0000000..25f1efd --- /dev/null +++ b/src/main/java/de/codeblocksmc/codelib/feature/ServerSoftware.java @@ -0,0 +1,12 @@ +package de.codeblocksmc.codelib.feature; + +public enum ServerSoftware { + BUNGEECORD, + WATERFALL, + VELOCITY, + SPIGOTMC, + CRAFT_BUKKIT, + PAPER, + PURPUR, + FOLIA +} \ No newline at end of file From fe08807ab4931ddadf9417854ec5b0b4c0fb35a7 Mon Sep 17 00:00:00 2001 From: Julian Weinelt Date: Tue, 27 May 2025 15:42:51 +0200 Subject: [PATCH 06/12] Basic command for library --- .../codelib/commands/CodeLibCommand.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/main/java/de/codeblocksmc/codelib/commands/CodeLibCommand.java diff --git a/src/main/java/de/codeblocksmc/codelib/commands/CodeLibCommand.java b/src/main/java/de/codeblocksmc/codelib/commands/CodeLibCommand.java new file mode 100644 index 0000000..45ab89d --- /dev/null +++ b/src/main/java/de/codeblocksmc/codelib/commands/CodeLibCommand.java @@ -0,0 +1,39 @@ +package de.codeblocksmc.codelib.commands; + +import de.codeblocksmc.codelib.api.chat.AdvancedTabCompleter; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; + +public class CodeLibCommand implements CommandExecutor { + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, + @NotNull String[] args) { + if (args.length == 1) { + + } else if (args.length == 2) { + + } else if (args.length == 3) { + + } + return false; + } + + + public static class Completer extends AdvancedTabCompleter implements TabCompleter { + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command cmd, + @NotNull String label, @NotNull String[] args) { + List completions = new ArrayList<>(); + + return completions; + } + } +} From 2b4eb72a457e897927196f2b96d6e9da7dafd66f Mon Sep 17 00:00:00 2001 From: Julian Weinelt Date: Tue, 27 May 2025 15:43:18 +0200 Subject: [PATCH 07/12] hooking for Caesar --- .../codelib/caesar/CodeLibCaesarHook.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/main/java/de/codeblocksmc/codelib/caesar/CodeLibCaesarHook.java diff --git a/src/main/java/de/codeblocksmc/codelib/caesar/CodeLibCaesarHook.java b/src/main/java/de/codeblocksmc/codelib/caesar/CodeLibCaesarHook.java new file mode 100644 index 0000000..0a8ac80 --- /dev/null +++ b/src/main/java/de/codeblocksmc/codelib/caesar/CodeLibCaesarHook.java @@ -0,0 +1,30 @@ +package de.codeblocksmc.codelib.caesar; + +import de.julianweinelt.caesar.plugin.CPlugin; + +public class CodeLibCaesarHook extends CPlugin { + @Override + public void onLoad() { + + } + + @Override + public void onEnable() { + + } + + @Override + public void onDisable() { + + } + + @Override + public void onDefineEvents() { + + } + + @Override + public void onCreateCommands() { + + } +} From 29867f307ff8558d90ac951d4d211058a619a2d4 Mon Sep 17 00:00:00 2001 From: Julian Weinelt Date: Tue, 27 May 2025 15:44:09 +0200 Subject: [PATCH 08/12] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8af63b9..4e03ca7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ⚙️CodeLib: super advanced Bukkit and Velocity API -![Version](https://img.shields.io/badge/Version-v3.3.1-green)![Update](https://img.shields.io/badge/Status-Stable-blue)[![Contribute](https://img.shields.io/badge/Contributions-Welcome-brightgreen)](CONTRIBUTING.md)[![Build](https://github.com/JWeinelt/codelib/actions/workflows/maven.yml/badge.svg)](https://github.com/JWeinelt/codelib/actions/workflows/maven.yml) +![Version](https://img.shields.io/badge/Version-v4.0.0--alpha1-green)![Update](https://img.shields.io/badge/Status-Stable-blue)[![Contribute](https://img.shields.io/badge/Contributions-Welcome-brightgreen)](CONTRIBUTING.md)[![Build](https://github.com/JWeinelt/codelib/actions/workflows/maven.yml/badge.svg)](https://github.com/JWeinelt/codelib/actions/workflows/maven.yml) Welcome to the official repository of **CodeLib!** From 31aa12efc43dfaf1696ca701d28453b1d1994c62 Mon Sep 17 00:00:00 2001 From: Julian Weinelt Date: Tue, 27 May 2025 15:57:13 +0200 Subject: [PATCH 09/12] Nick system --- .../de/codeblocksmc/codelib/api/CodeNick.java | 53 +++++++++++++++++-- .../codelib/api/spigot/CodeNick.java | 4 ++ 2 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 src/main/java/de/codeblocksmc/codelib/api/spigot/CodeNick.java diff --git a/src/main/java/de/codeblocksmc/codelib/api/CodeNick.java b/src/main/java/de/codeblocksmc/codelib/api/CodeNick.java index 561676c..026d28a 100644 --- a/src/main/java/de/codeblocksmc/codelib/api/CodeNick.java +++ b/src/main/java/de/codeblocksmc/codelib/api/CodeNick.java @@ -1,20 +1,67 @@ package de.codeblocksmc.codelib.api; +import com.destroystokyo.paper.profile.PlayerProfile; +import com.destroystokyo.paper.profile.ProfileProperty; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import net.kyori.adventure.text.Component; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; import java.util.WeakHashMap; public class CodeNick { private static final WeakHashMap instances = new WeakHashMap<>(); - public synchronized static CodeNick of(Plugin plugin) { + private SaveMethod saveMethod; + + public synchronized static CodeNick of(Plugin plugin, SaveMethod method) { CodeNick c = new CodeNick(); instances.put(plugin, c); + c.saving(method); return c; } - public void nickPlayer(Player player) { + public CodeNick saving(SaveMethod method) { + saveMethod = method; + return this; + } + + public boolean nickPlayer(Player player, String targetName) { + player.displayName(Component.text(targetName)); + + PlayerProfile playerProfile = player.getPlayerProfile(); + try { + URL url_0 = new URL("https://api.mojang.com/users/profiles/minecraft/" + targetName); + + InputStreamReader reader_0 = new InputStreamReader(url_0.openStream()); + + String uuid = JsonParser.parseReader(reader_0).getAsJsonObject().get("id").getAsString(); + + URL url_1 = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false"); + + InputStreamReader reader_1 = new InputStreamReader(url_1.openStream()); + + JsonObject properties = JsonParser.parseReader(reader_1).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject(); + + String value = properties.get("value").getAsString(); + String signature = properties.get("signature").getAsString(); + + playerProfile.setProperty(new ProfileProperty("textures", value, signature)); + player.setPlayerProfile(playerProfile); + + return true; + } catch (IllegalStateException | IOException | NullPointerException ignored) { + return false; + } + } + public enum SaveMethod { + INTERNAL, + MYSQL, + SQLITE } -} +} \ No newline at end of file diff --git a/src/main/java/de/codeblocksmc/codelib/api/spigot/CodeNick.java b/src/main/java/de/codeblocksmc/codelib/api/spigot/CodeNick.java new file mode 100644 index 0000000..f56888c --- /dev/null +++ b/src/main/java/de/codeblocksmc/codelib/api/spigot/CodeNick.java @@ -0,0 +1,4 @@ +package de.codeblocksmc.codelib.api.spigot; + +public class CodeNick { +} From d59355f686e53a6d50528557fe6cec4bc1ef608b Mon Sep 17 00:00:00 2001 From: Julian Weinelt Date: Tue, 27 May 2025 16:00:44 +0200 Subject: [PATCH 10/12] fix(api) --- .../java/de/codeblocksmc/codelib/api/util/ServerConnector.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/de/codeblocksmc/codelib/api/util/ServerConnector.java b/src/main/java/de/codeblocksmc/codelib/api/util/ServerConnector.java index c52d223..e7d58c3 100644 --- a/src/main/java/de/codeblocksmc/codelib/api/util/ServerConnector.java +++ b/src/main/java/de/codeblocksmc/codelib/api/util/ServerConnector.java @@ -2,7 +2,6 @@ import de.simonsator.partyandfriends.spigot.api.pafplayers.PAFPlayerManager; import de.simonsator.partyandfriends.spigot.api.party.PartyManager; -import io.github.leonardosnt.bungeechannelapi.BungeeChannelApi; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; @@ -12,7 +11,7 @@ /** * This class handles the connection of players to available servers, taking into account party-related restrictions. * It ensures that players cannot join a game while being in a party, unless they are the party leader. - * The class communicates with BungeeCord via the {@link BungeeChannelApi} to search for available servers and connect players. + * The class communicates with BungeeCord via the {@link de.codeblocksmc.codelib.api.util.BungeeChannelApi} to search for available servers and connect players. *

* It also integrates with the PartyAndFriends plugin to check if the player is in a party and if they are the leader. * If the player is in a party but not the leader, they will not be able to join the server. From 7e63da66250b87f9c686f6c41e864dab163cc7a4 Mon Sep 17 00:00:00 2001 From: Julian Weinelt Date: Tue, 27 May 2025 16:12:25 +0200 Subject: [PATCH 11/12] feat(Basic database API) --- .idea/jarRepositories.xml | 5 ++++ .../codelib/api/databsae/DBLib.java | 26 +++++++++++++++++++ .../codelib/api/databsae/DBLibConfig.java | 14 ++++++++++ .../codelib/api/databsae/DBSchema.java | 4 +++ .../codelib/api/databsae/DBTable.java | 4 +++ .../codelib/api/databsae/StorageProvider.java | 11 ++++++++ .../codelib/api/databsae/TableColumn.java | 4 +++ .../{ => template}/MSSQLTemplate.java | 3 ++- .../{ => template}/MySQLTemplate.java | 4 ++- .../{ => template}/MySQLTemplateVelocity.java | 3 ++- .../codeblocksmc/codelib/api/game/Game.java | 4 +++ 11 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 src/main/java/de/codeblocksmc/codelib/api/databsae/DBLib.java create mode 100644 src/main/java/de/codeblocksmc/codelib/api/databsae/DBLibConfig.java create mode 100644 src/main/java/de/codeblocksmc/codelib/api/databsae/DBSchema.java create mode 100644 src/main/java/de/codeblocksmc/codelib/api/databsae/DBTable.java create mode 100644 src/main/java/de/codeblocksmc/codelib/api/databsae/StorageProvider.java create mode 100644 src/main/java/de/codeblocksmc/codelib/api/databsae/TableColumn.java rename src/main/java/de/codeblocksmc/codelib/api/databsae/{ => template}/MSSQLTemplate.java (94%) rename src/main/java/de/codeblocksmc/codelib/api/databsae/{ => template}/MySQLTemplate.java (96%) rename src/main/java/de/codeblocksmc/codelib/api/databsae/{ => template}/MySQLTemplateVelocity.java (94%) create mode 100644 src/main/java/de/codeblocksmc/codelib/api/game/Game.java diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml index b801f6a..0b795b2 100644 --- a/.idea/jarRepositories.xml +++ b/.idea/jarRepositories.xml @@ -6,6 +6,11 @@