mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-20 05:21:21 +02:00
[API] Add a warp api, with future 3.x support :: minor cleanup
This commit is contained in:
@@ -43,6 +43,7 @@ public class I18n implements II18n
|
|||||||
instance = null;
|
instance = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Locale getCurrentLocale()
|
public Locale getCurrentLocale()
|
||||||
{
|
{
|
||||||
return currentLocale;
|
return currentLocale;
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
package com.earth2me.essentials;
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
public interface IConf {
|
public interface IConf
|
||||||
|
{
|
||||||
public void reloadConfig();
|
public void reloadConfig();
|
||||||
}
|
}
|
||||||
|
@@ -2,8 +2,17 @@ package com.earth2me.essentials;
|
|||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
public interface IReplyTo {
|
public interface IReplyTo
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Sets the user to reply to
|
||||||
|
* @param user
|
||||||
|
*/
|
||||||
public void setReplyTo(CommandSender user);
|
public void setReplyTo(CommandSender user);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the user the sender should reply to
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public CommandSender getReplyTo();
|
public CommandSender getReplyTo();
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
package com.earth2me.essentials;
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
import static com.earth2me.essentials.I18n._;
|
import static com.earth2me.essentials.I18n._;
|
||||||
|
import com.earth2me.essentials.api.IWarps;
|
||||||
|
import com.earth2me.essentials.api.InvalidNameException;
|
||||||
import com.earth2me.essentials.commands.WarpNotFoundException;
|
import com.earth2me.essentials.commands.WarpNotFoundException;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -11,7 +13,7 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
|
|
||||||
|
|
||||||
public class Warps implements IConf
|
public class Warps implements IConf, IWarps
|
||||||
{
|
{
|
||||||
private static final Logger logger = Logger.getLogger("Minecraft");
|
private static final Logger logger = Logger.getLogger("Minecraft");
|
||||||
private final Map<StringIgnoreCase, EssentialsConf> warpPoints = new HashMap<StringIgnoreCase, EssentialsConf>();
|
private final Map<StringIgnoreCase, EssentialsConf> warpPoints = new HashMap<StringIgnoreCase, EssentialsConf>();
|
||||||
@@ -29,6 +31,7 @@ public class Warps implements IConf
|
|||||||
reloadConfig();
|
reloadConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isEmpty()
|
public boolean isEmpty()
|
||||||
{
|
{
|
||||||
return warpPoints.isEmpty();
|
return warpPoints.isEmpty();
|
||||||
@@ -45,6 +48,7 @@ public class Warps implements IConf
|
|||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Location getWarp(String warp) throws Exception
|
public Location getWarp(String warp) throws Exception
|
||||||
{
|
{
|
||||||
EssentialsConf conf = warpPoints.get(new StringIgnoreCase(warp));
|
EssentialsConf conf = warpPoints.get(new StringIgnoreCase(warp));
|
||||||
@@ -55,6 +59,7 @@ public class Warps implements IConf
|
|||||||
return conf.getLocation(null, server);
|
return conf.getLocation(null, server);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setWarp(String name, Location loc) throws Exception
|
public void setWarp(String name, Location loc) throws Exception
|
||||||
{
|
{
|
||||||
String filename = Util.sanitizeFileName(name);
|
String filename = Util.sanitizeFileName(name);
|
||||||
@@ -126,6 +131,41 @@ public class Warps implements IConf
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is for api support, and so 3.x will not break this api
|
||||||
|
@Override
|
||||||
|
public Collection<String> getList()
|
||||||
|
{
|
||||||
|
final List<String> keys = new ArrayList<String>();
|
||||||
|
for (StringIgnoreCase stringIgnoreCase : warpPoints.keySet())
|
||||||
|
{
|
||||||
|
keys.add(stringIgnoreCase.getString());
|
||||||
|
}
|
||||||
|
Collections.sort(keys, String.CASE_INSENSITIVE_ORDER);
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is for api support, and so 3.x will not break this api
|
||||||
|
@Override
|
||||||
|
public void removeWarp(String name) throws Exception
|
||||||
|
{
|
||||||
|
EssentialsConf conf = warpPoints.get(new StringIgnoreCase(name));
|
||||||
|
if (conf == null)
|
||||||
|
{
|
||||||
|
throw new Exception(_("warpNotExist"));
|
||||||
|
}
|
||||||
|
if (!conf.getFile().delete())
|
||||||
|
{
|
||||||
|
throw new Exception(_("warpDeleteError"));
|
||||||
|
}
|
||||||
|
warpPoints.remove(new StringIgnoreCase(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
//This is here for future 3.x api support. Not implemented here becasue storage is handled differently
|
||||||
|
@Override
|
||||||
|
public File getWarpFile(String name) throws InvalidNameException
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
private static class StringIgnoreCase
|
private static class StringIgnoreCase
|
||||||
{
|
{
|
||||||
|
60
Essentials/src/com/earth2me/essentials/api/IWarps.java
Normal file
60
Essentials/src/com/earth2me/essentials/api/IWarps.java
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
package com.earth2me.essentials.api;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Collection;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
|
||||||
|
public interface IWarps
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get a warp by name
|
||||||
|
*
|
||||||
|
* @param warp - Warp name
|
||||||
|
* @return - Location the warp is set to
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
Location getWarp(String warp) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a list of warps
|
||||||
|
*
|
||||||
|
* @return - A {@link Collection} of warps
|
||||||
|
*/
|
||||||
|
Collection<String> getList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a warp from the warp DB
|
||||||
|
*
|
||||||
|
* @param name - Name of warp
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
void removeWarp(String name) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a warp
|
||||||
|
*
|
||||||
|
* @param name - Name of warp
|
||||||
|
* @param loc - Location of warp
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
void setWarp(String name, Location loc) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check to see if the file is empty
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
boolean isEmpty();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a warp file
|
||||||
|
* note: this is not yet implemented, as 3.x uses different storage methods
|
||||||
|
*
|
||||||
|
* @param name - name of file
|
||||||
|
* @return - an instance of the file
|
||||||
|
* @throws InvalidNameException - When the file is not found
|
||||||
|
*/
|
||||||
|
File getWarpFile(String name) throws InvalidNameException;
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,16 @@
|
|||||||
|
package com.earth2me.essentials.api;
|
||||||
|
|
||||||
|
|
||||||
|
public class InvalidNameException extends Exception
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* NOTE: This is not implemented yet, just here for future 3.x api support
|
||||||
|
* Allow serialization of the InvalidNameException exception
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1485321420293663139L;
|
||||||
|
|
||||||
|
public InvalidNameException(Throwable thrwbl)
|
||||||
|
{
|
||||||
|
super(thrwbl);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user