1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-17 20:11:21 +02:00

Code Cleanup

This commit is contained in:
Chris Ward
2013-04-07 20:35:57 +10:00
parent 4d8543bb3a
commit bf3e03fdaf
30 changed files with 57 additions and 142 deletions

View File

@@ -55,10 +55,9 @@ public class EssentialsTimer implements Runnable
user.setLastOnlineActivity(currentTime);
user.checkActivity();
boolean mailDisabled = false;
ISettings settings = ess.getSettings();
mailDisabled = settings.getData().getCommands().isDisabled("mail");
boolean mailDisabled = settings.getData().getCommands().isDisabled("mail");
// New mail notification
if (!mailDisabled && Permissions.MAIL.isAuthorized(user) && !user.gotMailInfo())

View File

@@ -154,7 +154,6 @@ public class ItemDb implements IItemDb
{
throw new Exception(_("§4Unknown item id:§r {0}§4.", itemid));
}
final ItemStack retval = new ItemStack(mat, mat.getMaxStackSize(), metaData);
return retval;
return new ItemStack(mat, mat.getMaxStackSize(), metaData);
}
}

View File

@@ -156,7 +156,7 @@ public class MetaItemStack
{
final String owner = split[1];
final SkullMeta meta = (SkullMeta)stack.getItemMeta();
boolean result = meta.setOwner(owner);
meta.setOwner(owner);
stack.setItemMeta(meta);
}
else
@@ -286,7 +286,7 @@ public class MetaItemStack
}
else if (split[0].equalsIgnoreCase("shape") || split[0].equalsIgnoreCase("type") || (allowShortName && (split[0].equalsIgnoreCase("s") || split[0].equalsIgnoreCase("t"))))
{
FireworkEffect.Type finalEffect = null;
FireworkEffect.Type finalEffect;
split[1] = (split[1].equalsIgnoreCase("large") ? "BALL_LARGE" : split[1]);
if (fireworkShape.containsKey(split[1].toUpperCase()))
{
@@ -513,7 +513,6 @@ public class MetaItemStack
private boolean hasMetaPermission(final IUser user, final String metaPerm, final boolean graceful, final boolean includeBase) throws Exception
{
final String permBase = includeBase ? "essentials.itemspawn.meta-" : "essentials.";
if (user == null || (includeBase ? Permissions.ITEMSPAWN.isAuthorized(user, "meta-" + metaPerm) : Permissions.ESSENTIALS.isAuthorized(user, metaPerm)))
{
return true;

17
Essentials/src/net/ess3/bukkit/BukkitPlugin.java Normal file → Executable file
View File

@@ -100,14 +100,15 @@ public class BukkitPlugin extends JavaPlugin implements IPlugin
final MetricsStarter metricsStarter = new MetricsStarter(ess);
if (metricsStarter.getStart() != null && metricsStarter.getStart() == true)
if (metricsStarter.getStart() != null)
{
getServer().getScheduler().runTaskLaterAsynchronously(this, metricsStarter, 1);
}
else if (metricsStarter.getStart() != null && metricsStarter.getStart() == false)
{
final MetricsListener metricsListener = new MetricsListener(ess, metricsStarter);
pm.registerEvents(metricsListener, this);
if(metricsStarter.getStart())
getServer().getScheduler().runTaskLaterAsynchronously(this, metricsStarter, 1);
else
{
final MetricsListener metricsListener = new MetricsListener(ess, metricsStarter);
pm.registerEvents(metricsListener, this);
}
}
}
@@ -149,7 +150,7 @@ public class BukkitPlugin extends JavaPlugin implements IPlugin
{
return getServer().getScheduler().runTaskLaterAsynchronously(this, run, delay);
}
@Override
public BukkitTask runTaskTimerAsynchronously(final Runnable run, final long delay, final long delay2)
{

View File

@@ -55,7 +55,7 @@ public class Commandeco extends EssentialsCommand
break;
}
}
if (ecoResetAll == true)
if (ecoResetAll)
{
ess.broadcastMessage(null, _("ecoResetAll", settings.getData().getEconomy().getCurrencySymbol() + amount));
}
@@ -89,7 +89,7 @@ public class Commandeco extends EssentialsCommand
break;
}
}
if (ecoResetAllOnline == true)
if (ecoResetAllOnline)
{
ess.broadcastMessage(null, _("ecoResetAllOnline", settings.getData().getEconomy().getCurrencySymbol() + amount));
}

