Merge branch '2.9' of github.com:essentials/Essentials into 2.9

This commit is contained in:
KHobbits 2013-04-29 23:50:49 +01:00
commit 012741fea6
25 changed files with 214 additions and 101 deletions

View File

@ -43,6 +43,7 @@ public class I18n implements II18n
instance = null;
}
@Override
public Locale getCurrentLocale()
{
return currentLocale;

View File

@ -1,5 +1,6 @@
package com.earth2me.essentials;
public interface IConf {
public interface IConf
{
public void reloadConfig();
}

View File

@ -2,8 +2,17 @@ package com.earth2me.essentials;
import org.bukkit.command.CommandSender;
public interface IReplyTo {
public interface IReplyTo
{
/**
* Sets the user to reply to
* @param user
*/
public void setReplyTo(CommandSender user);
/**
* Gets the user the sender should reply to
* @return
*/
public CommandSender getReplyTo();
}

View File

@ -4,6 +4,9 @@ import static com.earth2me.essentials.I18n._;
import static com.earth2me.essentials.I18n.capitalCase;
import com.earth2me.essentials.commands.NoChargeException;
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
import com.earth2me.essentials.textreader.IText;
import com.earth2me.essentials.textreader.KeywordReplacer;
import com.earth2me.essentials.textreader.SimpleTextInput;
import java.util.*;
import java.util.logging.Level;
import org.bukkit.configuration.ConfigurationSection;
@ -102,24 +105,28 @@ public class Kit
{
try
{
IText input = new SimpleTextInput(items);
IText output = new KeywordReplacer(input, user, ess);
boolean spew = false;
final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments();
for (String d : items)
for (String kitItem : output.getLines())
{
if (d.startsWith(ess.getSettings().getCurrencySymbol()))
if (kitItem.startsWith(ess.getSettings().getCurrencySymbol()))
{
Double value = Double.parseDouble(d.substring(ess.getSettings().getCurrencySymbol().length()).trim());
Double value = Double.parseDouble(kitItem.substring(ess.getSettings().getCurrencySymbol().length()).trim());
Trade t = new Trade(value, ess);
t.pay(user);
continue;
}
final String[] parts = d.split(" ");
final String[] parts = kitItem.split(" ");
final ItemStack parseStack = ess.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1);
final MetaItemStack metaStack = new MetaItemStack(parseStack);
if (parts.length > 2)
{
// We pass a null sender here because kits should not do perm checks
metaStack.parseStringMeta(null, allowUnsafe, parts, 2, ess);
}

View File

@ -1,6 +1,8 @@
package com.earth2me.essentials;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IWarps;
import com.earth2me.essentials.api.InvalidNameException;
import com.earth2me.essentials.commands.WarpNotFoundException;
import java.io.File;
import java.io.IOException;
@ -11,7 +13,7 @@ import org.bukkit.Location;
import org.bukkit.Server;
public class Warps implements IConf
public class Warps implements IConf, IWarps
{
private static final Logger logger = Logger.getLogger("Minecraft");
private final Map<StringIgnoreCase, EssentialsConf> warpPoints = new HashMap<StringIgnoreCase, EssentialsConf>();
@ -29,6 +31,7 @@ public class Warps implements IConf
reloadConfig();
}
@Override
public boolean isEmpty()
{
return warpPoints.isEmpty();
@ -45,6 +48,7 @@ public class Warps implements IConf
return keys;
}
@Override
public Location getWarp(String warp) throws Exception
{
EssentialsConf conf = warpPoints.get(new StringIgnoreCase(warp));
@ -55,6 +59,7 @@ public class Warps implements IConf
return conf.getLocation(null, server);
}
@Override
public void setWarp(String name, Location loc) throws Exception
{
String filename = Util.sanitizeFileName(name);
@ -126,6 +131,26 @@ public class Warps implements IConf
}
}
// This is for api support, and so 3.x will not break this api
@Override
public Collection<String> getList()
{
return getWarpNames();
}
// This is for api support, and so 3.x will not break this api
@Override
public void removeWarp(String name) throws Exception
{
delWarp(name);
}
//This is here for future 3.x api support. Not implemented here becasue storage is handled differently
@Override
public File getWarpFile(String name) throws InvalidNameException
{
throw new UnsupportedOperationException("Not supported yet.");
}
private static class StringIgnoreCase
{

View File

@ -0,0 +1,60 @@
package com.earth2me.essentials.api;
import java.io.File;
import java.util.Collection;
import org.bukkit.Location;
public interface IWarps
{
/**
* Get a warp by name
*
* @param warp - Warp name
* @return - Location the warp is set to
* @throws Exception
*/
Location getWarp(String warp) throws Exception;
/**
* Gets a list of warps
*
* @return - A {@link Collection} of warps
*/
Collection<String> getList();
/**
* Delete a warp from the warp DB
*
* @param name - Name of warp
* @throws Exception
*/
void removeWarp(String name) throws Exception;
/**
* Set a warp
*
* @param name - Name of warp
* @param loc - Location of warp
* @throws Exception
*/
void setWarp(String name, Location loc) throws Exception;
/**
* Check to see if the file is empty
*
* @return
*/
boolean isEmpty();
/**
* Get a warp file
* note: this is not yet implemented, as 3.x uses different storage methods
*
* @param name - name of file
* @return - an instance of the file
* @throws InvalidNameException - When the file is not found
*/
File getWarpFile(String name) throws InvalidNameException;
}

View File

@ -0,0 +1,16 @@
package com.earth2me.essentials.api;
public class InvalidNameException extends Exception
{
/**
* NOTE: This is not implemented yet, just here for future 3.x api support
* Allow serialization of the InvalidNameException exception
*/
private static final long serialVersionUID = 1485321420293663139L;
public InvalidNameException(Throwable thrwbl)
{
super(thrwbl);
}
}

View File

@ -3,7 +3,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import com.earth2me.essentials.textreader.ArrayListInput;
import com.earth2me.essentials.textreader.SimpleTextInput;
import com.earth2me.essentials.textreader.TextPager;
import java.text.DateFormat;
import java.util.*;
@ -21,7 +21,7 @@ public class Commandbalancetop extends EssentialsCommand
}
private static final int CACHETIME = 2 * 60 * 1000;
public static final int MINUSERS = 50;
private static ArrayListInput cache = new ArrayListInput();
private static SimpleTextInput cache = new SimpleTextInput();
private static long cacheage = 0;
private static ReentrantReadWriteLock lock = new ReentrantReadWriteLock();

View File

@ -19,27 +19,26 @@ public class Commandeco extends EssentialsCommand
@Override
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
Double broadcast = null;
Double broadcastAll = null;
final double startingBalance = (double)ess.getSettings().getStartingBalance();
if (args.length < 2)
{
throw new NotEnoughArgumentsException();
}
EcoCommands cmd;
Commandeco.EcoCommands cmd;
double startingBalance = (double)ess.getSettings().getStartingBalance();
double amount;
Double broadcast = null;
Double broadcastAll = null;
try
{
cmd = EcoCommands.valueOf(args[0].toUpperCase(Locale.ENGLISH));
amount = Double.parseDouble(args[2].replaceAll("[^0-9\\.]", ""));
cmd = Commandeco.EcoCommands.valueOf(args[0].toUpperCase(Locale.ENGLISH));
amount = (cmd == Commandeco.EcoCommands.RESET) ? startingBalance : Double.parseDouble(args[2].replaceAll("[^0-9\\.]", ""));
}
catch (Exception ex)
{
throw new NotEnoughArgumentsException(ex);
}
final double minBalance = ess.getSettings().getMinMoney();
if (args[1].contentEquals("**"))
{
for (String sUser : ess.getUserMap().getAllUniqueUsers())
@ -52,28 +51,13 @@ public class Commandeco extends EssentialsCommand
break;
case TAKE:
if (player.canAfford(amount, false))
{
player.takeMoney(amount);
}
else
{
if (player.getMoney() > 0)
{
player.setMoney(0);
}
}
take(amount, player, null);
break;
case RESET:
player.setMoney(startingBalance);
broadcastAll = startingBalance;
break;
case SET:
boolean underMinimum = (player.getMoney() - amount) < minBalance;
player.setMoney(underMinimum ? minBalance : amount);
broadcastAll = underMinimum ? minBalance : amount;
set(amount, player, null);
broadcastAll = amount;
break;
}
}
@ -90,28 +74,13 @@ public class Commandeco extends EssentialsCommand
break;
case TAKE:
if (player.canAfford(amount))
{
player.takeMoney(amount);
}
else
{
if (player.getMoney() > 0)
{
player.setMoney(0);
}
}
take(amount, player, null);
break;
case RESET:
player.setMoney(startingBalance);
broadcast = startingBalance;
break;
case SET:
boolean underMinimum = (player.getMoney() - amount) < minBalance;
player.setMoney(underMinimum ? minBalance : amount);
broadcast = underMinimum ? minBalance : amount;
set(amount, player, null);
broadcast = amount;
break;
}
}
@ -126,21 +95,12 @@ public class Commandeco extends EssentialsCommand
break;
case TAKE:
if (!player.canAfford(amount))
{
throw new Exception(_("notEnoughMoney"));
}
player.takeMoney(amount, sender);
take(amount, player, sender);
break;
case RESET:
player.setMoney(startingBalance);
break;
case SET:
boolean underMinimum = (player.getMoney() - amount) < minBalance;
player.setMoney(underMinimum ? minBalance : amount);
set(amount, player, sender);
break;
}
}
@ -155,9 +115,37 @@ public class Commandeco extends EssentialsCommand
}
}
private void take(double amount, final User player, final CommandSender sender)
{
double money = player.getMoney();
double minBalance = ess.getSettings().getMinMoney();
if (money - amount > minBalance)
{
player.takeMoney(amount, sender);
}
else
{
player.sendMessage(_("takenFromAccount", Util.displayCurrency(money - minBalance, ess)));
sender.sendMessage(_("takenFromOthersAccount", Util.displayCurrency(money - minBalance, ess), player.getDisplayName(), Util.displayCurrency(player.getMoney(), ess)));
player.setMoney(minBalance);
}
}
private void set(double amount, final User player, final CommandSender sender)
{
double minBalance = ess.getSettings().getMinMoney();
boolean underMinimum = amount < minBalance;
player.setMoney(underMinimum ? minBalance : amount);
player.sendMessage(_("setBal", Util.displayCurrency(player.getMoney(), ess)));
if (sender != null)
{
sender.sendMessage(_("setBalOthers", player.getDisplayName(), Util.displayCurrency(player.getMoney(), ess)));
}
}
private enum EcoCommands
{
GIVE, TAKE, RESET, SET
GIVE, TAKE, SET, RESET
}
}
}

