Merge branch 'master' into release

This commit is contained in:
snowleo 2011-08-30 09:46:49 +02:00
commit 3dcf8bc8fc
10 changed files with 104 additions and 49 deletions

View File

@ -28,6 +28,7 @@ import org.bukkit.*;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.earth2me.essentials.commands.IEssentialsCommand; import com.earth2me.essentials.commands.IEssentialsCommand;
import com.earth2me.essentials.commands.NoChargeException;
import com.earth2me.essentials.commands.NotEnoughArgumentsException; import com.earth2me.essentials.commands.NotEnoughArgumentsException;
import com.earth2me.essentials.register.payment.Methods; import com.earth2me.essentials.register.payment.Methods;
import com.earth2me.essentials.signs.SignBlockListener; import com.earth2me.essentials.signs.SignBlockListener;
@ -215,7 +216,7 @@ public class Essentials extends JavaPlugin implements IEssentials
if (getSettings().isUpdateEnabled()) if (getSettings().isUpdateEnabled())
{ {
updateTimer = new EssentialsUpdateTimer(this); updateTimer = new EssentialsUpdateTimer(this);
getScheduler().scheduleAsyncRepeatingTask(this, updateTimer, 20 * 60, 20 * 3600 * 6); getScheduler().scheduleAsyncRepeatingTask(this, updateTimer, 20 * 60 * 10, 20 * 3600 * 6);
} }
LOGGER.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), Util.joinList(this.getDescription().getAuthors()))); LOGGER.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), Util.joinList(this.getDescription().getAuthors())));
} }
@ -451,6 +452,10 @@ public class Essentials extends JavaPlugin implements IEssentials
} }
return true; return true;
} }
catch (NoChargeException ex)
{
return true;
}
catch (NotEnoughArgumentsException ex) catch (NotEnoughArgumentsException ex)
{ {
sender.sendMessage(command.getDescription()); sender.sendMessage(command.getDescription());

View File

@ -20,6 +20,9 @@ import java.util.logging.Level;
public class Commandhelp extends EssentialsCommand public class Commandhelp extends EssentialsCommand
{ {
private static final String DESCRIPTION = "description";
private static final String PERMISSION = "permission";
private static final String PERMISSIONS = "permissions";
public final Yaml yaml = new Yaml(new SafeConstructor()); public final Yaml yaml = new Yaml(new SafeConstructor());
public Commandhelp() public Commandhelp()
@ -28,7 +31,7 @@ public class Commandhelp extends EssentialsCommand
} }
@Override @Override
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{ {
int page = 1; int page = 1;
String match = ""; String match = "";
@ -53,34 +56,32 @@ public class Commandhelp extends EssentialsCommand
} }
} }
List<String> lines = getHelpLines(user, match); final List<String> lines = getHelpLines(user, match);
if (lines.size() > 0) if (lines.isEmpty())
{ {
int start = (page - 1) * 9; throw new Exception(Util.i18n("noHelpFound"));
int pages = lines.size() / 9 + (lines.size() % 9 > 0 ? 1 : 0);
user.sendMessage(Util.format("helpPages", page, pages));
for (int i = start; i < lines.size() && i < start + 9; i++)
{
user.sendMessage(lines.get(i));
}
} }
else
final int start = (page - 1) * 9;
final int pages = lines.size() / 9 + (lines.size() % 9 > 0 ? 1 : 0);
user.sendMessage(Util.format("helpPages", page, pages));
for (int i = start; i < lines.size() && i < start + 9; i++)
{ {
user.sendMessage(Util.i18n("noHelpFound")); user.sendMessage(lines.get(i));
} }
} }
@Override @Override
protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{ {
sender.sendMessage(Util.i18n("helpConsole")); sender.sendMessage(Util.i18n("helpConsole"));
} }
@SuppressWarnings("CallToThreadDumpStack") @SuppressWarnings("CallToThreadDumpStack")
private List<String> getHelpLines(User user, String match) throws Exception private List<String> getHelpLines(final User user, final String match) throws Exception
{ {
List<String> retval = new ArrayList<String>(); final List<String> retval = new ArrayList<String>();
File helpFile = new File(ess.getDataFolder(), "help_" + Util.sanitizeFileName(user.getName()) + ".txt"); File helpFile = new File(ess.getDataFolder(), "help_" + Util.sanitizeFileName(user.getName()) + ".txt");
if (!helpFile.exists()) if (!helpFile.exists())
{ {
@ -116,15 +117,16 @@ public class Commandhelp extends EssentialsCommand
try try
{ {
final PluginDescriptionFile desc = p.getDescription(); final PluginDescriptionFile desc = p.getDescription();
final HashMap<String, HashMap<String, String>> cmds = (HashMap<String, HashMap<String, String>>)desc.getCommands(); final HashMap<String, HashMap<String, Object>> cmds = (HashMap<String, HashMap<String, Object>>)desc.getCommands();
pluginName = p.getDescription().getName().toLowerCase(); pluginName = p.getDescription().getName().toLowerCase();
for (Entry<String, HashMap<String, String>> k : cmds.entrySet()) for (Entry<String, HashMap<String, Object>> k : cmds.entrySet())
{ {
try try
{ {
if ((!match.equalsIgnoreCase("")) if ((!match.equalsIgnoreCase(""))
&& (!k.getKey().toLowerCase().contains(match)) && (!k.getKey().toLowerCase().contains(match))
&& (!k.getValue().get("description").toLowerCase().contains(match)) && (!(k.getValue().get(DESCRIPTION) instanceof String
&& ((String)k.getValue().get(DESCRIPTION)).toLowerCase().contains(match)))
&& (!pluginName.contains(match))) && (!pluginName.contains(match)))
{ {
continue; continue;
@ -135,37 +137,69 @@ public class Commandhelp extends EssentialsCommand
final String node = "essentials." + k.getKey(); final String node = "essentials." + k.getKey();
if (!ess.getSettings().isCommandDisabled(k.getKey()) && user.isAuthorized(node)) if (!ess.getSettings().isCommandDisabled(k.getKey()) && user.isAuthorized(node))
{ {
retval.add("§c" + k.getKey() + "§7: " + k.getValue().get("description")); retval.add("§c" + k.getKey() + "§7: " + k.getValue().get(DESCRIPTION));
} }
} }
else else
{ {
if (ess.getSettings().showNonEssCommandsInHelp()) if (ess.getSettings().showNonEssCommandsInHelp())
{ {
final HashMap<String, String> value = k.getValue(); final HashMap<String, Object> value = k.getValue();
if (value.containsKey("permission") && value.get("permission") != null && !(value.get("permission").equals(""))) if (value.containsKey(PERMISSION) && value.get(PERMISSION) instanceof String && !(value.get(PERMISSION).equals("")))
{ {
if (user.isAuthorized(value.get("permission"))) if (user.isAuthorized((String)value.get(PERMISSION)))
{ {
retval.add("§c" + k.getKey() + "§7: " + value.get("description")); retval.add("§c" + k.getKey() + "§7: " + value.get(DESCRIPTION));
} }
} }
else if (value.containsKey("permissions") && value.get("permissions") != null && !(value.get("permissions").equals(""))) else if (value.containsKey(PERMISSION) && value.get(PERMISSION) instanceof List && !((List<Object>)value.get(PERMISSION)).isEmpty())
{ {
if (user.isAuthorized(value.get("permissions"))) boolean enabled = false;
for (Object o : (List<Object>)value.get(PERMISSION))
{ {
retval.add("§c" + k.getKey() + "§7: " + value.get("description")); if (o instanceof String && user.isAuthorized((String)o))
{
enabled = true;
break;
}
}
if (enabled)
{
retval.add("§c" + k.getKey() + "§7: " + value.get(DESCRIPTION));
}
}
else if (value.containsKey(PERMISSIONS) && value.get(PERMISSIONS) instanceof String && !(value.get(PERMISSIONS).equals("")))
{
if (user.isAuthorized((String)value.get(PERMISSIONS)))
{
retval.add("§c" + k.getKey() + "§7: " + value.get(DESCRIPTION));
}
}
else if (value.containsKey(PERMISSIONS) && value.get(PERMISSIONS) instanceof List && !((List<Object>)value.get(PERMISSIONS)).isEmpty())
{
boolean enabled = false;
for (Object o : (List<Object>)value.get(PERMISSIONS))
{
if (o instanceof String && user.isAuthorized((String)o))
{
enabled = true;
break;
}
}
if (enabled)
{
retval.add("§c" + k.getKey() + "§7: " + value.get(DESCRIPTION));
} }
} }
else if (user.isAuthorized("essentials.help." + pluginName)) else if (user.isAuthorized("essentials.help." + pluginName))
{ {
retval.add("§c" + k.getKey() + "§7: " + value.get("description")); retval.add("§c" + k.getKey() + "§7: " + value.get(DESCRIPTION));
} }
else else
{ {
if (!ess.getSettings().hidePermissionlessHelp()) if (!ess.getSettings().hidePermissionlessHelp())
{ {
retval.add("§c" + k.getKey() + "§7: " + value.get("description")); retval.add("§c" + k.getKey() + "§7: " + value.get(DESCRIPTION));
} }
} }
} }

View File

@ -58,5 +58,6 @@ public class Commandhome extends EssentialsCommand
user.sendMessage(Util.format("homes", Util.joinList(homes))); user.sendMessage(Util.format("homes", Util.joinList(homes)));
} }
} }
throw new NoChargeException();
} }
} }

View File

@ -17,17 +17,17 @@ public class Commandpowertool extends EssentialsCommand
} }
@Override @Override
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{ {
ItemStack is = user.getItemInHand(); final ItemStack itemStack = user.getItemInHand();
List<String> powertools = user.getPowertool(is); if (itemStack == null || itemStack.getType() == Material.AIR)
if (is == null || is.getType() == Material.AIR)
{ {
throw new Exception(Util.i18n("powerToolAir")); throw new Exception(Util.i18n("powerToolAir"));
} }
String itemName = is.getType().toString().toLowerCase().replaceAll("_", " "); final String itemName = itemStack.getType().toString().toLowerCase().replaceAll("_", " ");
String command = getFinalArg(args, 0); String command = getFinalArg(args, 0);
List<String> powertools = user.getPowertool(itemStack);
if (command != null && !command.isEmpty()) if (command != null && !command.isEmpty())
{ {
if (command.equalsIgnoreCase("l:")) if (command.equalsIgnoreCase("l:"))
@ -66,7 +66,7 @@ public class Commandpowertool extends EssentialsCommand
if (command.startsWith("a:")) if (command.startsWith("a:"))
{ {
command = command.substring(2); command = command.substring(2);
if(powertools.contains(command)) if (powertools.contains(command))
{ {
throw new Exception(Util.format("powerToolAlreadySet", command, itemName)); throw new Exception(Util.format("powerToolAlreadySet", command, itemName));
} }
@ -87,10 +87,13 @@ public class Commandpowertool extends EssentialsCommand
} }
else else
{ {
powertools.clear(); if (powertools != null)
{
powertools.clear();
}
user.sendMessage(Util.format("powerToolRemoveAll", itemName)); user.sendMessage(Util.format("powerToolRemoveAll", itemName));
} }
user.setPowertool(is, powertools); user.setPowertool(itemStack, powertools);
} }
} }

View File

@ -33,7 +33,7 @@ public class Commandtp extends EssentialsCommand
Trade charge = new Trade(this.getName(), ess); Trade charge = new Trade(this.getName(), ess);
charge.isAffordableFor(user); charge.isAffordableFor(user);
user.getTeleport().teleport(p, charge); user.getTeleport().teleport(p, charge);
break; throw new NoChargeException();
case 2: case 2:
if (!user.isAuthorized("essentials.tpohere")) if (!user.isAuthorized("essentials.tpohere"))
@ -62,5 +62,6 @@ public class Commandtp extends EssentialsCommand
User toPlayer = getPlayer(server, args, 1); User toPlayer = getPlayer(server, args, 1);
target.getTeleport().now(toPlayer, false); target.getTeleport().now(toPlayer, false);
target.sendMessage(Util.format("teleportAtoB", Console.NAME, toPlayer.getDisplayName())); target.sendMessage(Util.format("teleportAtoB", Console.NAME, toPlayer.getDisplayName()));
return;
} }
} }

