1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-22 06:12:56 +02:00

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);
@@ -136,31 +135,31 @@ public class Commandessentials extends EssentialsCommand
noteMap.put("2D#", 1.68f); noteMap.put("2D#", 1.68f);
noteMap.put("2E", 1.78f); noteMap.put("2E", 1.78f);
noteMap.put("2F", 1.88f); 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#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D#,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,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,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,2F#,1B,,1B,,";
final String[] tune = tuneStr.split(","); final String[] tune = tuneStr.split(",");
taskid = ess.scheduleSyncRepeatingTask(new Runnable() taskid = ess.scheduleSyncRepeatingTask(new Runnable()
{ {
int i = 0; int i = 0;
@Override @Override
public void run() public void run()
{
final String note = tune[i];
i++;
if (i >= tune.length)
{ {
final String note = tune[i]; Commandessentials.this.stopTune();
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));
}
} }
}, 20, 2); if (note.isEmpty() || note == null)
{
return;
}
for (Player onlinePlayer : server.getOnlinePlayers())
{
onlinePlayer.playSound(onlinePlayer.getLocation(), Sound.NOTE_PIANO, 1, noteMap.get(note));
}
}
}, 20, 2);
} }
private void stopTune() private void stopTune()
@@ -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"));
} }
}); });