- Removed Wrapper.java (unnecessary wrapper class which did unnecessary things)
- Removed Validate.java (BooleanSupplier)

- Changed how CommandLoader.Registry works, now uses ReflectionTools instead.
- Renamed Action to ClickAction to be more specific with what it does
- Added JavaDocs to ClickAction and IGUI, more to follow soon

💯
This commit is contained in:
Paldiu 2021-03-02 18:30:55 -06:00
parent 5490213609
commit 628b87bfc1
12 changed files with 171 additions and 180 deletions

View File

@ -1,6 +1,6 @@
package io.github.simplexdev.api; package io.github.simplexdev.api;
import io.github.simplexdev.api.func.Action; import io.github.simplexdev.api.func.ClickAction;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
@ -11,24 +11,79 @@ import org.jetbrains.annotations.Nullable;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
/**
* An interface which supplies customizable inventory GUI instances.
*/
public interface IGUI { public interface IGUI {
/**
* @return UUID of the inventory provided by the interface instance.
*/
UUID getInvUUId(); UUID getInvUUId();
/**
* The actual inventory provided by the interface instance.
* @return the inventory which is provided by the interface instance.
*/
Inventory getInventory(); Inventory getInventory();
void setItem(int slot, @NotNull ItemStack stack, @Nullable Action action); /**
* Sets the item for the defined slot to the specified item stack.
* You may define an action to run when the player clicks on the inventory slot,
* however it is not required; you may also pass null to the clickAction parameter.
* @param slot The inventory slot to set; remember that arrays start at 0, so
* an inventory size of 9 will range from 0 to 8.
* @param stack The item to display in the slot. This can be Material.AIR.
* @param clickAction The action to perform when a player clicks the inventory slot.
* This may be null.
*/
void setItem(int slot, @NotNull ItemStack stack, @Nullable ClickAction clickAction);
/**
* Sets the item for the defined slot to the specified item stack.
* This method should automatically define the slot action as null.
* @param slot The inventory slot to set; remember that arrays start at 0, so
* an inventory size of 9 will range from 0 to 8.
* @param stack The item to display in the slot. This can be Material.AIR.
*/
void setItem(int slot, @NotNull ItemStack stack); void setItem(int slot, @NotNull ItemStack stack);
/**
* Force a player to open the inventory provided by the interface instance.
* @param player The player to open the inventory on.
*/
void open(@NotNull Player player); void open(@NotNull Player player);
/**
* Force a player to close the inventory provided by the interface instance.
* @param player The player to close the inventory on.
*/
void close(@NotNull Player player); void close(@NotNull Player player);
/**
* Delete the inventory provided by the interface instance.
*/
void delete(); void delete();
Map<Integer, Action> getActions(); /**
* @return A map containing each inventory slot and their respective actions,
* but only if the slot actually has an action.
*/
Map<Integer, ClickAction> getActions();
/**
* Creates a new ItemStack instance to place in the inventory provided by the interface instance.
* @param material The item material
* @param name The name of the item
* @param lore Optional item descriptions
* @return The newly created item
*/
ItemStack newItem(@NotNull Material material, @NotNull String name, String... lore); ItemStack newItem(@NotNull Material material, @NotNull String name, String... lore);
/**
* Creates a new ItemStack instance to place in the inventory provided by the interface instance.
* @param material The item material
* @param name The name of the item
* @return The newly created item with no lore.
*/
ItemStack newItem(@NotNull Material material, @NotNull String name); ItemStack newItem(@NotNull Material material, @NotNull String name);
} }

View File

@ -1,8 +0,0 @@
package io.github.simplexdev.api.func;
import org.bukkit.entity.Player;
@FunctionalInterface
public interface Action {
void onClick(Player player);
}

View File

@ -0,0 +1,17 @@
package io.github.simplexdev.api.func;
import org.bukkit.entity.Player;
/**
* Functional interface which provides an action to execute
* when a player clicks on an {@link io.github.simplexdev.api.IGUI} provided inventory slot.
*/
@FunctionalInterface
public interface ClickAction {
/**
* Returns a void when a player clicks on an
* inventory slot provided by the GUI class for the GUIListener.
* @param player The player who interacted with the inventory slot.
*/
void onClick(Player player);
}

View File

@ -1,6 +0,0 @@
package io.github.simplexdev.api.func;
@FunctionalInterface
public interface Validate {
boolean isValid();
}

View File

