Merge branch 'refs/heads/master' into release

This commit is contained in:
snowleo 2011-11-28 20:03:09 +01:00
commit 3d839c2b21
20 changed files with 193 additions and 58 deletions

View File

@ -31,7 +31,7 @@ public interface ISettings extends IConf
String getCurrencySymbol();
int getDefaultStackSize();
int getOversizedStackSize();
double getHealCooldown();

View File

@ -81,10 +81,10 @@ public final class InventoryWorkaround
public static Map<Integer, ItemStack> addItem(final Inventory cinventory, final boolean forceDurability, final ItemStack... items)
{
return addItem(cinventory, forceDurability, false, null, items);
return addItem(cinventory, forceDurability, 0, items);
}
public static Map<Integer, ItemStack> addItem(final Inventory cinventory, final boolean forceDurability, final boolean dontBreakStacks, final IEssentials ess, final ItemStack... items)
public static Map<Integer, ItemStack> addItem(final Inventory cinventory, final boolean forceDurability, final int oversizedStacks, final ItemStack... items)
{
final Map<Integer, ItemStack> leftover = new HashMap<Integer, ItemStack>();
@ -146,11 +146,12 @@ public final class InventoryWorkaround
}
else
{
final int maxAmount = oversizedStacks > 0 ? oversizedStacks : item.getType().getMaxStackSize();
// More than a single stack!
if (item.getAmount() > (dontBreakStacks ? ess.getSettings().getDefaultStackSize() : item.getType().getMaxStackSize()))
if (item.getAmount() > maxAmount)
{
ItemStack stack = item.clone();
stack.setAmount(dontBreakStacks ? ess.getSettings().getDefaultStackSize() : item.getType().getMaxStackSize());
final ItemStack stack = item.clone();
stack.setAmount(maxAmount);
if (cinventory instanceof FakeInventory)
{
cinventory.setItem(firstFree, stack);
@ -159,7 +160,7 @@ public final class InventoryWorkaround
{
EnchantmentFix.setItem(cinventory, firstFree, stack);
}
item.setAmount(item.getAmount() - item.getType().getMaxStackSize());
item.setAmount(item.getAmount() - maxAmount);
}
else
{
@ -183,7 +184,7 @@ public final class InventoryWorkaround
final int amount = item.getAmount();
final int partialAmount = partialItem.getAmount();
final int maxAmount = dontBreakStacks ? ess.getSettings().getDefaultStackSize() : partialItem.getType().getMaxStackSize();
final int maxAmount = oversizedStacks > 0 ? oversizedStacks : partialItem.getType().getMaxStackSize();
// Check if it fully fits
if (amount + partialAmount <= maxAmount)

View File

@ -114,7 +114,7 @@ public class ItemDb implements IConf
throw new Exception(_("unknownItemId", itemid));
}
final ItemStack retval = new ItemStack(mat);
retval.setAmount(ess.getSettings().getDefaultStackSize());
retval.setAmount(mat.getMaxStackSize());
retval.setDurability(metaData);
return retval;
}

View File

@ -38,7 +38,7 @@ public enum Mob
BLAZE("Blaze", Enemies.ENEMY, CreatureType.BLAZE),
MUSHROOMCOW("MushroomCow", Enemies.FRIENDLY, CreatureType.MUSHROOM_COW),
MAGMACUBE("MagmaCube", Enemies.ENEMY, CreatureType.MAGMA_CUBE),
SNOWMAN("Snowman", Enemies.FRIENDLY, CreatureType.SNOWMAN);
SNOWMAN("Snowman", Enemies.FRIENDLY, "", CreatureType.SNOWMAN);
public static final Logger logger = Logger.getLogger("Minecraft");

View File

@ -82,9 +82,9 @@ public class Settings implements ISettings
}
@Override
public int getDefaultStackSize()
public int getOversizedStackSize()
{
return config.getInt("default-stack-size", 64);
return config.getInt("oversized-stacksize", 64);
}
@Override
@ -189,13 +189,13 @@ public class Settings implements ISettings
@Override
public double getTeleportCooldown()
{
return config.getDouble("teleport-cooldown", 60);
return config.getDouble("teleport-cooldown", 0);
}
@Override
public double getHealCooldown()
{
return config.getDouble("heal-cooldown", 60);
return config.getDouble("heal-cooldown", 0);
}
@Override
@ -246,7 +246,7 @@ public class Settings implements ISettings
@Override
public boolean getReclaimSetting()
{
return config.getBoolean("reclaim-onlogout", true);
return config.getBoolean("reclaim-onlogout", false);
}
@Override

View File

