Code householding + settings migration

- Migrate and remove unused properties in legacy Settings
- Add forgotten space in Register command
- Fix javadoc errors shown on Jenkins
This commit is contained in:
ljacqu
2016-04-15 15:17:58 +02:00
parent 71515f188a
commit 3674ac087c
7 changed files with 60 additions and 81 deletions
@@ -182,8 +182,7 @@ public class AsynchronousLogin implements Process {
// task, we schedule it in the end
// so that we can be sure, and have not to care if it might be
// processed in other order.
ProcessSyncPlayerLogin syncPlayerLogin = new ProcessSyncPlayerLogin(
player, plugin, database, service.getSettings());
ProcessSyncPlayerLogin syncPlayerLogin = new ProcessSyncPlayerLogin(player, plugin, database, service);
if (syncPlayerLogin.getLimbo() != null) {
if (syncPlayerLogin.getLimbo().getTimeoutTask() != null) {
syncPlayerLogin.getLimbo().getTimeoutTask().cancel();
@@ -1,22 +1,7 @@
package fr.xephi.authme.process.login;
import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.potion.PotionEffectType;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import org.apache.commons.lang.reflect.MethodUtils;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.backup.JsonCache;
@@ -28,14 +13,26 @@ import fr.xephi.authme.events.LoginEvent;
import fr.xephi.authme.events.RestoreInventoryEvent;
import fr.xephi.authme.events.SpawnTeleportEvent;
import fr.xephi.authme.listener.AuthMePlayerListener;
import fr.xephi.authme.process.Process;
import fr.xephi.authme.process.ProcessService;
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.util.Utils;
import fr.xephi.authme.util.Utils.GroupType;
import org.apache.commons.lang.reflect.MethodUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.potion.PotionEffectType;
import static fr.xephi.authme.settings.properties.RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN;
import static fr.xephi.authme.settings.properties.PluginSettings.KEEP_COLLISIONS_DISABLED;
import static fr.xephi.authme.settings.properties.RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN;
public class ProcessSyncPlayerLogin implements Runnable {
public class ProcessSyncPlayerLogin implements Process {
private final LimboPlayer limbo;
private final Player player;
@@ -44,7 +41,7 @@ public class ProcessSyncPlayerLogin implements Runnable {
private final AuthMe plugin;
private final PluginManager pm;
private final JsonCache playerCache;
private final NewSetting settings;
private final ProcessService service;
private final boolean restoreCollisions = MethodUtils
.getAccessibleMethod(LivingEntity.class, "setCollidable", new Class[]{}) != null;
@@ -55,10 +52,9 @@ public class ProcessSyncPlayerLogin implements Runnable {
* @param player Player
* @param plugin AuthMe
* @param database DataSource
* @param settings The plugin settings
* @param service The process service
*/
public ProcessSyncPlayerLogin(Player player, AuthMe plugin,
DataSource database, NewSetting settings) {
public ProcessSyncPlayerLogin(Player player, AuthMe plugin, DataSource database, ProcessService service) {
this.plugin = plugin;
this.pm = plugin.getServer().getPluginManager();
this.player = player;
@@ -66,7 +62,7 @@ public class ProcessSyncPlayerLogin implements Runnable {
this.limbo = LimboCache.getInstance().getLimboPlayer(name);
this.auth = database.getAuth(name);
this.playerCache = new JsonCache();
this.settings = settings;
this.service = service;
}
public LimboPlayer getLimbo() {
@@ -99,7 +95,7 @@ public class ProcessSyncPlayerLogin implements Runnable {
}
private void restoreSpeedEffects() {
if (!settings.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT) && settings.getProperty(RestrictionSettings.REMOVE_SPEED)) {
if (!service.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT) && service.getProperty(RestrictionSettings.REMOVE_SPEED)) {
player.setWalkSpeed(0.2F);
player.setFlySpeed(0.1F);
}
@@ -114,10 +110,10 @@ public class ProcessSyncPlayerLogin implements Runnable {
}
private void forceCommands() {
for (String command : Settings.forceCommands) {
for (String command : service.getProperty(RegistrationSettings.FORCE_COMMANDS)) {
player.performCommand(command.replace("%p", player.getName()));
}
for (String command : Settings.forceCommandsAsConsole) {
for (String command : service.getProperty(RegistrationSettings.FORCE_COMMANDS_AS_CONSOLE)) {
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command.replace("%p", player.getName()));
}
}
@@ -155,15 +151,15 @@ public class ProcessSyncPlayerLogin implements Runnable {
}
}
if (restoreCollisions && !settings.getProperty(KEEP_COLLISIONS_DISABLED)) {
if (restoreCollisions && !service.getProperty(KEEP_COLLISIONS_DISABLED)) {
player.setCollidable(true);
}
if (settings.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) {
if (service.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) {
restoreInventory();
}
if (settings.getProperty(RestrictionSettings.HIDE_TABLIST_BEFORE_LOGIN) && plugin.tablistHider != null) {
if (service.getProperty(RestrictionSettings.HIDE_TABLIST_BEFORE_LOGIN) && plugin.tablistHider != null) {
plugin.tablistHider.sendTablist(player);
}
@@ -188,24 +184,24 @@ public class ProcessSyncPlayerLogin implements Runnable {
}
restoreSpeedEffects();
if (settings.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
player.removePotionEffect(PotionEffectType.BLINDNESS);
}
// The Login event now fires (as intended) after everything is processed
Bukkit.getServer().getPluginManager().callEvent(new LoginEvent(player));
player.saveData();
if (settings.getProperty(HooksSettings.BUNGEECORD)) {
if (service.getProperty(HooksSettings.BUNGEECORD)) {
sendBungeeMessage();
}
// Login is done, display welcome message
if (settings.getProperty(RegistrationSettings.USE_WELCOME_MESSAGE)) {
if (settings.getProperty(RegistrationSettings.BROADCAST_WELCOME_MESSAGE)) {
for (String s : settings.getWelcomeMessage()) {
if (service.getProperty(RegistrationSettings.USE_WELCOME_MESSAGE)) {
if (service.getProperty(RegistrationSettings.BROADCAST_WELCOME_MESSAGE)) {
for (String s : service.getSettings().getWelcomeMessage()) {
Bukkit.getServer().broadcastMessage(plugin.replaceAllInfo(s, player));
}
} else {
for (String s : settings.getWelcomeMessage()) {
for (String s : service.getSettings().getWelcomeMessage()) {
player.sendMessage(plugin.replaceAllInfo(s, player));
}
}
@@ -218,10 +214,10 @@ public class ProcessSyncPlayerLogin implements Runnable {
}
private void sendTo() {
if (!settings.getProperty(HooksSettings.BUNGEECORD_SERVER).isEmpty()) {
if (!service.getProperty(HooksSettings.BUNGEECORD_SERVER).isEmpty()) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Connect");
out.writeUTF(settings.getProperty(HooksSettings.BUNGEECORD_SERVER));
out.writeUTF(service.getProperty(HooksSettings.BUNGEECORD_SERVER));
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
}
}
@@ -12,9 +12,11 @@ import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.process.Process;
import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.EmailSettings;
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.settings.properties.SecuritySettings;
import fr.xephi.authme.task.MessageTask;
import fr.xephi.authme.task.TimeoutTask;
import fr.xephi.authme.util.Utils;
@@ -23,6 +25,9 @@ import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitTask;
import static fr.xephi.authme.settings.properties.RestrictionSettings.HIDE_TABLIST_BEFORE_LOGIN;
import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND;
/**
*/
public class ProcessSyncPasswordRegister implements Process {
@@ -49,10 +54,10 @@ public class ProcessSyncPasswordRegister implements Process {
}
private void forceCommands() {
for (String command : Settings.forceRegisterCommands) {
for (String command : service.getProperty(RegistrationSettings.FORCE_REGISTER_COMMANDS)) {
player.performCommand(command.replace("%p", player.getName()));
}
for (String command : Settings.forceRegisterCommandsAsConsole) {
for (String command : service.getProperty(RegistrationSettings.FORCE_REGISTER_COMMANDS_AS_CONSOLE)) {
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
command.replace("%p", player.getName()));
}
@@ -62,7 +67,7 @@ public class ProcessSyncPasswordRegister implements Process {
Utils.teleportToSpawn(player);
LimboCache cache = LimboCache.getInstance();
cache.updateLimboPlayer(player);
int delay = service.getProperty(RestrictionSettings.TIMEOUT) * 20;
int delay = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
int interval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
BukkitTask task;
if (delay != 0) {
@@ -80,15 +85,15 @@ public class ProcessSyncPasswordRegister implements Process {
public void run() {
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name);
if (limbo != null) {
if (Settings.hideTablistBeforeLogin && plugin.tablistHider != null) {
if (service.getProperty(RestrictionSettings.HIDE_TABLIST_BEFORE_LOGIN) && plugin.tablistHider != null) {
plugin.tablistHider.sendTablist(player);
}
Utils.teleportToSpawn(player);
if (Settings.protectInventoryBeforeLogInEnabled && plugin.inventoryProtector != null) {
if (service.getProperty(HIDE_TABLIST_BEFORE_LOGIN) && plugin.inventoryProtector != null) {
RestoreInventoryEvent event = new RestoreInventoryEvent(player);
Bukkit.getPluginManager().callEvent(event);
service.callEvent(event);
if (!event.isCancelled()) {
plugin.inventoryProtector.sendInventoryPacket(player);
}
@@ -103,7 +108,7 @@ public class ProcessSyncPasswordRegister implements Process {
service.send(player, MessageKey.REGISTER_SUCCESS);
if (!Settings.getmailAccount.isEmpty()) {
if (!service.getProperty(EmailSettings.MAIL_ACCOUNT).isEmpty()) {
service.send(player, MessageKey.ADD_EMAIL_MESSAGE);
}
@@ -115,12 +120,12 @@ public class ProcessSyncPasswordRegister implements Process {
plugin.getServer().getPluginManager().callEvent(new LoginEvent(player));
player.saveData();
if (!Settings.noConsoleSpam) {
if (!service.getProperty(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE)) {
ConsoleLogger.info(player.getName() + " registered " + Utils.getPlayerIp(player));
}
// Kick Player after Registration is enabled, kick the player
if (Settings.forceRegKick) {
if (service.getProperty(RegistrationSettings.FORCE_KICK_AFTER_REGISTER)) {
player.kickPlayer(service.retrieveSingleMessage(MessageKey.REGISTER_SUCCESS));
return;
}
@@ -139,12 +144,12 @@ public class ProcessSyncPasswordRegister implements Process {
}
// Request Login after Registration
if (Settings.forceRegLogin) {
if (service.getProperty(RegistrationSettings.FORCE_LOGIN_AFTER_REGISTER)) {
forceLogin(player);
return;
}
if (Settings.bungee) {
if (service.getProperty(HooksSettings.BUNGEECORD)) {
sendBungeeMessage();
}