Create Wrapper as singleton; fix UtilsTest

This commit is contained in:
ljacqu
2015-11-25 22:34:27 +01:00
parent 43a60dc091
commit 498c3342f2
8 changed files with 81 additions and 57 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ public class AntiBot {
private static final AuthMe plugin = AuthMe.getInstance();
private static final Messages messages = plugin.getMessages();
private static Wrapper wrapper = new Wrapper(plugin);
private static Wrapper wrapper = Wrapper.getInstance();
private static final List<String> antibotPlayers = new ArrayList<>();
private static AntiBotStatus antiBotStatus = AntiBotStatus.DISABLED;
@@ -17,7 +17,7 @@ import java.util.Date;
*/
public final class ConsoleLogger {
private static Wrapper wrapper = new Wrapper(AuthMe.getInstance());
private static Wrapper wrapper = Wrapper.getInstance();
private static final DateFormat df = new SimpleDateFormat("[MM-dd HH:mm:ss]");
private ConsoleLogger() {
@@ -17,7 +17,6 @@ public class GeoLiteAPI {
"available at http://www.maxmind.com";
private static final String GEOIP_URL = "http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry" +
"/GeoIP.dat.gz";
private static final Wrapper wrapper = new Wrapper(AuthMe.getInstance());
private static final AuthMe plugin = AuthMe.getInstance();
private static LookupService lookupService;
@@ -26,7 +26,7 @@ import java.util.Collections;
*/
public final class Utils {
private static final AuthMe plugin;
private static AuthMe plugin;
private static Wrapper wrapper;
private static boolean getOnlinePlayersIsCollection = false;
@@ -34,7 +34,7 @@ public final class Utils {
static {
plugin = AuthMe.getInstance();
wrapper = new Wrapper(plugin);
wrapper = Wrapper.getInstance();
initializeOnlinePlayersIsCollectionField();
}
@@ -116,9 +116,10 @@ public final class Utils {
// Get the permissions manager, and make sure it's valid
PermissionsManager permsMan = plugin.getPermissionsManager();
if (permsMan == null)
ConsoleLogger.showError("Failed to access permissions manager instance, shutting down.");
assert permsMan != null;
if (permsMan == null) {
ConsoleLogger.showError("Failed to access permissions manager instance, aborting.");
return false;
}
// Remove old groups
permsMan.removeGroups(player, Arrays.asList(Settings.unRegisteredGroup,
@@ -13,22 +13,31 @@ import java.util.logging.Logger;
*/
public class Wrapper {
private AuthMe authMe;
private static Wrapper singleton;
public Wrapper(AuthMe authMe) {
this.authMe = authMe;
/**
* Package-private constructor for testing purposes to inject a mock instance.
*/
Wrapper() {
}
public static Wrapper getInstance() {
if (singleton == null) {
singleton = new Wrapper();
}
return singleton;
}
public AuthMe getAuthMe() {
return authMe;
return AuthMe.getInstance();
}
public Server getServer() {
return authMe.getServer();
return getAuthMe().getServer();
}
public Logger getLogger() {
return authMe.getLogger();
return getAuthMe().getLogger();
}
public BukkitScheduler getScheduler() {