Skip to content

Commit

Permalink
1.19 update tracker (#112)
Browse files Browse the repository at this point in the history
* Update to Spigot 1.19

* Fix a bug stopping the plugin from not starting

* Update XSeries

Now supports 1.19 blocks

* Don't import a world if already existent

Signed-off-by: Thomas Meaney <[email protected]>
  • Loading branch information
thomasmny authored Jun 15, 2022
1 parent 2b4bef8 commit e270774
Show file tree
Hide file tree
Showing 14 changed files with 258 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.bstats.charts.SimplePie;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import com.eintosti.buildsystem.object.world.BuildWorld;
import com.eintosti.buildsystem.object.world.Builder;
import com.eintosti.buildsystem.util.UUIDFetcher;
import org.apache.commons.lang.StringUtils;
import com.eintosti.buildsystem.util.external.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.cryptomorin.xseries.XMaterial;
import com.eintosti.buildsystem.BuildSystem;
import com.eintosti.buildsystem.manager.InventoryManager;
import com.eintosti.buildsystem.manager.WorldManager;
import com.eintosti.buildsystem.object.world.data.WorldStatus;
import com.eintosti.buildsystem.object.world.data.WorldType;
import org.bukkit.event.EventHandler;
Expand All @@ -27,12 +26,10 @@ public class InventoryCloseListener implements Listener {

private final BuildSystem plugin;
private final InventoryManager inventoryManager;
private final WorldManager worldManager;

public InventoryCloseListener(BuildSystem plugin) {
this.plugin = plugin;
this.inventoryManager = plugin.getInventoryManager();
this.worldManager = plugin.getWorldManager();
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,12 @@ public void managePlacePlantsSetting(PlayerInteractEvent event) {
return;
}

Material material = itemStack.getType();
if (!XTag.FLOWERS.isTagged(XMaterial.matchXMaterial(material))) {
XMaterial xMaterial = XMaterial.matchXMaterial(itemStack.getType());
if (!XTag.FLOWERS.isTagged(xMaterial)
&& !XTag.REPLACEABLE_PLANTS.isTagged(xMaterial)
&& !XTag.ALIVE_CORAL_PLANTS.isTagged(xMaterial)
&& !XTag.DEAD_CORAL_PLANTS.isTagged(xMaterial)
&& !XTag.SAPLINGS.isTagged(xMaterial)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.eintosti.buildsystem.object.world.data.WorldType;
import com.eintosti.buildsystem.util.exception.UnexpectedEnumValueException;
import com.eintosti.buildsystem.util.external.ItemSkulls;
import org.apache.commons.lang.StringUtils;
import com.eintosti.buildsystem.util.external.StringUtils;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ public void startWorldNameInput(Player player, WorldType worldType, @Nullable St

new PlayerChatInput(plugin, player, "enter_world_name", input -> {
for (String charString : input.split("")) {
if (charString.matches("[^A-Za-z0-9/_-]")) {
if (charString.matches("[^A-Za-z\\d/_-]")) {
player.sendMessage(plugin.getString("worlds_world_creation_invalid_characters"));
break;
}
}

String worldName = input.replaceAll("[^A-Za-z0-9/_-]", "").replace(" ", "_").trim();
String worldName = input.replaceAll("[^A-Za-z\\d/_-]", "").replace(" ", "_").trim();
if (worldName.isEmpty()) {
player.sendMessage(plugin.getString("worlds_world_creation_name_bank"));
return;
Expand Down Expand Up @@ -476,7 +476,7 @@ public ChunkGenerator getChunkGenerator(String generator, String generatorId, St
*/
public void importWorld(Player player, String worldName, Generator generator, String... generatorName) {
for (String charString : worldName.split("")) {
if (charString.matches("[^A-Za-z0-9/_-]")) {
if (charString.matches("[^A-Za-z\\d/_-]")) {
player.sendMessage(plugin.getString("worlds_import_invalid_character")
.replace("%world%", worldName)
.replace("%char%", charString)
Expand All @@ -491,6 +491,11 @@ public void importWorld(Player player, String worldName, Generator generator, St
return;
}

if (getBuildWorld(worldName) != null) {
player.sendMessage(plugin.getString("worlds_world_exists"));
return;
}

ChunkGenerator chunkGenerator = null;
if (generator == Generator.CUSTOM) {
List<String> genArray;
Expand Down Expand Up @@ -547,19 +552,24 @@ public void run() {

String worldName = worldList[i];
for (String charString : worldName.split("")) {
if (charString.matches("[^A-Za-z0-9/_-]")) {
if (charString.matches("[^A-Za-z\\d/_-]")) {
player.sendMessage(plugin.getString("worlds_importall_invalid_character").replace("%world%", worldName).replace("%char%", charString));
return;
}
}

if (getBuildWorld(worldName) != null) {
player.sendMessage(plugin.getString("worlds_importall_world_already_imported").replace("%world%", worldName));
return;
}

long creation = FileUtils.getDirectoryCreation(new File(Bukkit.getWorldContainer(), worldName));
BuildWorld buildWorld = new BuildWorld(plugin, worldName, "-", null, WorldType.IMPORTED, creation, false);
buildWorlds.add(buildWorld);
generateBukkitWorld(worldName, WorldType.VOID, buildWorld.getDifficulty());
player.sendMessage(plugin.getString("worlds_importall_world_imported").replace("%world%", worldName));

if (!(worldsImported.get() < worlds)) {
if (worldsImported.get() >= worlds) {
this.cancel();
player.sendMessage(plugin.getString("worlds_importall_finished"));
}
Expand Down Expand Up @@ -671,14 +681,14 @@ public void renameWorld(Player player, BuildWorld buildWorld, String newName) {
}

for (String charString : newName.split("")) {
if (charString.matches("[^A-Za-z0-9/_-]")) {
if (charString.matches("[^A-Za-z\\d/_-]")) {
player.sendMessage(plugin.getString("worlds_world_creation_invalid_characters"));
break;
}
}

player.closeInventory();
String parsedNewName = newName.replaceAll("[^A-Za-z0-9/_-]", "").replace(" ", "_").trim();
String parsedNewName = newName.replaceAll("[^A-Za-z\\d/_-]", "").replace(" ", "_").trim();
if (parsedNewName.isEmpty()) {
player.sendMessage(plugin.getString("worlds_world_creation_name_bank"));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public enum ServerVersion {
v1_17_R1(CustomBlocks_1_13_R1.class, GameRules_1_13_R1.class),
v1_18_R1(CustomBlocks_1_13_R1.class, GameRules_1_13_R1.class),
v1_18_R2(CustomBlocks_1_13_R1.class, GameRules_1_13_R1.class),
v1_19_R1(CustomBlocks_1_13_R1.class, GameRules_1_13_R1.class),
UNKNOWN;

private final Class<? extends CustomBlocks> customBlocks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

package com.eintosti.buildsystem.tabcomplete;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ public void createMessageFile() {
setMessage(sb, config, "worlds_importall_started", "%prefix% &7Beginning import of &b%amount% &7worlds...");
setMessage(sb, config, "worlds_importall_delay", "%prefix% &8➥ &7Delay between each world: &b%delay%s&7.");
setMessage(sb, config, "worlds_importall_invalid_character", "%prefix% &c✘ &7&o%world% &7contains invalid character &8(&c%char%&8)");
setMessage(sb, config, "worlds_importall_world_already_imported", "%prefix% &c&l✗ &7World already imported: &b%world%");
setMessage(sb, config, "worlds_importall_world_imported", "%prefix% &a✔ &7World imported: &b%world%");
setMessage(sb, config, "worlds_importall_finished", "%prefix% &7All worlds have been &asuccessfully &7imported.");
addLine(sb, "");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2022, Thomas Meaney
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.eintosti.buildsystem.util.external;

/**
* <p>Provides extra functionality for Java Number classes.</p>
*
* @since 2.0
*/
public class NumberUtils {

/**
* <p>{@code NumberUtils} instances should NOT be constructed in standard programming.
* Instead, the class should be used as {@code NumberUtils.toInt("6");}.</p>
*
* <p>This constructor is public to permit tools that require a JavaBean instance
* to operate.</p>
*/
public NumberUtils() {
}

/**
* <p>Convert a {@code String} to an {@code int}, returning
* {@code zero} if the conversion fails.</p>
*
* <p>If the string is {@code null}, {@code zero} is returned.</p>
*
* <pre>
* NumberUtils.toInt(null) = 0
* NumberUtils.toInt("") = 0
* NumberUtils.toInt("1") = 1
* </pre>
*
* @param str the string to convert, may be null
* @return the int represented by the string, or {@code zero} if
* conversion fails
* @since 2.1
*/
public static int toInt(final String str) {
return toInt(str, 0);
}

/**
* <p>Convert a {@code String} to an {@code int}, returning a
* default value if the conversion fails.</p>
*
* <p>If the string is {@code null}, the default value is returned.</p>
*
* <pre>
* NumberUtils.toInt(null, 1) = 1
* NumberUtils.toInt("", 1) = 1
* NumberUtils.toInt("1", 0) = 1
* </pre>
*
* @param str the string to convert, may be null
* @param defaultValue the default value
* @return the int represented by the string, or the default if conversion fails
* @since 2.1
*/
public static int toInt(final String str, final int defaultValue) {
if (str == null) {
return defaultValue;
}
try {
return Integer.parseInt(str);
} catch (final NumberFormatException nfe) {
return defaultValue;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
* Copyright (c) 2022, Thomas Meaney
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.eintosti.buildsystem.util.external;

/**
* <p>Operations on {@link java.lang.String} that are
* {@code null} safe.</p>
*
* <ul>
* <li><b>Difference</b>
* - compares Strings and reports on their differences</li>
* </ul>
*
* <p>The {@code StringUtils} class defines certain words related to
* String handling.</p>
*
* <ul>
* <li>null - {@code null}</li>
* <li>empty - a zero-length string ({@code ""})</li>
* <li>space - the space character ({@code ' '}, char 32)</li>
* <li>whitespace - the characters defined by {@link Character#isWhitespace(char)}</li>
* <li>trim - the characters &lt;= 32 as in {@link String#trim()}</li>
* </ul>
*
* <p>{@code StringUtils} handles {@code null} input Strings quietly.
* That is to say that a {@code null} input will return {@code null}.
* Where a {@code boolean} or {@code int} is being returned
* details vary by method.</p>
*
* <p>A side effect of the {@code null} handling is that a
* {@code NullPointerException} should be considered a bug in
* {@code StringUtils}.</p>
*
* <p>Methods in this class include sample code in their Javadoc comments to explain their operation.
* The symbol {@code *} is used to indicate any input including {@code null}.</p>
*
* <p>#ThreadSafe#</p>
*
* @see java.lang.String
* @since 1.0
*/
//@Immutable
public class StringUtils {

/**
* The empty String {@code ""}.
*
* @since 2.0
*/
public static final String EMPTY = "";

/**
* Represents a failed index search.
*
* @since 2.1
*/
public static final int INDEX_NOT_FOUND = -1;

/**
* <p>Compares two Strings, and returns the portion where they differ.
* More precisely, return the remainder of the second String,
* starting from where it's different from the first. This means that
* the difference between "abc" and "ab" is the empty String and not "c". </p>
*
* <p>For example,
* {@code difference("i am a machine", "i am a robot") -> "robot"}.</p>
*
* <pre>
* StringUtils.difference(null, null) = null
* StringUtils.difference("", "") = ""
* StringUtils.difference("", "abc") = "abc"
* StringUtils.difference("abc", "") = ""
* StringUtils.difference("abc", "abc") = ""
* StringUtils.difference("abc", "ab") = ""
* StringUtils.difference("ab", "abxyz") = "xyz"
* StringUtils.difference("abcde", "abxyz") = "xyz"
* StringUtils.difference("abcde", "xyz") = "xyz"
* </pre>
*
* @param str1 the first String, may be null
* @param str2 the second String, may be null
* @return the portion of str2 where it differs from str1; returns the
* empty String if they are equal
* @see #indexOfDifference(CharSequence, CharSequence)
* @since 2.0
*/
public static String difference(final String str1, final String str2) {
if (str1 == null) {
return str2;
}
if (str2 == null) {
return str1;
}
final int at = indexOfDifference(str1, str2);
if (at == INDEX_NOT_FOUND) {
return EMPTY;
}
return str2.substring(at);
}

/**
* <p>Compares two CharSequences, and returns the index at which the
* CharSequences begin to differ.</p>
*
* <p>For example,
* {@code indexOfDifference("i am a machine", "i am a robot") -> 7}</p>
*
* <pre>
* StringUtils.indexOfDifference(null, null) = -1
* StringUtils.indexOfDifference("", "") = -1
* StringUtils.indexOfDifference("", "abc") = 0
* StringUtils.indexOfDifference("abc", "") = 0
* StringUtils.indexOfDifference("abc", "abc") = -1
* StringUtils.indexOfDifference("ab", "abxyz") = 2
* StringUtils.indexOfDifference("abcde", "abxyz") = 2
* StringUtils.indexOfDifference("abcde", "xyz") = 0
* </pre>
*
* @param cs1 the first CharSequence, may be null
* @param cs2 the second CharSequence, may be null
* @return the index where cs1 and cs2 begin to differ; -1 if they are equal
* @since 2.0
* @since 3.0 Changed signature from indexOfDifference(String, String) to
* indexOfDifference(CharSequence, CharSequence)
*/
public static int indexOfDifference(final CharSequence cs1, final CharSequence cs2) {
if (cs1 == cs2) {
return INDEX_NOT_FOUND;
}
if (cs1 == null || cs2 == null) {
return 0;
}
int i;
for (i = 0; i < cs1.length() && i < cs2.length(); ++i) {
if (cs1.charAt(i) != cs2.charAt(i)) {
break;
}
}
if (i < cs2.length() || i < cs1.length()) {
return i;
}
return INDEX_NOT_FOUND;
}
}
Loading

0 comments on commit e270774

Please sign in to comment.