mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-01-26 01:21:27 +01:00
Fix codestyle, add test
This commit is contained in:
parent
c7c8e673f0
commit
610fed3c7b
@ -41,7 +41,7 @@ public class ServerListener implements Listener {
|
|||||||
pluginHookService.unhookEssentials();
|
pluginHookService.unhookEssentials();
|
||||||
ConsoleLogger.info("Essentials has been disabled: unhooking");
|
ConsoleLogger.info("Essentials has been disabled: unhooking");
|
||||||
} else if ("CMI".equalsIgnoreCase(pluginName)) {
|
} else if ("CMI".equalsIgnoreCase(pluginName)) {
|
||||||
pluginHookService.unhookCMI();
|
pluginHookService.unhookCmi();
|
||||||
spawnLoader.unloadCMISpawn();
|
spawnLoader.unloadCMISpawn();
|
||||||
ConsoleLogger.info("CMI has been disabled: unhooking");
|
ConsoleLogger.info("CMI has been disabled: unhooking");
|
||||||
} else if ("Multiverse-Core".equalsIgnoreCase(pluginName)) {
|
} else if ("Multiverse-Core".equalsIgnoreCase(pluginName)) {
|
||||||
@ -75,7 +75,7 @@ public class ServerListener implements Listener {
|
|||||||
} else if ("EssentialsSpawn".equalsIgnoreCase(pluginName)) {
|
} else if ("EssentialsSpawn".equalsIgnoreCase(pluginName)) {
|
||||||
spawnLoader.loadEssentialsSpawn();
|
spawnLoader.loadEssentialsSpawn();
|
||||||
} else if ("CMI".equalsIgnoreCase(pluginName)) {
|
} else if ("CMI".equalsIgnoreCase(pluginName)) {
|
||||||
pluginHookService.tryHookToCMI();
|
pluginHookService.tryHookToCmi();
|
||||||
spawnLoader.loadCMISpawn();
|
spawnLoader.loadCMISpawn();
|
||||||
} else if ("ProtocolLib".equalsIgnoreCase(pluginName)) {
|
} else if ("ProtocolLib".equalsIgnoreCase(pluginName)) {
|
||||||
protocolLibService.setup();
|
protocolLibService.setup();
|
||||||
|
@ -34,7 +34,7 @@ public class PluginHookService {
|
|||||||
public PluginHookService(PluginManager pluginManager) {
|
public PluginHookService(PluginManager pluginManager) {
|
||||||
this.pluginManager = pluginManager;
|
this.pluginManager = pluginManager;
|
||||||
tryHookToEssentials();
|
tryHookToEssentials();
|
||||||
tryHookToCMI();
|
tryHookToCmi();
|
||||||
tryHookToMultiverse();
|
tryHookToMultiverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ public class PluginHookService {
|
|||||||
*
|
*
|
||||||
* @return The CMI data folder, or null if unavailable
|
* @return The CMI data folder, or null if unavailable
|
||||||
*/
|
*/
|
||||||
public File getCMIDataFolder() {
|
public File getCmiDataFolder() {
|
||||||
Plugin plugin = pluginManager.getPlugin("CMI");
|
Plugin plugin = pluginManager.getPlugin("CMI");
|
||||||
if(plugin == null) {
|
if(plugin == null) {
|
||||||
return null;
|
return null;
|
||||||
@ -105,7 +105,7 @@ public class PluginHookService {
|
|||||||
/**
|
/**
|
||||||
* @return true if we have a hook to CMI, false otherwise
|
* @return true if we have a hook to CMI, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean isCMIAvailable() {
|
public boolean isCmiAvailable() {
|
||||||
return cmi != null;
|
return cmi != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ public class PluginHookService {
|
|||||||
/**
|
/**
|
||||||
* Attempts to create a hook into CMI.
|
* Attempts to create a hook into CMI.
|
||||||
*/
|
*/
|
||||||
public void tryHookToCMI() {
|
public void tryHookToCmi() {
|
||||||
try {
|
try {
|
||||||
cmi = getPlugin(pluginManager, "CMI", Plugin.class);
|
cmi = getPlugin(pluginManager, "CMI", Plugin.class);
|
||||||
} catch (Exception | NoClassDefFoundError ignored) {
|
} catch (Exception | NoClassDefFoundError ignored) {
|
||||||
@ -167,7 +167,7 @@ public class PluginHookService {
|
|||||||
/**
|
/**
|
||||||
* Unhooks from CMI.
|
* Unhooks from CMI.
|
||||||
*/
|
*/
|
||||||
public void unhookCMI() {
|
public void unhookCmi() {
|
||||||
cmi = null;
|
cmi = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ public class SpawnLoader implements Reloadable {
|
|||||||
* Load the spawn point defined in CMI.
|
* Load the spawn point defined in CMI.
|
||||||
*/
|
*/
|
||||||
public void loadCMISpawn() {
|
public void loadCMISpawn() {
|
||||||
File cmiFolder = pluginHookService.getCMIDataFolder();
|
File cmiFolder = pluginHookService.getCmiDataFolder();
|
||||||
if (cmiFolder == null) {
|
if (cmiFolder == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ public class ServerListenerTest {
|
|||||||
checkEnableHandling(ESSENTIALS, () -> verify(pluginHookService).tryHookToEssentials());
|
checkEnableHandling(ESSENTIALS, () -> verify(pluginHookService).tryHookToEssentials());
|
||||||
checkEnableHandling(ESSENTIALS_SPAWN, () -> verify(spawnLoader).loadEssentialsSpawn());
|
checkEnableHandling(ESSENTIALS_SPAWN, () -> verify(spawnLoader).loadEssentialsSpawn());
|
||||||
checkEnableHandling(CMI, () -> {
|
checkEnableHandling(CMI, () -> {
|
||||||
verify(pluginHookService).tryHookToCMI();
|
verify(pluginHookService).tryHookToCmi();
|
||||||
verify(spawnLoader).loadCMISpawn();
|
verify(spawnLoader).loadCMISpawn();
|
||||||
});
|
});
|
||||||
checkEnableHandling(MULTIVERSE, () -> verify(pluginHookService).tryHookToMultiverse());
|
checkEnableHandling(MULTIVERSE, () -> verify(pluginHookService).tryHookToMultiverse());
|
||||||
@ -73,7 +73,7 @@ public class ServerListenerTest {
|
|||||||
checkDisableHandling(ESSENTIALS, () -> verify(pluginHookService).unhookEssentials());
|
checkDisableHandling(ESSENTIALS, () -> verify(pluginHookService).unhookEssentials());
|
||||||
checkDisableHandling(ESSENTIALS_SPAWN, () -> verify(spawnLoader).unloadEssentialsSpawn());
|
checkDisableHandling(ESSENTIALS_SPAWN, () -> verify(spawnLoader).unloadEssentialsSpawn());
|
||||||
checkDisableHandling(CMI, () -> {
|
checkDisableHandling(CMI, () -> {
|
||||||
verify(pluginHookService).unhookCMI();
|
verify(pluginHookService).unhookCmi();
|
||||||
verify(spawnLoader).unloadCMISpawn();
|
verify(spawnLoader).unloadCMISpawn();
|
||||||
});
|
});
|
||||||
checkDisableHandling(MULTIVERSE, () -> verify(pluginHookService).unhookMultiverse());
|
checkDisableHandling(MULTIVERSE, () -> verify(pluginHookService).unhookMultiverse());
|
||||||
|
@ -35,6 +35,8 @@ public class PluginHookServiceTest {
|
|||||||
|
|
||||||
/** The plugin name of Essentials. */
|
/** The plugin name of Essentials. */
|
||||||
private static final String ESSENTIALS = "Essentials";
|
private static final String ESSENTIALS = "Essentials";
|
||||||
|
/** The plugin name of CMI. */
|
||||||
|
private static final String CMI = "CMI";
|
||||||
/** The plugin name of Multiverse-Core. */
|
/** The plugin name of Multiverse-Core. */
|
||||||
private static final String MULTIVERSE = "Multiverse-Core";
|
private static final String MULTIVERSE = "Multiverse-Core";
|
||||||
|
|
||||||
@ -71,6 +73,19 @@ public class PluginHookServiceTest {
|
|||||||
assertThat(pluginHookService.isEssentialsAvailable(), equalTo(true));
|
assertThat(pluginHookService.isEssentialsAvailable(), equalTo(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldHookIntoCmiAtInitialization() {
|
||||||
|
// given
|
||||||
|
PluginManager pluginManager = mock(PluginManager.class);
|
||||||
|
setPluginAvailable(pluginManager, CMI, Plugin.class);
|
||||||
|
|
||||||
|
// when
|
||||||
|
PluginHookService pluginHookService = new PluginHookService(pluginManager);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(pluginHookService.isCmiAvailable(), equalTo(true));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldHookIntoMultiverseAtInitialization() {
|
public void shouldHookIntoMultiverseAtInitialization() {
|
||||||
// given
|
// given
|
||||||
@ -175,6 +190,7 @@ public class PluginHookServiceTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(pluginHookService.isEssentialsAvailable(), equalTo(false));
|
assertThat(pluginHookService.isEssentialsAvailable(), equalTo(false));
|
||||||
|
assertThat(pluginHookService.isCmiAvailable(), equalTo(false));
|
||||||
assertThat(pluginHookService.isMultiverseAvailable(), equalTo(false));
|
assertThat(pluginHookService.isMultiverseAvailable(), equalTo(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user