mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-06-29 11:46:40 +00:00
Many changes for TFM 5.0
Improved admin system Improved Rank system Implemented config converter Improved command handling Updated Aero
This commit is contained in:
@ -4,7 +4,10 @@ import com.google.common.collect.Lists;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
@ -61,6 +64,7 @@ public class Ban implements ConfigLoadable, ConfigSavable, Validatable
|
||||
{
|
||||
this.ips.addAll(Arrays.asList(ips));
|
||||
}
|
||||
dedupeIps();
|
||||
this.by = by;
|
||||
this.expiryUnix = FUtil.getUnixTime(expire);
|
||||
}
|
||||
@ -215,12 +219,7 @@ public class Ban implements ConfigLoadable, ConfigSavable, Validatable
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hasUsername() && !(getUsername().equalsIgnoreCase(ban.getUsername())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return !(hasUsername() && !(getUsername().equalsIgnoreCase(ban.getUsername())));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -240,12 +239,14 @@ public class Ban implements ConfigLoadable, ConfigSavable, Validatable
|
||||
this.ips.addAll(cs.getStringList("ips"));
|
||||
this.by = cs.getString("by", null);
|
||||
this.reason = cs.getString("reason", null);
|
||||
this.expiryUnix = cs.getLong("expiry_unix", -1);
|
||||
this.expiryUnix = cs.getLong("expiry_unix", 0);
|
||||
dedupeIps();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveTo(ConfigurationSection cs)
|
||||
{
|
||||
dedupeIps();
|
||||
cs.set("username", username);
|
||||
cs.set("ips", ips.isEmpty() ? null : ips);
|
||||
cs.set("by", by);
|
||||
@ -258,4 +259,20 @@ public class Ban implements ConfigLoadable, ConfigSavable, Validatable
|
||||
{
|
||||
return username != null || !ips.isEmpty();
|
||||
}
|
||||
|
||||
private void dedupeIps()
|
||||
{
|
||||
|
||||
Set<String> uniqueIps = new HashSet<>();
|
||||
|
||||
Iterator<String> it = ips.iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
if (!uniqueIps.add(it.next()))
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -10,10 +10,10 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.config.YamlConfig;
|
||||
import net.pravian.aero.util.Ips;
|
||||
@ -41,17 +41,6 @@ public class BanManager extends FreedomService
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
load();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
saveAll();
|
||||
}
|
||||
|
||||
public void load()
|
||||
{
|
||||
config.load();
|
||||
|
||||
@ -79,58 +68,24 @@ public class BanManager extends FreedomService
|
||||
// Remove expired bans, repopulate ipBans and nameBans,
|
||||
updateViews();
|
||||
|
||||
FLog.info("Loaded " + ipBans.size() + " IP bans and " + nameBans.size() + " username bans");
|
||||
FLog.info("Loaded " + ipBans.size() + " IP bans and " + nameBans.size() + " username bans.");
|
||||
|
||||
// Load unbannable usernames
|
||||
unbannableUsernames.clear();
|
||||
unbannableUsernames.addAll((Collection<? extends String>) ConfigEntry.UNBANNABLE_USERNAMES.getList());
|
||||
unbannableUsernames.addAll((Collection<? extends String>) ConfigEntry.FAMOUS_PLAYERS.getList());
|
||||
FLog.info("Loaded " + unbannableUsernames.size() + " unbannable usernames.");
|
||||
|
||||
}
|
||||
|
||||
private void updateViews()
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
|
||||
// Remove expired bans
|
||||
for (Iterator<Ban> it = bans.iterator(); it.hasNext();)
|
||||
{
|
||||
if (it.next().isExpired())
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
ipBans.clear();
|
||||
nameBans.clear();
|
||||
for (Ban ban : bans)
|
||||
{
|
||||
if (ban.hasUsername())
|
||||
{
|
||||
nameBans.put(ban.getUsername().toLowerCase(), ban);
|
||||
}
|
||||
|
||||
if (ban.hasIps())
|
||||
{
|
||||
for (String ip : ban.getIps())
|
||||
{
|
||||
ipBans.put(ip, ban);
|
||||
}
|
||||
}
|
||||
}
|
||||
saveAll();
|
||||
logger.info("Saved " + bans.size() + " player bans");
|
||||
}
|
||||
|
||||
public void saveAll()
|
||||
public Set<Ban> getAllBans()
|
||||
{
|
||||
// Remove expired
|
||||
updateViews();
|
||||
|
||||
for (Ban ban : bans)
|
||||
{
|
||||
ban.saveTo(config.createSection(String.valueOf(ban.hashCode())));
|
||||
}
|
||||
|
||||
// Save config
|
||||
config.save();
|
||||
return Collections.unmodifiableSet(bans);
|
||||
}
|
||||
|
||||
public Collection<Ban> getIpBans()
|
||||
@ -143,6 +98,21 @@ public class BanManager extends FreedomService
|
||||
return Collections.unmodifiableCollection(nameBans.values());
|
||||
}
|
||||
|
||||
public void saveAll()
|
||||
{
|
||||
// Remove expired
|
||||
updateViews();
|
||||
|
||||
config.clear();
|
||||
for (Ban ban : bans)
|
||||
{
|
||||
ban.saveTo(config.createSection(String.valueOf(ban.hashCode())));
|
||||
}
|
||||
|
||||
// Save config
|
||||
config.save();
|
||||
}
|
||||
|
||||
public Ban getByIp(String ip)
|
||||
{
|
||||
final Ban directBan = ipBans.get(ip);
|
||||
@ -193,13 +163,12 @@ public class BanManager extends FreedomService
|
||||
{
|
||||
final Ban ban = getByIp(ip);
|
||||
|
||||
if (ban == null)
|
||||
if (ban != null)
|
||||
{
|
||||
return ban;
|
||||
bans.remove(ban);
|
||||
saveAll();
|
||||
}
|
||||
|
||||
bans.remove(ban);
|
||||
saveAll();
|
||||
return ban;
|
||||
}
|
||||
|
||||
@ -207,13 +176,12 @@ public class BanManager extends FreedomService
|
||||
{
|
||||
final Ban ban = getByUsername(username);
|
||||
|
||||
if (ban == null)
|
||||
if (ban != null)
|
||||
{
|
||||
return ban;
|
||||
bans.remove(ban);
|
||||
saveAll();
|
||||
}
|
||||
|
||||
bans.remove(ban);
|
||||
saveAll();
|
||||
return ban;
|
||||
}
|
||||
|
||||
@ -231,7 +199,7 @@ public class BanManager extends FreedomService
|
||||
{
|
||||
if (bans.add(ban))
|
||||
{
|
||||
updateViews();
|
||||
saveAll();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -242,23 +210,23 @@ public class BanManager extends FreedomService
|
||||
{
|
||||
if (bans.remove(ban))
|
||||
{
|
||||
updateViews();
|
||||
saveAll();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void purgeIpBans()
|
||||
public int purge()
|
||||
{
|
||||
ipBans.clear();
|
||||
saveAll();
|
||||
}
|
||||
config.clear();
|
||||
config.save();
|
||||
|
||||
public void purgeNameBans()
|
||||
{
|
||||
nameBans.clear();
|
||||
saveAll();
|
||||
int size = bans.size();
|
||||
bans.clear();
|
||||
updateViews();
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
@ -268,13 +236,13 @@ public class BanManager extends FreedomService
|
||||
final String ip = Ips.getIp(event);
|
||||
|
||||
// Regular ban
|
||||
Ban ban = plugin.bm.getByUsername(username);
|
||||
Ban ban = getByUsername(username);
|
||||
if (ban == null)
|
||||
{
|
||||
ban = plugin.bm.getByIp(ip);
|
||||
ban = getByIp(ip);
|
||||
}
|
||||
|
||||
if (ban != null)
|
||||
if (ban != null && !ban.isExpired())
|
||||
{
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, ban.bakeKickMessage());
|
||||
}
|
||||
@ -302,4 +270,34 @@ public class BanManager extends FreedomService
|
||||
player.setOp(true);
|
||||
}
|
||||
|
||||
private void updateViews()
|
||||
{
|
||||
// Remove expired bans
|
||||
for (Iterator<Ban> it = bans.iterator(); it.hasNext();)
|
||||
{
|
||||
if (it.next().isExpired())
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
nameBans.clear();
|
||||
ipBans.clear();
|
||||
for (Ban ban : bans)
|
||||
{
|
||||
if (ban.hasUsername())
|
||||
{
|
||||
nameBans.put(ban.getUsername().toLowerCase(), ban);
|
||||
}
|
||||
|
||||
if (ban.hasIps())
|
||||
{
|
||||
for (String ip : ban.getIps())
|
||||
{
|
||||
ipBans.put(ip, ban);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
package me.totalfreedom.totalfreedommod.banning;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import com.google.common.collect.Sets;
|
||||
import java.util.Set;
|
||||
import lombok.Getter;
|
||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.config.YamlConfig;
|
||||
import net.pravian.aero.util.Ips;
|
||||
@ -17,6 +17,7 @@ import org.bukkit.event.player.PlayerLoginEvent;
|
||||
|
||||
public class PermbanList extends FreedomService
|
||||
{
|
||||
|
||||
public static final String CONFIG_FILENAME = "permbans.yml";
|
||||
|
||||
@Getter
|
||||
@ -44,7 +45,7 @@ public class PermbanList extends FreedomService
|
||||
permbannedIps.addAll(config.getStringList(name));
|
||||
}
|
||||
|
||||
FLog.info("Loaded " + permbannedNames.size() + " permanently banned usernames and " + permbannedIps.size() + " permanently banned IPs.");
|
||||
FLog.info("Loaded " + permbannedIps.size() + " perm IP bans and " + permbannedNames.size() + " perm username bans.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user