9
0
mirror of https://github.com/WiIIiam278/HuskSync.git synced 2025-12-26 01:59:20 +00:00

Add notification slot configuration, support for toasts

This commit is contained in:
William278
2022-11-16 22:31:57 +00:00
parent b664e2586d
commit 16eee05065
7 changed files with 94 additions and 8 deletions

View File

@@ -108,6 +108,9 @@ public class Settings {
@YamlKey("synchronization.compress_data")
public boolean compressData = true;
@YamlKey("synchronization.notification_display_slot")
public NotificationDisplaySlot notificationDisplaySlot = NotificationDisplaySlot.TOAST;
@YamlKey("synchronization.save_dead_player_inventories")
public boolean saveDeadPlayerInventories = true;
@@ -162,6 +165,28 @@ public class Settings {
}
}
/**
* Determines the slot a system notification should be displayed in
*/
public enum NotificationDisplaySlot {
/**
* Displays the notification in the action bar
*/
ACTION_BAR,
/**
* Displays the notification in the chat
*/
CHAT,
/**
* Displays the notification in an advancement toast
*/
TOAST,
/**
* Does not display the notification
*/
NONE
}
/**
* Represents enabled synchronisation features
*/

View File

@@ -1,5 +1,6 @@
package net.william278.husksync.listener;
import de.themoep.minedown.adventure.MineDown;
import net.william278.husksync.HuskSync;
import net.william278.husksync.data.DataSaveCause;
import net.william278.husksync.data.ItemData;
@@ -121,7 +122,19 @@ public abstract class EventListener {
*/
private void handleSynchronisationCompletion(@NotNull OnlineUser user, boolean succeeded) {
if (succeeded) {
plugin.getLocales().getLocale("synchronisation_complete").ifPresent(user::sendActionBar);
switch (plugin.getSettings().notificationDisplaySlot) {
case CHAT -> plugin.getLocales().getLocale("synchronisation_complete")
.ifPresent(user::sendActionBar);
case ACTION_BAR -> plugin.getLocales().getLocale("synchronisation_complete")
.ifPresent(user::sendActionBar);
case TOAST -> {
// todo locale implementation
user.sendToast(new MineDown("Synchronization complete"),
new MineDown("Your data has been synchronized"),
"minecraft:structure_void",
"task");
}
}
plugin.getDatabase().ensureUser(user).join();
lockedPlayers.remove(user.uuid);
plugin.getEventCannon().fireSyncCompleteEvent(user);

View File

@@ -198,6 +198,17 @@ public abstract class OnlineUser extends User {
*/
public abstract void sendActionBar(@NotNull MineDown mineDown);
/**
* Dispatch a toast message to this player
*
* @param title the title of the toast
* @param description the description of the toast
* @param iconMaterial the namespace-keyed material to use as an icon of the toast
* @param backgroundType the background ("ToastType") of the toast
*/
public abstract void sendToast(@NotNull MineDown title, @NotNull MineDown description,
@NotNull String iconMaterial, @NotNull String backgroundType);
/**
* Returns if the player has the permission node
*
@@ -246,15 +257,15 @@ public abstract class OnlineUser extends User {
// Prevent synchronising user data from newer versions of Minecraft
if (Version.fromMinecraftVersionString(data.getMinecraftVersion()).compareTo(serverMinecraftVersion) > 0) {
logger.log(Level.SEVERE, "Cannot set data for " + username +
" because the Minecraft version of their user data (" + data.getMinecraftVersion() +
") is newer than the server's Minecraft version (" + serverMinecraftVersion + ").");
" because the Minecraft version of their user data (" + data.getMinecraftVersion() +
") is newer than the server's Minecraft version (" + serverMinecraftVersion + ").");
return false;
}
// Prevent synchronising user data from newer versions of the plugin
if (data.getFormatVersion() > UserData.CURRENT_FORMAT_VERSION) {
logger.log(Level.SEVERE, "Cannot set data for " + username +
" because the format version of their user data (v" + data.getFormatVersion() +
") is newer than the current format version (v" + UserData.CURRENT_FORMAT_VERSION + ").");
" because the format version of their user data (v" + data.getFormatVersion() +
") is newer than the current format version (v" + UserData.CURRENT_FORMAT_VERSION + ").");
return false;
}

View File

@@ -1,5 +1,6 @@
package net.william278.husksync.redis;
import de.themoep.minedown.adventure.MineDown;
import net.william278.husksync.HuskSync;
import net.william278.husksync.data.UserData;
import net.william278.husksync.player.User;
@@ -85,8 +86,19 @@ public class RedisManager {
user.setData(userData, plugin.getSettings(), plugin.getEventCannon(),
plugin.getLoggingAdapter(), plugin.getMinecraftVersion()).thenAccept(succeeded -> {
if (succeeded) {
plugin.getLocales().getLocale("data_update_complete")
.ifPresent(user::sendActionBar);
switch (plugin.getSettings().notificationDisplaySlot) {
case CHAT -> plugin.getLocales().getLocale("data_update_complete")
.ifPresent(user::sendMessage);
case ACTION_BAR -> plugin.getLocales().getLocale("data_update_complete")
.ifPresent(user::sendActionBar);
case TOAST -> {
// todo locale implementation
user.sendToast(new MineDown("Data updated"),
new MineDown("Your data has been updated"),
"minecraft:structure_void",
"task");
}
}
plugin.getEventCannon().fireSyncCompleteEvent(user);
} else {
plugin.getLocales().getLocale("data_update_failed")