Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit c92e748

Browse files
Make CapabilityRegisteredCallback store class names not class objects (#175)
1 parent 5c633e6 commit c92e748

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

patchwork-capabilities/src/main/java/net/patchworkmc/api/capability/CapabilityRegisteredCallback.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public interface CapabilityRegisteredCallback<C> {
2929
void onCapabilityRegistered(Capability<C> capability);
3030

3131
static <C> Event<CapabilityRegisteredCallback<C>> event(Class<C> type) {
32-
return CapabilityRegisteredCallbackInternal.getOrCreateEvent(type);
32+
return CapabilityRegisteredCallbackInternal.getOrCreateEvent(type.getName());
33+
}
34+
35+
static <C> Event<CapabilityRegisteredCallback<C>> event(String className) {
36+
return CapabilityRegisteredCallbackInternal.getOrCreateEvent(className);
3337
}
3438
}

patchwork-capabilities/src/main/java/net/patchworkmc/impl/capability/CapabilityRegisteredCallbackInternal.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
package net.patchworkmc.impl.capability;
2121

22-
import java.util.IdentityHashMap;
22+
import java.util.HashMap;
2323
import java.util.Map;
2424

2525
import org.apache.logging.log4j.LogManager;
@@ -33,10 +33,10 @@
3333
public class CapabilityRegisteredCallbackInternal {
3434
private static final Logger LOGGER = LogManager.getLogger(CapabilityRegisteredCallback.class);
3535

36-
private static final Map<Class<?>, Event<?>> CALLBACKS = new IdentityHashMap<>();
36+
private static final Map<String, Event<?>> CALLBACKS = new HashMap<>();
3737

3838
@SuppressWarnings("unchecked")
39-
public static <C> Event<CapabilityRegisteredCallback<C>> getOrCreateEvent(Class<C> type) {
39+
public static <C> Event<CapabilityRegisteredCallback<C>> getOrCreateEvent(String type) {
4040
return (Event<CapabilityRegisteredCallback<C>>) CALLBACKS.computeIfAbsent(type, $ -> EventFactory.createArrayBacked(CapabilityRegisteredCallback.class, capability -> { }, callbacks -> capability -> {
4141
boolean error = false;
4242
Throwable throwable = new Throwable();
@@ -51,7 +51,7 @@ public static <C> Event<CapabilityRegisteredCallback<C>> getOrCreateEvent(Class<
5151
}
5252

5353
if (error) {
54-
LOGGER.error("An uncaught exception was thrown while processing a CapabilityRegisteredCallback<{}>", type.getName(), throwable);
54+
LOGGER.error("An uncaught exception was thrown while processing a CapabilityRegisteredCallback<{}>", type, throwable);
5555
}
5656
}));
5757
}

0 commit comments

Comments
 (0)