This repository has been archived by the owner on Apr 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more automatic removals from the AFK list
Players are now being automatically removed from the afklist when they move or they write something in chat Also fixed the additional message that a player is back when he only was removed from the AFKlist due to leaving the server (Before sending a message: checking if the player is still online)
- Loading branch information
Showing
7 changed files
with
69 additions
and
3 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
40 changes: 40 additions & 0 deletions
40
src/de/kiridevs/kiricore/listeners/LISTonAsyncPlayerChatEvent.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,40 @@ | ||
package de.kiridevs.kiricore.listeners; | ||
|
||
import de.kiridevs.kiricore.main.Main; | ||
import de.kiridevs.kiricore.managers.AfkManager; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.AsyncPlayerChatEvent; | ||
|
||
import java.util.concurrent.Callable; | ||
|
||
public class LISTonAsyncPlayerChatEvent implements Listener { | ||
@EventHandler | ||
public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event) { | ||
Player player = event.getPlayer(); | ||
|
||
if (!(AfkManager.isAfk(player))) { return; } // Skip all events where the player isn't AFK to enhance speed | ||
|
||
event.setCancelled(true); // Cancel event so the "player is back" message is sent before the actual chat message is | ||
|
||
if (event.isAsynchronous()) { | ||
// Event was caused by an actual player -> async | ||
// Running sync method AfkManager.markBack(player) from async context: (Needed as another event is fired) | ||
Bukkit.getScheduler().callSyncMethod(Main.getPlugin(), new Callable<>() { | ||
@Override | ||
public Object call() { | ||
AfkManager.markBack(player); | ||
return null; | ||
} | ||
}); | ||
} else { | ||
// Event was caused by another Plugin forcing a player to speak -> sync | ||
AfkManager.markBack(player); | ||
} | ||
|
||
event.setCancelled(false); // Un-cancel event so the players message is sent | ||
|
||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
src/de/kiridevs/kiricore/listeners/LISTonPlayerMoveEvent.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,15 @@ | ||
package de.kiridevs.kiricore.listeners; | ||
|
||
import de.kiridevs.kiricore.managers.AfkManager; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerMoveEvent; | ||
|
||
public class LISTonPlayerMoveEvent implements Listener { | ||
@EventHandler | ||
public void onPlayerMoveEvent(PlayerMoveEvent event) { | ||
Player player = event.getPlayer(); | ||
AfkManager.markBack(player); | ||
} | ||
} |
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