Add logging to GoatHornEvent and register it

Introduced a logger to GoatHornEvent to record when a player uses a goat horn, both in and out of spawn. This helps with tracking player actions and debugging potential issues related to goat horn usage.
This commit is contained in:
Teriuihi 2024-08-11 23:53:53 +02:00
parent c0c8cbbfa4
commit 2fa3e3a6f0
2 changed files with 13 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import com.alttd.playerutils.commands.PlayerUtilsCommand;
import com.alttd.playerutils.commands.playerutils_subcommands.RotateBlock;
import com.alttd.playerutils.config.Config;
import com.alttd.playerutils.config.Messages;
import com.alttd.playerutils.event_listeners.GoatHornEvent;
import com.alttd.playerutils.event_listeners.RotateBlockEvent;
import com.alttd.playerutils.event_listeners.TeleportEvent;
import com.alttd.playerutils.event_listeners.XpBottleEvent;
@ -40,6 +41,7 @@ public final class PlayerUtils extends JavaPlugin {
PluginManager pluginManager = getServer().getPluginManager();
pluginManager.registerEvents(new XpBottleEvent(this, logger), this);
pluginManager.registerEvents(new TeleportEvent(), this);
pluginManager.registerEvents(new GoatHornEvent(logger), this);
RotateBlockEvent rotateBlockEvent = new RotateBlockEvent(logger);
pluginManager.registerEvents(rotateBlockEvent, this);

View File

@ -1,5 +1,6 @@
package com.alttd.playerutils.event_listeners;
import com.alttd.playerutils.util.Logger;
import org.bukkit.Location;
import org.bukkit.Tag;
import org.bukkit.entity.Player;
@ -12,6 +13,12 @@ import java.util.concurrent.TimeUnit;
public class GoatHornEvent implements Listener {
private final Logger logger;
public GoatHornEvent(Logger logger) {
this.logger = logger;
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
ItemStack item = event.getItem();
@ -32,10 +39,14 @@ public class GoatHornEvent implements Listener {
Location spawn = player.getLocation().clone();
spawn.set(0, player.getY(), 0);
if (player.getLocation().distance(spawn) > 250) {
logger.info(String.format("Player %s with uuid %s used a goat horn", player.getName(), player.getUniqueId()));
return;
}
logger.info(String.format("Player %s with uuid %s used a goat horn in spawn", player.getName(), player.getUniqueId()));
Tag.SNAPS_GOAT_HORN.getValues().forEach(horn ->
player.setCooldown(horn, (int) TimeUnit.MINUTES.toSeconds(5) * 20));
}