+ Fixed bug where prompts would be active even after death

Took 4 minutes
This commit is contained in:
Kiran Hart 2023-02-11 23:29:33 -05:00
parent 36a7c9efd3
commit 64ad7de626
No known key found for this signature in database
GPG Key ID: 5F36C7BC79D3EBC3
2 changed files with 24 additions and 10 deletions

View File

@ -30,6 +30,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
@ -54,6 +55,9 @@ public abstract class Input implements Listener, Runnable {
public void onExit(final Player player) {
}
public void onDeath(final Player player) {
}
public abstract boolean onInput(final String input);
public abstract String getTitle();
@ -74,8 +78,7 @@ public abstract class Input implements Listener, Runnable {
this.subtitle = subTitle;
}
if (actionBar != null)
ActionBar.sendActionBar(this.player, actionBar);
if (actionBar != null) ActionBar.sendActionBar(this.player, actionBar);
}
@EventHandler(priority = EventPriority.LOWEST)
@ -83,7 +86,7 @@ public abstract class Input implements Listener, Runnable {
if (e.getPlayer().equals(this.player)) {
if (ChatColor.stripColor(e.getMessage()).equals(Settings.TITLE_INPUT_CANCEL_WORD.getString())) {
e.setCancelled(true);
this.close(false);
this.close(false, false);
}
this.onInput(e.getMessage());
@ -101,22 +104,33 @@ public abstract class Input implements Listener, Runnable {
@EventHandler
public void close(PlayerQuitEvent e) {
if (e.getPlayer().equals(this.player)) {
this.close(false);
this.close(false, false);
}
}
@EventHandler
public void close(InventoryOpenEvent e) {
if (e.getPlayer().equals(this.player)) {
this.close(false);
this.close(false, false);
}
}
public void close(boolean completed) {
@EventHandler
public void death(PlayerDeathEvent e) {
if (e.getEntity().equals(this.player)) {
this.close(true, false);
}
}
public void close(boolean byDeath, boolean completed) {
HandlerList.unregisterAll(this);
this.task.cancel();
if (!completed) {
this.onExit(this.player);
if (byDeath) this.onDeath(this.player);
else {
if (!completed) {
this.onExit(this.player);
}
}
Titles.clearTitle(this.player);

View File

@ -54,7 +54,7 @@ public abstract class TitleInput extends Input {
public boolean onInput(String text) {
if (this.onResult(text)) {
this.close(true);
this.close(true, false);
}
return true;
}
@ -62,7 +62,7 @@ public abstract class TitleInput extends Input {
@EventHandler
public void close(PlayerInteractEvent e) {
if (e.getPlayer().equals(this.player) && (e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK)) {
this.close(false);
this.close(false, false);
}
}