@ -1,38 +1,37 @@
package io.github.simplexdev.simplexcore.chat; package io.github.simplexdev.simplexcore.chat;
import io.github.simplexdev.simplexcore.utils.Wrapper;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public final class ChatUtils { public final class ChatUtils {
protected final Wrapper<? extends CommandSender> target; protected final CommandSender target;
protected final TextComponentFactory factory = new TextComponentFactory(); protected final TextComponentFactory factory = new TextComponentFactory();
private ChatUtils(Wrapper<? extends CommandSender> target) { private <T extends CommandSender> ChatUtils(T target) {
this.target = target; this.target = target;
} }
public static <T extends CommandSender> ChatUtils target(T target) { public static <T extends CommandSender> ChatUtils target(T target) {
return new ChatUtils(Wrapper.of(target)); return new ChatUtils(target);
} }
public void msg(String message) { public void msg(String message) {
target.get().sendMessage(message); target.sendMessage(message);
} }
public void msg(TextComponent component) { public void msg(TextComponent component) {
target.get().sendMessage(component); target.sendMessage(component);
} }
public void err(Messages message) { public void err(Messages message) {
target.get().sendMessage(message.getMessage()); target.sendMessage(message.getMessage());
} }
public void color(String message) { public void color(String message) {
target.get().sendMessage(factory.colorize(message)); target.sendMessage(factory.colorize(message));
} }
public void color(TextComponent component) { public void color(TextComponent component) {
target.get().sendMessage(factory.colorize(component.getText())); target.sendMessage(factory.colorize(component.getText()));
} }
} }

View File

