diff options
author | snowleo <schneeleo@gmail.com> | 2011-12-06 17:28:48 +0100 |
---|---|---|
committer | snowleo <schneeleo@gmail.com> | 2011-12-06 17:28:48 +0100 |
commit | 72e187cd5c625fd709002bedfa860bdb0e2bd587 (patch) | |
tree | fa599929f4bd4541d4b08ae245d3efc89c2f03f5 | |
parent | 2851a4634cd8ea0c05dd2d2ed5d1d657dbdc11f4 (diff) | |
download | Essentials-72e187cd5c625fd709002bedfa860bdb0e2bd587.tar Essentials-72e187cd5c625fd709002bedfa860bdb0e2bd587.tar.gz Essentials-72e187cd5c625fd709002bedfa860bdb0e2bd587.tar.lz Essentials-72e187cd5c625fd709002bedfa860bdb0e2bd587.tar.xz Essentials-72e187cd5c625fd709002bedfa860bdb0e2bd587.zip |
Updated Jails to use the new config classes
19 files changed, 380 insertions, 207 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index 94b737338..376e0318c 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -19,6 +19,7 @@ package com.earth2me.essentials; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.Economy; +import com.earth2me.essentials.api.IJails; import com.earth2me.essentials.commands.EssentialsCommand; import com.earth2me.essentials.commands.IEssentialsCommand; import com.earth2me.essentials.commands.NoChargeException; @@ -65,7 +66,7 @@ public class Essentials extends JavaPlugin implements IEssentials private static final Logger LOGGER = Logger.getLogger("Minecraft"); private transient ISettings settings; private final transient TNTExplodeListener tntListener = new TNTExplodeListener(this); - private transient Jail jail; + private transient Jails jails; private transient Warps warps; private transient Worth worth; private transient List<IConf> confList; @@ -244,16 +245,8 @@ public class Essentials extends JavaPlugin implements IEssentials pm.registerEvent(Type.FOOD_LEVEL_CHANGE, entityListener, Priority.Lowest, this); //TODO: Check if this should be here, and not above before reload() - jail = new Jail(this); - final JailPlayerListener jailPlayerListener = new JailPlayerListener(this); - confList.add(jail); - pm.registerEvent(Type.BLOCK_BREAK, jail, Priority.Low, this); - pm.registerEvent(Type.BLOCK_DAMAGE, jail, Priority.Low, this); - pm.registerEvent(Type.BLOCK_PLACE, jail, Priority.Low, this); - pm.registerEvent(Type.PLAYER_INTERACT, jailPlayerListener, Priority.Low, this); - pm.registerEvent(Type.PLAYER_RESPAWN, jailPlayerListener, Priority.High, this); - pm.registerEvent(Type.PLAYER_TELEPORT, jailPlayerListener, Priority.High, this); - pm.registerEvent(Type.PLAYER_JOIN, jailPlayerListener, Priority.High, this); + jails = new Jails(this); + confList.add(jails); pm.registerEvent(Type.ENTITY_EXPLODE, tntListener, Priority.High, this); @@ -415,9 +408,9 @@ public class Essentials extends JavaPlugin implements IEssentials } @Override - public Jail getJail() + public IJails getJails() { - return jail; + return jails; } @Override diff --git a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java index 29658ae4d..dc2845414 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java @@ -729,6 +729,53 @@ public class EssentialsUpgrade doneFile.setProperty("updateSpawnsToNewSpawnsConfig", true); doneFile.save(); } + + private void updateJailsToNewJailsConfig() + { + if (doneFile.getBoolean("updateJailsToNewJailsConfig", false)) + { + return; + } + final File configFile = new File(ess.getDataFolder(), "jail.yml"); + if (configFile.exists()) + { + + final EssentialsConf config = new EssentialsConf(configFile); + try + { + config.load(); + if (!config.hasProperty("jails")) + { + final com.earth2me.essentials.settings.Jails jails = new com.earth2me.essentials.settings.Jails(); + List<String> keys = config.getKeys(); + for (String jailName : keys) + { + Location loc = getFakeLocation(config, jailName); + jails.getJails().put(jailName.toLowerCase(Locale.ENGLISH), loc); + } + if (!configFile.renameTo(new File(ess.getDataFolder(), "jail.yml.old"))) + { + throw new Exception(_("fileRenameError", "jail.yml")); + } + PrintWriter writer = new PrintWriter(configFile); + try + { + new YamlStorageWriter(writer).save(jails); + } + finally + { + writer.close(); + } + } + } + catch (Exception ex) + { + Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex); + } + } + doneFile.setProperty("updateJailsToNewJailsConfig", true); + doneFile.save(); + } public void beforeSettings() { @@ -751,5 +798,6 @@ public class EssentialsUpgrade updateUsersHomesFormat(); deleteOldItemsCsv(); updateSpawnsToNewSpawnsConfig(); + updateJailsToNewJailsConfig(); } } diff --git a/Essentials/src/com/earth2me/essentials/IEssentials.java b/Essentials/src/com/earth2me/essentials/IEssentials.java index be09b8e37..20c6c300e 100644 --- a/Essentials/src/com/earth2me/essentials/IEssentials.java +++ b/Essentials/src/com/earth2me/essentials/IEssentials.java @@ -1,5 +1,6 @@ package com.earth2me.essentials; +import com.earth2me.essentials.api.IJails; import com.earth2me.essentials.perm.PermissionsHandler; import com.earth2me.essentials.register.payment.Methods; import org.bukkit.World; @@ -34,7 +35,7 @@ public interface IEssentials extends Plugin BukkitScheduler getScheduler(); - Jail getJail(); + IJails getJails(); Warps getWarps(); diff --git a/Essentials/src/com/earth2me/essentials/IUser.java b/Essentials/src/com/earth2me/essentials/IUser.java index 52252786b..63081b4f9 100644 --- a/Essentials/src/com/earth2me/essentials/IUser.java +++ b/Essentials/src/com/earth2me/essentials/IUser.java @@ -5,6 +5,8 @@ import java.net.InetSocketAddress; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.inventory.PlayerInventory; + + /** * @deprecated This will be moved to the api package soon */ @@ -58,4 +60,8 @@ public interface IUser String getDisplayName(); boolean isHidden(); + + Teleport getTeleport(); + + void setJail(String jail); } diff --git a/Essentials/src/com/earth2me/essentials/Jail.java b/Essentials/src/com/earth2me/essentials/Jail.java deleted file mode 100644 index b573e4a13..000000000 --- a/Essentials/src/com/earth2me/essentials/Jail.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.earth2me.essentials; - -import static com.earth2me.essentials.I18n._; -import java.io.File; -import java.util.List; -import java.util.Locale; -import java.util.logging.Logger; -import org.bukkit.Location; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockDamageEvent; -import org.bukkit.event.block.BlockListener; -import org.bukkit.event.block.BlockPlaceEvent; - - -public class Jail extends BlockListener implements IConf -{ - private static final Logger logger = Logger.getLogger("Minecraft"); - private final EssentialsConf config; - private final IEssentials ess; - - public Jail(IEssentials ess) - { - this.ess = ess; - config = new EssentialsConf(new File(ess.getDataFolder(), "jail.yml")); - config.load(); - } - - public void setJail(Location loc, String jailName) throws Exception - { - config.setProperty(jailName.toLowerCase(Locale.ENGLISH), loc); - config.save(); - } - - public Location getJail(String jailName) throws Exception - { - if (jailName == null || config.getProperty(jailName.toLowerCase(Locale.ENGLISH)) == null) - { - throw new Exception(_("jailNotExist")); - } - - Location loc = config.getLocation(jailName.toLowerCase(Locale.ENGLISH), ess.getServer()); - return loc; - } - - public void sendToJail(User user, String jail) throws Exception - { - if (!(user.getBase() instanceof OfflinePlayer)) - { - user.getTeleport().now(getJail(jail), false); - } - user.setJail(jail); - } - - public void delJail(String jail) throws Exception - { - config.removeProperty(jail.toLowerCase(Locale.ENGLISH)); - config.save(); - } - - public List<String> getJails() throws Exception - { - return config.getKeys(null); - } - - @Override - public void reloadConfig() - { - config.load(); - } - - @Override - public void onBlockBreak(BlockBreakEvent event) - { - User user = ess.getUser(event.getPlayer()); - if (user.isJailed()) - { - event.setCancelled(true); - } - } - - @Override - public void onBlockPlace(BlockPlaceEvent event) - { - User user = ess.getUser(event.getPlayer()); - if (user.isJailed()) - { - event.setCancelled(true); - } - } - - @Override - public void onBlockDamage(BlockDamageEvent event) - { - User user = ess.getUser(event.getPlayer()); - if (user.isJailed()) - { - event.setCancelled(true); - } - } -} diff --git a/Essentials/src/com/earth2me/essentials/JailPlayerListener.java b/Essentials/src/com/earth2me/essentials/JailPlayerListener.java deleted file mode 100644 index ed632b1ad..000000000 --- a/Essentials/src/com/earth2me/essentials/JailPlayerListener.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.earth2me.essentials; - -import static com.earth2me.essentials.I18n._; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.bukkit.event.player.*; - - -public class JailPlayerListener extends PlayerListener -{ - private static final Logger LOGGER = Logger.getLogger("Minecraft"); - private final IEssentials ess; - - public JailPlayerListener(IEssentials parent) - { - this.ess = parent; - } - - @Override - public void onPlayerInteract(PlayerInteractEvent event) - { - final User user = ess.getUser(event.getPlayer()); - if (user.isJailed()) - { - event.setCancelled(true); - } - } - - @Override - public void onPlayerRespawn(PlayerRespawnEvent event) - { - final User user = ess.getUser(event.getPlayer()); - if (user.isJailed() && user.getJail() != null && !user.getJail().isEmpty()) - { - try - { - event.setRespawnLocation(ess.getJail().getJail(user.getJail())); - } - catch (Exception ex) - { - } - } - } - - @Override - public void onPlayerTeleport(PlayerTeleportEvent event) - { - final User user = ess.getUser(event.getPlayer()); - if (!user.isJailed() || user.getJail() == null || user.getJail().isEmpty()) - { - return; - } - try - { - event.setTo(ess.getJail().getJail(user.getJail())); - } - catch (Exception ex) - { - LOGGER.log(Level.WARNING, _("returnPlayerToJailError"), ex); - } - user.sendMessage(_("jailMessage")); - } - - @Override - public void onPlayerJoin(final PlayerJoinEvent event) - { - User u = ess.getUser(event.getPlayer()); - if (u.isJailed()) - { - try - { - ess.getJail().sendToJail(u, u.getJail()); - } - catch (Exception ex) - { - LOGGER.log(Level.WARNING, _("returnPlayerToJailError"), ex); - } - u.sendMessage(_("jailMessage")); - } - } -} diff --git a/Essentials/src/com/earth2me/essentials/Jails.java b/Essentials/src/com/earth2me/essentials/Jails.java new file mode 100644 index 000000000..2fbc57aa5 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/Jails.java @@ -0,0 +1,246 @@ +package com.earth2me.essentials; + +import com.earth2me.essentials.api.IJails; +import com.earth2me.essentials.storage.AsyncStorageObjectHolder; +import static com.earth2me.essentials.I18n._; +import java.io.File; +import java.util.*; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.event.Event.Priority; +import org.bukkit.event.Event.Type; +import org.bukkit.event.block.*; +import org.bukkit.event.player.*; +import org.bukkit.plugin.PluginManager; + + +public class Jails extends AsyncStorageObjectHolder<com.earth2me.essentials.settings.Jails> implements IJails +{ + private static final transient Logger LOGGER = Bukkit.getLogger(); + + public Jails(final IEssentials ess) + { + super(ess, com.earth2me.essentials.settings.Jails.class); + registerListeners(); + } + + private void registerListeners() + { + final PluginManager pluginManager = ess.getServer().getPluginManager(); + final JailBlockListener blockListener = new JailBlockListener(); + final JailPlayerListener playerListener = new JailPlayerListener(); + pluginManager.registerEvent(Type.BLOCK_BREAK, blockListener, Priority.Low, ess); + pluginManager.registerEvent(Type.BLOCK_DAMAGE, blockListener, Priority.Low, ess); + pluginManager.registerEvent(Type.BLOCK_PLACE, blockListener, Priority.Low, ess); + pluginManager.registerEvent(Type.PLAYER_INTERACT, playerListener, Priority.Low, ess); + pluginManager.registerEvent(Type.PLAYER_RESPAWN, playerListener, Priority.High, ess); + pluginManager.registerEvent(Type.PLAYER_TELEPORT, playerListener, Priority.High, ess); + pluginManager.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.High, ess); + } + + @Override + public File getStorageFile() + { + return new File(ess.getDataFolder(), "jail.yml"); + } + + @Override + public Location getJail(final String jailName) throws Exception + { + acquireReadLock(); + try + { + if (getData().getJails() == null || jailName == null + || !getData().getJails().containsKey(jailName.toLowerCase(Locale.ENGLISH))) + { + throw new Exception(_("jailNotExist")); + } + return getData().getJails().get(jailName.toLowerCase(Locale.ENGLISH)); + } + finally + { + unlock(); + } + } + + @Override + public Collection<String> getList() throws Exception + { + acquireReadLock(); + try + { + if (getData().getJails() == null) + { + return Collections.emptyList(); + } + return new ArrayList<String>(getData().getJails().keySet()); + } + finally + { + unlock(); + } + } + + @Override + public void removeJail(final String jail) throws Exception + { + acquireWriteLock(); + try + { + if (getData().getJails() == null) + { + return; + } + getData().getJails().remove(jail.toLowerCase(Locale.ENGLISH)); + } + finally + { + unlock(); + } + } + + @Override + public void sendToJail(final IUser user, final String jail) throws Exception + { + acquireReadLock(); + try + { + if (!(user.getBase() instanceof OfflinePlayer)) + { + user.getTeleport().now(getJail(jail), false); + } + user.setJail(jail); + } + finally + { + unlock(); + } + } + + @Override + public void setJail(final String jailName, final Location loc) throws Exception + { + acquireWriteLock(); + try + { + if (getData().getJails() == null) + { + getData().setJails(new HashMap<String, Location>()); + } + getData().getJails().put(jailName.toLowerCase(Locale.ENGLISH), loc); + } + finally + { + unlock(); + } + } + + + private class JailBlockListener extends BlockListener + { + @Override + public void onBlockBreak(final BlockBreakEvent event) + { + final User user = ess.getUser(event.getPlayer()); + if (user.isJailed()) + { + event.setCancelled(true); + } + } + + @Override + public void onBlockPlace(final BlockPlaceEvent event) + { + final User user = ess.getUser(event.getPlayer()); + if (user.isJailed()) + { + event.setCancelled(true); + } + } + + @Override + public void onBlockDamage(final BlockDamageEvent event) + { + final User user = ess.getUser(event.getPlayer()); + if (user.isJailed()) + { + event.setCancelled(true); + } + } + } + + + private class JailPlayerListener extends PlayerListener + { + @Override + public void onPlayerInteract(final PlayerInteractEvent event) + { + final User user = ess.getUser(event.getPlayer()); + if (user.isJailed()) + { + event.setCancelled(true); + } + } + + @Override + public void onPlayerRespawn(final PlayerRespawnEvent event) + { + final User user = ess.getUser(event.getPlayer()); + if (!user.isJailed() || user.getJail() == null || user.getJail().isEmpty()) + { + return; + } + + try + { + event.setRespawnLocation(getJail(user.getJail())); + } + catch (Exception ex) + { + LOGGER.log(Level.WARNING, _("returnPlayerToJailError"), ex); + } + } + + @Override + public void onPlayerTeleport(final PlayerTeleportEvent event) + { + final User user = ess.getUser(event.getPlayer()); + if (!user.isJailed() || user.getJail() == null || user.getJail().isEmpty()) + { + return; + } + + try + { + event.setTo(getJail(user.getJail())); + } + catch (Exception ex) + { + LOGGER.log(Level.WARNING, _("returnPlayerToJailError"), ex); + } + user.sendMessage(_("jailMessage")); + } + + @Override + public void onPlayerJoin(final PlayerJoinEvent event) + { + final User user = ess.getUser(event.getPlayer()); + if (!user.isJailed() || user.getJail() == null || user.getJail().isEmpty()) + { + return; + } + + try + { + sendToJail(user, user.getJail()); + } + catch (Exception ex) + { + LOGGER.log(Level.WARNING, _("returnPlayerToJailError"), ex); + } + user.sendMessage(_("jailMessage")); + } + } +} diff --git a/Essentials/src/com/earth2me/essentials/Teleport.java b/Essentials/src/com/earth2me/essentials/Teleport.java index 654232012..f82bdaac3 100644 --- a/Essentials/src/com/earth2me/essentials/Teleport.java +++ b/Essentials/src/com/earth2me/essentials/Teleport.java @@ -1,5 +1,6 @@ package com.earth2me.essentials; +import com.earth2me.essentials.api.ITeleport; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.commands.NotEnoughArgumentsException; import java.util.Calendar; @@ -11,7 +12,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerRespawnEvent; -public class Teleport implements Runnable +public class Teleport implements Runnable, ITeleport { private static final double MOVE_CONSTANT = 0.3; diff --git a/Essentials/src/com/earth2me/essentials/api/IEssentials.java b/Essentials/src/com/earth2me/essentials/api/IEssentials.java index 68c053a51..c04bed0bd 100644 --- a/Essentials/src/com/earth2me/essentials/api/IEssentials.java +++ b/Essentials/src/com/earth2me/essentials/api/IEssentials.java @@ -19,7 +19,7 @@ public interface IEssentials extends Plugin, IReload ISettings getSettings(); - IJail getJail(); + IJails getJail(); IWarps getWarps(); diff --git a/Essentials/src/com/earth2me/essentials/api/IJail.java b/Essentials/src/com/earth2me/essentials/api/IJails.java index 723117a3b..18866d8e5 100644 --- a/Essentials/src/com/earth2me/essentials/api/IJail.java +++ b/Essentials/src/com/earth2me/essentials/api/IJails.java @@ -4,15 +4,15 @@ import java.util.Collection; import org.bukkit.Location; -public interface IJail extends IReload +public interface IJails extends IReload { Location getJail(String jailName) throws Exception; - Collection<String> getJails() throws Exception; + Collection<String> getList() throws Exception; void removeJail(String jail) throws Exception; - void sendToJail(IUser user, String jail) throws Exception; + void sendToJail(com.earth2me.essentials.IUser user, String jail) throws Exception; void setJail(String jailName, Location loc) throws Exception; } diff --git a/Essentials/src/com/earth2me/essentials/api/ITeleport.java b/Essentials/src/com/earth2me/essentials/api/ITeleport.java new file mode 100644 index 000000000..9bcf4584e --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/api/ITeleport.java @@ -0,0 +1,9 @@ +package com.earth2me.essentials.api; + +import org.bukkit.Location; + + +public interface ITeleport +{ + void now(Location loc, boolean cooldown) throws Exception; +} diff --git a/Essentials/src/com/earth2me/essentials/api/IUser.java b/Essentials/src/com/earth2me/essentials/api/IUser.java index 0d0734ad9..5d2f9d4b8 100644 --- a/Essentials/src/com/earth2me/essentials/api/IUser.java +++ b/Essentials/src/com/earth2me/essentials/api/IUser.java @@ -36,4 +36,8 @@ public interface IUser extends Player, IReload Location getHome(Location loc) throws Exception; boolean isHidden(); + + ITeleport getTeleport(); + + void setJail(String jail); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanddeljail.java b/Essentials/src/com/earth2me/essentials/commands/Commanddeljail.java index 5b8e5d720..5c2c957e4 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanddeljail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanddeljail.java @@ -19,7 +19,7 @@ public class Commanddeljail extends EssentialsCommand { throw new NotEnoughArgumentsException(); } - ess.getJail().delJail(args[0]); + ess.getJails().removeJail(args[0]); sender.sendMessage(_("deleteJail", args[0])); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandjails.java b/Essentials/src/com/earth2me/essentials/commands/Commandjails.java index c5473e08d..051bcf710 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandjails.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandjails.java @@ -15,6 +15,6 @@ public class Commandjails extends EssentialsCommand @Override protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception { - sender.sendMessage("§7" + Util.joinList(" ", ess.getJail().getJails())); + sender.sendMessage("§7" + Util.joinList(" ", ess.getJails().getList())); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java b/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java index a4d6c4ba7..8ed298303 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java @@ -19,7 +19,7 @@ public class Commandsetjail extends EssentialsCommand { throw new NotEnoughArgumentsException(); } - ess.getJail().setJail(user.getLocation(), args[0]); + ess.getJails().setJail(args[0], user.getLocation()); user.sendMessage(_("jailSet", args[0])); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java b/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java index 323836ffb..f98343311 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java @@ -47,12 +47,12 @@ public class Commandtogglejail extends EssentialsCommand } if (!(player.getBase() instanceof OfflinePlayer)) { - ess.getJail().sendToJail(player, args[1]); + ess.getJails().sendToJail(player, args[1]); } else { // Check if jail exists - ess.getJail().getJail(args[1]); + ess.getJails().getJail(args[1]); } player.setJailed(true); player.sendMessage(_("userJailed")); diff --git a/Essentials/src/com/earth2me/essentials/settings/Jails.java b/Essentials/src/com/earth2me/essentials/settings/Jails.java new file mode 100644 index 000000000..4f9b79197 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/settings/Jails.java @@ -0,0 +1,18 @@ +package com.earth2me.essentials.settings; + +import com.earth2me.essentials.storage.MapValueType; +import com.earth2me.essentials.storage.StorageObject; +import java.util.HashMap; +import java.util.Map; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.bukkit.Location; + + +@Data +@EqualsAndHashCode(callSuper = false) +public class Jails implements StorageObject +{ + @MapValueType(Location.class) + private Map<String, Location> jails = new HashMap<String, Location>(); +} diff --git a/Essentials/src/com/earth2me/essentials/storage/AsyncStorageObjectHolder.java b/Essentials/src/com/earth2me/essentials/storage/AsyncStorageObjectHolder.java index bf3301e41..31c61a63f 100644 --- a/Essentials/src/com/earth2me/essentials/storage/AsyncStorageObjectHolder.java +++ b/Essentials/src/com/earth2me/essentials/storage/AsyncStorageObjectHolder.java @@ -2,13 +2,14 @@ package com.earth2me.essentials.storage; import com.earth2me.essentials.IConf; import com.earth2me.essentials.IEssentials; +import com.earth2me.essentials.api.IReload; import java.io.File; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.logging.Level; import org.bukkit.Bukkit; -public abstract class AsyncStorageObjectHolder<T extends StorageObject> implements IConf, IStorageObjectHolder<T> +public abstract class AsyncStorageObjectHolder<T extends StorageObject> implements IConf, IStorageObjectHolder<T>, IReload { private transient T data; private final transient ReentrantReadWriteLock rwl = new ReentrantReadWriteLock(); @@ -53,7 +54,7 @@ public abstract class AsyncStorageObjectHolder<T extends StorageObject> implemen { unlock(); } - + public void unlock() { if (rwl.isWriteLockedByCurrentThread()) @@ -73,6 +74,12 @@ public abstract class AsyncStorageObjectHolder<T extends StorageObject> implemen new StorageObjectDataReader(); } + @Override + public void onReload() + { + new StorageObjectDataReader(); + } + public abstract File getStorageFile(); diff --git a/Essentials/src/com/earth2me/essentials/user/User.java b/Essentials/src/com/earth2me/essentials/user/User.java index 89e664252..0e544ae06 100644 --- a/Essentials/src/com/earth2me/essentials/user/User.java +++ b/Essentials/src/com/earth2me/essentials/user/User.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.user; import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.IUser; +import com.earth2me.essentials.Teleport; import com.earth2me.essentials.commands.IEssentialsCommand; import lombok.Cleanup; import org.bukkit.Location; @@ -175,4 +176,24 @@ public class User extends UserBase implements IUser { throw new UnsupportedOperationException("Not supported yet."); } + + @Override + public Teleport getTeleport() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void setJail(final String jail) + { + acquireWriteLock(); + try + { + getData().setJail(jail); + } + finally + { + unlock(); + } + } } |