Last active
August 29, 2015 14:17
-
-
Save maxov/0489b33ff0a4ee0a82b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface DataManipulator { | |
void clear(); | |
void from(DataHolder holder); | |
} | |
interface DisplayNameData extends DataManipulator { | |
Optional<Message> getDisplayName(); | |
void setDisplayName(@Nullable Message displayName) | |
void clearDisplayName(); | |
} | |
interface DataHolder { | |
<T> Optional<T extends DataManipulator> obtain(Class<T> manipulatorClass); | |
boolean complies(Class<DataManipulator> manipulatorClass); | |
void accept(DataManipulator manipulator); | |
} | |
// Get an instance to a fresh DisplayNameData | |
DisplayNameData data = DataManipulators.obtain(DisplayNameData.class); | |
// or, if we want a data manipulator with fields already set to an item stack's data | |
DisplayNameData data = myItemStack.obtain(DisplayNameData.class); | |
data.setDisplayName(Messages.of("new name")); | |
myItemStack.accept(data); | |
myOtherItemStack.accept(data); | |
data.setDisplayName(Messages.of("other new name")); | |
myItemStack.accept(data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment