Merge remote branch 'remotes/origin/master' into release

This commit is contained in:
KHobbits 2012-01-16 12:43:09 +00:00
commit c7c7e5e4ce
13 changed files with 260 additions and 112 deletions

View File

@ -49,6 +49,9 @@ import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.world.WorldListener;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import org.bukkit.plugin.InvalidDescriptionException;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
@ -242,6 +245,10 @@ public class Essentials extends JavaPlugin implements IEssentials
pm.registerEvent(Type.ENTITY_DEATH, entityListener, Priority.Lowest, this);
pm.registerEvent(Type.ENTITY_REGAIN_HEALTH, entityListener, Priority.Lowest, this);
pm.registerEvent(Type.FOOD_LEVEL_CHANGE, entityListener, Priority.Lowest, this);
final EssentialsWorldListener worldListener = new EssentialsWorldListener(this);
pm.registerEvent(Type.WORLD_LOAD, worldListener, Priority.Monitor, this);
pm.registerEvent(Type.WORLD_UNLOAD, worldListener, Priority.Monitor, this);
//TODO: Check if this should be here, and not above before reload()
jails = new Jails(this);
@ -594,4 +601,46 @@ public class Essentials extends JavaPlugin implements IEssentials
{
return i18n;
}
private static class EssentialsWorldListener extends WorldListener implements Runnable {
private transient final IEssentials ess;
public EssentialsWorldListener(IEssentials ess)
{
this.ess = ess;
}
@Override
public void onWorldLoad(WorldLoadEvent event)
{
ess.getJails().onReload();
ess.getWarps().reloadConfig();
for (IConf iConf : ((Essentials)ess).confList)
{
if (iConf instanceof IEssentialsModule) {
iConf.reloadConfig();
}
}
}
@Override
public void onWorldUnload(WorldUnloadEvent event)
{
ess.getJails().onReload();
ess.getWarps().reloadConfig();
for (IConf iConf : ((Essentials)ess).confList)
{
if (iConf instanceof IEssentialsModule) {
iConf.reloadConfig();
}
}
}
@Override
public void run()
{
ess.reload();
}
}
}

View File

@ -282,22 +282,22 @@ public class EssentialsPlayerListener extends PlayerListener
{
final User user = ess.getUser(event.getPlayer());
user.updateActivity(true);
usePowertools(event);
if (event.getAnimationType() == PlayerAnimationType.ARM_SWING
&& user.hasPowerTools() && user.arePowerToolsEnabled())
{
usePowertools(user);
}
}
private void usePowertools(final PlayerAnimationEvent event)
private void usePowertools(final User user)
{
if (event.getAnimationType() != PlayerAnimationType.ARM_SWING)
{
return;
}
final User user = ess.getUser(event.getPlayer());
final ItemStack is = user.getItemInHand();
if (is == null || is.getType() == Material.AIR || !user.arePowerToolsEnabled())
int id;
if (is == null || (id = is.getTypeId()) == 0)
{
return;
}
final List<String> commandList = user.getPowertool(is);
final List<String> commandList = user.getPowertool(id);
if (commandList == null || commandList.isEmpty())
{
return;
@ -317,7 +317,7 @@ public class EssentialsPlayerListener extends PlayerListener
}
else
{
user.getServer().dispatchCommand(event.getPlayer(), command);
user.getServer().dispatchCommand(user.getBase(), command);
}
}
}

View File