@ -5,12 +5,10 @@ import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.collect.ConcurrentHashMultiset;
import java.io.File;
import java.util.HashSet;
import java.util.Collections;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -104,21 +102,9 @@ public class UserMap extends CacheLoader<String, User> implements IConf
users.invalidate(name.toLowerCase(Locale.ENGLISH));
}
public Set<User> getAllUsers()
public Set<String> getAllUniqueUsers()
{
final Set<User> userSet = new HashSet<User>();
for (String name : keys)
{
try
{
userSet.add(users.get(name));
}
catch (ExecutionException ex)
{
Bukkit.getLogger().log(Level.INFO, "Failed to load user " + name, ex);
}
}
return userSet;
return Collections.unmodifiableSet(keys.elementSet());
}
public int getUniqueUsers()

View File

@ -1,10 +1,10 @@
package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
@ -15,6 +15,12 @@ public class Commandbalancetop extends EssentialsCommand
{
super("balancetop");
}
private static final int CACHETIME = 5 * 60 * 1000;
public static final int MINUSERS = 50;
private static List<String> cache = new ArrayList<String>();
private static long cacheage = 0;
private static ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
@Override
protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
@ -24,7 +30,7 @@ public class Commandbalancetop extends EssentialsCommand
{
try
{
if (Integer.parseInt(args[0]) < 10)
if (Integer.parseInt(args[0]) < 19)
{
max = Integer.parseInt(args[0]);
}
@ -34,31 +40,141 @@ public class Commandbalancetop extends EssentialsCommand
//catch it because they tried to enter a string not number.
}
}
final Map<User, Double> balances = new HashMap<User, Double>();
for (User u : ess.getUserMap().getAllUsers())
if (lock.readLock().tryLock())
{
balances.put(u, u.getMoney());
try
{
if (cacheage > System.currentTimeMillis() - CACHETIME)
{
outputCache(sender, max);
return;
}
if (ess.getUserMap().getUniqueUsers() > MINUSERS)
{
sender.sendMessage(_("orderBalances", ess.getUserMap().getUniqueUsers()));
}
}
finally
{
lock.readLock().unlock();
}
ess.scheduleAsyncDelayedTask(new Viewer(sender, max));
}
else
{
if (ess.getUserMap().getUniqueUsers() > MINUSERS)
{
sender.sendMessage(_("orderBalances", ess.getUserMap().getUniqueUsers()));
}
ess.scheduleAsyncDelayedTask(new Viewer(sender, max));
}
final List<Map.Entry<User, Double>> sortedEntries = new ArrayList<Map.Entry<User, Double>>(balances.entrySet());
Collections.sort(sortedEntries, new Comparator<Map.Entry<User, Double>>()
{
@Override
public int compare(final Entry<User, Double> entry1, final Entry<User, Double> entry2)
{
return -entry1.getValue().compareTo(entry2.getValue());
}
});
int count = 0;
}
private static void outputCache(final CommandSender sender, int max)
{
sender.sendMessage(_("balanceTop", max));
for (Map.Entry<User, Double> entry : sortedEntries)
for (String line : cache)
{
if (count == max)
if (max == 0)
{
break;
}
sender.sendMessage(entry.getKey().getDisplayName() + ", " + Util.formatCurrency(entry.getValue(), ess));
count++;
max--;
sender.sendMessage(line);
}
}
private class Calculator implements Runnable
{
private final transient Viewer viewer;
public Calculator(final Viewer viewer)
{
this.viewer = viewer;
}
@Override
public void run()
{
lock.writeLock().lock();
try
{
if (cacheage < System.currentTimeMillis() - 5 * 60 * 1000)
{
final Map<String, Double> balances = new HashMap<String, Double>();
for (String u : ess.getUserMap().getAllUniqueUsers())
{
try
{
balances.put(u, ess.getUserMap().getUser(u).getMoney());
}
catch (NullPointerException ex)
{
}
}
final List<Map.Entry<String, Double>> sortedEntries = new ArrayList<Map.Entry<String, Double>>(balances.entrySet());
Collections.sort(sortedEntries, new Comparator<Map.Entry<String, Double>>()
{
@Override
public int compare(final Entry<String, Double> entry1, final Entry<String, Double> entry2)
{
return -entry1.getValue().compareTo(entry2.getValue());
}
});
int count = 0;
for (Map.Entry<String, Double> entry : sortedEntries)
{
if (count == 20)
{
break;
}
cache.add(entry.getKey() + ", " + Util.formatCurrency(entry.getValue(), ess));
count++;
}
cacheage = System.currentTimeMillis();
}
}
finally
{
lock.writeLock().unlock();
}
ess.scheduleAsyncDelayedTask(viewer);
}
}
private class Viewer implements Runnable
{
private final transient CommandSender sender;
private final transient int max;
public Viewer(final CommandSender sender, final int max)
{
this.sender = sender;
this.max = max;
}
@Override
public void run()
{
lock.readLock().lock();
try
{
if (cacheage > System.currentTimeMillis() - 5 * 60 * 1000)
{
outputCache(sender, max);
return;
}
}
finally
{
lock.readLock().unlock();
}
ess.scheduleAsyncDelayedTask(new Calculator(new Viewer(sender, max)));
}
}
}

