Build against 1.19 and replace apache-commons-lang

This commit is contained in:
Phoenix616 2022-06-13 22:52:26 +01:00
parent 4285358910
commit fd0035a99c
No known key found for this signature in database
GPG Key ID: 40E2321E71738EB0
6 changed files with 63 additions and 24 deletions

View File

@ -461,14 +461,14 @@
<repositories>
<repository>
<id>paper-repo</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<version>1.19-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
@ -522,7 +522,7 @@
<repositories>
<repository>
<id>paper-repo</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>

View File

@ -1,10 +1,11 @@
package com.Acrobot.Breeze.Utils;
import org.apache.commons.lang.WordUtils;
import org.bukkit.ChatColor;
import java.util.Arrays;
import java.util.Collection;
import java.util.Locale;
import java.util.stream.Collectors;
/**
* @author Acrobot
@ -22,9 +23,13 @@ public class StringUtil {
if (string == null || string.isEmpty()) {
return string;
}
char[] separators = new char[]{separator};
return WordUtils.capitalize(string.toLowerCase(Locale.ROOT), separators).replace(String.valueOf(separator), " ");
// Split into words
String[] words = string.toLowerCase(Locale.ROOT).split(String.valueOf(separator));
// Capitalize every word and return joined string
return Arrays.stream(words)
.map(word -> word.substring(0, 1).toUpperCase(Locale.ROOT) + word.substring(1))
.collect(Collectors.joining(" "));
}
/**
@ -116,4 +121,37 @@ public class StringUtil {
}
return width;
}
/**
* Strip whitespace from the front and back
* @param string The string to strip
* @return The string with all whitespace from front and back stripped; returns null if input is null
*/
public static String strip(String string) {
if (string == null)
return null;
// The result stripped string
StringBuilder stripped = new StringBuilder();
// The current white space which only gets added once we find a non-whitespace character
StringBuilder cachedWhitespace = new StringBuilder();
// Check each code point (not characters to support UTF16 properly)
for (int codePoint : string.codePoints().toArray()) {
// Check if it's a whitespace, so we know if we should add it
if (!Character.isWhitespace(codePoint)) {
// Check if we have cached whitespace, if so append it first and reset the cache
if (cachedWhitespace.length() > 0) {
stripped.append(cachedWhitespace);
cachedWhitespace = new StringBuilder();
}
// Append current code point
stripped.appendCodePoint(codePoint);
} else if (stripped.length() > 0) {
// If we already have some non-whitespace content in the final stripped
// then cache the current whitespace as it wasn't at the start
cachedWhitespace.appendCodePoint(codePoint);
} // Otherwise, this was the start, and we don't need the cached whitespace
}
// Return the stripped string, without any whitespace from the end left
return stripped.toString();
}
}

View File

