Add notification slot configuration, support for toasts

feat/data-edit-commands
William278 2 years ago
parent b664e2586d
commit 16eee05065

@ -4,6 +4,7 @@ dependencies {
implementation 'net.william278:mpdbdataconverter:1.0.1'
implementation 'net.william278:hsldataconverter:1.0'
implementation 'net.william278:MapDataAPI:1.0.2'
implementation 'net.william278:AndJam:1.0'
implementation 'me.lucko:commodore:2.2'
implementation 'net.kyori:adventure-platform-bukkit:4.1.2'
implementation 'dev.triumphteam:triumph-gui:3.1.3'
@ -12,6 +13,7 @@ dependencies {
compileOnly 'commons-io:commons-io:2.11.0'
compileOnly 'de.themoep:minedown-adventure:1.7.1-SNAPSHOT'
compileOnly 'dev.dejvokep:boosted-yaml:1.3'
compileOnly 'com.github.Roxeez:AdvancementAPI:9b959a88cc'
compileOnly 'com.zaxxer:HikariCP:5.0.1'
compileOnly 'net.william278:DesertWell:1.1'
compileOnly 'net.william278:Annotaml:2.0'
@ -33,7 +35,9 @@ shadowJar {
relocate 'net.william278.desertwell', 'net.william278.husksync.libraries.desertwell'
relocate 'net.william278.paginedown', 'net.william278.husksync.libraries.paginedown'
relocate 'net.william278.mapdataapi', 'net.william278.husksync.libraries.mapdataapi'
relocate 'net.william278.andjam', 'net.william278.husksync.libraries.andjam'
relocate 'net.querz', 'net.william278.husksync.libraries.nbt'
relocate 'net.roxeez', 'net.william278.husksync.libraries'
relocate 'me.lucko.commodore', 'net.william278.husksync.libraries.commodore'
relocate 'net.byteflux.libby', 'net.william278.husksync.libraries.libby'

@ -6,6 +6,8 @@ import dev.triumphteam.gui.builder.gui.StorageBuilder;
import dev.triumphteam.gui.guis.Gui;
import dev.triumphteam.gui.guis.StorageGui;
import net.kyori.adventure.audience.Audience;
import net.roxeez.advancement.display.FrameType;
import net.william278.andjam.Toast;
import net.william278.desertwell.Version;
import net.william278.husksync.BukkitHuskSync;
import net.william278.husksync.config.Settings;
@ -628,6 +630,19 @@ public class BukkitPlayer extends OnlineUser {
.replace().toComponent());
}
@Override
public void sendToast(@NotNull MineDown title, @NotNull MineDown description,
@NotNull String iconMaterial, @NotNull String backgroundType) {
final Material material = Material.matchMaterial(iconMaterial);
Toast.builder(BukkitHuskSync.getInstance())
.setTitle(title.toComponent())
.setDescription(description.toComponent())
.setIcon(material != null ? material : Material.BARRIER)
.setFrameType(FrameType.valueOf(backgroundType))
.build()
.show(player);
}
@Override
public void sendMessage(@NotNull MineDown mineDown) {
audience.sendMessage(mineDown

@ -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
*/

@ -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);

@ -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
*

@ -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")
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")

@ -142,6 +142,12 @@ public class DummyPlayer extends OnlineUser {
// do nothing
}
@Override
public void sendToast(@NotNull MineDown title, @NotNull MineDown description,
@NotNull String iconMaterial, @NotNull String backgroundType) {
// do nothing
}
@Override
public boolean hasPermission(@NotNull String node) {
return true;

Loading…
Cancel
Save