mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-30 02:05:41 +00:00
UUID definite bans
This commit is contained in:
parent
00f94e47f1
commit
aab4f55b7d
@ -10,6 +10,7 @@ import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
@ -27,6 +28,9 @@ public class Ban
|
||||
@Setter
|
||||
private String username = null;
|
||||
@Getter
|
||||
@Setter
|
||||
private UUID uuid = null;
|
||||
@Getter
|
||||
private final List<String> ips = Lists.newArrayList();
|
||||
@Getter
|
||||
@Setter
|
||||
@ -45,9 +49,10 @@ public class Ban
|
||||
{
|
||||
}
|
||||
|
||||
public Ban(String username, String ip, String by, Date at, Date expire, String reason)
|
||||
public Ban(String username, UUID uuid, String ip, String by, Date at, Date expire, String reason)
|
||||
{
|
||||
this(username,
|
||||
uuid,
|
||||
Arrays.asList(ip),
|
||||
by,
|
||||
at,
|
||||
@ -55,9 +60,10 @@ public class Ban
|
||||
reason);
|
||||
}
|
||||
|
||||
public Ban(String username, List<String> ips, String by, Date at, Date expire, String reason)
|
||||
public Ban(String username, UUID uuid, List<String> ips, String by, Date at, Date expire, String reason)
|
||||
{
|
||||
this.username = username;
|
||||
this.uuid = uuid;
|
||||
if (ips != null)
|
||||
{
|
||||
this.ips.addAll(ips);
|
||||
@ -78,12 +84,12 @@ public class Ban
|
||||
|
||||
public static Ban forPlayerIp(Player player, CommandSender by, Date expiry, String reason)
|
||||
{
|
||||
return new Ban(null, Arrays.asList(FUtil.getIp(player)), by.getName(), Date.from(Instant.now()), expiry, reason);
|
||||
return new Ban(null, null, Arrays.asList(FUtil.getIp(player)), by.getName(), Date.from(Instant.now()), expiry, reason);
|
||||
}
|
||||
|
||||
public static Ban forPlayerIp(String ip, CommandSender by, Date expiry, String reason)
|
||||
{
|
||||
return new Ban(null, ip, by.getName(), Date.from(Instant.now()), expiry, reason);
|
||||
return new Ban(null, null, ip, by.getName(), Date.from(Instant.now()), expiry, reason);
|
||||
}
|
||||
|
||||
//
|
||||
@ -96,7 +102,8 @@ public class Ban
|
||||
public static Ban forPlayerName(String player, CommandSender by, Date expiry, String reason)
|
||||
{
|
||||
return new Ban(player,
|
||||
new ArrayList<String>(),
|
||||
null,
|
||||
new ArrayList<>(),
|
||||
by.getName(),
|
||||
Date.from(Instant.now()),
|
||||
expiry,
|
||||
@ -113,6 +120,7 @@ public class Ban
|
||||
public static Ban forPlayer(Player player, CommandSender by, Date expiry, String reason)
|
||||
{
|
||||
return new Ban(player.getName(),
|
||||
player.getUniqueId(),
|
||||
FUtil.getIp(player),
|
||||
by.getName(),
|
||||
Date.from(Instant.now()),
|
||||
@ -123,6 +131,7 @@ public class Ban
|
||||
public static Ban forPlayerFuzzy(Player player, CommandSender by, Date expiry, String reason)
|
||||
{
|
||||
return new Ban(player.getName(),
|
||||
player.getUniqueId(),
|
||||
FUtil.getFuzzyIp(FUtil.getIp(player)),
|
||||
by.getName(),
|
||||
Date.from(Instant.now()),
|
||||
@ -135,6 +144,11 @@ public class Ban
|
||||
return username != null && !username.isEmpty();
|
||||
}
|
||||
|
||||
public boolean hasUUID()
|
||||
{
|
||||
return uuid != null;
|
||||
}
|
||||
|
||||
public boolean addIp(String ip)
|
||||
{
|
||||
return ips.add(ip);
|
||||
|
@ -12,6 +12,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
@ -27,8 +28,9 @@ public class BanManager extends FreedomService
|
||||
{
|
||||
|
||||
private final Set<Ban> bans = Sets.newHashSet();
|
||||
private final Map<String, Ban> ipBans = Maps.newHashMap();
|
||||
private final Map<String, Ban> nameBans = Maps.newHashMap();
|
||||
private final Map<UUID, Ban> uuidBans = Maps.newHashMap();
|
||||
private final Map<String, Ban> ipBans = Maps.newHashMap();
|
||||
private final List<String> unbannableUsernames = Lists.newArrayList();
|
||||
|
||||
//
|
||||
@ -44,12 +46,18 @@ public class BanManager extends FreedomService
|
||||
while (banSet.next())
|
||||
{
|
||||
String name = banSet.getString("name");
|
||||
UUID uuid = null;
|
||||
String strUUID = banSet.getString("uuid");
|
||||
if (strUUID != null)
|
||||
{
|
||||
uuid = UUID.fromString(strUUID);
|
||||
}
|
||||
List<String> ips = FUtil.stringToList(banSet.getString("ips"));
|
||||
String by = banSet.getString("by");
|
||||
Date at = new Date(banSet.getLong("at"));
|
||||
Date expires = new Date(banSet.getLong("expires"));
|
||||
String reason = banSet.getString("reason");
|
||||
Ban ban = new Ban(name, ips, by, at, expires, reason);
|
||||
Ban ban = new Ban(name, uuid, ips, by, at, expires, reason);
|
||||
bans.add(ban);
|
||||
}
|
||||
}
|
||||
@ -136,6 +144,18 @@ public class BanManager extends FreedomService
|
||||
return null;
|
||||
}
|
||||
|
||||
public Ban getByUUID(UUID uuid)
|
||||
{
|
||||
final Ban directBan = uuidBans.get(uuid);
|
||||
|
||||
if (directBan != null && !directBan.isExpired())
|
||||
{
|
||||
return directBan;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Ban unbanIp(String ip)
|
||||
{
|
||||
final Ban ban = getByIp(ip);
|
||||
@ -224,13 +244,19 @@ public class BanManager extends FreedomService
|
||||
public void onPlayerLogin(PlayerLoginEvent event)
|
||||
{
|
||||
final String username = event.getPlayer().getName();
|
||||
final UUID uuid = event.getPlayer().getUniqueId();
|
||||
final String ip = FUtil.getIp(event);
|
||||
|
||||
// Regular ban
|
||||
Ban ban = getByUsername(username);
|
||||
if (ban == null)
|
||||
{
|
||||
ban = getByIp(ip);
|
||||
ban = getByUUID(uuid);
|
||||
|
||||
if (ban == null)
|
||||
{
|
||||
ban = getByIp(ip);
|
||||
}
|
||||
}
|
||||
|
||||
if (ban != null && !ban.isExpired())
|
||||
@ -279,6 +305,7 @@ public class BanManager extends FreedomService
|
||||
}
|
||||
|
||||
nameBans.clear();
|
||||
uuidBans.clear();
|
||||
ipBans.clear();
|
||||
for (Ban ban : bans)
|
||||
{
|
||||
@ -287,6 +314,11 @@ public class BanManager extends FreedomService
|
||||
nameBans.put(ban.getUsername().toLowerCase(), ban);
|
||||
}
|
||||
|
||||
if (ban.hasUUID())
|
||||
{
|
||||
uuidBans.put(ban.getUuid(), ban);
|
||||
}
|
||||
|
||||
if (ban.hasIps())
|
||||
{
|
||||
for (String ip : ban.getIps())
|
||||
|
@ -121,7 +121,17 @@ public class Command_ban extends FreedomCommand
|
||||
}
|
||||
|
||||
// Ban player
|
||||
Ban ban = Ban.forPlayerName(username, sender, null, reason);
|
||||
Ban ban;
|
||||
|
||||
if (player != null)
|
||||
{
|
||||
ban = Ban.forPlayer(player, sender, null, reason);
|
||||
}
|
||||
else
|
||||
{
|
||||
ban = Ban.forPlayerName(username, sender, null, reason);
|
||||
}
|
||||
|
||||
for (String ip : ips)
|
||||
{
|
||||
ban.addIp(ip);
|
||||
|
@ -104,7 +104,18 @@ public class Command_tempban extends FreedomCommand
|
||||
msg("Quietly temporarily banned " + player.getName() + ".");
|
||||
}
|
||||
|
||||
Ban ban = Ban.forPlayerName(username, sender, expires, reason);
|
||||
|
||||
Ban ban;
|
||||
|
||||
if (player != null)
|
||||
{
|
||||
ban = Ban.forPlayer(player, sender, null, reason);
|
||||
}
|
||||
else
|
||||
{
|
||||
ban = Ban.forPlayerName(username, sender, null, reason);
|
||||
}
|
||||
|
||||
for (String ip : ips)
|
||||
{
|
||||
ban.addIp(ip);
|
||||
|
@ -70,7 +70,7 @@ public class SQLite extends FreedomService
|
||||
{
|
||||
try
|
||||
{
|
||||
connection.createStatement().execute("CREATE TABLE `bans` (`name` VARCHAR, `ips` VARCHAR, `by` VARCHAR NOT NULL, `at` LONG NOT NULL, `expires` LONG, `reason` VARCHAR);");
|
||||
connection.createStatement().execute("CREATE TABLE `bans` (`name` VARCHAR, `uuid` VARCHAR, `ips` VARCHAR, `by` VARCHAR NOT NULL, `at` LONG NOT NULL, `expires` LONG, `reason` VARCHAR);");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
@ -378,13 +378,19 @@ public class SQLite extends FreedomService
|
||||
{
|
||||
try
|
||||
{
|
||||
PreparedStatement statement = connection.prepareStatement("INSERT INTO bans VALUES (?, ?, ?, ?, ?, ?)");
|
||||
PreparedStatement statement = connection.prepareStatement("INSERT INTO bans VALUES (?, ?, ?, ?, ?, ?, ?)");
|
||||
statement.setString(1, ban.getUsername());
|
||||
statement.setString(2, FUtil.listToString(ban.getIps()));
|
||||
statement.setString(3, ban.getBy());
|
||||
statement.setLong(4, ban.getAt().getTime());
|
||||
statement.setLong(5, ban.getExpiryUnix());
|
||||
statement.setString(6, ban.getReason());
|
||||
String uuid = null;
|
||||
if (ban.hasUUID())
|
||||
{
|
||||
uuid = ban.getUuid().toString();
|
||||
}
|
||||
statement.setString(2, uuid);
|
||||
statement.setString(3, FUtil.listToString(ban.getIps()));
|
||||
statement.setString(4, ban.getBy());
|
||||
statement.setLong(5, ban.getAt().getTime());
|
||||
statement.setLong(6, ban.getExpiryUnix());
|
||||
statement.setString(7, ban.getReason());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
catch (SQLException e)
|
||||
|
Loading…
Reference in New Issue
Block a user