@ -1,7 +1,7 @@
package com.Acrobot.ChestShop.Commands;
import com.Acrobot.ChestShop.Configuration.Messages;
import org.apache.commons.lang.Validate;
import com.google.common.base.Preconditions;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@ -43,7 +43,7 @@ public class AccessToggle implements CommandExecutor {
}
public static boolean setIgnoring(Player player, boolean ignoring) {
Validate.notNull(player); // Make sure the player instance is not null, in case there are any errors in the code
Preconditions.checkNotNull(player); // Make sure the player instance is not null, in case there are any errors in the code
if (ignoring) {
toggledPlayers.add(player.getUniqueId());

View File

@ -1,7 +1,7 @@
package com.Acrobot.ChestShop.Commands;
import com.Acrobot.ChestShop.Configuration.Messages;
import org.apache.commons.lang.Validate;
import com.google.common.base.Preconditions;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
@ -61,7 +61,7 @@ public class Toggle implements CommandExecutor {
}
public static boolean setIgnoring(Player player, boolean ignoring) {
Validate.notNull(player); // Make sure the player instance is not null, in case there are any errors in the code
Preconditions.checkNotNull(player); // Make sure the player instance is not null, in case there are any errors in the code
if (ignoring) {
toggledPlayers.add(player.getUniqueId());

View File

@ -10,7 +10,6 @@ import com.Acrobot.ChestShop.Events.AccountQueryEvent;
import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import com.Acrobot.ChestShop.Utils.uBlock;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
@ -183,7 +182,7 @@ public class ChestShopSign {
for (int i = 0; i < 3; i++) {
boolean matches = false;
for (Pattern pattern : SHOP_SIGN_PATTERN[i]) {
if (pattern.matcher(StringUtils.strip(StringUtil.stripColourCodes(lines[i+1]))).matches()) {
if (pattern.matcher(StringUtil.strip(StringUtil.stripColourCodes(lines[i+1]))).matches()) {
matches = true;
break;
}
@ -213,7 +212,7 @@ public class ChestShopSign {
* @return The owner string
*/
public static String getOwner(String[] lines) {
return StringUtil.stripColourCodes(StringUtils.strip(StringUtil.stripColourCodes(lines[NAME_LINE])));
return StringUtil.stripColourCodes(StringUtil.strip(StringUtil.stripColourCodes(lines[NAME_LINE])));
}
/**
@ -233,7 +232,7 @@ public class ChestShopSign {
* @throws IllegalArgumentException Thrown when an invalid quantity is present
*/
public static String getQuantityLine(String[] lines) throws IllegalArgumentException {
return lines.length > QUANTITY_LINE ? StringUtils.strip(StringUtil.stripColourCodes(lines[QUANTITY_LINE])) : "";
return lines.length > QUANTITY_LINE ? StringUtil.strip(StringUtil.stripColourCodes(lines[QUANTITY_LINE])) : "";
}
/**
@ -262,7 +261,7 @@ public class ChestShopSign {
* @return The price line
*/
public static String getPrice(Sign sign) {
return StringUtils.strip(StringUtil.stripColourCodes(sign.getLine(PRICE_LINE)));
return StringUtil.strip(StringUtil.stripColourCodes(sign.getLine(PRICE_LINE)));
}
/**
@ -271,7 +270,7 @@ public class ChestShopSign {
* @return The price line
*/
public static String getPrice(String[] lines) {
return lines.length > PRICE_LINE ? StringUtils.strip(StringUtil.stripColourCodes(lines[PRICE_LINE])) : "";
return lines.length > PRICE_LINE ? StringUtil.strip(StringUtil.stripColourCodes(lines[PRICE_LINE])) : "";
}
/**
@ -289,6 +288,6 @@ public class ChestShopSign {
* @return The item line
*/
public static String getItem(String[] lines) {
return lines.length > ITEM_LINE ? StringUtils.strip(StringUtil.stripColourCodes(lines[ITEM_LINE])) : "";
return lines.length > ITEM_LINE ? StringUtil.strip(StringUtil.stripColourCodes(lines[ITEM_LINE])) : "";
}
}

View File

@ -12,10 +12,10 @@ import com.Acrobot.ChestShop.Events.AccountAccessEvent;
import com.Acrobot.ChestShop.Events.AccountQueryEvent;
import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import com.google.common.base.Preconditions;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.stmt.SelectArg;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
@ -63,8 +63,8 @@ public class NameManager implements Listener {
* @throws IllegalArgumentException when an invalid player object was passed
*/
public static Account getOrCreateAccount(OfflinePlayer player) {
Validate.notNull(player.getName(), "Name of player " + player.getUniqueId() + " is null?");
Validate.isTrue(!(player instanceof Player) || !Properties.ENSURE_CORRECT_PLAYERID || uuidVersion < 0 || player.getUniqueId().version() == uuidVersion,
Preconditions.checkNotNull(player.getName(), "Name of player " + player.getUniqueId() + " is null?");
Preconditions.checkArgument(!(player instanceof Player) || !Properties.ENSURE_CORRECT_PLAYERID || uuidVersion < 0 || player.getUniqueId().version() == uuidVersion,
"Invalid OfflinePlayer! " + player.getUniqueId() + " has version " + player.getUniqueId().version() + " and not server version " + uuidVersion + ". " +
"If you believe that is an error and your setup allows such UUIDs then set the ENSURE_CORRECT_PLAYERID config option to false.");
return getOrCreateAccount(player.getUniqueId(), player.getName());
@ -79,8 +79,8 @@ public class NameManager implements Listener {
* @throws IllegalArgumentException when id or name are null
*/
public static Account getOrCreateAccount(UUID id, String name) {
Validate.notNull(id, "UUID of player is null?");
Validate.notNull(name, "Name of player " + id + " is null?");
Preconditions.checkNotNull(id, "UUID of player is null?");
Preconditions.checkNotNull(name, "Name of player " + id + " is null?");
Account account = getAccount(id);
if (account == null) {
@ -124,7 +124,8 @@ public class NameManager implements Listener {
* @throws IllegalArgumentException if the username is empty or null
*/
public static Account getAccount(String fullName) {
Validate.notEmpty(fullName, "fullName cannot be null or empty!");
Preconditions.checkNotNull(fullName, "fullName cannot be null!");
Preconditions.checkArgument(!fullName.isEmpty(), "fullName cannot be empty!");
try {
return usernameToAccount.get(fullName, () -> {
try {
@ -161,7 +162,8 @@ public class NameManager implements Listener {
*/
@Deprecated
public static Account getAccountFromShortName(String shortName) {
Validate.notEmpty(shortName, "shortName cannot be null or empty!");
Preconditions.checkNotNull(shortName, "shortName cannot be null!");
Preconditions.checkArgument(!shortName.isEmpty(), "shortName cannot be empty!");
Account account = null;
try {