2018-10-28 09:10:56 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Player Analytics (Plan).
|
|
|
|
*
|
|
|
|
* Plan is free software: you can redistribute it and/or modify
|
2018-11-11 19:55:11 +01:00
|
|
|
* it under the terms of the GNU Lesser General Public License v3 as published by
|
2018-10-28 09:10:56 +01:00
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Plan is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2018-11-11 19:55:11 +01:00
|
|
|
* GNU Lesser General Public License for more details.
|
2018-10-28 09:10:56 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2019-08-30 22:14:54 +02:00
|
|
|
package com.djrapitops.plan.gathering.listeners.bukkit;
|
2018-01-13 12:46:32 +01:00
|
|
|
|
2022-08-14 19:35:32 +02:00
|
|
|
import com.djrapitops.plan.gathering.cache.JoinAddressCache;
|
|
|
|
import com.djrapitops.plan.gathering.domain.BukkitPlayerData;
|
|
|
|
import com.djrapitops.plan.gathering.domain.event.PlayerJoin;
|
|
|
|
import com.djrapitops.plan.gathering.domain.event.PlayerLeave;
|
|
|
|
import com.djrapitops.plan.gathering.events.PlayerJoinEventConsumer;
|
|
|
|
import com.djrapitops.plan.gathering.events.PlayerLeaveEventConsumer;
|
2019-08-30 22:14:54 +02:00
|
|
|
import com.djrapitops.plan.gathering.listeners.Status;
|
|
|
|
import com.djrapitops.plan.identification.ServerInfo;
|
2021-03-12 17:03:00 +01:00
|
|
|
import com.djrapitops.plan.identification.ServerUUID;
|
2019-08-30 22:14:54 +02:00
|
|
|
import com.djrapitops.plan.storage.database.DBSystem;
|
2022-08-14 19:35:32 +02:00
|
|
|
import com.djrapitops.plan.storage.database.transactions.events.BanStatusTransaction;
|
|
|
|
import com.djrapitops.plan.storage.database.transactions.events.KickStoreTransaction;
|
2024-03-10 09:25:42 +01:00
|
|
|
import com.djrapitops.plan.storage.database.transactions.events.StoreAllowlistBounceTransaction;
|
2020-05-15 11:20:29 +02:00
|
|
|
import com.djrapitops.plan.utilities.logging.ErrorContext;
|
2020-05-14 15:57:29 +02:00
|
|
|
import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
2018-01-13 12:46:32 +01:00
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
import org.bukkit.event.player.PlayerJoinEvent;
|
|
|
|
import org.bukkit.event.player.PlayerKickEvent;
|
|
|
|
import org.bukkit.event.player.PlayerLoginEvent;
|
|
|
|
import org.bukkit.event.player.PlayerQuitEvent;
|
|
|
|
|
2018-08-20 17:07:22 +02:00
|
|
|
import javax.inject.Inject;
|
2018-01-13 12:46:32 +01:00
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event Listener for PlayerJoin, PlayerQuit and PlayerKickEvents.
|
|
|
|
*
|
2021-02-13 14:16:03 +01:00
|
|
|
* @author AuroraLS3
|
2018-01-13 12:46:32 +01:00
|
|
|
*/
|
|
|
|
public class PlayerOnlineListener implements Listener {
|
|
|
|
|
2022-08-14 19:35:32 +02:00
|
|
|
private final PlayerJoinEventConsumer playerJoinEventConsumer;
|
|
|
|
private final PlayerLeaveEventConsumer playerLeaveEventConsumer;
|
|
|
|
private final JoinAddressCache joinAddressCache;
|
|
|
|
|
2018-09-18 17:30:31 +02:00
|
|
|
private final ServerInfo serverInfo;
|
2019-01-28 20:39:57 +01:00
|
|
|
private final DBSystem dbSystem;
|
2020-05-14 15:57:29 +02:00
|
|
|
private final ErrorLogger errorLogger;
|
[Merge] Module split (#786)
* Moved project files to 'common'-module
This is done so that refactoring into multiple smaller modules is easier
as the IDE will not attempt to move tests incorrectly when moving things
between different modules
* Created 'bukkit' module
Following classes were removed during the operation:
- BukkitServerInfo (Renamed to ServerServerInfo)
- SpongeServerInfo (could use ServerServerInfo)
- Hastebin (not viable on every platform, unused)
- HastebinTest
- MockPlayers (unused, bukkit specific)
Changes to classes:
- Renamed Importer to BukkitImporter (contained bukkit related impl.)
- Extracted Importer interface from BukkitImporter
- Turned BukkitPlanModule and BukkitClassBindingModule to interfaces by
using @Binds annotation
- Added Status class since PlayersOnlineListener had a boolean,
that stated if kicks were counted.
This commit completes split partially and was not pushed on commit.
* Created 'sponge' module
Changes to classes:
- Turned ServerSuperClassBindingModule, SuperClassBindingModule,
SpongePlanModule and SpongeClassBindingModule to interfaces by
using @Binds annotation
- Renamed SystemObjectBindingModule to SystemObjectProvidingModule
- Removed sponge related calls in ServerProperties
- Made EmptyImportSystem injectable
This commit completes split partially and was not pushed on commit.
* Changed shade configuration
Further tweaks required.
* Created 'bungeecord' module
Changes to classes:
- Removed use of BungeePingTimerTask in VelocityTaskSystem
- Removed use of RedisBungee in VelocityServerProperties
- Fixed bukkit command.commands.RegisterCommandFilter package
Changes to project structure:
- Dependency versions now in main pom via dependencyManagement
- Repositories now defined in main pom
* Created 'velocity' module
Changes to classes:
- Made RawDataResponse use Gson via reflection since it is no longer
available in dependencies of 'common' module
* Created 'plugin' module
This module is for creating a single deployment artifact and testing of
system interactions.
Fixes to tests:
- Reflection no longer fails to initialize if Bukkit.getServer() is null
- PingCountTimerBukkit no longer fails to be created if Reflection fails
- Removed unnecessary @AfterClass from H2Test
- Jar resource path fixes to Mocker
* Shading configuration
org.slf4j classes are relocated in 'common', 'bukkit' & 'bungeecord'.
In 'sponge' & 'velocity' they are not relocated, allowing injection
as plugin logger, while using slf4j-nop for HikariCP logging.
This allows single release artifact.
* Removed 'Icon' from .gitignore
* Attempt to fix test resources
Because all jar resources are located in 'common', an attempt to fetch
them is made to common/target/Plan-common.jar, which for some reason
is a bad path.
This attempts to remedy that by creating a temporary file from an
InputStream, read with Class#getResourceAsStream
Ignored HTTPSWebServerAuthTest as the certificate path was invalid for
some reason.
2018-11-11 11:55:09 +01:00
|
|
|
private final Status status;
|
2018-08-20 17:07:22 +02:00
|
|
|
|
|
|
|
@Inject
|
2018-08-29 09:58:29 +02:00
|
|
|
public PlayerOnlineListener(
|
2022-08-14 19:35:32 +02:00
|
|
|
PlayerJoinEventConsumer playerJoinEventConsumer,
|
|
|
|
PlayerLeaveEventConsumer playerLeaveEventConsumer,
|
|
|
|
JoinAddressCache joinAddressCache,
|
2018-09-18 17:30:31 +02:00
|
|
|
ServerInfo serverInfo,
|
2019-01-28 20:39:57 +01:00
|
|
|
DBSystem dbSystem,
|
[Merge] Module split (#786)
* Moved project files to 'common'-module
This is done so that refactoring into multiple smaller modules is easier
as the IDE will not attempt to move tests incorrectly when moving things
between different modules
* Created 'bukkit' module
Following classes were removed during the operation:
- BukkitServerInfo (Renamed to ServerServerInfo)
- SpongeServerInfo (could use ServerServerInfo)
- Hastebin (not viable on every platform, unused)
- HastebinTest
- MockPlayers (unused, bukkit specific)
Changes to classes:
- Renamed Importer to BukkitImporter (contained bukkit related impl.)
- Extracted Importer interface from BukkitImporter
- Turned BukkitPlanModule and BukkitClassBindingModule to interfaces by
using @Binds annotation
- Added Status class since PlayersOnlineListener had a boolean,
that stated if kicks were counted.
This commit completes split partially and was not pushed on commit.
* Created 'sponge' module
Changes to classes:
- Turned ServerSuperClassBindingModule, SuperClassBindingModule,
SpongePlanModule and SpongeClassBindingModule to interfaces by
using @Binds annotation
- Renamed SystemObjectBindingModule to SystemObjectProvidingModule
- Removed sponge related calls in ServerProperties
- Made EmptyImportSystem injectable
This commit completes split partially and was not pushed on commit.
* Changed shade configuration
Further tweaks required.
* Created 'bungeecord' module
Changes to classes:
- Removed use of BungeePingTimerTask in VelocityTaskSystem
- Removed use of RedisBungee in VelocityServerProperties
- Fixed bukkit command.commands.RegisterCommandFilter package
Changes to project structure:
- Dependency versions now in main pom via dependencyManagement
- Repositories now defined in main pom
* Created 'velocity' module
Changes to classes:
- Made RawDataResponse use Gson via reflection since it is no longer
available in dependencies of 'common' module
* Created 'plugin' module
This module is for creating a single deployment artifact and testing of
system interactions.
Fixes to tests:
- Reflection no longer fails to initialize if Bukkit.getServer() is null
- PingCountTimerBukkit no longer fails to be created if Reflection fails
- Removed unnecessary @AfterClass from H2Test
- Jar resource path fixes to Mocker
* Shading configuration
org.slf4j classes are relocated in 'common', 'bukkit' & 'bungeecord'.
In 'sponge' & 'velocity' they are not relocated, allowing injection
as plugin logger, while using slf4j-nop for HikariCP logging.
This allows single release artifact.
* Removed 'Icon' from .gitignore
* Attempt to fix test resources
Because all jar resources are located in 'common', an attempt to fetch
them is made to common/target/Plan-common.jar, which for some reason
is a bad path.
This attempts to remedy that by creating a temporary file from an
InputStream, read with Class#getResourceAsStream
Ignored HTTPSWebServerAuthTest as the certificate path was invalid for
some reason.
2018-11-11 11:55:09 +01:00
|
|
|
Status status,
|
2020-05-14 15:57:29 +02:00
|
|
|
ErrorLogger errorLogger
|
2018-08-29 09:58:29 +02:00
|
|
|
) {
|
2022-08-14 19:35:32 +02:00
|
|
|
this.playerJoinEventConsumer = playerJoinEventConsumer;
|
|
|
|
this.playerLeaveEventConsumer = playerLeaveEventConsumer;
|
|
|
|
this.joinAddressCache = joinAddressCache;
|
2018-09-18 17:30:31 +02:00
|
|
|
this.serverInfo = serverInfo;
|
2019-01-28 20:39:57 +01:00
|
|
|
this.dbSystem = dbSystem;
|
[Merge] Module split (#786)
* Moved project files to 'common'-module
This is done so that refactoring into multiple smaller modules is easier
as the IDE will not attempt to move tests incorrectly when moving things
between different modules
* Created 'bukkit' module
Following classes were removed during the operation:
- BukkitServerInfo (Renamed to ServerServerInfo)
- SpongeServerInfo (could use ServerServerInfo)
- Hastebin (not viable on every platform, unused)
- HastebinTest
- MockPlayers (unused, bukkit specific)
Changes to classes:
- Renamed Importer to BukkitImporter (contained bukkit related impl.)
- Extracted Importer interface from BukkitImporter
- Turned BukkitPlanModule and BukkitClassBindingModule to interfaces by
using @Binds annotation
- Added Status class since PlayersOnlineListener had a boolean,
that stated if kicks were counted.
This commit completes split partially and was not pushed on commit.
* Created 'sponge' module
Changes to classes:
- Turned ServerSuperClassBindingModule, SuperClassBindingModule,
SpongePlanModule and SpongeClassBindingModule to interfaces by
using @Binds annotation
- Renamed SystemObjectBindingModule to SystemObjectProvidingModule
- Removed sponge related calls in ServerProperties
- Made EmptyImportSystem injectable
This commit completes split partially and was not pushed on commit.
* Changed shade configuration
Further tweaks required.
* Created 'bungeecord' module
Changes to classes:
- Removed use of BungeePingTimerTask in VelocityTaskSystem
- Removed use of RedisBungee in VelocityServerProperties
- Fixed bukkit command.commands.RegisterCommandFilter package
Changes to project structure:
- Dependency versions now in main pom via dependencyManagement
- Repositories now defined in main pom
* Created 'velocity' module
Changes to classes:
- Made RawDataResponse use Gson via reflection since it is no longer
available in dependencies of 'common' module
* Created 'plugin' module
This module is for creating a single deployment artifact and testing of
system interactions.
Fixes to tests:
- Reflection no longer fails to initialize if Bukkit.getServer() is null
- PingCountTimerBukkit no longer fails to be created if Reflection fails
- Removed unnecessary @AfterClass from H2Test
- Jar resource path fixes to Mocker
* Shading configuration
org.slf4j classes are relocated in 'common', 'bukkit' & 'bungeecord'.
In 'sponge' & 'velocity' they are not relocated, allowing injection
as plugin logger, while using slf4j-nop for HikariCP logging.
This allows single release artifact.
* Removed 'Icon' from .gitignore
* Attempt to fix test resources
Because all jar resources are located in 'common', an attempt to fetch
them is made to common/target/Plan-common.jar, which for some reason
is a bad path.
This attempts to remedy that by creating a temporary file from an
InputStream, read with Class#getResourceAsStream
Ignored HTTPSWebServerAuthTest as the certificate path was invalid for
some reason.
2018-11-11 11:55:09 +01:00
|
|
|
this.status = status;
|
2020-05-14 15:57:29 +02:00
|
|
|
this.errorLogger = errorLogger;
|
2018-08-20 17:07:22 +02:00
|
|
|
}
|
|
|
|
|
2018-01-13 12:46:32 +01:00
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
|
|
|
public void onPlayerLogin(PlayerLoginEvent event) {
|
|
|
|
try {
|
2019-02-16 12:23:17 +01:00
|
|
|
UUID playerUUID = event.getPlayer().getUniqueId();
|
2021-04-17 07:24:42 +02:00
|
|
|
ServerUUID serverUUID = serverInfo.getServerUUID();
|
2022-08-14 19:35:32 +02:00
|
|
|
boolean banned = PlayerLoginEvent.Result.KICK_BANNED == event.getResult();
|
2024-03-10 09:25:42 +01:00
|
|
|
boolean notWhitelisted = PlayerLoginEvent.Result.KICK_WHITELIST == event.getResult();
|
|
|
|
|
|
|
|
if (notWhitelisted) {
|
|
|
|
dbSystem.getDatabase().executeTransaction(new StoreAllowlistBounceTransaction(playerUUID, event.getPlayer().getName(), serverUUID, System.currentTimeMillis()));
|
|
|
|
}
|
2022-08-14 19:35:32 +02:00
|
|
|
|
2022-11-08 15:38:09 +01:00
|
|
|
String address = event.getHostname();
|
|
|
|
if (!address.isEmpty()) {
|
2023-10-03 20:02:30 +02:00
|
|
|
if (address.contains(":")) {
|
|
|
|
address = address.substring(0, address.lastIndexOf(':'));
|
|
|
|
}
|
2022-11-08 15:38:09 +01:00
|
|
|
if (address.contains("\u0000")) {
|
|
|
|
address = address.substring(0, address.indexOf('\u0000'));
|
|
|
|
}
|
2022-11-11 20:20:57 +01:00
|
|
|
if (address.contains("fml")) {
|
|
|
|
address = address.substring(0, address.lastIndexOf("fml"));
|
|
|
|
}
|
2022-11-08 15:38:09 +01:00
|
|
|
joinAddressCache.put(playerUUID, address);
|
2021-03-17 10:31:14 +01:00
|
|
|
}
|
2022-08-14 19:35:32 +02:00
|
|
|
dbSystem.getDatabase().executeTransaction(new BanStatusTransaction(playerUUID, serverUUID, banned));
|
2018-01-13 12:46:32 +01:00
|
|
|
} catch (Exception e) {
|
2021-03-09 10:36:07 +01:00
|
|
|
errorLogger.error(e, ErrorContext.builder().related(event, event.getResult()).build());
|
2018-01-13 12:46:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PlayerKickEvent Listener.
|
|
|
|
* <p>
|
|
|
|
* Adds processing information to the ProcessingQueue.
|
|
|
|
* After KickEvent, the QuitEvent is automatically called.
|
|
|
|
*
|
|
|
|
* @param event Fired event
|
|
|
|
*/
|
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
|
|
|
public void onPlayerKick(PlayerKickEvent event) {
|
|
|
|
try {
|
2020-06-20 20:25:47 +02:00
|
|
|
if (status.areKicksNotCounted() || event.isCancelled()) {
|
2018-01-13 12:46:32 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
UUID uuid = event.getPlayer().getUniqueId();
|
2021-03-16 09:41:17 +01:00
|
|
|
if (BukkitAFKListener.afkTracker.isAfk(uuid)) {
|
2018-08-30 17:10:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-16 11:02:51 +01:00
|
|
|
dbSystem.getDatabase().executeTransaction(new KickStoreTransaction(uuid));
|
2018-01-13 12:46:32 +01:00
|
|
|
} catch (Exception e) {
|
2021-03-09 10:36:07 +01:00
|
|
|
errorLogger.error(e, ErrorContext.builder().related(event).build());
|
2018-01-13 12:46:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
|
|
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
|
|
|
try {
|
2018-04-11 16:00:57 +02:00
|
|
|
actOnJoinEvent(event);
|
|
|
|
} catch (Exception e) {
|
2021-03-09 10:36:07 +01:00
|
|
|
errorLogger.error(e, ErrorContext.builder().related(event).build());
|
2018-04-11 16:00:57 +02:00
|
|
|
}
|
|
|
|
}
|
2018-01-13 12:46:32 +01:00
|
|
|
|
2018-04-11 16:00:57 +02:00
|
|
|
private void actOnJoinEvent(PlayerJoinEvent event) {
|
2018-05-25 08:00:33 +02:00
|
|
|
long time = System.currentTimeMillis();
|
2022-08-14 19:35:32 +02:00
|
|
|
UUID playerUUID = event.getPlayer().getUniqueId();
|
2021-03-16 09:41:17 +01:00
|
|
|
BukkitAFKListener.afkTracker.performedAction(playerUUID, time);
|
2018-01-13 12:46:32 +01:00
|
|
|
|
2022-08-14 19:35:32 +02:00
|
|
|
playerJoinEventConsumer.onJoinGameServer(PlayerJoin.builder()
|
|
|
|
.server(serverInfo.getServer())
|
|
|
|
.player(new BukkitPlayerData(event.getPlayer(), joinAddressCache.getNullableString(playerUUID)))
|
|
|
|
.time(time)
|
|
|
|
.build());
|
2021-03-16 16:47:26 +01:00
|
|
|
}
|
|
|
|
|
2019-03-31 11:36:01 +02:00
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
|
|
|
public void beforePlayerQuit(PlayerQuitEvent event) {
|
2022-08-14 19:35:32 +02:00
|
|
|
try {
|
|
|
|
playerLeaveEventConsumer.beforeLeave(PlayerLeave.builder()
|
|
|
|
.server(serverInfo.getServer())
|
|
|
|
.player(new BukkitPlayerData(event.getPlayer(), null))
|
|
|
|
.time(System.currentTimeMillis())
|
|
|
|
.build());
|
|
|
|
} catch (Exception e) {
|
|
|
|
errorLogger.error(e, ErrorContext.builder().related(event).build());
|
|
|
|
}
|
2018-01-13 12:46:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
|
|
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
|
|
|
try {
|
2018-04-11 16:00:57 +02:00
|
|
|
actOnQuitEvent(event);
|
|
|
|
} catch (Exception e) {
|
2021-03-09 10:36:07 +01:00
|
|
|
errorLogger.error(e, ErrorContext.builder().related(event).build());
|
2018-04-11 16:00:57 +02:00
|
|
|
}
|
|
|
|
}
|
2018-01-13 12:46:32 +01:00
|
|
|
|
2018-04-11 16:00:57 +02:00
|
|
|
private void actOnQuitEvent(PlayerQuitEvent event) {
|
2018-05-25 08:03:26 +02:00
|
|
|
long time = System.currentTimeMillis();
|
2022-08-14 19:35:32 +02:00
|
|
|
UUID playerUUID = event.getPlayer().getUniqueId();
|
2021-03-16 09:41:17 +01:00
|
|
|
BukkitAFKListener.afkTracker.loggedOut(playerUUID, time);
|
2019-02-16 11:42:03 +01:00
|
|
|
|
2022-08-14 19:35:32 +02:00
|
|
|
playerLeaveEventConsumer.onLeaveGameServer(PlayerLeave.builder()
|
|
|
|
.server(serverInfo.getServer())
|
|
|
|
.player(new BukkitPlayerData(event.getPlayer(), null))
|
|
|
|
.time(System.currentTimeMillis())
|
|
|
|
.build());
|
2018-01-13 12:46:32 +01:00
|
|
|
}
|
|
|
|
}
|