Compile against 1.20.1 and fix some short name issues
Partially helps with #516, #521, #549
This commit is contained in:
parent
999f596125
commit
ed642ccf3c
22
pom.xml
22
pom.xml
|
@ -83,14 +83,22 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.kyori</groupId>
|
<groupId>net.kyori</groupId>
|
||||||
<artifactId>adventure-platform-bukkit</artifactId>
|
<artifactId>adventure-platform-bukkit</artifactId>
|
||||||
<version>4.2.0</version>
|
<version>4.3.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Should be kept in sync with Paper -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
<artifactId>adventure-api</artifactId>
|
||||||
|
<version>4.14.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.kyori</groupId>
|
<groupId>net.kyori</groupId>
|
||||||
<artifactId>adventure-text-serializer-gson</artifactId>
|
<artifactId>adventure-text-serializer-gson</artifactId>
|
||||||
<version>4.12.0</version>
|
<version>4.13.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
|
@ -111,7 +119,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bstats</groupId>
|
<groupId>org.bstats</groupId>
|
||||||
<artifactId>bstats-bukkit</artifactId>
|
<artifactId>bstats-bukkit</artifactId>
|
||||||
<version>3.0.0</version>
|
<version>3.0.1</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -212,6 +220,12 @@
|
||||||
<artifactId>worldedit-core</artifactId>
|
<artifactId>worldedit-core</artifactId>
|
||||||
<version>7.0.0-SNAPSHOT</version>
|
<version>7.0.0-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.yaml</groupId>
|
||||||
|
<artifactId>snakeyaml</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -446,7 +460,7 @@
|
||||||
<build.number>${buildNumber}</build.number>
|
<build.number>${buildNumber}</build.number>
|
||||||
<user.name>${buildType}</user.name>
|
<user.name>${buildType}</user.name>
|
||||||
<bukkit.plugin.version>${project.version} ${buildDescription}</bukkit.plugin.version>
|
<bukkit.plugin.version>${project.version} ${buildDescription}</bukkit.plugin.version>
|
||||||
<bukkit.dependency.version>1.19-R0.1-SNAPSHOT</bukkit.dependency.version>
|
<bukkit.dependency.version>1.20.1-R0.1-SNAPSHOT</bukkit.dependency.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<profiles>
|
<profiles>
|
||||||
|
|
|
@ -25,7 +25,6 @@ import org.yaml.snakeyaml.Yaml;
|
||||||
import org.yaml.snakeyaml.nodes.Tag;
|
import org.yaml.snakeyaml.nodes.Tag;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -54,6 +53,30 @@ public class MaterialUtil {
|
||||||
// 15 dashes fit on one sign line with the default resource pack:
|
// 15 dashes fit on one sign line with the default resource pack:
|
||||||
public static final int MAXIMUM_SIGN_WIDTH = (short) getMinecraftStringWidth("---------------");
|
public static final int MAXIMUM_SIGN_WIDTH = (short) getMinecraftStringWidth("---------------");
|
||||||
|
|
||||||
|
private static final Map<String, String> ABBREVIATIONS = StringUtil.map(
|
||||||
|
"Egg", "Eg",
|
||||||
|
"Spawn", "Spaw",
|
||||||
|
"Ender", "End",
|
||||||
|
"Tropical", "Tropic",
|
||||||
|
"Terracotta", "Terracot",
|
||||||
|
"Stained", "Stain",
|
||||||
|
"Sandstone", "Sandston",
|
||||||
|
"Sandston", "Sandsto",
|
||||||
|
"Sandsto", "Sandst",
|
||||||
|
"Block", "Bloc",
|
||||||
|
"Brewing", "Brew",
|
||||||
|
"Dolphin", "Dolph",
|
||||||
|
"Chicken", "Chick",
|
||||||
|
"Pottery", "Pot",
|
||||||
|
"Heartbreak", "Heartbr",
|
||||||
|
"Sherd", "Sher",
|
||||||
|
"Template", "Templ"
|
||||||
|
);
|
||||||
|
|
||||||
|
private static final Map<String, String> UNIDIRECTIONAL_ABBREVIATIONS = StringUtil.map(
|
||||||
|
"Endermite", "Endmite"
|
||||||
|
);
|
||||||
|
|
||||||
private static final SimpleCache<String, Material> MATERIAL_CACHE = new SimpleCache<>(Properties.CACHE_SIZE);
|
private static final SimpleCache<String, Material> MATERIAL_CACHE = new SimpleCache<>(Properties.CACHE_SIZE);
|
||||||
|
|
||||||
private static final Yaml YAML = new Yaml(new YamlBukkitConstructor(), new YamlRepresenter(), new DumperOptions());
|
private static final Yaml YAML = new Yaml(new YamlBukkitConstructor(), new YamlRepresenter(), new DumperOptions());
|
||||||
|
@ -146,6 +169,11 @@ public class MaterialUtil {
|
||||||
* @return Material found
|
* @return Material found
|
||||||
*/
|
*/
|
||||||
public static Material getMaterial(String name) {
|
public static Material getMaterial(String name) {
|
||||||
|
// revert unidirectional abbreviations
|
||||||
|
for (Map.Entry<String, String> entry : UNIDIRECTIONAL_ABBREVIATIONS.entrySet()) {
|
||||||
|
name = name.replaceAll(entry.getValue() + "([A-Z1-9].+)?$", entry.getKey() + "$1");
|
||||||
|
}
|
||||||
|
|
||||||
String formatted = name.replaceAll("(?<!^)([A-Z1-9])", "_$1").replace(' ', '_').toUpperCase(Locale.ROOT);
|
String formatted = name.replaceAll("(?<!^)([A-Z1-9])", "_$1").replace(' ', '_').toUpperCase(Locale.ROOT);
|
||||||
|
|
||||||
Material material = MATERIAL_CACHE.get(formatted);
|
Material material = MATERIAL_CACHE.get(formatted);
|
||||||
|
@ -264,7 +292,7 @@ public class MaterialUtil {
|
||||||
* @return The name shortened to the max length
|
* @return The name shortened to the max length
|
||||||
*/
|
*/
|
||||||
public static String getShortenedName(String itemName, int maxWidth) {
|
public static String getShortenedName(String itemName, int maxWidth) {
|
||||||
itemName = StringUtil.capitalizeFirstLetter(itemName.replace('_', ' '), ' ');
|
itemName = StringUtil.capitalizeFirstLetter(itemName, '_');
|
||||||
int width = getMinecraftStringWidth(itemName);
|
int width = getMinecraftStringWidth(itemName);
|
||||||
if (width <= maxWidth) {
|
if (width <= maxWidth) {
|
||||||
return itemName;
|
return itemName;
|
||||||
|
@ -275,6 +303,25 @@ public class MaterialUtil {
|
||||||
if (width <= maxWidth) {
|
if (width <= maxWidth) {
|
||||||
return itemName;
|
return itemName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Abbreviate some terms manually
|
||||||
|
for (Map.Entry<String, String> entry : ABBREVIATIONS.entrySet()) {
|
||||||
|
itemName = itemName.replaceAll(entry.getKey() + "([A-Z1-9].+)?$", entry.getValue() + "$1");
|
||||||
|
width = getMinecraftStringWidth(itemName);
|
||||||
|
if (width <= maxWidth) {
|
||||||
|
return itemName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply unidirectional abbreviations if it still doesn't work
|
||||||
|
for (Map.Entry<String, String> entry : UNIDIRECTIONAL_ABBREVIATIONS.entrySet()) {
|
||||||
|
itemName = itemName.replaceAll(entry.getKey() + "([A-Z1-9].+)?$", entry.getValue() + "$1");
|
||||||
|
width = getMinecraftStringWidth(itemName);
|
||||||
|
if (width <= maxWidth) {
|
||||||
|
return itemName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int exceeding = width - maxWidth;
|
int exceeding = width - maxWidth;
|
||||||
int shortestIndex = 0;
|
int shortestIndex = 0;
|
||||||
int longestIndex = 0;
|
int longestIndex = 0;
|
||||||
|
@ -408,6 +455,7 @@ public class MaterialUtil {
|
||||||
E currentEnum = null;
|
E currentEnum = null;
|
||||||
String[] typeParts = name.replaceAll("(?<!^)([A-Z1-9])", "_$1").toUpperCase(Locale.ROOT).split("[ _]");
|
String[] typeParts = name.replaceAll("(?<!^)([A-Z1-9])", "_$1").toUpperCase(Locale.ROOT).split("[ _]");
|
||||||
int length = Short.MAX_VALUE;
|
int length = Short.MAX_VALUE;
|
||||||
|
name = name.toUpperCase(Locale.ROOT);
|
||||||
for (E e : values) {
|
for (E e : values) {
|
||||||
String enumName = e.name();
|
String enumName = e.name();
|
||||||
if (enumName.length() < length && enumName.startsWith(name)) {
|
if (enumName.length() < length && enumName.startsWith(name)) {
|
||||||
|
|
|
@ -4,7 +4,9 @@ import org.bukkit.ChatColor;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -154,4 +156,19 @@ public class StringUtil {
|
||||||
// Return the stripped string, without any whitespace from the end left
|
// Return the stripped string, without any whitespace from the end left
|
||||||
return stripped.toString();
|
return stripped.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a map from strings
|
||||||
|
* @param values The values to add
|
||||||
|
* @return The map
|
||||||
|
*/
|
||||||
|
public static Map<String, String> map(String... values) {
|
||||||
|
Map<String, String> map = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
for (int i = 0; i + 1 < values.length; i+=2) {
|
||||||
|
map.put(values[i], values[i + 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.Acrobot.Breeze.Tests;
|
package com.Acrobot.Breeze.Tests;
|
||||||
|
|
||||||
import com.Acrobot.Breeze.Utils.MaterialUtil;
|
import com.Acrobot.Breeze.Utils.MaterialUtil;
|
||||||
|
import com.Acrobot.Breeze.Utils.StringUtil;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -33,7 +34,19 @@ public class MaterialTest {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String shortenedName = MaterialUtil.getShortenedName(material.toString(), MaterialUtil.MAXIMUM_SIGN_WIDTH);
|
String shortenedName = MaterialUtil.getShortenedName(material.toString(), MaterialUtil.MAXIMUM_SIGN_WIDTH);
|
||||||
assertSame(material, MaterialUtil.getMaterial(shortenedName));
|
assertSame(shortenedName + " did not produce " + material, material, MaterialUtil.getMaterial(shortenedName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCodesWithMeta() {
|
||||||
|
int maxWidth = MaterialUtil.MAXIMUM_SIGN_WIDTH - StringUtil.getMinecraftStringWidth("#AAA");
|
||||||
|
for (Material material : Material.values()) {
|
||||||
|
if (material.isLegacy()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String shortenedName = MaterialUtil.getShortenedName(material.toString(), maxWidth);
|
||||||
|
assertSame(shortenedName + " did not produce " + material, material, MaterialUtil.getMaterial(shortenedName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue