mirror of
https://github.com/WiIIiam278/HuskSync.git
synced 2026-01-04 15:31:37 +00:00
Flesh out Plan extension
This commit is contained in:
@@ -2,12 +2,15 @@ package net.william278.husksync.hook;
|
||||
|
||||
import com.djrapitops.plan.extension.CallEvents;
|
||||
import com.djrapitops.plan.extension.DataExtension;
|
||||
import com.djrapitops.plan.extension.ElementOrder;
|
||||
import com.djrapitops.plan.extension.FormatType;
|
||||
import com.djrapitops.plan.extension.annotation.NumberProvider;
|
||||
import com.djrapitops.plan.extension.annotation.PluginInfo;
|
||||
import com.djrapitops.plan.extension.annotation.StringProvider;
|
||||
import com.djrapitops.plan.extension.annotation.*;
|
||||
import com.djrapitops.plan.extension.icon.Color;
|
||||
import com.djrapitops.plan.extension.icon.Family;
|
||||
import com.djrapitops.plan.extension.icon.Icon;
|
||||
import com.djrapitops.plan.extension.table.Table;
|
||||
import com.djrapitops.plan.extension.table.TableColumnFormat;
|
||||
import net.william278.husksync.data.StatusData;
|
||||
import net.william278.husksync.data.UserDataSnapshot;
|
||||
import net.william278.husksync.database.Database;
|
||||
import net.william278.husksync.player.User;
|
||||
@@ -19,12 +22,26 @@ import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@TabInfo(
|
||||
tab = "Current Status",
|
||||
iconName = "id-card",
|
||||
iconFamily = Family.SOLID,
|
||||
elementOrder = {ElementOrder.VALUES, ElementOrder.TABLE, ElementOrder.GRAPH}
|
||||
)
|
||||
@TabInfo(
|
||||
tab = "Data Snapshots",
|
||||
iconName = "clipboard-list",
|
||||
iconFamily = Family.SOLID,
|
||||
elementOrder = {ElementOrder.VALUES, ElementOrder.TABLE, ElementOrder.GRAPH}
|
||||
)
|
||||
@TabOrder({"Current Status", "Data Snapshots"})
|
||||
@PluginInfo(
|
||||
name = "HuskSync",
|
||||
iconName = "cube",
|
||||
iconName = "exchange-alt",
|
||||
iconFamily = Family.SOLID,
|
||||
color = Color.NONE
|
||||
color = Color.LIGHT_BLUE
|
||||
)
|
||||
@SuppressWarnings("unused")
|
||||
public class PlanDataExtension implements DataExtension {
|
||||
|
||||
private Database database;
|
||||
@@ -57,27 +74,44 @@ public class PlanDataExtension implements DataExtension {
|
||||
});
|
||||
}
|
||||
|
||||
@BooleanProvider(
|
||||
text = "Has Synced",
|
||||
description = "Whether this user has saved, synchronised data.",
|
||||
iconName = "exchange-alt",
|
||||
iconFamily = Family.SOLID,
|
||||
conditionName = "hasSynced",
|
||||
hidden = true
|
||||
)
|
||||
@Tab("Current Status")
|
||||
public boolean getUserHasSynced(@NotNull UUID uuid) {
|
||||
return getCurrentUserData(uuid).join().isPresent();
|
||||
}
|
||||
|
||||
@Conditional("hasSynced")
|
||||
@NumberProvider(
|
||||
text = "Sync Time",
|
||||
description = "The last time the user had their data synced with the server.",
|
||||
iconName = "clock",
|
||||
iconFamily = Family.SOLID,
|
||||
format = FormatType.DATE_SECOND,
|
||||
priority = 1
|
||||
priority = 6
|
||||
)
|
||||
@Tab("Current Status")
|
||||
public long getCurrentDataTimestamp(@NotNull UUID uuid) {
|
||||
return getCurrentUserData(uuid).join().map(
|
||||
versionedUserData -> versionedUserData.versionTimestamp().getTime())
|
||||
.orElse(new Date().getTime());
|
||||
}
|
||||
|
||||
@Conditional("hasSynced")
|
||||
@StringProvider(
|
||||
text = "Version ID",
|
||||
description = "ID of the data version that the user is currently using.",
|
||||
iconName = "bolt",
|
||||
iconFamily = Family.SOLID,
|
||||
priority = 2
|
||||
priority = 5
|
||||
)
|
||||
@Tab("Current Status")
|
||||
public String getCurrentDataId(@NotNull UUID uuid) {
|
||||
return getCurrentUserData(uuid).join().map(
|
||||
versionedUserData -> versionedUserData.versionUUID().toString()
|
||||
@@ -85,16 +119,100 @@ public class PlanDataExtension implements DataExtension {
|
||||
.orElse(UNKNOWN_STRING);
|
||||
}
|
||||
|
||||
@Conditional("hasSynced")
|
||||
@StringProvider(
|
||||
text = "Health",
|
||||
description = "The number of health points out of the max health points this player currently has.",
|
||||
iconName = "heart",
|
||||
iconFamily = Family.SOLID,
|
||||
priority = 4
|
||||
)
|
||||
@Tab("Current Status")
|
||||
public String getHealth(@NotNull UUID uuid) {
|
||||
return getCurrentUserData(uuid).join().map(
|
||||
versionedUserData -> {
|
||||
final StatusData statusData = versionedUserData.userData().getStatusData();
|
||||
return (int) statusData.health + "/" + (int) statusData.maxHealth;
|
||||
})
|
||||
.orElse(UNKNOWN_STRING);
|
||||
}
|
||||
|
||||
@Conditional("hasSynced")
|
||||
@NumberProvider(
|
||||
text = "Advancements",
|
||||
description = "The number of advancements & recipes the player has progressed in",
|
||||
iconName = "award",
|
||||
text = "Hunger",
|
||||
description = "The number of hunger points this player currently has.",
|
||||
iconName = "drumstick-bite",
|
||||
iconFamily = Family.SOLID,
|
||||
priority = 3
|
||||
)
|
||||
@Tab("Current Status")
|
||||
public long getHunger(@NotNull UUID uuid) {
|
||||
return getCurrentUserData(uuid).join().map(
|
||||
versionedUserData -> (long) versionedUserData.userData().getStatusData().hunger)
|
||||
.orElse(0L);
|
||||
}
|
||||
|
||||
@Conditional("hasSynced")
|
||||
@NumberProvider(
|
||||
text = "Experience Level",
|
||||
description = "The number of experience levels this player currently has.",
|
||||
iconName = "hat-wizard",
|
||||
iconFamily = Family.SOLID,
|
||||
priority = 2
|
||||
)
|
||||
@Tab("Current Status")
|
||||
public long getExperienceLevel(@NotNull UUID uuid) {
|
||||
return getCurrentUserData(uuid).join().map(
|
||||
versionedUserData -> (long) versionedUserData.userData().getStatusData().expLevel)
|
||||
.orElse(0L);
|
||||
}
|
||||
|
||||
@Conditional("hasSynced")
|
||||
@StringProvider(
|
||||
text = "Game Mode",
|
||||
description = "The game mode this player is currently in.",
|
||||
iconName = "gamepad",
|
||||
iconFamily = Family.SOLID,
|
||||
priority = 1
|
||||
)
|
||||
@Tab("Current Status")
|
||||
public String getGameMode(@NotNull UUID uuid) {
|
||||
return getCurrentUserData(uuid).join().map(
|
||||
versionedUserData -> versionedUserData.userData().getStatusData().gameMode.toLowerCase())
|
||||
.orElse(UNKNOWN_STRING);
|
||||
}
|
||||
|
||||
@Conditional("hasSynced")
|
||||
@NumberProvider(
|
||||
text = "Advancements",
|
||||
description = "The number of advancements & recipes the player has progressed in.",
|
||||
iconName = "award",
|
||||
iconFamily = Family.SOLID
|
||||
)
|
||||
@Tab("Current Status")
|
||||
public long getAdvancementsCompleted(@NotNull UUID playerUUID) {
|
||||
return getCurrentUserData(playerUUID).join().map(
|
||||
versionedUserData -> (long) versionedUserData.userData().getAdvancementData().size())
|
||||
.orElse(0L);
|
||||
}
|
||||
|
||||
@Conditional("hasSynced")
|
||||
@TableProvider(tableColor = Color.LIGHT_BLUE)
|
||||
@Tab("Data Snapshots")
|
||||
public Table getDataSnapshots(@NotNull UUID playerUUID) {
|
||||
Table.Factory dataSnapshotsTable = Table.builder()
|
||||
.columnOne("Time", new Icon(Family.SOLID, "clock", Color.NONE))
|
||||
.columnOneFormat(TableColumnFormat.DATE_SECOND)
|
||||
.columnTwo("ID", new Icon(Family.SOLID, "bolt", Color.NONE))
|
||||
.columnThree("Cause", new Icon(Family.SOLID, "flag", Color.NONE))
|
||||
.columnFour("Pinned", new Icon(Family.SOLID, "thumbtack", Color.NONE));
|
||||
database.getUser(playerUUID).join().ifPresent(user ->
|
||||
database.getUserData(user).join().forEach(versionedUserData -> dataSnapshotsTable.addRow(
|
||||
versionedUserData.versionTimestamp().getTime(),
|
||||
versionedUserData.versionUUID().toString().split("-")[0],
|
||||
versionedUserData.cause().name().toLowerCase().replaceAll("_", " "),
|
||||
versionedUserData.pinned() ? "Yes" : "No"
|
||||
)));
|
||||
return dataSnapshotsTable.build();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user