Re-implement unbannable usernames. Resolves #180

This commit is contained in:
unknown 2014-05-13 17:01:49 +02:00
parent 7b8ba0bdf5
commit 73a91c02c6
3 changed files with 29 additions and 5 deletions

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Tue May 13 16:30:53 CEST 2014 #Tue May 13 17:00:06 CEST 2014
build.number=837 build.number=840

View File

@ -1,6 +1,6 @@
# #
# TotalFreedomMod banning config # TotalFreedomMod banning config
# Warning: modification of this file is not reccomended # Warning: modification of this file is not recomended
# #
# Format: # Format:
# Ip: [IP-address / UUID]:[Last login name]:[Expiry unix timestamp (0 = never)][Banned by]:[Reason] # Ip: [IP-address / UUID]:[Last login name]:[Expiry unix timestamp (0 = never)][Banned by]:[Reason]

View File

@ -6,12 +6,16 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import me.StevenLawson.TotalFreedomMod.Config.TFM_Config; import me.StevenLawson.TotalFreedomMod.Config.TFM_Config;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
public class TFM_BanManager public class TFM_BanManager
{ {
private static final TFM_BanManager INSTANCE; private static final TFM_BanManager INSTANCE;
private final List<TFM_Ban> ipBans; private final List<TFM_Ban> ipBans;
private final List<TFM_Ban> uuidBans; private final List<TFM_Ban> uuidBans;
private final List<UUID> unbannableUUIDs;
static static
{ {
@ -22,12 +26,14 @@ public class TFM_BanManager
{ {
ipBans = new ArrayList<TFM_Ban>(); ipBans = new ArrayList<TFM_Ban>();
uuidBans = new ArrayList<TFM_Ban>(); uuidBans = new ArrayList<TFM_Ban>();
unbannableUUIDs = new ArrayList<UUID>();
} }
public void load() public void load()
{ {
ipBans.clear(); ipBans.clear();
uuidBans.clear(); uuidBans.clear();
unbannableUUIDs.clear();
final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, "bans.yml", true); final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, "bans.yml", true);
config.load(); config.load();
@ -58,8 +64,21 @@ public class TFM_BanManager
// Save the config // Save the config
save(); save();
TFM_Log.info("Loaded " + ipBans.size() + " IP bans and " + uuidBans.size() + " UUID bans");
TFM_Log.info("Loaded " + ipBans.size() + " IP bans and " + uuidBans.size() + " UUID bans."); for (String username : (List<String>) TFM_ConfigEntry.UNBANNABLE_USERNAMES.getList())
{
final OfflinePlayer player = Bukkit.getOfflinePlayer(username);
if (player == null || player.getUniqueId() == null)
{
TFM_Log.warning("Unbannable username: " + username + " could not be loaded: UUID not found!");
continue;
}
unbannableUUIDs.add(player.getUniqueId());
}
TFM_Log.info("Loaded " + unbannableUUIDs.size() + " unbannable UUIDs");
} }
public void save() public void save()
@ -80,7 +99,7 @@ public class TFM_BanManager
for (TFM_Ban savedBan : uuidBans) for (TFM_Ban savedBan : uuidBans)
{ {
if (!savedBan.isExpired()) if (!savedBan.isExpired() && !unbannableUUIDs.contains(UUID.fromString(savedBan.getSubject())))
{ {
newUuidBans.add(savedBan.toString()); newUuidBans.add(savedBan.toString());
} }
@ -201,6 +220,11 @@ public class TFM_BanManager
return; return;
} }
if (unbannableUUIDs.contains(UUID.fromString(ban.getSubject())))
{
return;
}
uuidBans.add(ban); uuidBans.add(ban);
save(); save();
} }