Skip to content

Commit

Permalink
clear colours on world disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
ix0rai committed Aug 11, 2024
1 parent cc41a8c commit 8e86592
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/main/java/io/ix0rai/rainglow/Rainglow.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class Rainglow implements ModInitializer {
public static final Identifier SERVER_MODE_DATA_ID = id("server_mode_data");
public static final List<String> RAINGLOW_DATAPACKS = new ArrayList<>();

private static final Map<UUID, RainglowColour> colours = new HashMap<>();
private static final Map<UUID, RainglowColour> COLOURS = new HashMap<>();

@Override
public void onInitialize() {
Expand Down Expand Up @@ -69,6 +69,10 @@ public void onInitialize() {
Rainglow.setColour(entry.getKey(), colour);
}
});

ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> {
COLOURS.clear();
});
}

public static Identifier id(String id) {
Expand Down Expand Up @@ -99,14 +103,14 @@ public static Text translatableText(String key) {
}

public static RainglowColour getColour(Entity entity) {
RainglowColour colour = colours.get(entity.getUuid());
RainglowColour colour = COLOURS.get(entity.getUuid());
RainglowEntity entityType = RainglowEntity.get(entity);

// generate random colour if the squid's colour isn't currently loaded
if (colourUnloaded(entity.getWorld(), entityType, colour)) {
// Use last generated colour if not null else generate a new colour
colour = generateRandomColour(entity.getWorld(), entity.getRandom());
colours.put(entity.getUuid(), colour);
COLOURS.put(entity.getUuid(), colour);
}

return colour;
Expand All @@ -125,10 +129,10 @@ public static void setColour(Entity entity, RainglowColour colour) {
}

public static void setColour(UUID uuid, RainglowColour colour) {
colours.put(uuid, colour);
COLOURS.put(uuid, colour);
}

public static Map<UUID, RainglowColour> getColours() {
return colours;
return COLOURS;
}
}

0 comments on commit 8e86592

Please sign in to comment.