mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-05 23:33:36 +00:00
fancydialogs: Add open_random_dialog action
This commit is contained in:
@@ -5,6 +5,10 @@ order: 1
|
||||
|
||||
# FancyDialogs v0.x.x
|
||||
|
||||
## v0.0.9 [!badge variant="info" text="2025-06-28"]
|
||||
|
||||
- Added `open_random_dialog` action to open a random dialog from a list
|
||||
|
||||
## v0.0.8 [!badge variant="info" text="2025-06-28"]
|
||||
|
||||
- Fixed permission for dialog command
|
||||
|
||||
@@ -127,4 +127,5 @@ Available actions include:
|
||||
- `console_command`: Executes a command as the console (set `data` to the command)
|
||||
- `player_command`: Executes a command as the player (set `data` to the command)
|
||||
- `open_dialog`: Opens another dialog (set `data` to the ID of the dialog to open)
|
||||
- `open_random_dialog`: Opens another dialog (set `data` to a list of dialog IDs separated by commas: 'dialog1,dialog2,dialog3')
|
||||
- `send_to_server`: Sends the player to another server (requires BungeeCord or Velocity) (set `data` to the server name)
|
||||
@@ -1 +1 @@
|
||||
0.0.8
|
||||
0.0.9
|
||||
@@ -19,6 +19,7 @@ public class ActionRegistryImpl implements DialogActionRegistry {
|
||||
|
||||
private void registerDefaultActions() {
|
||||
registerAction("open_dialog", OpenDialogDialogAction.INSTANCE);
|
||||
registerAction("open_random_dialog", OpenRandomDialogDialogAction.INSTANCE);
|
||||
registerAction("message", MessageDialogAction.INSTANCE);
|
||||
registerAction("console_command", ConsoleCommandDialogAction.INSTANCE);
|
||||
registerAction("player_command", PlayerCommandDialogAction.INSTANCE);
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.fancyinnovations.fancydialogs.actions.defaultActions;
|
||||
|
||||
import com.fancyinnovations.fancydialogs.FancyDialogsPlugin;
|
||||
import com.fancyinnovations.fancydialogs.api.Dialog;
|
||||
import com.fancyinnovations.fancydialogs.api.DialogAction;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class OpenRandomDialogDialogAction implements DialogAction {
|
||||
|
||||
public static final OpenRandomDialogDialogAction INSTANCE = new OpenRandomDialogDialogAction();
|
||||
|
||||
private OpenRandomDialogDialogAction() {
|
||||
}
|
||||
|
||||
private static String pickRandomDialogId(String[] ids) {
|
||||
int randomIndex = (int) (Math.random() * ids.length);
|
||||
return ids[randomIndex].trim();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Player player, Dialog dialog, String data) {
|
||||
if (data == null || data.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String[] ids = data.split(",");
|
||||
if (ids.length == 0) {
|
||||
FancyDialogsPlugin.get().getFancyLogger().warn("No dialog IDs provided in data: " + data);
|
||||
return;
|
||||
}
|
||||
|
||||
String randomDialogId = pickRandomDialogId(ids);
|
||||
|
||||
Dialog targetDialog = FancyDialogsPlugin.get().getDialogRegistry().get(randomDialogId);
|
||||
if (targetDialog == null) {
|
||||
FancyDialogsPlugin.get().getFancyLogger().warn("Dialog with ID '" + data + "' not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
targetDialog.open(player);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user