diff --git a/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java b/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java index d98b7456..f071de86 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java @@ -1,5 +1,7 @@ package me.totalfreedom.totalfreedommod; +import java.util.ArrayList; +import java.util.List; import java.util.regex.Pattern; import lombok.Getter; import lombok.Setter; @@ -29,6 +31,8 @@ public class LoginProcess extends FreedomService public static final int MIN_USERNAME_LENGTH = 2; public static final int MAX_USERNAME_LENGTH = 20; public static final Pattern USERNAME_REGEX = Pattern.compile("^[\\w\\d_]{3,20}$"); + public List TELEPORT_ON_JOIN = new ArrayList<>(); + public List CLEAR_ON_JOIN = new ArrayList<>(); // @Getter @Setter @@ -195,18 +199,18 @@ public class LoginProcess extends FreedomService player.sendTitle(FUtil.colorize(ConfigEntry.SERVER_LOGIN_TITLE.getString()), FUtil.colorize(ConfigEntry.SERVER_LOGIN_SUBTITLE.getString()), 20, 100, 60); player.setOp(true); - if (ConfigEntry.ALLOW_TPR_ON_JOIN.getBoolean()) + if (TELEPORT_ON_JOIN.contains(player.getName())) { int x = FUtil.random(-10000, 10000); int z = FUtil.random(-10000, 10000); int y = player.getWorld().getHighestBlockYAt(x, z); Location location = new Location(player.getLocation().getWorld(), x, y, z); player.teleport(location); - player.sendMessage(ChatColor.GOLD + "You have been teleported to a random location automatically."); + player.sendMessage(ChatColor.AQUA + "You have been teleported to a random location automatically."); return; } - if (ConfigEntry.ALLOW_CLEAR_ON_JOIN.getBoolean()) + if (CLEAR_ON_JOIN.contains(player.getName())) { player.getInventory().clear(); player.sendMessage(ChatColor.AQUA + "Your inventory has been cleared automatically."); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java index f48d8e58..333bcd18 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java @@ -8,6 +8,7 @@ import me.totalfreedom.totalfreedommod.admin.AdminList; import me.totalfreedom.totalfreedommod.amp.AMP; import me.totalfreedom.totalfreedommod.banning.BanManager; import me.totalfreedom.totalfreedommod.banning.PermbanList; +import me.totalfreedom.totalfreedommod.banning.VPNBanList; import me.totalfreedom.totalfreedommod.blocking.BlockBlocker; import me.totalfreedom.totalfreedommod.blocking.EditBlocker; import me.totalfreedom.totalfreedommod.blocking.EventBlocker; @@ -99,6 +100,7 @@ public class TotalFreedomMod extends AeroPlugin public PunishmentList pul; public BanManager bm; public PermbanList pm; + public VPNBanList vn; public ProtectArea pa; public GameRuleHandler gr; public RollbackManager rb; @@ -174,6 +176,7 @@ public class TotalFreedomMod extends AeroPlugin backups.createBackups(TotalFreedomMod.CONFIG_FILENAME, true); backups.createBackups(AdminList.CONFIG_FILENAME); backups.createBackups(PermbanList.CONFIG_FILENAME); + backups.createBackups(VPNBanList.CONFIG_FILENAME); backups.createBackups(MasterBuilder.CONFIG_FILENAME); backups.createBackups(PunishmentList.CONFIG_FILENAME); @@ -210,6 +213,7 @@ public class TotalFreedomMod extends AeroPlugin pul = services.registerService(PunishmentList.class); bm = services.registerService(BanManager.class); pm = services.registerService(PermbanList.class); + vn = services.registerService(VPNBanList.class); pa = services.registerService(ProtectArea.class); gr = services.registerService(GameRuleHandler.class); snp = services.registerService(SignBlocker.class); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/banning/VPNBanList.java b/src/main/java/me/totalfreedom/totalfreedommod/banning/VPNBanList.java new file mode 100644 index 00000000..9b379f69 --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/banning/VPNBanList.java @@ -0,0 +1,76 @@ +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.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; +import org.bukkit.ChatColor; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerLoginEvent; + +public class VPNBanList extends FreedomService +{ + + public static final String CONFIG_FILENAME = "vpnbans.yml"; + + @Getter + private final Set vpnIps = Sets.newHashSet(); + + public VPNBanList(TotalFreedomMod plugin) + { + super(plugin); + } + + @Override + protected void onStart() + { + vpnIps.clear(); + + final YamlConfig config = new YamlConfig(plugin, CONFIG_FILENAME, true); + config.load(); + + for (String name : config.getKeys(false)) + { + vpnIps.addAll(config.getStringList(name)); + } + + FLog.info("Loaded " + vpnIps.size() + " VPN ips."); + } + + @Override + protected void onStop() + { + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onPlayerLogin(PlayerLoginEvent event) + { + final String ip = Ips.getIp(event); + + // Permbanned IPs + for (String testIp : getVPNIps()) + { + if (FUtil.fuzzyIpMatch(testIp, ip, 4)) + { + event.disallow(PlayerLoginEvent.Result.KICK_OTHER, + ChatColor.RED + "Your IP address is detected as a VPN\n" + + "If you believe this is an error, release procedures are available at\n" + + ChatColor.GOLD + ConfigEntry.SERVER_PERMBAN_URL.getString()); + return; + } + } + + } + + public Set getVPNIps() + { + return this.vpnIps; + } +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_autoclear.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_autoclear.java new file mode 100644 index 00000000..d0e84630 --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_autoclear.java @@ -0,0 +1,37 @@ +package me.totalfreedom.totalfreedommod.command; + +import me.totalfreedom.totalfreedommod.rank.Rank; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH) +@CommandParameters(description = "Toggle whether or not a player has their inventory automatically cleared when they join", usage = "/ ") +public class Command_autoclear extends FreedomCommand +{ + + @Override + public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + if (args.length == 0) + { + return false; + } + + boolean enabled = plugin.lp.CLEAR_ON_JOIN.contains(args[0]); + + if (enabled) + { + plugin.lp.CLEAR_ON_JOIN.remove(args[0]); + } + else + { + plugin.lp.CLEAR_ON_JOIN.add(args[0]); + } + + msg(args[0] + " will " + (enabled ? "no longer" : "now") + " have their inventory cleared when they join", ChatColor.GREEN); + + return true; + } +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_autotp.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_autotp.java new file mode 100644 index 00000000..a4b3d0d1 --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_autotp.java @@ -0,0 +1,37 @@ +package me.totalfreedom.totalfreedommod.command; + +import me.totalfreedom.totalfreedommod.rank.Rank; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH) +@CommandParameters(description = "Toggle whether or not a player is automatically teleported when they join", usage = "/ ") +public class Command_autotp extends FreedomCommand +{ + + @Override + public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + if (args.length == 0) + { + return false; + } + + boolean enabled = plugin.lp.TELEPORT_ON_JOIN.contains(args[0]); + + if (enabled) + { + plugin.lp.TELEPORT_ON_JOIN.remove(args[0]); + } + else + { + plugin.lp.TELEPORT_ON_JOIN.add(args[0]); + } + + msg(args[0] + " will " + (enabled ? "no longer" : "now") + " be automatically teleported when they join", ChatColor.GREEN); + + return true; + } +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java index c01eb597..1cd5c2ad 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java @@ -39,8 +39,6 @@ public class Command_toggle extends FreedomCommand msg("- unsafeenchs"); msg("- bells"); msg("- armorstands"); - msg("- clearonjoin"); - msg("- tpronjoin"); msg("- structureblocks"); msg("- jigsaws"); msg("- grindstones"); @@ -180,16 +178,6 @@ public class Command_toggle extends FreedomCommand toggle("The placement of armor stands is", ConfigEntry.ALLOW_ARMOR_STANDS); return true; } - else if (args[0].equalsIgnoreCase("clearonjoin")) - { - toggle("The clearing of inventories on join is", ConfigEntry.ALLOW_CLEAR_ON_JOIN); - return true; - } - else if (args[0].equalsIgnoreCase("tpronjoin")) - { - toggle("The random teleporting of players on join is", ConfigEntry.ALLOW_TPR_ON_JOIN); - return true; - } else if (args[0].equalsIgnoreCase("structureblocks")) { toggle("Structure blocks are", ConfigEntry.ALLOW_STRUCTURE_BLOCKS); @@ -244,7 +232,7 @@ public class Command_toggle extends FreedomCommand return Arrays.asList( "waterplace", "fireplace", "lavaplace", "fluidspread", "lavadmg", "firespread", "frostwalk", "firework", "prelog", "lockdown", "petprotect", "entitywipe", "nonuke", "explosives", "unsafeenchs", - "bells", "armorstands", "clearonjoin", "tpronjoin", "structureblocks", "jigsaws", "grindstones", "jukeboxes", "spawners", "4chan", "beehives"); + "bells", "armorstands", "structureblocks", "jigsaws", "grindstones", "jukeboxes", "spawners", "4chan", "beehives"); } return Collections.emptyList(); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vpnbanlist.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vpnbanlist.java new file mode 100644 index 00000000..f835a259 --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vpnbanlist.java @@ -0,0 +1,35 @@ +package me.totalfreedom.totalfreedommod.command; + +import me.totalfreedom.totalfreedommod.rank.Rank; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.ONLY_CONSOLE) +@CommandParameters(description = "Manage banned VPN ips.", usage = "/ reload") +public class Command_vpnbanlist extends FreedomCommand +{ + + @Override + public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + if (args.length != 1) + { + return false; + } + + if (!args[0].equalsIgnoreCase("reload")) + { + return false; + } + + msg("Reloading VPN ban list...", ChatColor.RED); + plugin.vn.stop(); + plugin.vn.start(); + msg("Reloaded VPN ban list."); + msg(plugin.vn.getVPNIps().size() + " IPs loaded"); + return true; + } + +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java index b0bf9312..6d5bc1e9 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java @@ -25,8 +25,6 @@ public enum ConfigEntry ALLOW_BELLS(Boolean.class, "allow.bells"), ALLOW_ARMOR_STANDS(Boolean.class, "allow.armorstands"), ALLOW_MINECARTS(Boolean.class, "allow.minecarts"), - ALLOW_CLEAR_ON_JOIN(Boolean.class, "allow.clearonjoin"), - ALLOW_TPR_ON_JOIN(Boolean.class, "allow.tpronjoin"), ALLOW_STRUCTURE_BLOCKS(Boolean.class, "allow.structureblocks"), ALLOW_JIGSAWS(Boolean.class, "allow.jigsaws"), ALLOW_GRINDSTONES(Boolean.class, "allow.grindstones"), diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index ee723658..795ea10e 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -145,7 +145,6 @@ allow: armorstands: true minecarts: false clearonjoin: false - tpronjoin: false structureblocks: false jigsaws: false grindstones: false diff --git a/src/main/resources/vpnbans.yml b/src/main/resources/vpnbans.yml new file mode 100644 index 00000000..c642975b --- /dev/null +++ b/src/main/resources/vpnbans.yml @@ -0,0 +1,9 @@ +# +# TotalFreedomMod 5.2 VPN Bans +# + +badnetwork1: + - 123.123.123.123 + - 321.321.321.321 +badnetwork2: + - 111.111.111.111