From b3ad960973b1b50e40e3f576cc7eb9a04f3c8ffb Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Dec 2023 16:14:37 +0100 Subject: [PATCH] Add MultiSchemType selection for GUI.preSchemDialog --- FightSystem_Core/src/config.yml | 3 +- .../src/de/steamwar/fightsystem/Config.java | 7 +-- .../de/steamwar/fightsystem/commands/GUI.java | 62 +++++++++++-------- .../de/steamwar/fightsystem/fight/Fight.java | 20 ++---- .../steamwar/fightsystem/fight/FightTeam.java | 14 ++--- 5 files changed, 53 insertions(+), 53 deletions(-) diff --git a/FightSystem_Core/src/config.yml b/FightSystem_Core/src/config.yml index ab03b87..3ec764b 100644 --- a/FightSystem_Core/src/config.yml +++ b/FightSystem_Core/src/config.yml @@ -61,6 +61,7 @@ Schematic: z: 0 # The schematic type that can be chosen in this arena Type: Normal # defaults to Normal if missing + SubTypes: [] # defaults to empty List # Shortcut of the schematic type Shortcut: "" # defaults to "" if missing # Spigot (1.8) material for GUIs @@ -73,7 +74,7 @@ Schematic: PasteAligned: false # defaults to false if missing # If only public schematics are allowed OnlyPublicSchematics: false # defaults to false if missing - # If the public only force should be completely disabled + # If the public only force should be completely disabled # TODO: I think this value is now obsolete! IgnorePublicOnly: false # defaults to false if missing # If obsidian and bedrock should be replaced during PRE_RUNNING ReplaceObsidianBedrock: false # defaults to false if missing diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index 9b8bf6d..816fefb 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -21,10 +21,7 @@ package de.steamwar.fightsystem; import de.steamwar.fightsystem.utils.Region; import de.steamwar.fightsystem.winconditions.Winconditions; -import de.steamwar.sql.Event; -import de.steamwar.sql.EventFight; -import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.Team; +import de.steamwar.sql.*; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -83,6 +80,7 @@ public class Config { public static final boolean OnlyPublicSchematics; public static final boolean IgnorePublicOnly; public static final de.steamwar.sql.SchematicType SchematicType; + public static final List SubTypes; public static final boolean RedRotate; public static final boolean BlueRotate; public static final boolean PasteAligned; @@ -181,6 +179,7 @@ public class Config { int schemsizeZ = config.getInt("Schematic.Size.z"); RanksEnabled = !config.getStringList("Ranks").isEmpty(); SchematicType = de.steamwar.sql.SchematicType.fromDB(Objects.requireNonNull(config.getString("Schematic.Type", "normal"))); + SubTypes = config.getStringList("Schematic.SubTypes").stream().map(de.steamwar.sql.SchematicType::fromDB).collect(Collectors.toList()); IgnorePublicOnly = config.getBoolean("Schematic.IgnorePublicOnly", false); boolean rotate = config.getBoolean("Schematic.Rotate", true); PasteAligned = config.getBoolean("Schematic.PasteAligned", false); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java index ad3c273..612bdab 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java @@ -29,6 +29,7 @@ import de.steamwar.inventory.*; import de.steamwar.message.Message; import de.steamwar.sql.PersonalKit; import de.steamwar.sql.SchematicNode; +import de.steamwar.sql.SchematicType; import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.api.ChatMessageType; import org.bukkit.Bukkit; @@ -167,36 +168,47 @@ public class GUI { return; } - SWInventory inv = new SWInventory(p, 9, msg.parse("SCHEM_TITLE", p, Config.GameName)); - inv.setItem(8, Material.REDSTONE, msg.parse("SCHEM_PUBLIC", p, Config.GameName), (ClickType click) -> { - p.closeInventory(); - schemDialog(p, true, false); - }); - if(Fight.getMaxRank() == 0){ - inv.setItem(0, SWItem.getDye(8), (byte)8, msg.parse("SCHEM_PRIVATE_FORBIDDEN", p, Config.GameName), (ClickType click)->{}); - }else { - if (Config.SchematicType.checkType() != null && !SchematicNode.getAllAccessibleSchematicsOfType(SteamwarUser.get(p.getUniqueId()).getId(), Config.SchematicType.checkType().toDB()).isEmpty()) { - inv.setItem(4, Material.ANVIL, msg.parse("SCHEM_UNCHECKED", p, Config.GameName), (ClickType click) -> { - p.closeInventory(); - schemDialog(p, false, true); - }); - } - - if(SchematicNode.getAllAccessibleSchematicsOfType(SteamwarUser.get(p.getUniqueId()).getId(), Config.SchematicType.toDB()).isEmpty() && !Config.test()){ - inv.setItem(0, SWItem.getDye(8), (byte)8, msg.parse("SCHEM_NO_PRIVATE", p, Config.GameName), (ClickType click)->{}); - }else{ - inv.setItem(0, SWItem.getMaterial("CAULDRON_ITEM"), msg.parse("SCHEM_PRIVATE", p, Config.GameName), (ClickType click) -> { - p.closeInventory(); - schemDialog(p, false, false); - }); - } + int invSize = (Config.SubTypes.size() + 1) * 9; + SWInventory inv = new SWInventory(p, invSize, msg.parse("SCHEM_TITLE", p, Config.GameName)); + setupSchemTypeRow(p, inv, Config.SchematicType, 0); + for (int i = 0; i < Config.SubTypes.size(); i++) { + setupSchemTypeRow(p, inv, Config.SubTypes.get(0), i + 1); } inv.setCallback(-999, (ClickType click) -> p.closeInventory()); inv.open(); } - private static void schemDialog(Player p, boolean publicSchems, boolean unchecked){ - SchematicSelector selector = new SchematicSelector(p, Config.test()?SchematicSelector.selectSchematic():SchematicSelector.selectSchematicTypeWithRank(unchecked ? Config.SchematicType.checkType() : Config.SchematicType, Fight.getMaxRank()), node -> { + private static void setupSchemTypeRow(Player p, SWInventory inv, SchematicType type, int row) { + inv.setItem(row * 9 + 8, Material.REDSTONE, msg.parse("SCHEM_PUBLIC", p, type.name()), (ClickType click) -> { + p.closeInventory(); + schemDialog(p, type, true, false); + }); + + if (Fight.publicOnly()) { + inv.setItem(row * 9, SWItem.getDye(8), (byte)8, msg.parse("SCHEM_PRIVATE_FORBIDDEN", p, type.name()), (ClickType click)->{}); + return; + } + + if (type.checkType() != null && type.checkType() != type && !SchematicNode.getAllAccessibleSchematicsOfType(SteamwarUser.get(p.getUniqueId()).getId(), type.checkType().toDB()).isEmpty()) { + inv.setItem(row * 9 + 4, Material.ANVIL, msg.parse("SCHEM_UNCHECKED", p, Config.GameName), (ClickType click) -> { + p.closeInventory(); + schemDialog(p, type, false, true); + }); + } + + if (SchematicNode.getAllAccessibleSchematicsOfType(SteamwarUser.get(p.getUniqueId()).getId(), Config.SchematicType.toDB()).isEmpty() && !Config.test()) { + inv.setItem(row * 9, SWItem.getDye(8), (byte)8, msg.parse("SCHEM_NO_PRIVATE", p, Config.GameName), (ClickType click)->{}); + return; + } + + inv.setItem(row * 9, SWItem.getMaterial("CAULDRON_ITEM"), msg.parse("SCHEM_PRIVATE", p, Config.GameName), (ClickType click) -> { + p.closeInventory(); + schemDialog(p, type, false, false); + }); + } + + private static void schemDialog(Player p, SchematicType type, boolean publicSchems, boolean unchecked){ + SchematicSelector selector = new SchematicSelector(p, Config.test() ? SchematicSelector.selectSchematic() : SchematicSelector.selectSchematicType(unchecked ? type.checkType() : type), node -> { FightTeam fightTeam = Fight.getPlayerTeam(p); if(fightTeam == null) return; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java index f7011d0..c50cf60 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java @@ -139,21 +139,13 @@ public class Fight { TinyProtocol.instance.sendPacket(player, ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.GAMEMODE, new GameProfile(player.getUniqueId(), player.getName()), enable ? GameMode.CREATIVE : GameMode.SPECTATOR)); } - public static int getMaxRank(){ - /* MaxRank of 0 is Pubonly*/ - if(Config.OnlyPublicSchematics){ - return 0; + public static boolean publicOnly() { + if (Config.OnlyPublicSchematics) { + return true; } - - if(Config.IgnorePublicOnly || ArenaMode.RankedEvent.contains(Config.mode)){ - return 1000; + if (redTeam.isPublicsOnly() || blueTeam.isPublicsOnly()) { + return true; } - - - if(redTeam.getLeader() == null || blueTeam.getLeader() == null){ - return 1000; - } - - return Math.min(redTeam.getSchemRank(), blueTeam.getSchemRank()); + return false; } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 94774aa..02aa943 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -90,7 +90,7 @@ public class FightTeam { private UUID designatedLeader; private FightPlayer leader; - private int schemRank; + private boolean publicsOnly; private final Map players = new HashMap<>(); @@ -113,7 +113,7 @@ public class FightTeam { this.spawn = spawn; this.schemRegion = schemRegion; this.extendRegion = extendRegion; - this.schemRank = 0; + this.publicsOnly = false; this.ready = false; this.skip = false; this.blue = blue; @@ -161,8 +161,8 @@ public class FightTeam { return isLeaderless() && (designatedLeader == null || designatedLeader.equals(p.getUniqueId())); } - public int getSchemRank() { - return schemRank; + public boolean isPublicsOnly() { + return publicsOnly; } public void teleportToSpawn(){ @@ -357,11 +357,7 @@ public class FightTeam { if(!silent) FightUI.addSubtitle("UI_LEADER_JOINS", prefix, leader.getEntity().getName()); - Optional maxRank = SchematicNode.getAllAccessibleSchematicsOfType(leader.getUser().getId(), Config.SchematicType.toDB()).stream().map(SchematicNode::getRank).max(Integer::compare); - if(Config.RanksEnabled) - schemRank = maxRank.orElse(1); - else - schemRank = maxRank.isPresent() ? 1 : 0; + publicsOnly = SchematicNode.getAllAccessibleSchematicsOfType(leader.getUser().getId(), Config.SchematicType.toDB()).isEmpty(); if(!Config.PersonalKits) leader.setKit(Kit.getKitByName(Config.LeaderDefault));