Use injection in and for LimboCache, migrate some legacy settings, remove setGroup from Utils

- New injector method allows to retrieve services if they've already been instantiated -> useful for onDisable() which might be run after aborted initialization
- Deprecate various methods that need to be removed
This commit is contained in:
ljacqu
2016-06-12 16:14:06 +02:00
parent 347d7bcf46
commit d6e1fd5ceb
19 changed files with 226 additions and 198 deletions
@@ -2,6 +2,7 @@ package fr.xephi.authme.process;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.settings.NewSetting;
@@ -102,4 +103,8 @@ public class ProcessService {
return permissionsManager.hasPermission(player, node);
}
public boolean setGroup(Player player, AuthGroupType group) {
return permissionsManager.setGroup(player, group);
}
}
@@ -10,10 +10,10 @@ import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.events.ProtectInventoryEvent;
import fr.xephi.authme.hooks.PluginHooks;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.permission.PlayerStatePermission;
import fr.xephi.authme.process.AsynchronousProcess;
import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.util.TeleportationService;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
@@ -22,8 +22,8 @@ import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.task.MessageTask;
import fr.xephi.authme.task.TimeoutTask;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.TeleportationService;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.util.Utils.GroupType;
import org.apache.commons.lang.reflect.MethodUtils;
import org.bukkit.GameMode;
import org.bukkit.entity.LivingEntity;
@@ -35,6 +35,7 @@ import org.bukkit.scheduler.BukkitTask;
import javax.inject.Inject;
import static fr.xephi.authme.settings.properties.RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN;
import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND;
public class AsynchronousJoin implements AsynchronousProcess {
@@ -116,7 +117,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
final boolean isAuthAvailable = database.isAuthAvailable(name);
if (isAuthAvailable) {
Utils.setGroup(player, GroupType.NOTLOGGEDIN);
service.setGroup(player, AuthGroupType.NOT_LOGGED_IN);
teleportationService.teleportOnJoin(player);
limboCache.updateLimboPlayer(player);
@@ -153,7 +154,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
// Not Registered
// Groups logic
Utils.setGroup(player, GroupType.UNREGISTERED);
service.setGroup(player, AuthGroupType.UNREGISTERED);
// Skip if registration is optional
if (!service.getProperty(RegistrationSettings.FORCE)) {
@@ -168,7 +169,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
limboCache.addLimboPlayer(player);
}
final int registrationTimeout = service.getProperty(RestrictionSettings.TIMEOUT) * 20;
final int registrationTimeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
bukkitService.scheduleSyncDelayedTask(new Runnable() {
@Override
@@ -123,7 +123,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
if (service.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP) > 0
&& !permissionsManager.hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS)
&& !"127.0.0.1".equalsIgnoreCase(ip) && !"localhost".equalsIgnoreCase(ip)) {
if (plugin.isLoggedIp(name, ip)) {
if (isLoggedIp(name, ip)) {
service.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
return null;
}
@@ -254,4 +254,16 @@ public class AsynchronousLogin implements AsynchronousProcess {
}
}
}
private boolean isLoggedIp(String name, String ip) {
int count = 0;
for (Player player : bukkitService.getOnlinePlayers()) {
if (ip.equalsIgnoreCase(Utils.getPlayerIp(player))
&& database.isLogged(player.getName().toLowerCase())
&& !player.getName().equalsIgnoreCase(name)) {
++count;
}
}
return count >= service.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP);
}
}
@@ -10,15 +10,14 @@ import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.events.LoginEvent;
import fr.xephi.authme.events.RestoreInventoryEvent;
import fr.xephi.authme.listener.AuthMePlayerListener;
import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.process.SynchronousProcess;
import fr.xephi.authme.util.TeleportationService;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.util.Utils.GroupType;
import fr.xephi.authme.util.TeleportationService;
import org.apache.commons.lang.reflect.MethodUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity;
@@ -95,7 +94,7 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
if (limbo != null) {
// Restore Op state and Permission Group
restoreOpState(player, limbo);
Utils.setGroup(player, GroupType.LOGGEDIN);
service.setGroup(player, AuthGroupType.LOGGED_IN);
teleportationService.teleportOnLogin(player, auth, limbo);
@@ -5,12 +5,12 @@ import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.process.AsynchronousProcess;
import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.process.SyncProcessManager;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.util.Utils.GroupType;
import org.bukkit.entity.Player;
import javax.inject.Inject;
@@ -63,7 +63,7 @@ public class AsynchronousLogout implements AsynchronousProcess {
limboCache.deleteLimboPlayer(name);
}
limboCache.addLimboPlayer(player);
Utils.setGroup(player, GroupType.NOTLOGGEDIN);
service.setGroup(player, AuthGroupType.NOT_LOGGED_IN);
syncProcessManager.processSyncPlayerLogout(player);
}
}
@@ -10,13 +10,12 @@ import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.process.SynchronousProcess;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.task.MessageTask;
import fr.xephi.authme.task.TimeoutTask;
import fr.xephi.authme.util.BukkitService;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@@ -53,7 +52,7 @@ public class ProcessSynchronousPlayerLogout implements SynchronousProcess {
}
private void restoreSpeedEffect(Player player) {
if (Settings.isRemoveSpeedEnabled) {
if (service.getProperty(RestrictionSettings.REMOVE_SPEED)) {
player.setWalkSpeed(0.0F);
player.setFlySpeed(0.0F);
}
@@ -86,8 +85,8 @@ public class ProcessSynchronousPlayerLogout implements SynchronousProcess {
player.setOp(false);
restoreSpeedEffect(player);
// Player is now logout... Time to fire event !
Bukkit.getServer().getPluginManager().callEvent(new LogoutEvent(player));
if (Settings.bungee) {
bukkitService.callEvent(new LogoutEvent(player));
if (service.getProperty(HooksSettings.BUNGEECORD)) {
sendBungeeMessage(player);
}
service.send(player, MessageKey.LOGOUT_SUCCESS);
@@ -5,6 +5,7 @@ import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.cache.limbo.LimboPlayer;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.process.SynchronousProcess;
import fr.xephi.authme.settings.Settings;
@@ -43,7 +44,7 @@ public class ProcessSyncEmailRegister implements SynchronousProcess {
final String name = player.getName().toLowerCase();
LimboPlayer limbo = limboCache.getLimboPlayer(name);
if (!Settings.getRegisteredGroup.isEmpty()) {
Utils.setGroup(player, Utils.GroupType.REGISTERED);
service.setGroup(player, AuthGroupType.REGISTERED);
}
service.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED);
int time = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
@@ -9,8 +9,9 @@ import fr.xephi.authme.cache.limbo.LimboPlayer;
import fr.xephi.authme.events.LoginEvent;
import fr.xephi.authme.events.RestoreInventoryEvent;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.process.SynchronousProcess;
import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.process.SynchronousProcess;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.EmailSettings;
import fr.xephi.authme.settings.properties.HooksSettings;
@@ -44,6 +45,9 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
@Inject
private BukkitService bukkitService;
@Inject
private LimboCache limboCache;
ProcessSyncPasswordRegister() { }
private void sendBungeeMessage(Player player) {
@@ -73,18 +77,17 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
private void requestLogin(Player player) {
final String name = player.getName().toLowerCase();
Utils.teleportToSpawn(player);
LimboCache cache = LimboCache.getInstance();
cache.updateLimboPlayer(player);
limboCache.updateLimboPlayer(player);
int delay = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
int interval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
BukkitTask task;
if (delay != 0) {
task = bukkitService.runTaskLater(new TimeoutTask(plugin, name, player), delay);
cache.getLimboPlayer(name).setTimeoutTask(task);
limboCache.getLimboPlayer(name).setTimeoutTask(task);
}
task = bukkitService.runTask(new MessageTask(bukkitService, plugin.getMessages(),
name, MessageKey.LOGIN_MESSAGE, interval));
cache.getLimboPlayer(name).setMessageTask(task);
limboCache.getLimboPlayer(name).setMessageTask(task);
if (player.isInsideVehicle() && player.getVehicle() != null) {
player.getVehicle().eject();
}
@@ -92,7 +95,7 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
public void processPasswordRegister(Player player) {
final String name = player.getName().toLowerCase();
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name);
LimboPlayer limbo = limboCache.getLimboPlayer(name);
if (limbo != null) {
if (service.getProperty(RestrictionSettings.HIDE_TABLIST_BEFORE_LOGIN) && plugin.tablistHider != null) {
plugin.tablistHider.sendTablist(player);
@@ -108,11 +111,11 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
}
}
LimboCache.getInstance().deleteLimboPlayer(name);
limboCache.deleteLimboPlayer(name);
}
if (!Settings.getRegisteredGroup.isEmpty()) {
Utils.setGroup(player, Utils.GroupType.REGISTERED);
service.setGroup(player, AuthGroupType.REGISTERED);
}
service.send(player, MessageKey.REGISTER_SUCCESS);
@@ -8,6 +8,7 @@ import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.cache.limbo.LimboPlayer;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.process.AsynchronousProcess;
import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.security.PasswordSecurity;
@@ -18,7 +19,6 @@ import fr.xephi.authme.task.MessageTask;
import fr.xephi.authme.task.TimeoutTask;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.util.Utils.GroupType;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@@ -62,12 +62,12 @@ public class AsynchronousUnregister implements AsynchronousProcess {
return;
}
int timeOut = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
if (Settings.isForcedRegistrationEnabled) {
if (service.getProperty(RegistrationSettings.FORCE)) {
Utils.teleportToSpawn(player);
player.saveData();
playerCache.removePlayer(player.getName().toLowerCase());
if (!Settings.getRegisteredGroup.isEmpty()) {
Utils.setGroup(player, GroupType.UNREGISTERED);
service.setGroup(player, AuthGroupType.UNREGISTERED);
}
limboCache.addLimboPlayer(player);
LimboPlayer limboPlayer = limboCache.getLimboPlayer(name);
@@ -83,7 +83,7 @@ public class AsynchronousUnregister implements AsynchronousProcess {
return;
}
if (!Settings.unRegisteredGroup.isEmpty()) {
Utils.setGroup(player, Utils.GroupType.UNREGISTERED);
service.setGroup(player, AuthGroupType.UNREGISTERED);
}
playerCache.removePlayer(name);