Skip to content

Commit

Permalink
Update to new ban method.
Browse files Browse the repository at this point in the history
  • Loading branch information
FearFree authored and khobbits committed Jul 12, 2014
1 parent 575a814 commit 51be213
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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;
Expand Down Expand Up @@ -357,21 +356,6 @@ private void updateCompass(final User user)
}
}

@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)
{
Expand All @@ -386,28 +370,6 @@ public void onPlayerLogin(final PlayerLoginEvent event)
}
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;
}
Expand Down
73 changes: 73 additions & 0 deletions Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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;
Expand All @@ -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)
{
Expand Down Expand Up @@ -659,6 +662,75 @@ public static void uuidFileConvert(IEssentials ess, Boolean ignoreUFCache)
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)

This comment has been minimized.

Copy link
@md-5

md-5 Jul 16, 2014

Member

Really?

{
//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())
Expand All @@ -678,6 +750,7 @@ public void afterSettings()
updateSpawnsToNewSpawnsConfig();
updateJailsToNewJailsConfig();
uuidFileChange();
banFormatChange();
warnMetrics();
}
}
12 changes: 0 additions & 12 deletions Essentials/src/com/earth2me/essentials/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -594,18 +594,6 @@ public boolean checkMuteTimeout(final long currentTime)
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())
Expand Down
21 changes: 0 additions & 21 deletions Essentials/src/com/earth2me/essentials/UserData.java
Original file line number Diff line number Diff line change
Expand Up @@ -667,27 +667,6 @@ public void setJailTimeout(long time)
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
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;


Expand Down Expand Up @@ -61,9 +63,7 @@ public void run(final Server server, final CommandSource sender, final String co
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public void run()
continue;
}

int ban = user.getBanReason().isEmpty() ? 0 : 1;
int ban = user.getBase().isBanned() ? 0 : 1;

