Cleanup of Essentials class

Moved all ban stuff to BanWorkaround
This commit is contained in:
snowleo 2011-07-15 23:39:56 +02:00
parent 963fd7cf01
commit 25c9557c59
12 changed files with 268 additions and 331 deletions

View File

@ -0,0 +1,157 @@
package com.earth2me.essentials;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.minecraft.server.ServerConfigurationManager;
import org.bukkit.craftbukkit.CraftServer;
public class BanWorkaround implements IConf
{
private transient final IEssentials ess;
private transient final ServerConfigurationManager scm;
private static final Logger LOGGER = Logger.getLogger("Minecraft");
private transient final Set<String> bans = new HashSet<String>();
private transient final Set<String> bannedIps = new HashSet<String>();
public BanWorkaround(final IEssentials ess)
{
this.ess = ess;
this.scm = ((CraftServer)ess.getServer()).getHandle();
}
public void banByName(final String name)
{
scm.a(name);
reloadConfig();
}
public void unbanByName(String name)
{
scm.b(name);
reloadConfig();
}
public void banByIp(final String ip)
{
scm.c(ip);
reloadConfig();
}
public void unbanByIp(final String ip)
{
scm.d(ip);
reloadConfig();
}
public boolean isNameBanned(final String name)
{
return bans.contains(name.toLowerCase());
}
public boolean isIpBanned(final String ip)
{
return bannedIps.contains(ip.toLowerCase());
}
public void reloadConfig()
{
//I don't like this but it needs to be done until CB fixors
final File file = new File(ess.getDataFolder().getParentFile().getParentFile(), "banned-players.txt");
try
{
if (!file.exists())
{
throw new FileNotFoundException(Util.i18n("bannedPlayersFileNotFound"));
}
final BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
try
{
bans.clear();
while (bufferedReader.ready())
{
final String line = bufferedReader.readLine().trim().toLowerCase();
if (line.length() > 0 && line.charAt(0) == '#')
{
continue;
}
bans.add(line);
}
}
catch (IOException io)
{
LOGGER.log(Level.SEVERE, Util.i18n("bannedPlayersFileError"), io);
}
finally
{
try
{
bufferedReader.close();
}
catch (IOException ex)
{
LOGGER.log(Level.SEVERE, Util.i18n("bannedPlayersFileError"), ex);
}
}
}
catch (FileNotFoundException ex)
{
LOGGER.log(Level.SEVERE, Util.i18n("bannedPlayersFileError"), ex);
}
final File ipFile = new File(ess.getDataFolder().getParentFile().getParentFile(), "banned-ips.txt");
try
{
if (!ipFile.exists())
{
throw new FileNotFoundException(Util.i18n("bannedIpsFileNotFound"));
}
final BufferedReader bufferedReader = new BufferedReader(new FileReader(ipFile));
try
{
bannedIps.clear();
while (bufferedReader.ready())
{
final String line = bufferedReader.readLine().trim().toLowerCase();
if (line.length() > 0 && line.charAt(0) == '#')
{
continue;
}
bannedIps.add(line);
}
}
catch (IOException io)
{
LOGGER.log(Level.SEVERE, Util.i18n("bannedIpsFileError"), io);
}
finally
{
try
{
bufferedReader.close();
}
catch (IOException ex)
{
LOGGER.log(Level.SEVERE, Util.i18n("bannedIpsFileError"), ex);
}
}
}
catch (FileNotFoundException ex)
{
LOGGER.log(Level.SEVERE, Util.i18n("bannedIpsFileError"), ex);
}
}
}

View File