@ -23,34 +23,37 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
private transient long lastOnlineActivity;
private transient long lastActivity = System.currentTimeMillis();
private boolean hidden = false;
private transient Location afkPosition;
private transient Location afkPosition = null;
private static final Logger logger = Logger.getLogger("Minecraft");
User(final Player base, final IEssentials ess)
{
super(base, ess);
teleport = new Teleport(this, ess);
afkPosition = getLocation();
if (isAfk())
{
afkPosition = getLocation();
}
}
User update(final Player base)
{
setBase(base);
return this;
}
@Override
public boolean isAuthorized(final IEssentialsCommand cmd)
{
return isAuthorized(cmd, "essentials.");
}
@Override
public boolean isAuthorized(final IEssentialsCommand cmd, final String permissionPrefix)
{
return isAuthorized(permissionPrefix + (cmd.getName().equals("r") ? "msg" : cmd.getName()));
}
@Override
public boolean isAuthorized(final String node)
{
@ -58,20 +61,20 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
{
return false;
}
if (isOp())
{
return true;
}
if (isJailed())
{
return false;
}
return ess.getPermissionsHandler().hasPermission(base, node);
}
public void healCooldown() throws Exception
{
final Calendar now = new GregorianCalendar();
@ -89,13 +92,13 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
}
setLastHealTimestamp(now.getTimeInMillis());
}
@Override
public void giveMoney(final double value)
{
giveMoney(value, null);
}
public void giveMoney(final double value, final CommandSender initiator)
{
if (value == 0)
@ -109,7 +112,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
initiator.sendMessage(_("addedToOthersAccount", Util.formatCurrency(value, ess), this.getDisplayName()));
}
}
public void payUser(final User reciever, final double value) throws Exception
{
if (value == 0)
@ -128,13 +131,13 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
throw new Exception(_("notEnoughMoney"));
}
}
@Override
public void takeMoney(final double value)
{
takeMoney(value, null);
}
public void takeMoney(final double value, final CommandSender initiator)
{
if (value == 0)
@ -148,36 +151,36 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
initiator.sendMessage(_("takenFromOthersAccount", Util.formatCurrency(value, ess), this.getDisplayName()));
}
}
public boolean canAfford(final double cost)
{
final double mon = getMoney();
return mon >= cost || isAuthorized("essentials.eco.loan");
}
public void dispose()
{
this.base = new OfflinePlayer(getName(), ess);
}
@Override
public void setReplyTo(final CommandSender user)
{
replyTo = user;
}
@Override
public CommandSender getReplyTo()
{
return replyTo;
}
@Override
public int compareTo(final User other)
{
return Util.stripColor(this.getDisplayName()).compareToIgnoreCase(Util.stripColor(other.getDisplayName()));
}
@Override
public boolean equals(final Object object)
{
@ -186,58 +189,58 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
return false;
}
return this.getName().equalsIgnoreCase(((User)object).getName());
}
@Override
public int hashCode()
{
return this.getName().hashCode();
}
public Boolean canSpawnItem(final int itemId)
{
return !ess.getSettings().itemSpawnBlacklist().contains(itemId);
}
public Location getHome() throws Exception
{
return getHome(getHomes().get(0));
}
public void setHome()
{
setHome("home", getLocation());
}
public void setHome(final String name)
{
setHome(name, getLocation());
}
@Override
public void setLastLocation()
{
setLastLocation(getLocation());
}
public void requestTeleport(final User player, final boolean here)
{
teleportRequestTime = System.currentTimeMillis();
teleportRequester = player;
teleportRequestHere = here;
}
public User getTeleportRequest()
{
return teleportRequester;
}
public boolean isTeleportRequestHere()
{
return teleportRequestHere;
}
public String getNick(boolean addprefixsuffix)
{
final StringBuilder nickname = new StringBuilder();
@ -261,7 +264,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
{
}
}
if (addprefixsuffix && ess.getSettings().addPrefixSuffix())
{
if (!ess.getSettings().disablePrefix())
@ -283,10 +286,10 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
nickname.append("§f");
}
}
return nickname.toString();
}
public void setDisplayNick()
{
String name = getNick(true);
@ -308,7 +311,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
logger.log(Level.INFO, "Playerlist for " + name + " was not updated. Use a shorter displayname prefix.");
}
}
@Override
public String getDisplayName()
{
@ -318,22 +321,22 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
}
return super.getDisplayName() == null ? super.getName() : super.getDisplayName();
}
public Teleport getTeleport()
{
return teleport;
}
public long getLastOnlineActivity()
{
return lastOnlineActivity;
}
public void setLastOnlineActivity(final long timestamp)
{
lastOnlineActivity = timestamp;
}
@Override
public double getMoney()
{
@ -355,7 +358,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
}
return super.getMoney();
}
@Override
public void setMoney(final double value)
{
@ -377,7 +380,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
}
super.setMoney(value);
}
@Override
public void setAfk(final boolean set)
{
@ -386,9 +389,13 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
{
afkPosition = getLocation();
}
else if (!set && isAfk())
{
afkPosition = null;
}
super.setAfk(set);
}
@Override
public boolean toggleAfk()
{
@ -396,13 +403,13 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
this.setSleepingIgnored(this.isAuthorized("essentials.sleepingignored") ? true : now);
return now;
}
@Override
public boolean isHidden()
{
return hidden;
}
public void setHidden(final boolean hidden)
{
this.hidden = hidden;
@ -453,7 +460,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
}
return false;
}
public void updateActivity(final boolean broadcast)
{
if (isAfk())
@ -466,7 +473,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
}
lastActivity = System.currentTimeMillis();
}
public void checkActivity()
{
final long autoafkkick = ess.getSettings().getAutoAfkKick();
@ -476,8 +483,8 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
final String kickReason = _("autoAfkKickReason", autoafkkick / 60.0);
lastActivity = 0;
kickPlayer(kickReason);
for (Player player : ess.getServer().getOnlinePlayers())
{
final User user = ess.getUser(player);
@ -497,12 +504,12 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
}
}
}
public Location getAfkPosition()
{
return afkPosition;
}
@Override
public boolean toggleGodModeEnabled()
{
@ -512,36 +519,36 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
}
return super.toggleGodModeEnabled();
}
@Override
public boolean isGodModeEnabled()
{
return (super.isGodModeEnabled() && !ess.getSettings().getNoGodWorlds().contains(getLocation().getWorld().getName()))
|| (isAfk() && ess.getSettings().getFreezeAfkPlayers());
}
public boolean isGodModeEnabledRaw()
{
return super.isGodModeEnabled();
}
public String getGroup()
{
return ess.getPermissionsHandler().getGroup(base);
}
public boolean inGroup(final String group)
{
return ess.getPermissionsHandler().inGroup(base, group);
}
public boolean canBuild()
{
return ess.getPermissionsHandler().canBuild(base, getGroup());
}
public long getTeleportRequestTime()
{
return teleportRequestTime;
}
}
}

