Implement login/logout events for /magnet
This commit is contained in:
parent
f545ce86c8
commit
b0bf3ed601
@ -241,7 +241,15 @@ public class MagnetCommandExecutor implements CommandExecutor {
|
|||||||
divIndex = (divIndex + 1) % subdivide;
|
divIndex = (divIndex + 1) % subdivide;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onMagnetLogout(final UUID magnet) {
|
||||||
|
if (magnetData.removeLogoutOnline(magnet))
|
||||||
|
updateMagnetismTask(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onMagnetLogin(final UUID magnet) {
|
||||||
|
if (magnetData.addLoginOnline(magnet))
|
||||||
|
updateMagnetismTask(false);
|
||||||
|
}
|
||||||
|
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
data.storeData("magnets", magnetData);
|
data.storeData("magnets", magnetData);
|
||||||
|
41
src/dev/w1zzrd/invtweaks/listener/MagnetismListener.java
Normal file
41
src/dev/w1zzrd/invtweaks/listener/MagnetismListener.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package dev.w1zzrd.invtweaks.listener;
|
||||||
|
|
||||||
|
import dev.w1zzrd.invtweaks.command.MagnetCommandExecutor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerKickEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
public class MagnetismListener implements Listener {
|
||||||
|
|
||||||
|
private final MagnetCommandExecutor magnetCommandExecutor;
|
||||||
|
|
||||||
|
public MagnetismListener(final MagnetCommandExecutor magnetCommandExecutor) {
|
||||||
|
this.magnetCommandExecutor = magnetCommandExecutor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoinEvent(final PlayerJoinEvent event) {
|
||||||
|
magnetCommandExecutor.onMagnetLogin(event.getPlayer().getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerDisconnectEvent(final PlayerQuitEvent event) {
|
||||||
|
onLeave(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerKickedEvent(final PlayerKickEvent event) {
|
||||||
|
onLeave(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onLeave(final Player player) {
|
||||||
|
magnetCommandExecutor.onMagnetLogout(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean shouldNotifyExecutor(final Player player) {
|
||||||
|
return magnetCommandExecutor.isMagnet(player);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user