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
commit 76e6d757da
38 changed files with 493 additions and 289 deletions

4
.gitignore vendored
View File

@ -22,10 +22,6 @@ hs_err_pid*
# Include the project's code style settings file
!.idea/codeStyleSettings.xml
# Include the project's dictionary
!.idea/dictionaries/
!.idea/dictionaries/*
# File-based project format:
*.ipr
*.iws

View File

@ -1,7 +0,0 @@
<component name="ProjectDictionaryState">
<dictionary name="Tim">
<words>
<w>authme</w>
</words>
</dictionary>
</component>

39
docs/translations.md Normal file
View File

@ -0,0 +1,39 @@
<!-- AUTO-GENERATED FILE! Do not edit this directly -->
<!-- File auto-generated on Sun Oct 09 09:42:48 CEST 2016. See translations/translations.tpl.md -->
# AuthMe Translations
The following translations are available in AuthMe. Set `messagesLanguage` to the language code
in your config.yml to use the language, or use another language code to start a new translation.
Code | Language | Translated | &nbsp;
---- | -------- | ---------: | ------
[en](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_en.yml) | English | 100% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=66ff66&w=100&h=5&txtpad=1" alt="bar" />
[bg](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_bg.yml) | Bulgarian | 73% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=bb8800&w=73&h=5&txtpad=1" alt="bar" />
[br](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_br.yml) | Brazilian | 100% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=66ff66&w=100&h=5&txtpad=1" alt="bar" />
[cz](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_cz.yml) | Czech | 91% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=88cc33&w=91&h=5&txtpad=1" alt="bar" />
[de](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_de.yml) | German | 97% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=66ee55&w=97&h=5&txtpad=1" alt="bar" />
[es](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_es.yml) | Spanish | 100% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=66ff66&w=100&h=5&txtpad=1" alt="bar" />
[eu](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_eu.yml) | Basque | 66% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=bb7700&w=66&h=5&txtpad=1" alt="bar" />
[fi](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_fi.yml) | Finnish | 70% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=bb8800&w=70&h=5&txtpad=1" alt="bar" />
[fr](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_fr.yml) | French | 97% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=66ee55&w=97&h=5&txtpad=1" alt="bar" />
[gl](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_gl.yml) | Galician | 74% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=bb8800&w=74&h=5&txtpad=1" alt="bar" />
[hu](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_hu.yml) | Hungarian | 100% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=66ff66&w=100&h=5&txtpad=1" alt="bar" />
[id](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_id.yml) | Indonesian | 74% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=bb8800&w=74&h=5&txtpad=1" alt="bar" />
[it](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_it.yml) | Italian | 100% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=66ff66&w=100&h=5&txtpad=1" alt="bar" />
[ko](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_ko.yml) | Korean | 76% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=bb9900&w=76&h=5&txtpad=1" alt="bar" />
[lt](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_lt.yml) | Latvian | 57% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=bb6600&w=57&h=5&txtpad=1" alt="bar" />
[nl](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_nl.yml) | Dutch | 80% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=aaaa11&w=80&h=5&txtpad=1" alt="bar" />
[pl](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_pl.yml) | Polish | 95% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=77dd44&w=95&h=5&txtpad=1" alt="bar" />
[pt](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_pt.yml) | Portuguese | 91% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=88cc33&w=91&h=5&txtpad=1" alt="bar" />
[ru](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_ru.yml) | Russian | 97% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=66ee55&w=97&h=5&txtpad=1" alt="bar" />
[sk](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_sk.yml) | Slovakian | 50% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=bb6600&w=50&h=5&txtpad=1" alt="bar" />
[tr](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_tr.yml) | Turkish | 85% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=99bb22&w=85&h=5&txtpad=1" alt="bar" />
[uk](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_uk.yml) | Ukrainian | 97% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=66ee55&w=97&h=5&txtpad=1" alt="bar" />
[vn](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_vn.yml) | Vietnamese | 85% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=99bb22&w=85&h=5&txtpad=1" alt="bar" />
[zhcn](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_zhcn.yml) | Chinese (China) | 85% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=99bb22&w=85&h=5&txtpad=1" alt="bar" />
[zhhk](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_zhhk.yml) | Chinese (Hong Kong) | 85% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=99bb22&w=85&h=5&txtpad=1" alt="bar" />
[zhtw](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_zhtw.yml) | Chinese (Taiwan) | 85% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg=99bb22&w=85&h=5&txtpad=1" alt="bar" />
---
This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Sun Oct 09 09:42:48 CEST 2016

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.
*

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);
}
}

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;
@ -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);
}
/**

View File

@ -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)) {

View File

@ -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

View File

@ -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)) {

View File

@ -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)) {

View File

@ -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;
}

View File

@ -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();

View File

@ -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);

View File

@ -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":

View File

@ -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;

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!'

View File

@ -5,7 +5,7 @@ import fr.xephi.authme.ReflectionTestUtils;
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.service.ValidationService;
@ -46,7 +46,7 @@ public class NewAPITest {
@Mock
private AuthMe authMe;
@Mock
private PluginHooks pluginHooks;
private PluginHookService pluginHookService;
@Mock
private ValidationService validationService;
@Mock
@ -86,7 +86,7 @@ public class NewAPITest {
public void shouldReturnIfPlayerIsNpc() {
// given
Player player = mock(Player.class);
given(pluginHooks.isNpc(player)).willReturn(true);
given(pluginHookService.isNpc(player)).willReturn(true);
// when
boolean result = api.isNPC(player);

View File

@ -5,7 +5,7 @@ import ch.jalu.injector.testing.DelayedInjectionRunner;
import ch.jalu.injector.testing.InjectDelayed;
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.settings.Settings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.service.ValidationService;
@ -41,7 +41,7 @@ public class ListenerServiceTest {
private DataSource dataSource;
@Mock
private PluginHooks pluginHooks;
private PluginHookService pluginHookService;
@Mock
private PlayerCache playerCache;
@ -161,14 +161,14 @@ public class ListenerServiceTest {
Player player = mockPlayerWithName(playerName);
EntityEvent event = mock(EntityEvent.class);
given(event.getEntity()).willReturn(player);
given(pluginHooks.isNpc(player)).willReturn(true);
given(pluginHookService.isNpc(player)).willReturn(true);
// when
boolean result = listenerService.shouldCancelEvent(event);
// then
assertThat(result, equalTo(false));
verify(pluginHooks).isNpc(player);
verify(pluginHookService).isNpc(player);
}
@Test
@ -215,7 +215,7 @@ public class ListenerServiceTest {
assertThat(result, equalTo(true));
verify(playerCache).isAuthenticated(playerName);
verifyZeroInteractions(dataSource);
verify(pluginHooks).isNpc(player);
verify(pluginHookService).isNpc(player);
}
private static Player mockPlayerWithName(String name) {

View File

@ -1,7 +1,7 @@
package fr.xephi.authme.listener;
import fr.xephi.authme.TestHelper;
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;
@ -41,7 +41,7 @@ public class ServerListenerTest {
private PermissionsManager permissionsManager;
@Mock
private PluginHooks pluginHooks;
private PluginHookService pluginHookService;
@Mock
private ProtocolLibService protocolLibService;
@ -59,7 +59,7 @@ public class ServerListenerTest {
checkEnableHandling(ESSENTIALS, new Runnable() {
@Override
public void run() {
verify(pluginHooks).tryHookToEssentials();
verify(pluginHookService).tryHookToEssentials();
}
});
checkEnableHandling(ESSENTIALS_SPAWN, new Runnable() {
@ -71,13 +71,13 @@ public class ServerListenerTest {
checkEnableHandling(MULTIVERSE, new Runnable() {
@Override
public void run() {
verify(pluginHooks).tryHookToMultiverse();
verify(pluginHookService).tryHookToMultiverse();
}
});
checkEnableHandling(COMBAT_TAG, new Runnable() {
@Override
public void run() {
verify(pluginHooks).tryHookToCombatPlus();
verify(pluginHookService).tryHookToCombatPlus();
}
});
checkEnableHandling(PROTOCOL_LIB, new Runnable() {
@ -99,7 +99,7 @@ public class ServerListenerTest {
checkDisableHandling(ESSENTIALS, new Runnable() {
@Override
public void run() {
verify(pluginHooks).unhookEssentials();
verify(pluginHookService).unhookEssentials();
}
});
checkDisableHandling(ESSENTIALS_SPAWN, new Runnable() {
@ -111,13 +111,13 @@ public class ServerListenerTest {
checkDisableHandling(MULTIVERSE, new Runnable() {
@Override
public void run() {
verify(pluginHooks).unhookMultiverse();
verify(pluginHookService).unhookMultiverse();
}
});
checkDisableHandling(COMBAT_TAG, new Runnable() {
@Override
public void run() {
verify(pluginHooks).unhookCombatPlus();
verify(pluginHookService).unhookCombatPlus();
}
});
checkDisableHandling(PROTOCOL_LIB, new Runnable() {
@ -164,8 +164,8 @@ public class ServerListenerTest {
}
private void verifyNoMoreInteractionsAndReset() {
verifyNoMoreInteractions(permissionsManager, pluginHooks, protocolLibService, spawnLoader);
reset(permissionsManager, pluginHooks, protocolLibService, spawnLoader);
verifyNoMoreInteractions(permissionsManager, pluginHookService, protocolLibService, spawnLoader);
reset(permissionsManager, pluginHookService, protocolLibService, spawnLoader);
}
private static <T extends PluginEvent> T mockEventWithPluginName(Class<T> eventClass, String name) {

View File

@ -1,7 +1,8 @@
package fr.xephi.authme.geoip;
package fr.xephi.authme.service;
import com.maxmind.geoip.Country;
import com.maxmind.geoip.LookupService;
import fr.xephi.authme.service.GeoIpService;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@ -22,12 +23,12 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
/**
* Test for {@link GeoIpManager}.
* Test for {@link GeoIpService}.
*/
@RunWith(MockitoJUnitRunner.class)
public class GeoIpManagerTest {
public class GeoIpServiceTest {
private GeoIpManager geoIpManager;
private GeoIpService geoIpService;
private File dataFolder;
@Mock
private LookupService lookupService;
@ -38,7 +39,7 @@ public class GeoIpManagerTest {
@Before
public void initializeGeoLiteApi() throws IOException {
dataFolder = temporaryFolder.newFolder();
geoIpManager = new GeoIpManager(dataFolder, lookupService);
geoIpService = new GeoIpService(dataFolder, lookupService);
}
@Test
@ -51,7 +52,7 @@ public class GeoIpManagerTest {
given(lookupService.getCountry(ip)).willReturn(country);
// when
String result = geoIpManager.getCountryCode(ip);
String result = geoIpService.getCountryCode(ip);
// then
assertThat(result, equalTo(countryCode));
@ -64,7 +65,7 @@ public class GeoIpManagerTest {
String ip = "127.0.0.1";
// when
String result = geoIpManager.getCountryCode(ip);
String result = geoIpService.getCountryCode(ip);
// then
assertThat(result, equalTo("--"));
@ -81,7 +82,7 @@ public class GeoIpManagerTest {
given(lookupService.getCountry(ip)).willReturn(country);
// when
String result = geoIpManager.getCountryName(ip);
String result = geoIpService.getCountryName(ip);
// then
assertThat(result, equalTo(countryName));
@ -94,7 +95,7 @@ public class GeoIpManagerTest {
String ip = "127.0.0.1";
// when
String result = geoIpManager.getCountryName(ip);
String result = geoIpService.getCountryName(ip);
// then
assertThat(result, equalTo("N/A"));

View File

@ -1,10 +1,11 @@
package fr.xephi.authme.hooks;
package fr.xephi.authme.service;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.User;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import fr.xephi.authme.service.PluginHookService;
import fr.xephi.authme.ReflectionTestUtils;
import fr.xephi.authme.TestHelper;
import org.bukkit.Location;
@ -29,9 +30,9 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
/**
* Test for {@link PluginHooks}.
* Test for {@link PluginHookService}.
*/
public class PluginHooksTest {
public class PluginHookServiceTest {
/** The plugin name of Essentials. */
private static final String ESSENTIALS = "Essentials";
@ -47,15 +48,15 @@ public class PluginHooksTest {
public void shouldHookIntoEssentials() {
// given
PluginManager pluginManager = mock(PluginManager.class);
PluginHooks pluginHooks = new PluginHooks(pluginManager);
PluginHookService pluginHookService = new PluginHookService(pluginManager);
setPluginAvailable(pluginManager, ESSENTIALS, Essentials.class);
assertThat(pluginHooks.isEssentialsAvailable(), equalTo(false));
assertThat(pluginHookService.isEssentialsAvailable(), equalTo(false));
// when
pluginHooks.tryHookToEssentials();
pluginHookService.tryHookToEssentials();
// then
assertThat(pluginHooks.isEssentialsAvailable(), equalTo(true));
assertThat(pluginHookService.isEssentialsAvailable(), equalTo(true));
}
// Note ljacqu 20160312: Cannot test with Multiverse or CombatTagPlus because their classes are declared final
@ -67,10 +68,10 @@ public class PluginHooksTest {
setPluginAvailable(pluginManager, ESSENTIALS, Essentials.class);
// when
PluginHooks pluginHooks = new PluginHooks(pluginManager);
PluginHookService pluginHookService = new PluginHookService(pluginManager);
// then
assertThat(pluginHooks.isEssentialsAvailable(), equalTo(true));
assertThat(pluginHookService.isEssentialsAvailable(), equalTo(true));
}
@Test
@ -80,10 +81,10 @@ public class PluginHooksTest {
setPluginAvailable(pluginManager, MULTIVERSE, MultiverseCore.class);
// when
PluginHooks pluginHooks = new PluginHooks(pluginManager);
PluginHookService pluginHookService = new PluginHookService(pluginManager);
// then
assertThat(pluginHooks.isMultiverseAvailable(), equalTo(true));
assertThat(pluginHookService.isMultiverseAvailable(), equalTo(true));
}
@Test
@ -96,10 +97,10 @@ public class PluginHooksTest {
PluginManager pluginManager = mock(PluginManager.class);
setPluginAvailable(pluginManager, ESSENTIALS, ess);
PluginHooks pluginHooks = new PluginHooks(pluginManager);
PluginHookService pluginHookService = new PluginHookService(pluginManager);
// when
File dataFolder = pluginHooks.getEssentialsDataFolder();
File dataFolder = pluginHookService.getEssentialsDataFolder();
// then
assertThat(dataFolder, equalTo(essDataFolder));
@ -109,10 +110,10 @@ public class PluginHooksTest {
public void shouldReturnNullForUnhookedEssentials() {
// given
PluginManager pluginManager = mock(PluginManager.class);
PluginHooks pluginHooks = new PluginHooks(pluginManager);
PluginHookService pluginHookService = new PluginHookService(pluginManager);
// when
File result = pluginHooks.getEssentialsDataFolder();
File result = pluginHookService.getEssentialsDataFolder();
// then
assertThat(result, nullValue());
@ -129,10 +130,10 @@ public class PluginHooksTest {
PluginManager pluginManager = mock(PluginManager.class);
setPluginAvailable(pluginManager, ESSENTIALS, ess);
PluginHooks pluginHooks = new PluginHooks(pluginManager);
PluginHookService pluginHookService = new PluginHookService(pluginManager);
// when
pluginHooks.setEssentialsSocialSpyStatus(player, true);
pluginHookService.setEssentialsSocialSpyStatus(player, true);
// then
verify(ess).getUser(player);
@ -142,10 +143,10 @@ public class PluginHooksTest {
@Test
public void shouldNotDoAnythingForUnhookedEssentials() {
// given
PluginHooks pluginHooks = new PluginHooks(mock(PluginManager.class));
PluginHookService pluginHookService = new PluginHookService(mock(PluginManager.class));
// when/then
pluginHooks.setEssentialsSocialSpyStatus(mock(Player.class), false);
pluginHookService.setEssentialsSocialSpyStatus(mock(Player.class), false);
}
@Test
@ -154,15 +155,15 @@ public class PluginHooksTest {
PluginManager pluginManager = mock(PluginManager.class);
setPluginAvailable(pluginManager, ESSENTIALS, Essentials.class);
setPluginAvailable(pluginManager, MULTIVERSE, MultiverseCore.class);
PluginHooks pluginHooks = new PluginHooks(pluginManager);
PluginHookService pluginHookService = new PluginHookService(pluginManager);
// when
pluginHooks.unhookEssentials();
pluginHooks.unhookMultiverse();
pluginHookService.unhookEssentials();
pluginHookService.unhookMultiverse();
// then
assertThat(pluginHooks.isEssentialsAvailable(), equalTo(false));
assertThat(pluginHooks.isMultiverseAvailable(), equalTo(false));
assertThat(pluginHookService.isEssentialsAvailable(), equalTo(false));
assertThat(pluginHookService.isMultiverseAvailable(), equalTo(false));
}
@Test
@ -173,23 +174,23 @@ public class PluginHooksTest {
doThrow(IllegalStateException.class).when(pluginManager).getPlugin(anyString());
// when
PluginHooks pluginHooks = new PluginHooks(pluginManager);
PluginHookService pluginHookService = new PluginHookService(pluginManager);
// then
assertThat(pluginHooks.isEssentialsAvailable(), equalTo(false));
assertThat(pluginHooks.isMultiverseAvailable(), equalTo(false));
assertThat(pluginHooks.isCombatTagPlusAvailable(), equalTo(false));
assertThat(pluginHookService.isEssentialsAvailable(), equalTo(false));
assertThat(pluginHookService.isMultiverseAvailable(), equalTo(false));
assertThat(pluginHookService.isCombatTagPlusAvailable(), equalTo(false));
}
@Test
public void shouldReturnNullForUnavailableMultiverse() {
// given
PluginManager pluginManager = mock(PluginManager.class);
PluginHooks pluginHooks = new PluginHooks(pluginManager);
PluginHookService pluginHookService = new PluginHookService(pluginManager);
World world = mock(World.class);
// when
Location result = pluginHooks.getMultiverseSpawn(world);
Location result = pluginHookService.getMultiverseSpawn(world);
// then
assertThat(result, nullValue());
@ -211,10 +212,10 @@ public class PluginHooksTest {
PluginManager pluginManager = mock(PluginManager.class);
setPluginAvailable(pluginManager, MULTIVERSE, multiverse);
PluginHooks pluginHooks = new PluginHooks(pluginManager);
PluginHookService pluginHookService = new PluginHookService(pluginManager);
// when
Location spawn = pluginHooks.getMultiverseSpawn(world);
Location spawn = pluginHookService.getMultiverseSpawn(world);
// then
assertThat(spawn, equalTo(location));
@ -234,10 +235,10 @@ public class PluginHooksTest {
MultiverseCore multiverse = mock(MultiverseCore.class);
setPluginAvailable(pluginManager, MULTIVERSE, multiverse);
given(multiverse.getMVWorldManager()).willReturn(mvWorldManager);
PluginHooks pluginHooks = new PluginHooks(pluginManager);
PluginHookService pluginHookService = new PluginHookService(pluginManager);
// when
Location spawn = pluginHooks.getMultiverseSpawn(world);
Location spawn = pluginHookService.getMultiverseSpawn(world);
// then
assertThat(spawn, nullValue());

View File

@ -5,7 +5,6 @@ import ch.jalu.injector.testing.DelayedInjectionRunner;
import ch.jalu.injector.testing.InjectDelayed;
import com.google.common.base.Strings;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.geoip.GeoIpManager;
import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.PlayerStatePermission;
@ -45,7 +44,7 @@ public class ValidationServiceTest {
@Mock
private PermissionsManager permissionsManager;
@Mock
private GeoIpManager geoIpManager;
private GeoIpService geoIpService;
@BeforeInjecting
public void createService() {
@ -266,7 +265,7 @@ public class ValidationServiceTest {
// then
assertThat(result, equalTo(true));
verifyZeroInteractions(geoIpManager);
verifyZeroInteractions(geoIpService);
}
@Test
@ -275,14 +274,14 @@ public class ValidationServiceTest {
given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(asList("ch", "it"));
given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(Collections.<String>emptyList());
String ip = "127.0.0.1";
given(geoIpManager.getCountryCode(ip)).willReturn("CH");
given(geoIpService.getCountryCode(ip)).willReturn("CH");
// when
boolean result = validationService.isCountryAdmitted(ip);
// then
assertThat(result, equalTo(true));
verify(geoIpManager).getCountryCode(ip);
verify(geoIpService).getCountryCode(ip);
}
@Test
@ -291,14 +290,14 @@ public class ValidationServiceTest {
given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(asList("ch", "it"));
given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(Collections.<String>emptyList());
String ip = "123.45.67.89";
given(geoIpManager.getCountryCode(ip)).willReturn("BR");
given(geoIpService.getCountryCode(ip)).willReturn("BR");
// when
boolean result = validationService.isCountryAdmitted(ip);
// then
assertThat(result, equalTo(false));
verify(geoIpManager).getCountryCode(ip);
verify(geoIpService).getCountryCode(ip);
}
@Test
@ -307,14 +306,14 @@ public class ValidationServiceTest {
given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(Collections.<String>emptyList());
given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(asList("ch", "it"));
String ip = "127.0.0.1";
given(geoIpManager.getCountryCode(ip)).willReturn("BR");
given(geoIpService.getCountryCode(ip)).willReturn("BR");
// when
boolean result = validationService.isCountryAdmitted(ip);
// then
assertThat(result, equalTo(true));
verify(geoIpManager).getCountryCode(ip);
verify(geoIpService).getCountryCode(ip);
}
@Test
@ -323,14 +322,14 @@ public class ValidationServiceTest {
given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(Collections.<String>emptyList());
given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(asList("ch", "it"));
String ip = "123.45.67.89";
given(geoIpManager.getCountryCode(ip)).willReturn("IT");
given(geoIpService.getCountryCode(ip)).willReturn("IT");
// when
boolean result = validationService.isCountryAdmitted(ip);
// then
assertThat(result, equalTo(false));
verify(geoIpManager).getCountryCode(ip);
verify(geoIpService).getCountryCode(ip);
}
private static void assertErrorEquals(ValidationResult validationResult, MessageKey messageKey, String... args) {

View File

@ -6,7 +6,7 @@ import ch.jalu.injector.testing.InjectDelayed;
import com.google.common.io.Files;
import fr.xephi.authme.TestHelper;
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.settings.properties.RestrictionSettings;
import org.bukkit.Location;
@ -42,7 +42,7 @@ public class SpawnLoaderTest {
private DataSource dataSource;
@Mock
private PluginHooks pluginHooks;
private PluginHookService pluginHookService;
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();

View File

@ -1,22 +1,25 @@
package tools.docs;
import com.google.common.collect.ImmutableSet;
import tools.commands.CommandPageCreater;
import tools.hashmethods.HashAlgorithmsDescriptionTask;
import tools.permissions.PermissionsListWriter;
import tools.docs.commands.CommandPageCreater;
import tools.docs.hashmethods.HashAlgorithmsDescriptionTask;
import tools.docs.permissions.PermissionsListWriter;
import tools.docs.translations.TranslationPageGenerator;
import tools.utils.AutoToolTask;
import tools.utils.ToolTask;
import java.util.Scanner;
import java.util.Set;
import java.util.function.Consumer;
/**
* Task that runs all tasks which update files in the docs folder.
*/
public class UpdateDocsTask implements AutoToolTask {
private static final Set<Class<? extends ToolTask>> TASKS = ImmutableSet.<Class<? extends ToolTask>>of(
CommandPageCreater.class, HashAlgorithmsDescriptionTask.class, PermissionsListWriter.class);
private static final Set<Class<? extends ToolTask>> TASKS = ImmutableSet
.of(CommandPageCreater.class, HashAlgorithmsDescriptionTask.class,
PermissionsListWriter.class, TranslationPageGenerator.class);
@Override
public String getTaskName() {
@ -25,22 +28,14 @@ public class UpdateDocsTask implements AutoToolTask {
@Override
public void execute(final Scanner scanner) {
executeTasks(new TaskRunner() {
@Override
public void execute(ToolTask task) {
task.execute(scanner);
}
});
executeTasks(task -> task.execute(scanner));
}
@Override
public void executeDefault() {
executeTasks(new TaskRunner() {
@Override
public void execute(ToolTask task) {
if (task instanceof AutoToolTask) {
((AutoToolTask) task).executeDefault();
}
executeTasks(task -> {
if (task instanceof AutoToolTask) {
((AutoToolTask) task).executeDefault();
}
});
}
@ -49,24 +44,15 @@ public class UpdateDocsTask implements AutoToolTask {
try {
return clazz.newInstance();
} catch (IllegalAccessException | InstantiationException e) {
throw new UnsupportedOperationException(e);
throw new UnsupportedOperationException("Could not instantiate task class '" + clazz + "'", e);
}
}
private static void executeTasks(TaskRunner runner) {
private static void executeTasks(Consumer<ToolTask> taskRunner) {
for (Class<? extends ToolTask> taskClass : TASKS) {
try {
ToolTask task = instantiateTask(taskClass);
System.out.println("\nRunning " + task.getTaskName() + "\n-------------------");
runner.execute(task);
} catch (UnsupportedOperationException e) {
System.err.println("Error running task of class '" + taskClass + "'");
e.printStackTrace();
}
ToolTask task = instantiateTask(taskClass);
System.out.println("\nRunning " + task.getTaskName() + "\n-------------------");
taskRunner.accept(task);
}
}
private interface TaskRunner {
void execute(ToolTask task);
}
}

View File

@ -1,4 +1,4 @@
package tools.commands;
package tools.docs.commands;
import fr.xephi.authme.command.CommandArgumentDescription;
import fr.xephi.authme.command.CommandDescription;
@ -37,7 +37,7 @@ public class CommandPageCreater implements AutoToolTask {
addCommandsInfo(commandTags, baseCommands);
FileUtils.generateFileFromTemplate(
ToolsConstants.TOOLS_SOURCE_ROOT + "commands/commands.tpl.md",
ToolsConstants.TOOLS_SOURCE_ROOT + "docs/commands/commands.tpl.md",
OUTPUT_FILE,
TagValueHolder.create().put("commands", commandTags));
System.out.println("Wrote to '" + OUTPUT_FILE + "' with " + baseCommands.size() + " base commands.");

View File

@ -1,8 +1,9 @@
package tools.hashmethods;
package tools.docs.hashmethods;
import ch.jalu.injector.Injector;
import ch.jalu.injector.InjectorBuilder;
import com.github.authme.configme.properties.Property;
import com.google.common.collect.ImmutableSet;
import fr.xephi.authme.security.HashAlgorithm;
import fr.xephi.authme.security.crypts.EncryptionMethod;
import fr.xephi.authme.security.crypts.HexSaltedMethod;
@ -19,7 +20,6 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import static com.google.common.collect.Sets.newHashSet;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -30,9 +30,8 @@ import static org.mockito.Mockito.when;
*/
public class EncryptionMethodInfoGatherer {
@SuppressWarnings("unchecked")
private final static Set<Class<? extends Annotation>> RELEVANT_ANNOTATIONS =
newHashSet(HasSalt.class, Recommendation.class, AsciiRestricted.class);
ImmutableSet.of(HasSalt.class, Recommendation.class, AsciiRestricted.class);
private static Injector injector = createInitializer();

View File

@ -1,4 +1,4 @@
package tools.hashmethods;
package tools.docs.hashmethods;
import fr.xephi.authme.security.HashAlgorithm;
import tools.utils.AutoToolTask;
@ -17,7 +17,7 @@ import java.util.Scanner;
*/
public class HashAlgorithmsDescriptionTask implements AutoToolTask {
private static final String CUR_FOLDER = ToolsConstants.TOOLS_SOURCE_ROOT + "hashmethods/";
private static final String CUR_FOLDER = ToolsConstants.TOOLS_SOURCE_ROOT + "docs/hashmethods/";
private static final String OUTPUT_FILE = ToolsConstants.DOCS_FOLDER + "hash_algorithms.md";
@Override

View File

@ -1,4 +1,4 @@
package tools.hashmethods;
package tools.docs.hashmethods;
import fr.xephi.authme.security.crypts.EncryptionMethod;
import fr.xephi.authme.security.crypts.description.SaltType;

View File

@ -1,18 +1,14 @@
package tools.permissions;
package tools.docs.permissions;
import fr.xephi.authme.permission.AdminPermission;
import fr.xephi.authme.ClassCollector;
import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.permission.PlayerStatePermission;
import tools.utils.FileUtils;
import tools.utils.ToolsConstants;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -31,36 +27,22 @@ public class PermissionNodesGatherer {
+ "(.*?)\\s+\\*/" // Capture everything until we encounter '*/'
+ "\\s+([A-Z_]+)\\("); // Match the enum name (e.g. 'LOGIN'), until before the first '('
/**
* Return a sorted collection of all permission nodes.
*
* @return AuthMe permission nodes sorted alphabetically
*/
public Set<String> gatherNodes() {
Set<String> nodes = new TreeSet<>();
for (PermissionNode perm : PlayerPermission.values()) {
nodes.add(perm.getNode());
}
for (PermissionNode perm : AdminPermission.values()) {
nodes.add(perm.getNode());
}
return nodes;
}
/**
* Return a sorted collection of all permission nodes, including its JavaDoc description.
*
* @return Ordered map whose keys are the permission nodes and the values the associated JavaDoc
*/
public Map<String, String> gatherNodesWithJavaDoc() {
public <T extends Enum<T> & PermissionNode> Map<String, String> gatherNodesWithJavaDoc() {
Map<String, String> result = new TreeMap<>();
result.put("authme.admin.*", "Give access to all admin commands.");
result.put("authme.player.*", "Permission to use all player (non-admin) commands.");
// TODO ljacqu 20160109: Add authme.player.email manual description?
result.put("authme.player.email", "Grants all email permissions.");
addDescriptionsForClass(PlayerPermission.class, result);
addDescriptionsForClass(AdminPermission.class, result);
addDescriptionsForClass(PlayerStatePermission.class, result);
new ClassCollector(ToolsConstants.MAIN_SOURCE_ROOT, "")
.collectClasses(PermissionNode.class)
.stream()
.filter(Class::isEnum)
.forEach(clz -> addDescriptionsForClass((Class<T>) clz, result));
return result;
}

View File

@ -1,4 +1,4 @@
package tools.permissions;
package tools.docs.permissions;
import tools.utils.AutoToolTask;
import tools.utils.FileUtils;
@ -8,7 +8,6 @@ import tools.utils.ToolsConstants;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
/**
* Task responsible for formatting a permissions node list and
@ -16,6 +15,7 @@ import java.util.Set;
*/
public class PermissionsListWriter implements AutoToolTask {
private static final String TEMPLATE_FILE = ToolsConstants.TOOLS_SOURCE_ROOT + "docs/permissions/permission_nodes.tpl.md";
private static final String PERMISSIONS_OUTPUT_FILE = ToolsConstants.DOCS_FOLDER + "permission_nodes.md";
@Override
@ -25,23 +25,7 @@ public class PermissionsListWriter implements AutoToolTask {
@Override
public void execute(Scanner scanner) {
// Ask if result should be written to file
System.out.println("Include description? [Enter 'n' for no]");
boolean includeDescription = !matches("n", scanner);
boolean writeToFile = false;
if (includeDescription) {
System.out.println("Write to file? [Enter 'n' for no]");
writeToFile = !matches("n", scanner);
}
if (!includeDescription) {
outputSimpleList();
} else if (writeToFile) {
generateAndWriteFile();
} else {
System.out.println(generatePermissionsList());
}
generateAndWriteFile();
}
@Override
@ -53,8 +37,7 @@ public class PermissionsListWriter implements AutoToolTask {
final NestedTagValue permissionsTagValue = generatePermissionsList();
TagValueHolder tags = TagValueHolder.create().put("nodes", permissionsTagValue);
FileUtils.generateFileFromTemplate(
ToolsConstants.TOOLS_SOURCE_ROOT + "permissions/permission_nodes.tpl.md", PERMISSIONS_OUTPUT_FILE, tags);
FileUtils.generateFileFromTemplate(TEMPLATE_FILE, PERMISSIONS_OUTPUT_FILE, tags);
System.out.println("Wrote to '" + PERMISSIONS_OUTPUT_FILE + "'");
System.out.println("Before committing, please verify the output!");
}
@ -70,20 +53,4 @@ public class PermissionsListWriter implements AutoToolTask {
}
return permissionTags;
}
private static void outputSimpleList() {
PermissionNodesGatherer gatherer = new PermissionNodesGatherer();
Set<String> nodes = gatherer.gatherNodes();
for (String node : nodes) {
System.out.println(node);
}
System.out.println();
System.out.println("Total: " + nodes.size());
}
private static boolean matches(String answer, Scanner sc) {
String userInput = sc.nextLine();
return answer.equalsIgnoreCase(userInput);
}
}

View File

@ -0,0 +1,143 @@
package tools.docs.translations;
import com.google.common.collect.ImmutableMap;
import tools.docs.translations.TranslationsGatherer.TranslationInfo;
import tools.utils.AutoToolTask;
import tools.utils.FileUtils;
import tools.utils.TagValue.NestedTagValue;
import tools.utils.TagValueHolder;
import tools.utils.ToolsConstants;
import java.util.Arrays;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;
import static com.google.common.base.Objects.firstNonNull;
/**
* Generates the translations page in docs.
*/
public class TranslationPageGenerator implements AutoToolTask {
private static final String DOCS_PAGE = ToolsConstants.DOCS_FOLDER + "translations.md";
private static final String TEMPLATE_FILE = ToolsConstants.TOOLS_SOURCE_ROOT + "docs/translations/translations.tpl.md";
private static final Map<String, String> LANGUAGE_NAMES = buildLanguageNames();
// Color configuration for the bars shown next to translation percentage
/**
* Percentage threshold under which the color will be computed from COLOR_0 to COLOR_1;
* above which COLOR_1 to COLOR_2 is used.
*/
private static final int COLOR_1_PERCENTAGE = 75;
// Colors are in RGB format, displayed as an int array of three values whose entries are in the range [0, 15].
private static final int[] COLOR_0 = { 9, 0, 0};
private static final int[] COLOR_1 = {12, 9, 0};
private static final int[] COLOR_2 = { 6, 15, 6};
private final TranslationsGatherer gatherer = new TranslationsGatherer();
@Override
public String getTaskName() {
return "updateTranslations";
}
@Override
public void execute(Scanner scanner) {
executeDefault();
}
@Override
public void executeDefault() {
NestedTagValue translationValuesHolder = new NestedTagValue();
for (TranslationInfo translation : gatherer.getTranslationInfo()) {
int percentage = (int) Math.round(translation.percentTranslated * 100);
String name = firstNonNull(LANGUAGE_NAMES.get(translation.code), "?");
TagValueHolder valueHolder = TagValueHolder.create()
.put("code", translation.code)
.put("name", name)
.put("percentage", Integer.toString(percentage))
.put("color", computeColor(percentage));
translationValuesHolder.add(valueHolder);
}
TagValueHolder tags = TagValueHolder.create().put("languages", translationValuesHolder);
FileUtils.generateFileFromTemplate(TEMPLATE_FILE, DOCS_PAGE, tags);
}
/**
* Returns the color for the given percentage as a 6-digit hex color code.
*
* @param percentage the percentage to generate a color for
* @return the color
*/
private String computeColor(int percentage) {
int[] color;
if (percentage < COLOR_1_PERCENTAGE) {
color = computeColor(percentage, COLOR_0, COLOR_1, 0, COLOR_1_PERCENTAGE);
} else {
color = computeColor(percentage, COLOR_1, COLOR_2, COLOR_1_PERCENTAGE, 100);
}
return Arrays.stream(color)
.mapToObj(i -> Integer.toString(i, 16))
.map(s -> s + s)
.collect(Collectors.joining());
}
/**
* Computes the color as the transition between two given colors.
*
* @param percentage the percentage to compute the color for
* @param colorA the color at the start of the range
* @param colorB the color at the end of the range
* @param rangeMin range start
* @param rangeMax range end
* @return color for the given percentage
*/
private static int[] computeColor(int percentage, int[] colorA, int[] colorB, int rangeMin, int rangeMax) {
double max = rangeMax - rangeMin;
double n = percentage - rangeMin;
return new int[]{
(int) (colorA[0] + n / max * (colorB[0] - colorA[0])),
(int) (colorA[1] + n / max * (colorB[1] - colorA[1])),
(int) (colorA[2] + n / max * (colorB[2] - colorA[2]))
};
}
/**
* @return map of language code -> language name
*/
private static Map<String, String> buildLanguageNames() {
return ImmutableMap.<String, String>builder()
.put("bg", "Bulgarian")
.put("br", "Brazilian")
.put("cz", "Czech")
.put("de", "German")
.put("en", "English")
.put("es", "Spanish")
.put("eu", "Basque")
.put("fi", "Finnish")
.put("fr", "French")
.put("gl", "Galician")
.put("hu", "Hungarian")
.put("id", "Indonesian")
.put("it", "Italian")
.put("ko", "Korean")
.put("lt", "Latvian")
.put("nl", "Dutch")
.put("pl", "Polish")
.put("pt", "Portuguese")
.put("ru", "Russian")
.put("sk", "Slovakian")
.put("tr", "Turkish")
.put("uk", "Ukrainian")
.put("vn", "Vietnamese")
.put("zhcn", "Chinese (China)")
.put("zhhk", "Chinese (Hong Kong)")
.put("zhtw", "Chinese (Taiwan)")
.build();
}
}

View File

@ -0,0 +1,86 @@
package tools.docs.translations;
import fr.xephi.authme.message.MessageKey;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import tools.utils.ToolsConstants;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Gathers all available translations of AuthMe.
*/
public class TranslationsGatherer {
private static final Pattern MESSAGES_PATTERN = Pattern.compile("messages_([a-z]{2,4})\\.yml");
private static final String MESSAGES_FOLDER = ToolsConstants.MAIN_RESOURCES_ROOT + "messages/";
private List<TranslationInfo> translationInfo = new ArrayList<>();
public TranslationsGatherer() {
gatherTranslations();
translationInfo.sort((e1, e2) -> getCode(e1).compareTo(getCode(e2)));
}
public List<TranslationInfo> getTranslationInfo() {
return translationInfo;
}
private void gatherTranslations() {
File[] files = new File(MESSAGES_FOLDER).listFiles();
if (files == null) {
throw new IllegalStateException("Cannot read files of '" + MESSAGES_FOLDER + "'");
}
for (File file : files) {
String code = getLanguageCode(file.getName());
if (code != null) {
processMessagesFile(code, file);
}
}
}
private void processMessagesFile(String code, File file) {
FileConfiguration configuration = YamlConfiguration.loadConfiguration(file);
int availableMessages = 0;
for (MessageKey key : MessageKey.values()) {
if (configuration.contains(key.getKey())) {
++availableMessages;
}
}
translationInfo.add(new TranslationInfo(code, (double) availableMessages / MessageKey.values().length));
}
private String getLanguageCode(String messagesFile) {
Matcher matcher = MESSAGES_PATTERN.matcher(messagesFile);
if (matcher.find()) {
return matcher.group(1);
}
return null;
}
public static final class TranslationInfo {
public final String code;
public final double percentTranslated;
TranslationInfo(String code, double percentTranslated) {
this.code = code;
this.percentTranslated = percentTranslated;
}
}
/**
* Returns the language code from the translation info for sorting purposes.
* Returns "a" for "en" language code to sort English on top.
*
* @param info the translation info
* @return the language code for sorting
*/
private static String getCode(TranslationInfo info) {
return "en".equals(info.code) ? "a" : info.code;
}
}

View File

@ -0,0 +1,14 @@
<!-- {gen_warning} -->
<!-- File auto-generated on {gen_date}. See translations/translations.tpl.md -->
# AuthMe Translations
The following translations are available in AuthMe. Set `messagesLanguage` to the language code
in your config.yml to use the language, or use another language code to start a new translation.
Code | Language | Translated | &nbsp;
---- | -------- | ---------: | ------
[#languages]
[{code}](https://github.com/AuthMe/AuthMeReloaded/blob/master/src/main/resources/messages/messages_{code}.yml) | {name} | {percentage}% | <img src="https://placeholdit.imgix.net/~text?txtsize=5&bg={color}&w={percentage}&h=5&txtpad=1" alt="bar" />
[/#languages]
{gen_footer}

View File

@ -1,2 +0,0 @@
# About
Helper script to generate a page with an up-to-date list of permission nodes.

View File

@ -3,7 +3,12 @@ package tools.utils;
import java.util.ArrayList;
import java.util.List;
/**
* Value of a tag.
*
* @param <T> the tag value type
* @see TagReplacer
*/
public abstract class TagValue<T> {
private final T value;
@ -18,6 +23,9 @@ public abstract class TagValue<T> {
public abstract boolean isEmpty();
/**
* Text value.
*/
public static final class TextTagValue extends TagValue<String> {
public TextTagValue(String value) {
super(value);
@ -29,9 +37,12 @@ public abstract class TagValue<T> {
}
}
/**
* List value (iterable).
*/
public static final class NestedTagValue extends TagValue<List<TagValueHolder>> {
public NestedTagValue() {
super(new ArrayList<TagValueHolder>());
super(new ArrayList<>());
}
@Override