@ -46,27 +46,24 @@ import org.bukkit.plugin.java.*;
public class Essentials extends JavaPlugin implements IEssentials
{
public static final String AUTHORS = "Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo, ceulemans and Xeology";
public static final int minBukkitBuildVersion = 974;
private static final Logger logger = Logger.getLogger("Minecraft");
private Settings settings;
private TNTExplodeListener tntListener;
private EssentialsDependancyChecker essDep;
public static final int BUKKIT_VERSION = 974;
private static final Logger LOGGER = Logger.getLogger("Minecraft");
private transient Settings settings;
private final transient TNTExplodeListener tntListener = new TNTExplodeListener(this);
private static Essentials instance = null;
private Spawn spawn;
private Jail jail;
private Warps warps;
private Worth worth;
private List<IConf> confList;
public ArrayList bans = new ArrayList();
public ArrayList bannedIps = new ArrayList();
private Backup backup;
private final Map<String, User> users = new HashMap<String, User>();
private EssentialsUpdateTimer updateTimer;
private boolean registerFallback = true;
private final Methods paymentMethod = new Methods();
private final static boolean enableErrorLogging = false;
private final EssentialsErrorHandler errorHandler = new EssentialsErrorHandler();
private IPermissionsHandler permissionsHandler;
private transient Spawn spawn;
private transient Jail jail;
private transient Warps warps;
private transient Worth worth;
private transient List<IConf> confList;
private transient Backup backup;
private transient BanWorkaround bans;
private transient final Map<String, User> users = new HashMap<String, User>();
private transient EssentialsUpdateTimer updateTimer;
private transient final Methods paymentMethod = new Methods();
private transient final static boolean enableErrorLogging = false;
private transient final EssentialsErrorHandler errorHandler = new EssentialsErrorHandler();
private transient IPermissionsHandler permissionsHandler;
public static IEssentials getStatic()
{
@ -78,13 +75,19 @@ public class Essentials extends JavaPlugin implements IEssentials
return settings;
}
public void setupForTesting(Server server) throws IOException, InvalidDescriptionException
public void setupForTesting(final Server server) throws IOException, InvalidDescriptionException
{
File dataFolder = File.createTempFile("essentialstest", "");
dataFolder.delete();
dataFolder.mkdir();
logger.log(Level.INFO, Util.i18n("usingTempFolderForTesting"));
logger.log(Level.INFO, dataFolder.toString());
final File dataFolder = File.createTempFile("essentialstest", "");
if (!dataFolder.delete())
{
throw new IOException();
}
if (!dataFolder.mkdir())
{
throw new IOException();
}
LOGGER.log(Level.INFO, Util.i18n("usingTempFolderForTesting"));
LOGGER.log(Level.INFO, dataFolder.toString());
this.initialize(null, server, new PluginDescriptionFile(new FileReader(new File("src" + File.separator + "plugin.yml"))), dataFolder, null, null);
settings = new Settings(dataFolder);
permissionsHandler = new ConfigPermissionsHandler(this);
@ -101,11 +104,11 @@ public class Essentials extends JavaPlugin implements IEssentials
final String[] javaversion = System.getProperty("java.version").split("\\.", 3);
if (javaversion == null || javaversion.length < 2 || Integer.parseInt(javaversion[1]) < 6)
{
logger.log(Level.SEVERE, "Java version not supported! Please install Java 1.6. You have " + System.getProperty("java.version"));
LOGGER.log(Level.SEVERE, "Java version not supported! Please install Java 1.6. You have " + System.getProperty("java.version"));
}
if (enableErrorLogging)
{
logger.addHandler(errorHandler);
LOGGER.addHandler(errorHandler);
}
setStatic();
EssentialsUpgrade upgrade = new EssentialsUpgrade(this.getDescription().getVersion(), this);
@ -121,36 +124,35 @@ public class Essentials extends JavaPlugin implements IEssentials
confList.add(warps);
worth = new Worth(this.getDataFolder());
confList.add(worth);
bans = new BanWorkaround(this);
confList.add(bans);
reload();
backup = new Backup(this);
essDep = new EssentialsDependancyChecker(this);
final PluginManager pm = getServer().getPluginManager();
for (Plugin plugin : pm.getPlugins())
{
if (plugin.getDescription().getName().startsWith("Essentials"))
if (plugin.getDescription().getName().startsWith("Essentials")
&& !plugin.getDescription().getVersion().equals(this.getDescription().getVersion()))
{
if (!plugin.getDescription().getVersion().equals(this.getDescription().getVersion()))
{
logger.log(Level.WARNING, Util.format("versionMismatch", plugin.getDescription().getName()));
LOGGER.log(Level.WARNING, Util.format("versionMismatch", plugin.getDescription().getName()));
}
}
}
Matcher versionMatch = Pattern.compile("git-Bukkit-([0-9]+).([0-9]+).([0-9]+)-[0-9]+-[0-9a-z]+-b([0-9]+)jnks.*").matcher(getServer().getVersion());
final Matcher versionMatch = Pattern.compile("git-Bukkit-([0-9]+).([0-9]+).([0-9]+)-[0-9]+-[0-9a-z]+-b([0-9]+)jnks.*").matcher(getServer().getVersion());
if (versionMatch.matches())
{
int versionNumber = Integer.parseInt(versionMatch.group(4));
if (versionNumber < minBukkitBuildVersion)
final int versionNumber = Integer.parseInt(versionMatch.group(4));
if (versionNumber < BUKKIT_VERSION)
{
logger.log(Level.WARNING, Util.i18n("notRecommendedBukkit"));
LOGGER.log(Level.WARNING, Util.i18n("notRecommendedBukkit"));
}
}
else
{
logger.log(Level.INFO, Util.i18n("bukkitFormatChanged"));
LOGGER.log(Level.INFO, Util.i18n("bukkitFormatChanged"));
}
Plugin permissionsPlugin = pm.getPlugin("Permissions");
final Plugin permissionsPlugin = pm.getPlugin("Permissions");
if (permissionsPlugin != null)
{
@ -224,7 +226,6 @@ public class Essentials extends JavaPlugin implements IEssentials
getServer().createWorld(settings.getNetherName(), World.Environment.NETHER);
}
tntListener = new TNTExplodeListener(this);
pm.registerEvent(Type.ENTITY_EXPLODE, tntListener, Priority.High, this);
final EssentialsTimer timer = new EssentialsTimer(this);
@ -234,20 +235,19 @@ public class Essentials extends JavaPlugin implements IEssentials
updateTimer = new EssentialsUpdateTimer(this);
getScheduler().scheduleAsyncRepeatingTask(this, updateTimer, 50, 50 * 60 * (this.getDescription().getVersion().startsWith("Dev") ? 60 : 360));
}
logger.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), AUTHORS));
LOGGER.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), AUTHORS));
}
public void onDisable()
{
instance = null;
Trade.closeLog();
logger.removeHandler(errorHandler);
LOGGER.removeHandler(errorHandler);
}
public void reload()
{
Trade.closeLog();
loadBanList();
for (IConf iConf : confList)
{
@ -270,7 +270,7 @@ public class Essentials extends JavaPlugin implements IEssentials
}
catch (Exception ex)
{
logger.log(Level.WARNING, Util.i18n("itemsCsvNotLoaded"), ex);
LOGGER.log(Level.WARNING, Util.i18n("itemsCsvNotLoaded"), ex);
}
}
@ -302,7 +302,7 @@ public class Essentials extends JavaPlugin implements IEssentials
}
catch (Throwable ex2)
{
logger.log(Level.WARNING, Util.format("corruptNodeInConfig", node));
LOGGER.log(Level.WARNING, Util.format("corruptNodeInConfig", node));
return new String[0];
}
}
@ -413,7 +413,7 @@ public class Essentials extends JavaPlugin implements IEssentials
if (sender instanceof Player)
{
user = getUser(sender);
logger.log(Level.INFO, String.format("[PLAYER_COMMAND] %s: /%s %s ", ((Player)sender).getName(), commandLabel, EssentialsCommand.getFinalArg(args, 0)));
LOGGER.log(Level.INFO, String.format("[PLAYER_COMMAND] %s: /%s %s ", ((Player)sender).getName(), commandLabel, EssentialsCommand.getFinalArg(args, 0)));
}
// New mail notification
@ -441,14 +441,14 @@ public class Essentials extends JavaPlugin implements IEssentials
catch (Exception ex)
{
sender.sendMessage(Util.format("commandNotLoaded", commandLabel));
logger.log(Level.SEVERE, Util.format("commandNotLoaded", commandLabel), ex);
LOGGER.log(Level.SEVERE, Util.format("commandNotLoaded", commandLabel), ex);
return true;
}
// Check authorization
if (user != null && !user.isAuthorized(cmd, permissionPrefix))
{
logger.log(Level.WARNING, Util.format("deniedAccessCommand", user.getName()));
LOGGER.log(Level.WARNING, Util.format("deniedAccessCommand", user.getName()));
user.sendMessage(Util.i18n("noAccessCommand"));
return true;
}
@ -480,7 +480,7 @@ public class Essentials extends JavaPlugin implements IEssentials
}
catch (Throwable ex)
{
logger.log(Level.SEVERE, Util.format("commandFailed", commandLabel), ex);
LOGGER.log(Level.SEVERE, Util.format("commandFailed", commandLabel), ex);
return true;
}
}
@ -492,7 +492,7 @@ public class Essentials extends JavaPlugin implements IEssentials
logRecord.setThrown(exception);
if (getSettings().isDebug())
{
logger.log(logRecord);
LOGGER.log(logRecord);
}
else
{
@ -504,100 +504,6 @@ public class Essentials extends JavaPlugin implements IEssentials
}
}
public void loadBanList()
{
//I don't like this but it needs to be done until CB fixors
File file = new File("banned-players.txt");
File ipFile = new File("banned-ips.txt");
try
{
if (!file.exists())
{
throw new FileNotFoundException(Util.i18n("bannedPlayersFileNotFound"));
}
final BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
try
{
bans.clear();
while (bufferedReader.ready())
{
final String line = bufferedReader.readLine().trim().toLowerCase();
if (line.length() > 0 && line.charAt(0) == '#')
{
continue;
}
bans.add(line);
}
}
catch (IOException io)
{
logger.log(Level.SEVERE, Util.i18n("bannedPlayersFileError"), io);
}
finally
{
try
{
bufferedReader.close();
}
catch (IOException ex)
{
logger.log(Level.SEVERE, Util.i18n("bannedPlayersFileError"), ex);
}
}
}
catch (FileNotFoundException ex)
{
logger.log(Level.SEVERE, Util.i18n("bannedPlayersFileError"), ex);
}
try
{
if (!ipFile.exists())
{
throw new FileNotFoundException(Util.i18n("bannedIpsFileNotFound"));
}
final BufferedReader bufferedReader = new BufferedReader(new FileReader(ipFile));
try
{
bannedIps.clear();
while (bufferedReader.ready())
{
final String line = bufferedReader.readLine().trim().toLowerCase();
if (line.length() > 0 && line.charAt(0) == '#')
{
continue;
}
bannedIps.add(line);
}
}
catch (IOException io)
{
logger.log(Level.SEVERE, Util.i18n("bannedIpsFileError"), io);
}
finally
{
try
{
bufferedReader.close();
}
catch (IOException ex)
{
logger.log(Level.SEVERE, Util.i18n("bannedIpsFileError"), ex);
}
}
}
catch (FileNotFoundException ex)
{
logger.log(Level.SEVERE, Util.i18n("bannedIpsFileError"), ex);
}
}
public CraftScheduler getScheduler()
{
return (CraftScheduler)this.getServer().getScheduler();
@ -676,35 +582,20 @@ public class Essentials extends JavaPlugin implements IEssentials
return null;
}
public World getWorld(String name)
public World getWorld(final String name)
{
if (name.matches("[0-9]+"))
{
int id = Integer.parseInt(name);
final int id = Integer.parseInt(name);
if (id < getServer().getWorlds().size())
{
return getServer().getWorlds().get(id);
}
}
World w = getServer().getWorld(name);
if (w != null)
{
return w;
}
return null;
return getServer().getWorld(name);
}
public void setRegisterFallback(boolean registerFallback)
{
this.registerFallback = registerFallback;
}
public boolean isRegisterFallbackEnabled()
{
return registerFallback;
}
public void addReloadListener(IConf listener)
public void addReloadListener(final IConf listener)
{
confList.add(listener);
}
@ -714,7 +605,7 @@ public class Essentials extends JavaPlugin implements IEssentials
return paymentMethod;
}
public int broadcastMessage(String name, String message)
public int broadcastMessage(final String name, final String message)
{
Player[] players = getServer().getOnlinePlayers();
@ -750,33 +641,23 @@ public class Essentials extends JavaPlugin implements IEssentials
return this.getScheduler().scheduleSyncDelayedTask(this, run, delay);
}
public int scheduleSyncRepeatingTask(final Runnable run, long delay, long period)
public int scheduleSyncRepeatingTask(final Runnable run, final long delay, final long period)
{
return this.getScheduler().scheduleSyncRepeatingTask(this, run, delay, period);
}
public List<String> getBans()
{
return bans;
}
public List<String> getBannedIps()
{
return bannedIps;
}
public TNTExplodeListener getTNTListener()
{
return tntListener;
}
public EssentialsDependancyChecker getDependancyChecker()
{
return essDep;
}
public IPermissionsHandler getPermissionsHandler()
{
return permissionsHandler;
}
public BanWorkaround getBans()
{
return bans;
}
}

