Make Thing extend ThingPicker.

By turning things into their own thing pickers, we can avoid creating a
bunch of SingleThingPicker wrappers, which are now redundant. Because
the semantics of using things and thing pickers are quite different, it
does perhaps make it necessary to be a bit more careful about picking
the right type.
This commit is contained in:
Andreas Troelsen 2021-08-06 14:42:15 +02:00
parent 1c225d93f9
commit 52226fa1c9
3 changed files with 11 additions and 24 deletions

View File

@ -1,21 +0,0 @@
package com.garbagemule.MobArena.things;
public class SingleThingPicker implements ThingPicker {
private final Thing thing;
public SingleThingPicker(Thing thing) {
this.thing = thing;
}
@Override
public Thing pick() {
return thing;
}
@Override
public String toString() {
return thing.toString();
}
}

View File

@ -12,8 +12,12 @@ import org.bukkit.entity.Player;
* The interface exposes three methods that are all optional operations. An
* operation returns false if it fails or if it isn't applicable to the given
* thing (which is the same as failing).
* <p>
* A thing is automatically a {@link ThingPicker} for itself, which means it
* can be used in any place that a thing picker is expected, avoiding the need
* to wrap things in a "dummy picker".
*/
public interface Thing {
public interface Thing extends ThingPicker {
/**
* Give this thing to the given player.
@ -39,4 +43,9 @@ public interface Thing {
*/
boolean heldBy(Player player);
@Override
default Thing pick() {
return this;
}
}

View File

@ -25,8 +25,7 @@ public class ThingPickerManager implements ThingPickerParser {
return picker;
}
}
Thing thing = things.parse(s);
return new SingleThingPicker(thing);
return things.parse(s);
}
}