player-canceled-input: event added.

This commit is contained in:
TinyTank800 2025-02-23 12:42:43 -08:00
parent be0884e3ae
commit bf2a46b5b4
3 changed files with 21 additions and 3 deletions

View File

@ -117,7 +117,11 @@ public class Utils implements Listener {
//if an item has an area for input instead of commands
if(panel.getConfig().contains("item." + foundSlot + section + ".player-input")) {
plugin.inputUtils.playerInput.put(p,new PlayerInput(panel,panel.getConfig().getStringList("item." + foundSlot + section + ".player-input"),e.getClick()));
List<String> cancelCommands = null;
if(panel.getConfig().contains("item." + foundSlot + section + ".player-canceled-input")){
cancelCommands = panel.getConfig().getStringList("item." + foundSlot + section + ".player-canceled-input");
}
plugin.inputUtils.playerInput.put(p,new PlayerInput(panel,panel.getConfig().getStringList("item." + foundSlot + section + ".player-input"),cancelCommands,e.getClick()));
plugin.inputUtils.sendMessage(panel,position,p);
}

View File

@ -9,10 +9,12 @@ public class PlayerInput {
public Panel panel;
public ClickType click;
public List<String> commands;
public List<String> cancelCommands;
public PlayerInput(Panel panel1, List<String> commands1, ClickType click1){
public PlayerInput(Panel panel1, List<String> commands1, List<String> cancelCommands1, ClickType click1){
panel = panel1;
click = click1;
commands = commands1;
cancelCommands = cancelCommands1;
}
}

View File

@ -28,7 +28,19 @@ public class UserInputUtils implements Listener {
e.setCancelled(true);
if(e.getMessage().equalsIgnoreCase(plugin.config.getString("input.input-cancel"))){
e.getPlayer().sendMessage(plugin.tex.colour( Objects.requireNonNull(plugin.config.getString("input.input-cancelled"))));
playerInput.remove(e.getPlayer());
if(playerInput.get(e.getPlayer()).cancelCommands != null){
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
if(playerInput.get(e.getPlayer()).cancelCommands != null){
plugin.commandRunner.runCommands(playerInput.get(e.getPlayer()).panel, PanelPosition.Top,e.getPlayer(), playerInput.get(e.getPlayer()).cancelCommands,playerInput.get(e.getPlayer()).click); //I have to do this to run regular Bukkit voids in an ASYNC Event
playerInput.remove(e.getPlayer());
}
}
});
} else {
playerInput.remove(e.getPlayer());
}
return;
}
playerInput.get(e.getPlayer()).panel.placeholders.addPlaceholder("player-input",e.getMessage());