From ad0b0f3d0feeeeecf49caef79c0dca753f296071 Mon Sep 17 00:00:00 2001 From: Aubri Seebauer Date: Sat, 15 Apr 2023 21:58:10 -0400 Subject: [PATCH] cleanup --- .../commands/AdminTabCompletion.java | 295 +++++++++--------- 1 file changed, 144 insertions(+), 151 deletions(-) diff --git a/src/main/java/me/ShermansWorld/AlathraWar/commands/AdminTabCompletion.java b/src/main/java/me/ShermansWorld/AlathraWar/commands/AdminTabCompletion.java index 48c75e5..7bae3b5 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/commands/AdminTabCompletion.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/commands/AdminTabCompletion.java @@ -1,18 +1,11 @@ package me.ShermansWorld.AlathraWar.commands; -import com.palmergames.bukkit.towny.TownyAPI; -import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; -import com.palmergames.bukkit.towny.object.Nation; -import com.palmergames.bukkit.towny.object.Town; -import me.ShermansWorld.AlathraWar.War; -import me.ShermansWorld.AlathraWar.data.WarData; +import com.palmergames.bukkit.towny.utils.NameUtil; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; -import java.util.ArrayList; import java.util.List; public class AdminTabCompletion implements TabCompleter { @@ -31,7 +24,7 @@ public class AdminTabCompletion implements TabCompleter { "war" }); - List raidModify = List.of(new String[] { + List raidModify = List.of(new String[]{ "score", "homeblock", "gather", @@ -45,7 +38,7 @@ public class AdminTabCompletion implements TabCompleter { // "clearActive" }); - List siegeModify = List.of(new String[] { + List siegeModify = List.of(new String[]{ "score", "homeblock", "time", @@ -54,7 +47,7 @@ public class AdminTabCompletion implements TabCompleter { // "move" }); - List warModify = List.of(new String[] { + List warModify = List.of(new String[]{ "score", "side", "name", @@ -63,7 +56,7 @@ public class AdminTabCompletion implements TabCompleter { "raidTime" }); - List force = List.of(new String[] { + List force = List.of(new String[]{ "end", "join", "leave" @@ -71,7 +64,6 @@ public class AdminTabCompletion implements TabCompleter { /** - * * //done * //edit war/event in real time, side can be "both" to effect both * -modify raid score [war] [town] [value] @@ -83,13 +75,13 @@ public class AdminTabCompletion implements TabCompleter { * -modify raid owner [war] [town] [add/set] [value] * -modify raid move [war] [town] [newWar] //low priority, moves raid to other war * -modify raid clearActive [war] [town] //low priority - * + *

* -modify siege score [war] [town] [side] [amt] * -modify siege homeblock [war] [town] (x) (Z) * -modify siege time [war] [town] [add/set/max] [value] //max modified the max length * -modify siege owner [war] [town] [add/set] [value] * -modify siege move [war] [town] [newWar] //low priority, moves siege to other war - * + *

* -modify war score [war] [side] [amt] * -modify war side [war] [side] [name] * -modify war name [war] [name] @@ -98,7 +90,7 @@ public class AdminTabCompletion implements TabCompleter { * -modify war surrender town [war] [town] //adds town to surrender list * -modify war surrender nation [war] [town] //adds all towns to surrender list * -modify war raidTime [add,set,reset] [war] [town] [amt] //set when last raid was - * + *

* // low priority idea * -info war score [war] * -info war surrenderedTowns [war] @@ -106,41 +98,40 @@ public class AdminTabCompletion implements TabCompleter { * -info war sieges [war] * -info war towns [war] * -info war lastRaidTime [war] - * + *

* -info raid homeblock [war] [town] * -info raid lootedTownBlocks [war] [town] * -info raid timeSinceLastRaid [town] - * + *

* -info siege homeblock [war] [town] - * + *

* //done * //force make event or war, if owner isnt defined, idk havent decided * -create siege [war] [town] (owner) * -create raid [war] [raidTown] (gatherTown) (owner) * -create war [name] [side1] [side2] - * + *

* //force end a war/event, can declare winner side, or no winner * -force end war [war] (side/victor) * -force end siege [war] [town] (side/victor) * -force end raid [war] [town] (side/victor) - * + *

* //done * //force player into or out of a war/event * -force join war [player] [war] [side] * -force join siege [player] [war] [town] (side) * -force join raid [player] [war] [town] (side) - * + *

* //done * -force leave raid [war] [town] [player] (timeout) //kicks from raid party * - * - * @param sender Source of the command. For players tab-completing a - * command inside of a command block, this will be the player, not - * the command block. + * @param sender Source of the command. For players tab-completing a + * command inside of a command block, this will be the player, not + * the command block. * @param command Command which was executed - * @param label Alias of the command which was used - * @param args The arguments passed to the command, including final - * partial argument to be completed + * @param label Alias of the command which was used + * @param args The arguments passed to the command, including final + * partial argument to be completed * @return */ @Override @@ -152,265 +143,267 @@ public class AdminTabCompletion implements TabCompleter { if (args.length == 0) { return base; - }else { + } else if (args.length == 1) { + return NameUtil.filterByStart(base, args[0]); + } else { if (args[0].equalsIgnoreCase("create")) { - if(args.length > 2) { - if(args[1].equals("raid")) { - if(args.length > 3) { - if(args.length > 4) { - if(args.length > 5) { - if(args.length > 6) { + if (args.length > 2) { + if (args[1].equals("raid")) { + if (args.length > 3) { + if (args.length > 4) { + if (args.length > 5) { + if (args.length > 6) { return null; } else { - return CommandHelper.getPlayers(); + return NameUtil.filterByStart(CommandHelper.getPlayers(), args[5]); } } else { - return CommandHelper.getTownyTowns(); + return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[4]); } } else { - return CommandHelper.getTownyTowns(); + return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[3]); } } else { - return CommandHelper.getWarNames(); + return NameUtil.filterByStart(CommandHelper.getWarNames(), args[2]); } - } else if(args[1].equals("siege")) { - if(args.length > 3) { - if(args.length > 4) { - if(args.length > 5) { + } else if (args[1].equals("siege")) { + if (args.length > 3) { + if (args.length > 4) { + if (args.length > 5) { return null; } else { - return CommandHelper.getPlayers(); + return NameUtil.filterByStart(CommandHelper.getPlayers(), args[4]); } } else { - return CommandHelper.getTownyTowns(); + return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[3]); } } else { - return CommandHelper.getWarNames(); + return NameUtil.filterByStart(CommandHelper.getWarNames(), args[2]); } - } else if(args[1].equals("war")) { + } else if (args[1].equals("war")) { return null; } else { return null; } } else { - return type; + return NameUtil.filterByStart(type, args[1]); } } else if (args[0].equalsIgnoreCase("force")) { - if(args.length > 2) { - if(args[1].equalsIgnoreCase("end")) { - if(args.length > 3) { - if(args[2].equalsIgnoreCase("raid")) { - if(args.length > 4) { - if(args.length > 5) { - if(args.length > 6) { - return null; - } else { - return CommandHelper.getWarSides(args[3]); - } - } else { - return CommandHelper.getTownyTowns(); - } - } else { - return CommandHelper.getWarNames(); - } - } else if(args[2].equalsIgnoreCase("siege")) { - if(args.length > 4) { - if(args.length > 5) { + if (args.length > 2) { + if (args[1].equalsIgnoreCase("end")) { + if (args.length > 3) { + if (args[2].equalsIgnoreCase("raid")) { + if (args.length > 4) { + if (args.length > 5) { if (args.length > 6) { return null; } else { - return CommandHelper.getWarSides(args[3]); + return NameUtil.filterByStart(CommandHelper.getWarSides(args[3]), args[5]); } } else { - return CommandHelper.getTownyTowns(); + return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[4]); } } else { - return CommandHelper.getWarNames(); + return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]); } - } else if(args[2].equalsIgnoreCase("war")) { - if(args.length > 4) { - if(args.length > 5) { + } else if (args[2].equalsIgnoreCase("siege")) { + if (args.length > 4) { + if (args.length > 5) { + if (args.length > 6) { + return null; + } else { + return NameUtil.filterByStart(CommandHelper.getWarSides(args[3]), args[5]); + } + } else { + return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[4]); + } + } else { + return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]); + } + } else if (args[2].equalsIgnoreCase("war")) { + if (args.length > 4) { + if (args.length > 5) { return null; } else { - return CommandHelper.getWarSides(args[3]); + return NameUtil.filterByStart(CommandHelper.getWarSides(args[3]), args[4]); } } else { - return CommandHelper.getWarNames(); + return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]); } } } else { - return type; + return NameUtil.filterByStart(type, args[2]); } - } else if(args[1].equalsIgnoreCase("join")) { - if(args.length > 3) { - if(args[2].equalsIgnoreCase("raid")) { - if(args.length > 4) { - if(args.length > 5) { + } else if (args[1].equalsIgnoreCase("join")) { + if (args.length > 3) { + if (args[2].equalsIgnoreCase("raid")) { + if (args.length > 4) { + if (args.length > 5) { if (args.length > 6) { if (args.length > 7) { return null; } else { - return CommandHelper.getWarSides(args[4]); + return NameUtil.filterByStart(CommandHelper.getWarSides(args[4]), args[6]); } } else { - return CommandHelper.getTownyTowns(); + return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[5]); } } else { - return CommandHelper.getWarNames(); + return NameUtil.filterByStart(CommandHelper.getWarNames(), args[4]); } } else { - return CommandHelper.getPlayers(); + return NameUtil.filterByStart(CommandHelper.getPlayers(), args[3]); } - } else if(args[2].equalsIgnoreCase("siege")) { - if(args.length > 4) { - if(args.length > 5) { + } else if (args[2].equalsIgnoreCase("siege")) { + if (args.length > 4) { + if (args.length > 5) { if (args.length > 6) { if (args.length > 7) { return null; } else { - return CommandHelper.getWarSides(args[4]); + return NameUtil.filterByStart(CommandHelper.getWarSides(args[4]), args[6]); } } else { - return CommandHelper.getTownyTowns(); + return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[5]); } } else { - return CommandHelper.getWarNames(); + return NameUtil.filterByStart(CommandHelper.getWarNames(), args[4]); } } else { - return CommandHelper.getPlayers(); + return NameUtil.filterByStart(CommandHelper.getPlayers(), args[3]); } - } else if(args[2].equalsIgnoreCase("war")) { - if(args.length > 4) { - if(args.length > 5) { - if(args.length > 6) { + } else if (args[2].equalsIgnoreCase("war")) { + if (args.length > 4) { + if (args.length > 5) { + if (args.length > 6) { return null; } else { - return CommandHelper.getWarSides(args[4]); + return NameUtil.filterByStart(CommandHelper.getWarSides(args[4]), args[5]); } } else { - return CommandHelper.getWarNames(); + return NameUtil.filterByStart(CommandHelper.getWarNames(), args[4]); } } else { - return CommandHelper.getPlayers(); + return NameUtil.filterByStart(CommandHelper.getPlayers(), args[3]); } } } else { - return type; + return NameUtil.filterByStart(type, args[2]); } - } else if(args[1].equalsIgnoreCase("leave")) { - if(args.length > 3) { - if(args[2].equalsIgnoreCase("raid")) { - if(args.length > 4) { - if(args.length > 5) { - if(args.length > 6) { + } else if (args[1].equalsIgnoreCase("leave")) { + if (args.length > 3) { + if (args[2].equalsIgnoreCase("raid")) { + if (args.length > 4) { + if (args.length > 5) { + if (args.length > 6) { return null; } else { - return CommandHelper.getPlayers(); + return NameUtil.filterByStart(CommandHelper.getPlayers(), args[5]); } } else { - return CommandHelper.getTownyTowns(); + return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[4]); } } else { - return CommandHelper.getWarNames(); + return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]); } } else { - return List.of(new String[]{"raid"}); + return NameUtil.filterByStart(List.of(new String[]{"raid"}), args[3]); } } else { - return List.of(new String[]{"raid"}); + return NameUtil.filterByStart(List.of(new String[]{"raid"}), args[2]); } } else { - return force; + return NameUtil.filterByStart(force, args[1]); } } else { - return force; + return NameUtil.filterByStart(force, args[1]); } } else if (args[0].equalsIgnoreCase("help")) { return null; } else if (args[0].equalsIgnoreCase("info")) { - if(args.length > 2) { - if(args[1].equalsIgnoreCase("raid")) { - if(args.length > 3) { - if(args.length > 4) { + if (args.length > 2) { + if (args[1].equalsIgnoreCase("raid")) { + if (args.length > 3) { + if (args.length > 4) { return null; } else { - return CommandHelper.getTownyTowns(); + return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[3]); } } else { - return CommandHelper.getWarNames(); + return NameUtil.filterByStart(CommandHelper.getWarNames(), args[2]); } } else if (args[1].equalsIgnoreCase("siege")) { - if(args.length > 3) { - if(args.length > 4) { + if (args.length > 3) { + if (args.length > 4) { return null; } else { - return CommandHelper.getTownyTowns(); + return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[3]); } } else { - return CommandHelper.getWarNames(); + return NameUtil.filterByStart(CommandHelper.getWarNames(), args[2]); } } else if (args[1].equalsIgnoreCase("war")) { - if(args.length > 3) { + if (args.length > 3) { return null; } else { - return CommandHelper.getWarNames(); + return NameUtil.filterByStart(CommandHelper.getWarNames(), args[2]); } } else { - return type; + return NameUtil.filterByStart(type, args[1]); } } else { - return type; + return NameUtil.filterByStart(type, args[1]); } } else if (args[0].equalsIgnoreCase("modify")) { - if(args.length > 2) { - if(args[1].equalsIgnoreCase("raid")) { - if(args.length > 3) { - if(args.length > 4) { - if(args.length > 5) { + if (args.length > 2) { + if (args[1].equalsIgnoreCase("raid")) { + if (args.length > 3) { + if (args.length > 4) { + if (args.length > 5) { return null; } else { - return CommandHelper.getTownyTowns(); + return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[4]); } } else { - return CommandHelper.getWarNames(); + return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]); } } else { - return raidModify; + return NameUtil.filterByStart(raidModify, args[2]); } } else if (args[1].equalsIgnoreCase("siege")) { - if(args.length > 3) { - if(args.length > 4) { - if(args.length > 5) { + if (args.length > 3) { + if (args.length > 4) { + if (args.length > 5) { return null; } else { - return CommandHelper.getTownyTowns(); + return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[4]); } } else { - return CommandHelper.getWarNames(); + return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]); } } else { - return raidModify; + return NameUtil.filterByStart(raidModify, args[2]); } } else if (args[1].equalsIgnoreCase("war")) { - if(args.length > 3) { - if(args.length > 4) { + if (args.length > 3) { + if (args.length > 4) { return null; } else { - return CommandHelper.getWarNames(); + return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]); } } else { - return raidModify; + return NameUtil.filterByStart(raidModify, args[2]); } } else { - return type; + return NameUtil.filterByStart(type, args[1]); } } else { - return type; + return NameUtil.filterByStart(type, args[1]); } } else { - return base; + return NameUtil.filterByStart(base, args[0]); } } - return base; + return NameUtil.filterByStart(base, args[0]); } }