diff --git a/README.md b/README.md index 8af63b9..913dc72 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ Welcome to the official repository of **CodeLib!** After years of private development for the CodeBlocksMC network, CodeLib is now available to everyone! Feel free to open issues, contribute, and build something great together! +Join the official Discord server [here](https://dc.codeblocksmc.de)! + ## 🌟 Features - 🎨 Advanced GUI Builder diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml index 4145bc3..66b5ea0 100644 --- a/dependency-reduced-pom.xml +++ b/dependency-reduced-pom.xml @@ -4,7 +4,7 @@ de.codeblocksmc.codelib CodeLib CodeLib - 3.3.1 + 3.3.9 @@ -15,7 +15,7 @@ maven-compiler-plugin - 3.8.1 + 3.14.0 16 16 @@ -23,7 +23,7 @@ maven-shade-plugin - 3.2.4 + 3.6.0 package @@ -59,19 +59,19 @@ org.projectlombok lombok - 1.18.30 + 1.18.38 provided de.simonsator spigot-party-api-for-party-and-friends - 1.0.4-RELEASE + 1.0.7-RELEASE provided de.simonsator Party-and-Friends-MySQL-Edition-Spigot-API - 1.5.4-RELEASE + 1.6.2-RELEASE provided diff --git a/pom.xml b/pom.xml index 308409c..0841098 100644 --- a/pom.xml +++ b/pom.xml @@ -6,8 +6,8 @@ de.codeblocksmc.codelib CodeLib - 3.3.1 - + 3.4.0 + jar CodeLib @@ -87,7 +87,7 @@ fr.mrmicky fastboard - 2.1.4 + 2.1.5 org.projectlombok 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/databsae/MySQLTemplate.java b/src/main/java/de/codeblocksmc/codelib/databsae/MySQLTemplate.java index 30e743f..6e0aea1 100644 --- a/src/main/java/de/codeblocksmc/codelib/databsae/MySQLTemplate.java +++ b/src/main/java/de/codeblocksmc/codelib/databsae/MySQLTemplate.java @@ -14,7 +14,7 @@ * @author JustCody * @version 1.0 */ -public class MySQLTemplate extends DatabaseObject { +public abstract class MySQLTemplate extends DatabaseObject { // The connection object to the MySQL database public Connection conn; @@ -84,4 +84,14 @@ public void checkConnection() { log.warning("MySQL connection check failed: " + e.getMessage()); } } + + public void disconnect() { + try { + conn.close(); + } catch (SQLException e) { + log.severe(e.getMessage()); + } + } + + public abstract void afterSuccessfulConnection(); } diff --git a/src/main/java/de/codeblocksmc/codelib/locations/LocUtil.java b/src/main/java/de/codeblocksmc/codelib/locations/LocUtil.java index ac11eb5..7fed960 100644 --- a/src/main/java/de/codeblocksmc/codelib/locations/LocUtil.java +++ b/src/main/java/de/codeblocksmc/codelib/locations/LocUtil.java @@ -2,9 +2,13 @@ import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.Material; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; +import java.util.List; + /** * Utility class for converting {@link LocationWrapper} and {@link Location} or wrapping {@link LocationSection} */ @@ -54,6 +58,15 @@ public static LocationWrapper fromBukkit(Location l) { return new LocationWrapper(l.getWorld().getName(), l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch()); } + @NotNull + public static Location fromWrapperReduced(@NotNull LocationWrapperReduced reduced, String world) { + return new Location( + Bukkit.getWorld(world), + reduced.getX(), reduced.getY(), reduced.getZ(), + reduced.getYaw(), reduced.getPitch() + ); + } + /** @@ -147,4 +160,32 @@ public static boolean isNear(Location targetLoc, Location middleLoc, int radius) return distanceSquared <= (radius * radius); } + + public static LocationWrapper getMiddle(LocationSection section) { + String world = section.getL1().getWorld(); // Assuming both locations are in the same world + double middleX = (section.getL1().getX() + section.getL2().getX()) / 2; + double middleY = (section.getL1().getY() + section.getL2().getY()) / 2; + double middleZ = (section.getL1().getZ() + section.getL2().getZ()) / 2; + float middleYaw = (section.getL1().getYaw() + section.getL2().getYaw()) / 2; + float middlePitch = (section.getL1().getPitch() + section.getL2().getPitch()) / 2; + + return new LocationWrapper(world, middleX, middleY, middleZ, middleYaw, middlePitch); + } + + public static List getBlocksAround(Location location) { + List blocks = new ArrayList<>(); + Location l = new Location(location.getWorld(), location.getX(), location.getY(), location.getZ()); + + blocks.add(location.clone().add(0, 0, 1).getBlock().getType()); + location = l; + blocks.add(location.clone().add(1, 0, 1).getBlock().getType()); + blocks.add(location.clone().add(-1, 0, 1).getBlock().getType()); + blocks.add(location.clone().add(0, 0, -1).getBlock().getType()); + blocks.add(location.clone().add(1, 0, -1).getBlock().getType()); + blocks.add(location.clone().add(-1, 0, -1).getBlock().getType()); + blocks.add(location.clone().add(1, 0, 0).getBlock().getType()); + blocks.add(location.clone().add(-1, 0, 0).getBlock().getType()); + + return blocks; + } } \ No newline at end of file diff --git a/src/main/java/de/codeblocksmc/codelib/locations/LocationWrapperReduced.java b/src/main/java/de/codeblocksmc/codelib/locations/LocationWrapperReduced.java new file mode 100644 index 0000000..25a49a2 --- /dev/null +++ b/src/main/java/de/codeblocksmc/codelib/locations/LocationWrapperReduced.java @@ -0,0 +1,127 @@ +package de.codeblocksmc.codelib.locations; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +/** + * A wrapper class for representing and saving positions in JSON files. + * + *

This class is designed to store positional data in a safe and + * serialization-friendly format. It is often used in scenarios where + * a {@link org.bukkit.Location} cannot be directly serialized, such as + * saving data to configuration files or databases.

+ * + *

The class provides getters and setters for all fields except worlds and supports + * JSON serialization through libraries like GSON.

+ * + *

The {@link LocationWrapperReduced} does not provide a {@link org.bukkit.World} field. It is indented for implementations + * of games that are not world-dependent, e.g., dynamic map loading.

+ * + * Use {@link LocationWrapperReduced#toWrapper(String)} to convert it to a full {@link LocationWrapper}. + */ +@Getter +@Setter +@NoArgsConstructor +public class LocationWrapperReduced { + + /** + * The X-coordinate of the location. + */ + private double x; + + /** + * The Y-coordinate of the location. + */ + private double y; + + /** + * The Z-coordinate of the location. + */ + private double z; + + /** + * The yaw (rotation on the Y-axis) of the location. + */ + private float yaw; + + /** + * The pitch (rotation on the X-axis) of the location. + */ + private float pitch; + + /** + * Constructs a {@link LocationWrapperReduced} with the specified values. + * + * @param x the X-coordinate of the location. + * @param y the Y-coordinate of the location. + * @param z the Z-coordinate of the location. + * @param yaw the yaw (rotation on the Y-axis) of the location. + * @param pitch the pitch (rotation on the X-axis) of the location. + */ + public LocationWrapperReduced(double x, double y, double z, float yaw, float pitch) { + this.x = x; + this.y = y; + this.z = z; + this.yaw = yaw; + this.pitch = pitch; + } + + + /** + * Creates a regular {@link LocationWrapper} object with a world. + * @param world World the location will have + * @return {@link LocationWrapper} representing this class with a world. + */ + public LocationWrapper toWrapper(String world) { + return new LocationWrapper(world, x, y, z, yaw, pitch); + } + + /** + * Provides a string representation of the {@link LocationWrapperReduced}. + * + * @return a formatted string containing the world name, coordinates, yaw, and pitch. + */ + @Override + public String toString() { + return String.format("LocationWrapper[world=%s, x=%.2f, y=%.2f, z=%.2f, yaw=%.2f, pitch=%.2f]", + "unknown", x, y, z, yaw, pitch); + } + + /** + * Checks if this {@link LocationWrapperReduced} is equal to another object. + * + *

Two {@link LocationWrapperReduced} instances are considered equal if all their fields match.

+ * + * @param obj the object to compare with this instance. + * @return {@code true} if the objects are equal; {@code false} otherwise. + */ + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + + LocationWrapperReduced other = (LocationWrapperReduced) obj; + return Double.compare(other.x, x) == 0 && + Double.compare(other.y, y) == 0 && + Double.compare(other.z, z) == 0 && + Float.compare(other.yaw, yaw) == 0 && + Float.compare(other.pitch, pitch) == 0; + } + + /** + * Generates a hash code for the {@link LocationWrapperReduced}. + * + * @return a hash code based on the fields of the object. + */ + @Override + public int hashCode() { + int result = 0; + result = 31 * result + Double.hashCode(x); + result = 31 * result + Double.hashCode(y); + result = 31 * result + Double.hashCode(z); + result = 31 * result + Float.floatToIntBits(yaw); + result = 31 * result + Float.floatToIntBits(pitch); + return result; + } +} diff --git a/src/main/java/de/codeblocksmc/codelib/util/ClientVersionTracker.java b/src/main/java/de/codeblocksmc/codelib/util/ClientVersionTracker.java new file mode 100644 index 0000000..4176c7e --- /dev/null +++ b/src/main/java/de/codeblocksmc/codelib/util/ClientVersionTracker.java @@ -0,0 +1,66 @@ +package de.codeblocksmc.codelib.util; + +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; + +public class ClientVersionTracker { + + private static final Map protocolVersions = new ConcurrentHashMap<>(); + + public static void setProtocolVersion(UUID uuid, int version) { + protocolVersions.put(uuid, version); + } + + public static int getProtocolVersion(UUID uuid) { + return protocolVersions.getOrDefault(uuid, -1); // -1 = unbekannt + } + + public static String getFriendlyName(int version) { + return switch (version) { + case 47 -> "1.8.9"; + case 107 -> "1.9"; + case 108 -> "1.9.1"; + case 109 -> "1.9.2"; + case 110 -> "1.9.4"; + case 210 -> "1.10.2"; + case 315 -> "1.11"; + case 316 -> "1.11.2"; + case 335 -> "1.12"; + case 338 -> "1.12.1"; + case 340 -> "1.12.2"; + case 393 -> "1.13"; + case 401 -> "1.13.1"; + case 404 -> "1.13.2"; + case 477 -> "1.14"; + case 480 -> "1.14.1"; + case 485 -> "1.14.2"; + case 490 -> "1.14.3"; + case 498 -> "1.14.4"; + case 573 -> "1.15"; + case 575 -> "1.15.1"; + case 578 -> "1.15.2"; + case 735 -> "1.16"; + case 736 -> "1.16.1"; + case 751 -> "1.16.2"; + case 753 -> "1.16.3"; + case 754 -> "1.16.5"; // auch 1.16.4 + case 755 -> "1.17"; + case 756 -> "1.17.1"; + case 757 -> "1.18"; + case 758 -> "1.18.2"; // auch 1.18.1 + case 759 -> "1.19"; + case 760 -> "1.19.1 / 1.19.2"; + case 761 -> "1.19.3"; + case 762 -> "1.19.4"; + case 763 -> "1.20"; + case 764 -> "1.20.1"; + case 765 -> "1.20.2"; + case 766 -> "1.20.3"; + case 767 -> "1.20.4"; + case 768 -> "1.20.5 / 1.20.6"; // (meist gleiches Protokoll) + default -> "1.20.4"; + }; + + } +} diff --git a/src/main/java/de/codeblocksmc/codelib/util/DataUtil.java b/src/main/java/de/codeblocksmc/codelib/util/DataUtil.java new file mode 100644 index 0000000..e900510 --- /dev/null +++ b/src/main/java/de/codeblocksmc/codelib/util/DataUtil.java @@ -0,0 +1,64 @@ +package de.codeblocksmc.codelib.util; + +import java.io.InputStream; +import java.net.URL; +import java.security.DigestInputStream; +import java.security.MessageDigest; +import java.util.ArrayList; +import java.util.List; + +public class DataUtil { + public static boolean isValidInt(String s) { + try { + int i = Integer.parseInt(s); + return true; + } catch (NumberFormatException ignored) {return false;} + } + + public static boolean isValidIntList(String a) { + List is = new ArrayList<>(); + for (String s : a.split(",")) { + if (!isValidInt(s)) return false; + } + return true; + } + + public static List convertDest(String argument) { + List is = new ArrayList<>(); + for (String s : argument.split(",")) { + if (isValidInt(s)) is.add(Integer.parseInt(s)); + } + return is; + } + + public static String checkHashURL(String input) { + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + InputStream is = new URL(input).openStream(); + + try { + is = new DigestInputStream(is, md); + + int b; + + while ((b = is.read()) > 0) { + ; + } + } finally { + is.close(); + } + byte[] digest = md.digest(); + StringBuilder sb = new StringBuilder(); + + for (byte b : digest) { + sb.append( + Integer.toString((b & 0xff) + 0x100, 16).substring( + 1)); + } + return sb.toString(); + + } catch (Exception ex) { + throw new RuntimeException(ex); + } + } +} diff --git a/src/main/java/de/codeblocksmc/codelib/worldman/WorldManCmd.java b/src/main/java/de/codeblocksmc/codelib/worldman/WorldManCmd.java index c795f48..c0d0e98 100644 --- a/src/main/java/de/codeblocksmc/codelib/worldman/WorldManCmd.java +++ b/src/main/java/de/codeblocksmc/codelib/worldman/WorldManCmd.java @@ -47,11 +47,16 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command sender.sendMessage("§cInvalid arguments provided."); } } else if (args.length == 2) { - if (Bukkit.getWorld(args[1]) == null) { + if (args[0].equalsIgnoreCase("create")) { + sender.sendMessage("§bCreating world §e" + args[1] + "..."); + manager.loadWorld(args[1]); + sender.sendMessage("§aDone!"); + } + if (Bukkit.getWorld(args[1]) == null && !args[1].equalsIgnoreCase("create")) { sender.sendMessage("§cThe world §e" + args[1] + "§c seems not to exist. Is there a typo?"); return false; } - if (args[0].equalsIgnoreCase("create")) { + if (args[0].equalsIgnoreCase("load")) { sender.sendMessage("§bLoading world §e" + args[1] + "..."); manager.loadWorld(args[1]); sender.sendMessage("§aDone!"); diff --git a/src/main/java/de/codeblocksmc/codelib/worldman/WorldManCom.java b/src/main/java/de/codeblocksmc/codelib/worldman/WorldManCom.java index 29b4b13..d7f14b1 100644 --- a/src/main/java/de/codeblocksmc/codelib/worldman/WorldManCom.java +++ b/src/main/java/de/codeblocksmc/codelib/worldman/WorldManCom.java @@ -1,6 +1,6 @@ package de.codeblocksmc.codelib.worldman; -import de.codeblocksmc.codelib.AdvancedTabCompleter; +import de.codeblocksmc.codelib.chat.AdvancedTabCompleter; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; @@ -24,7 +24,7 @@ public WorldManCom(WorldManager manager) { List completions = new ArrayList<>(); if (args.length <= 1) { - complete(completions, args[0], "teleport", "create", "remove", "list", "delete"); + complete(completions, args[0], "teleport", "create", "remove", "list", "delete", "load"); } else if (args.length == 2) { if (args[0].equalsIgnoreCase("remove") || args[0].equalsIgnoreCase("teleport")) complete(completions, args[1], manager.getLoadedWorlds()); diff --git a/src/main/java/de/codeblocksmc/codelib/wrapping/ItemBuilder.java b/src/main/java/de/codeblocksmc/codelib/wrapping/ItemBuilder.java index 9ced3f4..dcdc604 100644 --- a/src/main/java/de/codeblocksmc/codelib/wrapping/ItemBuilder.java +++ b/src/main/java/de/codeblocksmc/codelib/wrapping/ItemBuilder.java @@ -28,7 +28,7 @@ */ public class ItemBuilder { - private final ItemStack stack; + private ItemStack stack; private ItemMeta meta; /** @@ -59,6 +59,12 @@ public ItemBuilder displayname(String name) { return this; } + public ItemBuilder material(Material material) { + if (material == Material.AIR) throw new IllegalArgumentException("Material cannot be null or AIR."); + stack = stack.withType(material); + return this; + } + /** * Sets the item to be unbreakable. * @@ -302,4 +308,12 @@ public ItemStack build() { stack.setItemMeta(meta); return stack; } + + public Material getMaterial() { + return stack.getType(); + } + + public int getAmount() { + return stack.getAmount(); + } }