6
Essentials/src/net/ess3/commands/Commandkickall.java Normal file → Executable file
View File

@@ -16,11 +16,7 @@ public class Commandkickall extends EssentialsCommand
kickReason = FormatUtil.replaceFormat(kickReason.replace("\\n", "\n").replace("|", "\n"));
for (Player onlinePlayer : server.getOnlinePlayers())
{
if (sender instanceof IUser && onlinePlayer.getName().equalsIgnoreCase(((Player)sender).getName()))
{
continue;
}
else
if (!(sender instanceof IUser && onlinePlayer.getName().equalsIgnoreCase(sender.getName())))
{
onlinePlayer.kickPlayer(kickReason);
}

View File

@@ -76,7 +76,7 @@ public class Commandlist extends EssentialsCommand
}
list.add(getUser(onlinePlayer));
}
final String[] groups = sort.keySet().toArray(new String[0]);
final String[] groups = sort.keySet().toArray(new String[sort.size()]);
Arrays.sort(groups, String.CASE_INSENSITIVE_ORDER);
for (String group : groups)
{

View File

@@ -34,8 +34,7 @@ public class Commandspawner extends EssentialsCommand
{
String name = args[0];
EntityType mob = null;
mob = LivingEntities.fromName(name);
EntityType mob = LivingEntities.fromName(name);
if (mob == null)
{
user.sendMessage(_("Invalid mob type."));

View File

@@ -20,14 +20,14 @@ public class Commandthunder extends EssentialsCommand
if (args.length > 1)
{
world.setThundering(setThunder ? true : false);
world.setThundering(setThunder);
world.setThunderDuration(Integer.parseInt(args[1]) * 20);
user.sendMessage(_("§6You§c {0} §6thunder in your world for§c {1} §6seconds.", (setThunder ? _("enabled") : _("disabled")), Integer.parseInt(args[1])));
}
else
{
world.setThundering(setThunder ? true : false);
world.setThundering(setThunder);
user.sendMessage(_("§6You§c {0} §6thunder in your world.", setThunder ? _("enabled") : _("disabled")));
}

View File

@@ -26,7 +26,7 @@ public class Commandtime extends EssentialsCommand
add = true;
argList.set(0, argList.get(0) + "t");
}
final String[] validArgs = argList.toArray(new String[0]);
final String[] validArgs = argList.toArray(new String[argList.size()]);
// Which World(s) are we interested in?
String worldSelector = null;

View File

@@ -39,8 +39,7 @@ public class Commandtpa extends EssentialsCommand
player.sendMessage(_("§c{0}§6 has requested to teleport to you.", user.getPlayer().getDisplayName()));
player.sendMessage(_("§6To teleport, type §c/tpaccept§6."));
player.sendMessage(_("§6To deny this request, type §c/tpdeny§6."));
int tpaAcceptCancellation = 0;
tpaAcceptCancellation = settings.getData().getCommands().getTeleport().getRequestTimeout();
int tpaAcceptCancellation = settings.getData().getCommands().getTeleport().getRequestTimeout();
if (tpaAcceptCancellation != 0)
{
player.sendMessage(_("§6This request will timeout after§c {0} seconds§6.", tpaAcceptCancellation));

View File

@@ -54,8 +54,7 @@ public class Commandtpaall extends EssentialsCommand
player.requestTeleport(user, true);
player.sendMessage(_("§c{0}§6 has requested that you teleport to them.", user.getPlayer().getDisplayName()));
player.sendMessage(_("§6To teleport, type §c/tpaccept§6."));
int tpaAcceptCancellation = 0;
tpaAcceptCancellation = settings.getData().getCommands().getTeleport().getRequestTimeout();
int tpaAcceptCancellation = settings.getData().getCommands().getTeleport().getRequestTimeout();
if (tpaAcceptCancellation != 0)
{
player.sendMessage(_("§6This request will timeout after§c {0} seconds§6.", tpaAcceptCancellation));

View File

@@ -38,10 +38,7 @@ public class Commandtpahere extends EssentialsCommand
player.sendMessage(_("§c{0}§6 has requested that you teleport to them.", user.getPlayer().getDisplayName()));
player.sendMessage(_("§6To teleport, type §c/tpaccept§6."));
player.sendMessage(_("§6To deny this request, type §c/tpdeny§6."));
int tpaAcceptCancellation = 0;
{
tpaAcceptCancellation = settings.getData().getCommands().getTeleport().getRequestTimeout();
}
int tpaAcceptCancellation = settings.getData().getCommands().getTeleport().getRequestTimeout();
if (tpaAcceptCancellation != 0)
{
player.sendMessage(_("§6This request will timeout after§c {0} seconds§6.", tpaAcceptCancellation));

View File

@@ -32,7 +32,7 @@ public class Commandwarp extends EssentialsCommand
}
if (args.length > 0)
{
IUser otherUser = null;
IUser otherUser;
if (args.length == 2 && Permissions.WARP_OTHERS.isAuthorized(user))
{
if (Permissions.WARP_HIDDEN.isAuthorized(user))

View File

@@ -22,14 +22,14 @@ public class Commandweather extends EssentialsCommand
if (args.length > 1)
{
world.setStorm(isStorm ? true : false);
world.setStorm(isStorm);
world.setWeatherDuration(Integer.parseInt(args[1]) * 20);
user.sendMessage(
isStorm ? _("§6You set the weather to §cstorm§6 in§c {0} §6for {1} seconds.", world.getName(), args[1]) : _("§6You set the weather to §csun§6 in§c {0} §6for {1} seconds.", world.getName(), args[1]));
}
else
{
world.setStorm(isStorm ? true : false);
world.setStorm(isStorm);
user.sendMessage(
isStorm ? _("§6You set the weather to §cstorm§6 in§c {0}§6.", world.getName()) : _("§6You set the weather to §csun§6 in§c {0}§6.", world.getName()));
}
@@ -52,14 +52,14 @@ public class Commandweather extends EssentialsCommand
if (args.length > 2)
{
world.setStorm(isStorm ? true : false);
world.setStorm(isStorm);
world.setWeatherDuration(Integer.parseInt(args[2]) * 20);
sender.sendMessage(
isStorm ? _("§6You set the weather to §cstorm§6 in§c {0} §6for {1} seconds.", world.getName(), args[2]) : _("§6You set the weather to §csun§6 in§c {0} §6for {1} seconds.", world.getName(), args[2]));
}
else
{
world.setStorm(isStorm ? true : false);
world.setStorm(isStorm);
sender.sendMessage(
isStorm ? _("§6You set the weather to §cstorm§6 in§c {0}§6.", world.getName()) : _("§6You set the weather to §csun§6 in§c {0}§6.", world.getName()));
}

9
Essentials/src/net/ess3/commands/Commandwhois.java Normal file → Executable file
View File

@@ -83,11 +83,10 @@ public class Commandwhois extends EssentialsCommand
_(
"whoisMute", (userData.isMuted() ? user.getTimestamp(UserData.TimestampType.MUTE) > 0 ? DateUtil.formatDateDiff(
user.getTimestamp(UserData.TimestampType.MUTE)) : _("§atrue§r") : _("§4false§r"))));
if (!foundPlayer)
{
throw new NoSuchFieldException(_("§4Player not found."));
}
}
if (!foundPlayer)
{
throw new NoSuchFieldException(_("§4Player not found."));
}
}
}

View File

@@ -74,7 +74,7 @@ public class SetExpFix
//Without this people would be able to use exp and then still sell it.
public static int getTotalExperience(final Player player)
{
int exp = (int)Math.round(getExpAtLevel(player) * player.getExp());
int exp = Math.round(getExpAtLevel(player) * player.getExp());
int currentLevel = player.getLevel();
while (currentLevel > 0)
@@ -87,7 +87,7 @@ public class SetExpFix
public static int getExpUntilNextLevel(final Player player)
{
int exp = (int)Math.round(getExpAtLevel(player) * player.getExp());
int exp = Math.round(getExpAtLevel(player) * player.getExp());
int nextLevel = player.getLevel();
return getExpAtLevel(nextLevel) - exp;
}

View File

@@ -112,7 +112,7 @@ public class Trade
final int maxStackSize = dropStack.getType().getMaxStackSize();
final int stacks = dropStack.getAmount() / maxStackSize;
final int leftover = dropStack.getAmount() % maxStackSize;
final ItemStack[] itemStacks = new ItemStack[stacks + (leftover > 0 ? 1 : 0)];
final ItemStack[] itemStacks = new ItemStack[stacks + (leftover > 0 ? 1 : 0)]; // TODO: Written, but never read?
for (int i = 0; i < stacks; i++)
{
final ItemStack stack = dropStack.clone();

View File

@@ -155,7 +155,7 @@ public class Methods
int count = 0;
boolean match = false;
Plugin plugin = null;
Plugin plugin;
for (String name : getDependencies())
{

View File

@@ -96,11 +96,7 @@ public class VaultEco implements Method
public boolean createAccount(String name, double balance)
{
if (!this.economy.createBank(name, "").transactionSuccess())
{
return false;
}
return this.economy.bankDeposit(name, balance).transactionSuccess();
return this.economy.createBank(name, "").transactionSuccess() && this.economy.bankDeposit(name, balance).transactionSuccess();
}
@Override
@@ -176,15 +172,7 @@ public class VaultEco implements Method
@Override
public boolean set(double amount)
{
if (!this.economy.withdrawPlayer(this.name, this.balance()).transactionSuccess())
{
return false;
}
if (amount == 0)
{
return true;
}
return this.economy.depositPlayer(this.name, amount).transactionSuccess();
return this.economy.withdrawPlayer(this.name, this.balance()).transactionSuccess() && (amount == 0 || this.economy.depositPlayer(this.name, amount).transactionSuccess());
}
@Override
@@ -277,15 +265,7 @@ public class VaultEco implements Method
@Override
public boolean set(double amount)
{
if (!this.economy.bankWithdraw(this.bank, this.balance()).transactionSuccess())
{
return false;
}
if (amount == 0)
{
return true;
}
return this.economy.bankDeposit(this.bank, amount).transactionSuccess();
return this.economy.bankWithdraw(this.bank, this.balance()).transactionSuccess() && (amount == 0 || this.economy.bankDeposit(this.bank, amount).transactionSuccess());
}
@Override

View File

@@ -82,12 +82,7 @@ public class iCo5 implements Method
@Override
public boolean createAccount(String name)
{
if (hasAccount(name))
{
return false;
}
return com.iConomy.iConomy.Accounts.create(name);
return !hasAccount(name) && com.iConomy.iConomy.Accounts.create(name);
}
@Override

View File

@@ -81,23 +81,13 @@ public class iCo6 implements Method
@Override
public boolean createAccount(String name)
{
if (hasAccount(name))
{
return false;
}
return (new Accounts()).create(name);
return !hasAccount(name) && (new Accounts()) .create(name);
}
@Override
public boolean createAccount(String name, Double balance)
{
if (hasAccount(name))
{
return false;
}
return (new Accounts()).create(name, balance);
return !hasAccount(name) && (new Accounts()).create(name, balance);
}
@Override

View File

@@ -121,7 +121,7 @@ public class EssentialsEntityListener implements Listener
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerDeathEvent(final PlayerDeathEvent event)
{
final IUser user = ess.getUserMap().getUser((Player)event.getEntity());
final IUser user = ess.getUserMap().getUser(event.getEntity());
final ISettings settings = ess.getSettings();
if (Permissions.BACK_ONDEATH.isAuthorized(user) && !settings.getData().getCommands().isDisabled("back"))

View File

@@ -562,7 +562,6 @@ public class EssentialsPlayerListener implements Listener
if (command.matches(".*\\{player\\}.*"))
{
//user.sendMessage("Click a player to use this command");
continue;
}
else if (command.startsWith("c:"))
{
@@ -651,7 +650,7 @@ public class EssentialsPlayerListener implements Listener
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerFishEvent(final PlayerFishEvent event)
{
final IUser user = userMap.getUser((Player)event.getPlayer());
final IUser user = userMap.getUser(event.getPlayer());
user.updateActivity(true);
}
}

View File

@@ -32,9 +32,6 @@ public class MetricsStarter implements Runnable
EssentialsXMPP
}
;
public MetricsStarter(final IEssentials plugin)
{
ess = plugin;
@@ -56,7 +53,7 @@ public class MetricsStarter implements Runnable
ess.getLogger().info(_("metrics4"));
start = false;
}
else if (settings.getData().getGeneral().getMetricsEnabled() == true)
else if (settings.getData().getGeneral().getMetricsEnabled())
{
start = true;
}
@@ -140,7 +137,7 @@ public class MetricsStarter implements Runnable
ISettings settings = ess.getSettings();
final String BKcommand = settings.getData().getGeneral().getBackup().getCommand();
;
if (BKcommand != null && !"".equals(BKcommand))
{
enabledGraph.addPlotter(new SimplePlotter("Backup"));

View File

@@ -33,8 +33,7 @@ public abstract class AbstractRanks
format = format.replace("{WORLDNAME}", "{1}");
format = format.replace("{SHORTWORLDNAME}", "{2}");
format = format.replaceAll("\\{(\\D*)\\}", "\\[$1\\]");
MessageFormat mFormat = new MessageFormat(format);
return mFormat;
return new MessageFormat(format);
}
protected abstract String getRawChatFormat(final CommandSender sender);

View File

@@ -175,11 +175,7 @@ public class GMGroups extends AbstractRanks implements IRanks
try
{
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(getPlayer(player));
if (handler == null)
{
return false;
}
return handler.inGroup(player.getName(), groupname);
return handler != null && handler.inGroup(player.getName(), groupname);
}
catch (Exception e)
{

View File

@@ -39,7 +39,7 @@ public class RanksStorage extends AsyncStorageObjectHolder<Ranks> implements IRa
{
return Collections.emptyList();
}
final ArrayList<Entry<String, RankOptions>> list = new ArrayList();
final ArrayList<Entry<String, RankOptions>> list = new ArrayList<Entry<String, RankOptions>>();
for (Entry<String, RankOptions> entry : groups.entrySet())
{
if (Permissions.RANKS.isAuthorized(player, entry.getKey()))

View File

@@ -41,28 +41,16 @@ public class Alert implements StorageObject
public boolean getAlertOnPlacementContains(Material mat)
{
if (alertOnPlacement == null)
{
return false;
}
return alertOnPlacement.contains(mat);
return alertOnPlacement != null && alertOnPlacement.contains(mat);
}
public boolean getAlertOnUseContains(Material mat)
{
if (alertOnUse == null)
{
return false;
}
return alertOnUse.contains(mat);
return alertOnUse != null && alertOnUse.contains(mat);
}
public boolean getAlertOnBreakContains(Material mat)
{
if (alertOnBreak == null)
{
return false;
}
return alertOnBreak.contains(mat);
return alertOnBreak != null && alertOnBreak.contains(mat);
}
}

View File

@@ -46,37 +46,21 @@ public class BlackList implements StorageObject
public boolean getPlacement(Material mat)
{
if (placement == null)
{
return false;
}
return placement.contains(mat);
return placement != null && placement.contains(mat);
}
public boolean getUsage(Material mat)
{
if (usage == null)
{
return false;
}
return usage.contains(mat);
return usage != null && usage.contains(mat);
}
public boolean getBreaking(Material mat)
{
if (breaking == null)
{
return false;
}
return breaking.contains(mat);
return breaking != null && breaking.contains(mat);
}
public boolean getPiston(Material mat)
{
if (piston == null)
{
return false;
}
return piston.contains(mat);
return piston != null && piston.contains(mat);
}
}