[ci skip] Some cleanup for Platform class and other platform-specific stuff (#201)

* Ensure paths returned by Platform are absolute, add javadocs to Platform

Signed-off-by: Max <maxh2709@gmail.com>

* Use putIfAbsent for event buses to clean up some minor nastyness

Signed-off-by: Max <maxh2709@gmail.com>

* Remove explicit NotNull annotation
This commit is contained in:
Max
2022-02-19 00:43:12 +08:00
committed by shedaniel
parent bad3d30ead
commit 5d276f04ed
4 changed files with 77 additions and 9 deletions

View File

@@ -32,9 +32,7 @@ public final class EventBuses {
private static final Map<String, List<Consumer<IEventBus>>> ON_REGISTERED = new HashMap<>();
public static void registerModEventBus(String modId, IEventBus bus) {
IEventBus previous = EVENT_BUS_MAP.put(modId, bus);
if (previous != null) {
EVENT_BUS_MAP.put(modId, previous);
if (EVENT_BUS_MAP.putIfAbsent(modId, bus) != bus) {
throw new IllegalStateException("Can't register event bus for mod '" + modId + "' because it was previously registered!");
}

View File

@@ -91,11 +91,11 @@ public class PlatformImpl {
private final ModInfo info;
public ModImpl(String id) {
this.container = ModList.get().getModContainerById(id).get();
this.container = ModList.get().getModContainerById(id).orElseThrow();
this.info = ModList.get().getMods().stream()
.filter(modInfo -> Objects.equals(modInfo.getModId(), id))
.findAny()
.get();
.orElseThrow();
}
@Override