Package baritone.api.command.registry
Class Registry<V>
java.lang.Object
baritone.api.command.registry.Registry<V>
- Type Parameters:
V- The entry type that will be stored in this registry. This can be anything, really - preferably anything that works as a HashMap key, as that's what's used to keep track of which entries are registered or not.
This registry class allows for registration and unregistration of a certain type. This is mainly designed for use by
event handlers where newly registered ones are encountered first during iteration and can therefore override older
ones. In Baritone, this is used for commands and argument parsers so that mods and addons can extend Baritone's
functionality without resorting to hacks, wrappers, or mixins.
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal Collection<V> The collection of entries that are currently in this registry. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns an iterator that iterates over each entry in this registry, in the order they were added.Returns a stream that returns each entry in this registry, in the order they were added.iterator()Returns an iterator that iterates over each entry in this registry, with the newest elements iterated over first.booleanEnsures that the entryentryis registered.booleanregistered(V entry) stream()Returns a stream that contains each entry in this registry, with the newest elements ordered first.voidunregister(V entry) Unregisters this entry from this registry.
-
Field Details
-
entries
The collection of entries that are currently in this registry. This is a collection (and not a list) because, internally, entries are stored in a linked list, which is not the same as a normal list.
-
-
Constructor Details
-
Registry
public Registry()
-
-
Method Details
-
registered
- Parameters:
entry- The entry to check.- Returns:
- If this entry is currently registered in this registry.
-
register
Ensures that the entryentryis registered.- Parameters:
entry- The entry to register.- Returns:
- A boolean indicating whether or not this is a new registration. No matter the value of this boolean, the entry is always guaranteed to now be in this registry. This boolean simply indicates if the entry was not in the map prior to this method call.
-
unregister
Unregisters this entry from this registry. After this method call, the entry is guaranteed to be removed from the registry, since each entry only ever appears once.- Parameters:
entry- The entry to unregister.
-
iterator
Returns an iterator that iterates over each entry in this registry, with the newest elements iterated over first. Internally, as new elements are prepended to the registry rather than appended to the end, this order is the best way to search through the registry if you want to discover newer items first. -
descendingIterator
Returns an iterator that iterates over each entry in this registry, in the order they were added. Internally, this iterates through the registry backwards, as new elements are prepended to the registry rather than appended to the end. You should only do this when you need to, for example, list elements in order - it is almost always fine to simply useforEachon theentriescollection instead. -
stream
Returns a stream that contains each entry in this registry, with the newest elements ordered first. Internally, as new elements are prepended to the registry rather than appended to the end, this order is the best way to search through the registry if you want to discover newer items first. -
descendingStream
Returns a stream that returns each entry in this registry, in the order they were added. Internally, this orders the registry backwards, as new elements are prepended to the registry rather than appended to the end. You should only use this when you need to, for example, list elements in order - it is almost always fine to simply use the regularstream()method instead.
-