Add ThingPickerManager.
This little nugget is what we will wire up in the main plugin class once we're ready to introduce it to the code base for real. Its purpose is similar to that of the ThingManager, in that it _is_ a parser and can be passed around wherever a parser is needed, but it also is the main entry point for anything that is ThingPickerParser instances.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package com.garbagemule.MobArena.things;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ThingPickerManager implements ThingPickerParser {
|
||||
|
||||
private final List<ThingPickerParser> parsers;
|
||||
private final ThingParser things;
|
||||
|
||||
public ThingPickerManager(ThingParser things) {
|
||||
this.parsers = new ArrayList<>();
|
||||
this.things = things;
|
||||
}
|
||||
|
||||
public void register(ThingPickerParser parser) {
|
||||
parsers.add(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThingPicker parse(String s) {
|
||||
for (ThingPickerParser parser : parsers) {
|
||||
ThingPicker picker = parser.parse(s);
|
||||
if (picker != null) {
|
||||
return picker;
|
||||
}
|
||||
}
|
||||
Thing thing = things.parse(s);
|
||||
return new SingleThingPicker(thing);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user