geforkt von Mirrors/HeadDB
update task, documentation
Dieser Commit ist enthalten in:
Ursprung
5a9fb56953
Commit
3b1649dc63
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
||||
target/
|
||||
.idea/
|
||||
src/test/
|
||||
|
||||
dependency-reduced-pom.xml
|
||||
|
||||
|
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>tsp.headdb</groupId>
|
||||
<artifactId>HeadDB</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.0.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>HeadDB</name>
|
||||
|
@ -6,6 +6,7 @@ import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import tsp.headdb.api.HeadAPI;
|
||||
import tsp.headdb.command.CommandHeadDB;
|
||||
import tsp.headdb.database.DatabaseUpdateTask;
|
||||
import tsp.headdb.listener.JoinListener;
|
||||
import tsp.headdb.listener.MenuListener;
|
||||
import tsp.headdb.listener.PagedPaneListener;
|
||||
@ -13,6 +14,8 @@ import tsp.headdb.storage.PlayerDataFile;
|
||||
import tsp.headdb.util.Log;
|
||||
import tsp.headdb.util.Metrics;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class HeadDB extends JavaPlugin {
|
||||
|
||||
private static HeadDB instance;
|
||||
@ -39,10 +42,9 @@ public class HeadDB extends JavaPlugin {
|
||||
}
|
||||
|
||||
long refresh = getConfig().getLong("refresh") * 20;
|
||||
HeadAPI.getDatabase().updateAsync(heads -> Log.info("Fetched " + HeadAPI.getHeads().size() + " heads!")); // Update database on startup
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(this, new DatabaseUpdateTask(), refresh, refresh); // Update database on set interval (also saves data)
|
||||
HeadAPI.getDatabase().setRefresh(refresh);
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(this, task ->
|
||||
HeadAPI.getDatabase().updateAsync(heads -> Log.info("Fetched " + HeadAPI.getHeads().size() + " heads!")),
|
||||
0L, refresh);
|
||||
|
||||
new JoinListener(this);
|
||||
new MenuListener(this);
|
||||
@ -69,6 +71,7 @@ public class HeadDB extends JavaPlugin {
|
||||
return this.economy = economyProvider.getProvider();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Economy getEconomy() {
|
||||
return economy;
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import tsp.headdb.database.HeadDatabase;
|
||||
import tsp.headdb.inventory.InventoryUtils;
|
||||
import tsp.headdb.storage.PlayerDataFile;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -20,10 +21,14 @@ import java.util.UUID;
|
||||
*
|
||||
* @author TheSilentPro
|
||||
*/
|
||||
// TODO: Possibly change to singleton class
|
||||
public final class HeadAPI {
|
||||
|
||||
private HeadAPI() {}
|
||||
|
||||
/**
|
||||
* Main {@link HeadDatabase} that he HeadDB plugin uses.
|
||||
*/
|
||||
private static final HeadDatabase database = new HeadDatabase(HeadDB.getInstance());
|
||||
|
||||
/**
|
||||
@ -64,6 +69,12 @@ public final class HeadAPI {
|
||||
InventoryUtils.openSearchDatabase(player, search);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the database with results of a specific tag search term
|
||||
*
|
||||
* @param player Target player
|
||||
* @param tag Tag search term
|
||||
*/
|
||||
public static void openTagSearchDatabase(Player player, String tag) {
|
||||
InventoryUtils.openTagSearchDatabase(player, tag);
|
||||
}
|
||||
@ -90,6 +101,13 @@ public final class HeadAPI {
|
||||
return database.getHeadByUniqueId(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a {@link List} of {@link Head}'s by their tag
|
||||
*
|
||||
* @param tag The tag
|
||||
* @return List of heads
|
||||
*/
|
||||
@Nonnull
|
||||
public static List<Head> getHeadsByTag(String tag) {
|
||||
return database.getHeadsByTag(tag);
|
||||
}
|
||||
@ -100,6 +118,7 @@ public final class HeadAPI {
|
||||
* @param name The name to match for
|
||||
* @return List of heads
|
||||
*/
|
||||
@Nonnull
|
||||
public static List<Head> getHeadsByName(String name) {
|
||||
return database.getHeadsByName(name);
|
||||
}
|
||||
@ -111,6 +130,7 @@ public final class HeadAPI {
|
||||
* @param name The name to match for
|
||||
* @return List of heads
|
||||
*/
|
||||
@Nonnull
|
||||
public static List<Head> getHeadsByName(Category category, String name) {
|
||||
return database.getHeadsByName(category, name);
|
||||
}
|
||||
@ -132,6 +152,7 @@ public final class HeadAPI {
|
||||
* @param category The category to search in
|
||||
* @return List of heads
|
||||
*/
|
||||
@Nonnull
|
||||
public static List<Head> getHeads(Category category) {
|
||||
return database.getHeads(category);
|
||||
}
|
||||
@ -141,18 +162,38 @@ public final class HeadAPI {
|
||||
*
|
||||
* @return List of all heads
|
||||
*/
|
||||
@Nonnull
|
||||
public static List<Head> getHeads() {
|
||||
return database.getHeads();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a favorite {@link Head} to the player
|
||||
*
|
||||
* @param uuid The player's unique id
|
||||
* @param textureValue The head's texture value
|
||||
*/
|
||||
public static void addFavoriteHead(UUID uuid, String textureValue) {
|
||||
HeadDB.getInstance().getPlayerData().modifyFavorite(uuid, textureValue, PlayerDataFile.ModificationType.SET);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a favorite {@link Head} from the player
|
||||
*
|
||||
* @param uuid The player's unique id
|
||||
* @param textureValue The head's texture value
|
||||
*/
|
||||
public static void removeFavoriteHead(UUID uuid, String textureValue) {
|
||||
HeadDB.getInstance().getPlayerData().modifyFavorite(uuid, textureValue, PlayerDataFile.ModificationType.REMOVE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve a {@link List} of favorite {@link Head}'s for the player
|
||||
*
|
||||
* @param uuid The player's unique id
|
||||
* @return List of favorite {@link Head}'s for the player
|
||||
*/
|
||||
@Nonnull
|
||||
public static List<Head> getFavoriteHeads(UUID uuid) {
|
||||
List<Head> result = new ArrayList<>();
|
||||
|
||||
@ -164,6 +205,14 @@ public final class HeadAPI {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a list of {@link LocalHead}'s.
|
||||
* These are heads from players that have joined the server at least once.
|
||||
* Requires config option localHeads = true
|
||||
*
|
||||
* @return List of {@link LocalHead}'s
|
||||
*/
|
||||
@Nonnull
|
||||
public static List<LocalHead> getLocalHeads() {
|
||||
List<LocalHead> result = new ArrayList<>();
|
||||
for (String entry : HeadDB.getInstance().getPlayerData().getEntries()) {
|
||||
|
15
src/main/java/tsp/headdb/database/DatabaseUpdateTask.java
Normale Datei
15
src/main/java/tsp/headdb/database/DatabaseUpdateTask.java
Normale Datei
@ -0,0 +1,15 @@
|
||||
package tsp.headdb.database;
|
||||
|
||||
import tsp.headdb.HeadDB;
|
||||
import tsp.headdb.api.HeadAPI;
|
||||
import tsp.headdb.util.Log;
|
||||
|
||||
public class DatabaseUpdateTask implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
HeadDB.getInstance().getPlayerData().save();
|
||||
HeadAPI.getDatabase().updateAsync(heads -> Log.info("Fetched " + HeadAPI.getHeads().size() + " heads!"));
|
||||
}
|
||||
|
||||
}
|
@ -23,6 +23,10 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Class for handling the "dirty" work
|
||||
* such as inventories and economy.
|
||||
*/
|
||||
public class InventoryUtils {
|
||||
|
||||
private static final Map<String, Integer> uiLocation = new HashMap<>();
|
||||
|
@ -44,7 +44,6 @@ public class MenuListener implements Listener {
|
||||
player.closeInventory();
|
||||
return;
|
||||
}
|
||||
player.sendMessage("Clicked on favorites!");
|
||||
InventoryUtils.openFavoritesMenu(player);
|
||||
return;
|
||||
}
|
||||
|
@ -42,7 +42,6 @@ public class PlayerDataFile {
|
||||
JsonArray favorites = main.get(uuid.toString()).getAsJsonObject().get("favorites").getAsJsonArray();
|
||||
for (int i = 0; i < favorites.size(); i++) {
|
||||
String str = favorites.get(i).toString();
|
||||
Log.debug("str: " + str.substring(1, str.length() - 1));
|
||||
result.add(str.substring(1, str.length() - 1));
|
||||
}
|
||||
}
|
||||
@ -135,12 +134,6 @@ public class PlayerDataFile {
|
||||
return file;
|
||||
}
|
||||
|
||||
public void validateFile() {
|
||||
if (!file.exists()) {
|
||||
HeadDB.getInstance().saveResource(file.getName(), false);
|
||||
}
|
||||
}
|
||||
|
||||
public enum ModificationType {
|
||||
SET,
|
||||
REMOVE;
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren