diff --git a/leaf-server/src/main/java/org/dreeam/leaf/config/LeafGlobalConfig.java b/leaf-server/src/main/java/org/dreeam/leaf/config/LeafGlobalConfig.java index 3d4a6257..eba6cdf6 100644 --- a/leaf-server/src/main/java/org/dreeam/leaf/config/LeafGlobalConfig.java +++ b/leaf-server/src/main/java/org/dreeam/leaf/config/LeafGlobalConfig.java @@ -141,17 +141,41 @@ public class LeafGlobalConfig { public Double getDouble(String path) { String value = configFile.getString(path, null); - return value == null ? null : Double.parseDouble(value); // TODO: Need to check whether need to handle NFE correctly + if (value == null) { + return null; + } + try { + return Double.parseDouble(value); + } catch (NumberFormatException e) { + LeafConfig.LOGGER.warn("{} is not a valid number, skipped! Please check your configuration.", path, e); + return null; + } } public Integer getInt(String path) { String value = configFile.getString(path, null); - return value == null ? null : Integer.parseInt(value); // TODO: Need to check whether need to handle NFE correctly + if (value == null) { + return null; + } + try { + return Integer.parseInt(value); + } catch (NumberFormatException e) { + LeafConfig.LOGGER.warn("{} is not a valid number, skipped! Please check your configuration.", path, e); + return null; + } } public Long getLong(String path) { String value = configFile.getString(path, null); - return value == null ? null : Long.parseLong(value); // TODO: Need to check whether need to handle NFE correctly + if (value == null) { + return null; + } + try { + return Long.parseLong(value); + } catch (NumberFormatException e) { + LeafConfig.LOGGER.warn("{} is not a valid number, skipped! Please check your configuration.", path, e); + return null; + } } public List getList(String path) { diff --git a/leaf-server/src/main/java/org/dreeam/leaf/util/list/BlockEntityTickersList.java b/leaf-server/src/main/java/org/dreeam/leaf/util/list/BlockEntityTickersList.java index 48201f62..5cd10116 100644 --- a/leaf-server/src/main/java/org/dreeam/leaf/util/list/BlockEntityTickersList.java +++ b/leaf-server/src/main/java/org/dreeam/leaf/util/list/BlockEntityTickersList.java @@ -71,33 +71,35 @@ public final class BlockEntityTickersList extends ObjectArrayList 0) { + System.arraycopy(a, lastCopyIndex, a, writeIndex, blockLength); + writeIndex += blockLength; + } + lastCopyIndex = readIndex + 1; + + if (matches == requiredMatches) { + break; } - j = size - requiredMatches; - break; } } - Arrays.fill(a, j, size, null); - size = j; + final int finalBlockLength = size - lastCopyIndex; + if (finalBlockLength > 0) { + System.arraycopy(a, lastCopyIndex, a, writeIndex, finalBlockLength); + writeIndex += finalBlockLength; + } + + if (writeIndex < size) { + Arrays.fill(a, writeIndex, size, null); + } + size = writeIndex; } }