-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Init commit * Reverse if * Change PL translation * Update eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/AfkController.java Co-authored-by: Martin Sulikowski <vLuckyyy.biznes@gmail.com> * Revert changes * Follow suggestions * Make classes private * Replace Legacy class with built-in LegacyComponentSerializer using static import. Signed-off-by: Martin Sulikowski <vLuckyyy.biznes@gmail.com> --------- Signed-off-by: Martin Sulikowski <vLuckyyy.biznes@gmail.com> Co-authored-by: Martin Sulikowski <vLuckyyy.biznes@gmail.com>
- Loading branch information
Showing
8 changed files
with
90 additions
and
6 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
68 changes: 68 additions & 0 deletions
68
eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/AfkKickController.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,68 @@ | ||
package com.eternalcode.core.feature.afk; | ||
|
||
import static net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection; | ||
|
||
import com.eternalcode.core.configuration.implementation.PluginConfiguration; | ||
import com.eternalcode.core.feature.afk.event.AfkSwitchEvent; | ||
import com.eternalcode.core.injector.annotations.Inject; | ||
import com.eternalcode.core.injector.annotations.component.Controller; | ||
import com.eternalcode.core.translation.Translation; | ||
import com.eternalcode.core.translation.TranslationManager; | ||
import com.eternalcode.core.user.User; | ||
import com.eternalcode.core.user.UserManager; | ||
import net.kyori.adventure.text.Component; | ||
import net.kyori.adventure.text.minimessage.MiniMessage; | ||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; | ||
import org.bukkit.Server; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
|
||
import java.util.UUID; | ||
|
||
@Controller | ||
class AfkKickController implements Listener { | ||
|
||
private final MiniMessage miniMessage; | ||
private final Server server; | ||
private final UserManager userManager; | ||
private final PluginConfiguration configuration; | ||
private final TranslationManager translationManager; | ||
|
||
@Inject | ||
public AfkKickController( | ||
MiniMessage miniMessage, | ||
Server server, | ||
UserManager userManager, | ||
PluginConfiguration configuration, | ||
TranslationManager translationManager | ||
) { | ||
this.miniMessage = miniMessage; | ||
this.server = server; | ||
this.userManager = userManager; | ||
this.configuration = configuration; | ||
this.translationManager = translationManager; | ||
} | ||
|
||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||
void onAfkSwitch(AfkSwitchEvent event) { | ||
UUID playerUUID = event.getAfk().getPlayer(); | ||
|
||
if (!event.isAfk() || !this.configuration.afk.kickOnAfk) { | ||
return; | ||
} | ||
|
||
Player player = this.server.getPlayer(playerUUID); | ||
|
||
if (player == null) { | ||
return; | ||
} | ||
|
||
User user = this.userManager.getOrCreate(playerUUID, player.getName()); | ||
Translation translation = this.translationManager.getMessages(user); | ||
|
||
Component component = this.miniMessage.deserialize(translation.afk().afkKickReason()); | ||
player.kickPlayer(legacySection().serialize(component)); | ||
} | ||
} |
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