From 2c19ce5c6505640b28f5e6f2b5f1b902dd951d1e Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Mon, 9 Nov 2020 21:05:33 -0600 Subject: [PATCH] Adds https://tracker.telesphoreo.me/d/4-mbconfig-clearip --- .../command/Command_mbconfig.java | 79 +++++++++++++++++-- .../command/Command_myadmin.java | 9 +-- .../totalfreedommod/sql/SQLite.java | 2 +- .../totalfreedommod/staff/StaffMember.java | 1 - 4 files changed, 79 insertions(+), 12 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mbconfig.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mbconfig.java index a91d8061..b97d1b97 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mbconfig.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mbconfig.java @@ -13,10 +13,9 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @CommandPermissions(level = Rank.OP, source = SourceType.BOTH) -@CommandParameters(description = "List, add, or remove master builders, reload the master builder list, or view the info of master builders.", usage = "/ >>") +@CommandParameters(description = "List, add, or remove master builders. Master builders can also clear their own IPs.", usage = "/ | clearips | < >>") public class Command_mbconfig extends FreedomCommand { - @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { @@ -33,6 +32,68 @@ public class Command_mbconfig extends FreedomCommand return true; } + case "clearips": + { + if (args.length > 1) + { + return false; + } + + if (senderIsConsole) + { + msg("Only in-game players may use this command.", ChatColor.RED); + return true; + } + + PlayerData data = plugin.pl.getData(sender.getName()); + if (!data.isMasterBuilder()) + { + msg("You are not a master builder!", ChatColor.RED); + return true; + } + + int counter = data.getIps().size() - 1; + data.clearIps(); + data.addIp(FUtil.getIp(playerSender)); + plugin.sql.addPlayer(data); + msg(counter + " IPs removed."); + msg(data.getIps().get(0) + " is now your only IP address"); + FUtil.staffAction(sender.getName(), "Clearing my IPs", true); + return true; + } + case "clearip": + { + if (args.length < 2) + { + return false; + } + + if (senderIsConsole) + { + msg("Only in-game players may use this command.", ChatColor.RED); + return true; + } + + PlayerData data = plugin.pl.getData(sender.getName()); + final String targetIp = FUtil.getIp(playerSender); + + if (!data.isMasterBuilder()) + { + msg("You are not a master builder!", ChatColor.RED); + return true; + } + + if (targetIp.equals(args[1])) + { + msg("You cannot remove your current IP."); + return true; + } + data.removeIp(args[1]); + plugin.sql.addPlayer(data); + msg("Removed IP " + args[1]); + msg("Current IPs: " + StringUtils.join(data.getIps(), ", ")); + return true; + } case "add": { if (args.length < 2) @@ -123,7 +184,6 @@ public class Command_mbconfig extends FreedomCommand } return true; } - default: { return false; @@ -136,7 +196,7 @@ public class Command_mbconfig extends FreedomCommand { if (args.length == 1) { - return Arrays.asList("add", "remove", "list"); + return Arrays.asList("add", "remove", "list", "clearips", "clearip"); } else if (args.length == 2) { @@ -144,10 +204,19 @@ public class Command_mbconfig extends FreedomCommand { return FUtil.getPlayerList(); } - else if (args[0].equalsIgnoreCase("remove") || args[0].equalsIgnoreCase("list")) + else if (args[0].equalsIgnoreCase("remove")) { return plugin.pl.getMasterBuilderNames(); } + else if (args[0].equalsIgnoreCase("clearip")) + { + PlayerData data = plugin.pl.getData(sender.getName()); + if (data.isMasterBuilder()) + { + return data.getIps(); + } + return Collections.emptyList(); + } } return Collections.emptyList(); } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_myadmin.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_myadmin.java index 2483494e..2e5ca94a 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_myadmin.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_myadmin.java @@ -5,6 +5,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.discord.Discord; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.staff.StaffMember; @@ -16,10 +17,9 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @CommandPermissions(level = Rank.ADMIN, source = SourceType.ONLY_IN_GAME) -@CommandParameters(description = "Manage your staff entry.", usage = "/ [-o ] | setlogin | clearlogin | setscformat | clearscformat> | oldtags | logstick | syncroles>") +@CommandParameters(description = "Manage your admin entry.", usage = "/ [-o ] | setlogin | clearlogin | setscformat | clearscformat> | oldtags | logstick | syncroles>") public class Command_myadmin extends FreedomCommand { - @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { @@ -85,7 +85,6 @@ public class Command_myadmin extends FreedomCommand plugin.sl.save(target); plugin.sl.updateTables(); - plugin.pl.syncIps(target); msg(counter + " IPs removed."); @@ -121,7 +120,7 @@ public class Command_myadmin extends FreedomCommand } else { - msg("You cannot remove that staff members's current IP."); + msg("You cannot remove that staff members current IP."); } return true; } @@ -175,7 +174,7 @@ public class Command_myadmin extends FreedomCommand msg("Please run /linkdiscord first!", ChatColor.RED); return true; } - boolean synced = plugin.dc.syncRoles(target, playerData.getDiscordID()); + boolean synced = Discord.syncRoles(target, playerData.getDiscordID()); if (synced) { msg("Successfully synced your roles.", ChatColor.GREEN); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java b/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java index ce5fb786..71128d67 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java @@ -93,7 +93,7 @@ public class SQLite extends FreedomService { try { - connection.createStatement().execute("CREATE TABLE `players` (`username` VARCHAR NOT NULL, `ips` VARCHAR NOT NULL, `notes` VARCHAR, `tag` VARCHAR, `discord_id` VARCHAR, `backup_codes` VARCHAR, `donator` BOOLEAN NOT NULL, `master_builder` BOOLEAN NOT NULL,`verification` BOOLEAN NOT NULL, `ride_mode` VARCHAR NOT NULL, `coins` INT NOT NULL, `items` VARCHAR, `total_votes` INT NOT NULL, `display_discord` BOOLEAN NOT NULL, `reddit_username` VARCHAR, `login_message` VARCHAR);"); + connection.createStatement().execute("CREATE TABLE `players` (`username` VARCHAR NOT NULL, `ips` VARCHAR NOT NULL, `notes` VARCHAR, `tag` VARCHAR, `discord_id` VARCHAR, `backup_codes` VARCHAR, `donator` BOOLEAN NOT NULL, `master_builder` BOOLEAN NOT NULL,`verification` BOOLEAN NOT NULL, `ride_mode` VARCHAR NOT NULL, `coins` INT, `items` VARCHAR, `total_votes` INT NOT NULL, `display_discord` BOOLEAN NOT NULL, `reddit_username` VARCHAR, `login_message` VARCHAR);"); } catch (SQLException e) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/staff/StaffMember.java b/src/main/java/me/totalfreedom/totalfreedommod/staff/StaffMember.java index 525f85c5..934552f5 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/staff/StaffMember.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/staff/StaffMember.java @@ -19,7 +19,6 @@ import org.bukkit.entity.Player; public class StaffMember { - @Getter @Setter private String name;