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

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

This commit is contained in:
KHobbits
2012-01-16 12:43:09 +00:00
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.Event.Type;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener; 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.InvalidDescriptionException;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile; 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_DEATH, entityListener, Priority.Lowest, this);
pm.registerEvent(Type.ENTITY_REGAIN_HEALTH, entityListener, Priority.Lowest, this); pm.registerEvent(Type.ENTITY_REGAIN_HEALTH, entityListener, Priority.Lowest, this);
pm.registerEvent(Type.FOOD_LEVEL_CHANGE, 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() //TODO: Check if this should be here, and not above before reload()
jails = new Jails(this); jails = new Jails(this);
@@ -594,4 +601,46 @@ public class Essentials extends JavaPlugin implements IEssentials
{ {
return i18n; 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()); final User user = ess.getUser(event.getPlayer());
user.updateActivity(true); 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(); final ItemStack is = user.getItemInHand();
if (is == null || is.getType() == Material.AIR || !user.arePowerToolsEnabled()) int id;
if (is == null || (id = is.getTypeId()) == 0)
{ {
return; return;
} }
final List<String> commandList = user.getPowertool(is); final List<String> commandList = user.getPowertool(id);
if (commandList == null || commandList.isEmpty()) if (commandList == null || commandList.isEmpty())
{ {
return; return;
@@ -317,7 +317,7 @@ public class EssentialsPlayerListener extends PlayerListener
} }
else 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 lastOnlineActivity;
private transient long lastActivity = System.currentTimeMillis(); private transient long lastActivity = System.currentTimeMillis();
private boolean hidden = false; private boolean hidden = false;
private transient Location afkPosition; private transient Location afkPosition = null;
private static final Logger logger = Logger.getLogger("Minecraft"); private static final Logger logger = Logger.getLogger("Minecraft");
User(final Player base, final IEssentials ess) User(final Player base, final IEssentials ess)
{ {
super(base, ess); super(base, ess);
teleport = new Teleport(this, ess); teleport = new Teleport(this, ess);
afkPosition = getLocation(); if (isAfk())
{
afkPosition = getLocation();
}
} }
User update(final Player base) User update(final Player base)
{ {
setBase(base); setBase(base);
return this; return this;
} }
@Override @Override
public boolean isAuthorized(final IEssentialsCommand cmd) public boolean isAuthorized(final IEssentialsCommand cmd)
{ {
return isAuthorized(cmd, "essentials."); return isAuthorized(cmd, "essentials.");
} }
@Override @Override
public boolean isAuthorized(final IEssentialsCommand cmd, final String permissionPrefix) public boolean isAuthorized(final IEssentialsCommand cmd, final String permissionPrefix)
{ {
return isAuthorized(permissionPrefix + (cmd.getName().equals("r") ? "msg" : cmd.getName())); return isAuthorized(permissionPrefix + (cmd.getName().equals("r") ? "msg" : cmd.getName()));
} }
@Override @Override
public boolean isAuthorized(final String node) public boolean isAuthorized(final String node)
{ {
@@ -58,20 +61,20 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
{ {
return false; return false;
} }
if (isOp()) if (isOp())
{ {
return true; return true;
} }
if (isJailed()) if (isJailed())
{ {
return false; return false;
} }
return ess.getPermissionsHandler().hasPermission(base, node); return ess.getPermissionsHandler().hasPermission(base, node);
} }
public void healCooldown() throws Exception public void healCooldown() throws Exception
{ {
final Calendar now = new GregorianCalendar(); final Calendar now = new GregorianCalendar();
@@ -89,13 +92,13 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
} }
setLastHealTimestamp(now.getTimeInMillis()); setLastHealTimestamp(now.getTimeInMillis());
} }
@Override @Override
public void giveMoney(final double value) public void giveMoney(final double value)
{ {
giveMoney(value, null); giveMoney(value, null);
} }
public void giveMoney(final double value, final CommandSender initiator) public void giveMoney(final double value, final CommandSender initiator)
{ {
if (value == 0) 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())); initiator.sendMessage(_("addedToOthersAccount", Util.formatCurrency(value, ess), this.getDisplayName()));
} }
} }
public void payUser(final User reciever, final double value) throws Exception public void payUser(final User reciever, final double value) throws Exception
{ {
if (value == 0) if (value == 0)
@@ -128,13 +131,13 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
throw new Exception(_("notEnoughMoney")); throw new Exception(_("notEnoughMoney"));
} }
} }
@Override @Override
public void takeMoney(final double value) public void takeMoney(final double value)
{ {
takeMoney(value, null); takeMoney(value, null);
} }
public void takeMoney(final double value, final CommandSender initiator) public void takeMoney(final double value, final CommandSender initiator)
{ {
if (value == 0) 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())); initiator.sendMessage(_("takenFromOthersAccount", Util.formatCurrency(value, ess), this.getDisplayName()));
} }
} }
public boolean canAfford(final double cost) public boolean canAfford(final double cost)
{ {
final double mon = getMoney(); final double mon = getMoney();
return mon >= cost || isAuthorized("essentials.eco.loan"); return mon >= cost || isAuthorized("essentials.eco.loan");
} }
public void dispose() public void dispose()
{ {
this.base = new OfflinePlayer(getName(), ess); this.base = new OfflinePlayer(getName(), ess);
} }
@Override @Override
public void setReplyTo(final CommandSender user) public void setReplyTo(final CommandSender user)
{ {
replyTo = user; replyTo = user;
} }
@Override @Override
public CommandSender getReplyTo() public CommandSender getReplyTo()
{ {
return replyTo; return replyTo;
} }
@Override @Override
public int compareTo(final User other) public int compareTo(final User other)
{ {
return Util.stripColor(this.getDisplayName()).compareToIgnoreCase(Util.stripColor(other.getDisplayName())); return Util.stripColor(this.getDisplayName()).compareToIgnoreCase(Util.stripColor(other.getDisplayName()));
} }
@Override @Override
public boolean equals(final Object object) public boolean equals(final Object object)
{ {
@@ -186,58 +189,58 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
return false; return false;
} }
return this.getName().equalsIgnoreCase(((User)object).getName()); return this.getName().equalsIgnoreCase(((User)object).getName());
} }
@Override @Override
public int hashCode() public int hashCode()
{ {
return this.getName().hashCode(); return this.getName().hashCode();
} }
public Boolean canSpawnItem(final int itemId) public Boolean canSpawnItem(final int itemId)
{ {
return !ess.getSettings().itemSpawnBlacklist().contains(itemId); return !ess.getSettings().itemSpawnBlacklist().contains(itemId);
} }
public Location getHome() throws Exception public Location getHome() throws Exception
{ {
return getHome(getHomes().get(0)); return getHome(getHomes().get(0));
} }
public void setHome() public void setHome()
{ {
setHome("home", getLocation()); setHome("home", getLocation());
} }
public void setHome(final String name) public void setHome(final String name)
{ {
setHome(name, getLocation()); setHome(name, getLocation());
} }
@Override @Override
public void setLastLocation() public void setLastLocation()
{ {
setLastLocation(getLocation()); setLastLocation(getLocation());
} }
public void requestTeleport(final User player, final boolean here) public void requestTeleport(final User player, final boolean here)
{ {
teleportRequestTime = System.currentTimeMillis(); teleportRequestTime = System.currentTimeMillis();
teleportRequester = player; teleportRequester = player;
teleportRequestHere = here; teleportRequestHere = here;
} }
public User getTeleportRequest() public User getTeleportRequest()
{ {
return teleportRequester; return teleportRequester;
} }
public boolean isTeleportRequestHere() public boolean isTeleportRequestHere()
{ {
return teleportRequestHere; return teleportRequestHere;
} }
public String getNick(boolean addprefixsuffix) public String getNick(boolean addprefixsuffix)
{ {
final StringBuilder nickname = new StringBuilder(); 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 (addprefixsuffix && ess.getSettings().addPrefixSuffix())
{ {
if (!ess.getSettings().disablePrefix()) if (!ess.getSettings().disablePrefix())
@@ -283,10 +286,10 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
nickname.append("§f"); nickname.append("§f");
} }
} }
return nickname.toString(); return nickname.toString();
} }
public void setDisplayNick() public void setDisplayNick()
{ {
String name = getNick(true); 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."); logger.log(Level.INFO, "Playerlist for " + name + " was not updated. Use a shorter displayname prefix.");
} }
} }
@Override @Override
public String getDisplayName() 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(); return super.getDisplayName() == null ? super.getName() : super.getDisplayName();
} }
public Teleport getTeleport() public Teleport getTeleport()
{ {
return teleport; return teleport;
} }
public long getLastOnlineActivity() public long getLastOnlineActivity()
{ {
return lastOnlineActivity; return lastOnlineActivity;
} }
public void setLastOnlineActivity(final long timestamp) public void setLastOnlineActivity(final long timestamp)
{ {
lastOnlineActivity = timestamp; lastOnlineActivity = timestamp;
} }
@Override @Override
public double getMoney() public double getMoney()
{ {
@@ -355,7 +358,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
} }
return super.getMoney(); return super.getMoney();
} }
@Override @Override
public void setMoney(final double value) public void setMoney(final double value)
{ {
@@ -377,7 +380,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
} }
super.setMoney(value); super.setMoney(value);
} }
@Override @Override
public void setAfk(final boolean set) public void setAfk(final boolean set)
{ {
@@ -386,9 +389,13 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
{ {
afkPosition = getLocation(); afkPosition = getLocation();
} }
else if (!set && isAfk())
{
afkPosition = null;
}
super.setAfk(set); super.setAfk(set);
} }
@Override @Override
public boolean toggleAfk() 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); this.setSleepingIgnored(this.isAuthorized("essentials.sleepingignored") ? true : now);
return now; return now;
} }
@Override @Override
public boolean isHidden() public boolean isHidden()
{ {
return hidden; return hidden;
} }
public void setHidden(final boolean hidden) public void setHidden(final boolean hidden)
{ {
this.hidden = hidden; this.hidden = hidden;
@@ -453,7 +460,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
} }
return false; return false;
} }
public void updateActivity(final boolean broadcast) public void updateActivity(final boolean broadcast)
{ {
if (isAfk()) if (isAfk())
@@ -466,7 +473,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
} }
lastActivity = System.currentTimeMillis(); lastActivity = System.currentTimeMillis();
} }
public void checkActivity() public void checkActivity()
{ {
final long autoafkkick = ess.getSettings().getAutoAfkKick(); 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); final String kickReason = _("autoAfkKickReason", autoafkkick / 60.0);
lastActivity = 0; lastActivity = 0;
kickPlayer(kickReason); kickPlayer(kickReason);
for (Player player : ess.getServer().getOnlinePlayers()) for (Player player : ess.getServer().getOnlinePlayers())
{ {
final User user = ess.getUser(player); final User user = ess.getUser(player);
@@ -497,12 +504,12 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
} }
} }
} }
public Location getAfkPosition() public Location getAfkPosition()
{ {
return afkPosition; return afkPosition;
} }
@Override @Override
public boolean toggleGodModeEnabled() public boolean toggleGodModeEnabled()
{ {
@@ -512,36 +519,36 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
} }
return super.toggleGodModeEnabled(); return super.toggleGodModeEnabled();
} }
@Override @Override
public boolean isGodModeEnabled() public boolean isGodModeEnabled()
{ {
return (super.isGodModeEnabled() && !ess.getSettings().getNoGodWorlds().contains(getLocation().getWorld().getName())) return (super.isGodModeEnabled() && !ess.getSettings().getNoGodWorlds().contains(getLocation().getWorld().getName()))
|| (isAfk() && ess.getSettings().getFreezeAfkPlayers()); || (isAfk() && ess.getSettings().getFreezeAfkPlayers());
} }
public boolean isGodModeEnabledRaw() public boolean isGodModeEnabledRaw()
{ {
return super.isGodModeEnabled(); return super.isGodModeEnabled();
} }
public String getGroup() public String getGroup()
{ {
return ess.getPermissionsHandler().getGroup(base); return ess.getPermissionsHandler().getGroup(base);
} }
public boolean inGroup(final String group) public boolean inGroup(final String group)
{ {
return ess.getPermissionsHandler().inGroup(base, group); return ess.getPermissionsHandler().inGroup(base, group);
} }
public boolean canBuild() public boolean canBuild()
{ {
return ess.getPermissionsHandler().canBuild(base, getGroup()); return ess.getPermissionsHandler().canBuild(base, getGroup());
} }
public long getTeleportRequestTime() public long getTeleportRequestTime()
{ {
return teleportRequestTime; return teleportRequestTime;
} }
} }

