mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-18 08:15:12 +01:00
Minor - fix incorrect javadoc and add unit test for Messages#reload
This commit is contained in:
parent
57da572b23
commit
fcfe26f34d
@ -16,7 +16,7 @@ public class Messages {
|
||||
|
||||
private FileConfiguration configuration;
|
||||
private String fileName;
|
||||
private File defaultFile;
|
||||
private final File defaultFile;
|
||||
private FileConfiguration defaultConfiguration;
|
||||
|
||||
/**
|
||||
@ -91,7 +91,6 @@ public class Messages {
|
||||
* Retrieve the message from the text file.
|
||||
*
|
||||
* @param key The message key to retrieve
|
||||
*
|
||||
* @return The message from the file
|
||||
*/
|
||||
public String retrieveSingle(MessageKey key) {
|
||||
@ -100,6 +99,8 @@ public class Messages {
|
||||
|
||||
/**
|
||||
* Reload the messages manager.
|
||||
*
|
||||
* @param messagesFile The new file to load messages from
|
||||
*/
|
||||
public void reload(File messagesFile) {
|
||||
initializeFile(messagesFile);
|
||||
@ -119,9 +120,7 @@ public class Messages {
|
||||
defaultConfiguration = YamlConfiguration.loadConfiguration(defaultFile);
|
||||
}
|
||||
String message = defaultConfiguration.getString(code);
|
||||
return (message == null)
|
||||
? "Error retrieving message '" + code + "'"
|
||||
: message;
|
||||
return message == null ? getDefaultErrorMessage(code) : message;
|
||||
}
|
||||
|
||||
private static String getDefaultErrorMessage(String code) {
|
||||
|
@ -80,18 +80,17 @@ public class AsynchronousJoin {
|
||||
if (Settings.getMaxJoinPerIp > 0
|
||||
&& !plugin.getPermissionsManager().hasPermission(player, PlayerPermission.ALLOW_MULTIPLE_ACCOUNTS)
|
||||
&& !ip.equalsIgnoreCase("127.0.0.1")
|
||||
&& !ip.equalsIgnoreCase("localhost")) {
|
||||
if (plugin.hasJoinedIp(player.getName(), ip)) {
|
||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
&& !ip.equalsIgnoreCase("localhost")
|
||||
&& plugin.hasJoinedIp(player.getName(), ip)) {
|
||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
player.kickPlayer("A player with the same IP is already in game!");
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
player.kickPlayer("A player with the same IP is already in game!");
|
||||
}
|
||||
|
||||
});
|
||||
return;
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
final Location spawnLoc = plugin.getSpawnLocation(player);
|
||||
final boolean isAuthAvailable = database.isAuthAvailable(name);
|
||||
@ -104,12 +103,9 @@ public class AsynchronousJoin {
|
||||
public void run() {
|
||||
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnLoc, PlayerCache.getInstance().isAuthenticated(name));
|
||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
||||
if (!tpEvent.isCancelled()) {
|
||||
if (player.isOnline() && tpEvent.getTo() != null) {
|
||||
if (tpEvent.getTo().getWorld() != null) {
|
||||
player.teleport(tpEvent.getTo());
|
||||
}
|
||||
}
|
||||
if (!tpEvent.isCancelled() && player.isOnline() && tpEvent.getTo() != null
|
||||
&& tpEvent.getTo().getWorld() != null) {
|
||||
player.teleport(tpEvent.getTo());
|
||||
}
|
||||
}
|
||||
|
||||
@ -155,25 +151,21 @@ public class AsynchronousJoin {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Settings.noTeleport) {
|
||||
if (!needFirstSpawn() && Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) {
|
||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
if (!Settings.noTeleport && !needFirstSpawn() && Settings.isTeleportToSpawnEnabled
|
||||
|| (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) {
|
||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnLoc, PlayerCache.getInstance().isAuthenticated(name));
|
||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
||||
if (!tpEvent.isCancelled()) {
|
||||
if (player.isOnline() && tpEvent.getTo() != null) {
|
||||
if (tpEvent.getTo().getWorld() != null) {
|
||||
player.teleport(tpEvent.getTo());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnLoc, PlayerCache.getInstance().isAuthenticated(name));
|
||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
||||
if (!tpEvent.isCancelled() && player.isOnline() && tpEvent.getTo() != null
|
||||
&& tpEvent.getTo().getWorld() != null) {
|
||||
player.teleport(tpEvent.getTo());
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ public final class TestHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link File} to an existing file from the main (non-test) resources folder.
|
||||
* Return a {@link File} to a file in the JAR's resources (main or test).
|
||||
*
|
||||
* @param path The absolute path to the file
|
||||
* @return The project file
|
||||
|
@ -19,6 +19,7 @@ import static org.hamcrest.Matchers.arrayWithSize;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assume.assumeThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@ -249,4 +250,21 @@ public class MessagesIntegrationTest {
|
||||
// then
|
||||
assertThat(message, containsString("Error retrieving message"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldLoadOtherFile() {
|
||||
// given
|
||||
MessageKey key = MessageKey.WRONG_PASSWORD;
|
||||
// assumption: message comes back as defined in messages_test.yml
|
||||
assumeThat(messages.retrieveSingle(key), equalTo("§cWrong password!"));
|
||||
|
||||
// when
|
||||
messages.reload(TestHelper.getJarFile("/messages_test2.yml"));
|
||||
|
||||
// then
|
||||
assertThat(messages.retrieveSingle(key), equalTo("test2 - wrong password"));
|
||||
// check that default message handling still works
|
||||
assertThat(messages.retrieveSingle(MessageKey.MUST_REGISTER_MESSAGE),
|
||||
equalTo("Message from default file"));
|
||||
}
|
||||
}
|
||||
|
6
src/test/resources/messages_test2.yml
Normal file
6
src/test/resources/messages_test2.yml
Normal file
@ -0,0 +1,6 @@
|
||||
# Sample messages file
|
||||
|
||||
unknown_user: 'Message from test2'
|
||||
unsafe_spawn: 'test2 - unsafe spawn'
|
||||
not_logged_in: 'test2 - not logged in'
|
||||
wrong_pwd: 'test2 - wrong password'
|
Loading…
Reference in New Issue
Block a user