3
0
Mirror von https://github.com/TheSilentPro/HeadDB.git synchronisiert 2024-12-26 19:02:39 +01:00

migrate to nexuslib, add blockedHeads, fix langs/favs

Dieser Commit ist enthalten in:
Silent 2023-05-20 23:47:16 +02:00
Ursprung 421757e484
Commit 19fbd70bf8
21 geänderte Dateien mit 96 neuen und 113 gelöschten Zeilen

Datei anzeigen

@ -6,7 +6,7 @@
<groupId>tsp.headdb</groupId>
<artifactId>HeadDB</artifactId>
<version>5.0.0-rc.5</version>
<version>5.0.0-rc.6</version>
<packaging>jar</packaging>
<name>HeadDB</name>
@ -74,8 +74,8 @@
<!-- Hard Dependencies (Shaded) -->
<dependency>
<groupId>com.github.TheSilentPro</groupId>
<artifactId>SmartPlugin</artifactId>
<version>737fc7b893</version>
<artifactId>NexusLib</artifactId>
<version>c01a0a0a7d</version>
</dependency>
<dependency>
<groupId>com.github.TheSilentPro</groupId>

Datei anzeigen

@ -1,36 +1,25 @@
package tsp.headdb;
import org.bukkit.command.PluginCommand;
import tsp.headdb.core.command.CommandCategory;
import tsp.headdb.core.command.CommandGive;
import tsp.headdb.core.command.CommandHelp;
import tsp.headdb.core.command.CommandInfo;
import tsp.headdb.core.command.CommandLanguage;
import tsp.headdb.core.command.CommandMain;
import tsp.headdb.core.command.CommandManager;
import tsp.headdb.core.command.CommandReload;
import tsp.headdb.core.command.CommandSearch;
import tsp.headdb.core.command.CommandSettings;
import tsp.headdb.core.command.CommandTexture;
import tsp.headdb.core.command.CommandUpdate;
import tsp.headdb.core.command.*;
import tsp.headdb.core.economy.BasicEconomyProvider;
import tsp.headdb.core.economy.VaultProvider;
import tsp.headdb.core.storage.Storage;
import tsp.headdb.core.task.UpdateTask;
import tsp.headdb.core.util.HeadDBLogger;
import tsp.smartplugin.SmartPlugin;
import tsp.smartplugin.inventory.PaneListener;
import tsp.smartplugin.localization.TranslatableLocalization;
import tsp.smartplugin.utils.PluginUtils;
import tsp.nexuslib.NexusPlugin;
import tsp.nexuslib.inventory.PaneListener;
import tsp.nexuslib.localization.TranslatableLocalization;
import tsp.nexuslib.util.PluginUtils;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URISyntaxException;
import java.text.DecimalFormat;
import java.util.Optional;
public class HeadDB extends SmartPlugin {
public class HeadDB extends NexusPlugin {
private static HeadDB instance;
private HeadDBLogger logger;
@ -40,7 +29,7 @@ public class HeadDB extends SmartPlugin {
private CommandManager commandManager;
@Override
public void onStart() {
public void onStart(NexusPlugin nexusPlugin) {
instance = this;
instance.saveDefaultConfig();
instance.logger = new HeadDBLogger(getConfig().getBoolean("debug"));
@ -66,6 +55,16 @@ public class HeadDB extends SmartPlugin {
public void onDisable() {
if (storage != null) {
storage.getPlayerStorage().suspend();
File langFile = new File(getDataFolder(), "langs.data");
if (!langFile.exists()) {
try {
langFile.createNewFile();
localization.saveLanguages(langFile);
} catch (IOException ex) {
logger.error("Failed to save receiver langauges!");
ex.printStackTrace();
}
}
}
}
@ -101,7 +100,13 @@ public class HeadDB extends SmartPlugin {
instance.localization = new TranslatableLocalization(this, "messages");
try {
instance.localization.createDefaults();
return instance.localization.load();
int count = instance.localization.load();
File langFile = new File(getDataFolder(), "langs.data");
if (langFile.exists()) {
localization.loadLanguages(langFile);
}
return count;
} catch (URISyntaxException | IOException ex) {
instance.logger.error("Failed to load localization!");
ex.printStackTrace();

Datei anzeigen

@ -1,21 +1,17 @@
package tsp.headdb;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.lang.reflect.Method;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@ -26,12 +22,6 @@ import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.stream.Collectors;
import java.util.zip.GZIPOutputStream;
import javax.net.ssl.HttpsURLConnection;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
@SuppressWarnings({"all", "deprecation"}) // Class is from bstats, can't modify it.
class Metrics {

Datei anzeigen

@ -1,7 +1,6 @@
package tsp.headdb.core.api;
import org.bukkit.Bukkit;
import tsp.headdb.HeadDB;
import tsp.headdb.core.storage.PlayerData;
import tsp.headdb.core.util.Utils;
@ -12,14 +11,7 @@ import tsp.headdb.implementation.head.LocalHead;
import tsp.headdb.implementation.requester.HeadProvider;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;
/**

Datei anzeigen

@ -7,7 +7,7 @@ import tsp.headdb.core.api.HeadAPI;
import tsp.headdb.core.util.Utils;
import tsp.headdb.implementation.category.Category;
import tsp.headdb.implementation.head.Head;
import tsp.smartplugin.inventory.PagedPane;
import tsp.nexuslib.inventory.PagedPane;
import java.util.Arrays;
import java.util.List;

Datei anzeigen

@ -1,7 +1,7 @@
package tsp.headdb.core.command;
import org.bukkit.command.CommandSender;
import tsp.smartplugin.player.PlayerUtils;
import tsp.nexuslib.player.PlayerUtils;
public class CommandHelp extends SubCommand {

Datei anzeigen

@ -2,7 +2,7 @@ package tsp.headdb.core.command;
import org.bukkit.command.CommandSender;
import tsp.headdb.HeadDB;
import tsp.smartplugin.player.PlayerUtils;
import tsp.nexuslib.player.PlayerUtils;
public class CommandInfo extends SubCommand {

Datei anzeigen

@ -1,5 +1,6 @@
package tsp.headdb.core.command;
import net.wesjd.anvilgui.AnvilGUI;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.Command;
@ -8,23 +9,20 @@ import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import tsp.headdb.HeadDB;
import tsp.headdb.core.api.HeadAPI;
import tsp.headdb.core.util.Utils;
import tsp.headdb.implementation.category.Category;
import tsp.headdb.implementation.head.Head;
import tsp.headdb.implementation.head.LocalHead;
import tsp.smartplugin.inventory.Button;
import tsp.smartplugin.inventory.PagedPane;
import tsp.smartplugin.inventory.Pane;
import net.wesjd.anvilgui.AnvilGUI;
import tsp.smartplugin.utils.StringUtils;
import tsp.nexuslib.inventory.Button;
import tsp.nexuslib.inventory.PagedPane;
import tsp.nexuslib.inventory.Pane;
import tsp.nexuslib.util.StringUtils;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
@ -192,8 +190,7 @@ public class CommandMain extends HeadDBCommand implements CommandExecutor, TabCo
return new ArrayList<>(sub.get().getCompletions());
}
}
return Collections.singletonList("error"); // for debug purpose, todo: remove
return null;
}
}

Datei anzeigen

@ -5,7 +5,7 @@ import org.bukkit.entity.Player;
import tsp.headdb.core.api.HeadAPI;
import tsp.headdb.core.util.Utils;
import tsp.headdb.implementation.head.Head;
import tsp.smartplugin.inventory.PagedPane;
import tsp.nexuslib.inventory.PagedPane;
import java.util.ArrayList;
import java.util.List;

Datei anzeigen

@ -5,11 +5,11 @@ import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import tsp.headdb.core.util.Utils;
import tsp.smartplugin.builder.item.ItemBuilder;
import tsp.smartplugin.inventory.Button;
import tsp.smartplugin.inventory.PagedPane;
import tsp.smartplugin.inventory.Pane;
import tsp.smartplugin.utils.StringUtils;
import tsp.nexuslib.builder.ItemBuilder;
import tsp.nexuslib.inventory.Button;
import tsp.nexuslib.inventory.PagedPane;
import tsp.nexuslib.inventory.Pane;
import tsp.nexuslib.util.StringUtils;
import java.util.Set;

Datei anzeigen

@ -7,7 +7,7 @@ import net.md_5.bungee.api.chat.hover.content.Text;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import tsp.headdb.core.util.Utils;
import tsp.smartplugin.utils.StringUtils;
import tsp.nexuslib.util.StringUtils;
public class CommandTexture extends SubCommand {

Datei anzeigen

@ -2,8 +2,8 @@ package tsp.headdb.core.command;
import org.bukkit.command.CommandSender;
import tsp.headdb.HeadDB;
import tsp.smartplugin.localization.TranslatableLocalization;
import tsp.smartplugin.utils.Validate;
import tsp.nexuslib.localization.TranslatableLocalization;
import tsp.nexuslib.util.Validate;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;

Datei anzeigen

@ -4,9 +4,4 @@ import java.io.Serializable;
import java.util.Set;
import java.util.UUID;
// Notice that there is no need to add any additional boilerplate in order to make this serializable.
// Specifically, there is no need to add a serialVersionUID field,
// since the serialVersionUID of a record class is 0L unless explicitly declared,
// and the requirement for matching the serialVersionUID value is waived for record classes.
// Source: https://docs.oracle.com/en/java/javase/15/serializable-records/index.html#:~:text=Specifically%2C%20there%20is%20no%20need,is%20waived%20for%20record%20classes.
public record PlayerData(UUID uniqueId, Set<String> favorites) implements Serializable {}

Datei anzeigen

@ -4,13 +4,7 @@ import tsp.headdb.HeadDB;
import tsp.warehouse.storage.file.SerializableFileDataManager;
import java.io.File;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.*;
public class PlayerStorage extends SerializableFileDataManager<HashSet<PlayerData>> {

Datei anzeigen

@ -3,7 +3,7 @@ package tsp.headdb.core.task;
import tsp.headdb.HeadDB;
import tsp.headdb.core.api.HeadAPI;
import tsp.headdb.implementation.head.Head;
import tsp.smartplugin.tasker.Task;
import tsp.nexuslib.task.Task;
import java.util.List;
import java.util.concurrent.TimeUnit;
@ -25,7 +25,7 @@ public class UpdateTask implements Task {
size++;
}
}
HeadDB.getInstance().getLog().debug("Fetched: " + size + " Heads | Provider: " + HeadAPI.getDatabase().getRequester().getProvider().name() + " | Time: " + time + "ms (" + TimeUnit.MILLISECONDS.toSeconds(time) + "s)");
HeadDB.getInstance().getLog().info("Fetched: " + size + " Heads | Provider: " + HeadAPI.getDatabase().getRequester().getProvider().name() + " | Time: " + time + "ms (" + TimeUnit.MILLISECONDS.toSeconds(time) + "s)");
});
HeadDB.getInstance().getStorage().getPlayerStorage().backup();
HeadDB.getInstance().getLog().debug("UpdateTask finished!");

Datei anzeigen

@ -1,7 +1,7 @@
package tsp.headdb.core.util;
import org.bukkit.Bukkit;
import tsp.smartplugin.utils.StringUtils;
import tsp.nexuslib.util.StringUtils;
@SuppressWarnings("unused")
public class HeadDBLogger {

Datei anzeigen

@ -16,23 +16,18 @@ import tsp.headdb.core.economy.BasicEconomyProvider;
import tsp.headdb.core.hook.Hooks;
import tsp.headdb.implementation.category.Category;
import tsp.headdb.implementation.head.Head;
import tsp.smartplugin.inventory.Button;
import tsp.smartplugin.inventory.PagedPane;
import tsp.smartplugin.inventory.Pane;
import tsp.smartplugin.utils.StringUtils;
import tsp.smartplugin.utils.Validate;
import tsp.nexuslib.inventory.Button;
import tsp.nexuslib.inventory.PagedPane;
import tsp.nexuslib.inventory.Pane;
import tsp.nexuslib.util.StringUtils;
import tsp.nexuslib.util.Validate;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.CompletableFuture;
public class Utils {
@ -131,7 +126,7 @@ public class Utils {
Utils.purchase(player, head, amount);
} else if (fe.isRightClick()) {
HeadDB.getInstance().getStorage().getPlayerStorage().removeFavorite(player.getUniqueId(), head.getTexture());
HeadDB.getInstance().getLocalization().sendMessage(player, "removedFavorites");
HeadDB.getInstance().getLocalization().sendMessage(player, "removedFavorite");
openFavoritesMenu(player);
}
}));
@ -162,7 +157,7 @@ public class Utils {
} else if (e.isRightClick()) {
if (player.hasPermission("headdb.favorites")) {
HeadDB.getInstance().getStorage().getPlayerStorage().addFavorite(player.getUniqueId(), head.getTexture());
HeadDB.getInstance().getLocalization().sendMessage(player, "addedFavorites");
HeadDB.getInstance().getLocalization().sendMessage(player, "addedFavorite");
} else {
HeadDB.getInstance().getLocalization().sendMessage(player, "noAccessFavorites");
}

Datei anzeigen

@ -6,8 +6,8 @@ import org.bukkit.inventory.meta.ItemMeta;
import tsp.headdb.HeadDB;
import tsp.headdb.core.api.HeadAPI;
import tsp.headdb.core.util.Utils;
import tsp.smartplugin.builder.item.ItemBuilder;
import tsp.smartplugin.utils.StringUtils;
import tsp.nexuslib.builder.ItemBuilder;
import tsp.nexuslib.util.StringUtils;
import javax.annotation.Nonnull;
import java.util.Locale;

Datei anzeigen

@ -7,9 +7,9 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import tsp.headdb.HeadDB;
import tsp.headdb.implementation.category.Category;
import tsp.smartplugin.builder.item.ItemBuilder;
import tsp.smartplugin.localization.TranslatableLocalization;
import tsp.smartplugin.utils.Validate;
import tsp.nexuslib.builder.ItemBuilder;
import tsp.nexuslib.localization.TranslatableLocalization;
import tsp.nexuslib.util.Validate;
import javax.annotation.ParametersAreNonnullByDefault;
import java.lang.reflect.Field;

Datei anzeigen

@ -1,15 +1,14 @@
package tsp.headdb.implementation.requester;
import org.bukkit.plugin.java.JavaPlugin;
import tsp.headdb.HeadDB;
import tsp.headdb.core.util.Utils;
import tsp.headdb.implementation.category.Category;
import tsp.headdb.implementation.head.Head;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.bukkit.plugin.java.JavaPlugin;
import tsp.headdb.HeadDB;
import tsp.headdb.core.util.Utils;
import tsp.headdb.implementation.category.Category;
import tsp.headdb.implementation.head.Head;
import java.io.BufferedReader;
import java.io.IOException;
@ -43,8 +42,18 @@ public class Requester {
JsonArray main = JsonParser.parseString(response.response()).getAsJsonArray();
for (JsonElement entry : main) {
JsonObject obj = entry.getAsJsonObject();
int id = obj.get("id").getAsInt();
if (plugin.getConfig().contains("blockedHeads.ids")) {
List<Integer> blockedIds = plugin.getConfig().getIntegerList("blockedHeads.ids");
if (blockedIds.contains(id)) {
HeadDB.getInstance().getLog().debug("Skipped blocked head: " + obj.get("name").getAsString() + "(" + id + ")");
continue;
}
}
result.add(new Head(
obj.get("id").getAsInt(),
id,
Utils.validateUniqueId(obj.get("uuid").getAsString()).orElse(UUID.randomUUID()),
obj.get("name").getAsString(),
obj.get("value").getAsString(),

Datei anzeigen

@ -84,6 +84,12 @@ fallback: true
# Shows more plugin information. (/hdb info)
showAdvancedPluginInfo: true
# Block heads from all database instances.
blockedHeads:
# List of head ids to block
ids:
- -1
# Storage Options
storage:
# Amount of threads in the executor pool used for storage.