1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-18 20:41:37 +02:00

Fixing some bugs in 3.0

This commit is contained in:
snowleo
2013-03-03 14:48:57 +01:00
parent af93487eef
commit e5b26fc061
26 changed files with 121 additions and 140 deletions

2
.gitignore vendored
View File

@@ -31,3 +31,5 @@ manifest.mf
*.ipr *.ipr
*.iws *.iws
.idea/ .idea/
/EssentialsRelease/

View File

@@ -101,7 +101,7 @@ public class Teleport implements Runnable, ITeleport
chargeFor.charge(user); chargeFor.charge(user);
} }
} }
catch (Throwable ex) catch (Exception ex)
{ {
ess.getCommandHandler().showCommandError(user, "teleport", ex); ess.getCommandHandler().showCommandError(user, "teleport", ex);
} }

View File

@@ -3,5 +3,5 @@ package net.ess3.api;
public interface IBackup extends Runnable public interface IBackup extends Runnable
{ {
public void startTask(); void startTask();
} }

View File

@@ -10,9 +10,9 @@ public interface ICommandHandler extends IReload, TabExecutor
{ {
Map<String, String> disabledCommands(); Map<String, String> disabledCommands();
public void removePlugin(Plugin plugin); void removePlugin(Plugin plugin);
public void addPlugin(Plugin plugin); void addPlugin(Plugin plugin);
void showCommandError(CommandSender sender, String commandLabel, Throwable exception); void showCommandError(CommandSender sender, String commandLabel, Throwable exception);
} }

View File

@@ -3,19 +3,19 @@ package net.ess3.api;
public interface IEconomy extends IReload public interface IEconomy extends IReload
{ {
public double getMoney(String name) throws UserDoesNotExistException; double getMoney(String name) throws UserDoesNotExistException;
public void setMoney(String name, double balance) throws UserDoesNotExistException, NoLoanPermittedException; void setMoney(String name, double balance) throws UserDoesNotExistException, NoLoanPermittedException;
public void resetBalance(String name) throws UserDoesNotExistException, NoLoanPermittedException; void resetBalance(String name) throws UserDoesNotExistException, NoLoanPermittedException;
public String format(double amount); String format(double amount);
public boolean playerExists(String name); boolean playerExists(String name);
public boolean isNPC(String name) throws UserDoesNotExistException; boolean isNPC(String name) throws UserDoesNotExistException;
public boolean createNPC(String name); boolean createNPC(String name);
public void removeNPC(String name) throws UserDoesNotExistException; void removeNPC(String name) throws UserDoesNotExistException;
} }

View File

@@ -1,6 +0,0 @@
package net.ess3.api;
public interface IEssentialsModule
{
}

View File

