mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
Revert "Permbans are now indefinite bans."
This reverts commit 4003db6dd9
.
This commit is contained in:
parent
4003db6dd9
commit
54df0e08f5
@ -1,7 +1,7 @@
|
|||||||
package me.totalfreedom.totalfreedommod;
|
package me.totalfreedom.totalfreedommod;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import me.totalfreedom.totalfreedommod.banning.IndefiniteBanList;
|
import me.totalfreedom.totalfreedommod.banning.PermbanList;
|
||||||
import me.totalfreedom.totalfreedommod.config.YamlConfig;
|
import me.totalfreedom.totalfreedommod.config.YamlConfig;
|
||||||
import me.totalfreedom.totalfreedommod.permissions.PermissionConfig;
|
import me.totalfreedom.totalfreedommod.permissions.PermissionConfig;
|
||||||
import me.totalfreedom.totalfreedommod.punishments.PunishmentList;
|
import me.totalfreedom.totalfreedommod.punishments.PunishmentList;
|
||||||
@ -29,7 +29,7 @@ public class BackupManager extends FreedomService
|
|||||||
public void createAllBackups()
|
public void createAllBackups()
|
||||||
{
|
{
|
||||||
createBackups(TotalFreedomMod.CONFIG_FILENAME, true);
|
createBackups(TotalFreedomMod.CONFIG_FILENAME, true);
|
||||||
createBackups(IndefiniteBanList.CONFIG_FILENAME);
|
createBackups(PermbanList.CONFIG_FILENAME);
|
||||||
createBackups(PermissionConfig.PERMISSIONS_FILENAME, true);
|
createBackups(PermissionConfig.PERMISSIONS_FILENAME, true);
|
||||||
createBackups(PunishmentList.CONFIG_FILENAME);
|
createBackups(PunishmentList.CONFIG_FILENAME);
|
||||||
createBackups("database.db");
|
createBackups("database.db");
|
||||||
|
@ -1,63 +0,0 @@
|
|||||||
package me.totalfreedom.totalfreedommod.banning;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import me.totalfreedom.totalfreedommod.config.IConfig;
|
|
||||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
|
|
||||||
public class IndefiniteBan implements IConfig
|
|
||||||
{
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private String username = null;
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private UUID uuid = null;
|
|
||||||
@Getter
|
|
||||||
private final List<String> ips = Lists.newArrayList();
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private String reason = null;
|
|
||||||
|
|
||||||
public IndefiniteBan()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loadFrom(ConfigurationSection cs)
|
|
||||||
{
|
|
||||||
this.username = cs.getName();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
String strUUID = cs.getString("uuid", null);
|
|
||||||
if (strUUID != null)
|
|
||||||
{
|
|
||||||
UUID uuid = UUID.fromString(strUUID);
|
|
||||||
this.uuid = uuid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException e)
|
|
||||||
{
|
|
||||||
FLog.warning("Failed to load indefinite banned UUID for " + this.username + ". Make sure the UUID is in the correct format with dashes.");
|
|
||||||
}
|
|
||||||
this.ips.clear();
|
|
||||||
this.ips.addAll(cs.getStringList("ips"));
|
|
||||||
this.reason = cs.getString("reason", null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void saveTo(ConfigurationSection cs)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isValid()
|
|
||||||
{
|
|
||||||
return username != null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,140 +0,0 @@
|
|||||||
package me.totalfreedom.totalfreedommod.banning;
|
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import lombok.Getter;
|
|
||||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
|
||||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
|
||||||
import me.totalfreedom.totalfreedommod.config.YamlConfig;
|
|
||||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
|
||||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.player.PlayerLoginEvent;
|
|
||||||
|
|
||||||
public class IndefiniteBanList extends FreedomService
|
|
||||||
{
|
|
||||||
|
|
||||||
public static final String CONFIG_FILENAME = "indefinitebans.yml";
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
private final Set<IndefiniteBan> indefBans = Sets.newHashSet();
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
private int nameBanCount = 0;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
private int uuidBanCount = 0;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
private int ipBanCount = 0;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStart()
|
|
||||||
{
|
|
||||||
indefBans.clear();
|
|
||||||
|
|
||||||
final YamlConfig config = new YamlConfig(plugin, CONFIG_FILENAME, true);
|
|
||||||
config.load();
|
|
||||||
|
|
||||||
for (String name : config.getKeys(false))
|
|
||||||
{
|
|
||||||
if (!config.isConfigurationSection(name))
|
|
||||||
{
|
|
||||||
FLog.warning("Could not load indefinite ban for " + name + ": Invalid format!");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
IndefiniteBan indefBan = new IndefiniteBan();
|
|
||||||
ConfigurationSection cs = config.getConfigurationSection(name);
|
|
||||||
indefBan.loadFrom(cs);
|
|
||||||
|
|
||||||
if (!indefBan.isValid())
|
|
||||||
{
|
|
||||||
FLog.warning("Not adding indefinite ban for " + name + ": Missing information.");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
indefBans.add(indefBan);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateCount();
|
|
||||||
|
|
||||||
FLog.info("Loaded " + nameBanCount + " indefinite name bans, " + uuidBanCount + " UUID bans, and " + ipBanCount + " ip bans");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStop()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
|
||||||
public void onPlayerLogin(PlayerLoginEvent event)
|
|
||||||
{
|
|
||||||
final String username = event.getPlayer().getName();
|
|
||||||
final UUID uuid = event.getPlayer().getUniqueId();
|
|
||||||
final String ip = FUtil.getIp(event);
|
|
||||||
|
|
||||||
String bannedBy = "";
|
|
||||||
IndefiniteBan ban = null;
|
|
||||||
|
|
||||||
for (IndefiniteBan indefBan : indefBans)
|
|
||||||
{
|
|
||||||
if (username.toLowerCase().equals(indefBan.getUsername().toLowerCase()))
|
|
||||||
{
|
|
||||||
bannedBy = "username";
|
|
||||||
ban = indefBan;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (indefBan.getUuid() != null && indefBan.getUuid().equals(uuid))
|
|
||||||
{
|
|
||||||
bannedBy = "UUID";
|
|
||||||
ban = indefBan;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (indefBan.getIps().contains(ip))
|
|
||||||
{
|
|
||||||
bannedBy = "IP address";
|
|
||||||
ban = indefBan;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ban != null)
|
|
||||||
{
|
|
||||||
String kickMessage = ChatColor.RED + "Your " + bannedBy + " is indefinitely banned from this server.";
|
|
||||||
String reason = ban.getReason();
|
|
||||||
if (!Strings.isNullOrEmpty(reason))
|
|
||||||
{
|
|
||||||
kickMessage += "\nReason: " + ChatColor.GOLD + reason;
|
|
||||||
}
|
|
||||||
String appealURL = ConfigEntry.SERVER_INDEFBAN_URL.getString();
|
|
||||||
if (!Strings.isNullOrEmpty(appealURL))
|
|
||||||
{
|
|
||||||
kickMessage += ChatColor.RED + "\n\nRelease procedures are available at\n" + ChatColor.GOLD + ConfigEntry.SERVER_INDEFBAN_URL.getString();
|
|
||||||
}
|
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, kickMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateCount()
|
|
||||||
{
|
|
||||||
nameBanCount = 0;
|
|
||||||
uuidBanCount = 0;
|
|
||||||
ipBanCount = 0;
|
|
||||||
|
|
||||||
for (IndefiniteBan indefBan : indefBans)
|
|
||||||
{
|
|
||||||
nameBanCount += 1;
|
|
||||||
if (indefBan.getUuid() != null)
|
|
||||||
{
|
|
||||||
uuidBanCount += 1;
|
|
||||||
}
|
|
||||||
ipBanCount += indefBan.getIps().size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,92 @@
|
|||||||
|
package me.totalfreedom.totalfreedommod.banning;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import java.util.Set;
|
||||||
|
import lombok.Getter;
|
||||||
|
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||||
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
|
import me.totalfreedom.totalfreedommod.config.YamlConfig;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
|
|
||||||
|
public class PermbanList extends FreedomService
|
||||||
|
{
|
||||||
|
|
||||||
|
public static final String CONFIG_FILENAME = "permbans.yml";
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final Set<String> permbannedNames = Sets.newHashSet();
|
||||||
|
@Getter
|
||||||
|
private final Set<String> permbannedIps = Sets.newHashSet();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart()
|
||||||
|
{
|
||||||
|
permbannedNames.clear();
|
||||||
|
permbannedIps.clear();
|
||||||
|
|
||||||
|
final YamlConfig config = new YamlConfig(plugin, CONFIG_FILENAME, true);
|
||||||
|
config.load();
|
||||||
|
|
||||||
|
for (String name : config.getKeys(false))
|
||||||
|
{
|
||||||
|
permbannedNames.add(name.toLowerCase().trim());
|
||||||
|
permbannedIps.addAll(config.getStringList(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
FLog.info("Loaded " + permbannedIps.size() + " perm IP bans and " + permbannedNames.size() + " perm username bans.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public void onPlayerLogin(PlayerLoginEvent event)
|
||||||
|
{
|
||||||
|
final String username = event.getPlayer().getName();
|
||||||
|
final String ip = FUtil.getIp(event);
|
||||||
|
|
||||||
|
// Permbanned IPs
|
||||||
|
for (String testIp : getPermbannedIps())
|
||||||
|
{
|
||||||
|
if (FUtil.fuzzyIpMatch(testIp, ip, 4))
|
||||||
|
{
|
||||||
|
event.disallow(PlayerLoginEvent.Result.KICK_OTHER,
|
||||||
|
ChatColor.RED + "Your IP address is permanently banned from this server.\n"
|
||||||
|
+ "Release procedures are available at\n"
|
||||||
|
+ ChatColor.GOLD + ConfigEntry.SERVER_PERMBAN_URL.getString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Permbanned usernames
|
||||||
|
for (String testPlayer : getPermbannedNames())
|
||||||
|
{
|
||||||
|
if (testPlayer.equalsIgnoreCase(username))
|
||||||
|
{
|
||||||
|
event.disallow(PlayerLoginEvent.Result.KICK_OTHER,
|
||||||
|
ChatColor.RED + "Your username is permanently banned from this server.\n"
|
||||||
|
+ "Release procedures are available at\n"
|
||||||
|
+ ChatColor.GOLD + ConfigEntry.SERVER_PERMBAN_URL.getString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getPermbannedNames()
|
||||||
|
{
|
||||||
|
return this.permbannedNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getPermbannedIps()
|
||||||
|
{
|
||||||
|
return this.permbannedIps;
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,14 @@
|
|||||||
package me.totalfreedom.totalfreedommod.command;
|
package me.totalfreedom.totalfreedommod.command;
|
||||||
|
|
||||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.ONLY_CONSOLE)
|
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.ONLY_CONSOLE)
|
||||||
@CommandParameters(description = "Reload the indefinite ban list.", usage = "/<command> reload", aliases = "ib")
|
@CommandParameters(description = "Reload the permban list.", usage = "/<command> reload", aliases = "pb")
|
||||||
public class Command_indefban extends FreedomCommand
|
public class Command_permban extends FreedomCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -23,10 +24,12 @@ public class Command_indefban extends FreedomCommand
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg("Reloading the indefinite ban list...");
|
msg("Reloading permban list...", ChatColor.RED);
|
||||||
plugin.im.onStop();
|
plugin.pm.onStop();
|
||||||
plugin.im.onStart();
|
plugin.pm.onStart();
|
||||||
msg("Reloaded the indefinite ban list.");
|
msg("Reloaded permban list.");
|
||||||
|
msg(plugin.pm.getPermbannedIps().size() + " IPs and "
|
||||||
|
+ plugin.pm.getPermbannedNames().size() + " usernames loaded.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -3,14 +3,14 @@ package me.totalfreedom.totalfreedommod.httpd.module;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||||
import me.totalfreedom.totalfreedommod.banning.IndefiniteBanList;
|
import me.totalfreedom.totalfreedommod.banning.PermbanList;
|
||||||
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
|
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
|
||||||
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
||||||
|
|
||||||
public class Module_indefbans extends HTTPDModule
|
public class Module_permbans extends HTTPDModule
|
||||||
{
|
{
|
||||||
|
|
||||||
public Module_indefbans(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session)
|
public Module_permbans(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session)
|
||||||
{
|
{
|
||||||
super(plugin, session);
|
super(plugin, session);
|
||||||
}
|
}
|
||||||
@ -18,17 +18,17 @@ public class Module_indefbans extends HTTPDModule
|
|||||||
@Override
|
@Override
|
||||||
public NanoHTTPD.Response getResponse()
|
public NanoHTTPD.Response getResponse()
|
||||||
{
|
{
|
||||||
File permbanFile = new File(plugin.getDataFolder(), IndefiniteBanList.CONFIG_FILENAME);
|
File permbanFile = new File(plugin.getDataFolder(), PermbanList.CONFIG_FILENAME);
|
||||||
|
|
||||||
final String remoteAddress = socket.getInetAddress().getHostAddress();
|
final String remoteAddress = socket.getInetAddress().getHostAddress();
|
||||||
if (!isAuthorized(remoteAddress))
|
if (!isAuthorized(remoteAddress))
|
||||||
{
|
{
|
||||||
return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT,
|
return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT,
|
||||||
"You may not view the indefinite ban list. Your IP, " + remoteAddress + ", is not registered to an admin on the server.");
|
"You may not view the permban list. Your IP, " + remoteAddress + ", is not registered to an admin on the server.");
|
||||||
}
|
}
|
||||||
if (permbanFile.exists())
|
if (permbanFile.exists())
|
||||||
{
|
{
|
||||||
return HTTPDaemon.serveFileBasic(new File(plugin.getDataFolder(), IndefiniteBanList.CONFIG_FILENAME));
|
return HTTPDaemon.serveFileBasic(new File(plugin.getDataFolder(), PermbanList.CONFIG_FILENAME));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
@ -1,15 +0,0 @@
|
|||||||
#
|
|
||||||
# TotalFreedomMod Indefinite Bans
|
|
||||||
#
|
|
||||||
|
|
||||||
badplayer1:
|
|
||||||
uuid: '123e4567-e89b-12d3-a456-426614174000'
|
|
||||||
ips:
|
|
||||||
- 123.123.123.123
|
|
||||||
- 321.321.321.321
|
|
||||||
reason: 'bad player'
|
|
||||||
badplayer2:
|
|
||||||
ips:
|
|
||||||
- 111.111.111.111
|
|
||||||
badplayer3:
|
|
||||||
ips: []
|
|
10
src/main/resources/permbans.yml
Normal file
10
src/main/resources/permbans.yml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#
|
||||||
|
# TotalFreedomMod 5.5 Permanent Bans
|
||||||
|
#
|
||||||
|
|
||||||
|
badplayer1:
|
||||||
|
- 123.123.123.123
|
||||||
|
- 321.321.321.321
|
||||||
|
badplayer2:
|
||||||
|
- 111.111.111.111
|
||||||
|
badplayer3: []
|
Loading…
Reference in New Issue
Block a user