From 1464ef295221d731e75b5380a3ebb0c355a18d7f Mon Sep 17 00:00:00 2001 From: TuxCoding <1957196+TuxCoding@users.noreply.github.com> Date: Wed, 23 Apr 2025 16:46:37 +0200 Subject: [PATCH] Add command invoker for change command events Related #1285 --- .../fastlogin/bukkit/command/CrackedCommand.java | 4 ++-- .../fastlogin/bukkit/command/PremiumCommand.java | 4 ++-- .../event/BukkitFastLoginPremiumToggleEvent.java | 14 +++++++++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/command/CrackedCommand.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/command/CrackedCommand.java index b0ac8287..04c1c91a 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/command/CrackedCommand.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/command/CrackedCommand.java @@ -71,7 +71,7 @@ public class CrackedCommand extends ToggleCommand { plugin.getScheduler().runAsync(() -> { plugin.getCore().getStorage().save(profile); plugin.getServer().getPluginManager().callEvent( - new BukkitFastLoginPremiumToggleEvent(profile, PremiumToggleReason.COMMAND_OTHER)); + new BukkitFastLoginPremiumToggleEvent(sender, profile, PremiumToggleReason.COMMAND_OTHER)); }); } else { plugin.getCore().sendLocaleMessage("not-premium", sender); @@ -104,7 +104,7 @@ public class CrackedCommand extends ToggleCommand { plugin.getScheduler().runAsync(() -> { plugin.getCore().getStorage().save(profile); plugin.getServer().getPluginManager().callEvent( - new BukkitFastLoginPremiumToggleEvent(profile, PremiumToggleReason.COMMAND_OTHER)); + new BukkitFastLoginPremiumToggleEvent(sender, profile, PremiumToggleReason.COMMAND_OTHER)); }); } } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/command/PremiumCommand.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/command/PremiumCommand.java index 6f132271..20af2de4 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/command/PremiumCommand.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/command/PremiumCommand.java @@ -86,7 +86,7 @@ public class PremiumCommand extends ToggleCommand { plugin.getScheduler().runAsync(() -> { plugin.getCore().getStorage().save(profile); plugin.getServer().getPluginManager().callEvent( - new BukkitFastLoginPremiumToggleEvent(profile, PremiumToggleReason.COMMAND_SELF)); + new BukkitFastLoginPremiumToggleEvent(sender, profile, PremiumToggleReason.COMMAND_SELF)); }); plugin.getCore().sendLocaleMessage("add-premium", sender); @@ -117,7 +117,7 @@ public class PremiumCommand extends ToggleCommand { plugin.getScheduler().runAsync(() -> { plugin.getCore().getStorage().save(profile); plugin.getServer().getPluginManager().callEvent( - new BukkitFastLoginPremiumToggleEvent(profile, PremiumToggleReason.COMMAND_OTHER)); + new BukkitFastLoginPremiumToggleEvent(sender, profile, PremiumToggleReason.COMMAND_OTHER)); }); plugin.getCore().sendLocaleMessage("add-premium-other", sender); diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/event/BukkitFastLoginPremiumToggleEvent.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/event/BukkitFastLoginPremiumToggleEvent.java index 1e77e6d8..d292a7fc 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/event/BukkitFastLoginPremiumToggleEvent.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/event/BukkitFastLoginPremiumToggleEvent.java @@ -27,6 +27,7 @@ package com.github.games647.fastlogin.bukkit.event; import com.github.games647.fastlogin.core.shared.event.FastLoginPremiumToggleEvent; import com.github.games647.fastlogin.core.storage.StoredProfile; +import org.bukkit.command.CommandSender; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; @@ -34,11 +35,15 @@ import org.jetbrains.annotations.NotNull; public class BukkitFastLoginPremiumToggleEvent extends Event implements FastLoginPremiumToggleEvent { private static final HandlerList HANDLERS = new HandlerList(); + + private final CommandSender invoker; private final StoredProfile profile; private final PremiumToggleReason reason; - public BukkitFastLoginPremiumToggleEvent(StoredProfile profile, PremiumToggleReason reason) { + public BukkitFastLoginPremiumToggleEvent(CommandSender invoker, StoredProfile profile, PremiumToggleReason reason) { super(true); + + this.invoker = invoker; this.profile = profile; this.reason = reason; } @@ -48,6 +53,13 @@ public class BukkitFastLoginPremiumToggleEvent extends Event implements FastLogi return profile; } + /** + * @return who triggered this change. This could be a Player for itself or others (Admin) or the console. + */ + public CommandSender getInvoker() { + return invoker; + } + @Override public PremiumToggleReason getReason() { return reason;