diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandkick.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandkick.java index 52f4196ab..a919b4f5f 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandkick.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandkick.java @@ -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; diff --git a/Essentials/src/main/java/net/essentialsx/api/v2/events/UserKickEvent.java b/Essentials/src/main/java/net/essentialsx/api/v2/events/UserKickEvent.java new file mode 100644 index 000000000..3a214dbad --- /dev/null +++ b/Essentials/src/main/java/net/essentialsx/api/v2/events/UserKickEvent.java @@ -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; + } +}