mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-01-03 22:08:28 +00:00
Add UserKickEvent (#3490)
Co-authored-by: MD <1917406+md678685@users.noreply.github.com> Co-authored-by: JRoy <joshroy126@gmail.com>
This commit is contained in:
parent
2b7a4364b1
commit
1f1edd9b23
2 changed files with 71 additions and 2 deletions
|
@ -4,6 +4,7 @@ import com.earth2me.essentials.CommandSource;
|
|||
import com.earth2me.essentials.Console;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
import net.essentialsx.api.v2.events.UserKickEvent;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import java.util.Collections;
|
||||
|
@ -24,8 +25,9 @@ public class Commandkick extends EssentialsCommand {
|
|||
}
|
||||
|
||||
final User target = getPlayer(server, args, 0, true, false);
|
||||
if (sender.isPlayer()) {
|
||||
final User user = ess.getUser(sender.getPlayer());
|
||||
final User user = sender.isPlayer() ? ess.getUser(sender.getPlayer()) : null;
|
||||
|
||||
if (user != null) {
|
||||
if (target.isHidden(sender.getPlayer()) && !user.canInteractVanished() && !sender.getPlayer().canSee(target.getBase())) {
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
|
@ -38,6 +40,14 @@ public class Commandkick extends EssentialsCommand {
|
|||
String kickReason = args.length > 1 ? getFinalArg(args, 1) : tl("kickDefault");
|
||||
kickReason = FormatUtil.replaceFormat(kickReason.replace("\\n", "\n").replace("|", "\n"));
|
||||
|
||||
final UserKickEvent event = new UserKickEvent(user, target, kickReason);
|
||||
ess.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
kickReason = event.getReason();
|
||||
target.getBase().kickPlayer(kickReason);
|
||||
final String senderDisplayName = sender.isPlayer() ? sender.getPlayer().getDisplayName() : Console.DISPLAY_NAME;
|
||||
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
package net.essentialsx.api.v2.events;
|
||||
|
||||
import com.earth2me.essentials.IUser;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Called when a user is kicked with the /kick command.
|
||||
*/
|
||||
public class UserKickEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private final IUser kicked;
|
||||
private final IUser kicker;
|
||||
private String reason;
|
||||
private boolean cancelled;
|
||||
|
||||
public UserKickEvent(IUser kicked, IUser kicker, String reason) {
|
||||
this.kicked = kicked;
|
||||
this.kicker = kicker;
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
public IUser getKicked() {
|
||||
return kicked;
|
||||
}
|
||||
|
||||
public IUser getKicker() {
|
||||
return kicker;
|
||||
}
|
||||
|
||||
public String getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
public void setReason(String reason) {
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue