Merge branch 'master' of https://github.com/AuthMe-Team/AuthMeReloaded into 293-translate-help-messages

This commit is contained in:
ljacqu
2016-10-09 15:39:50 +02:00
38 changed files with 493 additions and 289 deletions
+34 -44
View File
@@ -5,7 +5,6 @@ import ch.jalu.injector.InjectorBuilder;
import com.google.common.annotations.VisibleForTesting;
import fr.xephi.authme.api.API;
import fr.xephi.authme.api.NewAPI;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.command.CommandHandler;
import fr.xephi.authme.datasource.DataSource;
@@ -26,6 +25,7 @@ import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.PermissionsSystemType;
import fr.xephi.authme.security.crypts.SHA256;
import fr.xephi.authme.service.BackupService;
import fr.xephi.authme.service.GeoIpService;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
@@ -33,7 +33,6 @@ import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.task.CleanupTask;
import fr.xephi.authme.task.purge.PurgeService;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.geoip.GeoIpManager;
import fr.xephi.authme.service.MigrationService;
import fr.xephi.authme.util.PlayerUtils;
import org.bukkit.Server;
@@ -47,7 +46,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;
import java.io.File;
import java.util.Date;
import static fr.xephi.authme.service.BukkitService.TICKS_PER_MINUTE;
import static fr.xephi.authme.util.Utils.isClassLoaded;
@@ -74,7 +72,7 @@ public class AuthMe extends JavaPlugin {
private DataSource database;
private BukkitService bukkitService;
private Injector injector;
private GeoIpManager geoIpManager;
private GeoIpService geoIpService;
private PlayerCache playerCache;
/**
@@ -134,8 +132,12 @@ public class AuthMe extends JavaPlugin {
*/
@Override
public void onEnable() {
// Load the plugin version data from the plugin description file
loadPluginInfo();
// Initialize the plugin
try {
initializeServices();
initialize();
} catch (Exception e) {
ConsoleLogger.logException("Aborting initialization of AuthMe:", e);
stopOrUnload();
@@ -172,10 +174,27 @@ public class AuthMe extends JavaPlugin {
cleanupTask.runTaskTimerAsynchronously(this, CLEANUP_INTERVAL, CLEANUP_INTERVAL);
}
private void initializeServices() throws Exception {
// Set the plugin instance and load plugin info from the plugin description.
loadPluginInfo();
/**
* Load the version and build number of the plugin from the description file.
*/
private void loadPluginInfo() {
String versionRaw = this.getDescription().getVersion();
int index = versionRaw.lastIndexOf("-");
if (index != -1) {
pluginVersion = versionRaw.substring(0, index);
pluginBuildNumber = versionRaw.substring(index + 1);
if (pluginBuildNumber.startsWith("b")) {
pluginBuildNumber = pluginBuildNumber.substring(1);
}
}
}
/**
* Initialize the plugin and all the services.
*
* @throws Exception if the initialization fails
*/
private void initialize() throws Exception {
// Set the Logger instance and log file path
ConsoleLogger.setLogger(getLogger());
ConsoleLogger.setLogFile(new File(getDataFolder(), LOG_FILENAME));
@@ -211,8 +230,11 @@ public class AuthMe extends JavaPlugin {
instantiateServices(injector);
// Reload support hook
reloadSupportHook();
// TODO: does this still make sense? -sgdc3
// If the server is empty (fresh start) just set all the players as unlogged
if (bukkitService.getOnlinePlayers().size() == 0) {
database.purgeLogged();
}
// Register event listeners
registerEventListeners(injector);
@@ -221,19 +243,6 @@ public class AuthMe extends JavaPlugin {
initializer.scheduleRecallEmailTask(settings, database, messages);
}
// Get version and build number of the plugin
private void loadPluginInfo() {
String versionRaw = this.getDescription().getVersion();
int index = versionRaw.lastIndexOf("-");
if (index != -1) {
pluginVersion = versionRaw.substring(0, index);
pluginBuildNumber = versionRaw.substring(index + 1);
if (pluginBuildNumber.startsWith("b")) {
pluginBuildNumber = pluginBuildNumber.substring(1);
}
}
}
/**
* Instantiates all services.
*
@@ -248,7 +257,7 @@ public class AuthMe extends JavaPlugin {
permsMan = injector.getSingleton(PermissionsManager.class);
bukkitService = injector.getSingleton(BukkitService.class);
commandHandler = injector.getSingleton(CommandHandler.class);
geoIpManager = injector.getSingleton(GeoIpManager.class);
geoIpService = injector.getSingleton(GeoIpService.class);
// Trigger construction of API classes; they will keep track of the singleton
injector.getSingleton(NewAPI.class);
@@ -315,24 +324,6 @@ public class AuthMe extends JavaPlugin {
}
}
// TODO: check this, do we really need it? -sgdc3
private void reloadSupportHook() {
if (database != null) {
int playersOnline = bukkitService.getOnlinePlayers().size();
if (playersOnline == 0) {
database.purgeLogged();
} else if (settings.getProperty(SecuritySettings.USE_RELOAD_COMMAND_SUPPORT)) {
for (PlayerAuth auth : database.getLoggedPlayers()) {
if (auth != null) {
auth.setLastLogin(new Date().getTime());
database.updateSession(auth);
playerCache.addPlayer(auth);
}
}
}
}
}
@Override
public void onDisable() {
// onDisable is also called when we prematurely abort, so any field may be null
@@ -374,10 +365,9 @@ public class AuthMe extends JavaPlugin {
.replace("{SERVER}", server.getServerName())
.replace("{VERSION}", server.getBukkitVersion())
// TODO: We should cache info like this, maybe with a class that extends Player?
.replace("{COUNTRY}", geoIpManager.getCountryName(ipAddress));
.replace("{COUNTRY}", geoIpService.getCountryName(ipAddress));
}
/**
* Handle Bukkit commands.
*
+5 -5
View File
@@ -4,7 +4,7 @@ import fr.xephi.authme.AuthMe;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.hooks.PluginHooks;
import fr.xephi.authme.service.PluginHookService;
import fr.xephi.authme.process.Management;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.crypts.HashedPassword;
@@ -28,7 +28,7 @@ public class API {
private static DataSource dataSource;
private static PasswordSecurity passwordSecurity;
private static Management management;
private static PluginHooks pluginHooks;
private static PluginHookService pluginHookService;
private static ValidationService validationService;
/*
@@ -36,12 +36,12 @@ public class API {
*/
@Inject
API(AuthMe instance, DataSource dataSource, PasswordSecurity passwordSecurity, Management management,
PluginHooks pluginHooks, ValidationService validationService) {
PluginHookService pluginHookService, ValidationService validationService) {
API.instance = instance;
API.dataSource = dataSource;
API.passwordSecurity = passwordSecurity;
API.management = management;
API.pluginHooks = pluginHooks;
API.pluginHookService = pluginHookService;
API.validationService = validationService;
}
@@ -171,7 +171,7 @@ public class API {
* @return true if player is an npc
*/
public boolean isNPC(Player player) {
return pluginHooks.isNpc(player);
return pluginHookService.isNpc(player);
}
}
@@ -4,7 +4,7 @@ import fr.xephi.authme.AuthMe;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.hooks.PluginHooks;
import fr.xephi.authme.service.PluginHookService;
import fr.xephi.authme.process.Management;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.crypts.HashedPassword;
@@ -27,7 +27,7 @@ public class NewAPI {
public static NewAPI singleton;
public final AuthMe plugin;
private final PluginHooks pluginHooks;
private final PluginHookService pluginHookService;
private final DataSource dataSource;
private final PasswordSecurity passwordSecurity;
private final Management management;
@@ -38,10 +38,10 @@ public class NewAPI {
* Constructor for NewAPI.
*/
@Inject
NewAPI(AuthMe plugin, PluginHooks pluginHooks, DataSource dataSource, PasswordSecurity passwordSecurity,
NewAPI(AuthMe plugin, PluginHookService pluginHookService, DataSource dataSource, PasswordSecurity passwordSecurity,
Management management, ValidationService validationService, PlayerCache playerCache) {
this.plugin = plugin;
this.pluginHooks = pluginHooks;
this.pluginHookService = pluginHookService;
this.dataSource = dataSource;
this.passwordSecurity = passwordSecurity;
this.management = management;
@@ -100,7 +100,7 @@ public class NewAPI {
* @return true if the player is an npc
*/
public boolean isNPC(Player player) {
return pluginHooks.isNpc(player);
return pluginHookService.isNpc(player);
}
/**
@@ -5,7 +5,7 @@ import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.data.backup.LimboPlayerStorage;
import fr.xephi.authme.data.limbo.LimboCache;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.hooks.PluginHooks;
import fr.xephi.authme.service.PluginHookService;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.SpawnLoader;
import fr.xephi.authme.settings.properties.RestrictionSettings;
@@ -36,7 +36,7 @@ public class OnShutdownPlayerSaver {
@Inject
private SpawnLoader spawnLoader;
@Inject
private PluginHooks pluginHooks;
private PluginHookService pluginHookService;
@Inject
private PlayerCache playerCache;
@@ -54,7 +54,7 @@ public class OnShutdownPlayerSaver {
private void savePlayer(Player player) {
final String name = player.getName().toLowerCase();
if (pluginHooks.isNpc(player) || validationService.isUnrestricted(name)) {
if (pluginHookService.isNpc(player) || validationService.isUnrestricted(name)) {
return;
}
if (limboCache.hasPlayerData(name)) {
@@ -2,7 +2,7 @@ package fr.xephi.authme.listener;
import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.hooks.PluginHooks;
import fr.xephi.authme.service.PluginHookService;
import fr.xephi.authme.initialization.SettingsDependent;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
@@ -20,17 +20,17 @@ import javax.inject.Inject;
class ListenerService implements SettingsDependent {
private final DataSource dataSource;
private final PluginHooks pluginHooks;
private final PluginHookService pluginHookService;
private final PlayerCache playerCache;
private final ValidationService validationService;
private boolean isRegistrationForced;
@Inject
ListenerService(Settings settings, DataSource dataSource, PluginHooks pluginHooks,
ListenerService(Settings settings, DataSource dataSource, PluginHookService pluginHookService,
PlayerCache playerCache, ValidationService validationService) {
this.dataSource = dataSource;
this.pluginHooks = pluginHooks;
this.pluginHookService = pluginHookService;
this.playerCache = playerCache;
this.validationService = validationService;
reload(settings);
@@ -79,7 +79,7 @@ class ListenerService implements SettingsDependent {
* @return true if the associated event should be canceled, false otherwise
*/
public boolean shouldCancelEvent(Player player) {
return player != null && !checkAuth(player.getName()) && !pluginHooks.isNpc(player);
return player != null && !checkAuth(player.getName()) && !pluginHookService.isNpc(player);
}
@Override
@@ -1,7 +1,7 @@
package fr.xephi.authme.listener;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.hooks.PluginHooks;
import fr.xephi.authme.service.PluginHookService;
import fr.xephi.authme.listener.protocollib.ProtocolLibService;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.settings.SpawnLoader;
@@ -17,7 +17,7 @@ import javax.inject.Inject;
public class ServerListener implements Listener {
@Inject
private PluginHooks pluginHooks;
private PluginHookService pluginHookService;
@Inject
private SpawnLoader spawnLoader;
@Inject
@@ -38,13 +38,13 @@ public class ServerListener implements Listener {
permissionsManager.onPluginDisable(pluginName);
if ("Essentials".equalsIgnoreCase(pluginName)) {
pluginHooks.unhookEssentials();
pluginHookService.unhookEssentials();
ConsoleLogger.info("Essentials has been disabled: unhooking");
} else if ("Multiverse-Core".equalsIgnoreCase(pluginName)) {
pluginHooks.unhookMultiverse();
pluginHookService.unhookMultiverse();
ConsoleLogger.info("Multiverse-Core has been disabled: unhooking");
} else if ("CombatTagPlus".equalsIgnoreCase(pluginName)) {
pluginHooks.unhookCombatPlus();
pluginHookService.unhookCombatPlus();
ConsoleLogger.info("CombatTagPlus has been disabled: unhooking");
} else if ("EssentialsSpawn".equalsIgnoreCase(pluginName)) {
spawnLoader.unloadEssentialsSpawn();
@@ -68,11 +68,11 @@ public class ServerListener implements Listener {
permissionsManager.onPluginEnable(pluginName);
if ("Essentials".equalsIgnoreCase(pluginName)) {
pluginHooks.tryHookToEssentials();
pluginHookService.tryHookToEssentials();
} else if ("Multiverse-Core".equalsIgnoreCase(pluginName)) {
pluginHooks.tryHookToMultiverse();
pluginHookService.tryHookToMultiverse();
} else if ("CombatTagPlus".equalsIgnoreCase(pluginName)) {
pluginHooks.tryHookToCombatPlus();
pluginHookService.tryHookToCombatPlus();
} else if ("EssentialsSpawn".equalsIgnoreCase(pluginName)) {
spawnLoader.loadEssentialsSpawn();
} else if ("ProtocolLib".equalsIgnoreCase(pluginName)) {
@@ -8,7 +8,7 @@ import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.data.limbo.LimboCache;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.events.ProtectInventoryEvent;
import fr.xephi.authme.hooks.PluginHooks;
import fr.xephi.authme.service.PluginHookService;
import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.permission.PlayerStatePermission;
@@ -61,7 +61,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
private SessionManager sessionManager;
@Inject
private PluginHooks pluginHooks;
private PluginHookService pluginHookService;
@Inject
private BukkitService bukkitService;
@@ -95,7 +95,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
}
if (service.getProperty(HooksSettings.DISABLE_SOCIAL_SPY)) {
pluginHooks.setEssentialsSocialSpyStatus(player, false);
pluginHookService.setEssentialsSocialSpyStatus(player, false);
}
if (isNameRestricted(name, ip, player.getAddress().getHostName())) {
@@ -172,7 +172,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
player.setWalkSpeed(0.0f);
}
player.setNoDamageTicks(registrationTimeout);
if (pluginHooks.isEssentialsAvailable() && service.getProperty(HooksSettings.USE_ESSENTIALS_MOTD)) {
if (pluginHookService.isEssentialsAvailable() && service.getProperty(HooksSettings.USE_ESSENTIALS_MOTD)) {
player.performCommand("motd");
}
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
@@ -1,4 +1,4 @@
package fr.xephi.authme.geoip;
package fr.xephi.authme.service;
import com.google.common.annotations.VisibleForTesting;
import com.maxmind.geoip.LookupService;
@@ -17,7 +17,7 @@ import java.net.URLConnection;
import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPInputStream;
public class GeoIpManager {
public class GeoIpService {
private static final String LICENSE =
"[LICENSE] This product uses data from the GeoLite API created by MaxMind, available at http://www.maxmind.com";
private static final String GEOIP_URL =
@@ -28,14 +28,14 @@ public class GeoIpManager {
private final File dataFile;
@Inject
GeoIpManager(@DataFolder File dataFolder) {
GeoIpService(@DataFolder File dataFolder) {
this.dataFile = new File(dataFolder, "GeoIP.dat");
// Fires download of recent data or the initialization of the look up service
isDataAvailable();
}
@VisibleForTesting
GeoIpManager(@DataFolder File dataFolder, LookupService lookupService) {
GeoIpService(@DataFolder File dataFolder, LookupService lookupService) {
this.dataFile = dataFolder;
this.lookupService = lookupService;
}
@@ -1,4 +1,4 @@
package fr.xephi.authme.hooks;
package fr.xephi.authme.service;
import ch.jalu.injector.annotations.NoFieldScan;
import com.earth2me.essentials.Essentials;
@@ -19,7 +19,7 @@ import java.io.File;
* Hooks into third-party plugins and allows to perform actions on them.
*/
@NoFieldScan
public class PluginHooks {
public class PluginHookService {
private final PluginManager pluginManager;
private Essentials essentials;
@@ -32,7 +32,7 @@ public class PluginHooks {
* @param pluginManager The server's plugin manager
*/
@Inject
public PluginHooks(PluginManager pluginManager) {
public PluginHookService(PluginManager pluginManager) {
this.pluginManager = pluginManager;
tryHookToCombatPlus();
tryHookToEssentials();
@@ -2,7 +2,6 @@ package fr.xephi.authme.service;
import com.github.authme.configme.properties.Property;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.geoip.GeoIpManager;
import fr.xephi.authme.initialization.Reloadable;
import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.permission.PermissionsManager;
@@ -36,7 +35,7 @@ public class ValidationService implements Reloadable {
@Inject
private PermissionsManager permissionsManager;
@Inject
private GeoIpManager geoIpManager;
private GeoIpService geoIpService;
private Pattern passwordRegex;
private Set<String> unrestrictedNames;
@@ -115,7 +114,7 @@ public class ValidationService implements Reloadable {
return true;
}
String countryCode = geoIpManager.getCountryCode(hostAddress);
String countryCode = geoIpService.getCountryCode(hostAddress);
return validateWhitelistAndBlacklist(countryCode,
ProtectionSettings.COUNTRIES_WHITELIST,
ProtectionSettings.COUNTRIES_BLACKLIST);
@@ -2,7 +2,7 @@ package fr.xephi.authme.settings;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.hooks.PluginHooks;
import fr.xephi.authme.service.PluginHookService;
import fr.xephi.authme.initialization.DataFolder;
import fr.xephi.authme.initialization.Reloadable;
import fr.xephi.authme.settings.properties.HooksSettings;
@@ -32,7 +32,7 @@ public class SpawnLoader implements Reloadable {
private final File authMeConfigurationFile;
private final Settings settings;
private final PluginHooks pluginHooks;
private final PluginHookService pluginHookService;
private FileConfiguration authMeConfiguration;
private String[] spawnPriority;
private Location essentialsSpawn;
@@ -42,18 +42,18 @@ public class SpawnLoader implements Reloadable {
*
* @param pluginFolder The AuthMe data folder
* @param settings The setting instance
* @param pluginHooks The plugin hooks instance
* @param pluginHookService The plugin hooks instance
* @param dataSource The plugin auth database instance
*/
@Inject
SpawnLoader(@DataFolder File pluginFolder, Settings settings, PluginHooks pluginHooks,
SpawnLoader(@DataFolder File pluginFolder, Settings settings, PluginHookService pluginHookService,
DataSource dataSource) {
File spawnFile = new File(pluginFolder, "spawn.yml");
// TODO ljacqu 20160312: Check if resource could be copied and handle the case if not
FileUtils.copyFileFromResource(spawnFile, "spawn.yml");
this.authMeConfigurationFile = new File(pluginFolder, "spawn.yml");
this.settings = settings;
this.pluginHooks = pluginHooks;
this.pluginHookService = pluginHookService;
reload();
}
@@ -112,7 +112,7 @@ public class SpawnLoader implements Reloadable {
*/
public void loadEssentialsSpawn() {
// EssentialsSpawn cannot run without Essentials, so it's fine to get the Essentials data folder
File essentialsFolder = pluginHooks.getEssentialsDataFolder();
File essentialsFolder = pluginHookService.getEssentialsDataFolder();
if (essentialsFolder == null) {
return;
}
@@ -160,7 +160,7 @@ public class SpawnLoader implements Reloadable {
break;
case "multiverse":
if (settings.getProperty(HooksSettings.MULTIVERSE)) {
spawnLoc = pluginHooks.getMultiverseSpawn(world);
spawnLoc = pluginHookService.getMultiverseSpawn(world);
}
break;
case "essentials":
@@ -2,7 +2,7 @@ package fr.xephi.authme.task.purge;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.hooks.PluginHooks;
import fr.xephi.authme.service.PluginHookService;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.PurgeSettings;
@@ -33,7 +33,7 @@ class PurgeExecutor {
private PermissionsManager permissionsManager;
@Inject
private PluginHooks pluginHooks;
private PluginHookService pluginHookService;
@Inject
private BukkitService bukkitService;
@@ -172,7 +172,7 @@ class PurgeExecutor {
}
int i = 0;
File essentialsDataFolder = pluginHooks.getEssentialsDataFolder();
File essentialsDataFolder = pluginHookService.getEssentialsDataFolder();
if (essentialsDataFolder == null) {
ConsoleLogger.info("Cannot purge Essentials: plugin is not loaded");
return;
+2 -2
View File
@@ -70,5 +70,5 @@ incomplete_email_settings: 'Hiba: nem lett beállítva az össze szükséges be
accounts_owned_other: 'A %name nevű játékosnak, %count db regisztrációja van:'
kicked_admin_registered: 'Adminisztrátor által regisztrálva lettél; kérlek lépj be újra!'
accounts_owned_self: '%count db regisztrációd van:'
# TODO recovery_code_incorrect: 'The recovery code is not correct! Use /email recovery [email] to generate a new one'
# TODO recovery_code_sent: 'A recovery code to reset your password has been sent to your email.'
recovery_code_incorrect: 'A visszaállító kód helytelen volt! Használd a következő parancsot: /email recovery [email címed] egy új generálásához'
recovery_code_sent: 'A jelszavad visszaállításához szükséges kódot sikeresen kiküldtük az email címedre!'