View File

@ -77,7 +77,11 @@ public class Commandgive extends EssentialsCommand
final User giveTo = getPlayer(server, args, 0);
final String itemName = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' ');
sender.sendMessage(ChatColor.BLUE + "Giving " + stack.getAmount() + " of " + itemName + " to " + giveTo.getDisplayName() + ".");
InventoryWorkaround.addItem(giveTo.getInventory(), true, true, ess, stack);
if (giveTo.isAuthorized("essentials.oversizedstacks")) {
InventoryWorkaround.addItem(giveTo.getInventory(), true, ess.getSettings().getOversizedStackSize(), stack);
} else {
InventoryWorkaround.addItem(giveTo.getInventory(), true, stack);
}
giveTo.updateInventory();
}
}

View File

@ -72,7 +72,11 @@ public class Commanditem extends EssentialsCommand
final String displayName = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' ');
user.sendMessage(_("itemSpawn", stack.getAmount(), displayName));
InventoryWorkaround.addItem(user.getInventory(), true, true, ess, stack);
if (user.isAuthorized("essentials.oversizedstacks")) {
InventoryWorkaround.addItem(user.getInventory(), true, ess.getSettings().getOversizedStackSize(), stack);
} else {
InventoryWorkaround.addItem(user.getInventory(), true, stack);
}
user.updateInventory();
}
}

View File

@ -119,12 +119,16 @@ public class Commandsell extends EssentialsCommand
{
continue;
}
if (!s.getEnchantments().equals(is.getEnchantments()))
{
continue;
}
max += s.getAmount();
}
if (stack)
{
amount *= 64;
amount *= is.getType().getMaxStackSize();
}
if (amount < 1)
{
@ -133,7 +137,7 @@ public class Commandsell extends EssentialsCommand
if (requireStack)
{
amount -= amount % 64;
amount -= amount % is.getType().getMaxStackSize();
}
if (amount > max || amount < 1)
{

View File

@ -53,9 +53,6 @@ teleport-delay: 0
# The delay, in seconds, required between /heal attempts
heal-cooldown: 60
# The number of items given if the quantity parameter is left out in /item or /give.
default-stack-size: 64
# What to prevent from /i /give
# e.g item-spawn-blacklist: 46,11,10
item-spawn-blacklist:
@ -230,6 +227,11 @@ death-messages: true
no-god-in-worlds:
# - world_nether
# Oversized stacks are stacks that ignore the normal max stacksize.
# They can be obtained using /give and /item, if the player has essentials.oversizedstacks permission.
# How many items should be in a oversized stack?
oversized-stacksize: 64
############################################################
# +------------------------------------------------------+ #
# | EssentialsHome | #
@ -388,6 +390,7 @@ protect:
creeper-playerdamage: false
creeper-blockdamage: false
enderman-pickup: false
villager-death: false
# Monsters won't follow players
# permission essentials.protect.entitytarget.bypass disables this
entitytarget: false
@ -415,6 +418,8 @@ protect:
villager: false
blaze: false
mushroom_cow: false
magma_cube: false
snowman: false
# Maximum height the creeper should explode. -1 allows them to explode everywhere.
# Set prevent.creeper-explosion to true, if you want to disable creeper explosions.

View File

@ -232,6 +232,7 @@ numberRequired=A number goes there, silly.
onlyDayNight=/time only supports day/night.
onlyPlayers=Only in-game players can use {0}.
onlySunStorm=/weather only supports sun/storm.
orderBalances=Ordering balances of {0} users, please wait ...
pTimeCurrent=\u00a7e{0}''s\u00a7f time is {1}.
pTimeCurrentFixed=\u00a7e{0}''s\u00a7f time is fixed to {1}.
pTimeNormal=\u00a7e{0}''s\u00a7f time is normal and matches the server.

View File

@ -232,6 +232,7 @@ numberRequired=Der skal v\u00e6re et nummer, fjolle.
onlyDayNight=/time underst\u00f8tter kun day/night.
onlyPlayers=Kun in-game spillere kan bruge {0}.
onlySunStorm=/weather only supports sun/storm.
orderBalances=Ordering balances of {0} users, please wait ...
pTimeCurrent=\u00a7e{0}''s\u00a7f time is {1}.
pTimeCurrentFixed=\u00a7e{0}''s\u00a7f time is fixed to {1}.
pTimeNormal=\u00a7e{0}''s\u00a7f time is normal and matches the server.

View File

@ -232,6 +232,7 @@ numberRequired=Ein Zahl wird ben\u00f6tigt.
onlyDayNight=/time unterst\u00fctzt nur day und night.
onlyPlayers=Nur Spieler k\u00f6nnen {0} benutzen.
onlySunStorm=/weather unterst\u00fctzt nur sun und storm.
orderBalances=Ordering balances of {0} users, please wait ...
pTimeCurrent=\u00a7e{0}''s\u00a7f time is {1}.
pTimeCurrentFixed=\u00a7e{0}''s\u00a7f Zeit wurde zu {1} gesetzt.
pTimeNormal=\u00a7e{0}''s\u00a7f Zeit ist normal und entspricht der Serverzeit.

View File

@ -232,6 +232,7 @@ numberRequired=A number goes there, silly.
onlyDayNight=/time only supports day/night.
onlyPlayers=Only in-game players can use {0}.
onlySunStorm=/weather only supports sun/storm.
orderBalances=Ordering balances of {0} users, please wait ...
pTimeCurrent=\u00a7e{0}''s\u00a7f time is {1}.
pTimeCurrentFixed=\u00a7e{0}''s\u00a7f time is fixed to {1}.
pTimeNormal=\u00a7e{0}''s\u00a7f time is normal and matches the server.

View File

@ -232,6 +232,7 @@ numberRequired=Un numero es necesario, amigo.
onlyDayNight=/time solo soporta day/night. (dia/noche)
onlyPlayers=Solo los jugadores conectados pueden usar {0}.
onlySunStorm=/weather solo soporta sun/storm. (sol/tormenta)
orderBalances=Ordering balances of {0} users, please wait ...
pTimeCurrent=\u00a7e{0}''s\u00a7f la hora es {1}.
pTimeCurrentFixed=\u00a7e{0}''s\u00a7f la hora ha sido cambiada a {1}.
pTimeNormal=\u00a7e{0}''s\u00a7f el tiempo es normal y coincide con el servidor.

View File

@ -232,6 +232,7 @@ numberRequired=Il faut fournir un nombre ici.
onlyDayNight=/time ne supporte que (jour) day/night (nuit).
onlyPlayers=Seulement les joueurs en jeu peuvent utiliser {0}.
onlySunStorm=/weather ne supporte que (soleil) sun/storm (temp\u00eate).
orderBalances=Ordering balances of {0} users, please wait ...
pTimeCurrent=\u00a7e{0}''s\u00a7f l''heure est {1}.
pTimeCurrentFixed=\u00a7e{0}''s\u00a7f l''heure est fix\u00e9e \u00e0 {1}.
pTimeNormal=\u00a7e{0}''s\u00a7f l''heure est normale et correspond au server.

View File

@ -232,6 +232,7 @@ numberRequired=Er moet daar een nummer, grapjas.
onlyDayNight=/time ondersteund alleen day/night.
onlyPlayers=Alleen in-game spelers kunnen {0} gebruiken.
onlySunStorm=/weather only supports sun/storm.
orderBalances=Ordering balances of {0} users, please wait ...
pTimeCurrent=\u00a7e{0}''s\u00a7f time is {1}.
pTimeCurrentFixed=\u00a7e{0}''s\u00a7f time is fixed to {1}.
pTimeNormal=\u00a7e{0}''s\u00a7f time is normal and matches the server.

View File

@ -32,6 +32,13 @@ public class EssentialsProtectEntityListener extends EntityListener
return;
}
final Entity target = event.getEntity();
if (target instanceof Villager && prot.getSettingBool(ProtectConfig.prevent_villager_death))
{
event.setCancelled(true);
return;
}
final User user = ess.getUser(target);
if (event instanceof EntityDamageByBlockEvent)
{

View File

@ -40,6 +40,7 @@ public enum ProtectConfig
prevent_creeper_playerdmg("protect.prevent.creeper-playerdamage", false),
prevent_creeper_blockdmg("protect.prevent.creeper-blockdamage", false),
prevent_enderman_pickup("protect.prevent.enderman-pickup", false),
prevent_villager_death("protect.prevent.villager-death", false),
prevent_entitytarget("protect.prevent.entitytarget", false),
protect_rails("protect.protect.rails", true),
protect_below_rails("protect.protect.block-below", true),