View File

@ -24,5 +24,6 @@ public class Commandtphere extends EssentialsCommand
p.getTeleport().teleport(user, new Trade(this.getName(), ess)); p.getTeleport().teleport(user, new Trade(this.getName(), ess));
user.sendMessage(Util.i18n("teleporting")); user.sendMessage(Util.i18n("teleporting"));
p.sendMessage(Util.i18n("teleporting")); p.sendMessage(Util.i18n("teleporting"));
throw new NoChargeException();
} }
} }

View File

@ -30,5 +30,6 @@ public class Commandtppos extends EssentialsCommand
charge.isAffordableFor(user); charge.isAffordableFor(user);
user.sendMessage(Util.i18n("teleporting")); user.sendMessage(Util.i18n("teleporting"));
user.getTeleport().teleport(l, charge); user.getTeleport().teleport(l, charge);
throw new NoChargeException();
} }
} }

View File

@ -26,8 +26,7 @@ public class Commandwarp extends EssentialsCommand
{ {
if (!user.isAuthorized("essentials.warp.list")) if (!user.isAuthorized("essentials.warp.list"))
{ {
user.sendMessage(Util.i18n("warpListPermission")); throw new Exception(Util.i18n("warpListPermission"));
return;
} }
Warps warps = ess.getWarps(); Warps warps = ess.getWarps();
@ -56,7 +55,7 @@ public class Commandwarp extends EssentialsCommand
} }
final int warpPage = (page - 1) * WARPS_PER_PAGE; final int warpPage = (page - 1) * WARPS_PER_PAGE;
user.sendMessage(Util.joinList(warpNameList.subList(warpPage, warpPage+Math.min(warpNameList.size() - warpPage, WARPS_PER_PAGE)))); user.sendMessage(Util.joinList(warpNameList.subList(warpPage, warpPage+Math.min(warpNameList.size() - warpPage, WARPS_PER_PAGE))));
return; throw new NoChargeException();
} }
if (args.length > 0) if (args.length > 0)
{ {
@ -66,13 +65,13 @@ public class Commandwarp extends EssentialsCommand
otherUser = ess.getUser(server.getPlayer(args[1])); otherUser = ess.getUser(server.getPlayer(args[1]));
if (otherUser == null) if (otherUser == null)
{ {
user.sendMessage(Util.i18n("playerNotFound")); throw new Exception(Util.i18n("playerNotFound"));
return;
} }
warpUser(otherUser, args[0]); warpUser(otherUser, args[0]);
return; throw new NoChargeException();
} }
warpUser(user, args[0]); warpUser(user, args[0]);
throw new NoChargeException();
} }
} }
@ -87,8 +86,7 @@ public class Commandwarp extends EssentialsCommand
user.getTeleport().warp(name, charge); user.getTeleport().warp(name, charge);
return; return;
} }
user.sendMessage(Util.i18n("warpUsePermission")); throw new Exception(Util.i18n("warpUsePermission"));
return;
} }
user.getTeleport().warp(name, charge); user.getTeleport().warp(name, charge);
} }

View File

@ -47,7 +47,7 @@ public class Commandworld extends EssentialsCommand
user.sendMessage(Util.i18n("invalidWorld")); user.sendMessage(Util.i18n("invalidWorld"));
user.sendMessage(Util.format("possibleWorlds", server.getWorlds().size() - 1)); user.sendMessage(Util.format("possibleWorlds", server.getWorlds().size() - 1));
user.sendMessage(Util.i18n("typeWorldName")); user.sendMessage(Util.i18n("typeWorldName"));
return; throw new NoChargeException();
} }
} }
@ -71,5 +71,6 @@ public class Commandworld extends EssentialsCommand
Trade charge = new Trade(this.getName(), ess); Trade charge = new Trade(this.getName(), ess);
charge.isAffordableFor(user); charge.isAffordableFor(user);
user.getTeleport().teleport(loc, charge); user.getTeleport().teleport(loc, charge);
throw new NoChargeException();
} }
} }

View File

@ -0,0 +1,10 @@
package com.earth2me.essentials.commands;
public class NoChargeException extends Exception
{
public NoChargeException()
{
super("Will charge later");
}
}