Dieser Commit ist enthalten in:
Silent 2020-12-08 22:22:41 +01:00
Ursprung a69d3a07de
Commit 6af5c2684b
11 geänderte Dateien mit 152 neuen und 264 gelöschten Zeilen

39
pom.xml
Datei anzeigen

@ -6,11 +6,11 @@
<groupId>tsp.headdb</groupId> <groupId>tsp.headdb</groupId>
<artifactId>HeadDB</artifactId> <artifactId>HeadDB</artifactId>
<version>1.3</version> <version>2.0</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>HeadDB</name> <name>HeadDB</name>
<description>Thousands of heads in a GUI</description> <description>Database with thousands of heads</description>
<repositories> <repositories>
<!-- Paper Repo --> <!-- Paper Repo -->
@ -23,9 +23,15 @@
<id>mojang-repo</id> <id>mojang-repo</id>
<url>https://libraries.minecraft.net/</url> <url>https://libraries.minecraft.net/</url>
</repository> </repository>
<!-- JitPack -->
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
<!-- Paper API -->
<dependency> <dependency>
<groupId>com.destroystokyo.paper</groupId> <groupId>com.destroystokyo.paper</groupId>
<artifactId>paper-api</artifactId> <artifactId>paper-api</artifactId>
@ -45,10 +51,17 @@
<version>1.5.21</version> <version>1.5.21</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- Storage Lib -->
<dependency>
<groupId>com.github.simplix-softworks</groupId>
<artifactId>simplixstorage</artifactId>
<version>3.2.0</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<!-- Compiler -->
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
@ -57,6 +70,28 @@
<target>8</target> <target>8</target>
</configuration> </configuration>
</plugin> </plugin>
<!-- Shade -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>tsp.headdb.HeadDB</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>

Datei anzeigen

