2424import net .minecraft .client .texture .NativeImageBackedTexture ;
2525import net .minecraft .nbt .NbtCompound ;
2626import net .minecraft .nbt .NbtElement ;
27+ import org .apache .commons .lang3 .StringUtils ;
2728import org .jetbrains .annotations .NotNull ;
2829
2930import java .io .File ;
3233import java .io .InputStream ;
3334import java .util .*;
3435import java .util .concurrent .ConcurrentHashMap ;
36+ import java .util .concurrent .CopyOnWriteArrayList ;
3537
3638public class Waypoints extends System <Waypoints > implements Iterable <Waypoint > {
39+ private static final String PNG = ".png" ;
40+
3741 public static final String [] BUILTIN_ICONS = {"square" , "circle" , "triangle" , "star" , "diamond" , "skull" };
3842
3943 public final Map <String , AbstractTexture > icons = new ConcurrentHashMap <>();
4044
41- private final List <Waypoint > waypoints = Collections . synchronizedList ( new ArrayList <>() );
45+ private final List <Waypoint > waypoints = new CopyOnWriteArrayList <>();
4246
4347 public Waypoints () {
4448 super (null );
@@ -54,18 +58,18 @@ public void init() {
5458 iconsFolder .mkdirs ();
5559
5660 for (String builtinIcon : BUILTIN_ICONS ) {
57- File iconFile = new File (iconsFolder , builtinIcon + ".png" );
61+ File iconFile = new File (iconsFolder , builtinIcon + PNG );
5862 if (!iconFile .exists ()) copyIcon (iconFile );
5963 }
6064
6165 File [] files = iconsFolder .listFiles ();
6266 if (files == null ) return ;
6367
6468 for (File file : files ) {
65- if (file .getName ().endsWith (".png" )) {
66- try {
67- String name = file .getName (). replace ( ".png" , "" );
68- AbstractTexture texture = new NativeImageBackedTexture (null , NativeImage .read (new FileInputStream ( file ) ));
69+ if (file .getName ().endsWith (PNG )) {
70+ try ( FileInputStream inputStream = new FileInputStream ( file )) {
71+ String name = StringUtils . removeEnd ( file .getName (), PNG );
72+ AbstractTexture texture = new NativeImageBackedTexture (() -> name , NativeImage .read (inputStream ));
6973 icons .put (name , texture );
7074 }
7175 catch (IOException e ) {
0 commit comments