diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index 6ab74e16c..6c62ae213 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -18,17 +18,13 @@ package com.earth2me.essentials; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.api.Economy; -import com.earth2me.essentials.api.IEssentialsEconomy; -import com.earth2me.essentials.api.IGroups; -import com.earth2me.essentials.api.IJails; -import com.earth2me.essentials.api.IReload; -import com.earth2me.essentials.api.IWarps; +import com.earth2me.essentials.api.*; import com.earth2me.essentials.commands.EssentialsCommand; import com.earth2me.essentials.commands.IEssentialsCommand; import com.earth2me.essentials.commands.NoChargeException; import com.earth2me.essentials.commands.NotEnoughArgumentsException; import com.earth2me.essentials.craftbukkit.ItemDupeFix; +import com.earth2me.essentials.listener.*; import com.earth2me.essentials.perm.PermissionsHandler; import com.earth2me.essentials.register.payment.Methods; import com.earth2me.essentials.signs.SignBlockListener; @@ -40,7 +36,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; -import java.util.logging.LogRecord; import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/Essentials/src/com/earth2me/essentials/EssentialsConf.java b/Essentials/src/com/earth2me/essentials/EssentialsConf.java index 35252532f..3a37f04b0 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsConf.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsConf.java @@ -16,7 +16,7 @@ import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; import org.bukkit.util.config.Configuration; - +@Deprecated public class EssentialsConf extends Configuration { private static final Logger LOGGER = Logger.getLogger("Minecraft"); diff --git a/Essentials/src/com/earth2me/essentials/EssentialsTimer.java b/Essentials/src/com/earth2me/essentials/EssentialsTimer.java index f3b447dae..bc7aa9b26 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsTimer.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsTimer.java @@ -3,13 +3,16 @@ package com.earth2me.essentials; import java.util.HashSet; import java.util.Iterator; import java.util.Set; +import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.user.UserData.TimestampType; import org.bukkit.entity.Player; public class EssentialsTimer implements Runnable { private final transient IEssentials ess; - private final transient Set onlineUsers = new HashSet(); + private final transient Set onlineUsers = new HashSet(); EssentialsTimer(final IEssentials ess) { @@ -22,19 +25,19 @@ public class EssentialsTimer implements Runnable final long currentTime = System.currentTimeMillis(); for (Player player : ess.getServer().getOnlinePlayers()) { - final User user = ess.getUser(player); + final IUser user = ess.getUser(player); onlineUsers.add(user); user.setLastOnlineActivity(currentTime); user.checkActivity(); } - final Iterator iterator = onlineUsers.iterator(); + final Iterator iterator = onlineUsers.iterator(); while (iterator.hasNext()) { - final User user = iterator.next(); - if (user.getLastOnlineActivity() < currentTime && user.getLastOnlineActivity() > user.getLastLogout()) + final IUser user = iterator.next(); + if (user.getLastOnlineActivity() < currentTime && user.getLastOnlineActivity() > user.getTimestamp(TimestampType.LOGOUT)) { - user.setLastLogout(user.getLastOnlineActivity()); + user.setTimestamp(TimestampType.LOGOUT, user.getLastOnlineActivity()); iterator.remove(); continue; } diff --git a/Essentials/src/com/earth2me/essentials/ItemDb.java b/Essentials/src/com/earth2me/essentials/ItemDb.java index e3df50bab..1ea45697d 100644 --- a/Essentials/src/com/earth2me/essentials/ItemDb.java +++ b/Essentials/src/com/earth2me/essentials/ItemDb.java @@ -1,6 +1,7 @@ package com.earth2me.essentials; import com.earth2me.essentials.api.IItemDb; +import com.earth2me.essentials.api.IEssentials; import static com.earth2me.essentials.I18n._; import java.util.HashMap; import java.util.List; @@ -24,7 +25,7 @@ public class ItemDb implements IConf, IItemDb private final transient ManagedFile file; @Override - public void reloadConfig() + public void onReload() { final List lines = file.getLines(); @@ -119,4 +120,10 @@ public class ItemDb implements IConf, IItemDb retval.setDurability(metaData); return retval; } + + @Override + public void reloadConfig() + { + onReload(); + } } diff --git a/Essentials/src/com/earth2me/essentials/Jails.java b/Essentials/src/com/earth2me/essentials/Jails.java index 2101dfdf6..6a756ea7d 100644 --- a/Essentials/src/com/earth2me/essentials/Jails.java +++ b/Essentials/src/com/earth2me/essentials/Jails.java @@ -1,12 +1,15 @@ package com.earth2me.essentials; import com.earth2me.essentials.api.IJails; +import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.IUser; 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 lombok.Cleanup; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.event.Event.Priority; @@ -37,9 +40,9 @@ public class Jails extends AsyncStorageObjectHolder els) throws NoChargeException + public static void checkTime(final IUser user, final String kitName, final Map els) throws NoChargeException { final double delay = els.containsKey("delay") ? ((Number)els.get("delay")).doubleValue() : 0L; final Calendar c = new GregorianCalendar(); @@ -59,7 +61,7 @@ public class Kit } } - public static List getItems(final User user, final Map els) throws Exception + public static List getItems(final IUser user, final Map els) throws Exception { try { @@ -72,7 +74,7 @@ public class Kit } } - public static void expandItems(final IEssentials ess, final User user, final List items) throws Exception + public static void expandItems(final IEssentials ess, final IUser user, final List items) throws Exception { try { diff --git a/Essentials/src/com/earth2me/essentials/ManagedFile.java b/Essentials/src/com/earth2me/essentials/ManagedFile.java index a1918fa20..0a2443f29 100644 --- a/Essentials/src/com/earth2me/essentials/ManagedFile.java +++ b/Essentials/src/com/earth2me/essentials/ManagedFile.java @@ -1,6 +1,7 @@ package com.earth2me.essentials; import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.api.IEssentials; import java.io.*; import java.math.BigInteger; import java.security.DigestInputStream; diff --git a/Essentials/src/com/earth2me/essentials/Teleport.java b/Essentials/src/com/earth2me/essentials/Teleport.java index bb33db62a..63adef052 100644 --- a/Essentials/src/com/earth2me/essentials/Teleport.java +++ b/Essentials/src/com/earth2me/essentials/Teleport.java @@ -2,6 +2,8 @@ package com.earth2me.essentials; import com.earth2me.essentials.api.ITeleport; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.ISettings; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.commands.NotEnoughArgumentsException; import com.earth2me.essentials.user.CooldownException; @@ -9,6 +11,7 @@ import com.earth2me.essentials.user.UserData.TimestampType; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.logging.Logger; +import lombok.Cleanup; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -115,7 +118,7 @@ public class Teleport implements Runnable, ITeleport } catch (Throwable ex) { - ess.showError(user.getBase(), ex, "teleport"); + ess.showCommandError(user.getBase(), "teleport", ex); } } catch (Exception ex) @@ -142,7 +145,7 @@ public class Teleport implements Runnable, ITeleport public void warp(String warp, Trade chargeFor, TeleportCause cause) throws Exception { - Location loc = ess.getWarps().getWarp(warp); + final Location loc = ess.getWarps2().getWarp(warp); teleport(new Target(loc), chargeFor, cause); user.sendMessage(_("warpingTo", warp)); } @@ -202,7 +205,7 @@ public class Teleport implements Runnable, ITeleport private void teleport(Target target, Trade chargeFor, TeleportCause cause) throws Exception { - double delay = ess.getSettings().getTeleportDelay(); + double delay = ess.getGroups().getTeleportDelay(user); if (chargeFor != null) { diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java index 06407b41e..981750942 100644 --- a/Essentials/src/com/earth2me/essentials/Util.java +++ b/Essentials/src/com/earth2me/essentials/Util.java @@ -1,12 +1,15 @@ package com.earth2me.essentials; import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.ISettings; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.*; import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; +import lombok.Cleanup; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -427,7 +430,10 @@ public class Util public static String formatCurrency(final double value, final IEssentials ess) { - String str = ess.getSettings().getCurrencySymbol() + df.format(value); + @Cleanup + final ISettings settings = ess.getSettings(); + settings.acquireReadLock(); + String str = settings.getData().getEconomy().getCurrencySymbol() + df.format(value); if (str.endsWith(".00")) { str = str.substring(0, str.length() - 3); diff --git a/Essentials/src/com/earth2me/essentials/api/IAlternativeCommandsHandler.java b/Essentials/src/com/earth2me/essentials/api/IAlternativeCommandsHandler.java index 11619bca4..f28174753 100644 --- a/Essentials/src/com/earth2me/essentials/api/IAlternativeCommandsHandler.java +++ b/Essentials/src/com/earth2me/essentials/api/IAlternativeCommandsHandler.java @@ -2,9 +2,14 @@ package com.earth2me.essentials.api; import java.util.Map; import org.bukkit.command.PluginCommand; +import org.bukkit.plugin.Plugin; public interface IAlternativeCommandsHandler { Map disabledCommands(); + + public void removePlugin(Plugin plugin); + + public void addPlugin(Plugin plugin); } diff --git a/Essentials/src/com/earth2me/essentials/api/IEssentials.java b/Essentials/src/com/earth2me/essentials/api/IEssentials.java index 5431a0bd8..efb4a4e3c 100644 --- a/Essentials/src/com/earth2me/essentials/api/IEssentials.java +++ b/Essentials/src/com/earth2me/essentials/api/IEssentials.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.api; +import com.earth2me.essentials.listener.TNTExplodeListener; import com.earth2me.essentials.perm.IPermissionsHandler; import com.earth2me.essentials.register.payment.Methods; import org.bukkit.World; @@ -18,7 +19,7 @@ public interface IEssentials extends Plugin, IReload II18n getI18n(); ISettings getSettings(); - + IGroups getGroups(); IJails getJails(); @@ -30,7 +31,7 @@ public interface IEssentials extends Plugin, IReload IItemDb getItemDb(); IUserMap getUserMap(); - + IBackup getBackup(); IEssentialsEconomy getEconomy(); @@ -52,4 +53,10 @@ public interface IEssentials extends Plugin, IReload IAlternativeCommandsHandler getAlternativeCommandsHandler(); void showCommandError(CommandSender sender, String commandLabel, Throwable exception); + + public void reload(); + + public IUser getOfflineUser(String string); + + public TNTExplodeListener getTNTListener(); } diff --git a/Essentials/src/com/earth2me/essentials/api/IGroups.java b/Essentials/src/com/earth2me/essentials/api/IGroups.java index 1e1b229a4..f11bb7cc6 100644 --- a/Essentials/src/com/earth2me/essentials/api/IGroups.java +++ b/Essentials/src/com/earth2me/essentials/api/IGroups.java @@ -7,10 +7,12 @@ import com.earth2me.essentials.storage.IStorageObjectHolder; public interface IGroups extends IStorageObjectHolder { double getHealCooldown(IUser player); - + double getTeleportCooldown(IUser player); + double getTeleportDelay(final IUser player); + String getPrefix(IUser player); - + String getSuffix(IUser player); } diff --git a/Essentials/src/com/earth2me/essentials/api/IItemDb.java b/Essentials/src/com/earth2me/essentials/api/IItemDb.java index ee4819215..b37d9e1a2 100644 --- a/Essentials/src/com/earth2me/essentials/api/IItemDb.java +++ b/Essentials/src/com/earth2me/essentials/api/IItemDb.java @@ -3,7 +3,7 @@ package com.earth2me.essentials.api; import org.bukkit.inventory.ItemStack; -public interface IItemDb +public interface IItemDb extends IReload { ItemStack get(final String name, final int quantity) throws Exception; diff --git a/Essentials/src/com/earth2me/essentials/api/IJails.java b/Essentials/src/com/earth2me/essentials/api/IJails.java index 18866d8e5..caa1ee0a8 100644 --- a/Essentials/src/com/earth2me/essentials/api/IJails.java +++ b/Essentials/src/com/earth2me/essentials/api/IJails.java @@ -12,7 +12,7 @@ public interface IJails extends IReload void removeJail(String jail) throws Exception; - void sendToJail(com.earth2me.essentials.IUser user, String jail) throws Exception; + void sendToJail(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 index 2f2bd9a5e..bcb018355 100644 --- a/Essentials/src/com/earth2me/essentials/api/ITeleport.java +++ b/Essentials/src/com/earth2me/essentials/api/ITeleport.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.api; import com.earth2me.essentials.Trade; import org.bukkit.Location; +import org.bukkit.entity.Entity; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -9,5 +10,19 @@ public interface ITeleport { void now(Location loc, boolean cooldown, TeleportCause cause) throws Exception; + void now(Entity entity, boolean cooldown, TeleportCause cause) throws Exception; + void back(Trade chargeFor) throws Exception; + + void teleport(Location bed, Trade charge, TeleportCause teleportCause) throws Exception; + + void teleport(Entity entity, Trade chargeFor, TeleportCause cause) throws Exception; + + void home(IUser player, String toLowerCase, Trade charge) throws Exception; + + void respawn(Trade charge, TeleportCause teleportCause) throws Exception; + + void back() throws Exception; + + public void warp(String name, Trade charge, TeleportCause teleportCause) throws Exception; } diff --git a/Essentials/src/com/earth2me/essentials/api/IUser.java b/Essentials/src/com/earth2me/essentials/api/IUser.java index 497303ca9..f4437d160 100644 --- a/Essentials/src/com/earth2me/essentials/api/IUser.java +++ b/Essentials/src/com/earth2me/essentials/api/IUser.java @@ -4,11 +4,13 @@ import com.earth2me.essentials.commands.IEssentialsCommand; import com.earth2me.essentials.storage.IStorageObjectHolder; import com.earth2me.essentials.user.CooldownException; import com.earth2me.essentials.user.UserData; +import java.util.List; import org.bukkit.Location; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -public interface IUser extends Player, IStorageObjectHolder, IReload, IReplyTo +public interface IUser extends Player, IStorageObjectHolder, IReload, IReplyTo, Comparable { boolean isAuthorized(String node); @@ -22,8 +24,16 @@ public interface IUser extends Player, IStorageObjectHolder, IReload, void takeMoney(double value); + void takeMoney(double value, CommandSender initiator); + void giveMoney(double value); + void giveMoney(double value, CommandSender initiator); + + void setMoney(double value); + + void payUser(final IUser reciever, final double value) throws Exception; + String getGroup(); void setLastLocation(); @@ -39,16 +49,54 @@ public interface IUser extends Player, IStorageObjectHolder, IReload, void checkCooldown(UserData.TimestampType cooldownType, double cooldown, boolean set, String bypassPermission) throws CooldownException; boolean toggleAfk(); - + void updateActivity(boolean broadcast); - + void updateDisplayName(); - - boolean checkJailTimeout(final long currentTime); - - boolean checkMuteTimeout(final long currentTime); - - boolean checkBanTimeout(final long currentTime); - - void setTimestamp(final UserData.TimestampType name, final long value); + + boolean checkJailTimeout(long currentTime); + + boolean checkMuteTimeout(long currentTime); + + boolean checkBanTimeout(long currentTime); + + long getTimestamp(UserData.TimestampType name); + + void setTimestamp(UserData.TimestampType name, long value); + + void setLastOnlineActivity(long currentTime); + + void checkActivity(); + + long getLastOnlineActivity(); + + boolean isGodModeEnabled(); + + boolean isIgnoringPlayer(String name); + + void setIgnoredPlayer(String name, boolean set); + + Location getAfkPosition(); + + boolean toggleGodModeEnabled(); + + void dispose(); + + void updateCompass(); + + List getHomes(); + + void addMail(String string); + + boolean toggleMuted(); + + public boolean toggleSocialSpy(); + + public void requestTeleport(IUser user, boolean b); + + public boolean isTeleportRequestHere(); + + public IUser getTeleportRequester(); + + public boolean toggleTeleportEnabled(); } diff --git a/Essentials/src/com/earth2me/essentials/api/IWarps.java b/Essentials/src/com/earth2me/essentials/api/IWarps.java index 14779e327..4e0dd5a47 100644 --- a/Essentials/src/com/earth2me/essentials/api/IWarps.java +++ b/Essentials/src/com/earth2me/essentials/api/IWarps.java @@ -8,9 +8,11 @@ public interface IWarps extends IReload { Location getWarp(String warp) throws Exception; - Collection getWarps(); + Collection getList(); void removeWarp(String name) throws Exception; void setWarp(String name, Location loc) throws Exception; + + public boolean isEmpty(); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java b/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java index 32c8c9e80..d1869e5b9 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.Backup; +import com.earth2me.essentials.api.IBackup; import static com.earth2me.essentials.I18n._; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -16,11 +16,7 @@ public class Commandbackup extends EssentialsCommand @Override protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception { - final Backup backup = ess.getBackup(); - if (backup == null) - { - throw new Exception(); - } + final IBackup backup = ess.getBackup(); backup.run(); sender.sendMessage(_("backupStarted")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java b/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java index 58f164ad6..f04b0b136 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java @@ -1,8 +1,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; import com.earth2me.essentials.Util; +import com.earth2me.essentials.api.IUser; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -25,7 +25,7 @@ public class Commandbalance extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { final double bal = (args.length < 1 || !(user.isAuthorized("essentials.balance.others") diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java index 5f73f84c2..87bce6b06 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Util; import com.earth2me.essentials.textreader.ArrayListInput; @@ -109,7 +109,7 @@ public class Commandbalancetop extends EssentialsCommand final Map balances = new HashMap(); for (String u : ess.getUserMap().getAllUniqueUsers()) { - final User user = ess.getUserMap().getUser(u); + final IUser user = ess.getUserMap().getUser(u); if (user != null) { balances.put(u, user.getMoney()); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandban.java b/Essentials/src/com/earth2me/essentials/commands/Commandban.java index d39419686..4c28391ee 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandban.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandban.java @@ -3,7 +3,9 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.OfflinePlayer; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.user.Ban; +import lombok.Cleanup; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -23,7 +25,8 @@ public class Commandban extends EssentialsCommand { throw new NotEnoughArgumentsException(); } - final User user = getPlayer(server, args, 0, true); + @Cleanup + final IUser user = getPlayer(server, args, 0, true); if (user.getBase() instanceof OfflinePlayer) { if (sender instanceof Player @@ -42,11 +45,13 @@ public class Commandban extends EssentialsCommand } } + user.acquireWriteLock(); String banReason; + user.getData().setBan(new Ban()); if (args.length > 1) { banReason = getFinalArg(args, 1); - user.setBanReason(banReason); + user.getData().getBan().setReason(banReason); } else { @@ -58,7 +63,7 @@ public class Commandban extends EssentialsCommand for (Player onlinePlayer : server.getOnlinePlayers()) { - final User player = ess.getUser(onlinePlayer); + final IUser player = ess.getUser(onlinePlayer); if (player.isAuthorized("essentials.ban.notify")) { onlinePlayer.sendMessage(_("playerBanned", senderName, user.getName(), banReason)); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java b/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java index 5459bd8fc..f067888f6 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java @@ -1,7 +1,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; +import lombok.Cleanup; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -21,7 +22,9 @@ public class Commandbanip extends EssentialsCommand throw new NotEnoughArgumentsException(); } - final User player = ess.getUser(args[0]); + @Cleanup + final IUser player = ess.getUser(args[0]); + player.acquireReadLock(); if (player == null) { @@ -30,12 +33,12 @@ public class Commandbanip extends EssentialsCommand } else { - final String ipAddress = player.getLastLoginAddress(); + final String ipAddress = player.getData().getIpAddress(); if (ipAddress.length() == 0) { throw new Exception(_("playerNotFound")); } - ess.getServer().banIP(player.getLastLoginAddress()); + ess.getServer().banIP(player.getData().getIpAddress()); sender.sendMessage(_("banIpAddress")); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java b/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java index 78d557934..e1e486344 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.Util; import org.bukkit.Location; import org.bukkit.Server; @@ -16,7 +16,7 @@ public class Commandbigtree extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { TreeType tree; if (args.length > 0 && args[0].equalsIgnoreCase("redwood")) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbreak.java b/Essentials/src/com/earth2me/essentials/commands/Commandbreak.java index a1db8e0b2..04b26cc71 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbreak.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbreak.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Material; import org.bukkit.Server; import org.bukkit.block.Block; @@ -16,7 +16,7 @@ public class Commandbreak extends EssentialsCommand //TODO: Switch to use util class @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { final Block block = user.getTargetBlock(null, 20); if (block == null) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java index ef2502b9b..94d83f250 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import java.util.List; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -17,7 +17,7 @@ public class Commandclearinventory extends EssentialsCommand //TODO: Cleanup @Override - public void run(Server server, User user, String commandLabel, String[] args) throws Exception + public void run(Server server, IUser user, String commandLabel, String[] args) throws Exception { if (args.length > 0 && user.isAuthorized("essentials.clearinventory.others")) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandcompass.java b/Essentials/src/com/earth2me/essentials/commands/Commandcompass.java index 25f8c34f6..3bb08967b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandcompass.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandcompass.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Server; @@ -13,7 +13,7 @@ public class Commandcompass extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { final int bearing = (int)(user.getLocation().getYaw() + 180 + 360) % 360; String dir; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java b/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java index ce891985e..1ea8f07ad 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java @@ -1,8 +1,9 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import java.util.Locale; +import lombok.Cleanup; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -22,7 +23,8 @@ public class Commanddelhome extends EssentialsCommand throw new NotEnoughArgumentsException(); } - User user = ess.getUser(sender); + @Cleanup + IUser user = ess.getUser(sender); String name; final String[] expandedArg = args[0].split(":"); @@ -45,7 +47,8 @@ public class Commanddelhome extends EssentialsCommand * throw new Exception("You cannot remove the vanilla home point"); * } */ - user.delHome(name.toLowerCase(Locale.ENGLISH)); + user.acquireWriteLock(); + user.getData().removeHome(name.toLowerCase(Locale.ENGLISH)); sender.sendMessage(_("deleteHome", name)); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java index 5eab72b33..bd60c2cd2 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java @@ -19,7 +19,7 @@ public class Commanddelwarp extends EssentialsCommand { throw new NotEnoughArgumentsException(); } - ess.getWarps().delWarp(args[0]); + ess.getWarps2().removeWarp(args[0]); sender.sendMessage(_("deleteWarp", args[0])); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanddepth.java b/Essentials/src/com/earth2me/essentials/commands/Commanddepth.java index 6c4fa2647..0124e0bc7 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanddepth.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanddepth.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Server; @@ -13,7 +13,7 @@ public class Commanddepth extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { final int depth = user.getLocation().getBlockY() - 63; if (depth > 0) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandeco.java b/Essentials/src/com/earth2me/essentials/commands/Commandeco.java index 8f432ca6e..46f8f6eba 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandeco.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandeco.java @@ -1,7 +1,9 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.ISettings; +import com.earth2me.essentials.api.IUser; import java.util.Locale; +import lombok.Cleanup; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -37,7 +39,7 @@ public class Commandeco extends EssentialsCommand { for (Player onlinePlayer : server.getOnlinePlayers()) { - final User player = ess.getUser(onlinePlayer); + final IUser player = ess.getUser(onlinePlayer); switch (cmd) { case GIVE: @@ -49,14 +51,16 @@ public class Commandeco extends EssentialsCommand break; case RESET: - player.setMoney(amount == 0 ? ess.getSettings().getStartingBalance() : amount); + @Cleanup ISettings settings = ess.getSettings(); + settings.acquireReadLock(); + player.setMoney(amount == 0 ? settings.getData().getEconomy().getStartingBalance() : amount); break; } } } else { - final User player = getPlayer(server, args, 1, true); + final IUser player = getPlayer(server, args, 1, true); switch (cmd) { case GIVE: @@ -68,7 +72,9 @@ public class Commandeco extends EssentialsCommand break; case RESET: - player.setMoney(amount == 0 ? ess.getSettings().getStartingBalance() : amount); + @Cleanup ISettings settings = ess.getSettings(); + settings.acquireReadLock(); + player.setMoney(amount == 0 ? settings.getData().getEconomy().getStartingBalance() : amount); break; } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java b/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java index 51a909d29..ae816141b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java @@ -2,7 +2,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.Enchantments; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.Util; import java.util.*; import org.bukkit.Server; @@ -19,7 +19,7 @@ public class Commandenchant extends EssentialsCommand //TODO: Implement charge costs: final Trade charge = new Trade("enchant-" + enchantmentName, ess); @Override - protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { final ItemStack stack = user.getItemInHand(); if (stack == null) @@ -78,7 +78,7 @@ public class Commandenchant extends EssentialsCommand } } - public static Enchantment getEnchantment(final String name, final User user) throws Exception + public static Enchantment getEnchantment(final String name, final IUser user) throws Exception { final Enchantment enchantment = Enchantments.getByName(name); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java index 14bbf5e02..5837d3268 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java @@ -1,9 +1,10 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.api.ISettings; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.Util; import java.util.HashMap; import java.util.Map; +import lombok.Cleanup; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Server; @@ -58,8 +59,11 @@ public class Commandessentials extends EssentialsCommand private void run_debug(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception { - ess.getSettings().setDebug(!ess.getSettings().isDebug()); - sender.sendMessage("Essentials " + ess.getDescription().getVersion() + " debug mode " + (ess.getSettings().isDebug() ? "enabled" : "disabled")); + @Cleanup + ISettings settings = ess.getSettings(); + settings.acquireWriteLock(); + settings.getData().getGeneral().setDebug(!settings.getData().getGeneral().isDebug()); + sender.sendMessage("Essentials " + ess.getDescription().getVersion() + " debug mode " + (settings.getData().getGeneral().isDebug() ? "enabled" : "disabled")); } private void run_reload(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception @@ -149,7 +153,7 @@ public class Commandessentials extends EssentialsCommand private void stopTune() { - ess.getScheduler().cancelTask(taskid); + ess.getServer().getScheduler().cancelTask(taskid); for (Block block : noteBlocks.values()) { if (block.getType() == Material.NOTE_BLOCK) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandext.java b/Essentials/src/com/earth2me/essentials/commands/Commandext.java index 3855e7b68..dac1a3e9c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandext.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandext.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -26,7 +26,7 @@ public class Commandext extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java b/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java index 0c1579835..7ab6b7ca9 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import java.util.List; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -16,11 +16,11 @@ public class Commandfeed extends EssentialsCommand } @Override - protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length > 0 && user.isAuthorized("essentials.feed.others")) { - feedOtherPlayers(server,user,args[0]); + feedOtherPlayers(server, user, args[0]); } else { @@ -29,8 +29,8 @@ public class Commandfeed extends EssentialsCommand user.sendMessage(_("feed")); } } - - private void feedOtherPlayers(final Server server, final CommandSender sender, final String name) + + private void feedOtherPlayers(final Server server, final CommandSender sender, final String name) { final List players = server.matchPlayer(name); if (players.isEmpty()) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandfireball.java b/Essentials/src/com/earth2me/essentials/commands/Commandfireball.java index 671d0f72b..868924a27 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandfireball.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandfireball.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Server; import org.bukkit.entity.Fireball; import org.bukkit.entity.SmallFireball; @@ -15,7 +15,7 @@ public class Commandfireball extends EssentialsCommand } @Override - protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { boolean small = false; if (args.length > 0 && args[0].equalsIgnoreCase("small")) @@ -23,7 +23,7 @@ public class Commandfireball extends EssentialsCommand small = true; } final Vector direction = user.getEyeLocation().getDirection().multiply(2); - Fireball fireball = user.getWorld().spawn(user.getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), small ? SmallFireball.class : Fireball.class); + final Fireball fireball = user.getWorld().spawn(user.getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), small ? SmallFireball.class : Fireball.class); fireball.setShooter(user.getBase()); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java b/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java index 62ace9357..396e3bef2 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import java.util.Locale; import org.bukkit.GameMode; import org.bukkit.Server; @@ -28,7 +28,7 @@ public class Commandgamemode extends EssentialsCommand } @Override - protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length > 0 && !args[0].trim().isEmpty() && user.isAuthorized("essentials.gamemode.others")) { @@ -44,7 +44,7 @@ public class Commandgamemode extends EssentialsCommand { for (Player matchPlayer : server.matchPlayer(name)) { - final User player = ess.getUser(matchPlayer); + final IUser player = ess.getUser(matchPlayer); if (player.isHidden()) { continue; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java b/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java index c61702e59..c7f54c593 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -14,11 +14,11 @@ public class Commandgetpos extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length > 0 && user.isAuthorized("essentials.getpos.others")) { - final User otherUser = getPlayer(server, args, 0); + final IUser otherUser = getPlayer(server, args, 0); outputPosition(user, otherUser.getLocation(), user.getLocation()); } else @@ -34,7 +34,7 @@ public class Commandgetpos extends EssentialsCommand { throw new NotEnoughArgumentsException(); } - final User user = getPlayer(server, args, 0); + final IUser user = getPlayer(server, args, 0); outputPosition(sender, user.getLocation(), null); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java index d6e3d8f98..645ae04d8 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.craftbukkit.InventoryWorkaround; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import java.util.Locale; import org.bukkit.ChatColor; import org.bukkit.Material; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgod.java b/Essentials/src/com/earth2me/essentials/commands/Commandgod.java index 4d5bd424b..0a1ca4dd0 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgod.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgod.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -26,7 +26,7 @@ public class Commandgod extends EssentialsCommand } @Override - protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length > 0 && !args[0].trim().isEmpty() && user.isAuthorized("essentials.god.others")) { @@ -41,7 +41,7 @@ public class Commandgod extends EssentialsCommand { for (Player matchPlayer : server.matchPlayer(name)) { - final User player = ess.getUser(matchPlayer); + final IUser player = ess.getUser(matchPlayer); if (player.isHidden()) { continue; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandheal.java b/Essentials/src/com/earth2me/essentials/commands/Commandheal.java index 02b8ed30c..26e644331 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandheal.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandheal.java @@ -1,7 +1,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.user.UserData.TimestampType; import java.util.List; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -16,23 +17,19 @@ public class Commandheal extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { - + if (args.length > 0 && user.isAuthorized("essentials.heal.others")) { - if (!user.isAuthorized("essentials.heal.cooldown.bypass")) - { - user.healCooldown(); - } + user.checkCooldown(TimestampType.LASTHEAL, ess.getGroups().getHealCooldown(user), true, "essentials.heal.cooldown.bypass"); + healOtherPlayers(server, user, args[0]); return; } - if (!user.isAuthorized("essentials.heal.cooldown.bypass")) - { - user.healCooldown(); - } + user.checkCooldown(TimestampType.LASTHEAL, ess.getGroups().getHealCooldown(user), true, "essentials.heal.cooldown.bypass"); + user.setHealth(20); user.setFoodLevel(20); user.sendMessage(_("heal")); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java b/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java index 328f692ea..03acac872 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.Util; import com.earth2me.essentials.textreader.*; import org.bukkit.Server; @@ -16,7 +16,7 @@ public class Commandhelp extends EssentialsCommand } @Override - protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { IText output; String pageStr = args.length > 0 ? args[0] : null; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java b/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java index f558a1b52..bd383d1ce 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import java.util.logging.Level; import org.bukkit.Server; import org.bukkit.entity.Player; @@ -15,7 +15,7 @@ public class Commandhelpop extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -26,7 +26,7 @@ public class Commandhelpop extends EssentialsCommand logger.log(Level.INFO, message); for (Player onlinePlayer : server.getOnlinePlayers()) { - final User player = ess.getUser(onlinePlayer); + final IUser player = ess.getUser(onlinePlayer); if (!player.isAuthorized("essentials.helpop.receive")) { continue; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java index d1db6c523..e1197a946 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java @@ -2,10 +2,11 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.Util; import java.util.List; import java.util.Locale; +import lombok.Cleanup; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -19,11 +20,11 @@ public class Commandhome extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { final Trade charge = new Trade(this.getName(), ess); charge.isAffordableFor(user); - User player = user; + IUser player = user; String homeName = ""; String[] nameParts; if (args.length > 0) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandignore.java b/Essentials/src/com/earth2me/essentials/commands/Commandignore.java index 93dd029a8..6fb17d3dc 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandignore.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandignore.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Server; @@ -13,13 +13,13 @@ public class Commandignore extends EssentialsCommand } @Override - protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { throw new NotEnoughArgumentsException(); } - User player; + IUser player; try { player = getPlayer(server, args, 0); @@ -33,7 +33,8 @@ public class Commandignore extends EssentialsCommand throw new Exception(_("playerNotFound")); } final String name = player.getName(); - if (user.isIgnoredPlayer(name)) + user.acquireWriteLock(); + if (user.isIgnoringPlayer(name)) { user.setIgnoredPlayer(name, false); user.sendMessage(_("unignorePlayer", player.getName())); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java b/Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java index 1f5c32faa..c2f5b7464 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java @@ -1,7 +1,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.user.Inventory; import java.util.Arrays; import org.bukkit.Server; import org.bukkit.inventory.ItemStack; @@ -15,29 +16,29 @@ public class Commandinvsee extends EssentialsCommand } @Override - protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { - if (args.length < 1 && user.getSavedInventory() == null) + if (args.length < 1 && user.getData().getInventory() == null) { throw new NotEnoughArgumentsException(); } - User invUser = user; + IUser invUser = user; if (args.length == 1) { invUser = getPlayer(server, args, 0); } - if (invUser == user && user.getSavedInventory() != null) + user.acquireWriteLock(); + if (invUser == user && user.getData().getInventory() != null) { - invUser.getInventory().setContents(user.getSavedInventory()); - user.setSavedInventory(null); + invUser.getInventory().setContents(user.getData().getInventory().getBukkitInventory()); + user.getData().setInventory(null); user.sendMessage(_("invRestored")); throw new NoChargeException(); } - - if (user.getSavedInventory() == null) + if (user.getData().getInventory() == null) { - user.setSavedInventory(user.getInventory().getContents()); + user.getData().setInventory(new Inventory(user.getInventory().getContents())); } ItemStack[] invUserStack = invUser.getInventory().getContents(); final int userStackLength = user.getInventory().getContents().length; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandjump.java b/Essentials/src/com/earth2me/essentials/commands/Commandjump.java index 39ca305e3..cee2134de 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandjump.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandjump.java @@ -2,7 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.Util; import org.bukkit.Location; import org.bukkit.Server; @@ -17,7 +17,7 @@ public class Commandjump extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { Location loc; final Location cloc = user.getLocation(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java index ae5db48fb..5a1a83cf6 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java @@ -2,7 +2,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -23,7 +23,7 @@ public class Commandkick extends EssentialsCommand throw new NotEnoughArgumentsException(); } - final User user = getPlayer(server, args, 0); + final IUser user = getPlayer(server, args, 0); if (user.isAuthorized("essentials.kick.exempt")) { throw new Exception(_("kickExempt")); @@ -34,7 +34,7 @@ public class Commandkick extends EssentialsCommand for (Player onlinePlayer : server.getOnlinePlayers()) { - User player = ess.getUser(onlinePlayer); + final IUser player = ess.getUser(onlinePlayer); if (player.isAuthorized("essentials.kick.notify")) { onlinePlayer.sendMessage(_("playerKicked", senderName, user.getName(), kickReason)); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java index c003d28ac..4d764394b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.*; +import com.earth2me.essentials.api.IUser; import static com.earth2me.essentials.I18n._; import java.util.*; import org.bukkit.Server; @@ -14,7 +15,7 @@ public class Commandkit extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java b/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java index be9ac61f5..73ab6db4e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java @@ -1,7 +1,9 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.api.ISettings; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; +import lombok.Cleanup; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.LightningStrike; @@ -19,7 +21,7 @@ public class Commandlightning extends EssentialsCommand public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception { - User user = null; + IUser user = null; if (sender instanceof Player) { user = ess.getUser(((Player)sender)); @@ -63,7 +65,10 @@ public class Commandlightning extends EssentialsCommand { matchPlayer.setHealth(matchPlayer.getHealth() < 5 ? 0 : matchPlayer.getHealth() - 5); } - if (ess.getSettings().warnOnSmite()) + @Cleanup + final ISettings settings = ess.getSettings(); + settings.acquireReadLock(); + if (settings.getData().getCommands().getLightning().isWarnPlayer()) { matchPlayer.sendMessage(_("lightningSmited")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java index 92833a66c..8c0c3723d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import java.util.*; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -43,26 +43,28 @@ public class Commandlist extends EssentialsCommand if (showhidden && playerHidden > 0) { online = _("listAmountHidden", server.getOnlinePlayers().length - playerHidden, playerHidden, server.getMaxPlayers()); - } else { - online = _("listAmount",server.getOnlinePlayers().length - playerHidden, server.getMaxPlayers()); + } + else + { + online = _("listAmount", server.getOnlinePlayers().length - playerHidden, server.getMaxPlayers()); } sender.sendMessage(online); if (ess.getSettings().getSortListByGroups()) { - Map> sort = new HashMap>(); + Map> sort = new HashMap>(); for (Player OnlinePlayer : server.getOnlinePlayers()) { - final User player = ess.getUser(OnlinePlayer); + final IUser player = ess.getUser(OnlinePlayer); if (player.isHidden() && !showhidden) { continue; } final String group = player.getGroup(); - List list = sort.get(group); + List list = sort.get(group); if (list == null) { - list = new ArrayList(); + list = new ArrayList(); sort.put(group, list); } list.add(player); @@ -73,10 +75,10 @@ public class Commandlist extends EssentialsCommand { final StringBuilder groupString = new StringBuilder(); groupString.append(group).append(": "); - final List users = sort.get(group); + final List users = sort.get(group); Collections.sort(users); boolean first = true; - for (User user : users) + for (IUser user : users) { if (!first) { @@ -86,9 +88,17 @@ public class Commandlist extends EssentialsCommand { first = false; } - if (user.isAfk()) + user.acquireReadLock(); + try { - groupString.append(_("listAfkTag")); + if (user.getData().isAfk()) + { + groupString.append(_("listAfkTag")); + } + } + finally + { + user.unlock(); } if (user.isHidden()) { @@ -102,10 +112,10 @@ public class Commandlist extends EssentialsCommand } else { - final List users = new ArrayList(); + final List users = new ArrayList(); for (Player OnlinePlayer : server.getOnlinePlayers()) { - final User player = ess.getUser(OnlinePlayer); + final IUser player = ess.getUser(OnlinePlayer); if (player.isHidden() && !showhidden) { continue; @@ -117,7 +127,7 @@ public class Commandlist extends EssentialsCommand final StringBuilder onlineUsers = new StringBuilder(); onlineUsers.append(_("connectedPlayers")); boolean first = true; - for (User user : users) + for (IUser user : users) { if (!first) { @@ -127,9 +137,17 @@ public class Commandlist extends EssentialsCommand { first = false; } - if (user.isAfk()) + user.acquireReadLock(); + try { - onlineUsers.append(_("listAfkTag")); + if (user.getData().isAfk()) + { + onlineUsers.append(_("listAfkTag")); + } + } + finally + { + user.unlock(); } if (user.isHidden()) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java index 6a66186e7..ed09ab706 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java @@ -1,9 +1,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import java.util.List; -import org.bukkit.ChatColor; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -18,12 +17,12 @@ public class Commandmail extends EssentialsCommand //TODO: Tidy this up @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length >= 1 && "read".equalsIgnoreCase(args[0])) { - final List mail = user.getMails(); - if (mail.isEmpty()) + final List mail = user.getData().getMails(); + if (mail == null || mail.isEmpty()) { user.sendMessage(_("noMail")); throw new NoChargeException(); @@ -43,7 +42,7 @@ public class Commandmail extends EssentialsCommand } Player player = server.getPlayer(args[1]); - User u; + IUser u; if (player != null) { u = ess.getUser(player); @@ -56,7 +55,7 @@ public class Commandmail extends EssentialsCommand { throw new Exception(_("playerNeverOnServer", args[1])); } - if (!u.isIgnoredPlayer(user.getName())) + if (!u.isIgnoringPlayer(user.getName())) { u.addMail(user.getName() + ": " + getFinalArg(args, 2)); } @@ -75,7 +74,8 @@ public class Commandmail extends EssentialsCommand } if (args.length >= 1 && "clear".equalsIgnoreCase(args[0])) { - user.setMails(null); + user.acquireWriteLock(); + user.getData().setMails(null); user.sendMessage(_("mailCleared")); return; } @@ -96,7 +96,7 @@ public class Commandmail extends EssentialsCommand else if (args.length >= 3 && "send".equalsIgnoreCase(args[0])) { Player player = server.getPlayer(args[1]); - User u; + IUser u; if (player != null) { u = ess.getUser(player); @@ -121,7 +121,7 @@ public class Commandmail extends EssentialsCommand { //allow sending from console without "send" argument, since it's the only thing the console can do Player player = server.getPlayer(args[0]); - User u; + IUser u; if (player != null) { u = ess.getUser(player); @@ -156,7 +156,7 @@ public class Commandmail extends EssentialsCommand { for (String username : ess.getUserMap().getAllUniqueUsers()) { - User user = ess.getUserMap().getUser(username); + IUser user = ess.getUserMap().getUser(username); if (user != null) { user.addMail(message); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandme.java b/Essentials/src/com/earth2me/essentials/commands/Commandme.java index 7ae87251d..2226bedef 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandme.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandme.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Server; @@ -13,9 +13,9 @@ public class Commandme extends EssentialsCommand } @Override - public void run(Server server, User user, String commandLabel, String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { - if (user.isMuted()) + if (user.getData().isMuted()) { throw new Exception(_("voiceSilenced")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmore.java b/Essentials/src/com/earth2me/essentials/commands/Commandmore.java index 3fce3110c..3ceb2168e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmore.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmore.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import java.util.Locale; import org.bukkit.Server; import org.bukkit.inventory.ItemStack; @@ -15,7 +15,7 @@ public class Commandmore extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { final ItemStack stack = user.getItemInHand(); if (stack == null) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java b/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java index 34754ec9c..7f545737d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java @@ -2,9 +2,10 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.IReplyTo; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IReplyTo; +import com.earth2me.essentials.api.IUser; import java.util.List; +import lombok.Cleanup; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -18,7 +19,7 @@ public class Commandmsg extends EssentialsCommand } @Override - public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception + public void run(final Server server, final CommandSender sender, final String commandLabel, String[] args) throws Exception { if (args.length < 2 || args[0].trim().isEmpty() || args[1].trim().isEmpty()) { @@ -27,8 +28,10 @@ public class Commandmsg extends EssentialsCommand if (sender instanceof Player) { - User user = ess.getUser(sender); - if (user.isMuted()) + @Cleanup + IUser user = ess.getUser(sender); + user.acquireReadLock(); + if (user.getData().isMuted()) { throw new Exception(_("voiceSilenced")); } @@ -60,7 +63,7 @@ public class Commandmsg extends EssentialsCommand int i = 0; for (Player p : matches) { - final User u = ess.getUser(p); + final IUser u = ess.getUser(p); if (u.isHidden()) { i++; @@ -74,8 +77,8 @@ public class Commandmsg extends EssentialsCommand for (Player p : matches) { sender.sendMessage(_("msgFormat", translatedMe, p.getDisplayName(), message)); - final User u = ess.getUser(p); - if (sender instanceof Player && (u.isIgnoredPlayer(((Player)sender).getName()) || u.isHidden())) + final IUser u = ess.getUser(p); + if (sender instanceof Player && (u.isIgnoringPlayer(((Player)sender).getName()) || u.isHidden())) { continue; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java index 3e70cc507..a3dcf3ce1 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java @@ -1,8 +1,10 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.Util; +import com.earth2me.essentials.user.UserData.TimestampType; +import lombok.Cleanup; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -22,8 +24,10 @@ public class Commandmute extends EssentialsCommand throw new NotEnoughArgumentsException(); } - final User player = getPlayer(server, args, 0, true); - if (!player.isMuted() && player.isAuthorized("essentials.mute.exempt")) + @Cleanup + final IUser player = getPlayer(server, args, 0, true); + player.acquireReadLock(); + if (!player.getData().isMuted() && player.isAuthorized("essentials.mute.exempt")) { throw new Exception(_("muteExempt")); } @@ -33,7 +37,7 @@ public class Commandmute extends EssentialsCommand String time = getFinalArg(args, 1); muteTimestamp = Util.parseDateDiff(time, true); } - player.setMuteTimeout(muteTimestamp); + player.setTimestamp(TimestampType.MUTE, muteTimestamp); final boolean muted = player.toggleMuted(); sender.sendMessage( muted diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnear.java b/Essentials/src/com/earth2me/essentials/commands/Commandnear.java index 0afcf1650..e667bb376 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandnear.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandnear.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.World; @@ -17,10 +17,10 @@ public class Commandnear extends EssentialsCommand } @Override - protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { long radius = 200; - User otherUser = null; + IUser otherUser = null; if (args.length > 0) { @@ -63,7 +63,7 @@ public class Commandnear extends EssentialsCommand protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception { - User otherUser = null; + IUser otherUser = null; if (args.length > 0) { otherUser = getPlayer(server, args, 0); @@ -86,7 +86,7 @@ public class Commandnear extends EssentialsCommand sender.sendMessage(_("nearbyPlayers", getLocal(server, otherUser, radius))); } - private String getLocal(final Server server, final User user, final long radius) + private String getLocal(final Server server, final IUser user, final long radius) { final Location loc = user.getLocation(); final World world = loc.getWorld(); @@ -95,7 +95,7 @@ public class Commandnear extends EssentialsCommand for (Player onlinePlayer : server.getOnlinePlayers()) { - final User player = ess.getUser(onlinePlayer); + final IUser player = ess.getUser(onlinePlayer); if (!player.equals(user) && !player.isHidden()) { final Location playerLoc = player.getLocation(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java index 95ad5ea84..178f20ea8 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java @@ -1,8 +1,10 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.api.ISettings; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import java.util.Locale; +import lombok.Cleanup; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -16,13 +18,16 @@ public class Commandnick extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { throw new NotEnoughArgumentsException(); } - if (!ess.getSettings().changeDisplayName()) + @Cleanup + final ISettings settings = ess.getSettings(); + settings.acquireReadLock(); + if (!settings.getData().getChat().getChangeDisplayname()) { throw new Exception(_("nickDisplayName")); } @@ -46,7 +51,10 @@ public class Commandnick extends EssentialsCommand { throw new NotEnoughArgumentsException(); } - if (!ess.getSettings().changeDisplayName()) + @Cleanup + final ISettings settings = ess.getSettings(); + settings.acquireReadLock(); + if (!settings.getData().getChat().getChangeDisplayname()) { throw new Exception(_("nickDisplayName")); } @@ -61,7 +69,7 @@ public class Commandnick extends EssentialsCommand sender.sendMessage(_("nickChanged")); } - private String formatNickname(final User user, final String nick) + private String formatNickname(final IUser user, final String nick) { if (user == null || user.isAuthorized("essentials.nick.color")) { @@ -84,7 +92,7 @@ public class Commandnick extends EssentialsCommand } } - private void setNickname(final Server server, final User target, final String nick) throws Exception + private void setNickname(final Server server, final IUser target, final String nick) throws Exception { if (nick.matches("[^a-zA-Z_0-9]")) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpay.java b/Essentials/src/com/earth2me/essentials/commands/Commandpay.java index 53927e012..a0e96522c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpay.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpay.java @@ -2,7 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Server; import org.bukkit.entity.Player; @@ -15,7 +15,7 @@ public class Commandpay extends EssentialsCommand } @Override - public void run(Server server, User user, String commandLabel, String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { @@ -27,7 +27,7 @@ public class Commandpay extends EssentialsCommand Boolean foundUser = false; for (Player p : server.matchPlayer(args[0])) { - User u = ess.getUser(p); + IUser u = ess.getUser(p); if (u.isHidden()) { continue; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandping.java b/Essentials/src/com/earth2me/essentials/commands/Commandping.java index 1fad701b2..758852ed6 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandping.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandping.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Server; @@ -13,7 +13,7 @@ public class Commandping extends EssentialsCommand } @Override - public void run(Server server, User player, String commandLabel, String[] args) throws Exception + public void run(final Server server, final IUser player, final String commandLabel, final String[] args) throws Exception { player.sendMessage(_("pong")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java index ca03364b2..64844fa5f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.Util; import java.util.ArrayList; import java.util.List; @@ -19,7 +19,7 @@ public class Commandpowertool extends EssentialsCommand } @Override - protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { String command = getFinalArg(args, 0); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpowertooltoggle.java b/Essentials/src/com/earth2me/essentials/commands/Commandpowertooltoggle.java index c8b737dfa..65eab2409 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpowertooltoggle.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpowertooltoggle.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Server; @@ -13,7 +13,7 @@ public class Commandpowertooltoggle extends EssentialsCommand } @Override - protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (!user.hasPowerTools()) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandptime.java b/Essentials/src/com/earth2me/essentials/commands/Commandptime.java index b16cbdc34..fd80e0ba7 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandptime.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandptime.java @@ -2,7 +2,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.DescParseTickFormat; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import java.util.*; import org.bukkit.Server; import org.bukkit.World; @@ -36,7 +36,7 @@ public class Commandptime extends EssentialsCommand { userSelector = args[1]; } - Set users = getUsers(server, sender, userSelector); + Set users = getUsers(server, sender, userSelector); // If no arguments we are reading the time if (args.length == 0) @@ -45,7 +45,7 @@ public class Commandptime extends EssentialsCommand return; } - User user = ess.getUser(sender); + IUser user = ess.getUser(sender); if ((!users.contains(user) || users.size() > 1) && user != null && !user.isAuthorized("essentials.ptime.others")) { user.sendMessage(_("pTimeOthersPermission")); @@ -89,14 +89,14 @@ public class Commandptime extends EssentialsCommand /** * Used to get the time and inform */ - private void getUsersTime(final CommandSender sender, final Collection users) + private void getUsersTime(final CommandSender sender, final Collection users) { if (users.size() > 1) { sender.sendMessage(_("pTimePlayers")); } - for (User user : users) + for (IUser user : users) { if (user.getPlayerTimeOffset() == 0) { @@ -120,13 +120,13 @@ public class Commandptime extends EssentialsCommand /** * Used to set the time and inform of the change */ - private void setUsersTime(final CommandSender sender, final Collection users, final Long ticks, Boolean relative) + private void setUsersTime(final CommandSender sender, final Collection users, final Long ticks, Boolean relative) { // Update the time if (ticks == null) { // Reset - for (User user : users) + for (IUser user : users) { user.resetPlayerTime(); } @@ -134,7 +134,7 @@ public class Commandptime extends EssentialsCommand else { // Set - for (User user : users) + for (IUser user : users) { final World world = user.getWorld(); long time = user.getPlayerTime(); @@ -149,7 +149,7 @@ public class Commandptime extends EssentialsCommand } final StringBuilder msg = new StringBuilder(); - for (User user : users) + for (IUser user : users) { if (msg.length() > 0) { @@ -181,13 +181,13 @@ public class Commandptime extends EssentialsCommand /** * Used to parse an argument of the type "users(s) selector" */ - private Set getUsers(final Server server, final CommandSender sender, final String selector) throws Exception + private Set getUsers(final Server server, final CommandSender sender, final String selector) throws Exception { - final Set users = new TreeSet(new UserNameComparator()); + final Set users = new TreeSet(); // If there is no selector we want the sender itself. Or all users if sender isn't a user. if (selector == null) { - final User user = ess.getUser(sender); + final IUser user = ess.getUser(sender); if (user == null) { for (Player player : server.getOnlinePlayers()) @@ -203,7 +203,7 @@ public class Commandptime extends EssentialsCommand } // Try to find the user with name = selector - User user = null; + IUser user = null; final List matchedPlayers = server.matchPlayer(selector); if (!matchedPlayers.isEmpty()) { @@ -231,13 +231,3 @@ public class Commandptime extends EssentialsCommand return users; } } - - -class UserNameComparator implements Comparator -{ - @Override - public int compare(User a, User b) - { - return a.getName().compareTo(b.getName()); - } -} diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandr.java b/Essentials/src/com/earth2me/essentials/commands/Commandr.java index 1da198444..474e96eb1 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandr.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandr.java @@ -2,8 +2,8 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.IReplyTo; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IReplyTo; +import com.earth2me.essentials.api.IUser; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -38,8 +38,8 @@ public class Commandr extends EssentialsCommand sender.sendMessage(_("msgFormat", _("me"), targetName, message)); if (target instanceof Player) { - User player = ess.getUser(target); - if (player.isIgnoredPlayer(sender instanceof Player ? ((Player)sender).getName() : Console.NAME)) + IUser player = ess.getUser(target); + if (player.isIgnoringPlayer(sender instanceof Player ? ((Player)sender).getName() : Console.NAME)) { return; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java index b48ac5bcb..61566c215 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.Util; import java.util.Locale; import org.bukkit.Server; @@ -26,7 +26,7 @@ public class Commandrealname extends EssentialsCommand final String whois = args[0].toLowerCase(Locale.ENGLISH); for (Player onlinePlayer : server.getOnlinePlayers()) { - final User u = ess.getUser(onlinePlayer); + final IUser u = ess.getUser(onlinePlayer); if (u.isHidden()) { continue; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandremove.java b/Essentials/src/com/earth2me/essentials/commands/Commandremove.java index d245d1239..28c8da441 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandremove.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandremove.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import java.util.Locale; import org.bukkit.Chunk; import org.bukkit.Server; @@ -29,7 +29,7 @@ public class Commandremove extends EssentialsCommand } @Override - protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java b/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java index cf9e43f9f..45209dfa8 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.*; +import com.earth2me.essentials.api.IUser; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -18,7 +19,7 @@ public class Commandrepair extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandseen.java b/Essentials/src/com/earth2me/essentials/commands/Commandseen.java index cf500e094..570abe4e0 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandseen.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandseen.java @@ -1,8 +1,9 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.Util; +import com.earth2me.essentials.user.UserData.TimestampType; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -23,17 +24,17 @@ public class Commandseen extends EssentialsCommand } try { - User u = getPlayer(server, args, 0); - sender.sendMessage(_("seenOnline", u.getDisplayName(), Util.formatDateDiff(u.getLastLogin()))); + IUser u = getPlayer(server, args, 0); + sender.sendMessage(_("seenOnline", u.getDisplayName(), Util.formatDateDiff(u.getTimestamp(TimestampType.LOGIN)))); } catch (NoSuchFieldException e) { - User u = ess.getOfflineUser(args[0]); + IUser u = ess.getOfflineUser(args[0]); if (u == null) { throw new Exception(_("playerNotFound")); } - sender.sendMessage(_("seenOffline", u.getDisplayName(), Util.formatDateDiff(u.getLastLogout()))); + sender.sendMessage(_("seenOffline", u.getDisplayName(), Util.formatDateDiff(u.getTimestamp(TimestampType.LOGOUT)))); if (u.isBanned()) { sender.sendMessage(_("whoisBanned", _("true"))); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java index d59c09b1e..12c43fbcf 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java @@ -3,7 +3,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.craftbukkit.InventoryWorkaround; import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.Util; import java.util.Locale; import java.util.logging.Level; @@ -20,7 +20,7 @@ public class Commandsell extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -74,7 +74,7 @@ public class Commandsell extends EssentialsCommand sellItem(user, is, args, false); } - private void sellItem(User user, ItemStack is, String[] args, boolean isBulkSell) throws Exception + private void sellItem(IUser user, ItemStack is, String[] args, boolean isBulkSell) throws Exception { if (is == null || is.getType() == Material.AIR) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java b/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java index e7687fcfd..74680a012 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import java.util.Locale; import org.bukkit.Server; @@ -14,7 +14,7 @@ public class Commandsethome extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, String[] args) throws Exception { if (args.length > 0) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java b/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java index 8ed298303..efef540b9 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Server; @@ -13,7 +13,7 @@ public class Commandsetjail extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java index bf5c11abe..10c974b9e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Location; import org.bukkit.Server; @@ -14,7 +14,7 @@ public class Commandsetwarp extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -22,7 +22,7 @@ public class Commandsetwarp extends EssentialsCommand } final Location loc = user.getLocation(); - ess.getWarps().setWarp(args[0], loc); + ess.getWarps2().setWarp(args[0], loc); user.sendMessage(_("warpSet", args[0])); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java b/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java index 1d236b70a..0a689755a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Server; import org.bukkit.inventory.ItemStack; @@ -14,7 +14,7 @@ public class Commandsetworth extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsocialspy.java b/Essentials/src/com/earth2me/essentials/commands/Commandsocialspy.java index 6080642a1..495393290 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsocialspy.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsocialspy.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Server; @@ -13,7 +13,7 @@ public class Commandsocialspy extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { user.sendMessage("§7SocialSpy " + (user.toggleSocialSpy() ? _("enabled") : _("disabled"))); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java index 73c86eba4..5c264c084 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java @@ -2,7 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Mob; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.Util; import java.util.Locale; import org.bukkit.Location; @@ -19,7 +19,7 @@ public class Commandspawner extends EssentialsCommand } @Override - protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length < 1 || args[0].length() < 2) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java index f867a1503..ba6255765 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java @@ -3,7 +3,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Mob; import com.earth2me.essentials.Mob.MobException; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.Util; import java.util.Locale; import java.util.Random; @@ -22,7 +22,7 @@ public class Commandspawnmob extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -76,7 +76,7 @@ public class Commandspawnmob extends EssentialsCommand { throw new Exception(_("unableToSpawnMob")); } - User otherUser = null; + IUser otherUser = null; if (args.length >= 3) { otherUser = getPlayer(ess.getServer(), args, 2); @@ -184,7 +184,7 @@ public class Commandspawnmob extends EssentialsCommand } } - private void changeMobData(final CreatureType type, final Entity spawned, final String data, final User user) throws Exception + private void changeMobData(final CreatureType type, final Entity spawned, final String data, final IUser user) throws Exception { if (type == CreatureType.SLIME || type == CreatureType.MAGMA_CUBE) { @@ -238,7 +238,7 @@ public class Commandspawnmob extends EssentialsCommand { final Wolf wolf = ((Wolf)spawned); wolf.setTamed(true); - wolf.setOwner(user); + wolf.setOwner(user.getBase()); wolf.setSitting(true); if (data.equalsIgnoreCase("tamedbaby")) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsudo.java b/Essentials/src/com/earth2me/essentials/commands/Commandsudo.java index 7f758ad2e..d73fdf13e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsudo.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsudo.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.command.PluginCommand; @@ -21,7 +21,7 @@ public class Commandsudo extends EssentialsCommand throw new NotEnoughArgumentsException(); } - final User user = getPlayer(server, args, 0, false); + final IUser user = getPlayer(server, args, 0, false); final String command = args[1]; final String[] arguments = new String[args.length - 2]; if (arguments.length > 0) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java b/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java index aa2ed5567..25c77856e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Server; @@ -13,7 +13,7 @@ public class Commandsuicide extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { user.setHealth(0); user.sendMessage(_("suicideMessage")); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java b/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java index 144d19d15..15d1a6d76 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java @@ -3,8 +3,9 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.OfflinePlayer; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.Util; +import com.earth2me.essentials.user.Ban; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -24,7 +25,7 @@ public class Commandtempban extends EssentialsCommand { throw new NotEnoughArgumentsException(); } - final User user = getPlayer(server, args, 0, true); + final IUser user = getPlayer(server, args, 0, true); if (user.getBase() instanceof OfflinePlayer) { if (sender instanceof Player @@ -46,15 +47,17 @@ public class Commandtempban extends EssentialsCommand final long banTimestamp = Util.parseDateDiff(time, true); final String banReason = _("tempBanned", Util.formatDateDiff(banTimestamp)); - user.setBanReason(banReason); - user.setBanTimeout(banTimestamp); + user.acquireWriteLock(); + user.getData().setBan(new Ban()); + user.getData().getBan().setReason(banReason); + user.getData().getBan().setTimeout(banTimestamp); user.setBanned(true); user.kickPlayer(banReason); final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME; for (Player onlinePlayer : server.getOnlinePlayers()) { - final User player = ess.getUser(onlinePlayer); + final IUser player = ess.getUser(onlinePlayer); if (player.isAuthorized("essentials.ban.notify")) { onlinePlayer.sendMessage(_("playerBanned", senderName, user.getName(), banReason)); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandthunder.java b/Essentials/src/com/earth2me/essentials/commands/Commandthunder.java index 3cb60e6e3..a682ce0f5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandthunder.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandthunder.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Server; import org.bukkit.World; @@ -14,7 +14,7 @@ public class Commandthunder extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtime.java b/Essentials/src/com/earth2me/essentials/commands/Commandtime.java index c49f34fbd..1da6a4e8c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtime.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtime.java @@ -2,7 +2,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.DescParseTickFormat; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import java.util.*; import org.bukkit.Server; import org.bukkit.World; @@ -34,7 +34,7 @@ public class Commandtime extends EssentialsCommand return; } - final User user = ess.getUser(sender); + final IUser user = ess.getUser(sender); if (user != null && !user.isAuthorized("essentials.time.set")) { user.sendMessage(_("timeSetPermission")); @@ -110,7 +110,7 @@ public class Commandtime extends EssentialsCommand // If there is no selector we want the world the user is currently in. Or all worlds if it isn't a user. if (selector == null) { - final User user = ess.getUser(sender); + final IUser user = ess.getUser(sender); if (user == null) { worlds.addAll(server.getWorlds()); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java b/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java index f98343311..766a0a70d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java @@ -2,8 +2,10 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.OfflinePlayer; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.Util; +import com.earth2me.essentials.user.UserData.TimestampType; +import lombok.Cleanup; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -24,9 +26,11 @@ public class Commandtogglejail extends EssentialsCommand throw new NotEnoughArgumentsException(); } - final User player = getPlayer(server, args, 0, true); + @Cleanup + final IUser player = getPlayer(server, args, 0, true); + player.acquireReadLock(); - if (args.length >= 2 && !player.isJailed()) + if (args.length >= 2 && !player.getData().isJailed()) { if (player.getBase() instanceof OfflinePlayer) { @@ -54,16 +58,16 @@ public class Commandtogglejail extends EssentialsCommand // Check if jail exists ess.getJails().getJail(args[1]); } - player.setJailed(true); + player.acquireWriteLock(); + player.getData().setJailed(true); player.sendMessage(_("userJailed")); - player.setJail(null); - player.setJail(args[1]); + player.getData().setJail(args[1]); long timeDiff = 0; if (args.length > 2) { final String time = getFinalArg(args, 2); timeDiff = Util.parseDateDiff(time, true); - player.setJailTimeout(timeDiff); + player.setTimestamp(TimestampType.JAIL, timeDiff); } sender.sendMessage((timeDiff > 0 ? _("playerJailedFor", player.getName(), Util.formatDateDiff(timeDiff)) @@ -71,31 +75,33 @@ public class Commandtogglejail extends EssentialsCommand return; } - if (args.length >= 2 && player.isJailed() && !args[1].equalsIgnoreCase(player.getJail())) + if (args.length >= 2 && player.getData().isJailed() && !args[1].equalsIgnoreCase(player.getData().getJail())) { - sender.sendMessage(_("jailAlreadyIncarcerated", player.getJail())); + sender.sendMessage(_("jailAlreadyIncarcerated", player.getData().getJail())); return; } - if (args.length >= 2 && player.isJailed() && args[1].equalsIgnoreCase(player.getJail())) + if (args.length >= 2 && player.getData().isJailed() && args[1].equalsIgnoreCase(player.getData().getJail())) { final String time = getFinalArg(args, 2); final long timeDiff = Util.parseDateDiff(time, true); - player.setJailTimeout(timeDiff); + player.acquireWriteLock(); + player.setTimestamp(TimestampType.JAIL, timeDiff); sender.sendMessage(_("jailSentenceExtended", Util.formatDateDiff(timeDiff))); return; } - if (args.length == 1 || (args.length == 2 && args[1].equalsIgnoreCase(player.getJail()))) + if (args.length == 1 || (args.length == 2 && args[1].equalsIgnoreCase(player.getData().getJail()))) { - if (!player.isJailed()) + if (!player.getData().isJailed()) { throw new NotEnoughArgumentsException(); } - player.setJailed(false); - player.setJailTimeout(0); + player.acquireWriteLock(); + player.getData().setJailed(false); + player.setTimestamp(TimestampType.JAIL, 0); player.sendMessage(_("jailReleasedPlayerNotify")); - player.setJail(null); + player.getData().setJail(null); if (!(player.getBase() instanceof OfflinePlayer)) { player.getTeleport().back(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtop.java b/Essentials/src/com/earth2me/essentials/commands/Commandtop.java index e91d0984a..30518ea0b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtop.java @@ -2,7 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -16,7 +16,7 @@ public class Commandtop extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { final int topX = user.getLocation().getBlockX(); final int topZ = user.getLocation().getBlockZ(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtp.java b/Essentials/src/com/earth2me/essentials/commands/Commandtp.java index 7ea3f0541..b051aa313 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtp.java @@ -3,7 +3,8 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; +import lombok.Cleanup; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -17,7 +18,7 @@ public class Commandtp extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { switch (args.length) { @@ -25,8 +26,10 @@ public class Commandtp extends EssentialsCommand throw new NotEnoughArgumentsException(); case 1: - final User player = getPlayer(server, args, 0); - if (!player.isTeleportEnabled()) + @Cleanup + final IUser player = getPlayer(server, args, 0); + player.acquireReadLock(); + if (!player.getData().isTeleportEnabled()) { throw new Exception(_("teleportDisabled", player.getDisplayName())); } @@ -43,8 +46,8 @@ public class Commandtp extends EssentialsCommand throw new Exception("You need access to /tpohere to teleport other players."); } user.sendMessage(_("teleporting")); - final User target = getPlayer(server, args, 0); - final User toPlayer = getPlayer(server, args, 1); + final IUser target = getPlayer(server, args, 0); + final IUser toPlayer = getPlayer(server, args, 1); target.getTeleport().now(toPlayer, false, TeleportCause.COMMAND); target.sendMessage(_("teleportAtoB", user.getDisplayName(), toPlayer.getDisplayName())); break; @@ -60,8 +63,8 @@ public class Commandtp extends EssentialsCommand } sender.sendMessage(_("teleporting")); - final User target = getPlayer(server, args, 0); - final User toPlayer = getPlayer(server, args, 1); + final IUser target = getPlayer(server, args, 0); + final IUser toPlayer = getPlayer(server, args, 1); target.getTeleport().now(toPlayer, false, TeleportCause.COMMAND); target.sendMessage(_("teleportAtoB", Console.NAME, toPlayer.getDisplayName())); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java index 34195d51a..599ae334b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java @@ -1,7 +1,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; +import lombok.Cleanup; import org.bukkit.Server; @@ -13,19 +14,21 @@ public class Commandtpa extends EssentialsCommand } @Override - public void run(Server server, User user, String commandLabel, String[] args) throws Exception + public void run(Server server, IUser user, String commandLabel, String[] args) throws Exception { if (args.length < 1) { throw new NotEnoughArgumentsException(); } - User player = getPlayer(server, args, 0); - if (!player.isTeleportEnabled()) + @Cleanup + IUser player = getPlayer(server, args, 0); + player.acquireReadLock(); + if (!player.getData().isTeleportEnabled()) { throw new Exception(_("teleportDisabled", player.getDisplayName())); } - if (!player.isIgnoredPlayer(user.getName())) + if (!player.isIgnoringPlayer(user.getName())) { player.requestTeleport(user, false); player.sendMessage(_("teleportRequest", user.getDisplayName())); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java index c0abdc1ad..e9494db2e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java @@ -1,7 +1,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; +import lombok.Cleanup; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -27,21 +28,23 @@ public class Commandtpaall extends EssentialsCommand throw new NotEnoughArgumentsException(); } - final User player = getPlayer(server, args, 0); + final IUser player = getPlayer(server, args, 0); teleportAAllPlayers(server, sender, player); } - private void teleportAAllPlayers(final Server server, final CommandSender sender, final User user) + private void teleportAAllPlayers(final Server server, final CommandSender sender, final IUser user) { sender.sendMessage(_("teleportAAll")); for (Player onlinePlayer : server.getOnlinePlayers()) { - final User player = ess.getUser(onlinePlayer); + @Cleanup + final IUser player = ess.getUser(onlinePlayer); + player.acquireReadLock(); if (user == player) { continue; } - if (!player.isTeleportEnabled()) + if (!player.getData().isTeleportEnabled()) { continue; } @@ -57,7 +60,7 @@ public class Commandtpaall extends EssentialsCommand } catch (Exception ex) { - ess.showError(sender, ex, getName()); + ess.showCommandError(sender, getName(), ex); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java index 0cece3310..12a471605 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java @@ -3,7 +3,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.OfflinePlayer; import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; +import lombok.Cleanup; import org.bukkit.Server; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -16,12 +17,15 @@ public class Commandtpaccept extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { - - final User target = user.getTeleportRequest(); - if (target == null - || target.getBase() instanceof OfflinePlayer + if (user.getTeleportRequester() == null) + { + throw new Exception(_("noPendingRequest")); + } + + final IUser target = user.getTeleportRequester(); + if (target.getBase() instanceof OfflinePlayer || (user.isTeleportRequestHere() && !target.isAuthorized("essentials.tpahere"))) { throw new Exception(_("noPendingRequest")); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java index 376c2be44..76a4422dd 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java @@ -1,7 +1,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; +import lombok.Cleanup; import org.bukkit.Server; @@ -13,15 +14,17 @@ public class Commandtpahere extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { throw new NotEnoughArgumentsException(); } - final User player = getPlayer(server, args, 0); - if (!player.isTeleportEnabled()) + @Cleanup + final IUser player = getPlayer(server, args, 0); + player.acquireReadLock(); + if (!player.getData().isTeleportEnabled()) { throw new Exception(_("teleportDisabled", player.getDisplayName())); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java index f21f1a6bc..9643a0ff3 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -28,16 +28,16 @@ public class Commandtpall extends EssentialsCommand throw new NotEnoughArgumentsException(); } - final User player = getPlayer(server, args, 0); + final IUser player = getPlayer(server, args, 0); teleportAllPlayers(server, sender, player); } - private void teleportAllPlayers(Server server, CommandSender sender, User user) + private void teleportAllPlayers(Server server, CommandSender sender, IUser user) { sender.sendMessage(_("teleportAll")); for (Player onlinePlayer : server.getOnlinePlayers()) { - final User player = ess.getUser(onlinePlayer); + final IUser player = ess.getUser(onlinePlayer); if (user == player) { continue; @@ -48,7 +48,7 @@ public class Commandtpall extends EssentialsCommand } catch (Exception ex) { - ess.showError(sender, ex, getName()); + ess.showCommandError(sender, getName(), ex); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpdeny.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpdeny.java index 92bba1054..6a2c787bc 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpdeny.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpdeny.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Server; @@ -13,9 +13,9 @@ public class Commandtpdeny extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { - final User player = user.getTeleportRequest(); + final IUser player = user.getTeleportRequester(); if (player == null) { throw new Exception(_("noPendingRequest")); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java b/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java index 733091d1a..065c5d2a4 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java @@ -2,7 +2,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; +import lombok.Cleanup; import org.bukkit.Server; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -15,10 +16,12 @@ public class Commandtphere extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { - final User player = getPlayer(server, args, 0); - if (!player.isTeleportEnabled()) + @Cleanup + final IUser player = getPlayer(server, args, 0); + player.acquireReadLock(); + if (!player.getData().isTeleportEnabled()) { throw new Exception(_("teleportDisabled", player.getDisplayName())); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpo.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpo.java index 7c13b80d4..5da17488f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpo.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpo.java @@ -2,7 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.OfflinePlayer; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Server; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -15,7 +15,7 @@ public class Commandtpo extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -23,7 +23,7 @@ public class Commandtpo extends EssentialsCommand } //Just basically the old tp command - final User player = getPlayer(server, args, 0, true); + final IUser player = getPlayer(server, args, 0, true); // Check if user is offline if (player.getBase() instanceof OfflinePlayer) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java index e226f0702..51bc900c2 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java @@ -2,7 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.OfflinePlayer; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Server; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -15,7 +15,7 @@ public class Commandtpohere extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -23,7 +23,7 @@ public class Commandtpohere extends EssentialsCommand } //Just basically the old tphere command - final User player = getPlayer(server, args, 0, true); + final IUser player = getPlayer(server, args, 0, true); // Check if user is offline if (player.getBase() instanceof OfflinePlayer) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java b/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java index 226fa44e3..0a85f4499 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java @@ -2,7 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -16,7 +16,7 @@ public class Commandtppos extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length < 3) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java b/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java index 1fc4c2aa4..d2256ac72 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Server; @@ -13,7 +13,7 @@ public class Commandtptoggle extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { user.sendMessage(user.toggleTeleportEnabled() ? _("teleportationEnabled") diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtree.java b/Essentials/src/com/earth2me/essentials/commands/Commandtree.java index 538611972..b3847d32a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtree.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtree.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.Util; import org.bukkit.Location; import org.bukkit.Server; @@ -16,7 +16,7 @@ public class Commandtree extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { TreeType tree; if (args.length < 1) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandunban.java b/Essentials/src/com/earth2me/essentials/commands/Commandunban.java index 8bc3ad068..186420fa1 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandunban.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandunban.java @@ -1,7 +1,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; +import lombok.Cleanup; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -23,7 +24,10 @@ public class Commandunban extends EssentialsCommand try { - final User player = getPlayer(server, args, 0, true); + @Cleanup + final IUser player = getPlayer(server, args, 0, true); + player.acquireWriteLock(); + player.getData().setBan(null); player.setBanned(false); sender.sendMessage(_("unbannedPlayer")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java b/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java index c539a596c..5a48f9843 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java @@ -1,7 +1,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; +import lombok.Cleanup; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -22,8 +23,10 @@ public class Commandunbanip extends EssentialsCommand } try { - final User user = getPlayer(server, args, 0, true); - ess.getServer().unbanIP(user.getLastLoginAddress()); + @Cleanup + final IUser user = getPlayer(server, args, 0, true); + user.acquireReadLock(); + ess.getServer().unbanIP(user.getData().getIpAddress()); } catch (Exception ex) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java b/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java index beff6a77b..27ba32faf 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java @@ -2,9 +2,10 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.craftbukkit.InventoryWorkaround; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import java.util.List; import java.util.Locale; +import lombok.Cleanup; import org.bukkit.Material; import org.bukkit.Server; import org.bukkit.inventory.ItemStack; @@ -18,19 +19,21 @@ public class Commandunlimited extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { throw new NotEnoughArgumentsException(); } - User target = user; + @Cleanup + IUser target = user; if (args.length > 1 && user.isAuthorized("essentials.unlimited.others")) { target = getPlayer(server, args, 1); - } + target.acquireReadLock(); + } if (args[0].equalsIgnoreCase("list")) { @@ -39,7 +42,8 @@ public class Commandunlimited extends EssentialsCommand } else if (args[0].equalsIgnoreCase("clear")) { - final List itemList = target.getUnlimited(); + //TODO: Fix this, the clear should always work, even when the player does not have permission. + final List itemList = target.getData().getUnlimited(); int index = 0; while (itemList.size() > index) @@ -57,7 +61,7 @@ public class Commandunlimited extends EssentialsCommand } } - private String getList(final User target) + private String getList(final IUser target) { final StringBuilder output = new StringBuilder(); output.append(_("unlimitedItems")).append(" "); @@ -81,7 +85,7 @@ public class Commandunlimited extends EssentialsCommand return output.toString(); } - private Boolean toggleUnlimited(final User user, final User target, final String item) throws Exception + private Boolean toggleUnlimited(final IUser user, final IUser target, final String item) throws Exception { final ItemStack stack = ess.getItemDb().get(item, 1); stack.setAmount(Math.min(stack.getType().getMaxStackSize(), 2)); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java index 51b64563b..30d2f602c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java @@ -2,9 +2,9 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.Util; -import com.earth2me.essentials.Warps; +import com.earth2me.essentials.api.IWarps; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -23,7 +23,7 @@ public class Commandwarp extends EssentialsCommand } @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length == 0 || args[0].matches("[0-9]+")) { @@ -36,7 +36,7 @@ public class Commandwarp extends EssentialsCommand } if (args.length > 0) { - User otherUser = null; + IUser otherUser = null; if (args.length == 2 && user.isAuthorized("essentials.warp.otherplayers")) { otherUser = ess.getUser(server.getPlayer(args[1])); @@ -60,7 +60,7 @@ public class Commandwarp extends EssentialsCommand warpList(sender, args); throw new NoChargeException(); } - User otherUser = ess.getUser(server.getPlayer(args[1])); + IUser otherUser = ess.getUser(server.getPlayer(args[1])); if (otherUser == null) { throw new Exception(_("playerNotFound")); @@ -73,14 +73,14 @@ public class Commandwarp extends EssentialsCommand //TODO: Use one of the new text classes, like /help ? private void warpList(final CommandSender sender, final String[] args) throws Exception { - final Warps warps = ess.getWarps(); + final IWarps warps = ess.getWarps2(); if (warps.isEmpty()) { throw new Exception(_("noWarpsDefined")); } - final List warpNameList = new ArrayList(warps.getWarpNames()); + final List warpNameList = new ArrayList(warps.getList()); - if (sender instanceof User) + if (sender instanceof IUser) { final Iterator iterator = warpNameList.iterator(); while (iterator.hasNext()) @@ -112,7 +112,7 @@ public class Commandwarp extends EssentialsCommand } } - private void warpUser(final User user, final String name) throws Exception + private void warpUser(final IUser user, final String name) throws Exception { final Trade charge = new Trade(this.getName(), ess); charge.isAffordableFor(user); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandweather.java b/Essentials/src/com/earth2me/essentials/commands/Commandweather.java index 1229c9ee4..ee2156251 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandweather.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandweather.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.Server; import org.bukkit.World; import org.bukkit.command.CommandSender; @@ -16,7 +16,7 @@ public class Commandweather extends EssentialsCommand //TODO: Remove duplication @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java index 7e211455e..bc3be185d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java @@ -1,9 +1,11 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.Util; +import com.earth2me.essentials.api.ISettings; import java.util.Locale; +import lombok.Cleanup; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -36,15 +38,21 @@ public class Commandwhois extends EssentialsCommand showhidden = true; } final String whois = args[0].toLowerCase(Locale.ENGLISH); - final int prefixLength = Util.stripColor(ess.getSettings().getNicknamePrefix()).length(); + @Cleanup + ISettings settings = ess.getSettings(); + settings.acquireReadLock(); + final int prefixLength = Util.stripColor(settings.getData().getChat().getNicknamePrefix()).length(); for (Player onlinePlayer : server.getOnlinePlayers()) { - final User user = ess.getUser(onlinePlayer); + @Cleanup + final IUser user = ess.getUser(onlinePlayer); + if (user.isHidden() && !showhidden) { continue; } - final String nickName = Util.stripColor(user.getNickname()); + user.acquireReadLock(); + final String nickName = Util.stripColor(user.getData().getNickname()); if (!whois.equalsIgnoreCase(nickName) && !whois.substring(prefixLength).equalsIgnoreCase(nickName) && !whois.equalsIgnoreCase(user.getName())) @@ -58,15 +66,15 @@ public class Commandwhois extends EssentialsCommand sender.sendMessage(_("whoisGod", (user.isGodModeEnabled() ? _("true") : _("false")))); sender.sendMessage(_("whoisGamemode", _(user.getGameMode().toString().toLowerCase(Locale.ENGLISH)))); sender.sendMessage(_("whoisLocation", user.getLocation().getWorld().getName(), user.getLocation().getBlockX(), user.getLocation().getBlockY(), user.getLocation().getBlockZ())); - if (!ess.getSettings().isEcoDisabled()) + if (!settings.getData().getEconomy().isEcoDisabled()) { sender.sendMessage(_("whoisMoney", Util.formatCurrency(user.getMoney(), ess))); } - sender.sendMessage(user.isAfk() + sender.sendMessage(user.getData().isAfk() ? _("whoisStatusAway") : _("whoisStatusAvailable")); sender.sendMessage(_("whoisIPAddress", user.getAddress().getAddress().toString())); - final String location = user.getGeoLocation(); + final String location = user.getData().getGeolocation(); if (location != null && (sender instanceof Player ? ess.getUser(sender).isAuthorized("essentials.geoip.show") : true)) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandworld.java b/Essentials/src/com/earth2me/essentials/commands/Commandworld.java index 41554c8ce..259aaf97a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandworld.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandworld.java @@ -2,7 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import java.util.List; import org.bukkit.Location; import org.bukkit.Server; @@ -18,7 +18,7 @@ public class Commandworld extends EssentialsCommand } @Override - protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { World world; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java index 586b31873..cdc8788c0 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.Util; import java.util.Locale; import org.bukkit.Server; @@ -18,7 +18,7 @@ public class Commandworth extends EssentialsCommand //TODO: Remove duplication @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception { ItemStack iStack = user.getInventory().getItemInHand(); int amount = iStack.getAmount(); diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java index 1daf67b32..e4d97a3c9 100644 --- a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java @@ -2,7 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IEssentials; -import com.earth2me.essentials.IEssentialsModule; +import com.earth2me.essentials.api.IEssentialsModule; import com.earth2me.essentials.OfflinePlayer; import com.earth2me.essentials.Trade; import com.earth2me.essentials.api.IUser; diff --git a/Essentials/src/com/earth2me/essentials/commands/IEssentialsCommand.java b/Essentials/src/com/earth2me/essentials/commands/IEssentialsCommand.java index 0143bade4..66dc05ff5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/IEssentialsCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/IEssentialsCommand.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.IEssentialsModule; +import com.earth2me.essentials.api.IEssentialsModule; import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IUser; import org.bukkit.Server; diff --git a/Essentials/src/com/earth2me/essentials/listener/EssentialsBlockListener.java b/Essentials/src/com/earth2me/essentials/listener/EssentialsBlockListener.java index 76329ad72..22f433260 100644 --- a/Essentials/src/com/earth2me/essentials/listener/EssentialsBlockListener.java +++ b/Essentials/src/com/earth2me/essentials/listener/EssentialsBlockListener.java @@ -1,9 +1,8 @@ package com.earth2me.essentials.listener; -import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.Util; -import java.util.logging.Logger; import org.bukkit.GameMode; import org.bukkit.event.block.BlockListener; import org.bukkit.event.block.BlockPlaceEvent; @@ -12,30 +11,30 @@ import org.bukkit.inventory.ItemStack; public class EssentialsBlockListener extends BlockListener { - private final IEssentials ess; - private static final Logger logger = Logger.getLogger("Minecraft"); + private final transient IEssentials ess; - public EssentialsBlockListener(IEssentials ess) + public EssentialsBlockListener(final IEssentials ess) { + super(); this.ess = ess; } @Override - public void onBlockPlace(BlockPlaceEvent event) + public void onBlockPlace(final BlockPlaceEvent event) { if (event.isCancelled()) { return; } - final User user = ess.getUser(event.getPlayer()); // Do not rely on getItemInHand(); // http://leaky.bukkit.org/issues/663 - final ItemStack is = Util.convertBlockToItem(event.getBlockPlaced()); - if (is == null) + final ItemStack itemstack = Util.convertBlockToItem(event.getBlockPlaced()); + if (itemstack == null) { return; } - boolean unlimitedForUser = user.hasUnlimited(is); + final IUser user = ess.getUser(event.getPlayer()); + final boolean unlimitedForUser = user.getData().hasUnlimited(itemstack.getType()); if (unlimitedForUser && user.getGameMode() == GameMode.SURVIVAL) { ess.scheduleSyncDelayedTask( @@ -44,7 +43,7 @@ public class EssentialsBlockListener extends BlockListener @Override public void run() { - user.getInventory().addItem(is); + user.getInventory().addItem(itemstack); user.updateInventory(); } }); diff --git a/Essentials/src/com/earth2me/essentials/listener/EssentialsEntityListener.java b/Essentials/src/com/earth2me/essentials/listener/EssentialsEntityListener.java index 1ead71451..c0004c6cc 100644 --- a/Essentials/src/com/earth2me/essentials/listener/EssentialsEntityListener.java +++ b/Essentials/src/com/earth2me/essentials/listener/EssentialsEntityListener.java @@ -1,10 +1,11 @@ package com.earth2me.essentials.listener; -import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.ISettings; +import com.earth2me.essentials.api.IUser; import static com.earth2me.essentials.I18n._; import java.util.List; -import java.util.logging.Logger; +import lombok.Cleanup; import org.bukkit.Material; import org.bukkit.entity.Animals; import org.bukkit.entity.Entity; @@ -16,29 +17,30 @@ import org.bukkit.inventory.ItemStack; public class EssentialsEntityListener extends EntityListener { - private static final Logger LOGGER = Logger.getLogger("Minecraft"); - private final IEssentials ess; + private final transient IEssentials ess; - public EssentialsEntityListener(IEssentials ess) + public EssentialsEntityListener(final IEssentials ess) { + super(); this.ess = ess; } @Override - public void onEntityDamage(EntityDamageEvent event) + public void onEntityDamage(final EntityDamageEvent event) { if (event instanceof EntityDamageByEntityEvent) { - EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent)event; - Entity eAttack = edEvent.getDamager(); - Entity eDefend = edEvent.getEntity(); + final EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent)event; + final Entity eAttack = edEvent.getDamager(); + final Entity eDefend = edEvent.getEntity(); if (eDefend instanceof Player && eAttack instanceof Player) { - User defender = ess.getUser(eDefend); - User attacker = ess.getUser(eAttack); + @Cleanup + final IUser attacker = ess.getUser(eAttack); + attacker.acquireReadLock(); attacker.updateActivity(true); - ItemStack is = attacker.getItemInHand(); - List commandList = attacker.getPowertool(is); + final ItemStack itemstack = attacker.getItemInHand(); + final List commandList = attacker.getData().getPowertool(itemstack.getType()); if (commandList != null && !commandList.isEmpty()) { for (String command : commandList) @@ -46,6 +48,7 @@ public class EssentialsEntityListener extends EntityListener if (command != null && !command.isEmpty()) { + final IUser defender = ess.getUser(eDefend); attacker.getServer().dispatchCommand(attacker, command.replaceAll("\\{player\\}", defender.getName())); event.setCancelled(true); return; @@ -55,9 +58,10 @@ public class EssentialsEntityListener extends EntityListener } if (eDefend instanceof Animals && eAttack instanceof Player) { - User player = ess.getUser(eAttack); - ItemStack hand = player.getItemInHand(); - if (hand != null && hand.getType() == Material.MILK_BUCKET) { + final IUser player = ess.getUser(eAttack); + final ItemStack hand = player.getItemInHand(); + if (hand != null && hand.getType() == Material.MILK_BUCKET) + { ((Animals)eDefend).setAge(-24000); hand.setType(Material.BUCKET); player.setItemInHand(hand); @@ -76,7 +80,7 @@ public class EssentialsEntityListener extends EntityListener } @Override - public void onEntityCombust(EntityCombustEvent event) + public void onEntityCombust(final EntityCombustEvent event) { if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled()) { @@ -90,13 +94,16 @@ public class EssentialsEntityListener extends EntityListener if (event instanceof PlayerDeathEvent) { final PlayerDeathEvent pdevent = (PlayerDeathEvent)event; - final User user = ess.getUser(pdevent.getEntity()); - if (user.isAuthorized("essentials.back.ondeath") && !ess.getSettings().isCommandDisabled("back")) + final IUser user = ess.getUser(pdevent.getEntity()); + @Cleanup + final ISettings settings = ess.getSettings(); + settings.acquireReadLock(); + if (user.isAuthorized("essentials.back.ondeath") && !settings.getData().getCommands().isDisabled("back")) { user.setLastLocation(); user.sendMessage(_("backAfterDeath")); } - if (!ess.getSettings().areDeathMessagesEnabled()) + if (!settings.getData().getGeneral().isDeathMessages()) { pdevent.setDeathMessage(""); } @@ -104,7 +111,7 @@ public class EssentialsEntityListener extends EntityListener } @Override - public void onFoodLevelChange(FoodLevelChangeEvent event) + public void onFoodLevelChange(final FoodLevelChangeEvent event) { if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled()) { @@ -113,12 +120,21 @@ public class EssentialsEntityListener extends EntityListener } @Override - public void onEntityRegainHealth(EntityRegainHealthEvent event) + public void onEntityRegainHealth(final EntityRegainHealthEvent event) { - if (event.getRegainReason() == RegainReason.SATIATED && event.getEntity() instanceof Player - && ess.getUser(event.getEntity()).isAfk() && ess.getSettings().getFreezeAfkPlayers()) + + if (event.getRegainReason() == RegainReason.SATIATED && event.getEntity() instanceof Player) { - event.setCancelled(true); + @Cleanup + final ISettings settings = ess.getSettings(); + settings.acquireReadLock(); + @Cleanup + final IUser user = ess.getUser(event.getEntity()); + user.acquireReadLock(); + if (user.getData().isAfk() && settings.getData().getCommands().getAfk().isFreezeAFKPlayers()) + { + event.setCancelled(true); + } } } } diff --git a/Essentials/src/com/earth2me/essentials/listener/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/listener/EssentialsPlayerListener.java index 5ca77e91a..74f82365f 100644 --- a/Essentials/src/com/earth2me/essentials/listener/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/listener/EssentialsPlayerListener.java @@ -39,6 +39,7 @@ public class EssentialsPlayerListener extends PlayerListener public EssentialsPlayerListener(final IEssentials parent) { + super(); this.ess = parent; this.server = parent.getServer(); } @@ -47,18 +48,17 @@ public class EssentialsPlayerListener extends PlayerListener public void onPlayerRespawn(final PlayerRespawnEvent event) { final IUser user = ess.getUser(event.getPlayer()); - updateCompass(user); - if (ess.getSettings().changeDisplayName()) - { - user.setDisplayNick(); - } + user.updateCompass(); + user.updateDisplayName(); } @Override public void onPlayerChat(final PlayerChatEvent event) { - final User user = ess.getUser(event.getPlayer()); - if (user.isMuted()) + @Cleanup + final IUser user = ess.getUser(event.getPlayer()); + user.acquireReadLock(); + if (user.getData().isMuted()) { event.setCancelled(true); user.sendMessage(_("playerMuted")); @@ -67,17 +67,14 @@ public class EssentialsPlayerListener extends PlayerListener final Iterator it = event.getRecipients().iterator(); while (it.hasNext()) { - final User u = ess.getUser(it.next()); - if (u.isIgnoredPlayer(user.getName())) + final IUser player = ess.getUser(it.next()); + if (player.isIgnoringPlayer(user.getName())) { it.remove(); } } user.updateActivity(true); - if (ess.getSettings().changeDisplayName()) - { - user.setDisplayNick(); - } + user.updateDisplayName(); } @Override @@ -87,9 +84,14 @@ public class EssentialsPlayerListener extends PlayerListener { return; } - final User user = ess.getUser(event.getPlayer()); + @Cleanup + final IUser user = ess.getUser(event.getPlayer()); + user.acquireReadLock(); + @Cleanup + final ISettings settings = ess.getSettings(); + settings.acquireReadLock(); - if (user.isAfk() && ess.getSettings().getFreezeAfkPlayers()) + if (user.getData().isAfk() && settings.getData().getCommands().getAfk().isFreezeAFKPlayers()) { final Location from = event.getFrom(); final Location to = event.getTo().clone(); @@ -117,15 +119,20 @@ public class EssentialsPlayerListener extends PlayerListener @Override public void onPlayerQuit(final PlayerQuitEvent event) { - final User user = ess.getUser(event.getPlayer()); - if (ess.getSettings().removeGodOnDisconnect() && user.isGodModeEnabled()) + @Cleanup + final IUser user = ess.getUser(event.getPlayer()); + user.acquireReadLock(); + @Cleanup + final ISettings settings = ess.getSettings(); + settings.acquireReadLock(); + if (settings.getData().getCommands().getGod().isRemoveOnDisconnect() && user.isGodModeEnabled()) { user.toggleGodModeEnabled(); } - if (user.getSavedInventory() != null) + if (user.getData().getInventory() != null) { - user.getInventory().setContents(user.getSavedInventory()); - user.setSavedInventory(null); + user.getInventory().setContents(user.getData().getInventory().getBukkitInventory()); + user.getData().setInventory(null); } user.updateActivity(false); user.dispose(); @@ -192,7 +199,7 @@ public class EssentialsPlayerListener extends PlayerListener { if (event.getResult() != Result.ALLOWED && event.getResult() != Result.KICK_FULL && event.getResult() != Result.KICK_BANNED) { - LOGGER.log(Level.INFO, "Disconnecting user " + event.getPlayer().toString() + " due to " + event.getResult().toString()); + LOGGER.log(Level.INFO, "Disconnecting user {0} due to {1}", new Object[]{event.getPlayer().toString(), event.getResult().toString()}); return; } @Cleanup @@ -208,7 +215,7 @@ public class EssentialsPlayerListener extends PlayerListener if (!banExpired && (user.isBanned() || event.getResult() == Result.KICK_BANNED)) { final String banReason = user.getData().getBan() == null ? "" : user.getData().getBan().getReason(); - event.disallow(Result.KICK_BANNED, banReason != null && !banReason.isEmpty() && !banReason.equalsIgnoreCase("ban") ? banReason : _("defaultBanReason")); + event.disallow(Result.KICK_BANNED, banReason == null || banReason.isEmpty() || banReason.equalsIgnoreCase("ban") ? _("defaultBanReason") : banReason); return; } @@ -220,24 +227,11 @@ public class EssentialsPlayerListener extends PlayerListener event.allow(); user.setTimestamp(TimestampType.LOGIN, System.currentTimeMillis()); - updateCompass(user); - } - - private void updateCompass(final IUser user) - { - Location loc = user.getHome(user.getLocation()); - if (loc == null) - { - loc = user.getBedSpawnLocation(); - } - if (loc != null) - { - user.setCompassTarget(loc); - } + user.updateCompass(); } @Override - public void onPlayerTeleport(PlayerTeleportEvent event) + public void onPlayerTeleport(final PlayerTeleportEvent event) { if (event.isCancelled()) { @@ -255,7 +249,7 @@ public class EssentialsPlayerListener extends PlayerListener } user.updateDisplayName(); - updateCompass(user); + user.updateCompass(); } @Override @@ -264,10 +258,10 @@ public class EssentialsPlayerListener extends PlayerListener @Cleanup final IUser user = ess.getUser(event.getPlayer()); user.acquireReadLock(); - final ItemStack is = new ItemStack(Material.EGG, 1); - if (user.getData().hasUnlimited(is.getType())) + final ItemStack hand = new ItemStack(Material.EGG, 1); + if (user.getData().hasUnlimited(hand.getType())) { - user.getInventory().addItem(is); + user.getInventory().addItem(hand); user.updateInventory(); } } @@ -309,12 +303,12 @@ public class EssentialsPlayerListener extends PlayerListener @Cleanup final IUser user = ess.getUser(event.getPlayer()); user.acquireReadLock(); - final ItemStack is = user.getItemInHand(); - if (is == null || is.getType() == Material.AIR || !user.getData().isPowertoolsenabled()) + final ItemStack hand = user.getItemInHand(); + if (hand == null || hand.getType() == Material.AIR || !user.getData().isPowertoolsenabled()) { return; } - final List commandList = user.getData().getPowertool(is.getType()); + final List commandList = user.getData().getPowertool(hand.getType()); if (commandList == null || commandList.isEmpty()) { return; @@ -382,7 +376,7 @@ public class EssentialsPlayerListener extends PlayerListener @Cleanup final IUser user = ess.getUser(event.getPlayer()); user.acquireReadLock(); - if (user.isGodModeEnabledRaw()) + if (user.getData().isGodmode()) { user.sendMessage(_("noGodWorldWarning")); } @@ -401,21 +395,33 @@ public class EssentialsPlayerListener extends PlayerListener return; } - if (ess.getSettings().getUpdateBedAtDaytime() && event.getClickedBlock().getType() == Material.BED_BLOCK) + @Cleanup + final ISettings settings = ess.getSettings(); + settings.acquireReadLock(); + if (settings.getData().getCommands().getHome().isUpdateBedAtDaytime() && event.getClickedBlock().getType() == Material.BED_BLOCK) { SetBed.setBed(event.getPlayer(), event.getClickedBlock()); } } @Override - public void onPlayerPickupItem(PlayerPickupItemEvent event) + public void onPlayerPickupItem(final PlayerPickupItemEvent event) { - if (event.isCancelled() || !ess.getSettings().getDisableItemPickupWhileAfk()) + if (event.isCancelled()) { return; } - final User user = ess.getUser(event.getPlayer()); - if (user.isAfk()) + @Cleanup + final ISettings settings = ess.getSettings(); + settings.acquireReadLock(); + if (!settings.getData().getCommands().getAfk().isDisableItemPickupWhileAfk()) + { + return; + } + @Cleanup + final IUser user = ess.getUser(event.getPlayer()); + user.acquireReadLock(); + if (user.getData().isAfk()) { event.setCancelled(true); } diff --git a/Essentials/src/com/earth2me/essentials/listener/EssentialsPluginListener.java b/Essentials/src/com/earth2me/essentials/listener/EssentialsPluginListener.java index 3f87bf731..5b63d890a 100644 --- a/Essentials/src/com/earth2me/essentials/listener/EssentialsPluginListener.java +++ b/Essentials/src/com/earth2me/essentials/listener/EssentialsPluginListener.java @@ -1,21 +1,25 @@ package com.earth2me.essentials.listener; import com.earth2me.essentials.IConf; -import com.earth2me.essentials.IEssentials; +import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.IReload; +import com.earth2me.essentials.api.ISettings; import java.util.logging.Level; import java.util.logging.Logger; +import lombok.Cleanup; import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.event.server.ServerListener; -public class EssentialsPluginListener extends ServerListener implements IConf +public class EssentialsPluginListener extends ServerListener implements IConf, IReload { private final transient IEssentials ess; private static final Logger LOGGER = Logger.getLogger("Minecraft"); public EssentialsPluginListener(final IEssentials ess) { + super(); this.ess = ess; } @@ -26,7 +30,7 @@ public class EssentialsPluginListener extends ServerListener implements IConf ess.getAlternativeCommandsHandler().addPlugin(event.getPlugin()); if (!ess.getPaymentMethod().hasMethod() && ess.getPaymentMethod().setMethod(ess.getServer().getPluginManager())) { - LOGGER.log(Level.INFO, "[Essentials] Payment method found (" + ess.getPaymentMethod().getMethod().getName() + " version: " + ess.getPaymentMethod().getMethod().getVersion() + ")"); + LOGGER.log(Level.INFO, "[Essentials] Payment method found ({0} version: {1})", new Object[]{ess.getPaymentMethod().getMethod().getName(), ess.getPaymentMethod().getMethod().getVersion()}); } } @@ -46,7 +50,11 @@ public class EssentialsPluginListener extends ServerListener implements IConf @Override public void reloadConfig() { - ess.getPermissionsHandler().setUseSuperperms(ess.getSettings().useBukkitPermissions()); - ess.getPermissionsHandler().checkPermissions(); + //ess.getPermissionsHandler().setUseSuperperms(ess.getSettings().useBukkitPermissions()); + } + + @Override + public void onReload() + { } } diff --git a/Essentials/src/com/earth2me/essentials/listener/TNTExplodeListener.java b/Essentials/src/com/earth2me/essentials/listener/TNTExplodeListener.java index 76bd87bb2..1f0035d76 100644 --- a/Essentials/src/com/earth2me/essentials/listener/TNTExplodeListener.java +++ b/Essentials/src/com/earth2me/essentials/listener/TNTExplodeListener.java @@ -1,7 +1,8 @@ package com.earth2me.essentials.listener; -import com.earth2me.essentials.IEssentials; +import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.craftbukkit.FakeExplosion; +import java.util.concurrent.atomic.AtomicBoolean; import org.bukkit.entity.LivingEntity; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityListener; @@ -10,7 +11,7 @@ import org.bukkit.event.entity.EntityListener; public class TNTExplodeListener extends EntityListener implements Runnable { private final transient IEssentials ess; - private transient boolean enabled = false; + private transient AtomicBoolean enabled = new AtomicBoolean(false); private transient int timer = -1; public TNTExplodeListener(final IEssentials ess) @@ -21,15 +22,14 @@ public class TNTExplodeListener extends EntityListener implements Runnable public void enable() { - if (!enabled) + if (enabled.compareAndSet(false, true)) { - enabled = true; timer = ess.scheduleSyncDelayedTask(this, 1000); return; } if (timer != -1) { - ess.getScheduler().cancelTask(timer); + ess.getServer().getScheduler().cancelTask(timer); timer = ess.scheduleSyncDelayedTask(this, 1000); } } @@ -37,7 +37,7 @@ public class TNTExplodeListener extends EntityListener implements Runnable @Override public void onEntityExplode(final EntityExplodeEvent event) { - if (!enabled) + if (!enabled.get()) { return; } @@ -52,6 +52,6 @@ public class TNTExplodeListener extends EntityListener implements Runnable @Override public void run() { - enabled = false; + enabled.set(false); } } diff --git a/Essentials/src/com/earth2me/essentials/perm/ConfigPermissionsHandler.java b/Essentials/src/com/earth2me/essentials/perm/ConfigPermissionsHandler.java index fad479444..39074e2b5 100644 --- a/Essentials/src/com/earth2me/essentials/perm/ConfigPermissionsHandler.java +++ b/Essentials/src/com/earth2me/essentials/perm/ConfigPermissionsHandler.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.perm; -import com.earth2me.essentials.IEssentials; +import com.earth2me.essentials.api.IEssentials; import java.util.List; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; diff --git a/Essentials/src/com/earth2me/essentials/settings/GroupsHolder.java b/Essentials/src/com/earth2me/essentials/settings/GroupsHolder.java index 39609553f..178221f74 100644 --- a/Essentials/src/com/earth2me/essentials/settings/GroupsHolder.java +++ b/Essentials/src/com/earth2me/essentials/settings/GroupsHolder.java @@ -95,6 +95,19 @@ public class GroupsHolder extends AsyncStorageObjectHolder implements IG } return 0; } + + @Override + public double getTeleportDelay(final IUser player) + { + for (GroupOptions groupOptions : getGroups(player)) + { + if (groupOptions.getTeleportDelay() != null) + { + return groupOptions.getTeleportDelay(); + } + } + return 0; + } @Override public String getPrefix(final IUser player) diff --git a/Essentials/src/com/earth2me/essentials/settings/commands/Afk.java b/Essentials/src/com/earth2me/essentials/settings/commands/Afk.java index 89151d737..f46e52d52 100644 --- a/Essentials/src/com/earth2me/essentials/settings/commands/Afk.java +++ b/Essentials/src/com/earth2me/essentials/settings/commands/Afk.java @@ -33,4 +33,6 @@ public class Afk implements StorageObject "since the player will not get a message, if he tries to move." }) private boolean freezeAFKPlayers = false; + + private boolean disableItemPickupWhileAfk = true; } diff --git a/Essentials/src/com/earth2me/essentials/settings/commands/Home.java b/Essentials/src/com/earth2me/essentials/settings/commands/Home.java index 8b3a0ca82..b856c881b 100644 --- a/Essentials/src/com/earth2me/essentials/settings/commands/Home.java +++ b/Essentials/src/com/earth2me/essentials/settings/commands/Home.java @@ -21,4 +21,6 @@ public class Home implements StorageObject private boolean bedSetsHome = false; @Comment("If no home is set, should the player be send to spawn, when /home is used.") private boolean spawnIfNoHome = false; + @Comment("Allows people to set their bed at daytime") + private boolean updateBedAtDaytime = true; } diff --git a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java index 1e62a6097..f93636f8e 100644 --- a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java +++ b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java @@ -2,6 +2,8 @@ package com.earth2me.essentials.signs; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.*; +import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.IUser; import java.util.HashSet; import java.util.Locale; import java.util.Set; @@ -27,7 +29,7 @@ public class EssentialsSign public final boolean onSignCreate(final SignChangeEvent event, final IEssentials ess) { final ISign sign = new EventSign(event); - final User user = ess.getUser(event.getPlayer()); + final IUser user = ess.getUser(event.getPlayer()); if (!(user.isAuthorized("essentials.signs." + signName.toLowerCase(Locale.ENGLISH) + ".create") || user.isAuthorized("essentials.signs.create." + signName.toLowerCase(Locale.ENGLISH)))) { @@ -47,11 +49,11 @@ public class EssentialsSign } catch (ChargeException ex) { - ess.showError(user, ex, signName); + ess.showCommandError(user, signName, ex); } catch (SignException ex) { - ess.showError(user, ex, signName); + ess.showCommandError(user, signName, ex); } // Return true, so the player sees the wrong sign. return true; @@ -67,7 +69,7 @@ public class EssentialsSign return _("signFormatTemplate", this.signName); } - private String getUsername(final User user) + private String getUsername(final IUser user) { return user.getName().substring(0, user.getName().length() > 13 ? 13 : user.getName().length()); } @@ -75,7 +77,7 @@ public class EssentialsSign public final boolean onSignInteract(final Block block, final Player player, final IEssentials ess) { final ISign sign = new BlockSign(block); - final User user = ess.getUser(player); + final IUser user = ess.getUser(player); try { return (user.isAuthorized("essentials.signs." + signName.toLowerCase(Locale.ENGLISH) + ".use") @@ -84,12 +86,12 @@ public class EssentialsSign } catch (ChargeException ex) { - ess.showError(user, ex, signName); + ess.showCommandError(user,signName, ex); return false; } catch (SignException ex) { - ess.showError(user, ex, signName); + ess.showCommandError(user, signName, ex); return false; } } @@ -97,7 +99,7 @@ public class EssentialsSign public final boolean onSignBreak(final Block block, final Player player, final IEssentials ess) { final ISign sign = new BlockSign(block); - final User user = ess.getUser(player); + final IUser user = ess.getUser(player); try { return (user.isAuthorized("essentials.signs." + signName.toLowerCase(Locale.ENGLISH) + ".break") @@ -106,72 +108,72 @@ public class EssentialsSign } catch (SignException ex) { - ess.showError(user, ex, signName); + ess.showCommandError(user, signName, ex); return false; } } - protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException + protected boolean onSignCreate(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException, ChargeException { return true; } - protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException + protected boolean onSignInteract(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException, ChargeException { return true; } - protected boolean onSignBreak(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException + protected boolean onSignBreak(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException { return true; } public final boolean onBlockPlace(final Block block, final Player player, final IEssentials ess) { - User user = ess.getUser(player); + IUser user = ess.getUser(player); try { return onBlockPlace(block, user, getUsername(user), ess); } catch (ChargeException ex) { - ess.showError(user, ex, signName); + ess.showCommandError(user, signName, ex); } catch (SignException ex) { - ess.showError(user, ex, signName); + ess.showCommandError(user, signName, ex); } return false; } public final boolean onBlockInteract(final Block block, final Player player, final IEssentials ess) { - User user = ess.getUser(player); + IUser user = ess.getUser(player); try { return onBlockInteract(block, user, getUsername(user), ess); } catch (ChargeException ex) { - ess.showError(user, ex, signName); + ess.showCommandError(user, signName, ex); } catch (SignException ex) { - ess.showError(user, ex, signName); + ess.showCommandError(user, signName, ex); } return false; } public final boolean onBlockBreak(final Block block, final Player player, final IEssentials ess) { - User user = ess.getUser(player); + IUser user = ess.getUser(player); try { return onBlockBreak(block, user, getUsername(user), ess); } catch (SignException ex) { - ess.showError(user, ex, signName); + ess.showCommandError(user, signName, ex); } return false; } @@ -235,17 +237,17 @@ public class EssentialsSign return sign.getLine(0).matches("§1\\[.*\\]"); } - protected boolean onBlockPlace(final Block block, final User player, final String username, final IEssentials ess) throws SignException, ChargeException + protected boolean onBlockPlace(final Block block, final IUser player, final String username, final IEssentials ess) throws SignException, ChargeException { return true; } - protected boolean onBlockInteract(final Block block, final User player, final String username, final IEssentials ess) throws SignException, ChargeException + protected boolean onBlockInteract(final Block block, final IUser player, final String username, final IEssentials ess) throws SignException, ChargeException { return true; } - protected boolean onBlockBreak(final Block block, final User player, final String username, final IEssentials ess) throws SignException + protected boolean onBlockBreak(final Block block, final IUser player, final String username, final IEssentials ess) throws SignException { return true; } @@ -271,7 +273,7 @@ public class EssentialsSign } protected final void validateTrade(final ISign sign, final int amountIndex, final int itemIndex, - final User player, final IEssentials ess) throws SignException + final IUser player, final IEssentials ess) throws SignException { final Trade trade = getTrade(sign, amountIndex, itemIndex, player, ess); final ItemStack item = trade.getItemStack(); @@ -280,7 +282,7 @@ public class EssentialsSign } protected final Trade getTrade(final ISign sign, final int amountIndex, final int itemIndex, - final User player, final IEssentials ess) throws SignException + final IUser player, final IEssentials ess) throws SignException { final ItemStack item = getItemStack(sign.getLine(itemIndex), 1, ess); diff --git a/Essentials/src/com/earth2me/essentials/signs/SignBalance.java b/Essentials/src/com/earth2me/essentials/signs/SignBalance.java index 0b7328ba5..2ef64003a 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignBalance.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignBalance.java @@ -1,8 +1,8 @@ package com.earth2me.essentials.signs; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.IUser; public class SignBalance extends EssentialsSign @@ -13,7 +13,7 @@ public class SignBalance extends EssentialsSign } @Override - protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException + protected boolean onSignInteract(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException { player.sendMessage(_("balance", player.getMoney())); return true; diff --git a/Essentials/src/com/earth2me/essentials/signs/SignBuy.java b/Essentials/src/com/earth2me/essentials/signs/SignBuy.java index aa4e41426..fd84bd0f3 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignBuy.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignBuy.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.signs; import com.earth2me.essentials.ChargeException; -import com.earth2me.essentials.IEssentials; +import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; public class SignBuy extends EssentialsSign @@ -14,7 +14,7 @@ public class SignBuy extends EssentialsSign } @Override - protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException + protected boolean onSignCreate(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException { validateTrade(sign, 1, 2, player, ess); validateTrade(sign, 3, ess); @@ -22,7 +22,7 @@ public class SignBuy extends EssentialsSign } @Override - protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException + protected boolean onSignInteract(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException, ChargeException { final Trade items = getTrade(sign, 1, 2, player, ess); final Trade charge = getTrade(sign, 3, ess); diff --git a/Essentials/src/com/earth2me/essentials/signs/SignDisposal.java b/Essentials/src/com/earth2me/essentials/signs/SignDisposal.java index f747ac07c..a6c64ca0b 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignDisposal.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignDisposal.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.signs; -import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.craftbukkit.ShowInventory; @@ -13,7 +13,7 @@ public class SignDisposal extends EssentialsSign } @Override - protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) + protected boolean onSignInteract(final ISign sign, final IUser player, final String username, final IEssentials ess) { ShowInventory.showEmptyInventory(player.getBase()); return true; diff --git a/Essentials/src/com/earth2me/essentials/signs/SignEnchant.java b/Essentials/src/com/earth2me/essentials/signs/SignEnchant.java index 5907442d9..9d640c735 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignEnchant.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignEnchant.java @@ -2,8 +2,8 @@ package com.earth2me.essentials.signs; import com.earth2me.essentials.ChargeException; import com.earth2me.essentials.Enchantments; -import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.IUser; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; import com.earth2me.essentials.craftbukkit.InventoryWorkaround; @@ -21,7 +21,7 @@ public class SignEnchant extends EssentialsSign } @Override - protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException + protected boolean onSignCreate(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException, ChargeException { final ItemStack stack = sign.getLine(1).equals("*") || sign.getLine(1).equalsIgnoreCase("any") ? null : getItemStack(sign.getLine(1), 1, ess); final String[] enchantLevel = sign.getLine(2).split(":"); @@ -64,7 +64,7 @@ public class SignEnchant extends EssentialsSign } @Override - protected boolean onSignInteract(ISign sign, User player, String username, IEssentials ess) throws SignException, ChargeException + protected boolean onSignInteract(ISign sign, IUser player, String username, IEssentials ess) throws SignException, ChargeException { final ItemStack search = sign.getLine(1).equals("*") || sign.getLine(1).equalsIgnoreCase("any") ? null : getItemStack(sign.getLine(1), 1, ess); int slot = -1; diff --git a/Essentials/src/com/earth2me/essentials/signs/SignFree.java b/Essentials/src/com/earth2me/essentials/signs/SignFree.java index 7af7dffd7..0dad2b100 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignFree.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignFree.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.signs; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.IEssentials; +import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.craftbukkit.ShowInventory; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -17,14 +17,14 @@ public class SignFree extends EssentialsSign } @Override - protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException + protected boolean onSignCreate(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException { getItemStack(sign.getLine(1), 1, ess); return true; } @Override - protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException + protected boolean onSignInteract(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException { final ItemStack item = getItemStack(sign.getLine(1), 1, ess); if (item.getType() == Material.AIR) diff --git a/Essentials/src/com/earth2me/essentials/signs/SignGameMode.java b/Essentials/src/com/earth2me/essentials/signs/SignGameMode.java index 37a9fb1b8..05fb7c17f 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignGameMode.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignGameMode.java @@ -2,9 +2,9 @@ package com.earth2me.essentials.signs; import com.earth2me.essentials.ChargeException; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.IEssentials; +import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import java.util.Locale; import org.bukkit.GameMode; @@ -17,14 +17,14 @@ public class SignGameMode extends EssentialsSign } @Override - protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException + protected boolean onSignCreate(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException { validateTrade(sign, 1, ess); return true; } @Override - protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException + protected boolean onSignInteract(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException, ChargeException { final Trade charge = getTrade(sign, 1, ess); charge.isAffordableFor(player); diff --git a/Essentials/src/com/earth2me/essentials/signs/SignHeal.java b/Essentials/src/com/earth2me/essentials/signs/SignHeal.java index be8b7ba1d..3f412f5b4 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignHeal.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignHeal.java @@ -2,9 +2,9 @@ package com.earth2me.essentials.signs; import com.earth2me.essentials.ChargeException; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.IEssentials; +import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; public class SignHeal extends EssentialsSign @@ -15,14 +15,14 @@ public class SignHeal extends EssentialsSign } @Override - protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException + protected boolean onSignCreate(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException { validateTrade(sign, 1, ess); return true; } @Override - protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException + protected boolean onSignInteract(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException, ChargeException { final Trade charge = getTrade(sign, 1, ess); charge.isAffordableFor(player); diff --git a/Essentials/src/com/earth2me/essentials/signs/SignKit.java b/Essentials/src/com/earth2me/essentials/signs/SignKit.java index 32a169592..16f314d5f 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignKit.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignKit.java @@ -1,6 +1,8 @@ package com.earth2me.essentials.signs; import com.earth2me.essentials.*; +import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.IUser; import java.util.List; import java.util.Locale; import java.util.Map; @@ -14,7 +16,7 @@ public class SignKit extends EssentialsSign } @Override - protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException + protected boolean onSignCreate(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException { validateTrade(sign, 3, ess); @@ -45,7 +47,7 @@ public class SignKit extends EssentialsSign } @Override - protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException + protected boolean onSignInteract(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException, ChargeException { final String kitName = sign.getLine(1).toLowerCase(Locale.ENGLISH); final String group = sign.getLine(2); diff --git a/Essentials/src/com/earth2me/essentials/signs/SignMail.java b/Essentials/src/com/earth2me/essentials/signs/SignMail.java index b220fb2f5..7845c86a6 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignMail.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignMail.java @@ -1,8 +1,8 @@ package com.earth2me.essentials.signs; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.IUser; import java.util.List; @@ -14,10 +14,19 @@ public class SignMail extends EssentialsSign } @Override - protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException + protected boolean onSignInteract(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException { - final List mail = player.getMails(); - if (mail.isEmpty()) + final List mail; + player.acquireReadLock(); + try + { + mail = player.getData().getMails(); + } + finally + { + player.unlock(); + } + if (mail == null || mail.isEmpty()) { player.sendMessage(_("noNewMail")); return false; diff --git a/Essentials/src/com/earth2me/essentials/signs/SignProtection.java b/Essentials/src/com/earth2me/essentials/signs/SignProtection.java index f64b6f3f1..1ec05ec2d 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignProtection.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignProtection.java @@ -2,9 +2,9 @@ package com.earth2me.essentials.signs; import com.earth2me.essentials.ChargeException; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.IEssentials; +import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.Util; import java.util.*; import org.bukkit.Location; @@ -29,7 +29,7 @@ public class SignProtection extends EssentialsSign } @Override - protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException + protected boolean onSignCreate(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException, ChargeException { sign.setLine(3, "§4" + username); if (hasAdjacentBlock(sign.getBlock())) @@ -47,7 +47,7 @@ public class SignProtection extends EssentialsSign } @Override - protected boolean onSignBreak(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException + protected boolean onSignBreak(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException { final SignProtectionState state = checkProtectionSign(sign, player, username); return state == SignProtectionState.OWNER; @@ -73,7 +73,7 @@ public class SignProtection extends EssentialsSign return false; } - private void checkIfSignsAreBroken(final Block block, final User player, final String username, final IEssentials ess) + private void checkIfSignsAreBroken(final Block block, final IUser player, final String username, final IEssentials ess) { final Map signs = getConnectedSigns(block, player, username, false); for (Map.Entry entry : signs.entrySet()) @@ -91,14 +91,14 @@ public class SignProtection extends EssentialsSign } } - private Map getConnectedSigns(final Block block, final User user, final String username, boolean secure) + private Map getConnectedSigns(final Block block, final IUser user, final String username, boolean secure) { final Map signs = new HashMap(); getConnectedSigns(block, signs, user, username, secure ? 4 : 2); return signs; } - private void getConnectedSigns(final Block block, final Map signs, final User user, final String username, final int depth) + private void getConnectedSigns(final Block block, final Map signs, final IUser user, final String username, final int depth) { final Block[] faces = getAdjacentBlocks(block); for (Block b : faces) @@ -124,7 +124,7 @@ public class SignProtection extends EssentialsSign NOT_ALLOWED, ALLOWED, NOSIGN, OWNER } - private SignProtectionState checkProtectionSign(final Block block, final User user, final String username) + private SignProtectionState checkProtectionSign(final Block block, final IUser user, final String username) { if (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN) { @@ -137,7 +137,7 @@ public class SignProtection extends EssentialsSign return SignProtectionState.NOSIGN; } - private SignProtectionState checkProtectionSign(final ISign sign, final User user, final String username) + private SignProtectionState checkProtectionSign(final ISign sign, final IUser user, final String username) { if (user == null || username == null) { @@ -179,7 +179,7 @@ public class SignProtection extends EssentialsSign }; } - public SignProtectionState isBlockProtected(final Block block, final User user, final String username, boolean secure) + public SignProtectionState isBlockProtected(final Block block, final IUser user, final String username, boolean secure) { final Map signs = getConnectedSigns(block, user, username, secure); SignProtectionState retstate = SignProtectionState.NOSIGN; @@ -247,7 +247,7 @@ public class SignProtection extends EssentialsSign } @Override - protected boolean onBlockPlace(final Block block, final User player, final String username, final IEssentials ess) throws SignException + protected boolean onBlockPlace(final Block block, final IUser player, final String username, final IEssentials ess) throws SignException { for (Block adjBlock : getAdjacentBlocks(block)) { @@ -265,7 +265,7 @@ public class SignProtection extends EssentialsSign } @Override - protected boolean onBlockInteract(final Block block, final User player, final String username, final IEssentials ess) throws SignException + protected boolean onBlockInteract(final Block block, final IUser player, final String username, final IEssentials ess) throws SignException { final SignProtectionState state = isBlockProtected(block, player, username, false); @@ -286,7 +286,7 @@ public class SignProtection extends EssentialsSign } @Override - protected boolean onBlockBreak(final Block block, final User player, final String username, final IEssentials ess) throws SignException + protected boolean onBlockBreak(final Block block, final IUser player, final String username, final IEssentials ess) throws SignException { final SignProtectionState state = isBlockProtected(block, player, username, false); diff --git a/Essentials/src/com/earth2me/essentials/signs/SignSell.java b/Essentials/src/com/earth2me/essentials/signs/SignSell.java index 442a503c2..7a5f4969b 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignSell.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignSell.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.signs; import com.earth2me.essentials.ChargeException; -import com.earth2me.essentials.IEssentials; +import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; public class SignSell extends EssentialsSign @@ -14,7 +14,7 @@ public class SignSell extends EssentialsSign } @Override - protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException + protected boolean onSignCreate(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException { validateTrade(sign, 1, 2, player, ess); validateTrade(sign, 3, ess); @@ -22,7 +22,7 @@ public class SignSell extends EssentialsSign } @Override - protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException + protected boolean onSignInteract(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException, ChargeException { final Trade charge = getTrade(sign, 1, 2, player, ess); final Trade money = getTrade(sign, 3, ess); diff --git a/Essentials/src/com/earth2me/essentials/signs/SignSpawnmob.java b/Essentials/src/com/earth2me/essentials/signs/SignSpawnmob.java index 7c4cfcd54..f21d937b3 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignSpawnmob.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignSpawnmob.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.signs; import com.earth2me.essentials.ChargeException; -import com.earth2me.essentials.IEssentials; +import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.commands.Commandspawnmob; @@ -15,7 +15,7 @@ public class SignSpawnmob extends EssentialsSign } @Override - protected boolean onSignCreate(ISign sign, User player, String username, IEssentials ess) throws SignException, ChargeException + protected boolean onSignCreate(ISign sign, IUser player, String username, IEssentials ess) throws SignException, ChargeException { validateInteger(sign, 1); validateTrade(sign, 3, ess); @@ -23,7 +23,7 @@ public class SignSpawnmob extends EssentialsSign } @Override - protected boolean onSignInteract(ISign sign, User player, String username, IEssentials ess) throws SignException, ChargeException + protected boolean onSignInteract(ISign sign, IUser player, String username, IEssentials ess) throws SignException, ChargeException { final Trade charge = getTrade(sign, 3, ess); charge.isAffordableFor(player); diff --git a/Essentials/src/com/earth2me/essentials/signs/SignTime.java b/Essentials/src/com/earth2me/essentials/signs/SignTime.java index 99c579ff4..2d1ab2a87 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignTime.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignTime.java @@ -2,9 +2,9 @@ package com.earth2me.essentials.signs; import com.earth2me.essentials.ChargeException; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.IEssentials; +import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; public class SignTime extends EssentialsSign @@ -15,7 +15,7 @@ public class SignTime extends EssentialsSign } @Override - protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException + protected boolean onSignCreate(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException { validateTrade(sign, 2, ess); final String timeString = sign.getLine(1); @@ -33,7 +33,7 @@ public class SignTime extends EssentialsSign } @Override - protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException + protected boolean onSignInteract(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException, ChargeException { final Trade charge = getTrade(sign, 2, ess); charge.isAffordableFor(player); diff --git a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java index 9296eb6f4..aaec002d4 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java @@ -2,6 +2,8 @@ package com.earth2me.essentials.signs; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.*; +import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.IUser; import org.bukkit.inventory.ItemStack; //TODO: Sell Enchantment on Trade signs? @@ -13,7 +15,7 @@ public class SignTrade extends EssentialsSign } @Override - protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException + protected boolean onSignCreate(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException, ChargeException { validateTrade(sign, 1, false, ess); validateTrade(sign, 2, true, ess); @@ -26,7 +28,7 @@ public class SignTrade extends EssentialsSign } @Override - protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException + protected boolean onSignInteract(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException, ChargeException { if (sign.getLine(3).substring(2).equalsIgnoreCase(username)) { @@ -65,7 +67,7 @@ public class SignTrade extends EssentialsSign return true; } - private Trade rechargeSign(final ISign sign, final IEssentials ess, final User player) throws SignException, ChargeException + private Trade rechargeSign(final ISign sign, final IEssentials ess, final IUser player) throws SignException, ChargeException { final Trade trade = getTrade(sign, 2, false, false, ess); if (trade.getItemStack() != null && player.getItemInHand() != null @@ -89,7 +91,7 @@ public class SignTrade extends EssentialsSign } @Override - protected boolean onSignBreak(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException + protected boolean onSignBreak(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException { if ((sign.getLine(3).length() > 3 && sign.getLine(3).substring(2).equalsIgnoreCase(username)) || player.isAuthorized("essentials.signs.trade.override")) diff --git a/Essentials/src/com/earth2me/essentials/signs/SignWarp.java b/Essentials/src/com/earth2me/essentials/signs/SignWarp.java index 76e8e730b..33ff7aa8a 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignWarp.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignWarp.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.signs; import com.earth2me.essentials.ChargeException; -import com.earth2me.essentials.IEssentials; +import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -15,7 +15,7 @@ public class SignWarp extends EssentialsSign } @Override - protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException + protected boolean onSignCreate(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException { validateTrade(sign, 3, ess); final String warpName = sign.getLine(1); @@ -29,7 +29,7 @@ public class SignWarp extends EssentialsSign { try { - ess.getWarps().getWarp(warpName); + ess.getWarps2().getWarp(warpName); } catch (Exception ex) { @@ -45,7 +45,7 @@ public class SignWarp extends EssentialsSign } @Override - protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException + protected boolean onSignInteract(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException, ChargeException { final String warpName = sign.getLine(1); final String group = sign.getLine(2); diff --git a/Essentials/src/com/earth2me/essentials/signs/SignWeather.java b/Essentials/src/com/earth2me/essentials/signs/SignWeather.java index 559fcc2e3..c674e04a9 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignWeather.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignWeather.java @@ -2,9 +2,9 @@ package com.earth2me.essentials.signs; import com.earth2me.essentials.ChargeException; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.IEssentials; +import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; public class SignWeather extends EssentialsSign @@ -15,7 +15,7 @@ public class SignWeather extends EssentialsSign } @Override - protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException + protected boolean onSignCreate(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException { validateTrade(sign, 2, ess); final String timeString = sign.getLine(1); @@ -33,7 +33,7 @@ public class SignWeather extends EssentialsSign } @Override - protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException + protected boolean onSignInteract(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException, ChargeException { final Trade charge = getTrade(sign, 2, ess); charge.isAffordableFor(player); diff --git a/Essentials/src/com/earth2me/essentials/textreader/HelpInput.java b/Essentials/src/com/earth2me/essentials/textreader/HelpInput.java index 85c00c1b6..7d8fc78d0 100644 --- a/Essentials/src/com/earth2me/essentials/textreader/HelpInput.java +++ b/Essentials/src/com/earth2me/essentials/textreader/HelpInput.java @@ -1,12 +1,14 @@ package com.earth2me.essentials.textreader; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.ISettings; +import com.earth2me.essentials.api.IUser; import java.io.IOException; import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; +import lombok.Cleanup; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; @@ -21,8 +23,11 @@ public class HelpInput implements IText private final transient Map bookmarks = new HashMap(); private final static Logger logger = Logger.getLogger("Minecraft"); - public HelpInput(final User user, final String match, final IEssentials ess) throws IOException + public HelpInput(final IUser user, final String match, final IEssentials ess) throws IOException { + @Cleanup + final ISettings settings = ess.getSettings(); + settings.acquireReadLock(); boolean reported = false; String pluginName = ""; for (Plugin p : ess.getServer().getPluginManager().getPlugins()) @@ -48,14 +53,14 @@ public class HelpInput implements IText if (pluginName.contains("essentials")) { final String node = "essentials." + k.getKey(); - if (!ess.getSettings().isCommandDisabled(k.getKey()) && user.isAuthorized(node)) + if (!settings.getData().getCommands().isDisabled(k.getKey()) && user.isAuthorized(node)) { lines.add("§c" + k.getKey() + "§7: " + k.getValue().get(DESCRIPTION)); } } else { - if (ess.getSettings().showNonEssCommandsInHelp()) + if (settings.getData().getCommands().getHelp().isShowNonEssCommandsInHelp()) { final HashMap value = k.getValue(); Object permissions = null; @@ -96,7 +101,7 @@ public class HelpInput implements IText } else { - if (!ess.getSettings().hidePermissionlessHelp()) + if (!settings.getData().getCommands().getHelp().isHidePermissionlessCommands()) { lines.add("§c" + k.getKey() + "§7: " + value.get(DESCRIPTION)); } diff --git a/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java b/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java index 182dba9d3..66a66c570 100644 --- a/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java +++ b/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java @@ -1,12 +1,13 @@ package com.earth2me.essentials.textreader; import com.earth2me.essentials.DescParseTickFormat; -import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.IUser; import java.text.DateFormat; import java.util.Date; import java.util.List; import java.util.Map; +import lombok.Cleanup; import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -33,11 +34,13 @@ public class KeywordReplacer implements IText String version; if (sender instanceof Player) { - final User user = ess.getUser(sender); + @Cleanup + final IUser user = ess.getUser(sender); + user.acquireReadLock(); displayName = user.getDisplayName(); ipAddress = user.getAddress().getAddress().toString(); balance = Double.toString(user.getMoney()); - mails = Integer.toString(user.getMails().size()); + mails = Integer.toString(user.getData().getMails() == null ? 0 : user.getData().getMails().size()); world = user.getLocation().getWorld().getName(); worldTime12 = DescParseTickFormat.format12(user.getWorld().getTime()); worldTime24 = DescParseTickFormat.format24(user.getWorld().getTime()); @@ -98,7 +101,7 @@ public class KeywordReplacer implements IText date = DateFormat.getDateInstance(DateFormat.MEDIUM, ess.getI18n().getCurrentLocale()).format(new Date()); time = DateFormat.getTimeInstance(DateFormat.MEDIUM, ess.getI18n().getCurrentLocale()).format(new Date()); - + version = ess.getServer().getVersion(); for (int i = 0; i < input.getLines().size(); i++) diff --git a/Essentials/src/com/earth2me/essentials/textreader/TextInput.java b/Essentials/src/com/earth2me/essentials/textreader/TextInput.java index b25c30d51..22cdf6f80 100644 --- a/Essentials/src/com/earth2me/essentials/textreader/TextInput.java +++ b/Essentials/src/com/earth2me/essentials/textreader/TextInput.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.textreader; -import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.Util; import java.io.*; import java.util.*; @@ -21,7 +21,7 @@ public class TextInput implements IText File file = null; if (sender instanceof Player) { - final User user = ess.getUser(sender); + final IUser user = ess.getUser(sender); file = new File(ess.getDataFolder(), filename + "_" + Util.sanitizeFileName(user.getName()) + ".txt"); if (!file.exists()) { diff --git a/Essentials/src/com/earth2me/essentials/user/Inventory.java b/Essentials/src/com/earth2me/essentials/user/Inventory.java index 0812f54a0..c39df0d54 100644 --- a/Essentials/src/com/earth2me/essentials/user/Inventory.java +++ b/Essentials/src/com/earth2me/essentials/user/Inventory.java @@ -18,10 +18,42 @@ public class Inventory implements StorageObject private int size; @MapKeyType(Integer.class) @MapValueType(ItemStack.class) - private Map items = new HashMap(); + private Map items = null; public Inventory() { - items.put(1, new ItemStack(Material.APPLE, 64)); + } + + public Inventory(ItemStack[] contents) + { + size = contents.length; + if (items == null) { + items = new HashMap(size); + } + items.clear(); + for (int i = 0; i < contents.length; i++) + { + ItemStack itemStack = contents[i]; + if (itemStack == null) { + continue; + } + items.put(i, itemStack); + } + } + + public ItemStack[] getBukkitInventory() + { + if (items == null) { + throw new IllegalStateException(); + } + final ItemStack[] inventory = new ItemStack[size]; + for (Map.Entry entry : items.entrySet()) + { + if (entry.getKey() < 0 || entry.getKey()>= size) { + continue; + } + inventory[entry.getKey()] = entry.getValue(); + } + return inventory; } } diff --git a/Essentials/src/com/earth2me/essentials/user/User.java b/Essentials/src/com/earth2me/essentials/user/User.java index bc1ebfe23..0dcd8c494 100644 --- a/Essentials/src/com/earth2me/essentials/user/User.java +++ b/Essentials/src/com/earth2me/essentials/user/User.java @@ -9,10 +9,10 @@ import com.earth2me.essentials.api.IGroups; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.commands.IEssentialsCommand; import com.earth2me.essentials.register.payment.Method; -import com.earth2me.essentials.settings.WorldOptions; import static com.earth2me.essentials.I18n._; import java.util.Calendar; import java.util.GregorianCalendar; +import java.util.List; import java.util.logging.Logger; import lombok.Cleanup; import lombok.Getter; @@ -29,7 +29,9 @@ public class User extends UserBase implements IUser @Getter @Setter private CommandSender replyTo = null; + @Getter private transient User teleportRequester; + @Getter private transient boolean teleportRequestHere; @Getter private transient final Teleport teleport; @@ -100,7 +102,7 @@ public class User extends UserBase implements IUser return isAuthorized(permissionPrefix + (cmd.getName().equals("r") ? "msg" : cmd.getName())); } - public void checkCooldown(final UserData.TimestampType cooldownType,final double cooldown, final boolean set, final String bypassPermission) throws CooldownException + public void checkCooldown(final UserData.TimestampType cooldownType, final double cooldown, final boolean set, final String bypassPermission) throws CooldownException { final Calendar now = new GregorianCalendar(); if (getTimestamp(cooldownType) > 0) @@ -114,7 +116,8 @@ public class User extends UserBase implements IUser throw new CooldownException(Util.formatDateDiff(cooldownTime.getTimeInMillis())); } } - if (set) { + if (set) + { setTimestamp(cooldownType, now.getTimeInMillis()); } } @@ -148,7 +151,7 @@ public class User extends UserBase implements IUser } } - public void payUser(final User reciever, final double value) throws Exception + public void payUser(final IUser reciever, final double value) throws Exception { if (value == 0) { @@ -224,16 +227,6 @@ public class User extends UserBase implements IUser teleportRequestHere = here; } - public User getTeleportRequest() - { - return teleportRequester; - } - - public boolean isTeleportRequestHere() - { - return teleportRequestHere; - } - public String getNick(boolean addprefixsuffix) { acquireReadLock(); @@ -305,7 +298,7 @@ public class User extends UserBase implements IUser { return super.getDisplayName() == null ? super.getName() : super.getDisplayName(); } - + @Override public void updateDisplayName() { @@ -586,4 +579,37 @@ public class User extends UserBase implements IUser { throw new UnsupportedOperationException("Not supported yet."); } + + @Override + public void updateCompass() + { + try + { + Location loc = getHome(getLocation()); + if (loc == null) + { + loc = getBedSpawnLocation(); + } + if (loc != null) + { + setCompassTarget(loc); + } + } + catch (Exception ex) + { + // Ignore + } + } + + @Override + public List getHomes() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public int compareTo(final IUser t) + { + return Util.stripColor(this.getDisplayName()).compareTo(Util.stripColor(t.getDisplayName())); + } } diff --git a/Essentials/src/com/earth2me/essentials/user/UserBase.java b/Essentials/src/com/earth2me/essentials/user/UserBase.java index 3a67efdd2..73eb1f913 100644 --- a/Essentials/src/com/earth2me/essentials/user/UserBase.java +++ b/Essentials/src/com/earth2me/essentials/user/UserBase.java @@ -6,7 +6,10 @@ import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.craftbukkit.OfflineBedLocation; import com.earth2me.essentials.storage.AsyncStorageObjectHolder; import java.io.File; +import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; +import java.util.Locale; import java.util.Map; import lombok.Cleanup; import lombok.Delegate; @@ -268,4 +271,99 @@ public abstract class UserBase extends AsyncStorageObjectHolder implem unlock(); } } + + public boolean toggleMuted() + { + acquireWriteLock(); + try + { + boolean ret = !getData().isMuted(); + getData().setMuted(ret); + return ret; + } + finally + { + unlock(); + } + } + + public boolean toggleSocialSpy() + { + acquireWriteLock(); + try + { + boolean ret = !getData().isSocialspy(); + getData().setSocialspy(ret); + return ret; + } + finally + { + unlock(); + } + } + + public boolean toggleTeleportEnabled() + { + acquireWriteLock(); + try + { + boolean ret = !getData().isTeleportEnabled(); + getData().setTeleportEnabled(ret); + return ret; + } + finally + { + unlock(); + } + } + + public boolean isIgnoringPlayer(final String name) + { + acquireReadLock(); + try + { + return getData().getIgnore() == null ? false : getData().getIgnore().contains(name.toLowerCase(Locale.ENGLISH)); + } + finally + { + unlock(); + } + } + + public void setIgnoredPlayer(final String name, final boolean set) + { + acquireWriteLock(); + try + { + if (getData().getIgnore() == null) + { + getData().setIgnore(new HashSet()); + } + if (set) + { + getData().getIgnore().add(name.toLowerCase(Locale.ENGLISH)); + } + else + { + getData().getIgnore().remove(name.toLowerCase(Locale.ENGLISH)); + } + } + finally + { + unlock(); + } + } + + public void addMail(String string) + { + acquireWriteLock(); + try { + if (getData().getMails() == null) { + getData().setMails(new ArrayList()); + } + getData().getMails().add(string); + } finally { + unlock(); + } + } } diff --git a/Essentials/src/com/earth2me/essentials/user/UserData.java b/Essentials/src/com/earth2me/essentials/user/UserData.java index f36f42eed..b9eb61008 100644 --- a/Essentials/src/com/earth2me/essentials/user/UserData.java +++ b/Essentials/src/com/earth2me/essentials/user/UserData.java @@ -17,7 +17,7 @@ public class UserData implements StorageObject { public enum TimestampType { - JAIL, MUTE, LASTHEAL, LASTTELEPORT, LOGIN + JAIL, MUTE, LASTHEAL, LASTTELEPORT, LOGIN, LOGOUT } private String nickname; private Double money; @@ -69,4 +69,12 @@ public class UserData implements StorageObject { return powerTools == null ? Collections.emptyList() : powerTools.get(mat); } + + public void removeHome(String home) + { + if (homes == null) { + return; + } + homes.remove(home); + } }