View File

@@ -264,6 +264,11 @@ public abstract class UserData extends PlayerExtension implements IConf
{ {
return (List<String>)powertools.get(stack.getTypeId()); 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) 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 com.google.common.util.concurrent.UncheckedExecutionException;
import java.io.File; import java.io.File;
import java.util.Collections; import java.util.Collections;
import java.util.Locale;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentSkipListSet; import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.ExecutionException; 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 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) public static String formatDateDiff(long date)

View File

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

View File

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

View File

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

View File

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

View File

@@ -56,7 +56,7 @@ public class EssentialsProtectBlockListener extends BlockListener
final Block below = blockPlaced.getRelative(BlockFace.DOWN); final Block below = blockPlaced.getRelative(BlockFace.DOWN);
if ((below.getType() == Material.RAILS || below.getType() == Material.POWERED_RAIL || below.getType() == Material.DETECTOR_RAIL) if ((below.getType() == Material.RAILS || below.getType() == Material.POWERED_RAIL || below.getType() == Material.DETECTOR_RAIL)
&& prot.getSettingBool(ProtectConfig.prevent_block_on_rail) && prot.getSettingBool(ProtectConfig.prevent_block_on_rail)
&& prot.getStorage().isProtected(below, user.getName())) && isProtected(below, user))
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;
@@ -69,7 +69,7 @@ public class EssentialsProtectBlockListener extends BlockListener
{ {
protect.add(blockPlaced); protect.add(blockPlaced);
if (prot.getSettingBool(ProtectConfig.protect_below_rails) 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)); protect.add(blockPlaced.getRelative(BlockFace.DOWN));
} }
@@ -82,7 +82,7 @@ public class EssentialsProtectBlockListener extends BlockListener
if (prot.getSettingBool(ProtectConfig.protect_against_signs) if (prot.getSettingBool(ProtectConfig.protect_against_signs)
&& event.getBlockAgainst().getType() != Material.SIGN_POST && event.getBlockAgainst().getType() != Material.SIGN_POST
&& event.getBlockAgainst().getType() != Material.WALL_SIGN && event.getBlockAgainst().getType() != Material.WALL_SIGN
&& !prot.getStorage().isProtected(event.getBlockAgainst(), user.getName())) && !isProtected(event.getBlockAgainst(), user))
{ {
protect.add(event.getBlockAgainst()); protect.add(event.getBlockAgainst());
} }
@@ -283,7 +283,7 @@ public class EssentialsProtectBlockListener extends BlockListener
else else
{ {
final boolean isProtected = storage.isProtected(block, user.getName()); final boolean isProtected = isProtected(block, user);
if (isProtected) if (isProtected)
{ {
event.setCancelled(true); 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;
}
} }