mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-12 04:20:41 +00:00
Update to new ban method.
This commit is contained in:
parent
575a8142ff
commit
51be2131f7
10 changed files with 97 additions and 83 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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")))
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
||||
|
@ -47,7 +49,8 @@ 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));
|
||||
|
||||
|
|
Loading…
Reference in a new issue