diff --git a/pom.xml b/pom.xml index 19830c7..bb92a09 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ ltd.rymc TpaForm - 2.0.0 + 2.0.1 jar TpaForm diff --git a/src/main/java/ltd/rymc/form/tpa/event/TpaFormReceiveEvent.java b/src/main/java/ltd/rymc/form/tpa/event/TpaFormReceiveEvent.java new file mode 100644 index 0000000..ffdb095 --- /dev/null +++ b/src/main/java/ltd/rymc/form/tpa/event/TpaFormReceiveEvent.java @@ -0,0 +1,52 @@ +package ltd.rymc.form.tpa.event; + +import ltd.rymc.form.tpa.tpa.TpaMode; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class TpaFormReceiveEvent extends Event implements Cancellable { + private static final HandlerList HANDLERS = new HandlerList(); + private final Player targetPlayer; + private final Player fromPlayer; + private final TpaMode mode; + private boolean cancelled = false; + + public TpaFormReceiveEvent(Player targetPlayer, Player fromPlayer, TpaMode mode){ + this.targetPlayer = targetPlayer; + this.fromPlayer = fromPlayer; + this.mode = mode; + } + + public TpaMode getMode(){ + return mode; + } + + public Player getFromPlayer() { + return fromPlayer; + } + + public Player getTargetPlayer() { + return targetPlayer; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + + @Override + public HandlerList getHandlers() { + return HANDLERS; + } + + public static HandlerList getHandlerList() { + return HANDLERS; + } +} diff --git a/src/main/java/ltd/rymc/form/tpa/forms/TpaReceiveForm.java b/src/main/java/ltd/rymc/form/tpa/forms/TpaReceiveForm.java index 7376883..20c2d0e 100644 --- a/src/main/java/ltd/rymc/form/tpa/forms/TpaReceiveForm.java +++ b/src/main/java/ltd/rymc/form/tpa/forms/TpaReceiveForm.java @@ -1,6 +1,7 @@ package ltd.rymc.form.tpa.forms; import ltd.rymc.form.tpa.TpaForm; +import ltd.rymc.form.tpa.event.TpaFormReceiveEvent; import ltd.rymc.form.tpa.form.RForm; import ltd.rymc.form.tpa.form.RSimpleForm; import ltd.rymc.form.tpa.tpa.TpaMode; @@ -37,4 +38,13 @@ public void onValidResult(SimpleForm form, SimpleFormResponse response) { String command = id == 0 ? TpaMode.getAcceptCommand(mode) : TpaMode.getDenyCommand(mode); Bukkit.dispatchCommand(bukkitPlayer,String.format(command,fromPlayer.getName())); } + + @Override + public void send(){ + if (player == null) return; + TpaFormReceiveEvent event = new TpaFormReceiveEvent(bukkitPlayer, fromPlayer, mode); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) return; + player.sendForm(builder); + } }