Merge branch 'bukkitupdate'

This commit is contained in:
snowleo 2011-09-15 00:34:29 +02:00
commit 828f97c9a8
17 changed files with 141 additions and 197 deletions

View File

@ -1,157 +0,0 @@
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

@ -57,7 +57,6 @@ public class Essentials extends JavaPlugin implements IEssentials
private transient Worth worth;
private transient List<IConf> confList;
private transient Backup backup;
private transient BanWorkaround bans;
private transient ItemDb itemDb;
private transient EssentialsUpdateTimer updateTimer;
private transient final Methods paymentMethod = new Methods();
@ -119,8 +118,6 @@ 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);
itemDb = new ItemDb(this);
confList.add(itemDb);
reload();
@ -675,12 +672,6 @@ public class Essentials extends JavaPlugin implements IEssentials
return permissionsHandler;
}
@Override
public BanWorkaround getBans()
{
return bans;
}
@Override
public ItemDb getItemDb()
{

View File

@ -266,14 +266,6 @@ public class EssentialsPlayerListener extends PlayerListener
ess.getBackup().onPlayerJoin();
final User user = ess.getUser(event.getPlayer());
//we do not know the ip address on playerlogin so we need to do this here.
if (user.isIpBanned())
{
final String banReason = user.getBanReason();
user.kickPlayer(banReason != null && !banReason.isEmpty() ? banReason : Util.i18n("defaultBanReason"));
return;
}
if (ess.getSettings().changeDisplayName())
{
user.setDisplayName(user.getNick());

View File

@ -424,5 +424,17 @@ public class FakeWorld implements World
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isAutoSave()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setAutoSave(boolean bln)
{
throw new UnsupportedOperationException("Not supported yet.");
}
}

View File

@ -53,8 +53,6 @@ public interface IEssentials extends Plugin
int scheduleSyncRepeatingTask(final Runnable run, long delay, long period);
BanWorkaround getBans();
TNTExplodeListener getTNTListener();
PermissionsHandler getPermissionsHandler();

View File

@ -39,22 +39,24 @@ public class OfflinePlayer implements Player
private Location location = new Location(null, 0, 0, 0, 0, 0);
private World world;
private UUID uniqueId = UUID.randomUUID();
private org.bukkit.OfflinePlayer base;
public OfflinePlayer(String name, IEssentials ess)
{
this.name = name;
this.ess = ess;
this.world = ess.getServer().getWorlds().get(0);
this.base = ess.getServer().getOfflinePlayer(name);
}
public boolean isOnline()
{
return false;
return base.isOnline();
}
public boolean isOp()
{
return false;
return base.isOp();
}
public void sendMessage(String string)
@ -576,6 +578,7 @@ public class OfflinePlayer implements Player
public void setOp(boolean bln)
{
base.setOp(bln);
}
@Override
@ -583,4 +586,28 @@ public class OfflinePlayer implements Player
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isBanned()
{
return base.isBanned();
}
@Override
public void setBanned(boolean bln)
{
base.setBanned(bln);
}
@Override
public boolean isWhitelisted()
{
return base.isWhitelisted();
}
@Override
public void setWhitelisted(boolean bln)
{
base.setWhitelisted(bln);
}
}

View File

@ -17,16 +17,6 @@ public class PlayerExtension extends PlayerWrapper
this.ess = ess;
}
public boolean isBanned()
{
return ess.getBans().isNameBanned(this.getName());
}
public boolean isIpBanned()
{
return ess.getBans().isIpBanned(getAddress().getAddress().getHostAddress());
}
public float getCorrectedYaw()
{
float angle = (getLocation().getYaw() - 90.0f) % 360.0f;

View File

@ -617,4 +617,28 @@ public class PlayerWrapper implements Player
{
base.sendMap(mv);
}
@Override
public boolean isBanned()
{
return base.isBanned();
}
@Override
public void setBanned(boolean bln)
{
base.setBanned(bln);
}
@Override
public boolean isWhitelisted()
{
return base.isWhitelisted();
}
@Override
public void setWhitelisted(boolean bln)
{
base.setWhitelisted(bln);
}
}

View File

@ -411,10 +411,10 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
public void checkBanTimeout(final long currentTime)
{
if (getBanTimeout() > 0 && getBanTimeout() < currentTime && ess.getBans().isNameBanned(getName()))
if (getBanTimeout() > 0 && getBanTimeout() < currentTime && isBanned())
{
setBanTimeout(0);
ess.getBans().unbanByName(getName());
setBanned(false);
}
}

View File

@ -52,8 +52,8 @@ public class Commandban extends EssentialsCommand
{
banReason = Util.i18n("defaultBanReason");
}
player.setBanned(true);
player.kickPlayer(banReason);
ess.getBans().banByName(player.getName());
String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME;
for(Player p : server.getOnlinePlayers())

View File

@ -20,7 +20,7 @@ public class Commandbanip extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
ess.getBans().banByIp(args[0]);
ess.getServer().banIP(args[0]);
sender.sendMessage(Util.i18n("banIpAddress"));
}
}

View File

@ -47,8 +47,8 @@ public class Commandtempban extends EssentialsCommand
final String banReason = Util.format("tempBanned", Util.formatDateDiff(banTimestamp));
player.setBanReason(banReason);
player.setBanTimeout(banTimestamp);
player.setBanned(true);
player.kickPlayer(banReason);
ess.getBans().banByName(player.getName());
String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME;
for(Player p : server.getOnlinePlayers())

View File

@ -26,12 +26,12 @@ public class Commandunban extends EssentialsCommand
{
User u = getPlayer(server, args, 0, true);
name = u.getName();
u.setBanned(false);
sender.sendMessage(Util.i18n("unbannedPlayer"));
}
catch (NoSuchFieldException e)
{
name = args[0];
sender.sendMessage(Util.i18n("playerNotFound"));
}
ess.getBans().unbanByName(name);
sender.sendMessage(Util.i18n("unbannedPlayer"));
}
}

View File

@ -20,7 +20,7 @@ public class Commandunbanip extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
ess.getBans().unbanByIp(args[0]);
ess.getServer().unbanIP(args[0]);
sender.sendMessage(Util.i18n("unbannedIP"));
}
}

View File

@ -4,6 +4,7 @@ import com.avaje.ebean.config.ServerConfig;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
@ -378,4 +379,70 @@ public class FakeServer implements Server
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setWhitelist(boolean bln)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Set<org.bukkit.OfflinePlayer> getWhitelistedPlayers()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void reloadWhitelist()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Player getPlayerExact(String string)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void shutdown()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int broadcast(String string, String string1)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public org.bukkit.OfflinePlayer getOfflinePlayer(String string)
{
return null;
}
@Override
public Set<String> getIPBans()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void banIP(String string)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void unbanIP(String string)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Set<org.bukkit.OfflinePlayer> getBannedPlayers()
{
throw new UnsupportedOperationException("Not supported yet.");
}
}

Binary file not shown.

Binary file not shown.