-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kick only idle when no link request, send message on link req replace
- Loading branch information
Showing
10 changed files
with
222 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/org/geysermc/globallinkserver/handler/MoveInactivityHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2025 GeyserMC | ||
* Licensed under the MIT license | ||
* @link https://github.com/GeyserMC/GlobalLinkServer | ||
*/ | ||
package org.geysermc.globallinkserver.handler; | ||
|
||
import it.unimi.dsi.fastutil.objects.Object2LongMap; | ||
import it.unimi.dsi.fastutil.objects.Object2LongMaps; | ||
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap; | ||
import java.util.UUID; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerJoinEvent; | ||
import org.bukkit.event.player.PlayerMoveEvent; | ||
import org.geysermc.globallinkserver.util.MultiConditionSet; | ||
|
||
public final class MoveInactivityHandler implements Listener { | ||
private static final long TIME_TILL_IDLE_MILLIS = 15 * 60 * 1000; // 15 minutes | ||
|
||
private final Object2LongMap<UUID> lastMoveAction = Object2LongMaps.synchronize(new Object2LongOpenHashMap<>()); | ||
|
||
public MoveInactivityHandler(MultiConditionSet<UUID> playerIdleTracker) { | ||
playerIdleTracker | ||
.addRemovalCondition(key -> { | ||
long lastMovement = lastMoveAction.getLong(key); | ||
// if not present, the value will be 0. It should never happen, so if that happens we remove them. | ||
return System.currentTimeMillis() - lastMovement >= TIME_TILL_IDLE_MILLIS; | ||
}) | ||
.addRemovalListener(lastMoveAction::removeLong); | ||
} | ||
|
||
@EventHandler | ||
public void onPlayerJoin(PlayerJoinEvent event) { | ||
// just to make sure that there aren't any weird edge cases of a player not firing a PlayerMoveEvent immediately | ||
lastMoveAction.put(event.getPlayer().getUniqueId(), System.currentTimeMillis()); | ||
} | ||
|
||
@EventHandler | ||
public void onPlayerMove(PlayerMoveEvent event) { | ||
int diffX = event.getFrom().getBlockX() - event.getTo().getBlockX(); | ||
int diffY = event.getFrom().getBlockZ() - event.getTo().getBlockZ(); | ||
if (Math.abs(diffX) > 0 || Math.abs(diffY) > 0) { | ||
lastMoveAction.put(event.getPlayer().getUniqueId(), System.currentTimeMillis()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.