View File

@ -264,6 +264,11 @@ public abstract class UserData extends PlayerExtension implements IConf
{
return (List<String>)powertools.get(stack.getTypeId());
}
public List<String> getPowertool(int id)
{
return (List<String>)powertools.get(id);
}
public void setPowertool(ItemStack stack, List<String> commandList)
{

View File

@ -6,7 +6,6 @@ import com.google.common.cache.CacheLoader;
import com.google.common.util.concurrent.UncheckedExecutionException;
import java.io.File;
import java.util.Collections;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.ExecutionException;

View File

@ -21,10 +21,11 @@ public class Util
{
}
private final static Logger logger = Logger.getLogger("Minecraft");
private final static Pattern INVALIDCHARS = Pattern.compile("[^a-z0-9]");
public static String sanitizeFileName(String name)
public static String sanitizeFileName(final String name)
{
return name.toLowerCase(Locale.ENGLISH).replaceAll("[^a-z0-9]", "_");
return INVALIDCHARS.matcher(name.toLowerCase(Locale.ENGLISH)).replaceAll("_");
}
public static String formatDateDiff(long date)

View File

@ -41,7 +41,7 @@ public class Commandhelp extends EssentialsCommand
output = new KeywordReplacer(input, user, ess);
}
final TextPager pager = new TextPager(output);
pager.showPage(pageStr, chapterPageStr, "help", user);
pager.showPage(pageStr, chapterPageStr, commandLabel, user);
}
@Override

View File

@ -50,7 +50,7 @@ public class Commandhome extends EssentialsCommand
if (bed != null)
{
user.getTeleport().teleport(bed, charge, TeleportCause.COMMAND);
return;
throw new NoChargeException();
}
}
user.getTeleport().home(player, homeName.toLowerCase(Locale.ENGLISH), charge);
@ -64,10 +64,10 @@ public class Commandhome extends EssentialsCommand
if (bed != null)
{
user.getTeleport().teleport(bed, charge, TeleportCause.COMMAND);
return;
throw new NoChargeException();
}
user.getTeleport().respawn(charge, TeleportCause.COMMAND);
return;
}
else if (homes.isEmpty())
{
@ -76,7 +76,6 @@ public class Commandhome extends EssentialsCommand
else if (homes.size() == 1 && player.equals(user))
{
user.getTeleport().home(player, homes.get(0), charge);
return;
}
else
{

View File

@ -21,6 +21,6 @@ public class Commandinfo extends EssentialsCommand
final IText input = new TextInput(sender, "info", true, ess);
final IText output = new KeywordReplacer(input, sender, ess);
final TextPager pager = new TextPager(output);
pager.showPage(args.length > 0 ? args[0] : null, args.length > 1 ? args[1] : null, "info", sender);
pager.showPage(args.length > 0 ? args[0] : null, args.length > 1 ? args[1] : null, commandLabel, sender);
}
}

View File

@ -21,6 +21,6 @@ public class Commandmotd extends EssentialsCommand
final IText input = new TextInput(sender, "motd", true, ess);
final IText output = new KeywordReplacer(input, sender, ess);
final TextPager pager = new TextPager(output);
pager.showPage(args.length > 0 ? args[0] : null, args.length > 1 ? args[1] : null, "motd", sender);
pager.showPage(args.length > 0 ? args[0] : null, args.length > 1 ? args[1] : null, commandLabel, sender);
}
}

