diff --git a/src/main/java/io/ix0rai/rainglow/Rainglow.java b/src/main/java/io/ix0rai/rainglow/Rainglow.java index ffcdf98..4588d2a 100644 --- a/src/main/java/io/ix0rai/rainglow/Rainglow.java +++ b/src/main/java/io/ix0rai/rainglow/Rainglow.java @@ -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 RAINGLOW_DATAPACKS = new ArrayList<>(); - private static final Map colours = new HashMap<>(); + private static final Map COLOURS = new HashMap<>(); @Override public void onInitialize() { @@ -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) { @@ -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; @@ -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 getColours() { - return colours; + return COLOURS; } }