@ -3,6 +3,7 @@ package io.github.simplexdev.simplexcore.command;
import io.github.simplexdev.api.annotations.CommandInfo; import io.github.simplexdev.api.annotations.CommandInfo;
import io.github.simplexdev.simplexcore.command.defaults.DefaultCommand; import io.github.simplexdev.simplexcore.command.defaults.DefaultCommand;
import io.github.simplexdev.simplexcore.utils.Constants; import io.github.simplexdev.simplexcore.utils.Constants;
import io.github.simplexdev.simplexcore.utils.ReflectionTools;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.*; import org.bukkit.command.*;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -13,7 +14,6 @@ import org.reflections.Reflections;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map; import java.util.Map;
import java.util.MissingResourceException; import java.util.MissingResourceException;
@ -52,7 +52,7 @@ public final class CommandLoader {
PluginCommand objectToRegister = Registry.create(Constants.getPlugin(), info.name().toLowerCase()); PluginCommand objectToRegister = Registry.create(Constants.getPlugin(), info.name().toLowerCase());
objectToRegister.setAliases(Arrays.asList(info.aliases().split(","))); objectToRegister.setAliases(Arrays.asList(info.aliases().split(",")));
objectToRegister.setDescription(info.description()); objectToRegister.setDescription(info.description());
objectToRegister.setExecutor(getFromSetName(info.name())); objectToRegister.setExecutor(getExecutorFromName(info.name()));
objectToRegister.setLabel(info.name().toLowerCase()); objectToRegister.setLabel(info.name().toLowerCase());
objectToRegister.setPermission(info.permission()); objectToRegister.setPermission(info.permission());
objectToRegister.setPermissionMessage(info.permissionMessage()); objectToRegister.setPermissionMessage(info.permissionMessage());
@ -62,7 +62,7 @@ public final class CommandLoader {
}); });
} }
public synchronized CommandExecutor getFromSetName(String name) { public synchronized CommandExecutor getExecutorFromName(String name) {
for (Class<? extends CommandExecutor> obj : reflections.getSubTypesOf(CommandExecutor.class)) { for (Class<? extends CommandExecutor> obj : reflections.getSubTypesOf(CommandExecutor.class)) {
if (!obj.isAnnotationPresent(CommandInfo.class)) { if (!obj.isAnnotationPresent(CommandInfo.class)) {
throw new RuntimeException("Missing annotation CommandInfo!"); throw new RuntimeException("Missing annotation CommandInfo!");
@ -73,8 +73,9 @@ public final class CommandLoader {
if (name.equalsIgnoreCase(info.name())) { if (name.equalsIgnoreCase(info.name())) {
try { try {
Constructor<? extends CommandExecutor> constr = obj.getDeclaredConstructor(); Constructor<? extends CommandExecutor> constr = obj.getDeclaredConstructor();
constr.setAccessible(true);
return constr.newInstance(); return constr.newInstance();
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) { } catch (ReflectiveOperationException ignored) {
return new DefaultCommand(); return new DefaultCommand();
} }
} }
@ -93,8 +94,9 @@ public final class CommandLoader {
if (name.equalsIgnoreCase(info.name())) { if (name.equalsIgnoreCase(info.name())) {
try { try {
Constructor<? extends TabCompleter> constr = obj.getDeclaredConstructor(); Constructor<? extends TabCompleter> constr = obj.getDeclaredConstructor();
constr.setAccessible(true);
return constr.newInstance(); return constr.newInstance();
} catch (NoSuchMethodException | InstantiationException | InvocationTargetException | IllegalAccessException e) { } catch (ReflectiveOperationException ignored) {
return new DefaultCommand(); return new DefaultCommand();
} }
} }
@ -108,40 +110,13 @@ public final class CommandLoader {
private static final Field knownCmdsField; private static final Field knownCmdsField;
static { static {
Constructor<PluginCommand> temp; constructor = ReflectionTools.getDeclaredConstructor(PluginCommand.class, String.class, Plugin.class);
try { cmdMapField = ReflectionTools.getDeclaredField(SimplePluginManager.class, "commandMap");
temp = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class); knownCmdsField = ReflectionTools.getDeclaredField(SimpleCommandMap.class, "knownCommands");
temp.setAccessible(true);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
constructor = temp;
Field cmf;
try {
cmf = SimplePluginManager.class.getDeclaredField("commandMap");
cmf.setAccessible(true);
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
}
cmdMapField = cmf;
Field kcf;
try {
kcf = SimpleCommandMap.class.getDeclaredField("knownCommands");
kcf.setAccessible(true);
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
}
knownCmdsField = kcf;
} }
public static PluginCommand create(@NotNull Plugin plugin, @NotNull String name) { public static PluginCommand create(@NotNull Plugin plugin, @NotNull String name) {
try { return ReflectionTools.initConstructor(constructor, name, plugin);
return constructor.newInstance(name, plugin);
} catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
throw new RuntimeException(e);
}
} }
public static void registerCommand(PluginCommand command) { public static void registerCommand(PluginCommand command) {

View File

@ -1,6 +1,6 @@
package io.github.simplexdev.simplexcore.gui; package io.github.simplexdev.simplexcore.gui;
import io.github.simplexdev.api.func.Action; import io.github.simplexdev.api.func.ClickAction;
import io.github.simplexdev.api.IGUI; import io.github.simplexdev.api.IGUI;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
@ -16,7 +16,7 @@ import java.util.*;
public abstract class AbstractGUI implements InventoryHolder, IGUI { public abstract class AbstractGUI implements InventoryHolder, IGUI {
private final Inventory INV; private final Inventory INV;
private final Map<Integer, Action> actions; private final Map<Integer, ClickAction> actions;
private final UUID uuid; private final UUID uuid;
private final List<Integer> validSize = new ArrayList<>(){{ private final List<Integer> validSize = new ArrayList<>(){{
@ -53,10 +53,10 @@ public abstract class AbstractGUI implements InventoryHolder, IGUI {
} }
@Override @Override
public void setItem(int slot, @NotNull ItemStack stack, @Nullable Action action) { public void setItem(int slot, @NotNull ItemStack stack, @Nullable ClickAction clickAction) {
INV.setItem(slot, stack); INV.setItem(slot, stack);
if (action != null) { if (clickAction != null) {
actions.put(slot, action); actions.put(slot, clickAction);
} }
} }
@ -97,7 +97,7 @@ public abstract class AbstractGUI implements InventoryHolder, IGUI {
} }
@Override @Override
public Map<Integer, Action> getActions() { public Map<Integer, ClickAction> getActions() {
return actions; return actions;
} }

View File

@ -1,7 +1,9 @@
package io.github.simplexdev.simplexcore.gui; package io.github.simplexdev.simplexcore.gui;
import io.github.simplexdev.api.func.Action; import io.github.simplexdev.api.func.ClickAction;
import io.github.simplexdev.api.IGUI; import io.github.simplexdev.api.IGUI;
import io.github.simplexdev.simplexcore.listener.SimplexListener;
import io.github.simplexdev.simplexcore.plugin.SimplexAddon;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@ -11,7 +13,11 @@ import org.bukkit.event.inventory.InventoryCloseEvent;
import java.util.UUID; import java.util.UUID;
public final class GUIHandler implements Listener { public final class GUIHandler extends SimplexListener {
public GUIHandler(SimplexAddon<?> plugin) {
register(this, plugin);
}
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void invClick(InventoryClickEvent event) { public void invClick(InventoryClickEvent event) {
if (!(event.getWhoClicked() instanceof Player)) { if (!(event.getWhoClicked() instanceof Player)) {
@ -25,9 +31,9 @@ public final class GUIHandler implements Listener {
if (invUUID != null) { if (invUUID != null) {
event.setCancelled(true); event.setCancelled(true);
IGUI gui = AbstractGUI.getInvByUUId().get(invUUID); IGUI gui = AbstractGUI.getInvByUUId().get(invUUID);
Action action = gui.getActions().get(event.getSlot()); ClickAction clickAction = gui.getActions().get(event.getSlot());
if (action != null) { if (clickAction != null) {
action.onClick(player); clickAction.onClick(player);
} }
} }
} }

View File

@ -1,6 +1,5 @@
package io.github.simplexdev.simplexcore.listener; package io.github.simplexdev.simplexcore.listener;
import io.github.simplexdev.api.func.Validate;
import io.github.simplexdev.simplexcore.utils.Constants; import io.github.simplexdev.simplexcore.utils.Constants;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@ -8,6 +7,7 @@ import org.bukkit.event.server.PluginEnableEvent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.BooleanSupplier;
public final class DependencyListener extends SimplexListener { public final class DependencyListener extends SimplexListener {
public List<String> PAPI_NAMES = new ArrayList<>() {{ public List<String> PAPI_NAMES = new ArrayList<>() {{
@ -30,14 +30,14 @@ public final class DependencyListener extends SimplexListener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void pluginRegister(PluginEnableEvent event) { public void pluginRegister(PluginEnableEvent event) {
Validate temp = () -> PLIB_NAMES.contains(event.getPlugin().getName()); BooleanSupplier temp = () -> PLIB_NAMES.contains(event.getPlugin().getName());
Validate temp2 = () -> PAPI_NAMES.contains(event.getPlugin().getName()); BooleanSupplier temp2 = () -> PAPI_NAMES.contains(event.getPlugin().getName());
if (temp.isValid()) { if (temp.getAsBoolean()) {
Constants.getPlugin().getInstances().getDependencyManager().registerProtocolLib(); Constants.getPlugin().getInstances().getDependencyManager().registerProtocolLib();
} }
if (temp2.isValid()) { if (temp2.getAsBoolean()) {
Constants.getPlugin().getInstances().getDependencyManager().registerPAPI(); Constants.getPlugin().getInstances().getDependencyManager().registerPAPI();
} }
} }

View File

@ -70,6 +70,10 @@ public class SignFactory {
@Nullable @Nullable
public IUsableSign addTagsToSign(Sign sign, Object... tags) { public IUsableSign addTagsToSign(Sign sign, Object... tags) {
if (getSignData() != null) { if (getSignData() != null) {
if (!SignData.getUnlabeledSigns().containsKey(sign)) {
createNoTag(sign);
}
AbstractSign abs = SignData.getUnlabeledSigns().get(sign); AbstractSign abs = SignData.getUnlabeledSigns().get(sign);
for (Object tag : tags) { for (Object tag : tags) {
if (tag instanceof VoidSupplier) { if (tag instanceof VoidSupplier) {
@ -126,10 +130,10 @@ public class SignFactory {
&& SIGN_TYPES.contains(event.getClickedBlock().getType())) { && SIGN_TYPES.contains(event.getClickedBlock().getType())) {
Sign sign = (Sign) event.getClickedBlock(); Sign sign = (Sign) event.getClickedBlock();
if (signMap.containsKey(sign)) { if (signMap.containsKey(sign)) {
IUsableSign isign = signMap.get(sign); IUsableSign iSign = signMap.get(sign);
String tag = isign.signTag(); String tag = iSign.signTag();
if (isign.getLines().get(0).equals(tag)) { if (iSign.getLines().get(0).equals(tag)) {
isign.execute(); iSign.execute();
} }
} }
} }

View File

@ -1,68 +1,95 @@
package io.github.simplexdev.simplexcore.utils; package io.github.simplexdev.simplexcore.utils;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.reflections.Reflections; import org.reflections.Reflections;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Objects;
import java.util.Set; import java.util.Set;
public final class ReflectionTools { public final class ReflectionTools {
public ReflectionTools() {
}
@NotNull @NotNull
public Reflections reflect(Class<?> loadFrom) { public static Reflections reflect(Class<?> loadFrom) {
return new Reflections(loadFrom.getName()); return new Reflections(loadFrom.getName());
} }
@NotNull @NotNull
public Set<Class<?>> getAnnotatedClasses(Class<?> loadFrom, Class<? extends Annotation> annotation) { public static Set<Class<?>> getAnnotatedClasses(Class<?> loadFrom, Class<? extends Annotation> annotation) {
return new Reflections(loadFrom.getName()).getTypesAnnotatedWith(annotation); return new Reflections(loadFrom.getName()).getTypesAnnotatedWith(annotation);
} }
@Nullable @Nullable
public Field getField(Class<?> cls, String name) { public static <T> Field getField(Class<T> cls, String name) {
try { try {
Field field = cls.getField(name); return asAccessible(cls.getField(name));
field.setAccessible(true);
return field;
} catch (NoSuchFieldException ignored) { } catch (NoSuchFieldException ignored) {
return null; return null;
} }
} }
@Nullable @Nullable
public Constructor<?> getConstructor(Class<?> cls, String name, Class<?>... initializers) { public static <T> Field getDeclaredField(Class<T> cls, String name) {
try { try {
return cls.getDeclaredConstructor(initializers); return asAccessible(cls.getDeclaredField(name));
} catch (ReflectiveOperationException ignored) {
return null;
}
}
@Nullable
public static <T> Constructor<T> getConstructor(Class<T> cls, Class<?>... initializers) {
try {
return asAccessible(cls.getConstructor(initializers));
} catch (NoSuchMethodException ignored) { } catch (NoSuchMethodException ignored) {
return null; return null;
} }
} }
@Nullable @Nullable
public Wrapper<?> initConstructor(Constructor<?> constructor, Object... initializers) { public static <T> Constructor<T> getDeclaredConstructor(Class<T> cls, Class<?>... initializers) {
try { try {
return Wrapper.of(constructor.newInstance(initializers)); return asAccessible(cls.getDeclaredConstructor(initializers));
} catch (InstantiationException | InvocationTargetException | IllegalAccessException e) { } catch (NoSuchMethodException ignored) {
return null; return null;
} }
} }
@Nullable @Nullable
public Method getMethod(Class<?> clazz, String name, Class<?>... params) { public static <T> T initConstructor(Constructor<? extends T> constructor, Object... initializers) {
try { try {
return Wrapper.of(clazz.getMethod(name, params)) return constructor.newInstance(initializers);
.perform(obj -> obj.setAccessible(true)) } catch (ReflectiveOperationException e) {
.get(); return null;
}
}
@Nullable
public static <T> Method getMethod(Class<T> clazz, String name, Class<?>... params) {
try {
return asAccessible(clazz.getMethod(name, params));
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
return null; return null;
} }
} }
@Nullable
public static <T> Method getDeclaredMethod(Class<T> clazz, String name, Class<?>... params) {
try {
return asAccessible(clazz.getDeclaredMethod(name, params));
} catch (ReflectiveOperationException ignored) {
return null;
}
}
@NotNull
@Contract(pure = true)
public static <T extends AccessibleObject> T asAccessible(T object) {
object.setAccessible(true);
return object;
}
} }

View File

@ -1,78 +0,0 @@
package io.github.simplexdev.simplexcore.utils;
import io.github.simplexdev.api.func.VoidSupplier;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
public final class Wrapper<T> {
protected T bean;
private Wrapper(T bean) {
this.bean = bean;
}
public void set(T bean) {
this.bean = bean;
}
public T get() {
return bean;
}
@Override
public int hashCode() {
return new HashCodeBuilder().append(get()).toHashCode();
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Wrapper<?>)) {
return false;
}
if (obj == this) {
return true;
}
return new EqualsBuilder().append(((Wrapper<?>) obj).get(), get()).isEquals();
}
@Override
public String toString() {
return get().toString();
}
public static <T> Wrapper<T> of(T object) {
return new Wrapper<>(object);
}
public final <P> P as(Function<? super Wrapper<T>, P> function) {
return function.apply(this);
}
public final <R> Wrapper<R> flatMap(Function<? super T, ? extends Wrapper<? extends R>> function) {
return new Wrapper<>(function.apply(get()).get());
}
public final <R> Wrapper<R> map(Function<? super T, ? extends R> function) {
return new Wrapper<>(function.apply(get()));
}
public final Wrapper<T> perform(Consumer<? super T> consumer) {
consumer.accept(get());
return this;
}
public final Wrapper<T> then(VoidSupplier supplier) {
supplier.get();
return this;
}
public final Wrapper<T> filter(Predicate<? super T> predicate) {
return predicate.test(get()) ? this : null;
}
}