@ -1,12 +1,15 @@
package tsp.headdb; package tsp.headdb;
import de.leonhard.storage.Config;
import de.leonhard.storage.Json;
import de.leonhard.storage.LightningBuilder;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import tsp.headdb.api.HeadAPI;
import tsp.headdb.command.Command_headdb; import tsp.headdb.command.Command_headdb;
import tsp.headdb.database.HeadDatabase;
import tsp.headdb.listener.JoinListener; import tsp.headdb.listener.JoinListener;
import tsp.headdb.listener.PagedPaneListener; import tsp.headdb.listener.PagedPaneListener;
import tsp.headdb.listener.MenuListener; import tsp.headdb.listener.MenuListener;
import tsp.headdb.util.Config;
import tsp.headdb.util.Log; import tsp.headdb.util.Log;
import tsp.headdb.util.Metrics; import tsp.headdb.util.Metrics;
import tsp.headdb.util.Utils; import tsp.headdb.util.Utils;
@ -15,16 +18,15 @@ public class HeadDB extends JavaPlugin {
private static HeadDB instance; private static HeadDB instance;
private static Config config; private static Config config;
private static Config playerdata; private static Json playerdata;
@Override @Override
public void onEnable() { public void onEnable() {
instance = this; instance = this;
Log.info("Loading HeadDB - " + getDescription().getVersion()); Log.info("Loading HeadDB - " + getDescription().getVersion());
saveDefaultConfig(); saveDefaultConfig();
config = new Config("plugins/HeadDB/config.yml"); config = LightningBuilder.fromPath("config.yml", "plugins/HeadDB").createConfig().addDefaultsFromInputStream();
playerdata = new Config("plugins/HeadDB/playerdata.yml"); playerdata = LightningBuilder.fromPath("playerdata.json", "plugins/HeadDB").createJson();
playerdata.create();
Log.debug("Starting metrics..."); Log.debug("Starting metrics...");
new Metrics(this, Utils.METRICS_ID); new Metrics(this, Utils.METRICS_ID);
@ -37,8 +39,15 @@ public class HeadDB extends JavaPlugin {
Log.debug("Registering commands..."); Log.debug("Registering commands...");
getCommand("headdb").setExecutor(new Command_headdb()); getCommand("headdb").setExecutor(new Command_headdb());
Log.debug("Initializing Database..."); if (config.getBoolean("fetchStartup")) {
HeadDatabase.update(); if (config.getBoolean("asyncStartup")) {
Log.debug("Initializing Database... (ASYNC)");
Bukkit.getScheduler().runTaskAsynchronously(this, task -> HeadAPI.getDatabase().update());
}else {
Log.debug("Initializing Database... (SYNC)");
Bukkit.getScheduler().runTask(this, task -> HeadAPI.getDatabase().update());
}
}
Log.info("Done!"); Log.info("Done!");
} }
@ -47,7 +56,7 @@ public class HeadDB extends JavaPlugin {
return config; return config;
} }
public static Config getPlayerdata() { public static Json getPlayerdata() {
return playerdata; return playerdata;
} }

Datei anzeigen

@ -22,6 +22,12 @@ public class Head {
private Category category; private Category category;
private int id; private int id;
public Head() {}
public Head(int id) {
this.id = id;
}
public ItemStack getItemStack() { public ItemStack getItemStack() {
Validate.notNull(name, "name must not be null!"); Validate.notNull(name, "name must not be null!");
Validate.notNull(uuid, "uuid must not be null!"); Validate.notNull(uuid, "uuid must not be null!");
@ -44,6 +50,7 @@ public class Head {
} }
meta.setLore(Arrays.asList( meta.setLore(Arrays.asList(
Utils.colorize("&cID: " + id), Utils.colorize("&cID: " + id),
" ",
Utils.colorize("&8Right-Click to add/remove from favorites.") Utils.colorize("&8Right-Click to add/remove from favorites.")
)); ));
item.setItemMeta(meta); item.setItemMeta(meta);
@ -55,85 +62,45 @@ public class Head {
return name; return name;
} }
public void setName(String name) {
this.name = name;
}
public UUID getUUID() { public UUID getUUID() {
return uuid; return uuid;
} }
public void setUUID(UUID uuid) {
this.uuid = uuid;
}
public String getValue() { public String getValue() {
return value; return value;
} }
public void setValue(String value) {
this.value = value;
}
public Category getCategory() { public Category getCategory() {
return category; return category;
} }
public void setCategory(Category category) {
this.category = category;
}
public int getId() { public int getId() {
return id; return id;
} }
public void setId(int id) { public Head withName(String name) {
this.id = id; this.name = name;
return this;
} }
public static class Builder { public Head withUUID(UUID uuid) {
this.uuid = uuid;
return this;
}
private String name; public Head withValue(String value) {
private UUID uuid; this.value = value;
private String value; return this;
private Category category; }
private int id;
public Builder withName(String name) { public Head withCategory(Category category) {
this.name = name; this.category = category;
return this; return this;
} }
public Builder withUUID(UUID uuid) {
this.uuid = uuid;
return this;
}
public Builder withValue(String value) {
this.value = value;
return this;
}
public Builder withCategory(Category category) {
this.category = category;
return this;
}
public Builder withId(int id) {
this.id = id;
return this;
}
public Head build() {
Head head = new Head();
head.setName(name);
head.setUUID(uuid);
head.setValue(value);
head.setCategory(category);
head.setId(id);
return head;
}
public Head withId(int id) {
this.id = id;
return this;
} }
} }

Datei anzeigen

