From c9bfcc5c0cc84f417fd33d5d51849003a2232844 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Mon, 24 Nov 2025 20:55:58 +0100 Subject: [PATCH] Fix not ignoring deleted teams Closes: #226 --- .../worldedit/types/TypeGenerator.java | 93 +++++++++++++++++++ CommonCore/SQL/src/de/steamwar/sql/Team.kt | 8 +- 2 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/types/TypeGenerator.java diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/types/TypeGenerator.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/types/TypeGenerator.java new file mode 100644 index 00000000..02038f18 --- /dev/null +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/types/TypeGenerator.java @@ -0,0 +1,93 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2025 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.worldedit.types; + +import com.google.common.collect.Sets; +import de.steamwar.bausystem.shared.Pair; +import de.steamwar.linkage.Linked; +import de.steamwar.linkage.api.Enable; +import org.bukkit.Material; + +import java.util.*; +import java.util.stream.Collectors; + +@Linked +public class TypeGenerator implements Enable { + + public static void main(String[] args) { + new TypeGenerator().enable(); + } + + @Override + public void enable() { + List materials = Arrays.stream(Material.values()) + .filter(material -> !material.isLegacy()) + .filter(Material::isBlock) + .sorted(Comparator.comparingInt(value -> value.name().length())) + .collect(Collectors.toList()); + + Map, Double> equalityMap = new HashMap<>(); + for (int i = 0; i < materials.size(); i++) { + Material first = materials.get(i); + String[] firstNameSplit = first.name().split("_"); + for (int j = i + 1; j < materials.size(); j++) { + Material second = materials.get(j); + String[] secondNameSplit = second.name().split("_"); + double equality = equality(secondNameSplit, firstNameSplit); + if (equality == 0) continue; + equalityMap.put(new Pair<>(first, second), equality); + } + } + + Map>> reverseEqualityMap = new HashMap<>(); + for (Map.Entry, Double> entry : equalityMap.entrySet()) { + reverseEqualityMap.computeIfAbsent(entry.getValue(), key -> new ArrayList<>()) + .add(entry.getKey()); + } + + List keys = reverseEqualityMap.keySet() + .stream() + .sorted(Comparator.comparingDouble(a -> -a)) + .collect(Collectors.toList()); + + for (int i = 0; i <= keys.size() - 1; i++) { + double key = keys.get(i); + List> list = reverseEqualityMap.get(key); + list.forEach(System.out::println); + break; + } + } + + private double equality(String[] first, String[] second) { + int equality = 0; + int divisor = 0; + Set firstSet = Sets.newHashSet(first); + Set secondSet = Sets.newHashSet(second); + for (int i = 0; i < first.length; i++) { + if (secondSet.contains(first[i])) equality += first[i].length(); + divisor += first[i].length(); + } + for (int i = 0; i < second.length; i++) { + if (firstSet.contains(second[i])) equality += second[i].length(); + divisor += second[i].length(); + } + return equality / (double) divisor; + } +} diff --git a/CommonCore/SQL/src/de/steamwar/sql/Team.kt b/CommonCore/SQL/src/de/steamwar/sql/Team.kt index 0c56a656..40e04ac9 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/Team.kt +++ b/CommonCore/SQL/src/de/steamwar/sql/Team.kt @@ -20,11 +20,9 @@ package de.steamwar.sql import de.steamwar.sql.internal.useDb +import org.jetbrains.exposed.v1.core.* import org.jetbrains.exposed.v1.core.dao.id.EntityID import org.jetbrains.exposed.v1.core.dao.id.IntIdTable -import org.jetbrains.exposed.v1.core.eq -import org.jetbrains.exposed.v1.core.lowerCase -import org.jetbrains.exposed.v1.core.or import org.jetbrains.exposed.v1.dao.IntEntity import org.jetbrains.exposed.v1.dao.IntEntityClass import org.jetbrains.exposed.v1.jdbc.select @@ -49,10 +47,10 @@ class Team(id: EntityID) : IntEntity(id) { fun byId(id: Int) = teamCache.computeIfAbsent(id) { useDb { Team[id] } } @JvmStatic - fun get(name: String) = useDb { find { TeamTable.name.lowerCase() eq name.lowercase() or (TeamTable.kuerzel.lowerCase() eq name.lowercase()) }.firstOrNull() } + fun get(name: String) = useDb { find { (TeamTable.name.lowerCase() eq name.lowercase() or (TeamTable.kuerzel.lowerCase() eq name.lowercase())) and not(TeamTable.deleted) }.firstOrNull() } @JvmStatic - fun getAll() = useDb { all().toList() } + fun getAll() = useDb { find { not(TeamTable.deleted) }.toList() } @JvmStatic fun create(kuerzel: String, name: String) = useDb {