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
*.iws
.idea/
/EssentialsRelease/

View File

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

View File

@@ -3,5 +3,5 @@ package net.ess3.api;
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();
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);
}

View File

@@ -3,19 +3,19 @@ package net.ess3.api;
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
{
/**
* Get an instance of essentials
*
@@ -42,6 +41,8 @@ public interface IPlugin extends Plugin
*/
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
*
@@ -125,11 +126,11 @@ public interface IPlugin extends Plugin
* @param name
* @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
@@ -137,5 +138,4 @@ public interface IPlugin extends Plugin
* @param module - Your plugin instance
*/
void registerModule(Plugin module);
}

View File

@@ -6,9 +6,9 @@ import net.ess3.storage.IStorageObjectHolder;
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

@@ -37,5 +37,5 @@ public interface ITeleport
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();
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();
@@ -133,9 +133,9 @@ public interface IUser extends OfflinePlayer, CommandSender, IStorageObjectHolde
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

View File

@@ -49,7 +49,7 @@ public interface IUserMap extends IReload
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

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

View File

@@ -150,6 +150,12 @@ public class BukkitPlugin extends JavaPlugin implements IPlugin
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
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);
UserData userData = user.getData();
// check to see if this is a clear all command
if (command != null && command.equalsIgnoreCase("d:"))
if (command.equalsIgnoreCase("d:"))
{
userData.clearAllPowertools();
user.queueSave();
@@ -36,7 +36,7 @@ public class Commandpowertool extends EssentialsCommand
final String itemName = itemStack.getType().toString().toLowerCase(Locale.ENGLISH).replaceAll("_", " ");
List<String> powertools = userData.getPowertool(itemStack.getType());
if (command != null && !command.isEmpty())
if (!command.isEmpty())
{
if (command.equalsIgnoreCase("l:"))
{

View File

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

View File

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

View File

@@ -4,7 +4,6 @@ import java.util.List;
import java.util.logging.Logger;
import static net.ess3.I18n._;
import net.ess3.api.IEssentials;
import net.ess3.api.IEssentialsModule;
import net.ess3.api.IUser;
import net.ess3.economy.Trade;
import net.ess3.permissions.AbstractSuperpermsPermission;
@@ -18,7 +17,6 @@ public abstract class EssentialsCommand extends AbstractSuperpermsPermission imp
{
protected String commandName;
protected IEssentials ess;
protected IEssentialsModule module;
protected Server server;
protected Logger logger;
private String permission;
@@ -33,12 +31,6 @@ public abstract class EssentialsCommand extends AbstractSuperpermsPermission imp
this.permission = "essentials." + commandName;
}
@Override
public void setEssentialsModule(final IEssentialsModule module)
{
this.module = module;
}
@Override
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 String commandPath;
private final String permissionPrefix;// TODO: Needed?
private final IEssentialsModule module;
private static final Logger LOGGER = Bukkit.getLogger();
private final Map<String, List<PluginCommand>> altcommands = new HashMap<String, List<PluginCommand>>();
private final Map<String, String> disabledList = new HashMap<String, String>();
@@ -25,16 +24,10 @@ public class EssentialsCommandHandler implements ICommandHandler, TabExecutor
private final 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.commandPath = commandPath;
this.permissionPrefix = permissionPrefix;
this.module = module;
this.ess = ess;
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.init(ess, commandName);
cmd.setEssentialsModule(module);
commands.put(commandName, cmd);
if (command instanceof PluginCommand)
{
@@ -163,13 +155,13 @@ public class EssentialsCommandHandler implements ICommandHandler, TabExecutor
}
return true;
}
catch (Throwable ex)
catch (Exception ex)
{
showCommandError(sender, commandLabel, ex);
return true;
}
}
catch (Throwable ex)
catch (Exception ex)
{
LOGGER.log(Level.SEVERE, _("commandFailed", commandLabel), ex);
return true;
@@ -236,7 +228,6 @@ public class EssentialsCommandHandler implements ICommandHandler, TabExecutor
{
cmd = (IEssentialsCommand)classLoader.loadClass(commandPath + commandName).newInstance();
cmd.init(ess, commandName);
cmd.setEssentialsModule(module);
commands.put(commandName, cmd);
if (command instanceof PluginCommand)
{
@@ -280,13 +271,13 @@ public class EssentialsCommandHandler implements ICommandHandler, TabExecutor
}
}
}
catch (Throwable ex)
catch (Exception ex)
{
showCommandError(sender, commandLabel, ex);
return null;
}
}
catch (Throwable ex)
catch (Exception ex)
{
LOGGER.log(Level.SEVERE, _("commandFailed", commandLabel), ex);
return null;

View File

@@ -2,7 +2,6 @@ package net.ess3.commands;
import java.util.List;
import net.ess3.api.IEssentials;
import net.ess3.api.IEssentialsModule;
import net.ess3.api.IPermission;
import net.ess3.api.IUser;
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);
void init(IEssentials ess, String commandLabel);
void setEssentialsModule(IEssentialsModule module);
}