@@ -9,7 +9,6 @@ import org.bukkit.scheduler.BukkitTask;
public interface IPlugin extends Plugin public interface IPlugin extends Plugin
{ {
/** /**
* Get an instance of essentials * Get an instance of essentials
* *
@@ -36,16 +35,18 @@ public interface IPlugin extends Plugin
/** /**
* Call an a-sync task to be run with a given delay * Call an a-sync task to be run with a given delay
* *
* @param run - Code to be run * @param run - Code to be run
* @param delay - Long that represents how long to wait * @param delay - Long that represents how long to wait
* @return - BukkitTask for the task created * @return - BukkitTask for the task created
*/ */
BukkitTask runTaskLaterAsynchronously(final Runnable run, final long delay); BukkitTask runTaskLaterAsynchronously(final Runnable run, final long delay);
BukkitTask runTaskTimerAsynchronously(final Runnable run, final long delay, final long delay2);
/** /**
* Schedule a sync (ran in main thread) delayed task * Schedule a sync (ran in main thread) delayed task
* *
* @param run - Code to run * @param run - Code to run
* @param delay - Long that represents how long to wait * @param delay - Long that represents how long to wait
* @return - Integer of the task ID * @return - Integer of the task ID
*/ */
@@ -54,8 +55,8 @@ public interface IPlugin extends Plugin
/** /**
* Schedule a sync (in the main thread) repeating task * Schedule a sync (in the main thread) repeating task
* *
* @param run - Code to run * @param run - Code to run
* @param delay - Delay for the first run * @param delay - Delay for the first run
* @param period - Time to wait between every run after the first * @param period - Time to wait between every run after the first
* @return - int of the task ID * @return - int of the task ID
*/ */
@@ -64,8 +65,8 @@ public interface IPlugin extends Plugin
/** /**
* Schedule an a-sync repeating task * Schedule an a-sync repeating task
* *
* @param run - Code to run * @param run - Code to run
* @param delay - Delay for the first run * @param delay - Delay for the first run
* @param period - Time to wait between every run after the first * @param period - Time to wait between every run after the first
* @return - int of the task ID * @return - int of the task ID
*/ */
@@ -105,8 +106,8 @@ public interface IPlugin extends Plugin
/** /**
* Call a re-spawn event on a player * Call a re-spawn event on a player
* *
* @param player - Player to re-spawn * @param player - Player to re-spawn
* @param loc - Location to send * @param loc - Location to send
* @param bedSpawn - do you use bed? * @param bedSpawn - do you use bed?
* @return - Location after event called * @return - Location after event called
*/ */
@@ -125,11 +126,11 @@ public interface IPlugin extends Plugin
* @param name * @param name
* @return * @return
*/ */
public boolean isModuleEnabled(String name); boolean isModuleEnabled(String name);
public void onPluginEnable(Plugin plugin); void onPluginEnable(Plugin plugin);
public void onPluginDisable(Plugin plugin); void onPluginDisable(Plugin plugin);
/** /**
* Register a module with Essentials * Register a module with Essentials
@@ -137,5 +138,4 @@ public interface IPlugin extends Plugin
* @param module - Your plugin instance * @param module - Your plugin instance
*/ */
void registerModule(Plugin module); void registerModule(Plugin module);
} }

View File

@@ -6,9 +6,9 @@ import net.ess3.storage.IStorageObjectHolder;
public interface ISettings extends IStorageObjectHolder<Settings> public interface ISettings extends IStorageObjectHolder<Settings>
{ {
public String getLocale(); String getLocale();
public boolean isDebug(); boolean isDebug();
public void setDebug(boolean b); void setDebug(boolean b);
} }

View File

@@ -12,9 +12,9 @@ public interface ITeleport
/** /**
* Teleport to a location now * Teleport to a location now
* *
* @param loc - location to send to * @param loc - location to send to
* @param cooldown - To check cooldown * @param cooldown - To check cooldown
* @param cause - Why was the send caused? Use a {@link TeleportCause} * @param cause - Why was the send caused? Use a {@link TeleportCause}
* @throws Exception * @throws Exception
*/ */
void now(Location loc, boolean cooldown, TeleportCause cause) throws Exception; void now(Location loc, boolean cooldown, TeleportCause cause) throws Exception;
@@ -37,5 +37,5 @@ public interface ITeleport
void back() throws Exception; void back() throws Exception;
public void warp(String name, Trade charge, TeleportCause teleportCause) throws Exception; void warp(String name, Trade charge, TeleportCause teleportCause) throws Exception;
} }

View File

@@ -105,11 +105,11 @@ public interface IUser extends OfflinePlayer, CommandSender, IStorageObjectHolde
List<String> getMails(); List<String> getMails();
public boolean canAfford(double money); boolean canAfford(double money);
public void updateMoneyCache(double userMoney); void updateMoneyCache(double userMoney);
public boolean canAfford(double amount, boolean b); boolean canAfford(double amount, boolean b);
boolean isVanished(); boolean isVanished();
@@ -133,9 +133,9 @@ public interface IUser extends OfflinePlayer, CommandSender, IStorageObjectHolde
boolean checkSignThrottle(int throttle); boolean checkSignThrottle(int throttle);
public boolean isRecipeSee(); boolean isRecipeSee();
public void setRecipeSee(boolean recipeSee); void setRecipeSee(boolean recipeSee);
/** /**
* Since the Player object should not be stored for a long time, this method should be called again with a null * Since the Player object should not be stored for a long time, this method should be called again with a null

View File

@@ -49,7 +49,7 @@ public interface IUserMap extends IReload
Set<IUser> matchUsersExcludingHidden(final String name, final Player requester); Set<IUser> matchUsersExcludingHidden(final String name, final Player requester);
public void addPrejoinedPlayer(Player player); void addPrejoinedPlayer(Player player);
public void removePrejoinedPlayer(Player player); void removePrejoinedPlayer(Player player);
} }

View File

@@ -35,7 +35,7 @@ public interface IWarps extends IReload
* Set a warp * Set a warp
* *
* @param name - Name of warp * @param name - Name of warp
* @param loc - Location of warp * @param loc - Location of warp
* @throws Exception * @throws Exception
*/ */
void setWarp(String name, Location loc) throws Exception; void setWarp(String name, Location loc) throws Exception;
@@ -45,7 +45,7 @@ public interface IWarps extends IReload
* *
* @return * @return
*/ */
public boolean isEmpty(); boolean isEmpty();
/** /**
* Get a warp file * Get a warp file
@@ -54,5 +54,5 @@ public interface IWarps extends IReload
* @return - an instance of the file * @return - an instance of the file
* @throws InvalidNameException - When the file is not found * @throws InvalidNameException - When the file is not found
*/ */
public File getWarpFile(String name) throws InvalidNameException; File getWarpFile(String name) throws InvalidNameException;
} }