View File

@ -1,68 +0,0 @@
package com.earth2me.essentials;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
public class EssentialsDependancyChecker
{
private static final Logger logger = Logger.getLogger("Minecraft");
final Essentials ess;
public EssentialsDependancyChecker(Essentials ess)
{
this.ess = ess;
}
public void checkProtectDependancies()
{
final String dependancyLocation = "http://mirrors.ibiblio.org/pub/mirrors/maven2/c3p0/c3p0/0.9.1.2/c3p0-0.9.1.2.jar";
File dependancyFile = new File("lib/c3p0-0.9.1.2.jar");
if (!dependancyFile.exists())
{
logger.log(Level.INFO, Util.i18n("dependancyNotFound"));
try
{
URL url = new URL(dependancyLocation);
BufferedInputStream inStream = new BufferedInputStream(url.openStream());
FileOutputStream fos = new FileOutputStream(dependancyFile);
BufferedOutputStream outStream = new BufferedOutputStream(fos, 1024);
byte[] buffer = new byte[1024];
int len = 0;
while ((len = inStream.read(buffer)) > 0)
{
outStream.write(buffer, 0, len);
}
outStream.close();
fos.close();
inStream.close();
logger.log(Level.INFO, Util.format("dependancyDownloaded", dependancyFile.getName()));
}
catch (MalformedURLException ex)
{
logger.log(Level.SEVERE, Util.i18n("urlMalformed"), ex);
}
catch (FileNotFoundException ex)
{
logger.log(Level.SEVERE, Util.i18n("dependancyException"), ex);
}
catch (IOException ex)
{
logger.log(Level.SEVERE, Util.i18n("dependancyException"), ex);
}
}
}
}

