From c7fcc596da3ae690be84fc19c57278728ee4e867 Mon Sep 17 00:00:00 2001 From: UnfamiliarLegacy <74633542+UnfamiliarLegacy@users.noreply.github.com> Date: Mon, 24 Jun 2024 04:28:34 +0200 Subject: [PATCH] Remove apache dependency from ShockPacketIncoming --- .../src/main/java/gearth/misc/ArrayUtils.java | 57 +++++++++++++++++++ .../packets/ShockPacketIncoming.java | 2 +- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 G-Earth/src/main/java/gearth/misc/ArrayUtils.java diff --git a/G-Earth/src/main/java/gearth/misc/ArrayUtils.java b/G-Earth/src/main/java/gearth/misc/ArrayUtils.java new file mode 100644 index 0000000..7407c54 --- /dev/null +++ b/G-Earth/src/main/java/gearth/misc/ArrayUtils.java @@ -0,0 +1,57 @@ +package gearth.misc; + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +public class ArrayUtils { + + /** + * The index value when an element is not found in a list or array: {@code -1}. + * This value is returned by methods in this class and can also be used in comparisons with values returned by + * various method from {@link java.util.List}. + */ + public static final int INDEX_NOT_FOUND = -1; + + /** + *

Finds the index of the given value in the array starting at the given index. + * + *

This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array. + * + *

A negative startIndex is treated as zero. A startIndex larger than the array + * length will return {@link #INDEX_NOT_FOUND} ({@code -1}). + * + * @param array the array to search through for the object, may be {@code null} + * @param valueToFind the value to find + * @param startIndex the index to start searching at + * @return the index of the value within the array, + * {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input + */ + public static int indexOf(final byte[] array, final byte valueToFind, int startIndex) { + if (array == null) { + return INDEX_NOT_FOUND; + } + if (startIndex < 0) { + startIndex = 0; + } + for (int i = startIndex; i < array.length; i++) { + if (valueToFind == array[i]) { + return i; + } + } + return INDEX_NOT_FOUND; + } + +} diff --git a/G-Earth/src/main/java/gearth/protocol/packethandler/shockwave/packets/ShockPacketIncoming.java b/G-Earth/src/main/java/gearth/protocol/packethandler/shockwave/packets/ShockPacketIncoming.java index 78e95d6..9812a08 100644 --- a/G-Earth/src/main/java/gearth/protocol/packethandler/shockwave/packets/ShockPacketIncoming.java +++ b/G-Earth/src/main/java/gearth/protocol/packethandler/shockwave/packets/ShockPacketIncoming.java @@ -1,9 +1,9 @@ package gearth.protocol.packethandler.shockwave.packets; import gearth.encoding.VL64Encoding; +import gearth.misc.ArrayUtils; import gearth.protocol.HPacket; import gearth.protocol.HPacketFormat; -import org.apache.commons.lang3.ArrayUtils; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;