View File

@@ -149,6 +149,12 @@ public class BukkitPlugin extends JavaPlugin implements IPlugin
{ {
return getServer().getScheduler().runTaskLaterAsynchronously(this, run, delay); return getServer().getScheduler().runTaskLaterAsynchronously(this, run, delay);
} }
@Override
public BukkitTask runTaskTimerAsynchronously(final Runnable run, final long delay, final long delay2)
{
return getServer().getScheduler().runTaskTimerAsynchronously(this, run, delay, delay2);
}
@Override @Override
public int scheduleSyncDelayedTask(final Runnable run, final long delay) public int scheduleSyncDelayedTask(final Runnable run, final long delay)

View File

@@ -20,7 +20,7 @@ public class Commandpowertool extends EssentialsCommand
String command = getFinalArg(args, 0); String command = getFinalArg(args, 0);
UserData userData = user.getData(); UserData userData = user.getData();
// check to see if this is a clear all command // check to see if this is a clear all command
if (command != null && command.equalsIgnoreCase("d:")) if (command.equalsIgnoreCase("d:"))
{ {
userData.clearAllPowertools(); userData.clearAllPowertools();
user.queueSave(); user.queueSave();
@@ -36,7 +36,7 @@ public class Commandpowertool extends EssentialsCommand
final String itemName = itemStack.getType().toString().toLowerCase(Locale.ENGLISH).replaceAll("_", " "); final String itemName = itemStack.getType().toString().toLowerCase(Locale.ENGLISH).replaceAll("_", " ");
List<String> powertools = userData.getPowertool(itemStack.getType()); List<String> powertools = userData.getPowertool(itemStack.getType());
if (command != null && !command.isEmpty()) if (!command.isEmpty())
{ {
if (command.equalsIgnoreCase("l:")) if (command.equalsIgnoreCase("l:"))
{ {

View File

@@ -32,7 +32,7 @@ public class Commandr extends EssentialsCommand
} }
else else
{ {
message = FormatUtil.replaceFormat(message); message = FormatUtil.stripFormat(message);
} }
replyTo = user; replyTo = user;
senderName = user.getPlayer().getDisplayName(); senderName = user.getPlayer().getDisplayName();

View File

@@ -60,7 +60,7 @@ public class Commandspawner extends EssentialsCommand
charge.charge(user); charge.charge(user);
user.sendMessage(_("setSpawner", mob.getName())); user.sendMessage(_("setSpawner", mob.getName()));
} }
catch (Throwable ex) catch (Exception ex)
{ {
throw new Exception(_("mobSpawnError"), ex); throw new Exception(_("mobSpawnError"), ex);
} }

View File

@@ -4,7 +4,6 @@ import java.util.List;
import java.util.logging.Logger; import java.util.logging.Logger;
import static net.ess3.I18n._; import static net.ess3.I18n._;
import net.ess3.api.IEssentials; import net.ess3.api.IEssentials;
import net.ess3.api.IEssentialsModule;
import net.ess3.api.IUser; import net.ess3.api.IUser;
import net.ess3.economy.Trade; import net.ess3.economy.Trade;
import net.ess3.permissions.AbstractSuperpermsPermission; import net.ess3.permissions.AbstractSuperpermsPermission;
@@ -18,7 +17,6 @@ public abstract class EssentialsCommand extends AbstractSuperpermsPermission imp
{ {
protected String commandName; protected String commandName;
protected IEssentials ess; protected IEssentials ess;
protected IEssentialsModule module;
protected Server server; protected Server server;
protected Logger logger; protected Logger logger;
private String permission; private String permission;
@@ -33,12 +31,6 @@ public abstract class EssentialsCommand extends AbstractSuperpermsPermission imp
this.permission = "essentials." + commandName; this.permission = "essentials." + commandName;
} }
@Override
public void setEssentialsModule(final IEssentialsModule module)
{
this.module = module;
}
@Override @Override
public final void run(final IUser user, final Command cmd, final String commandLabel, final String[] args) throws Exception public final void run(final IUser user, final Command cmd, final String commandLabel, final String[] args) throws Exception
{ {

View File

@@ -17,7 +17,6 @@ public class EssentialsCommandHandler implements ICommandHandler, TabExecutor
private final ClassLoader classLoader; private final ClassLoader classLoader;
private final String commandPath; private final String commandPath;
private final String permissionPrefix;// TODO: Needed? private final String permissionPrefix;// TODO: Needed?
private final IEssentialsModule module;
private static final Logger LOGGER = Bukkit.getLogger(); private static final Logger LOGGER = Bukkit.getLogger();
private final Map<String, List<PluginCommand>> altcommands = new HashMap<String, List<PluginCommand>>(); private final Map<String, List<PluginCommand>> altcommands = new HashMap<String, List<PluginCommand>>();
private final Map<String, String> disabledList = new HashMap<String, String>(); private final Map<String, String> disabledList = new HashMap<String, String>();
@@ -25,16 +24,10 @@ public class EssentialsCommandHandler implements ICommandHandler, TabExecutor
private final IEssentials ess; private final IEssentials ess;
public EssentialsCommandHandler(ClassLoader classLoader, String commandPath, String permissionPrefix, IEssentials ess) public EssentialsCommandHandler(ClassLoader classLoader, String commandPath, String permissionPrefix, IEssentials ess)
{
this(classLoader, commandPath, permissionPrefix, null, ess);
}
public EssentialsCommandHandler(ClassLoader classLoader, String commandPath, String permissionPrefix, IEssentialsModule module, IEssentials ess)
{ {
this.classLoader = classLoader; this.classLoader = classLoader;
this.commandPath = commandPath; this.commandPath = commandPath;
this.permissionPrefix = permissionPrefix; this.permissionPrefix = permissionPrefix;
this.module = module;
this.ess = ess; this.ess = ess;
for (Plugin plugin : ess.getServer().getPluginManager().getPlugins()) for (Plugin plugin : ess.getServer().getPluginManager().getPlugins())
{ {
@@ -104,7 +97,6 @@ public class EssentialsCommandHandler implements ICommandHandler, TabExecutor
{ {
cmd = (IEssentialsCommand)classLoader.loadClass(commandPath + commandName).newInstance(); cmd = (IEssentialsCommand)classLoader.loadClass(commandPath + commandName).newInstance();
cmd.init(ess, commandName); cmd.init(ess, commandName);
cmd.setEssentialsModule(module);
commands.put(commandName, cmd); commands.put(commandName, cmd);
if (command instanceof PluginCommand) if (command instanceof PluginCommand)
{ {
@@ -163,13 +155,13 @@ public class EssentialsCommandHandler implements ICommandHandler, TabExecutor
} }
return true; return true;
} }
catch (Throwable ex) catch (Exception ex)
{ {
showCommandError(sender, commandLabel, ex); showCommandError(sender, commandLabel, ex);
return true; return true;
} }
} }
catch (Throwable ex) catch (Exception ex)
{ {
LOGGER.log(Level.SEVERE, _("commandFailed", commandLabel), ex); LOGGER.log(Level.SEVERE, _("commandFailed", commandLabel), ex);
return true; return true;
@@ -236,7 +228,6 @@ public class EssentialsCommandHandler implements ICommandHandler, TabExecutor
{ {
cmd = (IEssentialsCommand)classLoader.loadClass(commandPath + commandName).newInstance(); cmd = (IEssentialsCommand)classLoader.loadClass(commandPath + commandName).newInstance();
cmd.init(ess, commandName); cmd.init(ess, commandName);
cmd.setEssentialsModule(module);
commands.put(commandName, cmd); commands.put(commandName, cmd);
if (command instanceof PluginCommand) if (command instanceof PluginCommand)
{ {
@@ -280,13 +271,13 @@ public class EssentialsCommandHandler implements ICommandHandler, TabExecutor
} }
} }
} }
catch (Throwable ex) catch (Exception ex)
{ {
showCommandError(sender, commandLabel, ex); showCommandError(sender, commandLabel, ex);
return null; return null;
} }
} }
catch (Throwable ex) catch (Exception ex)
{ {
LOGGER.log(Level.SEVERE, _("commandFailed", commandLabel), ex); LOGGER.log(Level.SEVERE, _("commandFailed", commandLabel), ex);
return null; return null;

View File

@@ -2,7 +2,6 @@ package net.ess3.commands;
import java.util.List; import java.util.List;
import net.ess3.api.IEssentials; import net.ess3.api.IEssentials;
import net.ess3.api.IEssentialsModule;
import net.ess3.api.IPermission; import net.ess3.api.IPermission;
import net.ess3.api.IUser; import net.ess3.api.IUser;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@@ -20,6 +19,4 @@ public interface IEssentialsCommand extends IPermission
List<String> tabComplete(CommandSender sender, Command cmd, String commandLabel, String[] args); List<String> tabComplete(CommandSender sender, Command cmd, String commandLabel, String[] args);
void init(IEssentials ess, String commandLabel); void init(IEssentials ess, String commandLabel);
void setEssentialsModule(IEssentialsModule module);
} }

View File

@@ -131,7 +131,7 @@ public class EssentialsPlayerListener implements Listener
} }
else else
{ {
event.setQuitMessage(quitMessage); event.setQuitMessage(null);
} }

View File

@@ -166,22 +166,22 @@ public enum Permissions implements IPermission
return PermissionFactory.checkPermission(sender, this); return PermissionFactory.checkPermission(sender, this);
} }
public static DotStarPermission ENCHANT = new DotStarPermission("essentials.enchant"); public static final DotStarPermission ENCHANT = new DotStarPermission("essentials.enchant");
public static DotStarPermission PERGROUPTELEPORT = new DotStarPermission("essentials.teleport.groups"); public static final DotStarPermission PERGROUPTELEPORT = new DotStarPermission("essentials.teleport.groups");
public static MaterialDotStarPermission GIVE = new MaterialDotStarPermission("essentials.give", PermissionDefault.TRUE); public static final MaterialDotStarPermission GIVE = new MaterialDotStarPermission("essentials.give", PermissionDefault.TRUE);
public static DotStarPermission RANKS = new DotStarPermission("essentials.ranks"); public static final DotStarPermission RANKS = new DotStarPermission("essentials.ranks");
public static DotStarPermission HELP = new DotStarPermission("essentials.help"); public static final DotStarPermission HELP = new DotStarPermission("essentials.help");
public static MaterialDotStarPermission ITEMSPAWN = new MaterialDotStarPermission("essentials.itemspawn", PermissionDefault.TRUE); public static final MaterialDotStarPermission ITEMSPAWN = new MaterialDotStarPermission("essentials.itemspawn", PermissionDefault.TRUE);
public static DotStarPermission KITS = new DotStarPermission("essentials.kits", PermissionDefault.TRUE); public static final DotStarPermission KITS = new DotStarPermission("essentials.kits", PermissionDefault.TRUE);
public static DotStarPermission NOCOMMANDCOST = new DotStarPermission("essentials.nocommandcost"); public static final DotStarPermission NOCOMMANDCOST = new DotStarPermission("essentials.nocommandcost");
public static DotStarPermission SPAWNER = new DotStarPermission("essentials.spawner"); public static final DotStarPermission SPAWNER = new DotStarPermission("essentials.spawner");
public static DotStarPermission SPAWNMOB = new DotStarPermission("essentials.spawnmob"); public static final DotStarPermission SPAWNMOB = new DotStarPermission("essentials.spawnmob");
public static MaterialDotStarPermission UNLIMITED = new MaterialDotStarPermission("essentials.unlimited.items"); public static final MaterialDotStarPermission UNLIMITED = new MaterialDotStarPermission("essentials.unlimited.items");
public static DotStarPermission WARPS = new DotStarPermission("essentials.warps", PermissionDefault.TRUE); public static final DotStarPermission WARPS = new DotStarPermission("essentials.warps", PermissionDefault.TRUE);
public static DotStarPermission WARP_OVERWRITE = new DotStarPermission("essentials.warp.overwrite"); public static final DotStarPermission WARP_OVERWRITE = new DotStarPermission("essentials.warp.overwrite");
public static DotStarPermission WORLD = new DotStarPermission("essentials.world"); public static final DotStarPermission WORLD = new DotStarPermission("essentials.world");
public static DotStarPermission NICK = new DotStarPermission("essentials.nick"); public static final DotStarPermission NICK = new DotStarPermission("essentials.nick");
public static DotStarPermission SIGNS = new DotStarPermission("essentials.signs"); public static final DotStarPermission SIGNS = new DotStarPermission("essentials.signs");
public static DotStarPermission CHAT = new DotStarPermission("essentials.chat"); public static final DotStarPermission CHAT = new DotStarPermission("essentials.chat");
public static DotStarPermission TIME_WORLDS = new DotStarPermission("essentials.time.worlds", PermissionDefault.TRUE); public static final DotStarPermission TIME_WORLDS = new DotStarPermission("essentials.time.worlds", PermissionDefault.TRUE);
} }

