diff options
author | snowleo <schneeleo@gmail.com> | 2012-10-06 16:49:40 +0200 |
---|---|---|
committer | snowleo <schneeleo@gmail.com> | 2012-10-06 16:49:40 +0200 |
commit | fabd88dc2585bf6798658f34a7ee122225316fe8 (patch) | |
tree | cdda3fad01567f042d5afbaa189ac12ef94f2b7e /EssentialsSigns | |
parent | 463c4ff62db553fc980545665a332ef7bbecdcc6 (diff) | |
download | Essentials-fabd88dc2585bf6798658f34a7ee122225316fe8.tar Essentials-fabd88dc2585bf6798658f34a7ee122225316fe8.tar.gz Essentials-fabd88dc2585bf6798658f34a7ee122225316fe8.tar.lz Essentials-fabd88dc2585bf6798658f34a7ee122225316fe8.tar.xz Essentials-fabd88dc2585bf6798658f34a7ee122225316fe8.zip |
Less locks please
Diffstat (limited to 'EssentialsSigns')
4 files changed, 26 insertions, 49 deletions
diff --git a/EssentialsSigns/src/net/ess3/signs/SignBlockListener.java b/EssentialsSigns/src/net/ess3/signs/SignBlockListener.java index ba528006f..d5cf4ff14 100644 --- a/EssentialsSigns/src/net/ess3/signs/SignBlockListener.java +++ b/EssentialsSigns/src/net/ess3/signs/SignBlockListener.java @@ -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; diff --git a/EssentialsSigns/src/net/ess3/signs/SignMail.java b/EssentialsSigns/src/net/ess3/signs/SignMail.java index 6acf14bb1..5b1c810ac 100644 --- a/EssentialsSigns/src/net/ess3/signs/SignMail.java +++ b/EssentialsSigns/src/net/ess3/signs/SignMail.java @@ -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")); diff --git a/EssentialsSigns/src/net/ess3/signs/SignsConfig.java b/EssentialsSigns/src/net/ess3/signs/SignsConfig.java index 70b606962..2db26f9c0 100644 --- a/EssentialsSigns/src/net/ess3/signs/SignsConfig.java +++ b/EssentialsSigns/src/net/ess3/signs/SignsConfig.java @@ -1,19 +1,21 @@ 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) { this.signs = signs; diff --git a/EssentialsSigns/src/net/ess3/signs/SignsConfigHolder.java b/EssentialsSigns/src/net/ess3/signs/SignsConfigHolder.java index fce56906d..49cf15647 100644 --- a/EssentialsSigns/src/net/ess3/signs/SignsConfigHolder.java +++ b/EssentialsSigns/src/net/ess3/signs/SignsConfigHolder.java @@ -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; } - } - finally - { - unlock(); - } - acquireWriteLock(); - try - { - final Map<String, Boolean> signs = new HashMap<String, Boolean>(); - for (Signs sign : Signs.values()) + final Signs sign = Signs.valueOf(entry.getKey().toUpperCase(Locale.ENGLISH)); + if (sign != null && entry.getValue()) { - signs.put(sign.toString(), enabledSigns.contains(sign.getSign())); + enabledSigns.add(sign.getSign()); + signsEnabled = true; } - getData().setSigns(signs); } - finally + + final Map<String, Boolean> signs2 = new HashMap<String, Boolean>(); + for (Signs sign : Signs.values()) { - unlock(); + signs2.put(sign.toString(), enabledSigns.contains(sign.getSign())); } + getData().setSigns(signs2); + queueSave(); } @Override |