New Interfaces in api package (WIP)

This commit is contained in:
snowleo 2011-12-06 16:32:06 +01:00
parent 5433a68502
commit 58237a796a
18 changed files with 256 additions and 8 deletions

View File

@ -402,11 +402,9 @@ public class Essentials extends JavaPlugin implements IEssentials
public void showError(final CommandSender sender, final Throwable exception, final String commandLabel)
{
sender.sendMessage(_("errorWithMessage", exception.getMessage()));
final LogRecord logRecord = new LogRecord(Level.WARNING, _("errorCallingCommand", commandLabel));
logRecord.setThrown(exception);
if (getSettings().isDebug())
{
LOGGER.log(logRecord);
LOGGER.log(Level.WARNING, _("errorCallingCommand", commandLabel), exception);
}
}

View File

@ -1,5 +1,6 @@
package com.earth2me.essentials;
import com.earth2me.essentials.api.II18n;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@ -12,7 +13,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
public class I18n
public class I18n implements II18n
{
private static I18n instance;
private static final String MESSAGES = "messages";

View File

@ -1,5 +1,9 @@
package com.earth2me.essentials;
/**
* @deprecated New interface will be IReload in api package
*/
@Deprecated
public interface IConf {
public void reloadConfig();
}

View File

@ -8,7 +8,10 @@ import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitScheduler;
/**
* @deprecated This will be moved to the api package soon
*/
@Deprecated
public interface IEssentials extends Plugin
{
void addReloadListener(IConf listener);

View File

@ -5,8 +5,10 @@ import java.net.InetSocketAddress;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.PlayerInventory;
/**
* @deprecated This will be moved to the api package soon
*/
@Deprecated
public interface IUser
{
int getHealth();

View File

@ -1,5 +1,6 @@
package com.earth2me.essentials;
import com.earth2me.essentials.api.IItemDb;
import static com.earth2me.essentials.I18n._;
import java.util.HashMap;
import java.util.List;
@ -9,7 +10,7 @@ import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
public class ItemDb implements IConf
public class ItemDb implements IConf, IItemDb
{
private final transient IEssentials ess;

View File

@ -0,0 +1,10 @@
package com.earth2me.essentials.api;
import java.util.Map;
import org.bukkit.command.PluginCommand;
public interface IAlternativeCommandsHandler
{
Map<String, String> disabledCommands();
}

View File

@ -0,0 +1,51 @@
package com.earth2me.essentials.api;
import com.earth2me.essentials.perm.IPermissionsHandler;
import com.earth2me.essentials.register.payment.Methods;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
public interface IEssentials extends Plugin, IReload
{
void addReloadListener(IReload listener);
IUser getUser(Object base);
int broadcastMessage(IUser sender, String message);
II18n getI18n();
ISettings getSettings();
IJail getJail();
IWarps getWarps();
IWorth getWorth();
IItemDb getItemDb();
IUserMap getUserMap();
IEssentialsEconomy getEconomy();
World getWorld(String name);
Methods getPaymentMethod();
int scheduleAsyncDelayedTask(Runnable run);
int scheduleSyncDelayedTask(Runnable run);
int scheduleSyncDelayedTask(Runnable run, long delay);
int scheduleSyncRepeatingTask(Runnable run, long delay, long period);
IPermissionsHandler getPermissionsHandler();
IAlternativeCommandsHandler getAlternativeCommandsHandler();
void showCommandError(CommandSender sender, String commandLabel, Throwable exception);
}

View File

@ -0,0 +1,37 @@
package com.earth2me.essentials.api;
public interface IEssentialsEconomy
{
double getMoney(String name) throws UserDoesNotExistException;
void setMoney(String name, double balance) throws UserDoesNotExistException, NoLoanPermittedException;
void add(String name, double amount) throws UserDoesNotExistException, NoLoanPermittedException;
void subtract(String name, double amount) throws UserDoesNotExistException, NoLoanPermittedException;
void divide(String name, double value) throws UserDoesNotExistException, NoLoanPermittedException;
void multiply(String name, double value) throws UserDoesNotExistException, NoLoanPermittedException;
void resetBalance(String name) throws UserDoesNotExistException, NoLoanPermittedException;
boolean hasEnough(String name, double amount) throws UserDoesNotExistException;
boolean hasMore(String name, double amount) throws UserDoesNotExistException;
boolean hasLess(String name, double amount) throws UserDoesNotExistException;
boolean isNegative(String name) throws UserDoesNotExistException;
String format(double amount);
boolean playerExists(String name);
boolean isNPC(String name) throws UserDoesNotExistException;
boolean createNPC(String name);
void removeNPC(String name) throws UserDoesNotExistException;
}

View File

@ -0,0 +1,9 @@
package com.earth2me.essentials.api;
import java.util.Locale;
public interface II18n
{
Locale getCurrentLocale();
}

View File

@ -0,0 +1,11 @@
package com.earth2me.essentials.api;
import org.bukkit.inventory.ItemStack;
public interface IItemDb
{
ItemStack get(final String name, final int quantity) throws Exception;
ItemStack get(final String name) throws Exception;
}

View File

@ -0,0 +1,18 @@
package com.earth2me.essentials.api;
import java.util.Collection;
import org.bukkit.Location;
public interface IJail extends IReload
{
Location getJail(String jailName) throws Exception;
Collection<String> getJails() throws Exception;
void removeJail(String jail) throws Exception;
void sendToJail(IUser user, String jail) throws Exception;
void setJail(Location loc, String jailName) throws Exception;
}

View File

@ -0,0 +1,7 @@
package com.earth2me.essentials.api;
public interface IReload
{
void onReload();
}

View File

@ -0,0 +1,10 @@
package com.earth2me.essentials.api;
import com.earth2me.essentials.settings.Settings;
import com.earth2me.essentials.storage.IStorageObjectHolder;
public interface ISettings extends IStorageObjectHolder<Settings>
{
}

View File

@ -0,0 +1,39 @@
package com.earth2me.essentials.api;
import com.earth2me.essentials.commands.IEssentialsCommand;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public interface IUser extends Player, IReload
{
long getLastTeleportTimestamp();
boolean isAuthorized(String node);
boolean isAuthorized(IEssentialsCommand cmd);
boolean isAuthorized(IEssentialsCommand cmd, String permissionPrefix);
void setLastTeleportTimestamp(long time);
Location getLastLocation();
Player getBase();
double getMoney();
void takeMoney(double value);
void giveMoney(double value);
String getGroup();
void setLastLocation();
Location getHome(String name) throws Exception;
Location getHome(Location loc) throws Exception;
boolean isHidden();
}

View File

@ -0,0 +1,20 @@
package com.earth2me.essentials.api;
import java.io.File;
import java.util.Set;
public interface IUserMap
{
boolean userExists(final String name);
IUser getUser(final String name);
void removeUser(final String name);
Set<String> getAllUniqueUsers();
int getUniqueUsers();
File getUserFile(final String name);
}

View File

@ -0,0 +1,16 @@
package com.earth2me.essentials.api;
import java.util.Collection;
import org.bukkit.Location;
public interface IWarps extends IReload
{
Location getWarp(String warp) throws Exception;
Collection<String> getWarps();
void removeWarp(String name) throws Exception;
void setWarp(String name, Location loc) throws Exception;
}

View File

@ -0,0 +1,11 @@
package com.earth2me.essentials.api;
import org.bukkit.inventory.ItemStack;
public interface IWorth extends IReload
{
double getPrice(ItemStack itemStack);
void setPrice(ItemStack itemStack, double price);
}