View File

@ -4,6 +4,7 @@ import com.earth2me.essentials.DescParseTickFormat;
import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.User;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -16,15 +17,17 @@ import org.bukkit.plugin.Plugin;
public class KeywordReplacer implements IText
{
private final transient IText input;
private final transient List<String> replaced;
private final transient IEssentials ess;
public KeywordReplacer(final IText input, final CommandSender sender, final IEssentials ess)
{
this.input = input;
this.replaced = new ArrayList<String>(this.input.getLines().size());
this.ess = ess;
replaceKeywords(sender);
}
private void replaceKeywords(final CommandSender sender)
{
String displayName, ipAddress, balance, mails, world;
@ -41,7 +44,7 @@ public class KeywordReplacer implements IText
world = user.getLocation().getWorld().getName();
worldTime12 = DescParseTickFormat.format12(user.getWorld().getTime());
worldTime24 = DescParseTickFormat.format24(user.getWorld().getTime());
worldDate = DateFormat.getDateInstance(DateFormat.MEDIUM, ess.getI18n().getCurrentLocale()).format(DescParseTickFormat.ticksToDate(user.getWorld().getTime()));
worldDate = DateFormat.getDateInstance(DateFormat.MEDIUM, ess.getI18n().getCurrentLocale()).format(DescParseTickFormat.ticksToDate(user.getWorld().getFullTime()));
}
else
{
@ -98,7 +101,7 @@ public class KeywordReplacer implements IText
date = DateFormat.getDateInstance(DateFormat.MEDIUM, ess.getI18n().getCurrentLocale()).format(new Date());
time = DateFormat.getTimeInstance(DateFormat.MEDIUM, ess.getI18n().getCurrentLocale()).format(new Date());
version = ess.getServer().getVersion();
for (int i = 0; i < input.getLines().size(); i++)
@ -120,14 +123,14 @@ public class KeywordReplacer implements IText
line = line.replace("{WORLDDATE}", worldDate);
line = line.replace("{PLUGINS}", plugins);
line = line.replace("{VERSION}", version);
input.getLines().set(i, line);
replaced.add(line);
}
}
@Override
public List<String> getLines()
{
return input.getLines();
return replaced;
}
@Override

View File

