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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user