@ -8,6 +8,7 @@ import tsp.headdb.database.Category;
import tsp.headdb.database.HeadDatabase; import tsp.headdb.database.HeadDatabase;
import tsp.headdb.inventory.InventoryUtils; import tsp.headdb.inventory.InventoryUtils;
import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -20,6 +21,17 @@ import java.util.UUID;
*/ */
public class HeadAPI { public class HeadAPI {
private static final HeadDatabase database = new HeadDatabase();
/**
* Retrieves the main {@link HeadDatabase}
*
* @return Head Database
*/
public static HeadDatabase getDatabase() {
return database;
}
/** /**
* Opens the database for a player * Opens the database for a player
* *
@ -55,8 +67,9 @@ public class HeadAPI {
* @param id The ID of the head * @param id The ID of the head
* @return The head * @return The head
*/ */
@Nullable
public static Head getHeadByID(int id) { public static Head getHeadByID(int id) {
return HeadDatabase.getHeadByID(id); return database.getHeadByID(id);
} }
/** /**
@ -65,8 +78,9 @@ public class HeadAPI {
* @param uuid The UUID of the head * @param uuid The UUID of the head
* @return The head * @return The head
*/ */
@Nullable
public static Head getHeadByUUID(UUID uuid) { public static Head getHeadByUUID(UUID uuid) {
return HeadDatabase.getHeadByUUID(uuid); return database.getHeadByUUID(uuid);
} }
/** /**
@ -76,7 +90,7 @@ public class HeadAPI {
* @return List of heads * @return List of heads
*/ */
public static List<Head> getHeadsByName(String name) { public static List<Head> getHeadsByName(String name) {
return HeadDatabase.getHeadsByName(name); return database.getHeadsByName(name);
} }
/** /**
@ -87,7 +101,7 @@ public class HeadAPI {
* @return List of heads * @return List of heads
*/ */
public static List<Head> getHeadsByName(Category category, String name) { public static List<Head> getHeadsByName(Category category, String name) {
return HeadDatabase.getHeadsByName(category, name); return database.getHeadsByName(category, name);
} }
/** /**
@ -96,8 +110,9 @@ public class HeadAPI {
* @param value The texture value * @param value The texture value
* @return The head * @return The head
*/ */
@Nullable
public static Head getHeadByValue(String value) { public static Head getHeadByValue(String value) {
return HeadDatabase.getHeadByValue(value); return database.getHeadByValue(value);
} }
/** /**
@ -107,7 +122,7 @@ public class HeadAPI {
* @return List of heads * @return List of heads
*/ */
public static List<Head> getHeads(Category category) { public static List<Head> getHeads(Category category) {
return HeadDatabase.getHeads(category); return database.getHeads(category);
} }
/** /**
@ -116,7 +131,7 @@ public class HeadAPI {
* @return List of all heads * @return List of all heads
*/ */
public static List<Head> getHeads() { public static List<Head> getHeads() {
return HeadDatabase.getHeads(); return database.getHeads();
} }
/** /**
@ -126,12 +141,11 @@ public class HeadAPI {
* @param id The ID of the head * @param id The ID of the head
*/ */
public static void addFavoriteHead(UUID uuid, int id) { public static void addFavoriteHead(UUID uuid, int id) {
List<Integer> favs = HeadDB.getPlayerdata().getIntList(uuid.toString() + ".favorites"); List<Integer> favs = HeadDB.getPlayerdata().getIntegerList(uuid.toString() + ".favorites");
if (!favs.contains(id)) { if (!favs.contains(id)) {
favs.add(id); favs.add(id);
} }
HeadDB.getPlayerdata().set(uuid.toString() + ".favorites", favs); HeadDB.getPlayerdata().set(uuid.toString() + ".favorites", favs);
HeadDB.getPlayerdata().save();
} }
/** /**
@ -141,7 +155,7 @@ public class HeadAPI {
* @param id The ID of the head * @param id The ID of the head
*/ */
public static void removeFavoriteHead(UUID uuid, int id) { public static void removeFavoriteHead(UUID uuid, int id) {
List<Integer> favs = HeadDB.getPlayerdata().getIntList(uuid.toString() + ".favorites"); List<Integer> favs = HeadDB.getPlayerdata().getIntegerList(uuid.toString() + ".favorites");
for (int i = 0; i < favs.size(); i++) { for (int i = 0; i < favs.size(); i++) {
if (favs.get(i) == id) { if (favs.get(i) == id) {
favs.remove(i); favs.remove(i);
@ -149,7 +163,6 @@ public class HeadAPI {
} }
} }
HeadDB.getPlayerdata().set(uuid.toString() + ".favorites", favs); HeadDB.getPlayerdata().set(uuid.toString() + ".favorites", favs);
HeadDB.getPlayerdata().save();
} }
/** /**
@ -160,7 +173,7 @@ public class HeadAPI {
*/ */
public static List<Head> getFavoriteHeads(UUID uuid) { public static List<Head> getFavoriteHeads(UUID uuid) {
List<Head> heads = new ArrayList<>(); List<Head> heads = new ArrayList<>();
List<Integer> ids = HeadDB.getPlayerdata().getIntList(uuid.toString() + ".favorites"); List<Integer> ids = HeadDB.getPlayerdata().getIntegerList(uuid.toString() + ".favorites");
for (int id : ids) { for (int id : ids) {
Head head = getHeadByID(id); Head head = getHeadByID(id);
heads.add(head); heads.add(head);
@ -177,12 +190,10 @@ public class HeadAPI {
*/ */
public static List<LocalHead> getLocalHeads() { public static List<LocalHead> getLocalHeads() {
List<LocalHead> heads = new ArrayList<>(); List<LocalHead> heads = new ArrayList<>();
for (String key : HeadDB.getPlayerdata().getKeys(false)) { for (String key : HeadDB.getPlayerdata().keySet()) {
OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(key)); OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(key));
heads.add(new LocalHead.Builder() heads.add(new LocalHead(player.getUniqueId())
.withUUID(player.getUniqueId()) .withName(player.getName()));
.withName(player.getName())
.build());
} }
return heads; return heads;
@ -192,7 +203,7 @@ public class HeadAPI {
* Update the Head Database * Update the Head Database
*/ */
public static void updateDatabase() { public static void updateDatabase() {
HeadDatabase.update(); database.update();
} }
} }

Datei anzeigen

@ -39,39 +39,18 @@ public class LocalHead {
return uuid; return uuid;
} }
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String name) { public LocalHead withUUID(UUID uuid) {
this.name = name; this.uuid = uuid;
return this;
} }
public static class Builder { public LocalHead withName(String name) {
this.name = name;
private UUID uuid; return this;
private String name;
public Builder withUUID(UUID uuid) {
this.uuid = uuid;
return this;
}
public Builder withName(String name) {
this.name = name;
return this;
}
public LocalHead build() {
LocalHead head = new LocalHead(uuid);
head.setName(name);
return head;
}
} }
} }

Datei anzeigen

@ -36,6 +36,7 @@ public class Command_headdb implements CommandExecutor {
if (sub.equalsIgnoreCase("info") || sub.equalsIgnoreCase("i")) { if (sub.equalsIgnoreCase("info") || sub.equalsIgnoreCase("i")) {
Utils.sendMessage(sender, "Running &cHeadDB v" + HeadDB.getInstance().getDescription().getVersion()); Utils.sendMessage(sender, "Running &cHeadDB v" + HeadDB.getInstance().getDescription().getVersion());
Utils.sendMessage(sender, "Created by &c" + HeadDB.getInstance().getDescription().getAuthors()); Utils.sendMessage(sender, "Created by &c" + HeadDB.getInstance().getDescription().getAuthors());
Utils.sendMessage(sender, "There are currently &c" + HeadAPI.getHeads().size() + " &7heads in the database.");
return true; return true;
} }
@ -56,7 +57,10 @@ public class Command_headdb implements CommandExecutor {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
for (int i = 1; i < args.length; i++) { for (int i = 1; i < args.length; i++) {
builder.append(args[i]).append(" "); builder.append(args[i]);
if (i != args.length - 1) {
builder.append(" ");
}
} }
String name = builder.toString(); String name = builder.toString();
Utils.sendMessage(sender, "Searching for &e" + name); Utils.sendMessage(sender, "Searching for &e" + name);

Datei anzeigen

@ -1,5 +1,6 @@
package tsp.headdb.database; package tsp.headdb.database;
import org.bukkit.ChatColor;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser; import org.json.simple.parser.JSONParser;
@ -23,11 +24,13 @@ import java.util.concurrent.TimeUnit;
*/ */
public class HeadDatabase { public class HeadDatabase {
private static final Map<Category, List<Head>> HEADS = new HashMap<>(); private final Map<Category, List<Head>> HEADS = new HashMap<>();
private static final String URL = "https://minecraft-heads.com/scripts/api.php?cat="; private final String URL = "https://minecraft-heads.com/scripts/api.php?cat=";
private static long updated; private long updated;
public HeadDatabase() {}
public static Head getHeadByValue(String value) { public Head getHeadByValue(String value) {
List<Head> heads = getHeads(); List<Head> heads = getHeads();
for (Head head : heads) { for (Head head : heads) {
if (head.getValue().equals(value)) { if (head.getValue().equals(value)) {
@ -38,7 +41,7 @@ public class HeadDatabase {
return null; return null;
} }
public static Head getHeadByID(int id) { public Head getHeadByID(int id) {
List<Head> heads = getHeads(); List<Head> heads = getHeads();
for (Head head : heads) { for (Head head : heads) {
if (head.getId() == id) { if (head.getId() == id) {
@ -49,7 +52,7 @@ public class HeadDatabase {
return null; return null;
} }
public static Head getHeadByUUID(UUID uuid) { public Head getHeadByUUID(UUID uuid) {
List<Head> heads = getHeads(); List<Head> heads = getHeads();
for (Head head : heads) { for (Head head : heads) {
if (head.getUUID().equals(uuid)) { if (head.getUUID().equals(uuid)) {
@ -60,11 +63,12 @@ public class HeadDatabase {
return null; return null;
} }
public static List<Head> getHeadsByName(Category category, String name) { public List<Head> getHeadsByName(Category category, String name) {
List<Head> result = new ArrayList<>(); List<Head> result = new ArrayList<>();
List<Head> heads = getHeads(category); List<Head> heads = getHeads(category);
for (Head head : heads) { for (Head head : heads) {
if (head.getName().toLowerCase().contains(name.toLowerCase())) { String hName = ChatColor.stripColor(head.getName().toLowerCase(Locale.ROOT));
if (hName.contains(ChatColor.stripColor(name.toLowerCase(Locale.ROOT)))) {
result.add(head); result.add(head);
} }
} }
@ -72,23 +76,20 @@ public class HeadDatabase {
return result; return result;
} }
public static List<Head> getHeadsByName(String name) { public List<Head> getHeadsByName(String name) {
List<Head> result = new ArrayList<>(); List<Head> result = new ArrayList<>();
List<Head> heads = getHeads(); for (Category category : Category.values()) {
for (Head head : heads) { result.addAll(getHeadsByName(category, name));
if (head.getName().toLowerCase().contains(name.toLowerCase())) {
result.add(head);
}
} }
return result; return result;
} }
public static List<Head> getHeads(Category category) { public List<Head> getHeads(Category category) {
return HEADS.get(category); return HEADS.get(category);
} }
public static List<Head> getHeads() { public List<Head> getHeads() {
if (!HEADS.isEmpty() && !isLastUpdateOld()) { if (!HEADS.isEmpty() && !isLastUpdateOld()) {
List<Head> heads = new ArrayList<>(); List<Head> heads = new ArrayList<>();
for (Category category : HEADS.keySet()) { for (Category category : HEADS.keySet()) {
@ -101,7 +102,7 @@ public class HeadDatabase {
return getHeads(); return getHeads();
} }
public static Map<Category, List<Head>> getHeadsNoCache() { public Map<Category, List<Head>> getHeadsNoCache() {
Map<Category, List<Head>> result = new HashMap<>(); Map<Category, List<Head>> result = new HashMap<>();
List<Category> categories = Category.getCategories(); List<Category> categories = Category.getCategories();
@ -116,9 +117,7 @@ public class HeadDatabase {
URLConnection connection = new URL(URL + category.getName()).openConnection(); URLConnection connection = new URL(URL + category.getName()).openConnection();
connection.setConnectTimeout(5000); connection.setConnectTimeout(5000);
connection.setRequestProperty("User-Agent", "HeadDB"); connection.setRequestProperty("User-Agent", "HeadDB");
try (BufferedReader in = new BufferedReader( try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
new InputStreamReader(
connection.getInputStream()))) {
while ((line = in.readLine()) != null) { while ((line = in.readLine()) != null) {
response.append(line); response.append(line);
} }
@ -127,13 +126,11 @@ public class HeadDatabase {
JSONArray array = (JSONArray) parser.parse(response.toString()); JSONArray array = (JSONArray) parser.parse(response.toString());
for (Object o : array) { for (Object o : array) {
JSONObject obj = (JSONObject) o; JSONObject obj = (JSONObject) o;
Head head = new Head.Builder() Head head = new Head(id)
.withName(obj.get("name").toString()) .withName(obj.get("name").toString())
.withUUID(UUID.fromString(obj.get("uuid").toString())) .withUUID(UUID.fromString(obj.get("uuid").toString()))
.withValue(obj.get("value").toString()) .withValue(obj.get("value").toString())
.withCategory(category) .withCategory(category);
.withId(id)
.build();
id++; id++;
heads.add(head); heads.add(head);
@ -150,7 +147,7 @@ public class HeadDatabase {
return result; return result;
} }
public static void update() { public void update() {
Map<Category, List<Head>> heads = getHeadsNoCache(); Map<Category, List<Head>> heads = getHeadsNoCache();
HEADS.clear(); HEADS.clear();
for (Map.Entry<Category, List<Head>> entry : heads.entrySet()) { for (Map.Entry<Category, List<Head>> entry : heads.entrySet()) {
@ -158,13 +155,13 @@ public class HeadDatabase {
} }
} }
public static long getLastUpdate() { public long getLastUpdate() {
long now = System.nanoTime(); long now = System.nanoTime();
long elapsed = now - updated; long elapsed = now - updated;
return TimeUnit.NANOSECONDS.toSeconds(elapsed); return TimeUnit.NANOSECONDS.toSeconds(elapsed);
} }
public static boolean isLastUpdateOld() { public boolean isLastUpdateOld() {
if (HeadDB.getCfg() == null && getLastUpdate() >= 3600) return true; if (HeadDB.getCfg() == null && getLastUpdate() >= 3600) return true;
return getLastUpdate() >= HeadDB.getCfg().getLong("refresh"); return getLastUpdate() >= HeadDB.getCfg().getLong("refresh");
} }

Datei anzeigen

@ -14,7 +14,6 @@ public class JoinListener implements Listener {
@EventHandler @EventHandler
public void onJoin(PlayerJoinEvent e) { public void onJoin(PlayerJoinEvent e) {
HeadDB.getPlayerdata().set(e.getPlayer().getUniqueId().toString() + ".username", e.getPlayer().getName()); HeadDB.getPlayerdata().set(e.getPlayer().getUniqueId().toString() + ".username", e.getPlayer().getName());
HeadDB.getPlayerdata().save();
} }
} }

Datei anzeigen

@ -1,119 +0,0 @@
package tsp.headdb.util;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Set;
/**
* @author TheSilentPro
*/
public class Config {
private final File file;
private FileConfiguration config;
public Config(File file) {
this.file = file;
this.config = YamlConfiguration.loadConfiguration(file);
}
public Config(String path) {
this.file = new File(path);
this.config = YamlConfiguration.loadConfiguration(file);
}
public Config(Config config) {
this.file = config.getFile();
this.config = config.getConfig();
}
public String getString(String path) {
return Utils.colorize(config.getString(path));
}
public boolean getBoolean(String path) {
return config.getBoolean(path);
}
public List<String> getStringList(String path) {
return config.getStringList(path);
}
public int getInt(String path) {
return config.getInt(path);
}
public List<Integer> getIntList(String path) {
return config.getIntegerList(path);
}
public long getLong(String path) {
return config.getLong(path);
}
public Set<String> getKeys(boolean deep) {
return config.getKeys(deep);
}
public ConfigurationSection getConfigurationSection(String path) {
return config.getConfigurationSection(path);
}
public Set<String> getKeys(ConfigurationSection configurationSection, boolean b) {
return configurationSection.getKeys(b);
}
public void set(String path, Object value) {
config.set(path, value);
}
public Object get(String path) {
return config.get(path);
}
public FileConfiguration getConfig() {
return config;
}
public File getFile() {
return file;
}
public boolean exists() {
return file.exists();
}
public void reload() {
this.config = YamlConfiguration.loadConfiguration(file);
}
public boolean create() {
if (!file.exists()) {
try {
return file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
return false;
}
public boolean save() {
try {
config.save(file);
return true;
} catch (IOException e) {
Log.error("Failed to save " + file.getName() + " | Stack Trace:");
e.printStackTrace();
}
return false;
}
}

Datei anzeigen

@ -1,3 +1,9 @@
# When enabled heads will be fetched from startup, otherwise when the /hdb command is ran
fetchStartup: true
# When enabled, heads will be fetched async (Startup Only)
asyncStartup: false
# If the cached heads are older than these amount of seconds, the plugin will refresh the database # If the cached heads are older than these amount of seconds, the plugin will refresh the database
refresh: 3600 refresh: 3600

Datei anzeigen

@ -1,8 +1,8 @@
name: HeadDB name: HeadDB
description: Adds a menu with thousands of heads description: Database with thousands of heads
main: tsp.headdb.HeadDB main: tsp.headdb.HeadDB
version: 1.3 version: 2.0
api-version: 1.16 api-version: 1.16
author: Silent author: Silent