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();
+ }
}