View File

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

View File

@@ -166,22 +166,22 @@ public enum Permissions implements IPermission
return PermissionFactory.checkPermission(sender, this);
}
public static DotStarPermission ENCHANT = new DotStarPermission("essentials.enchant");
public static DotStarPermission PERGROUPTELEPORT = new DotStarPermission("essentials.teleport.groups");
public static MaterialDotStarPermission GIVE = new MaterialDotStarPermission("essentials.give", PermissionDefault.TRUE);
public static DotStarPermission RANKS = new DotStarPermission("essentials.ranks");
public static DotStarPermission HELP = new DotStarPermission("essentials.help");
public static MaterialDotStarPermission ITEMSPAWN = new MaterialDotStarPermission("essentials.itemspawn", PermissionDefault.TRUE);
public static DotStarPermission KITS = new DotStarPermission("essentials.kits", PermissionDefault.TRUE);
public static DotStarPermission NOCOMMANDCOST = new DotStarPermission("essentials.nocommandcost");
public static DotStarPermission SPAWNER = new DotStarPermission("essentials.spawner");
public static DotStarPermission SPAWNMOB = new DotStarPermission("essentials.spawnmob");
public static MaterialDotStarPermission UNLIMITED = new MaterialDotStarPermission("essentials.unlimited.items");
public static DotStarPermission WARPS = new DotStarPermission("essentials.warps", PermissionDefault.TRUE);
public static DotStarPermission WARP_OVERWRITE = new DotStarPermission("essentials.warp.overwrite");
public static DotStarPermission WORLD = new DotStarPermission("essentials.world");
public static DotStarPermission NICK = new DotStarPermission("essentials.nick");
public static DotStarPermission SIGNS = new DotStarPermission("essentials.signs");
public static DotStarPermission CHAT = new DotStarPermission("essentials.chat");
public static DotStarPermission TIME_WORLDS = new DotStarPermission("essentials.time.worlds", PermissionDefault.TRUE);
public static final DotStarPermission ENCHANT = new DotStarPermission("essentials.enchant");
public static final DotStarPermission PERGROUPTELEPORT = new DotStarPermission("essentials.teleport.groups");
public static final MaterialDotStarPermission GIVE = new MaterialDotStarPermission("essentials.give", PermissionDefault.TRUE);
public static final DotStarPermission RANKS = new DotStarPermission("essentials.ranks");
public static final DotStarPermission HELP = new DotStarPermission("essentials.help");
public static final MaterialDotStarPermission ITEMSPAWN = new MaterialDotStarPermission("essentials.itemspawn", PermissionDefault.TRUE);
public static final DotStarPermission KITS = new DotStarPermission("essentials.kits", PermissionDefault.TRUE);
public static final DotStarPermission NOCOMMANDCOST = new DotStarPermission("essentials.nocommandcost");
public static final DotStarPermission SPAWNER = new DotStarPermission("essentials.spawner");
public static final DotStarPermission SPAWNMOB = new DotStarPermission("essentials.spawnmob");
public static final MaterialDotStarPermission UNLIMITED = new MaterialDotStarPermission("essentials.unlimited.items");
public static final DotStarPermission WARPS = new DotStarPermission("essentials.warps", PermissionDefault.TRUE);
public static final DotStarPermission WARP_OVERWRITE = new DotStarPermission("essentials.warp.overwrite");
public static final DotStarPermission WORLD = new DotStarPermission("essentials.world");
public static final DotStarPermission NICK = new DotStarPermission("essentials.nick");
public static final DotStarPermission SIGNS = new DotStarPermission("essentials.signs");
public static final DotStarPermission CHAT = new DotStarPermission("essentials.chat");
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 static net.ess3.I18n._;
import net.ess3.api.IEssentials;
import net.ess3.api.IEssentialsModule;
import net.ess3.api.ISettings;
import net.ess3.api.IUser;
import net.ess3.storage.AsyncStorageObjectHolder;
import net.ess3.storage.StoredLocation.WorldNotLoadedException;
@@ -26,7 +24,7 @@ import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.plugin.EventExecutor;
public class SpawnsHolder extends AsyncStorageObjectHolder<Spawns> implements IEssentialsModule
public class SpawnsHolder extends AsyncStorageObjectHolder<Spawns>
{
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 ISettings settings = ess.getSettings();
boolean respawnAtHome = ess.getSettings().getData().getCommands().getHome().isRespawnAtHome();
if (respawnAtHome)
{
@@ -250,7 +247,7 @@ public class SpawnsHolder extends AsyncStorageObjectHolder<Spawns> implements IE
@Override
public void run()
{
if (user.getPlayer() instanceof OfflinePlayer)
if (!user.getPlayer().isOnline())
{
return;
}

View File

@@ -166,7 +166,8 @@ public abstract class StorageObjectMap<I> extends CacheLoader<String, I> impleme
String sanitizedFilename = Util.sanitizeFileName(name) + ".yml";
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>();
public final static long DELAY = TimeUnit.NANOSECONDS.convert(1, TimeUnit.SECONDS);
private final AtomicBoolean enabled = new AtomicBoolean(false);
private final Object lock = new Object();
private final IPlugin plugin;
public StorageQueue(IPlugin plugin)
@@ -26,13 +25,15 @@ public class StorageQueue implements Runnable
@Override
public void run()
{
synchronized (lock)
if (enabled.get() || !queue.isEmpty())
{
work();
}
}
private void work()
{
final List<WriteRequest> requests = new ArrayList<WriteRequest>();
while (enabled.get() || !queue.isEmpty())
{
try
{
queue.drainTo(requests);
for (WriteRequest request : requests)
{
@@ -47,15 +48,6 @@ public class StorageQueue implements Runnable
plugin.runTaskAsynchronously(request.getRunnable());
}
}
requests.clear();
Thread.sleep(100);
}
catch (InterruptedException ex)
{
continue;
}
}
}
}
public void queue(AsyncStorageObjectHolder objectHolder)
@@ -72,18 +64,29 @@ public class StorageQueue implements Runnable
private void startThread()
{
synchronized (lock)
{
plugin.runTaskAsynchronously(this);
}
plugin.runTaskTimerAsynchronously(this, 5, 5);
}
public void setEnabled(boolean enabled)
{
if (this.enabled.getAndSet(enabled) != enabled && enabled)
if (this.enabled.getAndSet(enabled) != enabled)
{
if (enabled) {
startThread();
} else {
while (queue.size() > 0) {
work();
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
}
}
}
}
}
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 long timestamp;

View File

@@ -248,7 +248,7 @@ public class User extends UserBase implements IUser
{
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();
}
@@ -269,7 +269,7 @@ public class User extends UserBase implements IUser
final Method.MethodAccount account = Methods.getMethod().getAccount(this.getName());
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());
account.set(value);
}
catch (Throwable ex)
catch (Exception ex)
{
}
}

View File

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