Code cleanup

This commit is contained in:
KHobbits 2013-02-19 22:58:50 +00:00
parent 8710a133ce
commit 6ae6c51dc0

View file

@ -5,14 +5,10 @@ import com.earth2me.essentials.User;
import com.earth2me.essentials.UserMap; import com.earth2me.essentials.UserMap;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.metrics.Metrics; import com.earth2me.essentials.metrics.Metrics;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.bukkit.Instrument;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Note;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -33,7 +29,8 @@ public class Commandessentials extends EssentialsCommand
@Override @Override
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{ {
if (args.length == 0) { if (args.length == 0)
{
run_disabled(server, sender, commandLabel, args); run_disabled(server, sender, commandLabel, args);
} }
else if (args[0].equalsIgnoreCase("debug")) else if (args[0].equalsIgnoreCase("debug"))
@ -75,12 +72,14 @@ public class Commandessentials extends EssentialsCommand
final StringBuilder disabledCommands = new StringBuilder(); final StringBuilder disabledCommands = new StringBuilder();
for (Map.Entry<String, String> entry : ess.getAlternativeCommandsHandler().disabledCommands().entrySet()) for (Map.Entry<String, String> entry : ess.getAlternativeCommandsHandler().disabledCommands().entrySet())
{ {
if (disabledCommands.length() > 0) { if (disabledCommands.length() > 0)
{
disabledCommands.append(", "); disabledCommands.append(", ");
} }
disabledCommands.append(entry.getKey()).append(" => ").append(entry.getValue()); disabledCommands.append(entry.getKey()).append(" => ").append(entry.getValue());
} }
if (disabledCommands.length() > 0) { if (disabledCommands.length() > 0)
{
sender.sendMessage(_("blockList")); sender.sendMessage(_("blockList"));
sender.sendMessage(disabledCommands.toString()); sender.sendMessage(disabledCommands.toString());
} }
@ -90,7 +89,7 @@ public class Commandessentials extends EssentialsCommand
{ {
if (args.length < 2) if (args.length < 2)
{ {
throw new NotEnoughArgumentsException("/<command> reset <player>"); throw new Exception("/<command> reset <player>");
} }
final User user = getPlayer(server, args, 1, true); final User user = getPlayer(server, args, 1, true);
user.reset(); user.reset();
@ -128,7 +127,7 @@ public class Commandessentials extends EssentialsCommand
noteMap.put("2G", 1.06f); noteMap.put("2G", 1.06f);
noteMap.put("2G#", 1.12f); noteMap.put("2G#", 1.12f);
noteMap.put("2A", 1.18f); noteMap.put("2A", 1.18f);
noteMap.put("2A#",1.26f); noteMap.put("2A#", 1.26f);
noteMap.put("2B", 1.34f); noteMap.put("2B", 1.34f);
noteMap.put("2C", 1.42f); noteMap.put("2C", 1.42f);
noteMap.put("2C#", 1.5f); noteMap.put("2C#", 1.5f);
@ -178,13 +177,19 @@ public class Commandessentials extends EssentialsCommand
private void run_moo(final Server server, final CommandSender sender, final String command, final String args[]) private void run_moo(final Server server, final CommandSender sender, final String command, final String args[])
{ {
if(sender instanceof ConsoleCommandSender) if (sender instanceof ConsoleCommandSender)
{ {
sender.sendMessage(new String[]{" (__)", " (oo)", " /------\\/", " / | ||", " * /\\---/\\", " ~~ ~~", "....\"Have you mooed today?\"..." } ); sender.sendMessage(new String[]
{
" (__)", " (oo)", " /------\\/", " / | ||", " * /\\---/\\", " ~~ ~~", "....\"Have you mooed today?\"..."
});
} }
else else
{ {
sender.sendMessage(new String[]{" (__)", " (oo)", " /------\\/", " / | | |", " * /\\---/\\", " ~~ ~~", "....\"Have you mooed today?\"..." } ); sender.sendMessage(new String[]
{
" (__)", " (oo)", " /------\\/", " / | | |", " * /\\---/\\", " ~~ ~~", "....\"Have you mooed today?\"..."
});
Player player = (Player)sender; Player player = (Player)sender;
player.playSound(player.getLocation(), Sound.COW_IDLE, 1, 1.0f); player.playSound(player.getLocation(), Sound.COW_IDLE, 1, 1.0f);
} }
@ -211,12 +216,14 @@ public class Commandessentials extends EssentialsCommand
sender.sendMessage("Unable to modify 'plugins/PluginMetrics/config.yml': " + ex.getMessage()); sender.sendMessage("Unable to modify 'plugins/PluginMetrics/config.yml': " + ex.getMessage());
} }
} }
private void run_cleanup(final Server server, final CommandSender sender, final String command, final String args[]) throws Exception private void run_cleanup(final Server server, final CommandSender sender, final String command, final String args[]) throws Exception
{ {
if (args.length < 2 || !Util.isInt(args[1])) if (args.length < 2 || !Util.isInt(args[1]))
{ {
throw new NotEnoughArgumentsException("/<command> cleanup <days> [money] [homes] [bans]"); sender.sendMessage("This sub-command will delete users who havent logged in in the last <days> days.");
sender.sendMessage("Optional parameters define the minium amount required to prevent deletion.");
throw new Exception("/<command> cleanup <days> [money] [homes] [ban count]");
} }
sender.sendMessage(_("cleaning")); sender.sendMessage(_("cleaning"));
@ -226,8 +233,7 @@ public class Commandessentials extends EssentialsCommand
final int bansArg = args.length >= 5 && Util.isInt(args[4]) ? Integer.parseInt(args[4]) : 0; final int bansArg = args.length >= 5 && Util.isInt(args[4]) ? Integer.parseInt(args[4]) : 0;
final UserMap userMap = ess.getUserMap(); final UserMap userMap = ess.getUserMap();
ess.runTaskAsynchronously(new Runnable()
ess.runTaskAsynchronously( new Runnable()
{ {
@Override @Override
public void run() public void run()
@ -239,32 +245,18 @@ public class Commandessentials extends EssentialsCommand
{ {
continue; continue;
} }
int ban = user.getBanReason().equals("") ? 0 : 1; int ban = user.getBanReason().equals("") ? 0 : 1;
if (!(ban <= bansArg)) long timeDiff = System.currentTimeMillis() - user.getLastLogout();
{
continue;
}
long lastLogout = user.getLastLogout();
long timeNow = System.currentTimeMillis();
long timeDiff = timeNow - lastLogout;
long milliDays = daysArg * 24 * 60 * 60; long milliDays = daysArg * 24 * 60 * 60;
if (!(timeDiff >= milliDays))
{ if ((ban > bansArg) || (timeDiff < milliDays)
continue; || (user.getHomes().size() > homesArg) || (user.getMoney() > moneyArg))
}
int homes = user.getHomes().size();
if (!(homes <= homesArg))
{
continue;
}
double money = user.getMoney();
if (!(money <= moneyArg))
{ {
continue; continue;
} }
user.reset(); user.reset();
} }
userMap.reloadConfig();
sender.sendMessage(_("cleaned")); sender.sendMessage(_("cleaned"));
} }
}); });