3
0
Mirror von https://github.com/TheSilentPro/HeadDB.git synchronisiert 2024-12-27 11:20:05 +01:00

documentation, refactoring

Dieser Commit ist enthalten in:
Silent 2022-02-27 00:04:32 +01:00
Ursprung c551871f2e
Commit 87d1ff3a18
14 geänderte Dateien mit 90 neuen und 18 gelöschten Zeilen

Datei anzeigen

@ -20,6 +20,9 @@ import tsp.headdb.util.Utils;
import javax.annotation.Nullable;
import java.io.File;
/**
* Main class of HeadDB
*/
public class HeadDB extends JavaPlugin {
private static HeadDB instance;

Datei anzeigen

@ -1,5 +1,6 @@
package tsp.headdb.api;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
@ -47,7 +48,9 @@ public final class HeadAPI {
*
* @param player Target player
*/
public static void openDatabase(Player player) {
public static void openDatabase(@Nonnull Player player) {
Validate.notNull(player, "Player can not be null!");
InventoryUtils.openDatabase(player);
}
@ -57,7 +60,10 @@ public final class HeadAPI {
* @param player Target player
* @param category Category to open
*/
public static void openCategoryDatabase(Player player, Category category) {
public static void openCategoryDatabase(@Nonnull Player player, @Nonnull Category category) {
Validate.notNull(player, "Player can not be null!");
Validate.notNull(category, "Category can not be null!");
InventoryUtils.openCategoryDatabase(player, category);
}
@ -67,7 +73,10 @@ public final class HeadAPI {
* @param player Target player
* @param search Search term
*/
public static void openSearchDatabase(Player player, String search) {
public static void openSearchDatabase(@Nonnull Player player, @Nonnull String search) {
Validate.notNull(player, "Player can not be null!");
Validate.notNull(search, "Search can not be null!");
InventoryUtils.openSearchDatabase(player, search);
}
@ -77,7 +86,10 @@ public final class HeadAPI {
* @param player Target player
* @param tag Tag search term
*/
public static void openTagSearchDatabase(Player player, String tag) {
public static void openTagSearchDatabase(@Nonnull Player player, @Nonnull String tag) {
Validate.notNull(player, "Player can not be null!");
Validate.notNull(tag, "Tag can not be null!");
InventoryUtils.openTagSearchDatabase(player, tag);
}
@ -99,7 +111,9 @@ public final class HeadAPI {
* @return The head
*/
@Nullable
public static Head getHeadByUniqueId(UUID uuid) {
public static Head getHeadByUniqueId(@Nonnull UUID uuid) {
Validate.notNull(uuid, "UUID can not be null!");
return database.getHeadByUniqueId(uuid);
}
@ -110,7 +124,9 @@ public final class HeadAPI {
* @return List of heads
*/
@Nonnull
public static List<Head> getHeadsByTag(String tag) {
public static List<Head> getHeadsByTag(@Nonnull String tag) {
Validate.notNull(tag, "Tag can not be null!");
return database.getHeadsByTag(tag);
}
@ -121,7 +137,9 @@ public final class HeadAPI {
* @return List of heads
*/
@Nonnull
public static List<Head> getHeadsByName(String name) {
public static List<Head> getHeadsByName(@Nonnull String name) {
Validate.notNull(name, "Name can not be null!");
return database.getHeadsByName(name);
}
@ -133,7 +151,10 @@ public final class HeadAPI {
* @return List of heads
*/
@Nonnull
public static List<Head> getHeadsByName(Category category, String name) {
public static List<Head> getHeadsByName(@Nonnull Category category, @Nonnull String name) {
Validate.notNull(category, "Category can not be null!");
Validate.notNull(name, "Name can not be null!");
return database.getHeadsByName(category, name);
}
@ -144,7 +165,9 @@ public final class HeadAPI {
* @return The head
*/
@Nullable
public static Head getHeadByValue(String value) {
public static Head getHeadByValue(@Nonnull String value) {
Validate.notNull(value, "Value can not be null!");
return database.getHeadByValue(value);
}
@ -155,7 +178,9 @@ public final class HeadAPI {
* @return List of heads
*/
@Nonnull
public static List<Head> getHeads(Category category) {
public static List<Head> getHeads(@Nonnull Category category) {
Validate.notNull(category, "Category can not be null!");
return database.getHeads(category);
}
@ -175,7 +200,10 @@ public final class HeadAPI {
* @param uuid The player's unique id
* @param textureValue The head's texture value
*/
public static void addFavoriteHead(UUID uuid, String textureValue) {
public static void addFavoriteHead(@Nonnull UUID uuid, @Nonnull String textureValue) {
Validate.notNull(uuid, "UUID can not be null!");
Validate.notNull(textureValue, "Value can not be null!");
HeadDB.getInstance().getPlayerData().modifyFavorite(uuid, textureValue, PlayerDataFile.ModificationType.SET);
}
@ -185,7 +213,10 @@ public final class HeadAPI {
* @param uuid The player's unique id
* @param textureValue The head's texture value
*/
public static void removeFavoriteHead(UUID uuid, String textureValue) {
public static void removeFavoriteHead(@Nonnull UUID uuid, @Nonnull String textureValue) {
Validate.notNull(uuid, "UUID can not be null!");
Validate.notNull(textureValue, "Value can not be null!");
HeadDB.getInstance().getPlayerData().modifyFavorite(uuid, textureValue, PlayerDataFile.ModificationType.REMOVE);
}
@ -196,9 +227,12 @@ public final class HeadAPI {
* @return List of favorite {@link Head}'s for the player
*/
@Nonnull
public static List<Head> getFavoriteHeads(UUID uuid) {
public static List<Head> getFavoriteHeads(@Nonnull UUID uuid) {
Validate.notNull(uuid, "UUID can not be null!");
return HeadDB.getInstance().getPlayerData().getFavoriteHeadsByTexture(uuid).stream()
.map(HeadAPI::getHeadByValue)
.filter(head -> head != null)
.collect(Collectors.toList());
}

Datei anzeigen

@ -21,6 +21,7 @@ public class PlayerHeadPurchaseEvent extends Event implements Cancellable {
private double cost;
public PlayerHeadPurchaseEvent(Player player, Head head, double cost) {
super(true);
this.player = player;
this.head = head;
this.cost = cost;

Datei anzeigen

@ -26,6 +26,7 @@ import java.util.function.Consumer;
public class TreasuryProvider implements BasicEconomyProvider {
private EconomyProvider provider;
private EconomyTransactionInitiator<?> transactionInitiator;
private Currency currency;
@Override
@ -58,7 +59,7 @@ public class TreasuryProvider implements BasicEconomyProvider {
}).whenComplete((account, ex) -> {
account.withdrawBalance(
amount,
EconomyTransactionInitiator.createInitiator(EconomyTransactionInitiator.Type.PLUGIN, "HeadDB"),
transactionInitiator,
currency,
new EconomySubscriber<BigDecimal>() {
@Override
@ -85,6 +86,7 @@ public class TreasuryProvider implements BasicEconomyProvider {
}
provider = service.get().get();
transactionInitiator = EconomyTransactionInitiator.createInitiator(EconomyTransactionInitiator.Type.PLUGIN, "HeadDB");
String rawCurrency = HeadDB.getInstance().getConfig().getString("economy.currency");
if (rawCurrency == null || rawCurrency.isEmpty()) {

Datei anzeigen

@ -8,6 +8,11 @@ import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
/**
* Represents a category for heads
*
* @author TheSilentPro
*/
public enum Category {
ALPHABET("alphabet", ChatColor.YELLOW, 20),

Datei anzeigen

@ -4,6 +4,9 @@ import tsp.headdb.HeadDB;
import tsp.headdb.api.HeadAPI;
import tsp.headdb.util.Log;
/**
* Task that updates the database on an interval
*/
public class DatabaseUpdateTask implements Runnable {
@Override

Datei anzeigen

@ -14,6 +14,11 @@ import java.util.Arrays;
import java.util.List;
import java.util.UUID;
/**
* Represents a Head that a player can obtain via the database
*
* @author TheSilentPro
*/
public class Head {
private String name;

Datei anzeigen

@ -11,6 +11,11 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* Represents a local player head that can be obtained via the LocalHeads option
*
* @author TheSilentPro
*/
public class LocalHead extends Head {
private UUID uuid;

Datei anzeigen

@ -351,7 +351,7 @@ public class InventoryUtils {
}
public static void purchaseHead(Player player, Head head, int amount, String category, String description) {
Utils.sendMessage(player, "&7Purchasing &e" + amount + "x " + head.getName() + "&7. Please wait...");
Utils.sendMessage(player, String.format(localization.getMessage("processPayment"), amount, head.getName()));
processPayment(player, amount, category, description, result -> {
if (result) {
PlayerHeadPurchaseEvent event = new PlayerHeadPurchaseEvent(player, head, getCategoryCost(player, category));

Datei anzeigen

@ -6,6 +6,10 @@ import org.bukkit.event.player.PlayerJoinEvent;
import tsp.headdb.HeadDB;
import tsp.headdb.storage.PlayerDataFile;
/**
* This saves heads from players that join
* Used for local heads option
*/
public class JoinListener implements Listener {
public JoinListener(HeadDB plugin) {

Datei anzeigen

@ -16,6 +16,9 @@ import tsp.headdb.implementation.Category;
import tsp.headdb.inventory.InventoryUtils;
import tsp.headdb.util.Utils;
/**
* This handles all clicks on the main inventory
*/
public class MenuListener implements Listener {
public MenuListener(JavaPlugin plugin) {

Datei anzeigen

@ -19,6 +19,9 @@ import java.util.List;
import java.util.Set;
import java.util.UUID;
/**
* Manages the data file that stores information
*/
public class PlayerDataFile {
private final File file;

Datei anzeigen

@ -18,6 +18,9 @@ import java.net.URLConnection;
import java.util.function.Consumer;
import java.util.regex.Pattern;
/**
* Several utilities used by the plugin
*/
public class Utils {
private static final FileConfiguration config = HeadDB.getInstance().getConfig();

Datei anzeigen

@ -4,9 +4,10 @@ databaseOpen: "&7Opening &cHead Database"
invalidPlayer: "&cPlayer is not online!"
localFavorites: "&cLocal heads can not be added to favorites!"
noEconomy: "&7You received &e%d &7x &e%s&7!"
purchasedHead: "&7You purchased &e%d &7x &e%s &7for &e%.2f&7!"
notEnoughMoney: "&cYou do not have enough to purchase &e%d &cx &e%s&7."
free: "&7You received &e%d &7x &e%s &7for &efree&7!"
purchasedHead: "&7You purchased &e%dx %s &7for &e%.2f&7!"
proccessPayment: "&7Purchasing &e%dx %s&7. Please wait..."
notEnoughMoney: "&cYou do not have enough to purchase &e%dx %s&c."
free: "&7You received &e%dx %s &7for &efree&7!"
reloadMessages: "&aReloaded messages file!"
menu: