mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-06 07:43:36 +00:00
fancydialogs: Add dialog action system
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.fancyinnovations.fancydialogs;
|
||||
|
||||
import com.fancyinnovations.fancydialogs.actions.ActionRegistry;
|
||||
import com.fancyinnovations.fancydialogs.api.Dialog;
|
||||
import com.fancyinnovations.fancydialogs.api.FancyDialogs;
|
||||
import com.fancyinnovations.fancydialogs.api.data.DialogData;
|
||||
@@ -48,6 +49,7 @@ public class FancyDialogsPlugin extends JavaPlugin implements FancyDialogs {
|
||||
private Translator translator;
|
||||
private DialogRegistry dialogRegistry;
|
||||
private DialogStorage dialogStorage;
|
||||
private ActionRegistry actionRegistry;
|
||||
|
||||
public FancyDialogsPlugin() {
|
||||
INSTANCE = this;
|
||||
@@ -108,6 +110,8 @@ public class FancyDialogsPlugin extends JavaPlugin implements FancyDialogs {
|
||||
|
||||
DefaultDialogs.registerDefaultDialogs();
|
||||
|
||||
actionRegistry = new ActionRegistry();
|
||||
|
||||
fancyLogger.info("Successfully loaded FancyDialogs version %s".formatted(getDescription().getVersion()));
|
||||
}
|
||||
|
||||
@@ -202,4 +206,8 @@ public class FancyDialogsPlugin extends JavaPlugin implements FancyDialogs {
|
||||
public DialogStorage getDialogStorage() {
|
||||
return dialogStorage;
|
||||
}
|
||||
|
||||
public ActionRegistry getActionRegistry() {
|
||||
return actionRegistry;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.fancyinnovations.fancydialogs.actions;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ActionRegistry {
|
||||
|
||||
private final Map<String, DialogAction> actions;
|
||||
|
||||
public ActionRegistry() {
|
||||
this.actions = new ConcurrentHashMap<>();
|
||||
|
||||
registerDefaultActions();
|
||||
}
|
||||
|
||||
private void registerDefaultActions() {
|
||||
|
||||
}
|
||||
|
||||
public void registerAction(String actionId, DialogAction action) {
|
||||
if (actions.containsKey(actionId)) {
|
||||
throw new IllegalArgumentException("Action with ID " + actionId + " is already registered.");
|
||||
}
|
||||
|
||||
actions.put(actionId, action);
|
||||
}
|
||||
|
||||
public DialogAction getAction(String actionId) {
|
||||
return actions.get(actionId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.fancyinnovations.fancydialogs.actions;
|
||||
|
||||
import com.fancyinnovations.fancydialogs.api.Dialog;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface DialogAction {
|
||||
|
||||
void execute(Player player, Dialog dialog, String data);
|
||||
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.fancyinnovations.fancydialogs.listener;
|
||||
|
||||
import com.fancyinnovations.fancydialogs.FancyDialogsPlugin;
|
||||
import com.fancyinnovations.fancydialogs.actions.DialogAction;
|
||||
import com.fancyinnovations.fancydialogs.api.Dialog;
|
||||
import de.oliver.fancysitula.api.packets.FS_ServerboundCustomClickActionPacket;
|
||||
import de.oliver.fancysitula.api.packets.FS_ServerboundPacket;
|
||||
import de.oliver.fancysitula.api.utils.FS_PacketListener;
|
||||
@@ -36,7 +39,19 @@ public class CustomClickActionPacketListener {
|
||||
String actionId = packet.getPayload().get("action_id");
|
||||
String actionData = packet.getPayload().get("action_data");
|
||||
|
||||
// TODO process the dialog action
|
||||
Dialog dialog = FancyDialogsPlugin.get().getDialogRegistry().get(dialogId);
|
||||
if (dialog == null) {
|
||||
FancyDialogsPlugin.get().getFancyLogger().warn("Received action for unknown dialog: " + dialogId);
|
||||
return; // Ignore actions for unknown dialogs
|
||||
}
|
||||
|
||||
DialogAction action = FancyDialogsPlugin.get().getActionRegistry().getAction(actionId);
|
||||
if (action == null) {
|
||||
FancyDialogsPlugin.get().getFancyLogger().warn("Received unknown action: " + actionId);
|
||||
return; // Ignore unknown actions
|
||||
}
|
||||
|
||||
action.execute(event.player(), dialog, actionData);
|
||||
}
|
||||
|
||||
public FS_PacketListener getPacketListener() {
|
||||
|
||||
@@ -44,13 +44,13 @@ public class DefaultDialogs {
|
||||
new DialogButton(
|
||||
"<color:#ff4f19>Close</color>",
|
||||
"<color:#ff4f19>Enjoy using FancyDialogs</color>",
|
||||
"close_dialog",
|
||||
"close",
|
||||
""
|
||||
),
|
||||
new DialogButton(
|
||||
"<color:#ffd000>Run command</color>",
|
||||
"<color:#ff4f19>Click to give yourself an apple :)</color>",
|
||||
"run_command:",
|
||||
"console_command",
|
||||
"give {player} apple 1"
|
||||
)
|
||||
)
|
||||
@@ -74,26 +74,26 @@ public class DefaultDialogs {
|
||||
new DialogButton(
|
||||
"<color:red>Read the rules</color>",
|
||||
"<color:red>Click to read our rules!</color>",
|
||||
"message",
|
||||
"<click:open_url:'{LINK TO RULES}'>Visit our rules</click>!"
|
||||
"open_dialog",
|
||||
"rules"
|
||||
),
|
||||
new DialogButton(
|
||||
"<color:#00ff5e>Start playing</color>",
|
||||
"<color:#00ff5e>Click to start playing!</color>",
|
||||
"close_dialog",
|
||||
"close",
|
||||
""
|
||||
),
|
||||
new DialogButton(
|
||||
"<color:#1787ff>Join our Discord</color>",
|
||||
"<color:#1787ff>Click to join our Discord server!</color>",
|
||||
"message",
|
||||
"<click:open_url:'{LINK TO DISC SERVER}'>Join our Discord server</click>!"
|
||||
"Join our Discord server here: LINK TO DISCORD"
|
||||
),
|
||||
new DialogButton(
|
||||
"<color:#ffee00>Visit our website</color>",
|
||||
"<color:#ffee00>Click to visit our website!</color>",
|
||||
"message",
|
||||
"<click:open_url:'{LINK TO WEBSITE}'>Visit our website</click>!"
|
||||
"Visit our website here: LINK TO WEBSITE"
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -114,30 +114,30 @@ public class DefaultDialogs {
|
||||
"<color:#ffee00>Visit our website</color>",
|
||||
"<color:#ffee00>Click to visit our website!</color>",
|
||||
"message",
|
||||
"<click:open_url:'{LINK TO WEBSITE}'>Visit our website</click>!"
|
||||
"Visit our website here: LINK TO WEBSITE"
|
||||
),
|
||||
new DialogButton(
|
||||
"<color:#ffee00>Read the rules</color>",
|
||||
"<color:#ffee00>Click to read our rules!</color>",
|
||||
"message",
|
||||
"<click:open_url:'{LINK TO RULES}'>Visit our rules</click>!"
|
||||
"open_dialog",
|
||||
"rules"
|
||||
),
|
||||
new DialogButton(
|
||||
"<color:#ffee00>Join our Discord</color>",
|
||||
"<color:#ffee00>Click to join our Discord server!</color>",
|
||||
"message",
|
||||
"<click:open_url:'{LINK TO DISCORD}'>Join our Discord server</click>!"
|
||||
"Join our Discord server here: LINK TO DISCORD"
|
||||
),
|
||||
new DialogButton(
|
||||
"<color:#ffee00>Support us</color>",
|
||||
"<color:#ffee00>Click to support us!</color>",
|
||||
"message",
|
||||
"<click:open_url:'{LINK TO SUPPORT}'>Support us</click>!"
|
||||
"Support us here: LINK TO SUPPORT"
|
||||
),
|
||||
new DialogButton(
|
||||
"<color:red>Close</color>",
|
||||
"<color:red>Click to close this dialog!</color>",
|
||||
"close_dialog",
|
||||
"close",
|
||||
""
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user