summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFearFree <fearfree@cubetown.net>2014-07-12 17:37:25 +0100
committerKHobbits <rob@khobbits.co.uk>2014-07-12 17:40:14 +0100
commit6d8d3a486f76921433067c77589ca09b598979fa (patch)
tree95b66e861679acebef74afe6afd1b5768c91c0af
parent394ea6f172e211853a5cbf6fdb732fc84b1d4c04 (diff)
downloadEssentials-6d8d3a486f76921433067c77589ca09b598979fa.tar
Essentials-6d8d3a486f76921433067c77589ca09b598979fa.tar.gz
Essentials-6d8d3a486f76921433067c77589ca09b598979fa.tar.lz
Essentials-6d8d3a486f76921433067c77589ca09b598979fa.tar.xz
Essentials-6d8d3a486f76921433067c77589ca09b598979fa.zip
Update to new ban method.
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java38
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java73
-rw-r--r--Essentials/src/com/earth2me/essentials/User.java12
-rw-r--r--Essentials/src/com/earth2me/essentials/UserData.java21
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandban.java6
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandessentials.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandseen.java8
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandtempban.java8
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandunban.java7
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java5
10 files changed, 97 insertions, 83 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
index 980c0e030..66dbfd963 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
@@ -5,7 +5,6 @@ import com.earth2me.essentials.textreader.IText;
import com.earth2me.essentials.textreader.KeywordReplacer;
import com.earth2me.essentials.textreader.TextInput;
import com.earth2me.essentials.textreader.TextPager;
-import com.earth2me.essentials.utils.DateUtil;
import com.earth2me.essentials.utils.LocationUtil;
import java.io.IOException;
import java.util.Iterator;
@@ -357,21 +356,6 @@ public class EssentialsPlayerListener implements Listener
}
}
- @EventHandler(priority = EventPriority.LOWEST)
- public void onPlayerLogin2(final PlayerLoginEvent event)
- {
- switch (event.getResult())
- {
- case KICK_BANNED:
- break;
- default:
- return;
- }
-
- final String banReason = tl("banFormat", tl("defaultBanReason"), "Console");
- event.disallow(Result.KICK_BANNED, banReason);
- }
-
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerLogin(final PlayerLoginEvent event)
{
@@ -386,28 +370,6 @@ public class EssentialsPlayerListener implements Listener
}
event.disallow(Result.KICK_FULL, tl("serverFull"));
break;
-
- case KICK_BANNED:
- final User user = ess.getUser(event.getPlayer());
- final boolean banExpired = user.checkBanTimeout(System.currentTimeMillis());
- if (banExpired)
- {
- event.allow();
- return;
- }
- String banReason = user.getBanReason();
- if (banReason == null || banReason.isEmpty() || banReason.equalsIgnoreCase("ban"))
- {
- banReason = event.getKickMessage();
- }
- if (user.getBanTimeout() > 0)
- {
- //TODO: TL This
- banReason += "\n\n" + "Expires in " + DateUtil.formatDateDiff(user.getBanTimeout());
- }
- event.disallow(Result.KICK_BANNED, banReason);
- break;
-
default:
break;
}
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java
index a90641d4c..ba93f09c2 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java
@@ -14,6 +14,7 @@ import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.ess3.api.IEssentials;
+import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
@@ -24,6 +25,8 @@ public class EssentialsUpgrade
private final static Logger LOGGER = Logger.getLogger("Essentials");
private final transient IEssentials ess;
private final transient EssentialsConf doneFile;
+ private String banReason;
+ private Long banTimeout;
EssentialsUpgrade(final IEssentials essentials)
{
@@ -659,6 +662,75 @@ public class EssentialsUpgrade
ess.getLogger().info("To rerun the conversion type /essentials uuidconvert");
}
+ public void banFormatChange()
+ {
+ if (doneFile.getBoolean("banFormatChange", false))
+ {
+ return;
+ }
+
+ ess.getLogger().info("Starting Essentials ban format conversion");
+
+ final File userdir = new File(ess.getDataFolder(), "userdata");
+ if (!userdir.exists())
+ {
+ return;
+ }
+ File[] playerFiles = userdir.listFiles();
+
+ for (File pFile : playerFiles)
+ {
+ EssentialsConf conf = new EssentialsConf(pFile);
+ conf.load();
+ try
+ {
+ banReason = conf.getConfigurationSection("ban").getString("reason");
+ }
+ catch (NullPointerException n)
+ {
+ //No ban in userfile
+ banReason = "";
+ }
+
+ String playerName = conf.getString("lastAccountName");
+ if (!banReason.equals(""))
+ {
+ try
+ {
+ banTimeout = Long.parseLong(conf.getConfigurationSection("ban").getString("timeout"));
+ }
+ catch (NumberFormatException n)
+ {
+ //No ban timeout set, or malformed timeout.
+ banTimeout = 0L;
+ }
+ org.bukkit.OfflinePlayer player = ess.getServer().getOfflinePlayer(playerName);
+ if (player.isBanned())
+ {
+ updateBan(playerName, banReason, banTimeout);
+ }
+ }
+ conf.removeProperty("ban");
+ conf.save();
+ }
+
+ doneFile.setProperty("banFormatChange", true);
+ doneFile.save();
+ ess.getLogger().info("Ban format update complete.");
+ }
+
+ private void updateBan(String playerName, String banReason, Long banTimeout)
+ {
+ if (banTimeout == 0)
+ {
+ Bukkit.getBanList(BanList.Type.NAME).addBan(playerName, banReason, null, Console.NAME);
+ }
+ else
+ {
+ Bukkit.getBanList(BanList.Type.NAME).addBan(playerName, banReason, new Date(banTimeout), Console.NAME);
+ }
+ }
+
public void beforeSettings()
{
if (!ess.getDataFolder().exists())
@@ -678,6 +750,7 @@ public class EssentialsUpgrade
updateSpawnsToNewSpawnsConfig();
updateJailsToNewJailsConfig();
uuidFileChange();
+ banFormatChange();
warnMetrics();
}
}
diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java
index 7e0921739..bca444dde 100644
--- a/Essentials/src/com/earth2me/essentials/User.java
+++ b/Essentials/src/com/earth2me/essentials/User.java
@@ -594,18 +594,6 @@ public class User extends UserData implements Comparable<User>, IReplyTo, net.es
return false;
}
- //Returns true if status expired during this check
- public boolean checkBanTimeout(final long currentTime)
- {
- if (getBanTimeout() > 0 && getBanTimeout() < currentTime && this.getBase().isBanned())
- {
- setBanTimeout(0);
- this.getBase().setBanned(false);
- return true;
- }
- return false;
- }
-
public void updateActivity(final boolean broadcast)
{
if (isAfk() && ess.getSettings().cancelAfkOnInteract())
diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java
index 3de18092a..136e74fbe 100644
--- a/Essentials/src/com/earth2me/essentials/UserData.java
+++ b/Essentials/src/com/earth2me/essentials/UserData.java
@@ -667,27 +667,6 @@ public abstract class UserData extends PlayerExtension implements IConf
config.save();
}
- public String getBanReason()
- {
- return config.getString("ban.reason", "");
- }
-
- public void setBanReason(String reason)
- {
- config.setProperty("ban.reason", StringUtil.sanitizeString(reason));
- config.save();
- }
-
- public long getBanTimeout()
- {
- return config.getLong("ban.timeout", 0);
- }
-
- public void setBanTimeout(long time)
- {
- config.setProperty("ban.timeout", time);
- config.save();
- }
private long lastLogin;
private long _getLastLogin()
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandban.java b/Essentials/src/com/earth2me/essentials/commands/Commandban.java
index a9408360f..7480864d7 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandban.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandban.java
@@ -7,6 +7,8 @@ import com.earth2me.essentials.OfflinePlayer;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.FormatUtil;
import java.util.logging.Level;
+import org.bukkit.BanList;
+import org.bukkit.Bukkit;
import org.bukkit.Server;
@@ -61,9 +63,7 @@ public class Commandban extends EssentialsCommand
banReason = tl("defaultBanReason");
}
- user.setBanReason(tl("banFormat", banReason, senderName));
- user.getBase().setBanned(true);
- user.setBanTimeout(0);
+ Bukkit.getBanList(BanList.Type.NAME).addBan(user.getName(), banReason, null, senderName);
user.getBase().kickPlayer(tl("banFormat", banReason, senderName));
server.getLogger().log(Level.INFO, tl("playerBanned", senderName, user.getName(), banReason));
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java
index 44c632356..4c6c8f230 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java
@@ -289,7 +289,7 @@ public class Commandessentials extends EssentialsCommand
continue;
}
- int ban = user.getBanReason().isEmpty() ? 0 : 1;
+ int ban = user.getBase().isBanned() ? 0 : 1;
long lastLog = user.getLastLogout();
if (lastLog == 0)
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandseen.java b/Essentials/src/com/earth2me/essentials/commands/Commandseen.java
index 51a03c616..08d6cf4b3 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandseen.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandseen.java
@@ -9,6 +9,8 @@ import com.earth2me.essentials.utils.FormatUtil;
import com.earth2me.essentials.utils.StringUtil;
import java.util.ArrayList;
import java.util.List;
+import org.bukkit.BanList;
+import org.bukkit.Bukkit;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.Server;
@@ -59,6 +61,10 @@ public class Commandseen extends EssentialsCommand
sender.sendMessage(tl("isIpBanned", args[0]));
return;
}
+ else if (Bukkit.getBannedPlayers().contains(Bukkit.getOfflinePlayer(args[0]))) {
+ sender.sendMessage(tl("whoisBanned", showBan ? Bukkit.getBanList(BanList.Type.NAME).getBanEntry(Bukkit.getOfflinePlayer(args[0]).getName()).getReason() : tl("true")));
+ return;
+ }
else
{
throw new PlayerNotFoundException();
@@ -137,7 +143,7 @@ public class Commandseen extends EssentialsCommand
if (user.getBase().isBanned())
{
- sender.sendMessage(tl("whoisBanned", showBan ? user.getBanReason() : tl("true")));
+ sender.sendMessage(tl("whoisBanned", showBan ? Bukkit.getBanList(BanList.Type.NAME).getBanEntry(user.getName()).getReason() : tl("true")));
}
final String location = user.getGeoLocation();
if (location != null && (!(sender.isPlayer()) || ess.getUser(sender.getPlayer()).isAuthorized("essentials.geoip.show")))
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java b/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java
index 478c2c257..aeaf4dbd8 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java
@@ -5,8 +5,11 @@ import com.earth2me.essentials.Console;
import static com.earth2me.essentials.I18n.tl;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.DateUtil;
+import java.util.Date;
import java.util.GregorianCalendar;
import java.util.logging.Level;
+import org.bukkit.BanList;
+import org.bukkit.Bukkit;
import org.bukkit.Server;
@@ -61,9 +64,8 @@ public class Commandtempban extends EssentialsCommand
final String senderName = sender.isPlayer() ? sender.getPlayer().getDisplayName() : Console.NAME;
final String banReason = tl("tempBanned", DateUtil.formatDateDiff(banTimestamp), senderName, stringDregs);
- user.setBanReason(banReason);
- user.setBanTimeout(banTimestamp);
- user.getBase().setBanned(true);
+
+ Bukkit.getBanList(BanList.Type.NAME).addBan(user.getName(), banReason, new Date(banTimestamp), senderName);
user.getBase().kickPlayer(banReason);
final String message = tl("playerBanned", senderName, user.getName(), banReason, DateUtil.formatDateDiff(banTimestamp));
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandunban.java b/Essentials/src/com/earth2me/essentials/commands/Commandunban.java
index 44777dcd1..db358e0dd 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandunban.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandunban.java
@@ -5,6 +5,8 @@ import com.earth2me.essentials.Console;
import static com.earth2me.essentials.I18n.tl;
import com.earth2me.essentials.User;
import java.util.logging.Level;
+import org.bukkit.BanList;
+import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
@@ -28,8 +30,7 @@ public class Commandunban extends EssentialsCommand
{
final User user = getPlayer(server, args, 0, true, true);
name = user.getName();
- user.getBase().setBanned(false);
- user.setBanTimeout(0);
+ Bukkit.getBanList(BanList.Type.NAME).pardon(name);
}
catch (NoSuchFieldException e)
{
@@ -39,7 +40,7 @@ public class Commandunban extends EssentialsCommand
{
throw new Exception(tl("playerNotFound"), e);
}
- player.setBanned(false);
+ Bukkit.getBanList(BanList.Type.NAME).pardon(name);
}
final String senderName = sender.isPlayer() ? sender.getPlayer().getDisplayName() : Console.NAME;
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java b/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java
index 1d79c94e0..b7477f7e7 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java
@@ -6,6 +6,8 @@ import static com.earth2me.essentials.I18n.tl;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.FormatUtil;
import java.util.logging.Level;
+import org.bukkit.BanList;
+import org.bukkit.Bukkit;
import org.bukkit.Server;
@@ -46,8 +48,9 @@ public class Commandunbanip extends EssentialsCommand
{
throw new PlayerNotFoundException();
}
+
- ess.getServer().unbanIP(ipAddress);
+ Bukkit.getBanList(BanList.Type.IP).pardon(ipAddress);
final String senderName = sender.isPlayer() ? sender.getPlayer().getDisplayName() : Console.NAME;
server.getLogger().log(Level.INFO, tl("playerUnbanIpAddress", senderName, ipAddress));