Skip to content

Commit

Permalink
添加一个Event
Browse files Browse the repository at this point in the history
  • Loading branch information
lRENyaaa committed Dec 30, 2023
1 parent a67ea0f commit 754112e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ltd.rymc</groupId>
<artifactId>TpaForm</artifactId>
<version>2.0.0</version>
<version>2.0.1</version>
<packaging>jar</packaging>

<name>TpaForm</name>
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/ltd/rymc/form/tpa/event/TpaFormReceiveEvent.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
10 changes: 10 additions & 0 deletions src/main/java/ltd/rymc/form/tpa/forms/TpaReceiveForm.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 754112e

Please sign in to comment.