long lastLog = user.getLastLogout();
if (lastLog == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
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;
Expand Down Expand Up @@ -59,6 +61,10 @@ else if (FormatUtil.validIP(args[0]) && (server.getIPBans().contains(args[0])))
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();
Expand Down Expand Up @@ -137,7 +143,7 @@ private void seenOffline(final Server server, final CommandSource sender, User u

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")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
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;


Expand Down Expand Up @@ -61,9 +64,8 @@ public void run(final Server server, final CommandSource sender, final String co

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);

This comment has been minimized.

Copy link
@mibby

mibby Jul 14, 2014

@FearFree, @khobbits

Temp-ban isn't working. The command /tempban {name} {time} seems to be banning the player, not temp-banning. Maybe it has something to do with this instead? 0c416c8#diff-2fa6b6dcba0aa4e0708eb086bff9d036R47

This comment has been minimized.

Copy link
@khobbits

khobbits Jul 14, 2014

Member

It does appear to be working, I just tested it.

This comment has been minimized.

Copy link
@mibby

mibby Jul 14, 2014

Odd. I'm testing it myself now with different syntax compositions, but the result is the same. A full ban.

This comment has been minimized.

Copy link
@khobbits

khobbits Jul 14, 2014

Member

Why would you consider it a fullban?

This comment has been minimized.

Copy link
@mibby

mibby Jul 14, 2014

Maybe it has something to do with how it is worded and outputted? As it outputs twice.

[12:40:12] [Server thread/INFO]: CONSOLE issued server command: /tempban mibby 5 minutes Test
[12:40:12] [Server thread/INFO]: §6Player§c Console §6banned§c mibby §6for: §c§cYou have been temporarily banned for 4 minutes 59 seconds:
§rTest§6.
[12:40:12] [Server thread/INFO]: §6Player§c Console §6banned§c mibby §6for: §cTest§6.

Edit: Some more logs. Seems to double output when trying to log on and seen states a full ban instead of temp-ban.

[12:40:40] [Server thread/INFO]: Disconnecting net.minecraft.util.com.mojang.authlib.GameProfile@74e0bb4d[id=UUID,name=mibby,properties={textures=[net.minecraft.util.com.mojang.authlib.properties.Property@1cf01e19]},legacy=false] (/IP): You are banned from this server!
Reason: Test
Your ban will be removed on 2014-07-14 at 12:45:12 MST
[12:40:40] [Server thread/INFO]: net.minecraft.util.com.mojang.authlib.GameProfile@74e0bb4d[id=UUID,name=mibby,properties={textures=[net.minecraft.util.com.mojang.authlib.properties.Property@1cf01e19]},legacy=false] (/IP) lost connection: You are banned from this server!
Reason: Test
Your ban will be removed on 2014-07-14 at 12:45:12 MST
[12:44:24] [Server thread/INFO]: Player mibby has been offline since 18 minutes 29 seconds.
[12:44:24] [Server thread/INFO]:  - Banned: Test

This comment has been minimized.

Copy link
@khobbits

khobbits Jul 14, 2014

Member

Hmm, you are right, it's showing twice, I can fix that.
The rest looks fine though.
The big give away is the "Your ban will be removed on 2014-07-14 at 12:45:12 MST"

This comment has been minimized.

Copy link
@mibby

mibby Jul 14, 2014

That seems to be for console only. I typed the command in-game and it outputted;

/tempban mibby 5m test
"Player mibby2 banned mibby for: {reason}."

It does not specify a time or that it is a tempban. And there doesn't seem to be a time for players/staff to see how much time remains on a temp-ban (seen) or how much time was initially put when temp-banning, when outputting the results back to staff; so they know it is a temp-ban and not a regular ban.

This comment has been minimized.

Copy link
@khobbits

khobbits Jul 14, 2014

Member

I suppose I could make it a little more clear, I had to remove the tempban formatting, since bukkit now handles it.

This comment has been minimized.

Copy link
@mibby

mibby Jul 14, 2014

Hm. It seems only the second line of the double output is actually returned to the client. Console shows the following for /tempban mibby 5m test.

[12:49:38] [Server thread/INFO]: §6Player§c §mibby2§r §6banned§c mibby §6for: §c§cYou have been temporarily banned for 4 minutes 59 seconds:
§rtest§6.
[12:49:38] [Server thread/INFO]: §6Player§c §mibby2§r §6banned§c mibby §6for: §ctest§6.

But I was only shown the second line on my client.

Player mibby2 banned mibby for: test.

This comment has been minimized.

Copy link
@mibby

mibby Jul 14, 2014

It also seems datediff was removed? (Where temp-banned players trying to login, it outputted and counted down to the client how many days, hours, and minutes remained on the ban.) Now it only specifies an exact date and time when the player will be unbanned and in the timezone of the server node. :( Is there any way to bring back datediff or change the timezone outputted?

This comment has been minimized.

Copy link
@khobbits

khobbits Jul 14, 2014

Member

That's how Bukkit decided to handle tempbans, I'm not really a big fan, but I don't see an easy way to change the message, without breaking other ban plugins using the new system.

This comment has been minimized.

Copy link
@mibby

mibby Jul 14, 2014

Oh man.. This all just sucks. :( So no datediff and no way to change the timezone outputted to clients for static dates? Disappointing news indeed.

This comment has been minimized.

Copy link
@khobbits

khobbits Jul 15, 2014

Member

I did make a couple of formatting changes to the message shown ingame and in /seen to properly reflect that it is a tempban.

I probably will look into reformatting the ban/tempban messages shown on connect, but currently they show the new bukkit default ban/tempban messages.

The problem is working out when to replace the bukkit message with an essentials one. We don't want to overwrite changes by other plugins.

This comment has been minimized.

Copy link
@mibby

mibby Jul 16, 2014

Great progress. Much more clear now that it states temp-ban instead of ban when typing the command and /seen addition is wonderful.

One thing I did notice that should probably be updated is the default '/tempban' command syntax return.
It returns

/tempban <playername> <datediff>

Shouldn't [reason] be added to it?

Still optimistic that datediff may be readded in the future, but if not, I'll just have to live with the static date. :(

user.getBase().kickPlayer(banReason);

final String message = tl("playerBanned", senderName, user.getName(), banReason, DateUtil.formatDateDiff(banTimestamp));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
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;

Expand All @@ -28,8 +30,7 @@ public void run(final Server server, final CommandSource sender, final String co
{
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)
{
Expand All @@ -39,7 +40,7 @@ public void run(final Server server, final CommandSource sender, final String co
{
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
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;


Expand Down Expand Up @@ -46,8 +48,9 @@ public void run(final Server server, final CommandSource sender, final String co
{
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));

Expand Down

0 comments on commit 51be213

Please sign in to comment.