Skip to content

Commit b78deac

Browse files
Fix waypoints parse int
1 parent 8316418 commit b78deac

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

src/main/java/com/kevinthegreat/skyblockmod/waypoint/WaypointsListWidget.java

+19-25
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package com.kevinthegreat.skyblockmod.waypoint;
22

33
import com.kevinthegreat.skyblockmod.mixins.CheckboxWidgetAccessor;
4+
import it.unimi.dsi.fastutil.ints.Int2ObjectFunction;
45
import net.minecraft.client.MinecraftClient;
56
import net.minecraft.client.gui.DrawContext;
67
import net.minecraft.client.gui.Element;
78
import net.minecraft.client.gui.Selectable;
89
import net.minecraft.client.gui.widget.*;
910
import net.minecraft.text.Text;
1011
import net.minecraft.util.math.BlockPos;
11-
import org.apache.commons.lang3.math.NumberUtils;
1212

1313
import java.util.ArrayList;
1414
import java.util.Arrays;
@@ -227,35 +227,28 @@ public void updateName(String name) {
227227
}
228228

229229
public void updateX(String xString) {
230-
if (!NumberUtils.isParsable(xString)) return;
231-
int index = category.category.waypoints().indexOf(waypoint);
232-
int x = Integer.parseInt(xString);
233-
if (waypoint.pos.getX() == x) return;
234-
waypoint = waypoint.withX(x);
235-
if (index >= 0) {
236-
category.category.waypoints().set(index, waypoint);
237-
}
230+
updateInt(xString, waypoint.pos.getX(), waypoint::withX);
238231
}
239232

240233
public void updateY(String yString) {
241-
if (!NumberUtils.isParsable(yString)) return;
242-
int index = category.category.waypoints().indexOf(waypoint);
243-
int y = Integer.parseInt(yString);
244-
if (waypoint.pos.getY() == y) return;
245-
waypoint = waypoint.withY(y);
246-
if (index >= 0) {
247-
category.category.waypoints().set(index, waypoint);
248-
}
234+
updateInt(yString, waypoint.pos.getY(), waypoint::withY);
249235
}
250236

251237
public void updateZ(String zString) {
252-
if (!NumberUtils.isParsable(zString)) return;
253-
int index = category.category.waypoints().indexOf(waypoint);
254-
int z = Integer.parseInt(zString);
255-
if (waypoint.pos.getZ() == z) return;
256-
waypoint = waypoint.withZ(z);
257-
if (index >= 0) {
258-
category.category.waypoints().set(index, waypoint);
238+
updateInt(zString, waypoint.pos.getZ(), waypoint::withZ);
239+
}
240+
241+
public void updateInt(String newValueString, int currentValue, Int2ObjectFunction<NamedWaypoint> wither) {
242+
try {
243+
int index = category.category.waypoints().indexOf(waypoint);
244+
int newValue = Integer.parseInt(newValueString);
245+
if (newValue == currentValue) return;
246+
waypoint = wither.apply(newValue);
247+
if (index >= 0) {
248+
category.category.waypoints().set(index, waypoint);
249+
}
250+
} catch (NumberFormatException e) {
251+
Waypoints.LOGGER.warn("[Skyblocker Waypoints] Failed to parse integer: {}", newValueString, e);
259252
}
260253
}
261254

@@ -270,7 +263,8 @@ public void updateColor(String colorString) {
270263
if (index >= 0) {
271264
category.category.waypoints().set(index, waypoint);
272265
}
273-
} catch (NumberFormatException ignored) {
266+
} catch (NumberFormatException e) {
267+
Waypoints.LOGGER.error("[Skyblocker Waypoints] Failed to parse color: {}", colorString, e);
274268
}
275269
}
276270

0 commit comments

Comments
 (0)