generated from LabyMod/addon-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
153 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
core/src/main/java/com/funkeln/pronouns/event/ServerJoinListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.funkeln.pronouns.event; | ||
|
||
import com.funkeln.pronouns.PronounAddon; | ||
import net.labymod.api.event.Subscribe; | ||
import net.labymod.api.event.client.network.server.ServerJoinEvent; | ||
|
||
/** | ||
* @author https://github.com/PrincessAkira (Sarah) Today is the 9/9/2024 @11:18 PM This project is | ||
* named labymod4-addon-template | ||
* @description Another day of Insanity | ||
*/ | ||
public class ServerJoinListener { | ||
private final PronounAddon addon; | ||
|
||
public ServerJoinListener(PronounAddon addon) { | ||
this.addon = addon; | ||
} | ||
|
||
@Subscribe | ||
public void on(ServerJoinEvent event) { | ||
addon.publishNameUpdate(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
core/src/main/java/com/funkeln/pronouns/profile/ProfileRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.funkeln.pronouns.profile; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* @author https://github.com/PrincessAkira (Sarah) Today is the 9/9/2024 @10:21 PM This project is | ||
* named labymod4-addon-template | ||
* @description Another day of Insanity | ||
*/ | ||
public class ProfileRepository { | ||
private final static Map<UUID, Profile> profiles = new ConcurrentHashMap<>(); | ||
|
||
public static void enterName(UUID id, String name) { | ||
profiles.computeIfAbsent(id, Profile::new).updateName(name); | ||
} | ||
|
||
public static Optional<Profile> find(UUID id) { | ||
return Optional.ofNullable(profiles.get(id)); | ||
} | ||
|
||
public static Set<UUID> knownPlayers() { | ||
return profiles.keySet(); | ||
} | ||
|
||
public static void updateProfiles(boolean onlyUpdateFirstTimes) { | ||
for (Profile profile : profiles.values()) { | ||
if (profile.updateRequired()) { | ||
if (onlyUpdateFirstTimes && !profile.requiresUpdateNow()) { | ||
return; | ||
} | ||
profile.update(); | ||
} | ||
} | ||
} | ||
|
||
public static void clearExpired() { | ||
profiles.entrySet().removeIf( | ||
entry -> entry.getValue().expired() | ||
); | ||
} | ||
} |