Skip to content

Instantly share code, notes, and snippets.

@maxov
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxov/0489b33ff0a4ee0a82b7 to your computer and use it in GitHub Desktop.
Save maxov/0489b33ff0a4ee0a82b7 to your computer and use it in GitHub Desktop.
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