diff --git a/pom.xml b/pom.xml
index 0c40a2f..23d5c91 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,12 +6,12 @@
de.nehlen
gameapi
- 1.1-BUILD
+ 1.2
jar
Gameapi
- Game api for minigames
+ GameAPI for minigames
1.8
UTF-8
@@ -55,21 +55,13 @@
- spigotmc-repo
- https://hub.spigotmc.org/nexus/content/repositories/snapshots/
+ papermc-repo
+ https://repo.papermc.io/repository/maven-public/
sonatype
https://oss.sonatype.org/content/groups/public/
-
- cloudnet-releases
- https://repo.cloudnetservice.eu/repository/releases/
-
-
- exceptionflug
- http://mvn.exceptionflug.de/repository/exceptionflug-public/
-
hikari
https://mvnrepository.com/artifact/com.zaxxer/HikariCP/
@@ -77,12 +69,6 @@
-
- org.spigotmc
- spigot-api
- 1.14.4-R0.1-SNAPSHOT
- provided
-
org.projectlombok
lombok
@@ -92,61 +78,15 @@
com.zaxxer
HikariCP
- 5.0.0
+ 5.0.1
compile
-
-
-
- de.exceptionflug
- mccommons-config-spigot
- 2.0-SNAPSHOT
- provided
-
-
- de.exceptionflug
- mccommons-inventories-spigot
- 2.0-SNAPSHOT
- provided
-
-
- de.exceptionflug
- mccommons-holograms
- 2.0-SNAPSHOT
- provided
-
-
-
-
- de.dytanic.cloudnet
- cloudnet-wrapper-jvm
- 3.4.0-RELEASE
- provided
-
- de.dytanic.cloudnet
- cloudnet-bridge
- 3.4.0-RELEASE
+ io.papermc.paper
+ paper-api
+ 1.19.3-R0.1-SNAPSHOT
provided
-
- de.dytanic.cloudnet
- cloudnet-driver
- 3.4.0-RELEASE
- provided
-
-
- de.dytanic.cloudnet
- cloudnet-cloudperms
- 3.4.0-RELEASE
- provided
-
-
-
- org.spigotmc
- spigot
- 1.14.4-R0.1-SNAPSHOT
-
diff --git a/src/main/java/de/nehlen/gameapi/Gameapi.java b/src/main/java/de/nehlen/gameapi/Gameapi.java
index 27a3b69..a8f8e63 100644
--- a/src/main/java/de/nehlen/gameapi/Gameapi.java
+++ b/src/main/java/de/nehlen/gameapi/Gameapi.java
@@ -1,7 +1,7 @@
package de.nehlen.gameapi;
-import de.exceptionflug.mccommons.config.shared.ConfigFactory;
-import de.exceptionflug.mccommons.config.spigot.SpigotConfig;
+import de.nehlen.gameapi.YamlConfiguration.SpigotConfigurationWrapper;
+import de.nehlen.gameapi.YamlConfiguration.YamlConfig;
import de.nehlen.gameapi.PointsAPI.PointsAPI;
import de.nehlen.gameapi.TeamAPI.TeamAPI;
import de.nehlen.gameapi.listener.PlayerJoinListener;
@@ -18,10 +18,7 @@ public final class Gameapi extends JavaPlugin {
@Getter private static Gameapi gameapi;
@Getter private ServerID serverID;
-
- //CONFIGS
- @Getter private SpigotConfig generalConfig;
- @Getter private SpigotConfig databaseConfig;
+ @Getter private SpigotConfigurationWrapper databaseConfig;
//LISTENER
@Getter private PlayerJoinListener playerJoinListener;
@@ -36,8 +33,8 @@ public void onEnable() {
gameapi = this;
serverID = new ServerID(ServerID.generateRandomServerID());
- this.generalConfig = ConfigFactory.create(new File(getDataFolder(), "general_config.yml"), SpigotConfig.class);
- this.databaseConfig = ConfigFactory.create(new File(getDataFolder(), "database_config.yml"), SpigotConfig.class);
+ this.databaseConfig = new YamlConfig();
+ this.databaseConfig.load(new File(getDataFolder(), "database_config.yml"));
this.teamAPI = new TeamAPI(this);
this.databaseLib = new DatabaseLib(this);
diff --git a/src/main/java/de/nehlen/gameapi/ItemsAPI/Items.java b/src/main/java/de/nehlen/gameapi/ItemsAPI/Items.java
index 3a7fe5f..4e83942 100644
--- a/src/main/java/de/nehlen/gameapi/ItemsAPI/Items.java
+++ b/src/main/java/de/nehlen/gameapi/ItemsAPI/Items.java
@@ -1,6 +1,5 @@
package de.nehlen.gameapi.ItemsAPI;
-import de.nehlen.gameapi.util.UUIDFetcher;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Material;
@@ -140,20 +139,6 @@ public static ItemStack createEnchantment(Material material, String displayname,
}
- /**
- * @param Display
- * @param Owner
- * @return
- */
- public static ItemStack createSkull(String Display, String Owner) {
- ItemStack item = new ItemStack(Material.PLAYER_HEAD, 1);
- SkullMeta itemMeta = (SkullMeta) Bukkit.getItemFactory().getItemMeta(Material.PLAYER_HEAD);
-
- itemMeta.setOwningPlayer(Bukkit.getOfflinePlayer(UUIDFetcher.getUUID(Owner)));
- itemMeta.setDisplayName(Display);
- item.setItemMeta(itemMeta);
- return item;
- }
/**
* @param Display
diff --git a/src/main/java/de/nehlen/gameapi/PhaseApi/AbstractGamePhase.java b/src/main/java/de/nehlen/gameapi/PhaseApi/AbstractGamePhase.java
new file mode 100644
index 0000000..1c2a18e
--- /dev/null
+++ b/src/main/java/de/nehlen/gameapi/PhaseApi/AbstractGamePhase.java
@@ -0,0 +1,24 @@
+package de.nehlen.gameapi.PhaseApi;
+
+import de.nehlen.gameapi.Gameapi;
+import lombok.Getter;
+import lombok.Setter;
+import org.bukkit.Bukkit;
+
+public abstract class AbstractGamePhase implements GamePhase {
+
+ @Getter @Setter
+ protected int counter = 0;
+ protected int scheduler = 0;
+
+ public AbstractGamePhase(int counter) {
+ this.counter = counter;
+ }
+
+ public void startPhase() {
+ scheduler = Bukkit.getScheduler().scheduleSyncRepeatingTask(Gameapi.getGameapi(), () -> {}, 20L, 20L);
+ };
+ public void endPhase(){
+ Bukkit.getScheduler().cancelTask(scheduler);
+ };
+}
diff --git a/src/main/java/de/nehlen/gameapi/PhaseApi/GamePhase.java b/src/main/java/de/nehlen/gameapi/PhaseApi/GamePhase.java
index 2fc54f3..5f88e01 100644
--- a/src/main/java/de/nehlen/gameapi/PhaseApi/GamePhase.java
+++ b/src/main/java/de/nehlen/gameapi/PhaseApi/GamePhase.java
@@ -1,28 +1,17 @@
package de.nehlen.gameapi.PhaseApi;
-import de.nehlen.gameapi.Gameapi;
import lombok.Getter;
import lombok.Setter;
-import org.bukkit.Bukkit;
-public class GamePhase {
- @Getter @Setter
- public int counter = 0;
- public int scheduler = 0;
+public interface GamePhase {
+ int counter = 0;
+ int scheduler = 0;
- public GamePhase(int counter) {
- this.counter=counter;
- }
+ void setCounter(int counter);
- public void startPhase() {
- scheduler = Bukkit.getScheduler().scheduleSyncRepeatingTask(Gameapi.getGameapi(), new Runnable() {
- @Override
- public void run() {
- //PUT CONTENT HERE
- }
- }, 20L, 20L);
- };
- public void endPhase(){
- Bukkit.getScheduler().cancelTask(scheduler);
- };
+ int getCounter();
+
+ void startPhase();
+
+ void endPhase();
}
diff --git a/src/main/java/de/nehlen/gameapi/PhaseApi/GamePhaseManager.java b/src/main/java/de/nehlen/gameapi/PhaseApi/GamePhaseManager.java
new file mode 100644
index 0000000..d64d405
--- /dev/null
+++ b/src/main/java/de/nehlen/gameapi/PhaseApi/GamePhaseManager.java
@@ -0,0 +1,47 @@
+package de.nehlen.gameapi.PhaseApi;
+
+import de.nehlen.gameapi.PhaseApi.exceptions.GamePhaseLastException;
+import de.nehlen.gameapi.PhaseApi.exceptions.GamePhaseNotRegisteredException;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class GamePhaseManager {
+
+ private Map gamePhases = new HashMap<>();
+
+ public void registerPhase(String name, GamePhase gamePhase) {
+ gamePhases.put(name, gamePhase);
+ }
+
+ public void startPhase(String name, int count) {
+ GamePhase gamePhase = gamePhases.get(name);
+ if (gamePhase != null) {
+ gamePhase.setCounter(count);
+ gamePhase.startPhase();
+ } else {
+ throw new GamePhaseNotRegisteredException("Game Phase with name " + name + " is not registered.");
+ }
+ }
+
+ public void endPhase(String name) {
+ GamePhase gamePhase = gamePhases.get(name);
+ if (gamePhase != null) {
+ gamePhase.endPhase();
+ } else {
+ throw new GamePhaseNotRegisteredException("Game Phase with name " + name + " is not registered.");
+ }
+ }
+
+ public void continueToNextPhase() {
+ if(gamePhases.size() <= 1) {
+ throw new GamePhaseLastException("No Game Phase to continue to.");
+ }
+ Map.Entry currentGamePhase = gamePhases.entrySet().iterator().next();
+ currentGamePhase.getValue().endPhase();
+ gamePhases.remove(currentGamePhase.getKey());
+
+ Map.Entry newCurrentPhase = gamePhases.entrySet().iterator().next();
+ newCurrentPhase.getValue().startPhase();
+ }
+}
diff --git a/src/main/java/de/nehlen/gameapi/PhaseApi/exceptions/GamePhaseLastException.java b/src/main/java/de/nehlen/gameapi/PhaseApi/exceptions/GamePhaseLastException.java
new file mode 100644
index 0000000..ee05ac5
--- /dev/null
+++ b/src/main/java/de/nehlen/gameapi/PhaseApi/exceptions/GamePhaseLastException.java
@@ -0,0 +1,8 @@
+package de.nehlen.gameapi.PhaseApi.exceptions;
+
+public class GamePhaseLastException extends RuntimeException {
+
+ public GamePhaseLastException(String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/de/nehlen/gameapi/PhaseApi/exceptions/GamePhaseNotRegisteredException.java b/src/main/java/de/nehlen/gameapi/PhaseApi/exceptions/GamePhaseNotRegisteredException.java
new file mode 100644
index 0000000..fc5f209
--- /dev/null
+++ b/src/main/java/de/nehlen/gameapi/PhaseApi/exceptions/GamePhaseNotRegisteredException.java
@@ -0,0 +1,7 @@
+package de.nehlen.gameapi.PhaseApi.exceptions;
+
+public class GamePhaseNotRegisteredException extends RuntimeException {
+ public GamePhaseNotRegisteredException(String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/de/nehlen/gameapi/TeamAPI/Team.java b/src/main/java/de/nehlen/gameapi/TeamAPI/Team.java
index 455785b..234e64d 100644
--- a/src/main/java/de/nehlen/gameapi/TeamAPI/Team.java
+++ b/src/main/java/de/nehlen/gameapi/TeamAPI/Team.java
@@ -10,6 +10,7 @@
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.UUID;
/*
@@ -23,7 +24,7 @@ public class Team {
private ArrayList registeredPlayers;
private Integer maxTeamSize;
private ChatColor teamColor;
- private Integer uuid;
+ private UUID uuid;
private HashMap memory;
@Getter @Setter
@@ -140,7 +141,7 @@ public ChatColor getTeamColor() {
return this.teamColor;
}
- public Integer getUuid() {
+ public UUID getUuid() {
return this.uuid;
}
diff --git a/src/main/java/de/nehlen/gameapi/YamlConfiguration/SpigotConfigurationWrapper.java b/src/main/java/de/nehlen/gameapi/YamlConfiguration/SpigotConfigurationWrapper.java
new file mode 100644
index 0000000..639ed0d
--- /dev/null
+++ b/src/main/java/de/nehlen/gameapi/YamlConfiguration/SpigotConfigurationWrapper.java
@@ -0,0 +1,118 @@
+package de.nehlen.gameapi.YamlConfiguration;
+
+import org.bukkit.Location;
+import org.bukkit.configuration.file.YamlConfiguration;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * An interface for interacting with configuration files using the Yaml format.
+ */
+public interface SpigotConfigurationWrapper {
+
+ /**
+ * Loads the configuration data from the specified file.
+ *
+ * @param file the file to load the configuration data from
+ * @return current Configuration instance
+ */
+ SpigotConfigurationWrapper load(File file);
+
+ /**
+ * Saves the configuration data to the specified file.
+ *
+ */
+ void save();
+
+ /**
+ * Reloads the configuration data from the file it was last loaded from.
+ *
+ * @throws IOException if there was an error reading or parsing the configuration file
+ */
+ void reload() throws IOException;
+
+ /**
+ * Checks if the configuration contains a value at the specified path.
+ *
+ * @param path the path to check for a value
+ * @return true if a value exists at the specified path, false otherwise
+ */
+ boolean contains(String path);
+
+ /**
+ * Sets the value at the specified path.
+ *
+ * @param path the path to set the value at
+ * @param value the value to set
+ */
+ void set(String path, Object value);
+
+ /**
+ * Gets the value at the specified path.
+ *
+ * @param path the path to get the value at
+ * @return the value at the specified path, or null if no value exists at the path
+ */
+ T get(String path);
+
+ /**
+ * Gets the string value at the specified path.
+ *
+ * @param path the path to get the value at
+ * @return the string value at the specified path, or null if no value exists at the path
+ */
+ String getString(String path);
+
+ /**
+ * Gets the integer value at the specified path.
+ *
+ * @param path the path to get the value at
+ * @return the integer value at the specified path, or 0 if no value exists at the path or the value is not an integer
+ */
+ int getInt(String path);
+
+ /**
+ * Gets the double value at the specified path.
+ *
+ * @param path the path to get the value at
+ * @return the double value at the specified path, or 0.0 if no value exists at the path or the value is not a double
+ */
+ double getDouble(String path);
+
+ /**
+ * Gets the boolean value at the specified path.
+ *
+ * @param path the path to get the value at
+ * @return the boolean value at the specified path, or false if no value exists at the path or the value is not a boolean
+ */
+ boolean getBoolean(String path);
+
+ /**
+ * Gets the location value at the specified path.
+ *
+ * @param path the path to get the value at
+ * @return the Location value at the specified path, or 0,0,0 if no value exists at the path or the value is not a location
+ */
+ Location getLocation(String path);
+
+ /**
+ * Gets the underlying YamlConfiguration object.
+ *
+ * @return the underlying YamlConfiguration object
+ */
+ YamlConfiguration getConfig();
+
+ /**
+ * Gets the value at the specified path, or sets the value to the default value and returns it if no value exists at the path.
+ *
+ * @param path the path to get the value at
+ * @param defaultValue the default value to set and return if no value exists at the path
+ * @return the value at the specified path, or the default value if no value exists at the path
+ */
+ T getOrSetDefault(String path, T defaultValue);
+
+ boolean isSet(String path);
+}
+
+
diff --git a/src/main/java/de/nehlen/gameapi/YamlConfiguration/YamlConfig.java b/src/main/java/de/nehlen/gameapi/YamlConfiguration/YamlConfig.java
new file mode 100644
index 0000000..d1b024a
--- /dev/null
+++ b/src/main/java/de/nehlen/gameapi/YamlConfiguration/YamlConfig.java
@@ -0,0 +1,167 @@
+package de.nehlen.gameapi.YamlConfiguration;
+
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.WorldCreator;
+import org.bukkit.configuration.file.YamlConfiguration;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.logging.Level;
+
+public class YamlConfig implements SpigotConfigurationWrapper {
+
+ private final YamlConfiguration fileConfiguration = new YamlConfiguration();
+ private File file;
+
+ public YamlConfig(File file) {
+ File directory = file.getParentFile();
+ if (!file.exists()) {
+ if (!directory.exists()) {
+ directory.mkdirs();
+ }
+ try {file.createNewFile();}
+ catch (Exception e) {Bukkit.getLogger().log(Level.SEVERE, "Could not create " + file.getName() + ":", e);}
+ }
+ this.load(file);
+ }
+
+ @Override
+ public SpigotConfigurationWrapper load(File file) {
+ this.file = file;
+ try {
+ fileConfiguration.load(file);
+ } catch (Exception e) {
+ Bukkit.getLogger().log(Level.SEVERE, "Could not read " + file.getParentFile().getAbsolutePath() + ":", e);
+ }
+ return this;
+ }
+
+ @Override
+ public void save() {
+ if (file != null) {
+ try {
+ getConfig().save(file);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ @Override
+ public void reload() throws IOException {
+ if (file != null) {
+ try {
+ fileConfiguration.load(file);
+ } catch (Exception e) {
+ throw new IOException(e);
+ }
+ }
+ }
+
+ @Override
+ public boolean contains(String path) {
+ try {
+ return fileConfiguration.contains(path);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void set(final String path, final Object value) {
+ if (value instanceof Location) {
+ set(path + ".world", ((Location) value).getWorld().getName());
+ set(path + ".x", ((Location) value).getX());
+ set(path + ".y", ((Location) value).getY());
+ set(path + ".z", ((Location) value).getZ());
+ set(path + ".yaw", ((Location) value).getYaw());
+ set(path + ".pitch", ((Location) value).getPitch());
+ return;
+ }
+ fileConfiguration.set(path, value);
+ save();
+ }
+
+ @Override
+ public T get(String path) {
+ try {
+ return (T) fileConfiguration.get(path);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public String getString(String path) {
+ try {
+ return fileConfiguration.getString(path);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public int getInt(String path) {
+ try {
+ return fileConfiguration.getInt(path);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public double getDouble(String path) {
+ try {
+ return fileConfiguration.getDouble(path);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public boolean getBoolean(String path) {
+ try {
+ return fileConfiguration.getBoolean(path);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public Location getLocation(String path) {
+ final String worldName = getOrSetDefault(path + ".world", "world");
+ final double x = getOrSetDefault(path + ".x", 0D);
+ final double y = getOrSetDefault(path + ".y", 60D);
+ final double z = getOrSetDefault(path + ".z", 0D);
+ final double yaw = getOrSetDefault(path + ".yaw", 0D);
+ final double pitch = getOrSetDefault(path + ".pitch", 0D);
+ return new Location(Bukkit.getWorld(worldName), x, y, z, (float) yaw, (float) pitch);
+ }
+
+ @Override
+ public YamlConfiguration getConfig() {
+ return fileConfiguration;
+ }
+
+ @Override
+ public T getOrSetDefault(String path, T defaultValue) {
+ if (defaultValue instanceof Location && fileConfiguration.isSet(path + ".world")) {
+ return (T) new Location(Bukkit.createWorld(new WorldCreator(fileConfiguration.getString(path + ".world"))), fileConfiguration.getDouble(path + ".x"), fileConfiguration.getDouble(path + ".y"), fileConfiguration.getDouble(path + ".z"), (float) fileConfiguration.getDouble(path + ".yaw"), (float) fileConfiguration.getDouble(path + ".pitch"));
+ }
+ final Object object = fileConfiguration.get(path);
+ if (object == null) {
+ if (defaultValue != null) {
+ set(path, defaultValue);
+ }
+ return defaultValue;
+ }
+ return (T) object;
+ }
+
+ @Override
+ public boolean isSet(String path) {
+ return fileConfiguration.isSet(path);
+ }
+}
+
diff --git a/src/main/java/de/nehlen/gameapi/util/DatabaseLib.java b/src/main/java/de/nehlen/gameapi/util/DatabaseLib.java
index a76e67c..43835ad 100644
--- a/src/main/java/de/nehlen/gameapi/util/DatabaseLib.java
+++ b/src/main/java/de/nehlen/gameapi/util/DatabaseLib.java
@@ -19,9 +19,9 @@ public class DatabaseLib implements Closeable {
public DatabaseLib(Gameapi gameapi) {
this.gameapi = gameapi;
HikariConfig hikariConfig = new HikariConfig();
- hikariConfig.setJdbcUrl(gameapi.getDatabaseConfig().getOrSetDefault("config.database.url", "jdbc:mysql://localhost:3306/database"));
- hikariConfig.setUsername(gameapi.getDatabaseConfig().getOrSetDefault("config.database.username", "username"));
- hikariConfig.setPassword(gameapi.getDatabaseConfig().getOrSetDefault("config.database.password", "password"));
+ hikariConfig.setJdbcUrl((String) gameapi.getDatabaseConfig().getOrSetDefault("config.database.url", "jdbc:mysql://localhost:3306/database"));
+ hikariConfig.setUsername((String) gameapi.getDatabaseConfig().getOrSetDefault("config.database.username", "username"));
+ hikariConfig.setPassword((String) gameapi.getDatabaseConfig().getOrSetDefault("config.database.password", "password"));
hikariConfig.addDataSourceProperty("cachePrepStmts", "true");
hikariConfig.addDataSourceProperty("prepStmtCacheSize", "250");
hikariConfig.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
diff --git a/src/main/java/de/nehlen/gameapi/util/ServerID.java b/src/main/java/de/nehlen/gameapi/util/ServerID.java
index c81abd1..b84347c 100644
--- a/src/main/java/de/nehlen/gameapi/util/ServerID.java
+++ b/src/main/java/de/nehlen/gameapi/util/ServerID.java
@@ -1,7 +1,7 @@
package de.nehlen.gameapi.util;
import lombok.Getter;
-import org.apache.commons.lang.RandomStringUtils;
+import org.apache.commons.lang3.RandomStringUtils;
public class ServerID {
diff --git a/src/main/java/de/nehlen/gameapi/util/UUIDFetcher.java b/src/main/java/de/nehlen/gameapi/util/UUIDFetcher.java
deleted file mode 100644
index 648933c..0000000
--- a/src/main/java/de/nehlen/gameapi/util/UUIDFetcher.java
+++ /dev/null
@@ -1,135 +0,0 @@
-package de.nehlen.gameapi.util;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.mojang.util.UUIDTypeAdapter;
-
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.function.Consumer;
-
-public class UUIDFetcher {
-
- /**
- * Date when name changes were introduced
- * @see UUIDFetcher#getUUIDAt(String, long)
- */
- public static final long FEBRUARY_2015 = 1422748800000L;
-
-
- private static Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create();
-
- private static final String UUID_URL = "https://api.mojang.com/users/profiles/minecraft/%s?at=%d";
- private static final String NAME_URL = "https://api.mojang.com/user/profiles/%s/names";
-
- private static Map uuidCache = new HashMap();
- private static Map nameCache = new HashMap();
-
- private static ExecutorService pool = Executors.newCachedThreadPool();
-
- private String name;
- private UUID id;
-
- /**
- * Fetches the uuid asynchronously and passes it to the consumer
- *
- * @param name The name
- * @param action Do what you want to do with the uuid her
- */
- public static void getUUID(String name, Consumer action) {
- pool.execute(() -> action.accept(getUUID(name)));
- }
-
- /**
- * Fetches the uuid synchronously and returns it
- *
- * @param name The name
- * @return The uuid
- */
- public static UUID getUUID(String name) {
- return getUUIDAt(name, System.currentTimeMillis());
- }
-
- /**
- * Fetches the uuid synchronously for a specified name and time and passes the result to the consumer
- *
- * @param name The name
- * @param timestamp Time when the player had this name in milliseconds
- * @param action Do what you want to do with the uuid her
- */
- public static void getUUIDAt(String name, long timestamp, Consumer action) {
- pool.execute(() -> action.accept(getUUIDAt(name, timestamp)));
- }
-
- /**
- * Fetches the uuid synchronously for a specified name and time
- *
- * @param name The name
- * @param timestamp Time when the player had this name in milliseconds
- * @see UUIDFetcher#FEBRUARY_2015
- */
- public static UUID getUUIDAt(String name, long timestamp) {
- name = name.toLowerCase();
- if (uuidCache.containsKey(name)) {
- return uuidCache.get(name);
- }
- try {
- HttpURLConnection connection = (HttpURLConnection) new URL(String.format(UUID_URL, name, timestamp/1000)).openConnection();
- connection.setReadTimeout(5000);
- UUIDFetcher data = gson.fromJson(new BufferedReader(new InputStreamReader(connection.getInputStream())), UUIDFetcher.class);
-
- uuidCache.put(name, data.id);
- nameCache.put(data.id, data.name);
-
- return data.id;
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- return null;
- }
-
- /**
- * Fetches the name asynchronously and passes it to the consumer
- *
- * @param uuid The uuid
- * @param action Do what you want to do with the name her
- */
- public static void getName(UUID uuid, Consumer action) {
- pool.execute(() -> action.accept(getName(uuid)));
- }
-
- /**
- * Fetches the name synchronously and returns it
- *
- * @param uuid The uuid
- * @return The name
- */
- public static String getName(UUID uuid) {
- if (nameCache.containsKey(uuid)) {
- return nameCache.get(uuid);
- }
- try {
- HttpURLConnection connection = (HttpURLConnection) new URL(String.format(NAME_URL, UUIDTypeAdapter.fromUUID(uuid))).openConnection();
- connection.setReadTimeout(5000);
- UUIDFetcher[] nameHistory = gson.fromJson(new BufferedReader(new InputStreamReader(connection.getInputStream())), UUIDFetcher[].class);
- UUIDFetcher currentNameData = nameHistory[nameHistory.length - 1];
-
- uuidCache.put(currentNameData.name.toLowerCase(), uuid);
- nameCache.put(uuid, currentNameData.name);
-
- return currentNameData.name;
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- return null;
- }
-}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 372d85a..093a63e 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,8 +1,7 @@
name: GameAPI
version: '${project.version}'
main: de.nehlen.gameapi.Gameapi
-api-version: 1.13
-depend: [MCCommons]
+api-version: 1.19
prefix: GameAPI
authors: [ DasNiklas ]
description: GameAPI for minigames