View File

@ -43,8 +43,7 @@ public class EssentialsTimer implements Runnable, IConf
for (User user: allUsers) {
if (user.getBanTimeout() > 0 && user.getBanTimeout() < currentTime) {
user.setBanTimeout(0);
((CraftServer)ess.getServer()).getHandle().b(user.getName());
ess.loadBanList();
ess.getBans().unbanByName(user.getName());
}
if (user.getMuteTimeout() > 0 && user.getMuteTimeout() < currentTime && user.isMuted()) {
user.setMuteTimeout(0);

View File

@ -11,6 +11,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.scheduler.CraftScheduler;
import org.bukkit.plugin.PluginDescriptionFile;
public interface IEssentials
{
void addReloadListener(IConf listener);
@ -45,11 +46,7 @@ public interface IEssentials
Spawn getSpawn();
void loadBanList();
public boolean isRegisterFallbackEnabled();
public Methods getPaymentMethod();
Methods getPaymentMethod();
Server getServer();
@ -65,14 +62,10 @@ public interface IEssentials
int scheduleSyncRepeatingTask(final Runnable run, long delay, long period);
List<String> getBans();
List<String> getBannedIps();
BanWorkaround getBans();
TNTExplodeListener getTNTListener();
EssentialsDependancyChecker getDependancyChecker();
IPermissionsHandler getPermissionsHandler();
void showError(final CommandSender sender, final Throwable exception, final String commandLabel);

View File

@ -19,12 +19,12 @@ public class PlayerExtension extends PlayerWrapper
public boolean isBanned()
{
return ess.getBans().contains(getName());
return ess.getBans().isNameBanned(this.getName());
}
public boolean isIpBanned()
{
return ess.getBannedIps().contains(getAddress().getAddress().toString().replace("/", ""));
return ess.getBans().isIpBanned(getAddress().getAddress().getHostAddress());
}
public float getCorrectedYaw()

View File

@ -276,7 +276,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
@Override
public double getMoney()
{
if (ess.isRegisterFallbackEnabled() && ess.getPaymentMethod().hasMethod())
if (ess.getPaymentMethod().hasMethod())
{
try
{
@ -298,7 +298,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
@Override
public void setMoney(double value)
{
if (ess.isRegisterFallbackEnabled() && ess.getPaymentMethod().hasMethod())
if (ess.getPaymentMethod().hasMethod())
{
try
{

View File

@ -2,7 +2,6 @@ package com.earth2me.essentials.commands;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.CraftServer;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
@ -15,7 +14,7 @@ public class Commandban 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, final String[] args) throws Exception
{
if (args.length < 1)
{
@ -24,7 +23,7 @@ public class Commandban extends EssentialsCommand
if (server.matchPlayer(args[0]).isEmpty())
{
((CraftServer)server).getHandle().a(args[0]);
ess.getBans().banByName(args[0]);
server.broadcastMessage(Util.format("playerBanned", args[0], Util.i18n("defaultBanReason")));
}
else
@ -41,9 +40,8 @@ public class Commandban extends EssentialsCommand
banReason = Util.i18n("defaultBanReason");
}
player.kickPlayer(banReason);
((CraftServer)server).getHandle().a(player.getName());
ess.getBans().banByName(args[0]);
server.broadcastMessage(Util.format("playerBanned", player.getName(), banReason));
}
ess.loadBanList();
}
}

View File

@ -3,7 +3,6 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.Util;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.CraftServer;
public class Commandbanip extends EssentialsCommand
@ -21,9 +20,7 @@ public class Commandbanip extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
((CraftServer)server).getHandle().c(args[0]);
ess.getBans().banByIp(args[0]);
sender.sendMessage(Util.i18n("banIpAddress"));
ess.loadBanList();
}
}

View File

@ -2,8 +2,6 @@ package com.earth2me.essentials.commands;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.CraftServer;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
@ -16,36 +14,22 @@ public class Commandtempban 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, final String[] args) throws Exception
{
if (args.length < 2)
{
throw new NotEnoughArgumentsException();
}
User p = null;
try
{
p = getPlayer(server, args, 0);
}
catch (NoSuchFieldException ex)
{
p = ess.getOfflineUser(args[0]);
}
if (p == null)
{
sender.sendMessage(Util.format("playerNotFound"));
}
final User player = getPlayer(server, args, 0, true);
final String time = getFinalArg(args, 1);
final long banTimestamp = Util.parseDateDiff(time, true);
String time = getFinalArg(args, 1);
long banTimestamp = Util.parseDateDiff(time, true);
String banReason = Util.format("tempBanned", Util.formatDateDiff(banTimestamp));
p.setBanReason(banReason);
p.setBanTimeout(banTimestamp);
p.kickPlayer(banReason);
((CraftServer)server).getHandle().a(p.getName());
server.broadcastMessage(Util.format("playerBanned", p.getName(), banReason));
Essentials.getStatic().loadBanList();
final String banReason = Util.format("tempBanned", Util.formatDateDiff(banTimestamp));
player.setBanReason(banReason);
player.setBanTimeout(banTimestamp);
player.kickPlayer(banReason);
ess.getBans().banByName(player.getName());
server.broadcastMessage(Util.format("playerBanned", player.getName(), banReason));
}
}

View File

@ -3,7 +3,6 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.Util;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.CraftServer;
public class Commandunban extends EssentialsCommand
@ -14,15 +13,14 @@ public class Commandunban 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, final String[] args) throws Exception
{
if (args.length < 1)
{
throw new NotEnoughArgumentsException();
}
((CraftServer)server).getHandle().b(args[0]);
ess.getBans().unbanByName(args[0]);
sender.sendMessage(Util.i18n("unbannedPlayer"));
ess.loadBanList();
}
}

View File

@ -3,7 +3,6 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.Util;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.CraftServer;
public class Commandunbanip extends EssentialsCommand
@ -14,15 +13,14 @@ public class Commandunbanip 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, final String[] args) throws Exception
{
if (args.length < 1)
{
throw new NotEnoughArgumentsException();
}
((CraftServer)server).getHandle().d(args[0]);
ess.getBans().unbanByIp(args[0]);
sender.sendMessage(Util.i18n("unbannedIP"));
ess.loadBanList();
}
}