View File

@ -1,31 +0,0 @@
package com.earth2me.essentials.textreader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class ArrayListInput implements IText
{
private final transient List<String> lines = new ArrayList<String>();
@Override
public List<String> getLines()
{
return lines;
}
@Override
public List<String> getChapters()
{
return Collections.emptyList();
}
@Override
public Map<String, Integer> getBookmarks()
{
return Collections.emptyMap();
}
}

View File

@ -6,11 +6,21 @@ import java.util.*;
public class SimpleTextInput implements IText
{
private final transient List<String> lines = new ArrayList<String>();
public SimpleTextInput (final String input) {
public SimpleTextInput(final String input)
{
lines.addAll(Arrays.asList(input.split("\\n")));
}
public SimpleTextInput(final List<String> input)
{
lines.addAll(input);
}
public SimpleTextInput()
{
}
@Override
public List<String> getLines()
{
@ -28,5 +38,4 @@ public class SimpleTextInput implements IText
{
return Collections.emptyMap();
}
}

View File

@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
cannotStackMob=\u00a74You do not have permission to stack multiple mobs.
kitNotFound=\u00a74That kit does not exist.
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
setBal=\u00a7aYour balance was set to {0}.
setBalOthers=\u00a7aYou set {0}''s balance to {1}.

View File

@ -538,3 +538,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
kitNotFound=\u00a74That kit does not exist.
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
setBal=\u00a7aYour balance was set to {0}.
setBalOthers=\u00a7aYou set {0}''s balance to {1}.

View File

@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
kitNotFound=\u00a74That kit does not exist.
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
setBal=\u00a7aYour balance was set to {0}.
setBalOthers=\u00a7aYou set {0}''s balance to {1}.

View File

@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
kitNotFound=\u00a74That kit does not exist.
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
setBal=\u00a7aYour balance was set to {0}.
setBalOthers=\u00a7aYou set {0}''s balance to {1}.

View File

@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
cannotStackMob=\u00a74You do not have permission to stack multiple mobs.
kitNotFound=\u00a74That kit does not exist.
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
setBal=\u00a7aYour balance was set to {0}.
setBalOthers=\u00a7aYou set {0}''s balance to {1}.

View File

@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
kitNotFound=\u00a74That kit does not exist.
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
setBal=\u00a7aYour balance was set to {0}.
setBalOthers=\u00a7aYou set {0}''s balance to {1}.

View File

@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
kitNotFound=\u00a74That kit does not exist.
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
setBal=\u00a7aYour balance was set to {0}.
setBalOthers=\u00a7aYou set {0}''s balance to {1}.

View File

@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
kitNotFound=\u00a74That kit does not exist.
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
setBal=\u00a7aYour balance was set to {0}.
setBalOthers=\u00a7aYou set {0}''s balance to {1}.

View File

@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
kitNotFound=\u00a74That kit does not exist.
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
setBal=\u00a7aYour balance was set to {0}.
setBalOthers=\u00a7aYou set {0}''s balance to {1}.

View File

@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
kitNotFound=\u00a74That kit does not exist.
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
setBal=\u00a7aYour balance was set to {0}.
setBalOthers=\u00a7aYou set {0}''s balance to {1}.

View File

@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Niepoprawny typ pogody
cannotStackMob=\u00a74Nie masz uprawnien by stackowac wiele mobow
kitNotFound=\u00a74That kit does not exist.
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
setBal=\u00a7aYour balance was set to {0}.
setBalOthers=\u00a7aYou set {0}''s balance to {1}.

View File

@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
kitNotFound=\u00a74That kit does not exist.
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
setBal=\u00a7aYour balance was set to {0}.
setBalOthers=\u00a7aYou set {0}''s balance to {1}.

View File

@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
kitNotFound=\u00a74That kit does not exist.
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
setBal=\u00a7aYour balance was set to {0}.
setBalOthers=\u00a7aYou set {0}''s balance to {1}.

View File

@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
kitNotFound=\u00a74That kit does not exist.
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
setBal=\u00a7aYour balance was set to {0}.
setBalOthers=\u00a7aYou set {0}''s balance to {1}.