geforkt von Mirrors/HeadDB
minor changes
Dieser Commit ist enthalten in:
Ursprung
9cb2fb0fd2
Commit
47afd36dd7
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>tsp.headdb</groupId>
|
||||
<artifactId>HeadDB</artifactId>
|
||||
<version>4.0.0</version>
|
||||
<version>4.1.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>HeadDB</name>
|
||||
|
|
|
@ -5,6 +5,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||
import tsp.headdb.api.HeadAPI;
|
||||
import tsp.headdb.command.HeadDBCommand;
|
||||
import tsp.headdb.economy.TreasuryProvider;
|
||||
import tsp.headdb.implementation.DataSaveTask;
|
||||
import tsp.headdb.implementation.DatabaseUpdateTask;
|
||||
import tsp.headdb.economy.BasicEconomyProvider;
|
||||
import tsp.headdb.economy.VaultProvider;
|
||||
|
@ -14,7 +15,6 @@ import tsp.headdb.listener.PagedPaneListener;
|
|||
import tsp.headdb.storage.PlayerDataFile;
|
||||
import tsp.headdb.util.Localization;
|
||||
import tsp.headdb.util.Log;
|
||||
import tsp.headdb.util.Metrics;
|
||||
import tsp.headdb.util.Utils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -53,9 +53,9 @@ public class HeadDB extends JavaPlugin {
|
|||
}
|
||||
|
||||
long refresh = getConfig().getLong("refresh") * 20;
|
||||
HeadAPI.getDatabase().update(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, new DatabaseUpdateTask(), 0, refresh);
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(this, new DataSaveTask(), refresh, refresh);
|
||||
|
||||
new JoinListener(this);
|
||||
new MenuListener(this);
|
||||
|
@ -64,7 +64,7 @@ public class HeadDB extends JavaPlugin {
|
|||
getCommand("headdb").setExecutor(new HeadDBCommand());
|
||||
|
||||
Log.debug("Starting metrics...");
|
||||
new Metrics(this, 9152);
|
||||
initMetrics();
|
||||
|
||||
Utils.isLatestVersion(this, 84967, latest -> {
|
||||
if (!latest) {
|
||||
|
@ -78,6 +78,7 @@ public class HeadDB extends JavaPlugin {
|
|||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
Bukkit.getScheduler().cancelTasks(this);
|
||||
this.playerData.save();
|
||||
}
|
||||
|
||||
|
@ -109,5 +110,21 @@ public class HeadDB extends JavaPlugin {
|
|||
this.localization.load();
|
||||
}
|
||||
|
||||
private void initMetrics() {
|
||||
Metrics metrics = new Metrics(this, 9152);
|
||||
if (!metrics.isEnabled()) {
|
||||
Log.debug("Metrics are disabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
metrics.addCustomChart(new Metrics.SimplePie("economy_provider", () -> {
|
||||
if (this.getEconomyProvider() != null) {
|
||||
return this.getConfig().getString("economy.provider");
|
||||
}
|
||||
|
||||
return "None";
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package tsp.headdb.util;
|
||||
package tsp.headdb;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
@ -28,7 +28,7 @@ import java.util.zip.GZIPOutputStream;
|
|||
* Check out https://bStats.org/ to learn more about bStats!
|
||||
*/
|
||||
@SuppressWarnings({"WeakerAccess", "unused"})
|
||||
public class Metrics {
|
||||
class Metrics {
|
||||
|
||||
static {
|
||||
// You can use the property to disable the check in your test environment
|
11
src/main/java/tsp/headdb/implementation/DataSaveTask.java
Normale Datei
11
src/main/java/tsp/headdb/implementation/DataSaveTask.java
Normale Datei
|
@ -0,0 +1,11 @@
|
|||
package tsp.headdb.implementation;
|
||||
|
||||
import tsp.headdb.HeadDB;
|
||||
|
||||
public class DataSaveTask implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
HeadDB.getInstance().getPlayerData().save();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package tsp.headdb.implementation;
|
||||
|
||||
import tsp.headdb.HeadDB;
|
||||
import tsp.headdb.api.HeadAPI;
|
||||
import tsp.headdb.util.Log;
|
||||
|
||||
|
@ -11,7 +10,6 @@ public class DatabaseUpdateTask implements Runnable {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
HeadDB.getInstance().getPlayerData().save();
|
||||
HeadAPI.getDatabase().update(heads -> Log.info("Fetched " + HeadAPI.getHeads().size() + " heads!"));
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.util.Map;
|
|||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
|
@ -116,8 +117,9 @@ public class HeadDatabase {
|
|||
return result;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public List<Head> getHeads(Category category) {
|
||||
return Collections.unmodifiableList(HEADS.get(category));
|
||||
return HEADS.get(category) != null ? Collections.unmodifiableList(HEADS.get(category)) : new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -127,20 +129,9 @@ public class HeadDatabase {
|
|||
*/
|
||||
@Nonnull
|
||||
public List<Head> getHeads() {
|
||||
if (HEADS.isEmpty() || isLastUpdateOld()) {
|
||||
// Technically this should never be reached due to the update task in the main class.
|
||||
update(result -> {
|
||||
if (result != null) {
|
||||
for (Category category : result.keySet()) {
|
||||
HEADS.put(category, result.get(category));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
List<Head> heads = new ArrayList<>();
|
||||
for (Category category : HEADS.keySet()) {
|
||||
heads.addAll(HEADS.get(category));
|
||||
heads.addAll(getHeads(category));
|
||||
}
|
||||
return heads;
|
||||
}
|
||||
|
|
|
@ -122,11 +122,17 @@ public class PlayerDataFile {
|
|||
}
|
||||
|
||||
public void save() {
|
||||
if (main == null) {
|
||||
Log.debug("No data to save! Skipping...");
|
||||
return;
|
||||
}
|
||||
|
||||
FileWriter writer;
|
||||
try {
|
||||
writer = new FileWriter(file);
|
||||
writer.write(main.toString());
|
||||
writer.close();
|
||||
Log.debug("Saved data to " + file.getName());
|
||||
} catch (IOException e) {
|
||||
Log.error("Failed to save player_data.json contents!");
|
||||
Log.error(e);
|
||||
|
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren