|
| 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