#1182: Consolidate Preconditions use and minor cleanup

By: Doc <nachito94@msn.com>
This commit is contained in:
CraftBukkit/Spigot
2023-06-12 19:41:02 +10:00
parent 5ff68bfbcb
commit ff78bf30f6
72 changed files with 695 additions and 855 deletions

View File

@@ -1,5 +1,6 @@
package org.bukkit.craftbukkit.map;
import com.google.common.base.Preconditions;
import java.awt.Color;
import java.awt.Image;
import java.util.Arrays;
@@ -102,9 +103,7 @@ public class CraftMapCanvas implements MapCanvas {
public void drawText(int x, int y, MapFont font, String text) {
int xStart = x;
byte color = MapPalette.DARK_GRAY;
if (!font.isValid(text)) {
throw new IllegalArgumentException("text contains invalid characters");
}
Preconditions.checkArgument(font.isValid(text), "text (%s) contains invalid characters", text);
for (int i = 0; i < text.length(); ++i) {
char ch = text.charAt(i);
@@ -114,15 +113,13 @@ public class CraftMapCanvas implements MapCanvas {
continue;
} else if (ch == '\u00A7') {
int j = text.indexOf(';', i);
if (j >= 0) {
try {
color = Byte.parseByte(text.substring(i + 1, j));
i = j;
continue;
} catch (NumberFormatException ex) {
}
Preconditions.checkArgument(j >= 0, "text (%s) unterminated color string", text);
try {
color = Byte.parseByte(text.substring(i + 1, j));
i = j;
continue;
} catch (NumberFormatException ex) {
}
throw new IllegalArgumentException("Text contains unterminated color string");
}
CharacterSprite sprite = font.getChar(text.charAt(i));

View File

@@ -1,5 +1,6 @@
package org.bukkit.craftbukkit.map;
import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -16,7 +17,6 @@ import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.map.MapRenderer;
import org.bukkit.map.MapView;
import org.bukkit.map.MapView.Scale;
public final class CraftMapView implements MapView {
@@ -33,14 +33,11 @@ public final class CraftMapView implements MapView {
@Override
public int getId() {
String text = worldMap.id;
if (text.startsWith("map_")) {
try {
return Integer.parseInt(text.substring("map_".length()));
} catch (NumberFormatException ex) {
throw new IllegalStateException("Map has non-numeric ID");
}
} else {
throw new IllegalStateException("Map has invalid ID");
Preconditions.checkState(text.startsWith("map_"), "Map has a invalid ID");
try {
return Integer.parseInt(text.substring("map_".length()));
} catch (NumberFormatException ex) {
throw new IllegalStateException("Map has non-numeric ID");
}
}