Skip to content

Commit d11b2ac

Browse files
committed
[PlaybackController] Added playback metadata registry
1 parent f28cc1f commit d11b2ac

File tree

5 files changed

+79
-6
lines changed

5 files changed

+79
-6
lines changed

src/main/java/com/minecrafttas/mctcommon/events/EventListenerRegistry.java

+14
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ public static void register(EventBase eventListener) {
9595
}
9696
}
9797

98+
/**
99+
* Registers multiple objects to be an event listener. The objects must implement an event extending {@link EventBase}
100+
* @param eventListeners The event listeners to register
101+
*/
98102
public static void register(EventBase... eventListeners) {
99103
for(EventBase eventListener : eventListeners) {
100104
register(eventListener);
@@ -122,6 +126,16 @@ public static void unregister(EventBase eventListener) {
122126
}
123127
}
124128
}
129+
130+
/**
131+
* Unregisters multiple objects from being an event listener.
132+
* @param eventListener The event listeners to unregister
133+
*/
134+
public static void unregister(EventBase... eventListeners) {
135+
for(EventBase eventListener : eventListeners) {
136+
unregister(eventListener);
137+
}
138+
}
125139

126140
/**
127141
* Fires an event without parameters

src/main/java/com/minecrafttas/mctcommon/server/PacketHandlerRegistry.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static void unregister(PacketHandlerBase handler) {
4141
if (REGISTRY.contains(handler)) {
4242
REGISTRY.remove(handler);
4343
} else {
44-
MCTCommon.LOGGER.warn("Trying to unregister packet handler {}, but is was not registered!", handler.getClass().getName());
44+
MCTCommon.LOGGER.warn("Trying to unregister packet handler {}, but it was not registered!", handler.getClass().getName());
4545
}
4646
}
4747

src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java

-3
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,14 @@
1717
import com.minecrafttas.tasmod.TASmod;
1818
import com.minecrafttas.tasmod.TASmodClient;
1919
import com.minecrafttas.tasmod.events.EventClient.EventDrawHotbar;
20-
import com.minecrafttas.tasmod.handlers.InterpolationHandler;
2120
import com.minecrafttas.tasmod.monitoring.DesyncMonitoring;
2221
import com.minecrafttas.tasmod.playback.ControlByteHandler;
2322
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate;
24-
import com.minecrafttas.tasmod.util.TrajectoriesCalculator;
2523
import com.mojang.realmsclient.gui.ChatFormatting;
2624

2725
import net.minecraft.client.Minecraft;
2826
import net.minecraft.client.gui.GuiScreen;
2927
import net.minecraft.client.gui.ScaledResolution;
30-
import net.minecraft.util.math.Vec3d;
3128

3229
/**
3330
* The info hud is a hud that is always being rendered ontop of the screen, it can show some stuff such as coordinates, etc.,

src/main/java/com/minecrafttas/tasmod/playback/PlaybackMetadata.java src/main/java/com/minecrafttas/tasmod/playback/metadata/PlaybackMetadata.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.minecrafttas.tasmod.playback;
1+
package com.minecrafttas.tasmod.playback.metadata;
22

33
import java.util.LinkedHashMap;
44
import java.util.Properties;
@@ -16,5 +16,6 @@ public PlaybackMetadata() {
1616
this.metadata = new LinkedHashMap<>();
1717
}
1818

19-
19+
public void setValue(String category, String key, String value) {
20+
}
2021
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.minecrafttas.tasmod.playback.metadata;
2+
3+
import java.util.ArrayList;
4+
5+
import com.minecrafttas.mctcommon.MCTCommon;
6+
7+
public class PlaybackMetadataRegistry {
8+
9+
private static final ArrayList<PlaybackMetadataExtension> METADATA_EXTENSION = new ArrayList<>();
10+
11+
public static void register(PlaybackMetadataExtension extension) {
12+
if(extension==null) {
13+
throw new NullPointerException("Tried to register a playback extension with value null");
14+
}
15+
16+
if(containsClass(extension)) {
17+
MCTCommon.LOGGER.warn("Trying to register the playback extension {}, but another instance of this class is already registered!", extension.getClass().getName());
18+
return;
19+
}
20+
21+
if (!METADATA_EXTENSION.contains(extension)) {
22+
METADATA_EXTENSION.add(extension);
23+
} else {
24+
MCTCommon.LOGGER.warn("Trying to register the playback extension {}, but it is already registered!", extension.getClass().getName());
25+
}
26+
}
27+
28+
public static void unregister(PlaybackMetadataExtension extension) {
29+
if(extension==null) {
30+
throw new NullPointerException("Tried to unregister an extension with value null");
31+
}
32+
if (METADATA_EXTENSION.contains(extension)) {
33+
METADATA_EXTENSION.remove(extension);
34+
} else {
35+
MCTCommon.LOGGER.warn("Trying to unregister the playback extension {}, but it was not registered!", extension.getClass().getName());
36+
}
37+
}
38+
39+
public static PlaybackMetadata handleOnLoad() {
40+
return null; //TODO implement
41+
}
42+
43+
public static void handleOnStore(PlaybackMetadata metadata) {
44+
//TODO
45+
}
46+
47+
private static boolean containsClass(PlaybackMetadataExtension newExtension) {
48+
for(PlaybackMetadataExtension extension : METADATA_EXTENSION) {
49+
if(extension.getClass().equals(newExtension.getClass())) {
50+
return true;
51+
}
52+
}
53+
return false;
54+
}
55+
56+
public static interface PlaybackMetadataExtension {
57+
public PlaybackMetadata onStore();
58+
59+
public void onLoad(PlaybackMetadata metadata);
60+
}
61+
}

0 commit comments

Comments
 (0)