forked from SteamWar/SteamWar
+93
@@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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<Material> materials = Arrays.stream(Material.values())
|
||||||
|
.filter(material -> !material.isLegacy())
|
||||||
|
.filter(Material::isBlock)
|
||||||
|
.sorted(Comparator.comparingInt(value -> value.name().length()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
Map<Pair<Material, Material>, 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<Double, List<Pair<Material, Material>>> reverseEqualityMap = new HashMap<>();
|
||||||
|
for (Map.Entry<Pair<Material, Material>, Double> entry : equalityMap.entrySet()) {
|
||||||
|
reverseEqualityMap.computeIfAbsent(entry.getValue(), key -> new ArrayList<>())
|
||||||
|
.add(entry.getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Double> 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<Pair<Material, Material>> list = reverseEqualityMap.get(key);
|
||||||
|
list.forEach(System.out::println);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private double equality(String[] first, String[] second) {
|
||||||
|
int equality = 0;
|
||||||
|
int divisor = 0;
|
||||||
|
Set<String> firstSet = Sets.newHashSet(first);
|
||||||
|
Set<String> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,11 +20,9 @@
|
|||||||
package de.steamwar.sql
|
package de.steamwar.sql
|
||||||
|
|
||||||
import de.steamwar.sql.internal.useDb
|
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.EntityID
|
||||||
import org.jetbrains.exposed.v1.core.dao.id.IntIdTable
|
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.IntEntity
|
||||||
import org.jetbrains.exposed.v1.dao.IntEntityClass
|
import org.jetbrains.exposed.v1.dao.IntEntityClass
|
||||||
import org.jetbrains.exposed.v1.jdbc.select
|
import org.jetbrains.exposed.v1.jdbc.select
|
||||||
@@ -49,10 +47,10 @@ class Team(id: EntityID<Int>) : IntEntity(id) {
|
|||||||
fun byId(id: Int) = teamCache.computeIfAbsent(id) { useDb { Team[id] } }
|
fun byId(id: Int) = teamCache.computeIfAbsent(id) { useDb { Team[id] } }
|
||||||
|
|
||||||
@JvmStatic
|
@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
|
@JvmStatic
|
||||||
fun getAll() = useDb { all().toList() }
|
fun getAll() = useDb { find { not(TeamTable.deleted) }.toList() }
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun create(kuerzel: String, name: String) = useDb {
|
fun create(kuerzel: String, name: String) = useDb {
|
||||||
|
|||||||
Reference in New Issue
Block a user