1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-10-02 17:16:59 +02:00

Less locks please

This commit is contained in:
snowleo
2012-10-06 16:49:40 +02:00
parent 463c4ff62d
commit fabd88dc25
75 changed files with 805 additions and 1618 deletions

View File

@@ -47,7 +47,8 @@ public class EssentialsTimer implements Runnable
try
{
final IUser user = ess.getUserMap().getUser(player);
if (user == null) {
if (user == null)
{
continue;
}
onlineUsers.add(user);
@@ -56,15 +57,9 @@ public class EssentialsTimer implements Runnable
boolean mailDisabled = false;
ISettings settings = ess.getSettings();
settings.acquireReadLock();
try
{
mailDisabled = settings.getData().getCommands().isDisabled("mail");
}
finally
{
settings.unlock();
}
mailDisabled = settings.getData().getCommands().isDisabled("mail");
// New mail notification
if (!mailDisabled && Permissions.MAIL.isAuthorized(user) && !user.gotMailInfo())
{

View File

@@ -5,7 +5,6 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Pattern;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.IEssentials;
import net.ess3.api.IItemDb;
@@ -66,9 +65,7 @@ public class ItemDb implements IItemDb
{
final ItemStack stack = get(id.toLowerCase(Locale.ENGLISH));
@Cleanup
net.ess3.api.ISettings settings = ess.getSettings();
settings.acquireReadLock();
final int defaultStackSize = settings.getData().getGeneral().getDefaultStacksize();

View File

@@ -4,7 +4,6 @@ import java.io.File;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.IEssentials;
import net.ess3.api.IJails;
@@ -55,114 +54,68 @@ public class Jails extends AsyncStorageObjectHolder<net.ess3.settings.Jails> imp
@Override
public Location getJail(final String jailName) throws Exception
{
acquireReadLock();
try
if (getData().getJails() == null || jailName == null
|| !getData().getJails().containsKey(jailName.toLowerCase(Locale.ENGLISH)))
{
if (getData().getJails() == null || jailName == null
|| !getData().getJails().containsKey(jailName.toLowerCase(Locale.ENGLISH)))
{
throw new Exception(_("jailNotExist"));
}
Location loc = getData().getJails().get(jailName.toLowerCase(Locale.ENGLISH)).getStoredLocation();
if (loc == null || loc.getWorld() == null)
{
throw new Exception(_("jailNotExist"));
}
return loc;
throw new Exception(_("jailNotExist"));
}
finally
Location loc = getData().getJails().get(jailName.toLowerCase(Locale.ENGLISH)).getStoredLocation();
if (loc == null || loc.getWorld() == null)
{
unlock();
throw new Exception(_("jailNotExist"));
}
return loc;
}
@Override
public Collection<String> getList() throws Exception
{
acquireReadLock();
try
if (getData().getJails() == null)
{
if (getData().getJails() == null)
{
return Collections.emptyList();
}
return new ArrayList<String>(getData().getJails().keySet());
}
finally
{
unlock();
return Collections.emptyList();
}
return new ArrayList<String>(getData().getJails().keySet());
}
@Override
public void removeJail(final String jail) throws Exception
{
acquireWriteLock();
try
if (getData().getJails() == null)
{
if (getData().getJails() == null)
{
return;
}
getData().getJails().remove(jail.toLowerCase(Locale.ENGLISH));
}
finally
{
unlock();
return;
}
getData().removeJail(jail.toLowerCase(Locale.ENGLISH));
queueSave();
}
@Override
public void sendToJail(final IUser user, final String jail) throws Exception
{
acquireReadLock();
try
if (user.isOnline())
{
if (user.isOnline())
{
Location loc = getJail(jail);
user.getTeleport().now(loc, false, TeleportCause.COMMAND);
}
user.acquireWriteLock();
try
{
user.getData().setJail(jail);
}
finally
{
unlock();
}
}
finally
{
unlock();
Location loc = getJail(jail);
user.getTeleport().now(loc, false, TeleportCause.COMMAND);
}
user.getData().setJail(jail);
user.queueSave();
}
@Override
public void setJail(final String jailName, final Location loc) throws Exception
{
acquireWriteLock();
try
{
getData().addJail(jailName.toLowerCase(Locale.ENGLISH), loc);
}
finally
{
unlock();
}
getData().addJail(jailName.toLowerCase(Locale.ENGLISH), loc);
queueSave();
}
@Override
public void finishRead()
{
}
@Override
public void finishWrite()
{
}
@Override
@@ -177,9 +130,7 @@ public class Jails extends AsyncStorageObjectHolder<net.ess3.settings.Jails> imp
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockBreak(final BlockBreakEvent event)
{
@Cleanup
final IUser user = ess.getUserMap().getUser(event.getPlayer());
user.acquireReadLock();
if (user.getData().isJailed())
{
event.setCancelled(true);
@@ -189,9 +140,7 @@ public class Jails extends AsyncStorageObjectHolder<net.ess3.settings.Jails> imp
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockPlace(final BlockPlaceEvent event)
{
@Cleanup
final IUser user = ess.getUserMap().getUser(event.getPlayer());
user.acquireReadLock();
if (user.getData().isJailed())
{
event.setCancelled(true);
@@ -201,9 +150,7 @@ public class Jails extends AsyncStorageObjectHolder<net.ess3.settings.Jails> imp
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockDamage(final BlockDamageEvent event)
{
@Cleanup
final IUser user = ess.getUserMap().getUser(event.getPlayer());
user.acquireReadLock();
if (user.getData().isJailed())
{
event.setCancelled(true);
@@ -217,9 +164,7 @@ public class Jails extends AsyncStorageObjectHolder<net.ess3.settings.Jails> imp
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerInteract(final PlayerInteractEvent event)
{
@Cleanup
final IUser user = ess.getUserMap().getUser(event.getPlayer());
user.acquireReadLock();
if (user.getData().isJailed())
{
event.setCancelled(true);
@@ -229,9 +174,7 @@ public class Jails extends AsyncStorageObjectHolder<net.ess3.settings.Jails> imp
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerRespawn(final PlayerRespawnEvent event)
{
@Cleanup
final IUser user = ess.getUserMap().getUser(event.getPlayer());
user.acquireReadLock();
if (!user.getData().isJailed() || user.getData().getJail() == null || user.getData().getJail().isEmpty())
{
return;
@@ -257,9 +200,7 @@ public class Jails extends AsyncStorageObjectHolder<net.ess3.settings.Jails> imp
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerTeleport(final PlayerTeleportEvent event)
{
@Cleanup
final IUser user = ess.getUserMap().getUser(event.getPlayer());
user.acquireReadLock();
if (!user.getData().isJailed() || user.getData().getJail() == null || user.getData().getJail().isEmpty())
{
return;
@@ -286,9 +227,7 @@ public class Jails extends AsyncStorageObjectHolder<net.ess3.settings.Jails> imp
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerJoin(final PlayerJoinEvent event)
{
@Cleanup
final IUser user = ess.getUserMap().getUser(event.getPlayer());
user.acquireReadLock();
if (!user.getData().isJailed() || user.getData().getJail() == null || user.getData().getJail().isEmpty())
{
return;

View File

@@ -32,25 +32,17 @@ public class Kits extends AsyncStorageObjectHolder<net.ess3.settings.Kits> imple
@Override
public Kit getKit(String kitName) throws Exception
{
acquireReadLock();
try
if (getData().getKits() == null || kitName == null
|| !getData().getKits().containsKey(kitName.toLowerCase(Locale.ENGLISH)))
{
if (getData().getKits() == null || kitName == null
|| !getData().getKits().containsKey(kitName.toLowerCase(Locale.ENGLISH)))
{
throw new Exception(_("kitError2"));
}
final Kit kit = getData().getKits().get(kitName.toLowerCase(Locale.ENGLISH));
if (kit == null)
{
throw new Exception(_("kitError2"));
}
return kit;
throw new Exception(_("kitError2"));
}
finally
final Kit kit = getData().getKits().get(kitName.toLowerCase(Locale.ENGLISH));
if (kit == null)
{
unlock();
throw new Exception(_("kitError2"));
}
return kit;
}
@Override
@@ -70,19 +62,11 @@ public class Kits extends AsyncStorageObjectHolder<net.ess3.settings.Kits> imple
@Override
public Collection<String> getList() throws Exception
{
acquireReadLock();
try
if (getData().getKits() == null)
{
if (getData().getKits() == null)
{
return Collections.emptyList();
}
return new ArrayList<String>(getData().getKits().keySet());
}
finally
{
unlock();
return Collections.emptyList();
}
return new ArrayList<String>(getData().getKits().keySet());
}
@Override
@@ -94,13 +78,11 @@ public class Kits extends AsyncStorageObjectHolder<net.ess3.settings.Kits> imple
@Override
public void finishRead()
{
}
@Override
public void finishWrite()
{
}
@Override

View File

@@ -20,9 +20,9 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
public class Teleport implements Runnable, ITeleport
{
private static final double MOVE_CONSTANT = 0.3;
private static class Target
{
private final Location location;
@@ -269,29 +269,13 @@ public class Teleport implements Runnable, ITeleport
@Override
public void back(Trade chargeFor) throws Exception
{
user.acquireReadLock();
try
{
teleport(new Target(user.getData().getLastLocation().getStoredLocation()), chargeFor, TeleportCause.COMMAND);
}
finally
{
user.unlock();
}
teleport(new Target(user.getData().getLastLocation().getStoredLocation()), chargeFor, TeleportCause.COMMAND);
}
@Override
public void back() throws Exception
{
user.acquireReadLock();
try
{
now(new Target(user.getData().getLastLocation().getStoredLocation()), TeleportCause.COMMAND);
}
finally
{
user.unlock();
}
now(new Target(user.getData().getLastLocation().getStoredLocation()), TeleportCause.COMMAND);
}
@Override

View File

@@ -37,15 +37,7 @@ public class Warps extends StorageObjectMap<IWarp> implements IWarps
{
continue;
}
warp.acquireReadLock();
try
{
names.add(warp.getData().getName());
}
finally
{
warp.unlock();
}
names.add(warp.getData().getName());
}
Collections.sort(names, String.CASE_INSENSITIVE_ORDER);
return names;
@@ -59,15 +51,7 @@ public class Warps extends StorageObjectMap<IWarp> implements IWarps
{
throw new WarpNotFoundException(_("warpNotExist"));
}
warp.acquireReadLock();
try
{
return warp.getData().getLocation().getStoredLocation();
}
finally
{
warp.unlock();
}
return warp.getData().getLocation().getStoredLocation();
}
@Override
@@ -83,15 +67,8 @@ public class Warps extends StorageObjectMap<IWarp> implements IWarps
{
warp = new WarpHolder(name, ess);
}
warp.acquireWriteLock();
try
{
warp.getData().setLocation(loc);
}
finally
{
warp.unlock();
}
warp.getData().setLocation(loc);
warp.queueSave();
}
@Override

View File

@@ -128,7 +128,7 @@ public interface IUser extends OfflinePlayer, CommandSender, IStorageObjectHolde
/**
* Since the Player object should not be stored for a long time, this method should be called again with a null
* value or the close() method should be called.
* value.
*
* @param player
*/

View File

@@ -5,7 +5,6 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.IBackup;
import net.ess3.api.IEssentials;
@@ -37,9 +36,7 @@ public class Backup implements Runnable, IBackup
{
if (running.compareAndSet(false, true))
{
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
final long interval = settings.getData().getGeneral().getBackup().getInterval() * 1200; // minutes -> ticks
if (interval < 1200)
{
@@ -57,9 +54,7 @@ public class Backup implements Runnable, IBackup
{
return;
}
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
final String command = settings.getData().getGeneral().getBackup().getCommand();
if (command == null || command.isEmpty())
{

View File

@@ -1,6 +1,5 @@
package net.ess3.commands;
import lombok.Cleanup;
import net.ess3.Console;
import static net.ess3.I18n._;
import net.ess3.api.IUser;
@@ -19,7 +18,6 @@ public class Commandban extends EssentialsCommand
{
throw new NotEnoughArgumentsException();
}
@Cleanup
final IUser user = ess.getUserMap().matchUser(args[0], false, true);
if (!user.isOnline())
{
@@ -38,7 +36,6 @@ public class Commandban extends EssentialsCommand
}
}
user.acquireWriteLock();
final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME;
String banReason;
user.getData().setBan(new Ban());
@@ -55,6 +52,7 @@ public class Commandban extends EssentialsCommand
}
user.setBanned(true);
user.queueSave();
user.getPlayer().kickPlayer(banReason);
for (Player player : server.getOnlinePlayers())
{

View File

@@ -1,6 +1,5 @@
package net.ess3.commands;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.IUser;
import org.bukkit.command.CommandSender;
@@ -16,9 +15,7 @@ public class Commandbanip extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
@Cleanup
final IUser player = ess.getUserMap().getUser(args[0]);
player.acquireReadLock();
if (player == null)
{

View File

@@ -1,7 +1,6 @@
package net.ess3.commands;
import java.util.Locale;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.IUser;
import net.ess3.permissions.Permissions;
@@ -18,7 +17,6 @@ public class Commanddelhome extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
@Cleanup
IUser user = sender instanceof IUser ? (IUser)sender : null;
String name;
String[] expandedArg;
@@ -51,8 +49,8 @@ public class Commanddelhome extends EssentialsCommand
/*
* if (name.equalsIgnoreCase("bed")) { throw new Exception("You cannot remove the vanilla home point"); }
*/
user.acquireWriteLock();
user.getData().removeHome(name.toLowerCase(Locale.ENGLISH));
user.queueSave();
sender.sendMessage(_("deleteHome", name));
}
}

View File

@@ -1,7 +1,6 @@
package net.ess3.commands;
import java.util.Locale;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.ISettings;
import net.ess3.api.IUser;
@@ -49,9 +48,7 @@ public class Commandeco extends EssentialsCommand
break;
case RESET:
@Cleanup
ISettings settings = ess.getSettings();
settings.acquireReadLock();
player.setMoney(amount == 0 ? settings.getData().getEconomy().getStartingBalance() : amount);
break;
}
@@ -77,9 +74,7 @@ public class Commandeco extends EssentialsCommand
break;
case RESET:
@Cleanup
ISettings settings = ess.getSettings();
settings.acquireReadLock();
player.setMoney(amount == 0 ? settings.getData().getEconomy().getStartingBalance() : amount);
break;
}
@@ -103,8 +98,7 @@ public class Commandeco extends EssentialsCommand
break;
case RESET:
@Cleanup ISettings settings = ess.getSettings();
settings.acquireReadLock();
ISettings settings = ess.getSettings();
player.setMoney(amount == 0 ? settings.getData().getEconomy().getStartingBalance() : amount);
break;
}

View File

@@ -15,7 +15,6 @@ public class Commandignore extends EssentialsCommand
}
IUser player = ess.getUserMap().matchUser(args[0], false, false);
user.acquireWriteLock();
if (user.isIgnoringPlayer(player))
{
user.setIgnoredPlayer(player, false);
@@ -26,5 +25,6 @@ public class Commandignore extends EssentialsCommand
user.setIgnoredPlayer(player, true);
user.sendMessage(_("ignorePlayer", player.getName()));
}
user.queueSave();
}
}

View File

@@ -23,17 +23,18 @@ public class Commandinvsee extends EssentialsCommand
{
invUser = ess.getUserMap().matchUser(args[0], false, false);
}
user.acquireWriteLock();
if (invUser == user && user.getData().getInventory() != null)
{
invUser.getPlayer().getInventory().setContents(user.getData().getInventory().getBukkitInventory());
user.getData().setInventory(null);
user.queueSave();
user.sendMessage(_("invRestored"));
throw new NoChargeException();
}
if (user.getData().getInventory() == null)
{
user.getData().setInventory(new Inventory(user.getPlayer().getInventory().getContents()));
user.queueSave();
}
ItemStack[] invUserStack = invUser.getPlayer().getInventory().getContents();
final int userStackLength = user.getPlayer().getInventory().getContents().length;

View File

@@ -1,6 +1,5 @@
package net.ess3.commands;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.ISettings;
import net.ess3.api.IUser;
@@ -51,9 +50,7 @@ public class Commandlightning extends EssentialsCommand
{
matchPlayer.getPlayer().damage(power, strike);
}
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
if (settings.getData().getCommands().getLightning().isWarnPlayer())
{
matchPlayer.sendMessage(_("lightningSmited"));

View File

@@ -6,10 +6,10 @@ import net.ess3.api.ISettings;
import net.ess3.api.IUser;
import net.ess3.permissions.Permissions;
import net.ess3.utils.FormatUtil;
import net.ess3.utils.Util;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Commandlist extends EssentialsCommand
{
@Override
@@ -40,17 +40,9 @@ public class Commandlist extends EssentialsCommand
}
sender.sendMessage(online);
boolean sortListByGroups = false;
ISettings settings = ess.getSettings();
settings.acquireReadLock();
try
{
sortListByGroups = settings.getData().getCommands().getList().isSortByGroups();
}
finally
{
settings.unlock();
}
boolean sortListByGroups = sortListByGroups = settings.getData().getCommands().getList().isSortByGroups();
if (sortListByGroups)
{
@@ -76,7 +68,7 @@ public class Commandlist extends EssentialsCommand
for (String group : groups)
{
final StringBuilder groupString = new StringBuilder();
groupString.append(_("listGroupTag",FormatUtil.replaceFormat(group)));
groupString.append(_("listGroupTag", FormatUtil.replaceFormat(group)));
final List<IUser> users = sort.get(group);
Collections.sort(users);
boolean first = true;
@@ -90,18 +82,12 @@ public class Commandlist extends EssentialsCommand
{
first = false;
}
user.acquireReadLock();
try
if (user.getData().isAfk())
{
if (user.getData().isAfk())
{
groupString.append(_("listAfkTag"));
}
}
finally
{
user.unlock();
groupString.append(_("listAfkTag"));
}
if (user.isHidden())
{
groupString.append(_("listHiddenTag"));
@@ -140,18 +126,12 @@ public class Commandlist extends EssentialsCommand
{
first = false;
}
user.acquireReadLock();
try
if (user.getData().isAfk())
{
if (user.getData().isAfk())
{
onlineUsers.append(_("listAfkTag"));
}
}
finally
{
user.unlock();
onlineUsers.append(_("listAfkTag"));
}
if (user.isHidden())
{
onlineUsers.append(_("listHiddenTag"));

View File

@@ -62,8 +62,8 @@ public class Commandmail extends EssentialsCommand
}
if (args.length >= 1 && "clear".equalsIgnoreCase(args[0]))
{
user.acquireWriteLock();
user.getData().clearMails();
user.queueSave();
user.sendMessage(_("mailCleared"));
return;
}

View File

@@ -18,19 +18,11 @@ public class Commandmore extends EssentialsCommand
{
throw new Exception(_("cantSpawnItem", "Air"));
}
int defaultStackSize = 0;
int oversizedStackSize = 0;
ISettings settings = ess.getSettings();
settings.acquireReadLock();
try
{
defaultStackSize = settings.getData().getGeneral().getDefaultStacksize();
oversizedStackSize = settings.getData().getGeneral().getOversizedStacksize();
}
finally
{
settings.unlock();
}
int defaultStackSize = settings.getData().getGeneral().getDefaultStacksize();
int oversizedStackSize = settings.getData().getGeneral().getOversizedStacksize();
if (stack.getAmount() >= (Permissions.OVERSIZEDSTACKS.isAuthorized(user)
? oversizedStackSize
: defaultStackSize > 0 ? defaultStackSize : stack.getMaxStackSize()))

View File

@@ -1,15 +1,12 @@
package net.ess3.commands;
import java.util.List;
import java.util.Set;
import lombok.Cleanup;
import net.ess3.Console;
import static net.ess3.I18n._;
import net.ess3.api.IReplyTo;
import net.ess3.api.IUser;
import net.ess3.permissions.Permissions;
import net.ess3.utils.FormatUtil;
import net.ess3.utils.Util;
import org.bukkit.command.CommandSender;
@@ -27,9 +24,7 @@ public class Commandmsg extends EssentialsCommand
String message = getFinalArg(args, 1);
if (isUser(sender))
{
@Cleanup
IUser user = getUser(sender);
user.acquireReadLock();
IUser user = getUser(sender);;
if (user.getData().isMuted())
{
throw new Exception(_("voiceSilenced"));

View File

@@ -1,6 +1,5 @@
package net.ess3.commands;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.IUser;
import net.ess3.permissions.Permissions;
@@ -8,6 +7,7 @@ import net.ess3.user.UserData.TimestampType;
import net.ess3.utils.DateUtil;
import org.bukkit.command.CommandSender;
public class Commandmute extends EssentialsCommand
{
@Override
@@ -18,9 +18,7 @@ public class Commandmute extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
@Cleanup
final IUser player = ess.getUserMap().matchUser(args[0], false, true);
player.acquireReadLock();
if (!player.getData().isMuted() && Permissions.MUTE_EXEMPT.isAuthorized(player))
{
throw new Exception(_("muteExempt"));

View File

@@ -1,13 +1,11 @@
package net.ess3.commands;
import java.util.Locale;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.ISettings;
import net.ess3.api.IUser;
import net.ess3.permissions.Permissions;
import net.ess3.utils.FormatUtil;
import net.ess3.utils.Util;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -22,9 +20,7 @@ public class Commandnick extends EssentialsCommand
{
throw new NotEnoughArgumentsException();
}
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
if (!settings.getData().getChat().getChangeDisplayname())
{
throw new Exception(_("nickDisplayName"));
@@ -49,9 +45,7 @@ public class Commandnick extends EssentialsCommand
{
throw new NotEnoughArgumentsException();
}
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
if (!settings.getData().getChat().getChangeDisplayname())
{
throw new Exception(_("nickDisplayName"));

View File

@@ -21,8 +21,8 @@ public class Commandpowertool extends EssentialsCommand
// check to see if this is a clear all command
if (command != null && command.equalsIgnoreCase("d:"))
{
user.acquireWriteLock();
user.getData().clearAllPowertools();
user.queueSave();
user.sendMessage(_("powerToolClearAll"));
return;
}
@@ -34,7 +34,6 @@ public class Commandpowertool extends EssentialsCommand
}
final String itemName = itemStack.getType().toString().toLowerCase(Locale.ENGLISH).replaceAll("_", " ");
user.acquireReadLock();
List<String> powertools = user.getData().getPowertool(itemStack.getType());
if (command != null && !command.isEmpty())
{
@@ -58,6 +57,7 @@ public class Commandpowertool extends EssentialsCommand
throw new Exception(_("powerToolNoSuchCommandAssigned", command, itemName));
}
powertools = new ArrayList<String>(powertools);
powertools.remove(command);
user.sendMessage(_("powerToolRemove", command, itemName));
}
@@ -74,11 +74,7 @@ public class Commandpowertool extends EssentialsCommand
{
throw new Exception(_("powerToolAlreadySet", command, itemName));
}
}
else if (powertools != null && !powertools.isEmpty())
{
// Replace all commands with this one
powertools.clear();
powertools = new ArrayList<String>(powertools);
}
else
{
@@ -91,10 +87,7 @@ public class Commandpowertool extends EssentialsCommand
}
else
{
if (powertools != null)
{
powertools.clear();
}
powertools = new ArrayList<String>();
user.sendMessage(_("powerToolRemoveAll", itemName));
}
@@ -103,7 +96,7 @@ public class Commandpowertool extends EssentialsCommand
user.getData().setPowerToolsEnabled(true);
user.sendMessage(_("powerToolsEnabled"));
}
user.acquireWriteLock();
user.getData().setPowertool(itemStack.getType(), powertools);
user.queueSave();
}
}

View File

@@ -14,8 +14,8 @@ public class Commandpowertooltoggle extends EssentialsCommand
user.sendMessage(_("noPowerTools"));
return;
}
user.acquireWriteLock();
user.getData().setPowerToolsEnabled(!user.getData().isPowerToolsEnabled());
user.queueSave();
user.sendMessage(user.getData().isPowerToolsEnabled()
? _("powerToolsEnabled")
: _("powerToolsDisabled"));

View File

@@ -1,12 +1,10 @@
package net.ess3.commands;
import java.util.Locale;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.ISettings;
import net.ess3.api.IUser;
import net.ess3.utils.FormatUtil;
import net.ess3.utils.Util;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -20,7 +18,6 @@ public class Commandrealname extends EssentialsCommand
{
throw new NotEnoughArgumentsException();
}
@Cleanup
final ISettings settings = ess.getSettings();
final String whois = args[0].toLowerCase(Locale.ENGLISH);
for (Player onlinePlayer : server.getOnlinePlayers())
@@ -32,7 +29,6 @@ public class Commandrealname extends EssentialsCommand
}
u.setDisplayNick();
final String displayName = FormatUtil.stripFormat(u.getPlayer().getDisplayName()).toLowerCase(Locale.ENGLISH);
settings.acquireReadLock();
if (!whois.equals(displayName)
&& !displayName.equals(FormatUtil.stripFormat(settings.getData().getChat().getNicknamePrefix()) + whois)
&& !whois.equalsIgnoreCase(u.getName()))

View File

@@ -1,6 +1,5 @@
package net.ess3.commands;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.IUser;
import net.ess3.permissions.Permissions;
@@ -36,13 +35,11 @@ public class Commandseen extends EssentialsCommand
}
catch (PlayerNotFoundException e)
{
@Cleanup
IUser u = ess.getUserMap().getUser(args[0]);
if (u == null)
{
throw new Exception(_("playerNotFound"));
}
u.acquireReadLock();
sender.sendMessage(_("seenOffline", u.getPlayer().getDisplayName(), DateUtil.formatDateDiff(u.getTimestamp(TimestampType.LOGOUT))));
if (u.isBanned())
{

View File

@@ -1,8 +1,6 @@
package net.ess3.commands;
import java.util.HashMap;
import java.util.Locale;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.IUser;
import net.ess3.permissions.Permissions;
@@ -33,8 +31,8 @@ public class Commandsethome extends EssentialsCommand
if ((user.getHomes().size() < ess.getRanks().getHomeLimit(user))
|| (user.getHomes().contains(args[0].toLowerCase(Locale.ENGLISH))))
{
user.acquireWriteLock();
user.getData().addHome(args[0].toLowerCase(Locale.ENGLISH), user.getPlayer().getLocation());
user.queueSave();
}
else
{
@@ -51,7 +49,6 @@ public class Commandsethome extends EssentialsCommand
{
if (Permissions.SETHOME_OTHERS.isAuthorized(user))
{
@Cleanup
IUser usersHome = ess.getUserMap().getUser(ess.getServer().getPlayer(args[0]));
if (usersHome == null)
{
@@ -67,15 +64,15 @@ public class Commandsethome extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
usersHome.acquireWriteLock();
usersHome.getData().addHome(name, user.getPlayer().getLocation());
usersHome.queueSave();
}
}
}
else
{
user.acquireWriteLock();
user.getData().addHome("home", user.getPlayer().getLocation());
user.queueSave();
}
user.sendMessage(_("homeSet", user.getPlayer().getLocation().getWorld().getName(), user.getPlayer().getLocation().getBlockX(), user.getPlayer().getLocation().getBlockY(), user.getPlayer().getLocation().getBlockZ()));

View File

@@ -136,17 +136,11 @@ public class Commandspawnmob extends EssentialsCommand
if (args.length >= 2)
{
int mobCount = Integer.parseInt(args[1]);
int serverLimit = 1;
ISettings settings = ess.getSettings();
settings.acquireReadLock();
try
{
serverLimit = settings.getData().getCommands().getSpawnmob().getLimit();
}
finally
{
settings.unlock();
}
int serverLimit = settings.getData().getCommands().getSpawnmob().getLimit();
if (mobCount > serverLimit)
{
mobCount = serverLimit;

View File

@@ -40,11 +40,11 @@ public class Commandtempban extends EssentialsCommand
final long banTimestamp = DateUtil.parseDateDiff(time, true);
final String banReason = _("tempBanned", DateUtil.formatDateDiff(banTimestamp));
user.acquireWriteLock();
user.getData().setBan(new Ban());
user.getData().getBan().setReason(banReason);
user.getData().getBan().setTimeout(banTimestamp);
user.setBanned(true);
user.queueSave();
user.getPlayer().kickPlayer(banReason);
final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME;

View File

@@ -1,6 +1,5 @@
package net.ess3.commands;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.IUser;
import net.ess3.permissions.Permissions;
@@ -19,9 +18,7 @@ public class Commandtogglejail extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
@Cleanup
final IUser player = ess.getUserMap().matchUser(args[0], false, true);
player.acquireReadLock();
if (args.length >= 2 && !player.getData().isJailed())
{
@@ -50,7 +47,6 @@ public class Commandtogglejail extends EssentialsCommand
// Check if jail exists
ess.getJails().getJail(args[1]);
}
player.acquireWriteLock();
player.getData().setJailed(true);
player.sendMessage(_("userJailed"));
player.getData().setJail(args[1]);
@@ -61,6 +57,7 @@ public class Commandtogglejail extends EssentialsCommand
timeDiff = DateUtil.parseDateDiff(time, true);
player.setTimestamp(TimestampType.JAIL, timeDiff);
}
player.queueSave();
sender.sendMessage((timeDiff > 0
? _("playerJailedFor", player.getName(), DateUtil.formatDateDiff(timeDiff))
: _("playerJailed", player.getName())));
@@ -77,8 +74,8 @@ public class Commandtogglejail extends EssentialsCommand
{
final String time = getFinalArg(args, 2);
final long timeDiff = DateUtil.parseDateDiff(time, true);
player.acquireWriteLock();
player.setTimestamp(TimestampType.JAIL, timeDiff);
player.queueSave();
sender.sendMessage(_("jailSentenceExtended", DateUtil.formatDateDiff(timeDiff)));
return;
}
@@ -89,7 +86,6 @@ public class Commandtogglejail extends EssentialsCommand
{
throw new NotEnoughArgumentsException();
}
player.acquireWriteLock();
player.getData().setJailed(false);
player.setTimestamp(TimestampType.JAIL, 0);
player.sendMessage(_("jailReleasedPlayerNotify"));
@@ -98,6 +94,7 @@ public class Commandtogglejail extends EssentialsCommand
{
player.getTeleport().back();
}
player.queueSave();
sender.sendMessage(_("jailReleased", player.getName()));
}
}

View File

@@ -1,6 +1,5 @@
package net.ess3.commands;
import lombok.Cleanup;
import net.ess3.Console;
import static net.ess3.I18n._;
import net.ess3.api.ISettings;
@@ -16,18 +15,14 @@ public class Commandtp extends EssentialsCommand
@Override
public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
{
@Cleanup
ISettings settings = ess.getSettings();
settings.acquireReadLock();
switch (args.length)
{
case 0:
throw new NotEnoughArgumentsException();
case 1:
@Cleanup
final IUser player = ess.getUserMap().matchUser(args[0], false, false);
player.acquireReadLock();
if (!player.getData().isTeleportEnabled())
{
throw new Exception(_("teleportDisabled", player.getPlayer().getDisplayName()));
@@ -49,12 +44,10 @@ public class Commandtp extends EssentialsCommand
throw new Exception(_("needTpohere"));
}
user.sendMessage(_("teleporting"));
@Cleanup
final IUser target = ess.getUserMap().matchUser(args[0], false, false);
@Cleanup
final IUser toPlayer = ess.getUserMap().matchUser(args[1], false, false);
target.acquireReadLock();
toPlayer.acquireReadLock();
if (!target.getData().isTeleportEnabled())
{

View File

@@ -1,6 +1,5 @@
package net.ess3.commands;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.ISettings;
import net.ess3.api.IUser;
@@ -17,16 +16,14 @@ public class Commandtpa extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
@Cleanup
IUser player = ess.getUserMap().matchUser(args[0], false, false);
player.acquireReadLock();
if (!player.getData().isTeleportEnabled())
{
throw new Exception(_("teleportDisabled", player.getPlayer().getDisplayName()));
}
@Cleanup
ISettings settings = ess.getSettings();
settings.acquireReadLock();
if (user.getPlayer().getWorld() != player.getPlayer().getWorld() && ess.getSettings().getData().getGeneral().isWorldTeleportPermissions()
&& !Permissions.WORLD.isAuthorized(user, user.getPlayer().getWorld().getName()))
{

View File

@@ -1,6 +1,5 @@
package net.ess3.commands;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.ISettings;
import net.ess3.api.IUser;
@@ -33,9 +32,8 @@ public class Commandtpaall extends EssentialsCommand
sender.sendMessage(_("teleportAAll"));
for (Player onlinePlayer : server.getOnlinePlayers())
{
@Cleanup
final IUser player = ess.getUserMap().getUser(onlinePlayer);
player.acquireReadLock();
if (user == player)
{
continue;
@@ -44,9 +42,8 @@ public class Commandtpaall extends EssentialsCommand
{
continue;
}
@Cleanup
ISettings settings = ess.getSettings();
settings.acquireReadLock();
if (user.getPlayer().getWorld() != player.getPlayer().getWorld() && settings.getData().getGeneral().isWorldTeleportPermissions()
&& !Permissions.WORLD.isAuthorized(user, user.getPlayer().getWorld().getName()))
{

View File

@@ -32,17 +32,9 @@ public class Commandtpaccept extends EssentialsCommand
throw new Exception(_("noPendingRequest"));
}
int tpaAcceptCancellation = 0;
ISettings settings = ess.getSettings();
settings.acquireReadLock();
try
{
tpaAcceptCancellation = settings.getData().getCommands().getTpa().getTimeout();
}
finally
{
settings.unlock();
}
int tpaAcceptCancellation = settings.getData().getCommands().getTpa().getTimeout();
if (tpaAcceptCancellation != 0 && (System.currentTimeMillis() - user.getTeleportRequestTime()) / 1000 > tpaAcceptCancellation)
{

View File

@@ -1,6 +1,5 @@
package net.ess3.commands;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.ISettings;
import net.ess3.api.IUser;
@@ -17,16 +16,14 @@ public class Commandtpahere extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
@Cleanup
final IUser player = ess.getUserMap().matchUser(args[0], false, false);
player.acquireReadLock();
if (!player.getData().isTeleportEnabled())
{
throw new Exception(_("teleportDisabled", player.getPlayer().getDisplayName()));
}
@Cleanup
ISettings settings = ess.getSettings();
settings.acquireReadLock();
if (user.getPlayer().getWorld() != player.getPlayer().getWorld() && settings.getData().getGeneral().isWorldTeleportPermissions()
&& !Permissions.WORLD.isAuthorized(user, user.getPlayer().getWorld().getName()))
{

View File

@@ -1,6 +1,5 @@
package net.ess3.commands;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.ISettings;
import net.ess3.api.IUser;
@@ -39,9 +38,8 @@ public class Commandtpall extends EssentialsCommand
{
continue;
}
@Cleanup
ISettings settings = ess.getSettings();
settings.acquireReadLock();
if (user.getPlayer().getWorld() != player.getPlayer().getWorld() && settings.getData().getGeneral().isWorldTeleportPermissions()
&& !Permissions.WORLD.isAuthorized(user, user.getPlayer().getWorld().getName()))

View File

@@ -1,6 +1,5 @@
package net.ess3.commands;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.IUser;
import net.ess3.economy.Trade;
@@ -12,9 +11,7 @@ public class Commandtphere extends EssentialsCommand
@Override
public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
{
@Cleanup
final IUser player = ess.getUserMap().matchUser(args[0], false, false);
player.acquireReadLock();
if (!player.getData().isTeleportEnabled())
{
throw new Exception(_("teleportDisabled", player.getPlayer().getDisplayName()));

View File

@@ -1,6 +1,5 @@
package net.ess3.commands;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.ISettings;
import net.ess3.api.IUser;
@@ -26,9 +25,8 @@ public class Commandtpohere extends EssentialsCommand
{
throw new NoSuchFieldException(_("playerNotFound"));
}
@Cleanup
ISettings settings = ess.getSettings();
settings.acquireReadLock();
//todo - common method
if (user.getPlayer().getWorld() != player.getPlayer().getWorld() && settings.getData().getGeneral().isWorldTeleportPermissions()
&& !Permissions.WORLD.isAuthorized(player, user.getPlayer().getWorld().getName()))

View File

@@ -1,6 +1,5 @@
package net.ess3.commands;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.IUser;
import org.bukkit.command.CommandSender;
@@ -16,11 +15,11 @@ public class Commandunban extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
@Cleanup
final IUser player = ess.getUserMap().matchUser(args[0], false, true);
player.acquireWriteLock();
player.getData().setBan(null);
player.setBanned(false);
player.queueSave();
sender.sendMessage(_("unbannedPlayer"));
}
}

View File

@@ -1,6 +1,5 @@
package net.ess3.commands;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.IUser;
import org.bukkit.command.CommandSender;
@@ -17,9 +16,7 @@ public class Commandunbanip extends EssentialsCommand
}
try
{
@Cleanup
final IUser user = ess.getUserMap().matchUser(args[0], false, true);
user.acquireReadLock();
ess.getServer().unbanIP(user.getData().getIpAddress());
}
catch (Exception ex)

View File

@@ -2,7 +2,6 @@ package net.ess3.commands;
import java.util.Locale;
import java.util.Set;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.IUser;
import net.ess3.craftbukkit.InventoryWorkaround;
@@ -21,13 +20,12 @@ public class Commandunlimited extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
@Cleanup
IUser target = user;
if (args.length > 1 && Permissions.UNLIMITED_OTHERS.isAuthorized(user))
{
target = ess.getUserMap().matchUser(args[1], false, false);
target.acquireReadLock();
}
if (args[0].equalsIgnoreCase("list"))
@@ -103,8 +101,8 @@ public class Commandunlimited extends EssentialsCommand
user.sendMessage(_(message, itemname, target.getPlayer().getDisplayName()));
}
target.sendMessage(_(message, itemname, target.getPlayer().getDisplayName()));
target.acquireWriteLock();
target.getData().setUnlimited(stack.getType(), enableUnlimited);
target.queueSave();
return true;
}

View File

@@ -1,7 +1,6 @@
package net.ess3.commands;
import java.util.Locale;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.ISettings;
import net.ess3.api.IUser;
@@ -15,7 +14,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Commandwhois extends EssentialsCommand
{
@Override
@@ -38,21 +36,18 @@ public class Commandwhois extends EssentialsCommand
showhidden = true;
}
final String whois = args[0].toLowerCase(Locale.ENGLISH);
@Cleanup
ISettings settings = ess.getSettings();
settings.acquireReadLock();
final int prefixLength = FormatUtil.stripColor(settings.getData().getChat().getNicknamePrefix()).length();
boolean foundPlayer = false;
for (Player onlinePlayer : server.getOnlinePlayers())
{
@Cleanup
final IUser user = ess.getUserMap().getUser(onlinePlayer);
if (user.isHidden() && !showhidden)
{
continue;
}
user.acquireReadLock();
final String nickName = FormatUtil.stripFormat(user.getData().getNickname());
if (!whois.equalsIgnoreCase(nickName)
&& !whois.substring(prefixLength).equalsIgnoreCase(nickName)

View File

@@ -51,19 +51,11 @@ public class EssentialsCommandHandler implements ICommandHandler
@Override
public boolean handleCommand(final CommandSender sender, final Command command, final String commandLabel, final String[] args)
{
boolean disabled = false;
boolean overridden = false;
ISettings settings = ess.getSettings();
settings.acquireReadLock();
try
{
disabled = settings.getData().getCommands().isDisabled(command.getName());
overridden = !disabled || settings.getData().getCommands().isOverridden(command.getName());
}
finally
{
settings.unlock();
}
boolean disabled = settings.getData().getCommands().isDisabled(command.getName());
boolean overridden = !disabled || settings.getData().getCommands().isOverridden(command.getName());
// TODO: Move this stuff to bukkit workarounds
// Allow plugins to override the command via onCommand
if (!overridden && (!commandLabel.startsWith("e") || commandLabel.equalsIgnoreCase(command.getName())))
@@ -150,7 +142,6 @@ public class EssentialsCommandHandler implements ICommandHandler
}
else
{
user.acquireReadLock();
user.setPlayerCache((Player)sender);
try
{
@@ -158,7 +149,7 @@ public class EssentialsCommandHandler implements ICommandHandler
}
finally
{
user.unlock();
user.setPlayerCache(null);
}
}
return true;

View File

@@ -1,12 +1,10 @@
package net.ess3.economy;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import net.ess3.api.*;
import net.ess3.permissions.Permissions;
import net.ess3.utils.FormatUtil;
import net.ess3.utils.Util;
public class Economy implements IEconomy
@@ -22,64 +20,27 @@ public class Economy implements IEconomy
private double getNPCBalance(String name) throws UserDoesNotExistException
{
npcs.acquireReadLock();
try
Double balance = npcs.getData().getBalances().get(name.toLowerCase(Locale.ENGLISH));
if (balance == null)
{
Map<String, Double> balances = npcs.getData().getBalances();
if (balances == null)
{
throw new UserDoesNotExistException(name);
}
Double balance = npcs.getData().getBalances().get(name.toLowerCase(Locale.ENGLISH));
if (balance == null)
{
throw new UserDoesNotExistException(name);
}
return balance;
}
finally
{
npcs.unlock();
throw new UserDoesNotExistException(name);
}
return balance;
}
private void setNPCBalance(String name, double balance, boolean checkExistance) throws UserDoesNotExistException
{
npcs.acquireWriteLock();
try
Map<String, Double> balances = npcs.getData().getBalances();
if (checkExistance && !balances.containsKey(name.toLowerCase(Locale.ENGLISH)))
{
Map<String, Double> balances = npcs.getData().getBalances();
if (balances == null)
{
balances = new HashMap<String, Double>();
npcs.getData().setBalances(balances);
}
if (checkExistance && !balances.containsKey(name.toLowerCase(Locale.ENGLISH)))
{
throw new UserDoesNotExistException(name);
}
balances.put(name.toLowerCase(Locale.ENGLISH), balance);
}
finally
{
npcs.unlock();
throw new UserDoesNotExistException(name);
}
npcs.getData().setBalance(name.toLowerCase(Locale.ENGLISH), balance);
}
private double getStartingBalance()
{
double startingBalance = 0;
ISettings settings = ess.getSettings();
settings.acquireReadLock();
try
{
startingBalance = settings.getData().getEconomy().getStartingBalance();
}
finally
{
settings.unlock();
}
return startingBalance;
return ess.getSettings().getData().getEconomy().getStartingBalance();
}
@Override
@@ -182,27 +143,15 @@ public class Economy implements IEconomy
@Override
public void removeNPC(String name) throws UserDoesNotExistException
{
npcs.acquireWriteLock();
try
Map<String, Double> balances = npcs.getData().getBalances();
if (balances.containsKey(name.toLowerCase(Locale.ENGLISH)))
{
Map<String, Double> balances = npcs.getData().getBalances();
if (balances == null)
{
balances = new HashMap<String, Double>();
npcs.getData().setBalances(balances);
}
if (balances.containsKey(name.toLowerCase(Locale.ENGLISH)))
{
balances.remove(name.toLowerCase(Locale.ENGLISH));
}
else
{
throw new UserDoesNotExistException(name);
}
npcs.getData().removeBalance(name.toLowerCase(Locale.ENGLISH));
}
finally
else
{
npcs.unlock();
throw new UserDoesNotExistException(name);
}
}
}

View File

@@ -1,9 +1,13 @@
package net.ess3.economy;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import lombok.AccessLevel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import net.ess3.storage.MapValueType;
import net.ess3.storage.StorageObject;
@@ -13,5 +17,29 @@ import net.ess3.storage.StorageObject;
public class Money implements StorageObject
{
@MapValueType(Double.class)
private Map<String, Double> balances = new HashMap<String, Double>();
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
private Map<String, Double> balances;
public Map<String, Double> getBalances()
{
return balances == null
? Collections.<String, Double>emptyMap()
: Collections.unmodifiableMap(balances);
}
public void setBalance(String name, Double value) {
Map<String, Double> balanceMap = new HashMap<String, Double>(getBalances());
balanceMap.put(name, value);
balances = balanceMap;
}
void removeBalance(String name)
{
Map<String, Double> balanceMap = new HashMap<String, Double>(getBalances());
balanceMap.remove(name);
balances = balanceMap;
}
}

View File

@@ -9,7 +9,6 @@ import java.util.Locale;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.ChargeException;
import net.ess3.api.IEssentials;
@@ -81,9 +80,8 @@ public class Trade
throw new ChargeException(_("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " ")));
}
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
double money;
if (command != null && !command.isEmpty()
@@ -167,15 +165,14 @@ public class Trade
{
throw new ChargeException(_("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " ")));
}
InventoryWorkaround.removeItem(user.getPlayer().getInventory() , true, true, getItemStack());
InventoryWorkaround.removeItem(user.getPlayer().getInventory(), true, true, getItemStack());
user.getPlayer().updateInventory();
}
if (command != null && !command.isEmpty()
&& !Permissions.NOCOMMANDCOST.isAuthorized(user, command))
{
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
final double cost = settings.getData().getEconomy().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command);
if (!user.canAfford(cost) && cost > 0)
{
@@ -227,9 +224,7 @@ public class Trade
public static void log(String type, String subtype, String event, String sender, Trade charge, String receiver, Trade pay, Location loc, IEssentials ess)
{
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
if (!settings.getData().getEconomy().isLogEnabled())
{
return;

View File

@@ -2,7 +2,6 @@ package net.ess3.economy;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import net.ess3.api.IEssentials;
import net.ess3.api.IWorth;
@@ -15,20 +14,16 @@ import org.bukkit.material.MaterialData;
public class WorthHolder extends AsyncStorageObjectHolder<net.ess3.economy.Worth> implements IWorth
{
@Override
public void finishRead()
{
}
@Override
public void finishWrite()
{
}
public WorthHolder(final IEssentials ess)
{
super(ess, net.ess3.economy.Worth.class);
@@ -38,55 +33,44 @@ public class WorthHolder extends AsyncStorageObjectHolder<net.ess3.economy.Worth
@Override
public double getPrice(final ItemStack itemStack)
{
this.acquireReadLock();
try
final Map<MaterialData, Double> prices = this.getData().getSell();
if (prices == null || itemStack == null)
{
final Map<MaterialData, Double> prices = this.getData().getSell();
if (prices == null || itemStack == null)
return Double.NaN;
}
final Double basePrice = prices.get(itemStack.getData());
if (basePrice == null || Double.isNaN(basePrice))
{
return Double.NaN;
}
double multiplier = 1.0;
if (itemStack.getType().getMaxDurability() > 0)
{
multiplier *= (double)itemStack.getDurability() / (double)itemStack.getType().getMaxDurability();
}
if (itemStack.getEnchantments() != null && !itemStack.getEnchantments().isEmpty())
{
final Map<EnchantmentLevel, Double> enchantmentMultipliers = this.getData().getEnchantmentMultiplier();
if (enchantmentMultipliers != null)
{
return Double.NaN;
}
final Double basePrice = prices.get(itemStack.getData());
if (basePrice == null || Double.isNaN(basePrice))
{
return Double.NaN;
}
double multiplier = 1.0;
if (itemStack.getType().getMaxDurability() > 0) {
multiplier *= (double)itemStack.getDurability() / (double)itemStack.getType().getMaxDurability();
}
if (itemStack.getEnchantments() != null && !itemStack.getEnchantments().isEmpty())
{
final Map<EnchantmentLevel, Double> enchantmentMultipliers = this.getData().getEnchantmentMultiplier();
if (enchantmentMultipliers != null)
for (Map.Entry<Enchantment, Integer> entry : itemStack.getEnchantments().entrySet())
{
for (Map.Entry<Enchantment, Integer> entry : itemStack.getEnchantments().entrySet())
final Double enchMult = enchantmentMultipliers.get(new EnchantmentLevel(entry.getKey(), entry.getValue()));
if (enchMult != null)
{
final Double enchMult = enchantmentMultipliers.get(new EnchantmentLevel(entry.getKey(), entry.getValue()));
if (enchMult != null)
{
multiplier *= enchMult;
}
multiplier *= enchMult;
}
}
}
return basePrice * multiplier;
}
finally
{
this.unlock();
}
return basePrice * multiplier;
}
@Override
public void setPrice(final ItemStack itemStack, final double price)
{
acquireWriteLock();
try {
getData().setSellPrice(itemStack.getData(), price);
} finally {
unlock();
}
getData().setSellPrice(itemStack.getData(), price);
queueSave();
}
@Override

View File

@@ -1,6 +1,5 @@
package net.ess3.listener;
import lombok.Cleanup;
import net.ess3.api.IEssentials;
import net.ess3.api.IUser;
import net.ess3.bukkit.BukkitMaterial;
@@ -33,9 +32,8 @@ public class EssentialsBlockListener implements Listener
return;
}
@Cleanup
final IUser user = ess.getUserMap().getUser(event.getPlayer());
user.acquireReadLock();
final boolean unlimitedForUser = user.getData().hasUnlimited(itemstack.getType());
if (unlimitedForUser && user.getPlayer().getGameMode() != GameMode.CREATIVE)

View File

@@ -1,7 +1,6 @@
package net.ess3.listener;
import java.util.List;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.IEssentials;
import net.ess3.api.ISettings;
@@ -38,15 +37,12 @@ public class EssentialsEntityListener implements Listener
if (eDefend instanceof Player && eAttack instanceof Player)
{
@Cleanup
final IUser attacker = ess.getUserMap().getUser((Player)eAttack);
@Cleanup
final IUser defender = ess.getUserMap().getUser((Player)eDefend);
@Cleanup
ISettings settings = ess.getSettings();
settings.acquireReadLock();
attacker.acquireReadLock();
defender.acquireReadLock();
attacker.updateActivity(true);
if (settings.getData().getGeneral().getLoginAttackDelay() > 0 && !Permissions.PVPDELAY_EXEMPT.isAuthorized(attacker)
@@ -121,9 +117,8 @@ public class EssentialsEntityListener implements Listener
public void onPlayerDeathEvent(final PlayerDeathEvent event)
{
final IUser user = ess.getUserMap().getUser((Player)event.getEntity());
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
if (Permissions.BACK_ONDEATH.isAuthorized(user) && !settings.getData().getCommands().isDisabled("back"))
{
user.setLastLocation();
@@ -161,12 +156,10 @@ public class EssentialsEntityListener implements Listener
if (event.getRegainReason() == RegainReason.SATIATED && event.getEntity() instanceof Player)
{
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
@Cleanup
final IUser user = ess.getUserMap().getUser((Player)event.getEntity());
user.acquireReadLock();
if (user.getData().isAfk() && settings.getData().getCommands().getAfk().isFreezeAFKPlayers())
{
event.setCancelled(true);
@@ -187,18 +180,10 @@ public class EssentialsEntityListener implements Listener
return;
}
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
try
final Boolean prevent = settings.getData().getWorldOptions(event.getLocation().getWorld().getName()).getPreventSpawn(creature);
if (prevent != null && prevent)
{
final Boolean prevent = settings.getData().getWorldOptions(event.getLocation().getWorld().getName()).getPreventSpawn(creature);
if (prevent != null && prevent)
{
event.setCancelled(true);
}
}
finally
{
settings.unlock();
event.setCancelled(true);
}
}
}

View File

@@ -7,7 +7,6 @@ import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.IEssentials;
import net.ess3.api.ISettings;
@@ -60,9 +59,7 @@ public class EssentialsPlayerListener implements Listener
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerChat(final PlayerChatEvent event)
{
@Cleanup
final IUser user = ess.getUserMap().getUser(event.getPlayer());
user.acquireReadLock();
if (user.getData().isMuted())
{
event.setCancelled(true);
@@ -85,12 +82,9 @@ public class EssentialsPlayerListener implements Listener
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerMove(final PlayerMoveEvent event)
{
@Cleanup
final IUser user = ess.getUserMap().getUser(event.getPlayer());
user.acquireReadLock();
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
if (user.getData().isAfk() && settings.getData().getCommands().getAfk().isFreezeAFKPlayers())
{
@@ -120,12 +114,9 @@ public class EssentialsPlayerListener implements Listener
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(final PlayerQuitEvent event)
{
@Cleanup
final IUser user = ess.getUserMap().getUser(event.getPlayer());
user.acquireReadLock();
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
if (settings.getData().getCommands().getGod().isRemoveOnDisconnect() && user.isGodModeEnabled())
{
user.setGodModeEnabled(false);
@@ -151,9 +142,8 @@ public class EssentialsPlayerListener implements Listener
return;
}
ess.getBackup().startTask();
@Cleanup
final IUser user = ess.getUserMap().getUser(event.getPlayer());
user.acquireWriteLock();
user.updateDisplayName();
user.getData().setIpAddress(user.getPlayer().getAddress().getAddress().getHostAddress());
@@ -171,10 +161,10 @@ public class EssentialsPlayerListener implements Listener
{
user.getPlayer().setSleepingIgnored(true);
}
user.queueSave();
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
if (!settings.getData().getCommands().isDisabled("motd") && Permissions.MOTD.isAuthorized(user))
{
@@ -224,9 +214,8 @@ public class EssentialsPlayerListener implements Listener
default:
return;
}
@Cleanup
final IUser user = ess.getUserMap().getUser(event.getPlayer());
user.acquireWriteLock();
user.getData().setNpc(false);
final long currentTime = System.currentTimeMillis();
@@ -250,14 +239,14 @@ public class EssentialsPlayerListener implements Listener
user.setTimestamp(TimestampType.LOGIN, System.currentTimeMillis());
user.updateCompass();
user.queueSave();
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerTeleport(final PlayerTeleportEvent event)
{
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
//There is TeleportCause.COMMMAND but plugins have to actively pass the cause in on their teleports.
if ((event.getCause() == TeleportCause.PLUGIN || event.getCause() == TeleportCause.COMMAND) && settings.getData().getCommands().getBack().isRegisterBackInListener())
{
@@ -270,9 +259,8 @@ public class EssentialsPlayerListener implements Listener
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerEggThrow(final PlayerEggThrowEvent event)
{
@Cleanup
final IUser user = ess.getUserMap().getUser(event.getPlayer());
user.acquireReadLock();
final ItemStack hand = new ItemStack(Material.EGG, 1);
if (user.getData().hasUnlimited(hand.getType()))
{
@@ -284,9 +272,8 @@ public class EssentialsPlayerListener implements Listener
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerBucketEmpty(final PlayerBucketEmptyEvent event)
{
@Cleanup
final IUser user = ess.getUserMap().getUser(event.getPlayer());
user.acquireReadLock();
if (user.getData().hasUnlimited(event.getBucket()))
{
event.getItemStack().setType(event.getBucket());
@@ -311,9 +298,7 @@ public class EssentialsPlayerListener implements Listener
{
for (Player player : ess.getServer().getOnlinePlayers())
{
@Cleanup
IUser spyer = ess.getUserMap().getUser(player);
spyer.acquireReadLock();
if (spyer.getData().isSocialspy() && !user.equals(spyer))
{
player.sendMessage(user.getPlayer().getDisplayName() + " : " + event.getMessage());
@@ -329,12 +314,9 @@ public class EssentialsPlayerListener implements Listener
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerChangedWorld(final PlayerChangedWorldEvent event)
{
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
@Cleanup
final IUser user = ess.getUserMap().getUser(event.getPlayer());
user.acquireReadLock();
if (settings.getData().getChat().getChangeDisplayname())
{
user.updateDisplayName();
@@ -359,9 +341,7 @@ public class EssentialsPlayerListener implements Listener
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerInteract(final PlayerInteractEvent event)
{
@Cleanup
final IUser user = ess.getUserMap().getUser(event.getPlayer());
user.acquireReadLock();
user.updateActivity(true);
switch (event.getAction())
{
@@ -370,9 +350,8 @@ public class EssentialsPlayerListener implements Listener
{
return;
}
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
if (settings.getData().getCommands().getHome().isUpdateBedAtDaytime() && event.getClickedBlock().getType() == Material.BED_BLOCK)
{
event.getPlayer().setBedSpawnLocation(event.getClickedBlock().getLocation());
@@ -441,16 +420,13 @@ public class EssentialsPlayerListener implements Listener
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerPickupItem(final PlayerPickupItemEvent event)
{
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
if (!settings.getData().getCommands().getAfk().isDisableItemPickupWhileAfk())
{
return;
}
@Cleanup
final IUser user = ess.getUserMap().getUser(event.getPlayer());
user.acquireReadLock();
if (user.getData().isAfk())
{
event.setCancelled(true);

View File

@@ -65,16 +65,8 @@ public class EssentialsPluginListener implements Listener, IReload
private void checkGroups()
{
ISettings settings = ess.getSettings();
settings.acquireReadLock();
General.GroupStorage storage = General.GroupStorage.FILE;
try
{
storage = settings.getData().getGeneral().getGroupStorage();
}
finally
{
settings.unlock();
}
General.GroupStorage storage = settings.getData().getGeneral().getGroupStorage();
if (storage == General.GroupStorage.GROUPMANAGER)
{
Plugin groupManager = ess.getServer().getPluginManager().getPlugin("GroupManager");

View File

@@ -1,7 +1,6 @@
package net.ess3.metrics;
import java.util.logging.Level;
import lombok.Cleanup;
import net.ess3.api.IEssentials;
import net.ess3.api.ISettings;
import net.ess3.api.IUser;
@@ -30,16 +29,15 @@ public class MetricsListener implements Listener
public void onPlayerJoin(final PlayerJoinEvent event)
{
final IUser player = ess.getUserMap().getUser(event.getPlayer());
@Cleanup
ISettings settings = ess.getSettings();
settings.acquireReadLock();
if (settings.getData().getGeneral().getMetricsEnabled() == null && (Permissions.ESSENTIALS.isAuthorized(event.getPlayer()) || event.getPlayer().hasPermission("bukkit.broadcast.admin")))
{
player.sendMessage("PluginMetrics collects minimal statistic data, starting in about 5 minutes.");
player.sendMessage("To opt out, run /essentials opt-out");
ess.getLogger().log(Level.INFO, "[Metrics] Admin join - Starting 5 minute opt-out period.");
settings.acquireWriteLock();
settings.getData().getGeneral().setMetricsEnabled(true);
settings.queueSave();
ess.getPlugin().scheduleAsyncDelayedTask(starter, 5 * 1200);
}
}

View File

@@ -2,7 +2,6 @@ package net.ess3.metrics;
import java.util.Locale;
import java.util.logging.Level;
import lombok.Cleanup;
import net.ess3.api.IEssentials;
import net.ess3.api.ISettings;
import net.ess3.economy.register.Method;
@@ -38,9 +37,7 @@ public class MetricsStarter implements Runnable
final Metrics metrics = new Metrics(ess.getPlugin());
ess.setMetrics(metrics);
@Cleanup
ISettings settings = ess.getSettings();
settings.acquireReadLock();
if (!metrics.isOptOut())
{
if (settings.getData().getGeneral().getMetricsEnabled() == true)
@@ -128,9 +125,8 @@ public class MetricsStarter implements Runnable
final Graph enabledGraph = metrics.createGraph("EnabledFeatures");
enabledGraph.addPlotter(new SimplePlotter("Total"));
@Cleanup
ISettings settings = ess.getSettings();
settings.acquireReadLock();
final String BKcommand = settings.getData().getGeneral().getBackup().getCommand();;
if (BKcommand != null && !"".equals(BKcommand))
{

View File

@@ -1,7 +1,6 @@
package net.ess3.ranks;
import java.text.MessageFormat;
import lombok.Cleanup;
import net.ess3.api.IEssentials;
import net.ess3.api.IRanks;
import net.ess3.api.ISettings;
@@ -11,7 +10,9 @@ import org.anjocaido.groupmanager.GroupManager;
import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler;
import org.bukkit.plugin.Plugin;
public class GMGroups implements IRanks {
public class GMGroups implements IRanks
{
private final transient IEssentials ess;
private final transient GroupManager groupManager;
@@ -90,16 +91,16 @@ public class GMGroups implements IRanks {
@Override
public MessageFormat getChatFormat(final IUser player)
{
String format = getRawChatFormat(player);
format = FormatUtil.replaceFormat(format);
format = format.replace("{DISPLAYNAME}", "%1$s");
format = format.replace("{GROUP}", "{0}");
format = format.replace("{MESSAGE}", "%2$s");
format = format.replace("{WORLDNAME}", "{1}");
format = format.replace("{SHORTWORLDNAME}", "{2}");
format = format.replaceAll("\\{(\\D*)\\}", "\\[$1\\]");
MessageFormat mFormat = new MessageFormat(format);
return mFormat;
String format = getRawChatFormat(player);
format = FormatUtil.replaceFormat(format);
format = format.replace("{DISPLAYNAME}", "%1$s");
format = format.replace("{GROUP}", "{0}");
format = format.replace("{MESSAGE}", "%2$s");
format = format.replace("{WORLDNAME}", "{1}");
format = format.replace("{SHORTWORLDNAME}", "{2}");
format = format.replaceAll("\\{(\\D*)\\}", "\\[$1\\]");
MessageFormat mFormat = new MessageFormat(format);
return mFormat;
}
private String getRawChatFormat(final IUser player)
@@ -108,14 +109,13 @@ public class GMGroups implements IRanks {
if (handler != null)
{
String chatformat = handler.getPermissionString(player.getName(), "chatformat");
if (chatformat != null && !chatformat.isEmpty()) {
if (chatformat != null && !chatformat.isEmpty())
{
return chatformat;
}
}
@Cleanup
ISettings settings = ess.getSettings();
settings.acquireReadLock();
return settings.getData().getChat().getDefaultFormat();
}

View File

@@ -7,7 +7,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
import lombok.Cleanup;
import net.ess3.api.IEssentials;
import net.ess3.api.IRanks;
import net.ess3.api.ISettings;
@@ -43,31 +42,23 @@ public class RanksStorage extends AsyncStorageObjectHolder<Ranks> implements IRa
public Collection<Entry<String, RankOptions>> getGroups(final IUser player)
{
acquireReadLock();
try
final Map<String, RankOptions> groups = getData().getRanks();
if (groups == null || groups.isEmpty())
{
final Map<String, RankOptions> groups = getData().getRanks();
if (groups == null || groups.isEmpty())
return Collections.emptyList();
}
final ArrayList<Entry<String, RankOptions>> list = new ArrayList();
for (Entry<String, RankOptions> entry : groups.entrySet())
{
if (Permissions.RANKS.isAuthorized(player, entry.getKey()))
{
return Collections.emptyList();
}
final ArrayList<Entry<String, RankOptions>> list = new ArrayList();
for (Entry<String, RankOptions> entry : groups.entrySet())
{
if (Permissions.RANKS.isAuthorized(player, entry.getKey()))
if (entry.getValue() != null)
{
if (entry.getValue() != null)
{
list.add(entry);
}
list.add(entry);
}
}
return list;
}
finally
{
unlock();
}
return list;
}
@Override
@@ -173,9 +164,8 @@ public class RanksStorage extends AsyncStorageObjectHolder<Ranks> implements IRa
return groupOptions.getValue().getMessageFormat();
}
}
@Cleanup
ISettings settings = ess.getSettings();
settings.acquireReadLock();
return settings.getData().getChat().getDefaultFormat();
}

View File

@@ -1,7 +1,6 @@
package net.ess3.ranks;
import java.text.MessageFormat;
import lombok.Cleanup;
import net.ess3.api.IEssentials;
import net.ess3.api.IRanks;
import net.ess3.api.ISettings;
@@ -92,9 +91,7 @@ public class VaultGroups implements IRanks
return chatformat;
}
@Cleanup
ISettings settings = ess.getSettings();
settings.acquireReadLock();
return settings.getData().getChat().getDefaultFormat();
}

View File

@@ -35,4 +35,11 @@ public class Jails implements StorageObject
jailMap.put(name, new StoredLocation(loc));
jails = jailMap;
}
public void removeJail(String name)
{
Map<String, StoredLocation> jailMap = new HashMap<String, StoredLocation>(getJails());
jailMap.remove(name);
jails = jailMap;
}
}

View File

@@ -9,19 +9,17 @@ import net.ess3.storage.AsyncStorageObjectHolder;
public class SettingsHolder extends AsyncStorageObjectHolder<Settings> implements ISettings
{
@Override
public void finishRead()
{
}
@Override
public void finishWrite()
{
}
private final transient AtomicBoolean debug = new AtomicBoolean(false);
private transient volatile boolean debug = false;
public SettingsHolder(final IEssentials ess)
{
super(ess, Settings.class);
@@ -32,12 +30,8 @@ public class SettingsHolder extends AsyncStorageObjectHolder<Settings> implement
public final void onReload()
{
super.onReload();
acquireReadLock();
try {
debug.set(getData().getGeneral().isDebug());
} finally {
unlock();
}
debug = getData().getGeneral().isDebug();
}
@Override
@@ -49,29 +43,20 @@ public class SettingsHolder extends AsyncStorageObjectHolder<Settings> implement
@Override
public String getLocale()
{
acquireReadLock();
try {
return getData().getGeneral().getLocale();
} finally {
unlock();
}
return getData().getGeneral().getLocale();
}
@Override
public boolean isDebug()
{
return debug.get();
return debug;
}
@Override
public void setDebug(final boolean set)
{
debug.set(set);
acquireWriteLock();
try {
getData().getGeneral().setDebug(set);
} finally {
unlock();
}
debug = set;
getData().getGeneral().setDebug(set);
queueSave();
}
}

View File

@@ -29,17 +29,14 @@ import org.bukkit.plugin.EventExecutor;
public class SpawnsHolder extends AsyncStorageObjectHolder<Spawns> implements IEssentialsModule
{
@Override
public void finishRead()
{
}
@Override
public void finishWrite()
{
}
public SpawnsHolder(final IEssentials ess)
@@ -57,15 +54,8 @@ public class SpawnsHolder extends AsyncStorageObjectHolder<Spawns> implements IE
public void setSpawn(final Location loc, final String group)
{
acquireWriteLock();
try
{
getData().addSpawn(group, loc);
}
finally
{
unlock();
}
getData().addSpawn(group, loc);
queueSave();
if ("default".equalsIgnoreCase(group))
{
@@ -75,35 +65,27 @@ public class SpawnsHolder extends AsyncStorageObjectHolder<Spawns> implements IE
public Location getSpawn(final String group)
{
acquireReadLock();
if (getData().getSpawns() == null || group == null)
{
return getWorldSpawn();
}
final Map<String, net.ess3.storage.StoredLocation> spawnMap = getData().getSpawns();
String groupName = group.toLowerCase(Locale.ENGLISH);
if (!spawnMap.containsKey(groupName))
{
groupName = "default";
}
if (!spawnMap.containsKey(groupName))
{
return getWorldSpawn();
}
try
{
if (getData().getSpawns() == null || group == null)
{
return getWorldSpawn();
}
final Map<String, net.ess3.storage.StoredLocation> spawnMap = getData().getSpawns();
String groupName = group.toLowerCase(Locale.ENGLISH);
if (!spawnMap.containsKey(groupName))
{
groupName = "default";
}
if (!spawnMap.containsKey(groupName))
{
return getWorldSpawn();
}
try
{
return spawnMap.get(groupName).getStoredLocation();
}
catch (WorldNotLoadedException ex)
{
return getWorldSpawn();
}
return spawnMap.get(groupName).getStoredLocation();
}
finally
catch (WorldNotLoadedException ex)
{
unlock();
return getWorldSpawn();
}
}
@@ -122,70 +104,37 @@ public class SpawnsHolder extends AsyncStorageObjectHolder<Spawns> implements IE
public EventPriority getRespawnPriority()
{
acquireReadLock();
try
for (EventPriority priority : EventPriority.values())
{
for (EventPriority priority : EventPriority.values())
if (priority.toString().equalsIgnoreCase(getData().getRespawnPriority()))
{
if (priority.toString().equalsIgnoreCase(getData().getRespawnPriority()))
{
return priority;
}
return priority;
}
return EventPriority.NORMAL;
}
finally
{
unlock();
}
return EventPriority.NORMAL;
}
public Location getNewbieSpawn()
{
acquireReadLock();
try
if (getData().getNewbieSpawn() == null || getData().getNewbieSpawn().isEmpty()
|| getData().getNewbieSpawn().equalsIgnoreCase("none"))
{
if (getData().getNewbieSpawn() == null || getData().getNewbieSpawn().isEmpty()
|| getData().getNewbieSpawn().equalsIgnoreCase("none"))
{
return null;
}
return getSpawn(getData().getNewbieSpawn());
}
finally
{
unlock();
return null;
}
return getSpawn(getData().getNewbieSpawn());
}
public boolean getAnnounceNewPlayers()
{
acquireReadLock();
try
{
return getData().getNewPlayerAnnouncement() != null && !getData().getNewPlayerAnnouncement().isEmpty();
}
finally
{
unlock();
}
return getData().getNewPlayerAnnouncement() != null && !getData().getNewPlayerAnnouncement().isEmpty();
}
public String getAnnounceNewPlayerFormat(IUser user)
{
acquireReadLock();
try
{
return getData().getNewPlayerAnnouncement().replace('&', '\u00a7').replace("\u00a7\u00a7", "&").replace("{PLAYER}", user.getPlayer().getDisplayName()).replace("{DISPLAYNAME}", user.getPlayer().getDisplayName()).replace("{GROUP}", ess.getRanks().getMainGroup(user)).replace("{USERNAME}", user.getName()).replace("{ADDRESS}", user.getPlayer().getAddress().toString());
}
finally
{
unlock();
}
return getData().getNewPlayerAnnouncement().replace('&', '\u00a7').replace("\u00a7\u00a7", "&").replace("{PLAYER}", user.getPlayer().getDisplayName()).replace("{DISPLAYNAME}", user.getPlayer().getDisplayName()).replace("{GROUP}", ess.getRanks().getMainGroup(user)).replace("{USERNAME}", user.getName()).replace("{ADDRESS}", user.getPlayer().getAddress().toString());
}
//TODO: Why is this stuff here in the settings folder?
private void registerListeners()
{
final SpawnPlayerListener playerListener = new SpawnPlayerListener(ess, this);
@@ -224,17 +173,8 @@ public class SpawnsHolder extends AsyncStorageObjectHolder<Spawns> implements IE
{
final IUser user = ess.getUserMap().getUser(event.getPlayer());
boolean respawnAtHome = false;
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
try
{
respawnAtHome = ess.getSettings().getData().getCommands().getHome().isRespawnAtHome();
}
finally
{
settings.unlock();
}
boolean respawnAtHome = ess.getSettings().getData().getCommands().getHome().isRespawnAtHome();
if (respawnAtHome)
{
Location home;

View File

@@ -13,7 +13,7 @@ import org.bukkit.Bukkit;
public abstract class AsyncStorageObjectHolder<T extends StorageObject> implements IStorageObjectHolder<T>
{
private transient T data;
private final transient ReentrantReadWriteLock rwl = new ReentrantReadWriteLock();
//private final transient ReentrantReadWriteLock rwl = new ReentrantReadWriteLock();
private final transient Class<T> clazz;
protected final transient IEssentials ess;
private final transient StorageObjectDataWriter writer;
@@ -52,7 +52,7 @@ public abstract class AsyncStorageObjectHolder<T extends StorageObject> implemen
return data;
}
@Override
/*@Override
public void acquireReadLock()
{
rwl.readLock().lock();
@@ -67,9 +67,9 @@ public abstract class AsyncStorageObjectHolder<T extends StorageObject> implemen
}
rwl.writeLock().lock();
rwl.readLock().lock();
}
}*/
@Override
/*@Override
public void close()
{
unlock();
@@ -87,8 +87,16 @@ public abstract class AsyncStorageObjectHolder<T extends StorageObject> implemen
{
rwl.readLock().unlock();
}
}*/
@Override
public void queueSave()
{
writer.schedule();
}
@Override
public void onReload()
{
@@ -123,14 +131,14 @@ public abstract class AsyncStorageObjectHolder<T extends StorageObject> implemen
@Override
public StorageObject getObject()
{
acquireReadLock();
//acquireReadLock();
return getData();
}
@Override
public void onFinish()
{
unlock();
//unlock();
finishWrite();
}
}
@@ -147,11 +155,11 @@ public abstract class AsyncStorageObjectHolder<T extends StorageObject> implemen
public File onStart() throws IOException
{
final File file = getStorageFile();
while (rwl.getReadHoldCount() > 0)
/*while (rwl.getReadHoldCount() > 0)
{
rwl.readLock().unlock();
}
rwl.writeLock().lock();
rwl.writeLock().lock();*/
return file;
}
@@ -162,7 +170,7 @@ public abstract class AsyncStorageObjectHolder<T extends StorageObject> implemen
{
data = object;
}
rwl.writeLock().unlock();
//rwl.writeLock().unlock();
loaded.set(true);
}
@@ -180,7 +188,7 @@ public abstract class AsyncStorageObjectHolder<T extends StorageObject> implemen
Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
}
}
rwl.writeLock().unlock();
//rwl.writeLock().unlock();
loaded.set(true);
if (exception instanceof FileNotFoundException)
{

View File

@@ -7,11 +7,11 @@ public interface IStorageObjectHolder<T extends StorageObject> extends IReload
{
T getData();
void acquireReadLock();
//void acquireReadLock();
void acquireWriteLock();
//void acquireWriteLock();
void close();
void queueSave();
void unlock();
//void unlock();
}

View File

@@ -6,7 +6,6 @@ import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import lombok.Cleanup;
import lombok.Getter;
import lombok.Setter;
import net.ess3.Console;
@@ -67,18 +66,6 @@ public class User extends UserBase implements IUser
playerCache = new WeakReference<Player>(player);
}
private void destroyPlayerCache()
{
playerCache = null;
}
@Override
public void close()
{
super.close();
destroyPlayerCache();
}
@Override
public Player getPlayer()
{
@@ -90,21 +77,6 @@ public class User extends UserBase implements IUser
return player;
}
public void example()
{
// Cleanup will call close at the end of the function
@Cleanup
final User user = this;
// read lock allows to read data from the user
user.acquireReadLock();
final double money = user.getData().getMoney();
// write lock allows only one thread to modify the data
user.acquireWriteLock();
user.getData().setMoney(10 + money);
}
@Override
public void finishRead()
{
@@ -150,20 +122,13 @@ public class User extends UserBase implements IUser
{
return;
}
acquireWriteLock();
try
setMoney(getMoney() + value);
sendMessage(_("addedToAccount", FormatUtil.displayCurrency(value, ess)));
if (initiator != null)
{
setMoney(getMoney() + value);
sendMessage(_("addedToAccount", FormatUtil.displayCurrency(value, ess)));
if (initiator != null)
{
initiator.sendMessage(_("addedToOthersAccount", FormatUtil.displayCurrency(value, ess), this.getPlayer().getDisplayName()));
}
}
finally
{
unlock();
initiator.sendMessage(_("addedToOthersAccount", FormatUtil.displayCurrency(value, ess), this.getPlayer().getDisplayName()));
}
queueSave();
}
@Override
@@ -220,58 +185,42 @@ public class User extends UserBase implements IUser
@Override
public void setLastLocation()
{
acquireWriteLock();
try
{
getData().setLastLocation(new net.ess3.storage.StoredLocation(getPlayer().getLocation()));
}
finally
{
unlock();
}
getData().setLastLocation(new net.ess3.storage.StoredLocation(getPlayer().getLocation()));
queueSave();
}
public String getNick(boolean addprefixsuffix)
{
acquireReadLock();
try
{
final String nick = getData().getNickname();
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
final IRanks groups = ess.getRanks();
// default: {PREFIX}{NICKNAMEPREFIX}{NAME}{SUFFIX}
String displayname = settings.getData().getChat().getDisplaynameFormat();
if (settings.getData().getCommands().isDisabled("nick") || nick == null || nick.isEmpty() || nick.equals(getName()))
{
displayname = displayname.replace("{NAME}", getName());
displayname = displayname.replace("{NICKNAMEPREFIX}", "");
}
else
{
displayname = displayname.replace("{NAME}", nick);
displayname = displayname.replace("{NICKNAMEPREFIX}", settings.getData().getChat().getNicknamePrefix());
}
if (displayname.contains("{PREFIX}"))
{
displayname = displayname.replace("{PREFIX}", groups.getPrefix(this));
}
if (displayname.contains("{SUFFIX}"))
{
displayname = displayname.replace("{SUFFIX}", groups.getSuffix(this));
}
displayname = displayname.replace("{WORLDNAME}", this.getPlayer().getWorld().getName());
displayname = displayname.replace('&', '\u00a7');
displayname = displayname.concat("\u00a7f");
return displayname;
}
finally
final String nick = getData().getNickname();
final ISettings settings = ess.getSettings();
final IRanks groups = ess.getRanks();
// default: {PREFIX}{NICKNAMEPREFIX}{NAME}{SUFFIX}
String displayname = settings.getData().getChat().getDisplaynameFormat();
if (settings.getData().getCommands().isDisabled("nick") || nick == null || nick.isEmpty() || nick.equals(getName()))
{
unlock();
displayname = displayname.replace("{NAME}", getName());
displayname = displayname.replace("{NICKNAMEPREFIX}", "");
}
else
{
displayname = displayname.replace("{NAME}", nick);
displayname = displayname.replace("{NICKNAMEPREFIX}", settings.getData().getChat().getNicknamePrefix());
}
if (displayname.contains("{PREFIX}"))
{
displayname = displayname.replace("{PREFIX}", groups.getPrefix(this));
}
if (displayname.contains("{SUFFIX}"))
{
displayname = displayname.replace("{SUFFIX}", groups.getSuffix(this));
}
displayname = displayname.replace("{WORLDNAME}", this.getPlayer().getWorld().getName());
displayname = displayname.replace('&', '\u00a7');
displayname = displayname.concat("\u00a7f");
return displayname;
}
@Override
@@ -300,9 +249,7 @@ public class User extends UserBase implements IUser
@Override
public void updateDisplayName()
{
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
if (isOnline() && settings.getData().getChat().getChangeDisplayname())
{
setDisplayNick();
@@ -355,20 +302,14 @@ public class User extends UserBase implements IUser
public void setAfk(final boolean set)
{
acquireWriteLock();
try
this.getPlayer().setSleepingIgnored(Permissions.SLEEPINGIGNORED.isAuthorized(this) ? true : set);
if (set && !getData().isAfk())
{
this.getPlayer().setSleepingIgnored(Permissions.SLEEPINGIGNORED.isAuthorized(this) ? true : set);
if (set && !getData().isAfk())
{
afkPosition = getPlayer().getLocation();
}
getData().setAfk(set);
}
finally
{
unlock();
afkPosition = getPlayer().getLocation();
}
getData().setAfk(set);
queueSave();
}
@Override
@@ -383,109 +324,76 @@ public class User extends UserBase implements IUser
@Override
public boolean checkJailTimeout(final long currentTime)
{
acquireReadLock();
try
if (getTimestamp(UserData.TimestampType.JAIL) > 0 && getTimestamp(UserData.TimestampType.JAIL) < currentTime && getData().isJailed())
{
if (getTimestamp(UserData.TimestampType.JAIL) > 0 && getTimestamp(UserData.TimestampType.JAIL) < currentTime && getData().isJailed())
setTimestamp(UserData.TimestampType.JAIL, 0);
getData().setJailed(false);
sendMessage(_("haveBeenReleased"));
getData().setJail(null);
queueSave();
try
{
acquireWriteLock();
setTimestamp(UserData.TimestampType.JAIL, 0);
getData().setJailed(false);
sendMessage(_("haveBeenReleased"));
getData().setJail(null);
try
{
teleport.back();
}
catch (Exception ex)
{
}
return true;
teleport.back();
}
return false;
}
finally
{
unlock();
catch (Exception ex)
{
}
return true;
}
return false;
}
//Returns true if status expired during this check
@Override
public boolean checkMuteTimeout(final long currentTime)
{
acquireReadLock();
try
if (getTimestamp(UserData.TimestampType.MUTE) > 0 && getTimestamp(UserData.TimestampType.MUTE) < currentTime && getData().isMuted())
{
if (getTimestamp(UserData.TimestampType.MUTE) > 0 && getTimestamp(UserData.TimestampType.MUTE) < currentTime && getData().isMuted())
{
acquireWriteLock();
setTimestamp(UserData.TimestampType.MUTE, 0);
sendMessage(_("canTalkAgain"));
getData().setMuted(false);
return true;
}
return false;
}
finally
{
unlock();
setTimestamp(UserData.TimestampType.MUTE, 0);
sendMessage(_("canTalkAgain"));
getData().setMuted(false);
queueSave();
return true;
}
return false;
}
//Returns true if status expired during this check
@Override
public boolean checkBanTimeout(final long currentTime)
{
acquireReadLock();
try
if (getData().getBan() != null && getData().getBan().getTimeout() > 0 && getData().getBan().getTimeout() < currentTime && isBanned())
{
if (getData().getBan() != null && getData().getBan().getTimeout() > 0 && getData().getBan().getTimeout() < currentTime && isBanned())
{
acquireWriteLock();
getData().setBan(null);
setBanned(false);
return true;
}
return false;
}
finally
{
unlock();
getData().setBan(null);
setBanned(false);
queueSave();
return true;
}
return false;
}
@Override
public void updateActivity(final boolean broadcast)
{
acquireReadLock();
try
if (getData().isAfk())
{
if (getData().isAfk())
getData().setAfk(false);
queueSave();
if (broadcast && !hidden)
{
acquireWriteLock();
getData().setAfk(false);
if (broadcast && !hidden)
{
ess.broadcastMessage(this, _("userIsNotAway", getPlayer().getDisplayName()));
}
ess.broadcastMessage(this, _("userIsNotAway", getPlayer().getDisplayName()));
}
lastActivity = System.currentTimeMillis();
}
finally
{
unlock();
}
lastActivity = System.currentTimeMillis();
}
@Override
public void checkActivity()
{
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
final long autoafkkick = settings.getData().getCommands().getAfk().getAutoAFKKick();
if (autoafkkick > 0 && lastActivity > 0 && (lastActivity + (autoafkkick * 1000)) < System.currentTimeMillis()
&& !hidden
@@ -506,22 +414,15 @@ public class User extends UserBase implements IUser
}
}
final long autoafk = settings.getData().getCommands().getAfk().getAutoAFK();
acquireReadLock();
try
if (!getData().isAfk() && autoafk > 0 && lastActivity + autoafk * 1000 < System.currentTimeMillis() && Permissions.AFK.isAuthorized(this))
{
if (!getData().isAfk() && autoafk > 0 && lastActivity + autoafk * 1000 < System.currentTimeMillis() && Permissions.AFK.isAuthorized(this))
setAfk(true);
if (!hidden)
{
setAfk(true);
if (!hidden)
{
ess.broadcastMessage(this, _("userIsAway", getPlayer().getDisplayName()));
}
ess.broadcastMessage(this, _("userIsAway", getPlayer().getDisplayName()));
}
}
finally
{
unlock();
}
}
@Override
@@ -533,20 +434,10 @@ public class User extends UserBase implements IUser
@Override
public boolean isGodModeEnabled()
{
acquireReadLock();
try
{
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
return (getData().isGodmode()
&& !settings.getData().getWorldOptions(getPlayer().getLocation().getWorld().getName()).isGodmode())
|| (getData().isAfk() && settings.getData().getCommands().getAfk().isFreezeAFKPlayers());
}
finally
{
unlock();
}
final ISettings settings = ess.getSettings();
return (getData().isGodmode()
&& !settings.getData().getWorldOptions(getPlayer().getLocation().getWorld().getName()).isGodmode())
|| (getData().isAfk() && settings.getData().getCommands().getAfk().isFreezeAFKPlayers());
}
@Override
@@ -649,9 +540,7 @@ public class User extends UserBase implements IUser
final Map<Integer, ItemStack> overfilled;
if (Permissions.OVERSIZEDSTACKS.isAuthorized(this))
{
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
int oversizedStackSize = settings.getData().getGeneral().getOversizedStacksize();
overfilled = InventoryWorkaround.addItem(getPlayer().getInventory(), true, oversizedStackSize, itemStack);
@@ -684,9 +573,7 @@ public class User extends UserBase implements IUser
final double mon = getMoney();
if (Permissions.ECO_LOAN.isAuthorized(this))
{
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
return (mon - cost) >= settings.getData().getEconomy().getMinMoney();
}
return cost <= mon;
@@ -710,9 +597,7 @@ public class User extends UserBase implements IUser
public void enableInvulnerabilityAfterTeleport()
{
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
final long time = settings.getData().getGeneral().getTeleportInvulnerability();
if (time > 0)

View File

@@ -3,7 +3,6 @@ package net.ess3.user;
import java.io.File;
import java.io.IOException;
import java.util.*;
import lombok.Cleanup;
import lombok.Delegate;
import net.ess3.api.IEssentials;
import net.ess3.api.ISettings;
@@ -41,7 +40,8 @@ public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implem
public void sendMessage(String string)
{
Player player = offlinePlayer.getPlayer();
if (player != null) {
if (player != null)
{
player.sendMessage(string);
}
}
@@ -50,7 +50,8 @@ public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implem
public void sendMessage(String[] strings)
{
Player player = offlinePlayer.getPlayer();
if (player != null) {
if (player != null)
{
player.sendMessage(strings);
}
}
@@ -65,9 +66,12 @@ public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implem
public boolean isPermissionSet(String string)
{
Player player = offlinePlayer.getPlayer();
if (player != null) {
if (player != null)
{
return player.isPermissionSet(string);
} else {
}
else
{
return false;
}
}
@@ -76,9 +80,12 @@ public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implem
public boolean isPermissionSet(Permission prmsn)
{
Player player = offlinePlayer.getPlayer();
if (player != null) {
if (player != null)
{
return player.isPermissionSet(prmsn);
} else {
}
else
{
return false;
}
}
@@ -87,9 +94,12 @@ public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implem
public boolean hasPermission(String string)
{
Player player = offlinePlayer.getPlayer();
if (player != null) {
if (player != null)
{
return player.hasPermission(string);
} else {
}
else
{
return false;
}
}
@@ -98,9 +108,12 @@ public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implem
public boolean hasPermission(Permission prmsn)
{
Player player = offlinePlayer.getPlayer();
if (player != null) {
if (player != null)
{
return player.hasPermission(prmsn);
} else {
}
else
{
return false;
}
}
@@ -162,300 +175,174 @@ public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implem
public long getTimestamp(final UserData.TimestampType name)
{
acquireReadLock();
try
{
return getData().getTimestamp(name);
}
finally
{
unlock();
}
return getData().getTimestamp(name);
}
public void setTimestamp(final UserData.TimestampType name, final long value)
{
acquireWriteLock();
try
{
getData().setTimestamp(name, value);
}
finally
{
unlock();
}
getData().setTimestamp(name, value);
queueSave();
}
public void setMoney(final double value)
{
acquireWriteLock();
try
final ISettings settings = ess.getSettings();
if (Math.abs(value) > settings.getData().getEconomy().getMaxMoney())
{
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
if (Math.abs(value) > settings.getData().getEconomy().getMaxMoney())
{
getData().setMoney(value < 0 ? -settings.getData().getEconomy().getMaxMoney() : settings.getData().getEconomy().getMaxMoney());
}
else
{
getData().setMoney(value);
}
getData().setMoney(value < 0 ? -settings.getData().getEconomy().getMaxMoney() : settings.getData().getEconomy().getMaxMoney());
}
finally
else
{
unlock();
getData().setMoney(value);
}
queueSave();
}
public double getMoney()
{
acquireReadLock();
try
Double money = getData().getMoney();
final ISettings settings = ess.getSettings();
if (money == null)
{
Double money = getData().getMoney();
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
if (money == null)
{
money = (double)settings.getData().getEconomy().getStartingBalance();
}
if (Math.abs(money) > settings.getData().getEconomy().getMaxMoney())
{
money = money < 0 ? -settings.getData().getEconomy().getMaxMoney() : settings.getData().getEconomy().getMaxMoney();
}
return money;
money = (double)settings.getData().getEconomy().getStartingBalance();
}
finally
if (Math.abs(money) > settings.getData().getEconomy().getMaxMoney())
{
unlock();
money = money < 0 ? -settings.getData().getEconomy().getMaxMoney() : settings.getData().getEconomy().getMaxMoney();
}
return money;
}
public void setHome(String name, Location loc)
{
acquireWriteLock();
try
{
getData().addHome(Util.sanitizeKey(name), loc);
}
finally
{
unlock();
}
getData().addHome(Util.sanitizeKey(name), loc);
queueSave();
}
public boolean toggleAfk()
{
acquireWriteLock();
try
{
boolean ret = !getData().isAfk();
getData().setAfk(ret);
return ret;
}
finally
{
unlock();
}
boolean ret = !getData().isAfk();
getData().setAfk(ret);
queueSave();
return ret;
}
public void setGodModeEnabled(boolean set)
{
acquireWriteLock();
try
{
getData().setGodmode(set);
}
finally
{
unlock();
}
getData().setGodmode(set);
queueSave();
}
public void setMuted(boolean mute)
{
acquireWriteLock();
try
{
getData().setMuted(mute);
}
finally
{
unlock();
}
getData().setMuted(mute);
queueSave();
}
public boolean toggleSocialSpy()
{
acquireWriteLock();
try
{
boolean ret = !getData().isSocialspy();
getData().setSocialspy(ret);
return ret;
}
finally
{
unlock();
}
boolean ret = !getData().isSocialspy();
getData().setSocialspy(ret);
queueSave();
return ret;
}
public boolean toggleTeleportEnabled()
{
acquireWriteLock();
try
{
boolean ret = !getData().isTeleportEnabled();
getData().setTeleportEnabled(ret);
return ret;
}
finally
{
unlock();
}
boolean ret = !getData().isTeleportEnabled();
getData().setTeleportEnabled(ret);
queueSave();
return ret;
}
public boolean isIgnoringPlayer(final IUser user)
{
acquireReadLock();
try
{
return getData().getIgnore() == null ? false : getData().getIgnore().contains(user.getName().toLowerCase(Locale.ENGLISH)) && Permissions.CHAT_IGNORE_EXEMPT.isAuthorized(user);
}
finally
{
unlock();
}
return getData().getIgnore() == null ? false : getData().getIgnore().contains(user.getName().toLowerCase(Locale.ENGLISH)) && Permissions.CHAT_IGNORE_EXEMPT.isAuthorized(user);
}
public void setIgnoredPlayer(final IUser user, final boolean set)
{
acquireWriteLock();
try
{
getData().setIgnore(user.getName().toLowerCase(Locale.ENGLISH), set);
}
finally
{
unlock();
}
getData().setIgnore(user.getName().toLowerCase(Locale.ENGLISH), set);
queueSave();
}
public void addMail(String string)
{
acquireWriteLock();
try
{
getData().addMail(string);
}
finally
{
unlock();
}
getData().addMail(string);
queueSave();
}
public List<String> getMails()
{
acquireReadLock();
try
{
return getData().getMails();
}
finally
{
unlock();
}
return getData().getMails();
}
public Location getHome(String name) throws Exception
{
acquireReadLock();
if (getData().getHomes() == null)
{
return null;
}
try
{
if (getData().getHomes() == null)
{
return null;
}
try
{
return getData().getHomes().get(Util.sanitizeKey(name)).getStoredLocation();
}
catch (WorldNotLoadedException ex)
{
return null;
}
return getData().getHomes().get(Util.sanitizeKey(name)).getStoredLocation();
}
finally
catch (WorldNotLoadedException ex)
{
unlock();
return null;
}
}
public Location getHome(Location loc)
{
acquireReadLock();
try
if (getData().getHomes() == null)
{
if (getData().getHomes() == null)
return null;
}
ArrayList<Location> worldHomes = new ArrayList<Location>();
for (net.ess3.storage.StoredLocation location : getData().getHomes().values())
{
if (location.getWorldName().equals(loc.getWorld().getName()))
{
return null;
}
ArrayList<Location> worldHomes = new ArrayList<Location>();
for (net.ess3.storage.StoredLocation location : getData().getHomes().values())
{
if (location.getWorldName().equals(loc.getWorld().getName()))
try
{
try
{
worldHomes.add(location.getStoredLocation());
}
catch (WorldNotLoadedException ex)
{
continue;
}
worldHomes.add(location.getStoredLocation());
}
catch (WorldNotLoadedException ex)
{
continue;
}
}
if (worldHomes.isEmpty())
{
return null;
}
if (worldHomes.size() == 1)
{
return worldHomes.get(0);
}
double distance = Double.MAX_VALUE;
Location target = null;
for (Location location : worldHomes)
{
final double d = loc.distanceSquared(location);
if (d < distance)
{
target = location;
distance = d;
}
}
return target;
}
finally
if (worldHomes.isEmpty())
{
unlock();
return null;
}
if (worldHomes.size() == 1)
{
return worldHomes.get(0);
}
double distance = Double.MAX_VALUE;
Location target = null;
for (Location location : worldHomes)
{
final double d = loc.distanceSquared(location);
if (d < distance)
{
target = location;
distance = d;
}
}
return target;
}
public Set<String> getHomes()
{
acquireReadLock();
try
{
return getData().getHomes().keySet();
}
finally
{
unlock();
}
return getData().getHomes().keySet();
}
}

View File

@@ -51,7 +51,8 @@ public class UserMap extends StorageObjectMap<IUser> implements IUserMap
}
}
Player player = ess.getServer().getPlayerExact(name);
if (player != null) {
if (player != null)
{
return new User(ess.getServer().getOfflinePlayer(player.getName()), ess);
}
final File userFile = getUserFile(name);
@@ -242,14 +243,6 @@ public class UserMap extends StorageObjectMap<IUser> implements IUserMap
private String getNickNamePrefix()
{
ess.getSettings().acquireReadLock();
try
{
return ess.getSettings().getData().getChat().getNicknamePrefix();
}
finally
{
ess.getSettings().unlock();
}
return ess.getSettings().getData().getChat().getNicknamePrefix();
}
}

View File

@@ -4,7 +4,6 @@ import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;
import java.util.regex.Pattern;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.IEssentials;
import net.ess3.api.ISettings;
@@ -126,17 +125,13 @@ public class FormatUtil
public static String shortCurrency(final double value, final IEssentials ess)
{
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
return settings.getData().getEconomy().getCurrencySymbol() + formatAsCurrency(value);
}
public static String displayCurrency(final double value, final IEssentials ess)
{
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
return _("currency", settings.getData().getEconomy().getCurrencySymbol(), formatAsCurrency(value));
}

View File

@@ -4,7 +4,6 @@ import java.io.IOException;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import lombok.Cleanup;
import static net.ess3.I18n._;
import net.ess3.api.IEssentials;
import net.ess3.api.ISettings;
@@ -26,9 +25,7 @@ public class HelpInput implements IText
public HelpInput(final IUser user, final String match, final IEssentials ess) throws IOException
{
@Cleanup
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
boolean reported = false;
final List<String> newLines = new ArrayList<String>();
String pluginName = "";

View File

@@ -5,7 +5,6 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import lombok.Cleanup;
import net.ess3.api.IEssentials;
import net.ess3.api.IUser;
import net.ess3.utils.DescParseTickFormat;
@@ -37,9 +36,7 @@ public class KeywordReplacer implements IText
String userName, address, version;
if (sender instanceof Player)
{
@Cleanup
final IUser user = ess.getUserMap().getUser((Player)sender);
user.acquireReadLock();
user.setDisplayNick();
displayName = user.getPlayer().getDisplayName();
userName = user.getPlayer().getName();

View File

@@ -1,5 +1,8 @@
package net.ess3.chat;
import java.util.Locale;
import java.util.Map;
import java.util.logging.Logger;
import static net.ess3.I18n._;
import net.ess3.api.ChargeException;
import net.ess3.api.IEssentials;
@@ -8,10 +11,6 @@ import net.ess3.api.ISettings;
import net.ess3.api.IUser;
import net.ess3.economy.Trade;
import net.ess3.permissions.Permissions;
import net.ess3.utils.Util;
import java.util.Locale;
import java.util.Map;
import java.util.logging.Logger;
import net.ess3.utils.FormatUtil;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
@@ -112,18 +111,8 @@ public abstract class EssentialsChatPlayer implements Listener
protected void handleLocalChat(final PlayerChatEvent event, final ChatStore chatStore)
{
long radius = 0;
ISettings settings = ess.getSettings();
settings.acquireReadLock();
try
{
radius = settings.getData().getChat().getLocalRadius();
}
finally
{
settings.unlock();
}
long radius = settings.getData().getChat().getLocalRadius();
if (radius < 1)
{

View File

@@ -50,64 +50,50 @@ public class EssentialsGeoIPPlayerListener implements Listener, IReload
{
return;
}
config.acquireReadLock();
try
if (event.getPlayer().getAddress() == null || event.getPlayer().getAddress().getAddress() == null)
{
if (event.getPlayer().getAddress() == null || event.getPlayer().getAddress().getAddress() == null) {
return;
}
final InetAddress address = event.getPlayer().getAddress().getAddress();
final StringBuilder builder = new StringBuilder();
if (config.getData().getDatabase().isShowCities())
{
final Location loc = ls.getLocation(address);
if (loc == null)
{
return;
}
final InetAddress address = event.getPlayer().getAddress().getAddress();
final StringBuilder builder = new StringBuilder();
if (config.getData().getDatabase().isShowCities())
if (loc.city != null)
{
final Location loc = ls.getLocation(address);
if (loc == null)
{
return;
}
if (loc.city != null)
{
builder.append(loc.city).append(", ");
}
final String region = regionName.regionNameByCode(loc.countryCode, loc.region);
if (region != null)
{
builder.append(region).append(", ");
}
builder.append(loc.countryName);
builder.append(loc.city).append(", ");
}
else
final String region = regionName.regionNameByCode(loc.countryCode, loc.region);
if (region != null)
{
builder.append(ls.getCountry(address).getName());
}
if (config.getData().isShowOnWhois())
{
u.acquireWriteLock();
try
{
u.getData().setGeolocation(builder.toString());
}
finally
{
u.unlock();
}
}
if (config.getData().isShowOnLogin() && !u.isHidden())
{
for (Player player : event.getPlayer().getServer().getOnlinePlayers())
{
final IUser user = ess.getUserMap().getUser(player);
if (Permissions.GEOIP_SHOW.isAuthorized(user))
{
user.sendMessage(_("geoipJoinFormat", user.getPlayer().getDisplayName(), builder.toString()));
}
}
builder.append(region).append(", ");
}
builder.append(loc.countryName);
}
finally
else
{
config.unlock();
builder.append(ls.getCountry(address).getName());
}
if (config.getData().isShowOnWhois())
{
u.getData().setGeolocation(builder.toString());
u.queueSave();
}
if (config.getData().isShowOnLogin() && !u.isHidden())
{
for (Player player : event.getPlayer().getServer().getOnlinePlayers())
{
final IUser user = ess.getUserMap().getUser(player);
if (Permissions.GEOIP_SHOW.isAuthorized(user))
{
user.sendMessage(_("geoipJoinFormat", user.getPlayer().getDisplayName(), builder.toString()));
}
}
}
}
@@ -115,48 +101,40 @@ public class EssentialsGeoIPPlayerListener implements Listener, IReload
public final void onReload()
{
config.onReload();
config.acquireReadLock();
try
if (config.getData().getDatabase().isShowCities())
{
if (config.getData().getDatabase().isShowCities())
databaseFile = new File(geoip.getDataFolder(), "GeoIPCity.dat");
}
else
{
databaseFile = new File(geoip.getDataFolder(), "GeoIP.dat");
}
if (!databaseFile.exists())
{
if (config.getData().getDatabase().isDownloadIfMissing())
{
databaseFile = new File(geoip.getDataFolder(), "GeoIPCity.dat");
}
else
{
databaseFile = new File(geoip.getDataFolder(), "GeoIP.dat");
}
if (!databaseFile.exists())
{
if (config.getData().getDatabase().isDownloadIfMissing())
if (config.getData().getDatabase().isShowCities())
{
if (config.getData().getDatabase().isShowCities())
{
downloadDatabase(config.getData().getDatabase().getDownloadUrlCity());
}
else
{
downloadDatabase(config.getData().getDatabase().getDownloadUrl());
}
downloadDatabase(config.getData().getDatabase().getDownloadUrlCity());
}
else
{
LOGGER.log(Level.SEVERE, _("cantFindGeoIpDB"));
return;
downloadDatabase(config.getData().getDatabase().getDownloadUrl());
}
}
try
else
{
ls = new LookupService(databaseFile);
}
catch (IOException ex)
{
LOGGER.log(Level.SEVERE, _("cantReadGeoIpDB"), ex);
LOGGER.log(Level.SEVERE, _("cantFindGeoIpDB"));
return;
}
}
finally
try
{
config.unlock();
ls = new LookupService(databaseFile);
}
catch (IOException ex)
{
LOGGER.log(Level.SEVERE, _("cantReadGeoIpDB"), ex);
}
}
@@ -167,7 +145,8 @@ public class EssentialsGeoIPPlayerListener implements Listener, IReload
LOGGER.log(Level.SEVERE, _("geoIpUrlEmpty"));
return;
}
if (!databaseFile.getAbsoluteFile().getParentFile().exists()) {
if (!databaseFile.getAbsoluteFile().getParentFile().exists())
{
databaseFile.getAbsoluteFile().getParentFile().mkdirs();
}
InputStream input = null;

View File

@@ -22,42 +22,34 @@ public class EssentialsProtectBlockListener implements Listener
public void onBlockIgnite(BlockIgniteEvent event)
{
final ProtectHolder settings = prot.getSettings();
settings.acquireReadLock();
try
final Block block = event.getBlock();
if (event.getBlock().getType() == Material.OBSIDIAN
|| event.getBlock().getRelative(BlockFace.DOWN).getType() == Material.OBSIDIAN)
{
final Block block = event.getBlock();
if (event.getBlock().getType() == Material.OBSIDIAN
|| event.getBlock().getRelative(BlockFace.DOWN).getType() == Material.OBSIDIAN)
{
event.setCancelled(settings.getData().getPrevent().isPortalCreation());
return;
}
if (event.getCause().equals(BlockIgniteEvent.IgniteCause.SPREAD))
{
event.setCancelled(settings.getData().getPrevent().isFirespread());
return;
}
if (event.getCause().equals(BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL) && event.getPlayer() != null)
{
event.setCancelled(Permissions.USEFLINTSTEEL.isAuthorized(event.getPlayer()));
return;
}
if (event.getCause().equals(BlockIgniteEvent.IgniteCause.LAVA))
{
event.setCancelled(settings.getData().getPrevent().isLavaFirespread());
return;
}
if (event.getCause().equals(BlockIgniteEvent.IgniteCause.LIGHTNING))
{
event.setCancelled(settings.getData().getPrevent().isLightningFirespread());
}
event.setCancelled(settings.getData().getPrevent().isPortalCreation());
return;
}
finally
if (event.getCause().equals(BlockIgniteEvent.IgniteCause.SPREAD))
{
settings.unlock();
event.setCancelled(settings.getData().getPrevent().isFirespread());
return;
}
if (event.getCause().equals(BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL) && event.getPlayer() != null)
{
event.setCancelled(Permissions.USEFLINTSTEEL.isAuthorized(event.getPlayer()));
return;
}
if (event.getCause().equals(BlockIgniteEvent.IgniteCause.LAVA))
{
event.setCancelled(settings.getData().getPrevent().isLavaFirespread());
return;
}
if (event.getCause().equals(BlockIgniteEvent.IgniteCause.LIGHTNING))
{
event.setCancelled(settings.getData().getPrevent().isLightningFirespread());
}
}
@@ -65,47 +57,32 @@ public class EssentialsProtectBlockListener implements Listener
public void onBlockFromTo(final BlockFromToEvent event)
{
final ProtectHolder settings = prot.getSettings();
settings.acquireReadLock();
try
final Block block = event.getBlock();
if (block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER)
{
final Block block = event.getBlock();
if (block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER)
{
event.setCancelled(settings.getData().getPrevent().isWaterFlow());
return;
}
event.setCancelled(settings.getData().getPrevent().isWaterFlow());
return;
}
if (block.getType() == Material.LAVA || block.getType() == Material.STATIONARY_LAVA)
{
event.setCancelled(settings.getData().getPrevent().isLavaFlow());
}
// TODO: Test if this still works
/*
* if (block.getType() == Material.AIR) {
* event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_water_bucket_flow)); return; }
*/
}
finally
if (block.getType() == Material.LAVA || block.getType() == Material.STATIONARY_LAVA)
{
settings.unlock();
event.setCancelled(settings.getData().getPrevent().isLavaFlow());
}
// TODO: Test if this still works
/*
* if (block.getType() == Material.AIR) {
* event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_water_bucket_flow)); return; }
*/
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockBurn(final BlockBurnEvent event)
{
final ProtectHolder settings = prot.getSettings();
settings.acquireReadLock();
try
if (settings.getData().getPrevent().isFirespread())
{
if (settings.getData().getPrevent().isFirespread())
{
event.setCancelled(true);
}
}
finally
{
settings.unlock();
event.setCancelled(true);
}
}
}

View File

@@ -23,140 +23,132 @@ public class EssentialsProtectEntityListener implements Listener
public void onEntityDamage(final EntityDamageEvent event)
{
final ProtectHolder settings = prot.getSettings();
settings.acquireReadLock();
try
{
final Entity target = event.getEntity();
final Entity target = event.getEntity();
if (target instanceof Villager && settings.getData().getPrevent().isVillagerDeath())
if (target instanceof Villager && settings.getData().getPrevent().isVillagerDeath())
{
event.setCancelled(true);
return;
}
final Player user = target instanceof Player ? (Player)target : null;
if (target instanceof Player && event instanceof EntityDamageByBlockEvent)
{
final DamageCause cause = event.getCause();
if (cause == DamageCause.CONTACT
&& (Permissions.PREVENTDAMAGE_CONTACT.isAuthorized(user)
&& !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{
event.setCancelled(true);
return;
}
if (cause == DamageCause.LAVA
&& (Permissions.PREVENTDAMAGE_LAVADAMAGE.isAuthorized(user)
&& !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{
event.setCancelled(true);
return;
}
if (cause == DamageCause.BLOCK_EXPLOSION
&& (Permissions.PREVENTDAMAGE_TNT.isAuthorized(user)
&& !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{
event.setCancelled(true);
return;
}
}
if (target instanceof Player && event instanceof EntityDamageByEntityEvent)
{
final EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent)event;
final Entity eAttack = edEvent.getDamager();
final Player attacker = eAttack instanceof Player ? (Player)eAttack : null;
// PVP Settings
if (target instanceof Player && eAttack instanceof Player
&& (!Permissions.PVP.isAuthorized(user) || !Permissions.PVP.isAuthorized(attacker)))
{
event.setCancelled(true);
return;
}
final Player user = target instanceof Player ? (Player)target : null;
if (target instanceof Player && event instanceof EntityDamageByBlockEvent)
//Creeper explode prevention
if (eAttack instanceof Creeper && settings.getData().getPrevent().isCreeperExplosion()
|| (Permissions.PREVENTDAMAGE_CREEPER.isAuthorized(user)
&& !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{
final DamageCause cause = event.getCause();
if (cause == DamageCause.CONTACT
&& (Permissions.PREVENTDAMAGE_CONTACT.isAuthorized(user)
&& !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{
event.setCancelled(true);
return;
}
if (cause == DamageCause.LAVA
&& (Permissions.PREVENTDAMAGE_LAVADAMAGE.isAuthorized(user)
&& !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{
event.setCancelled(true);
return;
}
if (cause == DamageCause.BLOCK_EXPLOSION
&& (Permissions.PREVENTDAMAGE_TNT.isAuthorized(user)
&& !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{
event.setCancelled(true);
return;
}
event.setCancelled(true);
return;
}
if (target instanceof Player && event instanceof EntityDamageByEntityEvent)
if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
&& (Permissions.PREVENTDAMAGE_FIREBALL.isAuthorized(user)
&& !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{
final EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent)event;
final Entity eAttack = edEvent.getDamager();
final Player attacker = eAttack instanceof Player ? (Player)eAttack : null;
// PVP Settings
if (target instanceof Player && eAttack instanceof Player
&& (!Permissions.PVP.isAuthorized(user) || !Permissions.PVP.isAuthorized(attacker)))
{
event.setCancelled(true);
return;
}
//Creeper explode prevention
if (eAttack instanceof Creeper && settings.getData().getPrevent().isCreeperExplosion()
|| (Permissions.PREVENTDAMAGE_CREEPER.isAuthorized(user)
&& !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{
event.setCancelled(true);
return;
}
if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
&& (Permissions.PREVENTDAMAGE_FIREBALL.isAuthorized(user)
&& !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{
event.setCancelled(true);
return;
}
if (eAttack instanceof TNTPrimed
&& (Permissions.PREVENTDAMAGE_TNT.isAuthorized(user)
&& !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{
event.setCancelled(true);
return;
}
if (edEvent.getDamager() instanceof Projectile
&& ((Permissions.PREVENTDAMAGE_PROJECTILES.isAuthorized(user)
&& !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user))
|| (((Projectile)edEvent.getDamager()).getShooter() instanceof Player
&& (!Permissions.PVP.isAuthorized(user)
|| !Permissions.PVP.isAuthorized((Player)((Projectile)edEvent.getDamager()).getShooter())))))
{
event.setCancelled(true);
return;
}
event.setCancelled(true);
return;
}
final DamageCause cause = event.getCause();
if (target instanceof Player)
if (eAttack instanceof TNTPrimed
&& (Permissions.PREVENTDAMAGE_TNT.isAuthorized(user)
&& !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{
if (cause == DamageCause.FALL
&& (Permissions.PREVENTDAMAGE_FALL.isAuthorized(user)
&& !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{
event.setCancelled(true);
return;
}
event.setCancelled(true);
return;
}
if (cause == DamageCause.SUFFOCATION
&& (Permissions.PREVENTDAMAGE_SUFFOCATION.isAuthorized(user)
&& !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{
event.setCancelled(true);
return;
}
if ((cause == DamageCause.FIRE
|| cause == DamageCause.FIRE_TICK)
&& (Permissions.PREVENTDAMAGE_FIRE.isAuthorized(user)
&& !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{
event.setCancelled(true);
return;
}
if (cause == DamageCause.DROWNING
&& (Permissions.PREVENTDAMAGE_DROWNING.isAuthorized(user)
&& !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{
event.setCancelled(true);
return;
}
if (cause == DamageCause.LIGHTNING
&& (Permissions.PREVENTDAMAGE_LIGHTNING.isAuthorized(user)
&& !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{
event.setCancelled(true);
}
if (edEvent.getDamager() instanceof Projectile
&& ((Permissions.PREVENTDAMAGE_PROJECTILES.isAuthorized(user)
&& !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user))
|| (((Projectile)edEvent.getDamager()).getShooter() instanceof Player
&& (!Permissions.PVP.isAuthorized(user)
|| !Permissions.PVP.isAuthorized((Player)((Projectile)edEvent.getDamager()).getShooter())))))
{
event.setCancelled(true);
return;
}
}
finally
final DamageCause cause = event.getCause();
if (target instanceof Player)
{
settings.unlock();
if (cause == DamageCause.FALL
&& (Permissions.PREVENTDAMAGE_FALL.isAuthorized(user)
&& !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{
event.setCancelled(true);
return;
}
if (cause == DamageCause.SUFFOCATION
&& (Permissions.PREVENTDAMAGE_SUFFOCATION.isAuthorized(user)
&& !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{
event.setCancelled(true);
return;
}
if ((cause == DamageCause.FIRE
|| cause == DamageCause.FIRE_TICK)
&& (Permissions.PREVENTDAMAGE_FIRE.isAuthorized(user)
&& !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{
event.setCancelled(true);
return;
}
if (cause == DamageCause.DROWNING
&& (Permissions.PREVENTDAMAGE_DROWNING.isAuthorized(user)
&& !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{
event.setCancelled(true);
return;
}
if (cause == DamageCause.LIGHTNING
&& (Permissions.PREVENTDAMAGE_LIGHTNING.isAuthorized(user)
&& !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{
event.setCancelled(true);
}
}
}
@@ -164,42 +156,34 @@ public class EssentialsProtectEntityListener implements Listener
public void onEntityExplode(final EntityExplodeEvent event)
{
final ProtectHolder settings = prot.getSettings();
settings.acquireReadLock();
try
{
final int maxHeight = settings.getData().getCreeperMaxHeight();
final int maxHeight = settings.getData().getCreeperMaxHeight();
if (event.getEntity() instanceof EnderDragon
&& settings.getData().getPrevent().isEnderdragonBlockdamage())
{
event.setCancelled(true);
return;
}
else if (event.getEntity() instanceof Creeper
&& (settings.getData().getPrevent().isCreeperExplosion()
|| settings.getData().getPrevent().isCreeperBlockdamage()
|| (maxHeight >= 0 && event.getLocation().getBlockY() > maxHeight)))
{
event.setCancelled(true);
event.getLocation().getWorld().createExplosion(event.getLocation(), 0F);
return;
}
else if (event.getEntity() instanceof TNTPrimed
&& settings.getData().getPrevent().isTntExplosion())
{
event.setCancelled(true);
return;
}
else if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
&& settings.getData().getPrevent().isFireballExplosion())
{
event.setCancelled(true);
return;
}
}
finally
if (event.getEntity() instanceof EnderDragon
&& settings.getData().getPrevent().isEnderdragonBlockdamage())
{
settings.unlock();
event.setCancelled(true);
return;
}
else if (event.getEntity() instanceof Creeper
&& (settings.getData().getPrevent().isCreeperExplosion()
|| settings.getData().getPrevent().isCreeperBlockdamage()
|| (maxHeight >= 0 && event.getLocation().getBlockY() > maxHeight)))
{
event.setCancelled(true);
event.getLocation().getWorld().createExplosion(event.getLocation(), 0F);
return;
}
else if (event.getEntity() instanceof TNTPrimed
&& settings.getData().getPrevent().isTntExplosion())
{
event.setCancelled(true);
return;
}
else if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
&& settings.getData().getPrevent().isFireballExplosion())
{
event.setCancelled(true);
return;
}
}
@@ -226,18 +210,10 @@ public class EssentialsProtectEntityListener implements Listener
public void onExplosionPrime(final ExplosionPrimeEvent event)
{
final ProtectHolder settings = prot.getSettings();
settings.acquireReadLock();
try
if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
&& settings.getData().getPrevent().isFireballFire())
{
if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
&& settings.getData().getPrevent().isFireballFire())
{
event.setFire(false);
}
}
finally
{
settings.unlock();
event.setFire(false);
}
}
@@ -245,17 +221,9 @@ public class EssentialsProtectEntityListener implements Listener
public void onEntityChangeBlock(final EntityChangeBlockEvent event)
{
final ProtectHolder settings = prot.getSettings();
settings.acquireReadLock();
try
if (event.getEntityType() == EntityType.ENDERMAN && settings.getData().getPrevent().isEndermanPickup())
{
if (event.getEntityType() == EntityType.ENDERMAN && settings.getData().getPrevent().isEndermanPickup())
{
event.setCancelled(true);
}
}
finally
{
settings.unlock();
event.setCancelled(true);
}
}
}

View File

@@ -21,19 +21,12 @@ public class EssentialsProtectWeatherListener implements Listener
public void onWeatherChange(final WeatherChangeEvent event)
{
final ProtectHolder settings = prot.getSettings();
settings.acquireReadLock();
try
if (!event.isCancelled()
&& settings.getData().isDisableStorm()
&& event.toWeatherState())
{
if (!event.isCancelled()
&& settings.getData().isDisableStorm()
&& event.toWeatherState())
{
event.setCancelled(true);
}
}
finally
{
settings.unlock();
event.setCancelled(true);
}
}
@@ -41,18 +34,11 @@ public class EssentialsProtectWeatherListener implements Listener
public void onLightningStrike(final LightningStrikeEvent event)
{
final ProtectHolder settings = prot.getSettings();
settings.acquireReadLock();
try
if (!event.isCancelled()
&& settings.getData().isDisableLighting())
{
if (!event.isCancelled()
&& settings.getData().isDisableLighting())
{
event.setCancelled(true);
}
}
finally
{
settings.unlock();
event.setCancelled(true);
}
}
@@ -60,19 +46,12 @@ public class EssentialsProtectWeatherListener implements Listener
public void onThunderChange(final ThunderChangeEvent event)
{
final ProtectHolder settings = prot.getSettings();
settings.acquireReadLock();
try
if (!event.isCancelled()
&& settings.getData().isDisableThunder()
&& event.toThunderState())
{
if (!event.isCancelled()
&& settings.getData().isDisableThunder()
&& event.toThunderState())
{
event.setCancelled(true);
}
}
finally
{
settings.unlock();
event.setCancelled(true);
}
}
}

View File

@@ -1,11 +1,10 @@
package net.ess3.signs;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.ess3.api.IEssentials;
import net.ess3.api.ISettings;
import net.ess3.api.IUser;
import net.ess3.utils.Util;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.ess3.permissions.Permissions;
import net.ess3.utils.FormatUtil;
import org.bukkit.Material;
@@ -36,7 +35,6 @@ public class SignBlockListener implements Listener
public void onBlockBreak(final BlockBreakEvent event)
{
ISettings settings = ess.getSettings();
settings.acquireReadLock();
if (plugin.getSettings().areSignsDisabled())
{
return;

View File

@@ -16,16 +16,7 @@ public class SignMail extends EssentialsSign
@Override
protected boolean onSignInteract(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException
{
final List<String> mail;
player.acquireReadLock();
try
{
mail = player.getData().getMails();
}
finally
{
player.unlock();
}
final List<String> mail = player.getData().getMails();
if (mail == null || mail.isEmpty())
{
player.sendMessage(_("noNewMail"));

View File

@@ -1,17 +1,19 @@
package net.ess3.signs;
import net.ess3.storage.StorageObject;
import java.util.HashMap;
import java.util.Collections;
import java.util.Map;
import net.ess3.storage.StorageObject;
public class SignsConfig implements StorageObject
{
private Map<String, Boolean> signs = new HashMap<String, Boolean>();
private Map<String, Boolean> signs;
public Map<String, Boolean> getSigns()
{
return signs;
return signs == null
? Collections.<String, Boolean>emptyMap()
: Collections.unmodifiableMap(signs);
}
public void setSigns(final Map<String, Boolean> signs)

View File

@@ -19,43 +19,29 @@ public class SignsConfigHolder extends AsyncStorageObjectHolder<SignsConfig>
super(ess, SignsConfig.class);
this.plugin = plugin;
onReload();
acquireReadLock();
try
final Map<String, Boolean> signs = getData().getSigns();
for (Map.Entry<String, Boolean> entry : signs.entrySet())
{
final Map<String, Boolean> signs = getData().getSigns();
for (Map.Entry<String, Boolean> entry : signs.entrySet())
if (entry.getKey().trim().toUpperCase(Locale.ENGLISH).equals("COLOR") || entry.getKey().trim().toUpperCase(Locale.ENGLISH).equals("COLOUR"))
{
if (entry.getKey().trim().toUpperCase(Locale.ENGLISH).equals("COLOR") || entry.getKey().trim().toUpperCase(Locale.ENGLISH).equals("COLOUR"))
{
signsEnabled = true;
continue;
}
final Signs sign = Signs.valueOf(entry.getKey().toUpperCase(Locale.ENGLISH));
if (sign != null && entry.getValue())
{
enabledSigns.add(sign.getSign());
signsEnabled = true;
}
signsEnabled = true;
continue;
}
final Signs sign = Signs.valueOf(entry.getKey().toUpperCase(Locale.ENGLISH));
if (sign != null && entry.getValue())
{
enabledSigns.add(sign.getSign());
signsEnabled = true;
}
}
finally
final Map<String, Boolean> signs2 = new HashMap<String, Boolean>();
for (Signs sign : Signs.values())
{
unlock();
}
acquireWriteLock();
try
{
final Map<String, Boolean> signs = new HashMap<String, Boolean>();
for (Signs sign : Signs.values())
{
signs.put(sign.toString(), enabledSigns.contains(sign.getSign()));
}
getData().setSigns(signs);
}
finally
{
unlock();
signs2.put(sign.toString(), enabledSigns.contains(sign.getSign()));
}
getData().setSigns(signs2);
queueSave();
}
@Override