-
Notifications
You must be signed in to change notification settings - Fork 1
feat: implement confinement analysis to detect AFK pools and similar … #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3986c24
feat: implement confinement analysis to detect AFK pools and similar …
bentahsin 7dbee5a
refactor: improve world comparison in isInsideRadius method using Obj…
bentahsin 604ca07
refactor: use Objects.equals for world comparison in PlayerBehaviorData
bentahsin 4327444
refactor: remove unnecessary blank line in config.yml
bentahsin 4092a88
refactor: optimize confinement logic and improve thread safety in Pla…
bentahsin 2152540
test: add unit tests for confinement detection logic in PlayerBehavio…
bentahsin f8a2d7a
feat: add localization for learned bot patterns and AFK pool detection
bentahsin 8b082b3
feat: log confinement period end and reset data in BehaviorAnalysisTask
bentahsin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
88 changes: 51 additions & 37 deletions
88
AntiAFK-Core/src/main/java/com/bentahsin/antiafk/behavior/PlayerBehaviorData.java
This file contains hidden or 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 |
|---|---|---|
| @@ -1,63 +1,77 @@ | ||
| package com.bentahsin.antiafk.behavior; | ||
|
|
||
| import org.bukkit.Location; | ||
|
|
||
| import java.util.LinkedList; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Her oyuncu için davranış analizi verilerini tutan veri sınıfı. | ||
| * Bu sınıf, oyuncunun hareket geçmişini ve tespit edilen otonom hareket | ||
| * tekrarlarını depolamak için kullanılır. | ||
| */ | ||
| public class PlayerBehaviorData { | ||
|
|
||
| /** | ||
| * Oyuncunun son 'X' saniyelik tüm anlamlı hareketlerini tutan ana veri havuzu. | ||
| * LinkedList, listenin başından (en eski veri) eleman silme işlemlerinde | ||
| * (FIFO - First-In, First-Out) ArrayList'e göre daha performanslıdır. | ||
| */ | ||
| private final LinkedList<Location> movementHistory = new LinkedList<>(); | ||
|
|
||
| /** | ||
| * Tespit edilen son tekrarın ne zaman gerçekleştiğini milisaniye cinsinden tutar. | ||
| * Bu, tekrarların ardışık olup olmadığını anlamak için kullanılır. | ||
| */ | ||
| private long lastRepeatTimestamp; | ||
| private volatile Location confinementStartLocation; | ||
| private volatile long confinementStartTime; | ||
| private volatile double totalDistanceTraveled = 0.0; | ||
| private Location lastMoveLocation; | ||
bentahsin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Birbirini takip eden (ardışık) tekrar sayısını tutar. | ||
| * Oyuncu kalıbı bozduğunda bu sayaç sıfırlanır. | ||
| */ | ||
| private int consecutiveRepeatCount = 0; | ||
| private volatile long lastRepeatTimestamp; | ||
| private volatile int consecutiveRepeatCount = 0; | ||
|
|
||
| public LinkedList<Location> getMovementHistory() { | ||
| return movementHistory; | ||
| public synchronized void processMovement(Location current, double maxRadius) { | ||
| long now = System.currentTimeMillis(); | ||
|
|
||
| if (confinementStartLocation == null) { | ||
| resetConfinement(current, now); | ||
| return; | ||
| } | ||
|
|
||
| if (!isInsideRadius(current, confinementStartLocation, maxRadius)) { | ||
| resetConfinement(current, now); | ||
| return; | ||
| } | ||
|
|
||
| if (lastMoveLocation != null && Objects.equals(lastMoveLocation.getWorld(), current.getWorld())) { | ||
| totalDistanceTraveled += current.distance(lastMoveLocation); | ||
| } | ||
|
|
||
| lastMoveLocation = current; | ||
| } | ||
|
|
||
| public long getLastRepeatTimestamp() { | ||
| return lastRepeatTimestamp; | ||
| private void resetConfinement(Location current, long timestamp) { | ||
| this.confinementStartLocation = current; | ||
| this.lastMoveLocation = current; | ||
| this.confinementStartTime = timestamp; | ||
| this.totalDistanceTraveled = 0.0; | ||
| } | ||
|
|
||
| public void setLastRepeatTimestamp(long lastRepeatTimestamp) { | ||
| this.lastRepeatTimestamp = lastRepeatTimestamp; | ||
| private boolean isInsideRadius(Location loc1, Location loc2, double radius) { | ||
| if (!Objects.equals(loc1.getWorld(), loc2.getWorld())) return false; | ||
| return loc1.distanceSquared(loc2) <= (radius * radius); | ||
| } | ||
|
|
||
| public int getConsecutiveRepeatCount() { | ||
| return consecutiveRepeatCount; | ||
| public synchronized long getConfinementDuration() { | ||
| return (confinementStartLocation == null) ? 0 : System.currentTimeMillis() - confinementStartTime; | ||
| } | ||
|
|
||
| public void setConsecutiveRepeatCount(int consecutiveRepeatCount) { | ||
| this.consecutiveRepeatCount = consecutiveRepeatCount; | ||
| public synchronized double getTotalDistanceTraveled() { | ||
| return totalDistanceTraveled; | ||
| } | ||
|
|
||
| /** | ||
| * Oyuncunun tüm analiz verilerini sıfırlar. | ||
| * Bu metot, oyuncu AFK olarak işaretlendiğinde veya bilinçli bir aktivite | ||
| * (sohbet, envanter açma vb.) göstererek kalıbı bozduğunda çağrılır. | ||
| */ | ||
| public void reset() { | ||
| public LinkedList<Location> getMovementHistory() { | ||
| return movementHistory; | ||
| } | ||
|
|
||
| public long getLastRepeatTimestamp() { return lastRepeatTimestamp; } | ||
| public void setLastRepeatTimestamp(long lastRepeatTimestamp) { this.lastRepeatTimestamp = lastRepeatTimestamp; } | ||
|
|
||
| public int getConsecutiveRepeatCount() { return consecutiveRepeatCount; } | ||
| public void setConsecutiveRepeatCount(int consecutiveRepeatCount) { this.consecutiveRepeatCount = consecutiveRepeatCount; } | ||
|
|
||
| public synchronized void reset() { | ||
| this.movementHistory.clear(); | ||
| this.lastRepeatTimestamp = 0; | ||
| this.consecutiveRepeatCount = 0; | ||
| this.confinementStartLocation = null; | ||
| this.totalDistanceTraveled = 0; | ||
| this.lastMoveLocation = null; | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
70 changes: 70 additions & 0 deletions
70
AntiAFK-Core/src/test/java/com/bentahsin/antiafk/behavior/ConfinementDetectionTest.java
This file contains hidden or 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,70 @@ | ||
| package com.bentahsin.antiafk.behavior; | ||
|
|
||
| import org.bukkit.Location; | ||
| import org.bukkit.World; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.Mock; | ||
| import org.mockito.MockitoAnnotations; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
| import static org.mockito.Mockito.*; | ||
|
|
||
| class ConfinementDetectionTest { | ||
|
|
||
| private PlayerBehaviorData behaviorData; | ||
| @Mock private World mockWorld; | ||
| @Mock private Location loc1; | ||
| @Mock private Location loc2; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| MockitoAnnotations.openMocks(this); | ||
| behaviorData = new PlayerBehaviorData(); | ||
|
|
||
| when(loc1.getWorld()).thenReturn(mockWorld); | ||
| when(loc2.getWorld()).thenReturn(mockWorld); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Pozitif Tespit: Oyuncu dar alanda çok hareket ederse yakalanmalı") | ||
| void testConfinementPositive() { | ||
| behaviorData.processMovement(loc1, 5.0); | ||
|
|
||
| when(loc1.distance(loc2)).thenReturn(2.0); | ||
| when(loc1.distanceSquared(loc2)).thenReturn(4.0); | ||
|
|
||
| for(int i = 0; i < 50; i++) { | ||
| behaviorData.processMovement(loc2, 5.0); | ||
| behaviorData.processMovement(loc1, 5.0); | ||
| } | ||
|
|
||
| assertTrue(behaviorData.getTotalDistanceTraveled() >= 100.0, "Toplam mesafe doğru hesaplanmadı."); | ||
| assertTrue(behaviorData.getConfinementDuration() >= 0); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Negatif Tespit: Oyuncu alanın dışına çıkarsa sayaç sıfırlanmalı") | ||
| void testConfinementResetOnExit() { | ||
| behaviorData.processMovement(loc1, 3.0); | ||
|
|
||
| when(loc1.distanceSquared(loc2)).thenReturn(100.0); | ||
|
|
||
| behaviorData.processMovement(loc2, 3.0); | ||
| assertEquals(0.0, behaviorData.getTotalDistanceTraveled(), 0.001); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Dünya Değişimi: Farklı dünyaya geçerse sistem sıfırlanmalı") | ||
| void testWorldChangeReset() { | ||
| World otherWorld = mock(World.class); | ||
| Location otherWorldLoc = mock(Location.class); | ||
| when(otherWorldLoc.getWorld()).thenReturn(otherWorld); | ||
|
|
||
| behaviorData.processMovement(loc1, 5.0); | ||
| behaviorData.processMovement(otherWorldLoc, 5.0); | ||
|
|
||
| assertEquals(0.0, behaviorData.getTotalDistanceTraveled(), "Dünya değişince veriler sıfırlanmadı."); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.