Fix some code style issues

This commit is contained in:
graywolf336 2016-05-31 12:38:39 -05:00
parent 1b3d8c7bdf
commit 1e241eef3c
No known key found for this signature in database
GPG Key ID: F8F0E59498A452CF
9 changed files with 42 additions and 46 deletions

View File

@ -407,6 +407,9 @@ public class JailIO {
default: default:
break; break;
} }
//Make sure the statement is closed.
if(!st.isClosed()) st.close();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
pl.getLogger().severe("---------- Jail Error!!! ----------"); pl.getLogger().severe("---------- Jail Error!!! ----------");
@ -512,7 +515,7 @@ public class JailIO {
} }
//Remove the invalid prisoners //Remove the invalid prisoners
if(cellsToRemove.size() != 0) { if(!cellsToRemove.isEmpty()) {
StringBuilder ids = new StringBuilder(); StringBuilder ids = new StringBuilder();
for(int c : cellsToRemove) { for(int c : cellsToRemove) {
if(ids.length() == 0) ids.append("'" + c + "'"); if(ids.length() == 0) ids.append("'" + c + "'");
@ -585,7 +588,7 @@ public class JailIO {
} }
//Remove the invalid prisoners //Remove the invalid prisoners
if(prisonersToRemove.size() != 0) { if(!prisonersToRemove.isEmpty()) {
String names = ""; String names = "";
for(String s : prisonersToRemove) { for(String s : prisonersToRemove) {
if(names.isEmpty()) names = "'" + s + "'"; if(names.isEmpty()) names = "'" + s + "'";

View File

@ -39,7 +39,7 @@ public class CommandHandler {
public List<String> parseTabComplete(JailManager jm, CommandSender sender, String commandLine, String[] args) throws Exception { public List<String> parseTabComplete(JailManager jm, CommandSender sender, String commandLine, String[] args) throws Exception {
List<Command> matches = getMatches(commandLine); List<Command> matches = getMatches(commandLine);
if(matches.size() == 0 || matches.size() > 1) return Collections.emptyList(); if(matches.isEmpty() || matches.size() > 1) return Collections.emptyList();
else { else {
CommandInfo i = matches.get(0).getClass().getAnnotation(CommandInfo.class); CommandInfo i = matches.get(0).getClass().getAnnotation(CommandInfo.class);
@ -83,7 +83,7 @@ public class CommandHandler {
List<Command> matches = getMatches(commandLine); List<Command> matches = getMatches(commandLine);
//If no matches were found, send them the unknown command message. //If no matches were found, send them the unknown command message.
if(matches.size() == 0) { if(matches.isEmpty()) {
if(commandLine.startsWith("jail")) { if(commandLine.startsWith("jail")) {
String j = commandLine.substring(0, 4); String j = commandLine.substring(0, 4);
String a0 = commandLine.substring(4, commandLine.length()); String a0 = commandLine.substring(4, commandLine.length());

View File

@ -162,7 +162,7 @@ public class JailHandler {
//Get the matches from the first argument passed //Get the matches from the first argument passed
List<Command> matches = getMatches(args[0].toLowerCase()); List<Command> matches = getMatches(args[0].toLowerCase());
if(matches.size() == 0) { if(matches.isEmpty()) {
//No matches found, thus it is more likely than not they are trying to jail someone //No matches found, thus it is more likely than not they are trying to jail someone
c = getMatches("jail").get(0); c = getMatches("jail").get(0);
@ -182,12 +182,10 @@ public class JailHandler {
CommandInfo i = c.getClass().getAnnotation(CommandInfo.class); CommandInfo i = c.getClass().getAnnotation(CommandInfo.class);
// First, let's check if the sender has permission for the command. // First, let's check if the sender has permission for the command.
if(!i.permission().isEmpty()) { if(!i.permission().isEmpty() && !sender.hasPermission(i.permission())) {
if(!sender.hasPermission(i.permission())) { jailmanager.getPlugin().debug("Sender has no permission: " + i.permission());
jailmanager.getPlugin().debug("Sender has no permission: " + i.permission()); sender.sendMessage(Lang.NOPERMISSION.get() + (jailmanager.getPlugin().inDebug() ? " (" + i.permission() + ")" : ""));
sender.sendMessage(Lang.NOPERMISSION.get() + (jailmanager.getPlugin().inDebug() ? " (" + i.permission() + ")" : "")); return true;
return true;
}
} }
// Next, let's check if we need a player and then if the sender is actually a player // Next, let's check if we need a player and then if the sender is actually a player

View File

@ -202,9 +202,7 @@ public class JailCommand implements Command {
//If the jailer gave no reason, then let's get the default reason //If the jailer gave no reason, then let's get the default reason
String reason = ""; String reason = "";
if(!params.isReason()) { if(params.isReason()) {
reason = Lang.DEFAULTJAILEDREASON.get();
}else {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for(String s : params.getReason()) { for(String s : params.getReason()) {
sb.append(s).append(' '); sb.append(s).append(' ');
@ -212,6 +210,9 @@ public class JailCommand implements Command {
sb.deleteCharAt(sb.length() - 1); sb.deleteCharAt(sb.length() - 1);
reason = sb.toString(); reason = sb.toString();
}else {
reason = Lang.DEFAULTJAILEDREASON.get();
} }
//If the config has automatic muting, then let's set them as muted //If the config has automatic muting, then let's set them as muted
@ -320,9 +321,8 @@ public class JailCommand implements Command {
List<String> results = new ArrayList<String>(); List<String> results = new ArrayList<String>();
for(Cell c : jm.getJail(jail).getCells()) for(Cell c : jm.getJail(jail).getCells())
if(!c.hasPrisoner()) if(!c.hasPrisoner() && (cell.isEmpty() || StringUtil.startsWithIgnoreCase(c.getName(), cell)))
if(cell.isEmpty() || StringUtil.startsWithIgnoreCase(c.getName(), cell)) results.add(c.getName());
results.add(c.getName());
Collections.sort(results); Collections.sort(results);

View File

@ -39,7 +39,7 @@ public class JailListCellsCommand implements Command {
Collections.sort(cells); Collections.sort(cells);
sender.sendMessage(cells.size() == 0 ? Lang.NOCELLS.get(j.getName()) : ChatColor.GREEN + Util.getStringFromList(", ", cells)); sender.sendMessage(cells.isEmpty() ? Lang.NOCELLS.get(j.getName()) : ChatColor.GREEN + Util.getStringFromList(", ", cells));
}else { }else {
sender.sendMessage(Lang.NOJAIL.get(args[1])); sender.sendMessage(Lang.NOJAIL.get(args[1]));
} }

View File

@ -194,9 +194,8 @@ public class JailTransferCommand implements Command {
List<String> results = new ArrayList<String>(); List<String> results = new ArrayList<String>();
for(Cell c : jm.getJail(jail).getCells()) for(Cell c : jm.getJail(jail).getCells())
if(!c.hasPrisoner()) if(!c.hasPrisoner() && (cell.isEmpty() || StringUtil.startsWithIgnoreCase(c.getName(), cell)))
if(cell.isEmpty() || StringUtil.startsWithIgnoreCase(c.getName(), cell)) results.add(c.getName());
results.add(c.getName());
Collections.sort(results); Collections.sort(results);

View File

@ -47,19 +47,17 @@ public class HandCuffListener implements Listener {
public void onPlayerTeleport(PlayerTeleportEvent event) { public void onPlayerTeleport(PlayerTeleportEvent event) {
if(event.isCancelled()) return; if(event.isCancelled()) return;
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) { if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId()) && event.getTo() != tos.get(event.getPlayer().getName())) {
if(event.getTo() != tos.get(event.getPlayer().getName())) { Location to = pl.getHandCuffManager().getLocation(event.getPlayer().getUniqueId());
Location to = pl.getHandCuffManager().getLocation(event.getPlayer().getUniqueId()); to.setPitch(event.getTo().getPitch());
to.setPitch(event.getTo().getPitch()); to.setYaw(event.getTo().getYaw());
to.setYaw(event.getTo().getYaw());
tos.put(event.getPlayer().getName(), to); tos.put(event.getPlayer().getName(), to);
event.getPlayer().teleport(to); event.getPlayer().teleport(to);
if(System.currentTimeMillis() >= pl.getHandCuffManager().getNextMessageTime(event.getPlayer().getUniqueId())) { if(System.currentTimeMillis() >= pl.getHandCuffManager().getNextMessageTime(event.getPlayer().getUniqueId())) {
event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and cant move!"); event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and cant move!");
pl.getHandCuffManager().updateNextTime(event.getPlayer().getUniqueId()); pl.getHandCuffManager().updateNextTime(event.getPlayer().getUniqueId());
}
} }
} }
} }
@ -68,11 +66,9 @@ public class HandCuffListener implements Listener {
public void playerChat(AsyncPlayerChatEvent event) { public void playerChat(AsyncPlayerChatEvent event) {
if(event.isCancelled()) return; if(event.isCancelled()) return;
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) { if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId()) && !event.getPlayer().hasPermission("jail.command.handcuff")) {
if(!event.getPlayer().hasPermission("jail.command.handcuff")) { event.setCancelled(true);
event.setCancelled(true); event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and aren't allowed to talk!");
event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and aren't allowed to talk!");
}
} }
} }
@ -100,13 +96,9 @@ public class HandCuffListener implements Listener {
public void preCommands(PlayerCommandPreprocessEvent event) { public void preCommands(PlayerCommandPreprocessEvent event) {
if(event.isCancelled()) return; if(event.isCancelled()) return;
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) { if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId()) && !event.getPlayer().hasPermission("jail.command.handcuff") && (!event.getMessage().startsWith("/r") || !event.getMessage().startsWith("/reply"))) {
if(!event.getPlayer().hasPermission("jail.command.handcuff")) { event.setCancelled(true);
if(!event.getMessage().startsWith("/r") || !event.getMessage().startsWith("/reply")) { event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and aren't allowed to use commands!");
event.setCancelled(true);
event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and aren't allowed to use commands!");
}
}
} }
} }
} }

View File

@ -15,8 +15,8 @@ import org.bukkit.inventory.PlayerInventory;
public class MockPlayerInventory implements PlayerInventory { public class MockPlayerInventory implements PlayerInventory {
private int armorSize = 4, inventorySize = 36; private int armorSize = 4, inventorySize = 36;
ItemStack[] armorContents = new ItemStack[armorSize]; private ItemStack[] armorContents = new ItemStack[armorSize];
ItemStack[] inventoryContents = new ItemStack[inventorySize]; private ItemStack[] inventoryContents = new ItemStack[inventorySize];
@Override @Override
public ItemStack[] getArmorContents() { public ItemStack[] getArmorContents() {

View File

@ -395,6 +395,10 @@ public class TestInstanceCreator {
return this.mockPlayerSender; return this.mockPlayerSender;
} }
public ConsoleCommandSender getConsoleSender() {
return this.consoleSender;
}
private void deleteFolder(File folder) { private void deleteFolder(File folder) {
File[] files = folder.listFiles(); File[] files = folder.listFiles();
if(files != null) { if(files != null) {