Change some way we let people know of hte language system.

Also added a console command sender to the test setup, just in case we
want to use it later on down the road.
This commit is contained in:
graywolf336 2014-01-14 18:28:02 -06:00
parent cf7c9fc4c2
commit 976149743a
2 changed files with 26 additions and 11 deletions

View File

@ -52,18 +52,14 @@ public class JailIO {
lang = YamlConfiguration.loadConfiguration(langFile); lang = YamlConfiguration.loadConfiguration(langFile);
pl.getLogger().info("Loaded the language: " + language); pl.getLogger().info("Loaded the language: " + language);
}else { }else {
pl.getLogger().severe("The language file can not be a folder, please"); pl.getLogger().severe("The language file can not be a folder.");
pl.getLogger().info("double check your setup. Because of that, we"); pl.getLogger().severe("As a result, we are reverting back to English as the language.");
pl.getLogger().info("are reverting back to English as the language.");
lang = YamlConfiguration.loadConfiguration(pl.getResource("en.yml")); lang = YamlConfiguration.loadConfiguration(pl.getResource("en.yml"));
save = true; save = true;
} }
}else { }else {
pl.getLogger().info("Loading the default language of: en"); pl.getLogger().warning("Loading the default language of: en");
pl.getLogger().info("If you wish to change this,"); pl.getLogger().warning("If you wish to change this, please rename 'en.yml' to whatever you wish and set the config value to the name of the file.");
pl.getLogger().info("please rename 'en.yml' to whatever");
pl.getLogger().info("you wish and set the config value");
pl.getLogger().info("to the name of the file.");
lang = YamlConfiguration.loadConfiguration(pl.getResource("en.yml")); lang = YamlConfiguration.loadConfiguration(pl.getResource("en.yml"));
save = true; save = true;
} }

View File

@ -14,6 +14,7 @@ import org.bukkit.Server;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.WorldCreator; import org.bukkit.WorldCreator;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftItemFactory; import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftItemFactory;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission; import org.bukkit.permissions.Permission;
@ -23,13 +24,10 @@ import org.bukkit.plugin.PluginLogger;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitScheduler;
import org.junit.Assert; import org.junit.Assert;
import org.mockito.Matchers; import org.mockito.Matchers;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito; import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.MockGateway; import org.powermock.core.MockGateway;
import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.PrepareForTest;
@ -45,6 +43,7 @@ public class TestInstanceCreator {
private Server mockServer; private Server mockServer;
private Player mockPlayer; private Player mockPlayer;
private CommandSender mockSender, mockPlayerSender; private CommandSender mockSender, mockPlayerSender;
private ConsoleCommandSender consoleSender;
public static final File serverDirectory = new File("bin" + File.separator + "test" + File.separator + "server"); public static final File serverDirectory = new File("bin" + File.separator + "test" + File.separator + "server");
public static final File worldsDirectory = new File("bin" + File.separator + "test" + File.separator + "server"); public static final File worldsDirectory = new File("bin" + File.separator + "test" + File.separator + "server");
@ -188,6 +187,26 @@ public class TestInstanceCreator {
serverField.setAccessible(true); serverField.setAccessible(true);
serverField.set(main, mockServer); serverField.set(main, mockServer);
// Init our command sender
final Logger consoleSenderLogger = Logger.getLogger("ConsoleCommandSender");
consoleSenderLogger.setParent(Util.logger);
consoleSender = mock(ConsoleCommandSender.class);
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock invocation) throws Throwable {
consoleSenderLogger.info(ChatColor.stripColor((String) invocation.getArguments()[0]));
return null;
}
}).when(consoleSender).sendMessage(anyString());
when(consoleSender.getServer()).thenReturn(mockServer);
when(consoleSender.getName()).thenReturn("MockCommandSender");
when(consoleSender.isPermissionSet(anyString())).thenReturn(true);
when(consoleSender.isPermissionSet(Matchers.isA(Permission.class))).thenReturn(true);
when(consoleSender.hasPermission(anyString())).thenReturn(true);
when(consoleSender.hasPermission(Matchers.isA(Permission.class))).thenReturn(true);
when(consoleSender.addAttachment(main)).thenReturn(null);
when(consoleSender.isOp()).thenReturn(true);
when(mockServer.getConsoleSender()).thenReturn(consoleSender);
// Init our command sender // Init our command sender
final Logger commandSenderLogger = Logger.getLogger("CommandSender"); final Logger commandSenderLogger = Logger.getLogger("CommandSender");
commandSenderLogger.setParent(Util.logger); commandSenderLogger.setParent(Util.logger);