|
| 1 | +package net.coreprotect.event; |
| 2 | + |
| 3 | +import org.bukkit.command.CommandSender; |
| 4 | +import org.bukkit.event.Cancellable; |
| 5 | +import org.bukkit.event.Event; |
| 6 | +import org.bukkit.event.HandlerList; |
| 7 | +import org.jetbrains.annotations.NotNull; |
| 8 | + |
| 9 | +import java.util.List; |
| 10 | + |
| 11 | +public class CoreProtectLookupEvent extends Event implements Cancellable { |
| 12 | + private static final HandlerList handlers = new HandlerList(); |
| 13 | + private boolean cancelled = false; |
| 14 | + private final CommandSender commandSender; |
| 15 | + private List<String> users; |
| 16 | + private String cancelMessage = "This lookup was cancelled by another plugin."; |
| 17 | + |
| 18 | + public CoreProtectLookupEvent(CommandSender commandSender, List<String> users) { |
| 19 | + this.commandSender = commandSender; |
| 20 | + this.users = users; |
| 21 | + } |
| 22 | + |
| 23 | + public CommandSender getSender() { |
| 24 | + return commandSender; |
| 25 | + } |
| 26 | + |
| 27 | + public List<String> getUsers() { |
| 28 | + return users; |
| 29 | + } |
| 30 | + |
| 31 | + public void setUsers(List<String> users) { |
| 32 | + if (users.isEmpty()) { |
| 33 | + setCancelled(true); |
| 34 | + setCancelMessage("Users list was modified by another plugin. No users remaining."); |
| 35 | + return; |
| 36 | + } |
| 37 | + this.users = users; |
| 38 | + } |
| 39 | + |
| 40 | + public void setCancelMessage(String cancelMessage) { |
| 41 | + this.cancelMessage = cancelMessage; |
| 42 | + } |
| 43 | + |
| 44 | + public String getCancelMessage() { |
| 45 | + return cancelMessage; |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public boolean isCancelled() { |
| 50 | + return cancelled; |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public void setCancelled(boolean cancel) { |
| 55 | + this.cancelled = cancel; |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public @NotNull HandlerList getHandlers() { |
| 60 | + return handlers; |
| 61 | + } |
| 62 | + |
| 63 | + public static HandlerList getHandlerList() { |
| 64 | + return handlers; |
| 65 | + } |
| 66 | +} |
0 commit comments