View File

@@ -6,8 +6,6 @@ import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import static net.ess3.I18n._; import static net.ess3.I18n._;
import net.ess3.api.IEssentials; import net.ess3.api.IEssentials;
import net.ess3.api.IEssentialsModule;
import net.ess3.api.ISettings;
import net.ess3.api.IUser; import net.ess3.api.IUser;
import net.ess3.storage.AsyncStorageObjectHolder; import net.ess3.storage.AsyncStorageObjectHolder;
import net.ess3.storage.StoredLocation.WorldNotLoadedException; import net.ess3.storage.StoredLocation.WorldNotLoadedException;
@@ -26,7 +24,7 @@ import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.plugin.EventExecutor; import org.bukkit.plugin.EventExecutor;
public class SpawnsHolder extends AsyncStorageObjectHolder<Spawns> implements IEssentialsModule public class SpawnsHolder extends AsyncStorageObjectHolder<Spawns>
{ {
public SpawnsHolder(final IEssentials ess) public SpawnsHolder(final IEssentials ess)
{ {
@@ -188,7 +186,6 @@ public class SpawnsHolder extends AsyncStorageObjectHolder<Spawns> implements IE
{ {
final IUser user = ess.getUserMap().getUser(event.getPlayer()); final IUser user = ess.getUserMap().getUser(event.getPlayer());
final ISettings settings = ess.getSettings();
boolean respawnAtHome = ess.getSettings().getData().getCommands().getHome().isRespawnAtHome(); boolean respawnAtHome = ess.getSettings().getData().getCommands().getHome().isRespawnAtHome();
if (respawnAtHome) if (respawnAtHome)
{ {
@@ -250,7 +247,7 @@ public class SpawnsHolder extends AsyncStorageObjectHolder<Spawns> implements IE
@Override @Override
public void run() public void run()
{ {
if (user.getPlayer() instanceof OfflinePlayer) if (!user.getPlayer().isOnline())
{ {
return; return;
} }

View File

@@ -166,7 +166,8 @@ public abstract class StorageObjectMap<I> extends CacheLoader<String, I> impleme
String sanitizedFilename = Util.sanitizeFileName(name) + ".yml"; String sanitizedFilename = Util.sanitizeFileName(name) + ".yml";
if (zippedfiles.containsKey(sanitizedFilename)) if (zippedfiles.containsKey(sanitizedFilename))
{ {
zippedfiles.put(sanitizedFilename, null); //TODO: Handle zip files correctly, files are never deleted from zip files.
zippedfiles.remove(sanitizedFilename);
} }
} }

View File

@@ -15,7 +15,6 @@ public class StorageQueue implements Runnable
private DelayQueue<WriteRequest> queue = new DelayQueue<WriteRequest>(); private DelayQueue<WriteRequest> queue = new DelayQueue<WriteRequest>();
public final static long DELAY = TimeUnit.NANOSECONDS.convert(1, TimeUnit.SECONDS); public final static long DELAY = TimeUnit.NANOSECONDS.convert(1, TimeUnit.SECONDS);
private final AtomicBoolean enabled = new AtomicBoolean(false); private final AtomicBoolean enabled = new AtomicBoolean(false);
private final Object lock = new Object();
private final IPlugin plugin; private final IPlugin plugin;
public StorageQueue(IPlugin plugin) public StorageQueue(IPlugin plugin)
@@ -26,34 +25,27 @@ public class StorageQueue implements Runnable
@Override @Override
public void run() public void run()
{ {
synchronized (lock) if (enabled.get() || !queue.isEmpty())
{ {
final List<WriteRequest> requests = new ArrayList<WriteRequest>(); work();
while (enabled.get() || !queue.isEmpty()) }
}
private void work()
{
final List<WriteRequest> requests = new ArrayList<WriteRequest>();
queue.drainTo(requests);
for (WriteRequest request : requests)
{
final RequestState state = request.getRequestState();
if (state == RequestState.REQUEUE)
{ {
try queue.add(request);
{ continue;
queue.drainTo(requests); }
for (WriteRequest request : requests) else if (state == RequestState.SCHEDULE)
{ {
final RequestState state = request.getRequestState(); plugin.runTaskAsynchronously(request.getRunnable());
if (state == RequestState.REQUEUE)
{
queue.add(request);
continue;
}
else if (state == RequestState.SCHEDULE)
{
plugin.runTaskAsynchronously(request.getRunnable());
}
}
requests.clear();
Thread.sleep(100);
}
catch (InterruptedException ex)
{
continue;
}
} }
} }
} }
@@ -72,18 +64,29 @@ public class StorageQueue implements Runnable
private void startThread() private void startThread()
{ {
synchronized (lock) plugin.runTaskTimerAsynchronously(this, 5, 5);
{
plugin.runTaskAsynchronously(this);
}
} }
public void setEnabled(boolean enabled) public void setEnabled(boolean enabled)
{ {
if (this.enabled.getAndSet(enabled) != enabled && enabled) if (this.enabled.getAndSet(enabled) != enabled)
{ {
startThread(); if (enabled) {
startThread();
} else {
while (queue.size() > 0) {
work();
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
}
}
}
} }
} }
public int getQueueSize() public int getQueueSize()
@@ -92,7 +95,7 @@ public class StorageQueue implements Runnable
} }
private class WriteRequest implements Delayed private static class WriteRequest implements Delayed
{ {
private final AsyncStorageObjectHolder objectHolder; private final AsyncStorageObjectHolder objectHolder;
private final long timestamp; private final long timestamp;

View File

@@ -248,7 +248,7 @@ public class User extends UserBase implements IUser
{ {
final Boolean changeDisplayname = ess.getSettings().getData().getChat().getChangeDisplayname(); final Boolean changeDisplayname = ess.getSettings().getData().getChat().getChangeDisplayname();
if (isOnline() && (changeDisplayname == true || (changeDisplayname == null && ess.getPlugin().isModuleEnabled("Chat")))) if (isOnline() && ((changeDisplayname == null && ess.getPlugin().isModuleEnabled("Chat")) || changeDisplayname == true))
{ {
setDisplayNick(); setDisplayNick();
} }
@@ -269,7 +269,7 @@ public class User extends UserBase implements IUser
final Method.MethodAccount account = Methods.getMethod().getAccount(this.getName()); final Method.MethodAccount account = Methods.getMethod().getAccount(this.getName());
return account.balance(); return account.balance();
} }
catch (Throwable ex) catch (Exception ex)
{ {
} }
} }
@@ -291,7 +291,7 @@ public class User extends UserBase implements IUser
final Method.MethodAccount account = Methods.getMethod().getAccount(this.getName()); final Method.MethodAccount account = Methods.getMethod().getAccount(this.getName());
account.set(value); account.set(value);
} }
catch (Throwable ex) catch (Exception ex)
{ {
} }
} }

View File

@@ -1,9 +1,7 @@
package net.ess3.signs; package net.ess3.signs;
import net.ess3.api.IEssentialsModule;
public interface ISignsPlugin
public interface ISignsPlugin extends IEssentialsModule
{ {
SignsConfigHolder getSettings(); SignsConfigHolder getSettings();
} }