summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2013-02-19 22:58:50 +0000
committerKHobbits <rob@khobbits.co.uk>2013-02-19 23:06:04 +0000
commit6ae6c51dc05582c56a820e2f6317eff232952d70 (patch)
tree2699fcb6150acc1f96cf497dcf5dc7c1ee98cc9c
parent8710a133ce1e9756e1c5ffb61a26e12836a6cc6e (diff)
downloadEssentials-6ae6c51dc05582c56a820e2f6317eff232952d70.tar
Essentials-6ae6c51dc05582c56a820e2f6317eff232952d70.tar.gz
Essentials-6ae6c51dc05582c56a820e2f6317eff232952d70.tar.lz
Essentials-6ae6c51dc05582c56a820e2f6317eff232952d70.tar.xz
Essentials-6ae6c51dc05582c56a820e2f6317eff232952d70.zip
Code cleanup
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandessentials.java138
1 files changed, 65 insertions, 73 deletions
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java
index 6a3c9d28c..40ba93a0d 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java
@@ -5,14 +5,10 @@ import com.earth2me.essentials.User;
import com.earth2me.essentials.UserMap;
import com.earth2me.essentials.Util;
import com.earth2me.essentials.metrics.Metrics;
-import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
-import org.bukkit.Instrument;
-import org.bukkit.Location;
import org.bukkit.Material;
-import org.bukkit.Note;
import org.bukkit.Server;
import org.bukkit.Sound;
import org.bukkit.block.Block;
@@ -33,7 +29,8 @@ public class Commandessentials extends EssentialsCommand
@Override
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);
}
else if (args[0].equalsIgnoreCase("debug"))
@@ -60,55 +57,57 @@ public class Commandessentials extends EssentialsCommand
{
run_cleanup(server, sender, commandLabel, args);
}
- else
+ else
{
run_reload(server, sender, commandLabel, args);
}
}
-
+
//If you do not supply an argument this command will list 'overridden' commands.
private void run_disabled(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
sender.sendMessage("Essentials " + ess.getDescription().getVersion());
sender.sendMessage("/<command> <reload/debug>");
-
+
final StringBuilder disabledCommands = new StringBuilder();
for (Map.Entry<String, String> entry : ess.getAlternativeCommandsHandler().disabledCommands().entrySet())
{
- if (disabledCommands.length() > 0) {
+ if (disabledCommands.length() > 0)
+ {
disabledCommands.append(", ");
}
disabledCommands.append(entry.getKey()).append(" => ").append(entry.getValue());
}
- if (disabledCommands.length() > 0) {
+ if (disabledCommands.length() > 0)
+ {
sender.sendMessage(_("blockList"));
sender.sendMessage(disabledCommands.toString());
}
}
-
+
private void run_reset(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
if (args.length < 2)
{
- throw new NotEnoughArgumentsException("/<command> reset <player>");
+ throw new Exception("/<command> reset <player>");
}
final User user = getPlayer(server, args, 1, true);
user.reset();
sender.sendMessage("Reset Essentials userdata for player: " + user.getDisplayName());
}
-
+
private void run_debug(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
ess.getSettings().setDebug(!ess.getSettings().isDebug());
sender.sendMessage("Essentials " + ess.getDescription().getVersion() + " debug mode " + (ess.getSettings().isDebug() ? "enabled" : "disabled"));
}
-
+
private void run_reload(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
ess.reload();
sender.sendMessage(_("essentialsReload", ess.getDescription().getVersion()));
}
-
+
private void run_nya(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
final Map<String, Float> noteMap = new HashMap<String, Float>();
@@ -128,7 +127,7 @@ public class Commandessentials extends EssentialsCommand
noteMap.put("2G", 1.06f);
noteMap.put("2G#", 1.12f);
noteMap.put("2A", 1.18f);
- noteMap.put("2A#",1.26f);
+ noteMap.put("2A#", 1.26f);
noteMap.put("2B", 1.34f);
noteMap.put("2C", 1.42f);
noteMap.put("2C#", 1.5f);
@@ -136,31 +135,31 @@ public class Commandessentials extends EssentialsCommand
noteMap.put("2D#", 1.68f);
noteMap.put("2E", 1.78f);
noteMap.put("2F", 1.88f);
- final String tuneStr = "1D#,1E,2F#,,2A#,1E,1D#,1E,2F#,2B,2D#,2E,2D#,2A#,2B,,2F#,,1D#,1E,2F#,2B,2C#,2A#,2B,2C#,2E,2D#,2E,2C#,,2F#,,2G#,,1D,1D#,,1C#,1D,1C#,1B,,1B,,1C#,,1D,,1D,1C#,1B,1C#,1D#,2F#,2G#,1D#,2F#,1C#,1D#,1B,1C#,1B,1D#,,2F#,,2G#,1D#,2F#,1C#,1D#,1B,1D,1D#,1D,1C#,1B,1C#,1D,,1B,1C#,1D#,2F#,1C#,1D,1C#,1B,1C#,,1B,,1C#,,2F#,,2G#,,1D,1D#,,1C#,1D,1C#,1B,,1B,,1C#,,1D,,1D,1C#,1B,1C#,1D#,2F#,2G#,1D#,2F#,1C#,1D#,1B,1C#,1B,1D#,,2F#,,2G#,1D#,2F#,1C#,1D#,1B,1D,1D#,1D,1C#,1B,1C#,1D,,1B,1C#,1D#,2F#,1C#,1D,1C#,1B,1C#,,1B,,1B,,1B,,1F#,1G#,1B,,1F#,1G#,1B,1C#,1D#,1B,1E,1D#,1E,2F#,1B,,1B,,1F#,1G#,1B,1E,1D#,1C#,1B,,,,1F#,1B,,1F#,1G#,1B,,1F#,1G#,1B,1B,1C#,1D#,1B,1F#,1G#,1F#,1B,,1B,1A#,1B,1F#,1G#,1B,1E,1D#,1E,2F#,1B,,1A#,,1B,,1F#,1G#,1B,,1F#,1G#,1B,1C#,1D#,1B,1E,1D#,1E,2F#,1B,,1B,,1F#,1G#,1B,1F#,1E,1D#,1C#,1B,,,,1F#,1B,,1F#,1G#,1B,,1F#,1G#,1B,1B,1C#,1D#,1B,1F#,1G#,1F#,1B,,1B,1A#,1B,1F#,1G#,1B,1E,1D#,1E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,,,1F#,1B,,1F#,1G#,1B,,1F#,1G#,1B,1B,1C#,1D#,1B,1F#,1G#,1F#,1B,,1B,1A#,1B,1F#,1G#,1B,1E,1D#,1E,2F#,1B,,1B,,";
+ final String[] tune = tuneStr.split(",");
+ taskid = ess.scheduleSyncRepeatingTask(new Runnable()
+ {
+ int i = 0;
- @Override
- public void run()
+ @Override
+ public void run()
+ {
+ final String note = tune[i];
+ i++;
+ if (i >= tune.length)
{
- final String note = tune[i];
- i++;
- if (i >= tune.length)
- {
- Commandessentials.this.stopTune();
- }
- if (note.isEmpty() || note == null)
- {
- return;
- }
- for (Player onlinePlayer : server.getOnlinePlayers())
- {
- onlinePlayer.playSound(onlinePlayer.getLocation(), Sound.NOTE_PIANO, 1, noteMap.get(note));
- }
+ Commandessentials.this.stopTune();
+ }
+ if (note.isEmpty() || note == null)
+ {
+ return;
}
- }, 20, 2);
+ for (Player onlinePlayer : server.getOnlinePlayers())
+ {
+ onlinePlayer.playSound(onlinePlayer.getLocation(), Sound.NOTE_PIANO, 1, noteMap.get(note));
+ }
+ }
+ }, 20, 2);
}
private void stopTune()
@@ -175,32 +174,38 @@ public class Commandessentials extends EssentialsCommand
}
noteBlocks.clear();
}
-
+
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
{
- sender.sendMessage(new String[]{" (__)", " (oo)", " /------\\/", " / | | |", " * /\\---/\\", " ~~ ~~", "....\"Have you mooed today?\"..." } );
+ sender.sendMessage(new String[]
+ {
+ " (__)", " (oo)", " /------\\/", " / | | |", " * /\\---/\\", " ~~ ~~", "....\"Have you mooed today?\"..."
+ });
Player player = (Player)sender;
player.playSound(player.getLocation(), Sound.COW_IDLE, 1, 1.0f);
}
}
-
+
private void run_optout(final Server server, final CommandSender sender, final String command, final String args[])
{
final Metrics metrics = ess.getMetrics();
try
{
sender.sendMessage("Essentials collects simple metrics to highlight which features to concentrate work on in the future.");
- if (metrics.isOptOut())
+ if (metrics.isOptOut())
{
- metrics.enable();
- }
- else
+ metrics.enable();
+ }
+ else
{
metrics.disable();
}
@@ -211,23 +216,24 @@ public class Commandessentials extends EssentialsCommand
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
{
-
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"));
final int daysArg = Integer.parseInt(args[1]);
final double moneyArg = args.length >= 3 ? Double.parseDouble(args[2].replaceAll("[^0-9\\.]", "")) : 0;
final int homesArg = args.length >= 4 && Util.isInt(args[3]) ? Integer.parseInt(args[3]) : 0;
- 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();
-
-
- ess.runTaskAsynchronously( new Runnable()
+
+ ess.runTaskAsynchronously(new Runnable()
{
@Override
public void run()
@@ -239,35 +245,21 @@ public class Commandessentials extends EssentialsCommand
{
continue;
}
+
int ban = user.getBanReason().equals("") ? 0 : 1;
- if (!(ban <= bansArg))
- {
- continue;
- }
- long lastLogout = user.getLastLogout();
- long timeNow = System.currentTimeMillis();
- long timeDiff = timeNow - lastLogout;
+ long timeDiff = System.currentTimeMillis() - user.getLastLogout();
long milliDays = daysArg * 24 * 60 * 60;
- if (!(timeDiff >= milliDays))
- {
- continue;
- }
- int homes = user.getHomes().size();
- if (!(homes <= homesArg))
- {
- continue;
- }
- double money = user.getMoney();
- if (!(money <= moneyArg))
+
+ if ((ban > bansArg) || (timeDiff < milliDays)
+ || (user.getHomes().size() > homesArg) || (user.getMoney() > moneyArg))
{
continue;
}
user.reset();
}
- userMap.reloadConfig();
sender.sendMessage(_("cleaned"));
}
});
-
+
}
}