@ -4,6 +4,7 @@ import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import java.io.*;
import java.lang.ref.SoftReference;
import java.util.*;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -11,9 +12,11 @@ import org.bukkit.entity.Player;
public class TextInput implements IText
{
private final transient List<String> lines = new ArrayList<String>();
private final transient List<String> chapters = new ArrayList<String>();
private final transient Map<String, Integer> bookmarks = new HashMap<String, Integer>();
private final transient List<String> lines;
private final transient List<String> chapters;
private final transient Map<String, Integer> bookmarks;
private final transient long lastChange;
private final static HashMap<String, SoftReference<TextInput>> cache = new HashMap<String, SoftReference<TextInput>>();
public TextInput(final CommandSender sender, final String filename, final boolean createFile, final IEssentials ess) throws IOException
{
@ -34,33 +37,62 @@ public class TextInput implements IText
}
if (file.exists())
{
final BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
try
lastChange = file.lastModified();
boolean readFromfile;
synchronized (cache)
{
int lineNumber = 0;
while (bufferedReader.ready())
final SoftReference<TextInput> inputRef = cache.get(file.getName());
TextInput input;
if (inputRef == null || (input = inputRef.get()) == null || input.lastChange < lastChange)
{
final String line = bufferedReader.readLine();
if (line == null)
{
break;
}
if (line.length() > 0 && line.charAt(0) == '#')
{
bookmarks.put(line.substring(1).toLowerCase(Locale.ENGLISH).replaceAll("&[0-9a-f]", ""), lineNumber);
chapters.add(line.substring(1).replace('&', '§').replace("§§", "&"));
}
lines.add(line.replace('&', '§').replace("§§", "&"));
lineNumber++;
lines = new ArrayList<String>();
chapters = new ArrayList<String>();
bookmarks = new HashMap<String, Integer>();
cache.put(file.getName(), new SoftReference<TextInput>(this));
readFromfile = true;
}
else
{
lines = Collections.unmodifiableList(input.getLines());
chapters = Collections.unmodifiableList(input.getChapters());
bookmarks = Collections.unmodifiableMap(input.getBookmarks());
readFromfile = false;
}
}
finally
if (readFromfile)
{
bufferedReader.close();
final BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
try
{
int lineNumber = 0;
while (bufferedReader.ready())
{
final String line = bufferedReader.readLine();
if (line == null)
{
break;
}
if (line.length() > 0 && line.charAt(0) == '#')
{
bookmarks.put(line.substring(1).toLowerCase(Locale.ENGLISH).replaceAll("&[0-9a-f]", ""), lineNumber);
chapters.add(line.substring(1).replace('&', '§').replace("§§", "&"));
}
lines.add(line.replace('&', '§').replace("§§", "&"));
lineNumber++;
}
}
finally
{
bufferedReader.close();
}
}
}
else
{
lastChange = 0;
lines = Collections.emptyList();
chapters = Collections.emptyList();
bookmarks = Collections.emptyMap();
if (createFile)
{
final InputStream input = ess.getResource(filename + ".txt");
@ -68,8 +100,7 @@ public class TextInput implements IText
try
{
final byte[] buffer = new byte[1024];
int length = 0;
length = input.read(buffer);
int length = input.read(buffer);
while (length > 0)
{
output.write(buffer, 0, length);

View File

@ -56,7 +56,7 @@ public class EssentialsProtectBlockListener extends BlockListener
final Block below = blockPlaced.getRelative(BlockFace.DOWN);
if ((below.getType() == Material.RAILS || below.getType() == Material.POWERED_RAIL || below.getType() == Material.DETECTOR_RAIL)
&& prot.getSettingBool(ProtectConfig.prevent_block_on_rail)
&& prot.getStorage().isProtected(below, user.getName()))
&& isProtected(below, user))
{
event.setCancelled(true);
return;
@ -69,7 +69,7 @@ public class EssentialsProtectBlockListener extends BlockListener
{
protect.add(blockPlaced);
if (prot.getSettingBool(ProtectConfig.protect_below_rails)
&& !prot.getStorage().isProtected(blockPlaced.getRelative(BlockFace.DOWN), user.getName()))
&& !isProtected(blockPlaced.getRelative(BlockFace.DOWN), user))
{
protect.add(blockPlaced.getRelative(BlockFace.DOWN));
}
@ -82,7 +82,7 @@ public class EssentialsProtectBlockListener extends BlockListener
if (prot.getSettingBool(ProtectConfig.protect_against_signs)
&& event.getBlockAgainst().getType() != Material.SIGN_POST
&& event.getBlockAgainst().getType() != Material.WALL_SIGN
&& !prot.getStorage().isProtected(event.getBlockAgainst(), user.getName()))
&& !isProtected(event.getBlockAgainst(), user))
{
protect.add(event.getBlockAgainst());
}
@ -283,7 +283,7 @@ public class EssentialsProtectBlockListener extends BlockListener
else
{
final boolean isProtected = storage.isProtected(block, user.getName());
final boolean isProtected = isProtected(block, user);
if (isProtected)
{
event.setCancelled(true);
@ -422,4 +422,58 @@ public class EssentialsProtectBlockListener extends BlockListener
}
}
}
private boolean isProtected(final Block block, final User user)
{
final Material type = block.getType();
if (prot.getSettingBool(ProtectConfig.protect_signs))
{
if (type == Material.WALL_SIGN || type == Material.SIGN_POST)
{
return prot.getStorage().isProtected(block, user.getName());
}
if (prot.getSettingBool(ProtectConfig.protect_against_signs))
{
final Block up = block.getRelative(BlockFace.UP);
if (up != null && up.getType() == Material.SIGN_POST)
{
return prot.getStorage().isProtected(block, user.getName());
}
final BlockFace[] directions = new BlockFace[]
{
BlockFace.NORTH,
BlockFace.EAST,
BlockFace.SOUTH,
BlockFace.WEST
};
for (BlockFace blockFace : directions)
{
final Block signblock = block.getRelative(blockFace);
if (signblock.getType() == Material.WALL_SIGN)
{
final org.bukkit.material.Sign signMat = (org.bukkit.material.Sign)signblock.getState().getData();
if (signMat != null && signMat.getFacing() == blockFace)
{
return prot.getStorage().isProtected(block, user.getName());
}
}
}
}
}
if (prot.getSettingBool(ProtectConfig.protect_rails)) {
if (type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL)
{
return prot.getStorage().isProtected(block, user.getName());
}
if (prot.getSettingBool(ProtectConfig.protect_below_rails))
{
final Block up = block.getRelative(BlockFace.UP);
if (up != null && (type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL))
{
return prot.getStorage().isProtected(block, user.getName());
}
}
}
return false;
}
}