refactor and localHeads option

Dieser Commit ist enthalten in:
Silent 2021-08-02 18:03:30 +02:00
Ursprung 7fceb6ca59
Commit 47f4f5b2b1
7 geänderte Dateien mit 24 neuen und 51 gelöschten Zeilen

Datei anzeigen

@ -6,7 +6,7 @@
<groupId>tsp.headdb</groupId>
<artifactId>HeadDB</artifactId>
<version>2.4.0</version>
<version>2.4.1</version>
<packaging>jar</packaging>
<name>HeadDB</name>
@ -92,8 +92,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>16</source>
<target>16</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

Datei anzeigen

@ -11,7 +11,6 @@ import tsp.headdb.listener.MenuListener;
import tsp.headdb.util.Log;
import tsp.headdb.util.Metrics;
import tsp.headdb.util.Storage;
import tsp.headdb.util.Utils;
import org.bukkit.plugin.RegisteredServiceProvider;
import net.milkbowl.vault.economy.Economy;
@ -48,9 +47,6 @@ public class HeadDB extends JavaPlugin {
}
}
Log.debug("Starting metrics...");
new Metrics(this, Utils.METRICS_ID);
Log.debug("Registering listeners...");
new PagedPaneListener(this);
new MenuListener(this);
@ -59,6 +55,8 @@ public class HeadDB extends JavaPlugin {
Log.debug("Registering commands...");
getCommand("headdb").setExecutor(new Command_headdb());
Log.debug("Starting metrics...");
new Metrics(this, 9152);
Log.info("Done!");
}

Datei anzeigen

@ -1,6 +1,5 @@
package tsp.headdb.database;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;
import org.json.simple.JSONArray;
@ -8,8 +7,8 @@ import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import tsp.headdb.api.Head;
import tsp.headdb.event.HeadDatabaseUpdateEvent;
import tsp.headdb.util.Log;
import tsp.headdb.util.Utils;
import java.io.BufferedReader;
import java.io.IOException;
@ -164,10 +163,11 @@ public class HeadDatabase {
for (Object o : array) {
JSONObject obj = (JSONObject) o;
String uuid = obj.get("uuid").toString();
Log.debug(!Utils.isValid(uuid) + "Invalid UUID: " + uuid);
Head head = new Head(id)
.withName(obj.get("name").toString())
.withUniqueId(uuid.isEmpty() ? UUID.randomUUID() : UUID.fromString(uuid))
.withUniqueId(Utils.isValid(uuid) ? UUID.fromString(uuid) : UUID.randomUUID())
.withValue(obj.get("value").toString())
.withTags(obj.get("tags") != null ? obj.get("tags").toString() : "None")
.withCategory(category);
@ -207,7 +207,6 @@ public class HeadDatabase {
for (Map.Entry<Category, List<Head>> entry : heads.entrySet()) {
HEADS.put(entry.getKey(), entry.getValue());
}
Bukkit.getPluginManager().callEvent(new HeadDatabaseUpdateEvent(this));
return true;
}

Datei anzeigen

@ -1,38 +0,0 @@
package tsp.headdb.event;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import tsp.headdb.database.HeadDatabase;
public class HeadDatabaseUpdateEvent extends Event implements Cancellable {
private final HandlerList handlerList = new HandlerList();
private boolean cancelled;
private final HeadDatabase database;
public HeadDatabaseUpdateEvent(HeadDatabase database) {
this.database = database;
}
public HeadDatabase getDatabase() {
return database;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean b) {
this.cancelled = b;
}
@Override
public @NotNull HandlerList getHandlers() {
return handlerList;
}
}

Datei anzeigen

@ -8,8 +8,11 @@ import tsp.headdb.HeadDB;
public class JoinListener implements Listener {
public JoinListener(HeadDB plugin) {
// If local heads are disabled, there is no need for this listener.
if (HeadDB.getInstance().getConfiguration().getBoolean("localHeads")) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
}
@EventHandler
public void onJoin(PlayerJoinEvent e) {

Datei anzeigen

@ -3,9 +3,17 @@ package tsp.headdb.util;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Utils {
public static final int METRICS_ID = 9152;
public static final Pattern UUID_PATTERN = Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$");
public static boolean isValid(String uuid) {
Matcher matcher = UUID_PATTERN.matcher(uuid);
return matcher.find();
}
public static void sendMessage(CommandSender sender, String message) {
sender.sendMessage(colorize(message));

Datei anzeigen

@ -7,6 +7,9 @@ asyncStartup: false
# If the cached heads are older than these amount of seconds, the plugin will refresh the database
refresh: 3600
# If local heads should be enabled. Only keeps track of joined players when enabled!
localHeads: true
# Economy options
economy:
enable: false