#1113 Create LimboService (work in progress)
- Introduce new LimboService with a higher level abstraction for outside classes to trigger LimboPlayer actions - Add methods to LimboPlayerTaskManager for muting the MessagesTask safely
This commit is contained in:
@@ -2,8 +2,8 @@ package fr.xephi.authme.task;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.data.limbo.LimboCache;
|
||||
import fr.xephi.authme.data.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.data.limbo.LimboService;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.message.Messages;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
@@ -33,7 +33,7 @@ public class LimboPlayerTaskManager {
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Inject
|
||||
private LimboCache limboCache;
|
||||
private LimboService limboService;
|
||||
|
||||
@Inject
|
||||
private PlayerCache playerCache;
|
||||
@@ -53,7 +53,7 @@ public class LimboPlayerTaskManager {
|
||||
final int interval = settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
||||
final MessageKey key = getMessageKey(isRegistered);
|
||||
if (interval > 0) {
|
||||
final LimboPlayer limboPlayer = limboCache.getPlayerData(name);
|
||||
final LimboPlayer limboPlayer = limboService.getLimboPlayer(name);
|
||||
if (limboPlayer == null) {
|
||||
ConsoleLogger.info("PlayerData for '" + name + "' is not available");
|
||||
} else {
|
||||
@@ -73,7 +73,7 @@ public class LimboPlayerTaskManager {
|
||||
public void registerTimeoutTask(Player player) {
|
||||
final int timeout = settings.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
||||
if (timeout > 0) {
|
||||
final LimboPlayer limboPlayer = limboCache.getPlayerData(player.getName());
|
||||
final LimboPlayer limboPlayer = limboService.getLimboPlayer(player.getName());
|
||||
if (limboPlayer == null) {
|
||||
ConsoleLogger.info("PlayerData for '" + player.getName() + "' is not available");
|
||||
} else {
|
||||
@@ -85,6 +85,27 @@ public class LimboPlayerTaskManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void muteMessageTask(Player player) {
|
||||
LimboPlayer limbo = limboService.getLimboPlayer(player.getName());
|
||||
if (limbo != null) {
|
||||
setMuted(limbo.getMessageTask(), true);
|
||||
}
|
||||
}
|
||||
|
||||
public void unmuteMessageTask(Player player) {
|
||||
LimboPlayer limbo = limboService.getLimboPlayer(player.getName());
|
||||
if (limbo != null) {
|
||||
setMuted(limbo.getMessageTask(), false);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearTasks(Player player) {
|
||||
LimboPlayer limbo = limboService.getLimboPlayer(player.getName());
|
||||
if (limbo != null) {
|
||||
limbo.clearTasks();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the appropriate message key according to the registration status and settings.
|
||||
*
|
||||
@@ -120,4 +141,16 @@ public class LimboPlayerTaskManager {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Null-safe method to set the muted flag on a message task.
|
||||
*
|
||||
* @param task the task to modify (or null)
|
||||
* @param isMuted the value to set if task is not null
|
||||
*/
|
||||
private static void setMuted(MessageTask task, boolean isMuted) {
|
||||
if (task != null) {
|
||||
task.setMuted(isMuted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user