Merge pull request 'Enable a Dirt Block (Schem owner -1 and Name like GameMode) to be selected for any ServerTeam member' (#51) from FightSystem/EnableDirtBlockForServerTeam into main

Reviewed-on: SteamWar/SteamWar#51
Reviewed-by: Lixfel <lixfel@noreply.localhost>
This commit is contained in:
2025-05-29 12:06:41 +02:00
5 changed files with 38 additions and 12 deletions
@@ -76,6 +76,7 @@ KITSEARCH_TITLE=Search for kit
SCHEM_NO_ENEMY=§cNo schematic selection without an opponent
SCHEM_TITLE={0} selection
SCHEM_DIRT=§eDirt Block
SCHEM_PUBLIC=§ePublic {0}
SCHEM_UNCHECKED=§eUnchecked {0}
SCHEM_PRIVATE=§ePrivate {0}
@@ -70,6 +70,7 @@ KITSEARCH_TITLE=Nach Kit suchen
SCHEM_NO_ENEMY=§cKeine Schematicwahl ohne Gegner
SCHEM_TITLE={0}-Auswahl
SCHEM_DIRT=§eErdblock
SCHEM_PUBLIC=§eÖffentliches {0}
SCHEM_UNCHECKED=§eUngeprüftes {0}
SCHEM_PRIVATE=§ePrivates {0}
@@ -24,15 +24,14 @@ import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.ai.AIManager;
import de.steamwar.fightsystem.fight.*;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.listener.PersonalKitCreator;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.utils.ColorConverter;
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 de.steamwar.sql.*;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@@ -40,7 +39,10 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.stream.Collectors;
public class GUI {
@@ -206,6 +208,14 @@ public class GUI {
for (int i = 0; i < Config.SubTypes.size(); i++) {
setupSchemTypeRow(p, inv, Config.SubTypes.get(i), i + 1);
}
if (!Config.test() && SteamwarUser.get(p.getUniqueId()).hasPerm(UserPerm.TEAM)) {
SchematicNode node = SchematicNode.getSchematicNode(-1, Config.GameName, (Integer) null);
if (node != null) {
inv.setItem(2, new SWItem(SWItem.getMaterial(node.getItem()), msg.parse("SCHEM_DIRT", p), click -> {
schemSelect(p, node);
}));
}
}
inv.setCallback(-999, (ClickType click) -> p.closeInventory());
inv.open();
}
@@ -241,14 +251,18 @@ public class GUI {
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;
if(Config.test() || FightState.getFightState() != FightState.POST_SCHEM_SETUP)
fightTeam.pasteSchem(node);
p.closeInventory();
schemSelect(p, node);
});
selector.setPublicMode(publicSchems?SchematicSelector.PublicMode.PUBLIC_ONLY:SchematicSelector.PublicMode.PRIVATE_ONLY);
selector.open();
}
private static void schemSelect(Player p, SchematicNode node) {
FightTeam fightTeam = Fight.getPlayerTeam(p);
if(fightTeam == null)
return;
if(Config.test() || FightState.getFightState() != FightState.POST_SCHEM_SETUP)
fightTeam.pasteSchem(node);
p.closeInventory();
}
}
@@ -84,6 +84,9 @@ public class WinconditionBlocks extends Wincondition implements PrintableWincond
}
private void check() {
// Edge Case for DirtBlock
if (blocks.isEmpty()) return;
blocks.removeIf(block -> !isOfType.test(block));
if(blocks.isEmpty())
win(Fight.getOpposite(team), "WIN_TECHKO", team.getColoredName());
@@ -78,6 +78,7 @@ public class WinconditionPercent extends Wincondition implements PrintableWincon
private int totalBlocks = 0;
private int currentBlocks = 0;
private boolean countAnyBlock = false;
private TeamPercent(FightTeam team, Winconditions wincondition) {
this.team = team;
@@ -98,7 +99,7 @@ public class WinconditionPercent extends Wincondition implements PrintableWincon
}
event.blockList().forEach(block -> {
if (Config.PercentBlocks.contains(block.getType()) == Config.PercentBlocksWhitelist) {
if (countAnyBlock || Config.PercentBlocks.contains(block.getType()) == Config.PercentBlocksWhitelist) {
currentBlocks--;
}
});
@@ -108,10 +109,16 @@ public class WinconditionPercent extends Wincondition implements PrintableWincon
private void enable() {
totalBlocks = 0;
countAnyBlock = false;
team.getSchemRegion().forEach((x, y, z) -> {
if (Config.PercentBlocks.contains(Config.world.getBlockAt(x, y, z).getType()) == Config.PercentBlocksWhitelist)
totalBlocks++;
});
// Edge Case for DirtBlock
if (totalBlocks == 0) {
totalBlocks = team.getSchemRegion().volume();
countAnyBlock = true;
}
currentBlocks = totalBlocks;
postEnable.accept(team);
}