diff --git a/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/BotManager.java b/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/BotManager.java index 428fed95..4d5abb7b 100644 --- a/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/BotManager.java +++ b/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/BotManager.java @@ -40,11 +40,10 @@ public interface BotManager { /** * Register a custom bot action. * - * @param name action name * @param action action executor * @return true if success, or false */ - boolean registerCustomBotAction(String name, CustomBotAction action); + boolean registerCustomBotAction(CustomBotAction action); /** * Unregister a custom bot action. diff --git a/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/action/AbstractCustomBotAction.java b/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/action/AbstractCustomBotAction.java new file mode 100644 index 00000000..20599568 --- /dev/null +++ b/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/action/AbstractCustomBotAction.java @@ -0,0 +1,54 @@ +package org.leavesmc.leaves.entity.bot.action; + +import java.util.UUID; +import java.util.function.Consumer; + +public abstract class AbstractCustomBotAction implements BotAction, CustomBotAction { + private boolean cancelled = false; + private Consumer onFail = null, onSuccess = null, onStop = null; + + @Override + public final UUID getUUID() { + throw new UnsupportedOperationException("getUUID() is not supported in CustomBotAction"); + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setOnFail(Consumer onFail) { + this.onFail = onFail; + } + + @Override + public Consumer getOnFail() { + return onFail; + } + + @Override + public void setOnSuccess(Consumer onSuccess) { + this.onSuccess = onSuccess; + } + + @Override + public Consumer getOnSuccess() { + return onSuccess; + } + + @Override + public void setOnStop(Consumer onStop) { + this.onStop = onStop; + } + + @Override + public Consumer getOnStop() { + return onStop; + } +} diff --git a/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/action/AbstractCustomStateBotAction.java b/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/action/AbstractCustomStateBotAction.java new file mode 100644 index 00000000..6bda788d --- /dev/null +++ b/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/action/AbstractCustomStateBotAction.java @@ -0,0 +1,54 @@ +package org.leavesmc.leaves.entity.bot.action; + +import java.util.UUID; +import java.util.function.Consumer; + +public abstract class AbstractCustomStateBotAction implements StateBotAction, CustomBotAction { + private boolean cancelled = false; + private Consumer onFail = null, onSuccess = null, onStop = null; + + @Override + public final UUID getUUID() { + throw new UnsupportedOperationException("getUUID() is not supported in CustomBotAction"); + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setOnFail(Consumer onFail) { + this.onFail = onFail; + } + + @Override + public Consumer getOnFail() { + return onFail; + } + + @Override + public void setOnSuccess(Consumer onSuccess) { + this.onSuccess = onSuccess; + } + + @Override + public Consumer getOnSuccess() { + return onSuccess; + } + + @Override + public void setOnStop(Consumer onStop) { + this.onStop = onStop; + } + + @Override + public Consumer getOnStop() { + return onStop; + } +} diff --git a/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/action/AbstractCustomTimerBotAction.java b/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/action/AbstractCustomTimerBotAction.java new file mode 100644 index 00000000..b2e61756 --- /dev/null +++ b/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/action/AbstractCustomTimerBotAction.java @@ -0,0 +1,95 @@ +package org.leavesmc.leaves.entity.bot.action; + +import java.util.UUID; +import java.util.function.Consumer; + +public abstract class AbstractCustomTimerBotAction implements TimerBotAction, CustomBotAction { + private boolean cancelled = false; + private int startDelayTick = 0, doIntervalTick = 0, doNumber = 0; + private Consumer onFail = null, onSuccess = null, onStop = null; + + @Override + public final UUID getUUID() { + throw new UnsupportedOperationException("getUUID() is not supported in CustomTimerBotAction"); + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setOnFail(Consumer onFail) { + this.onFail = onFail; + } + + @Override + public Consumer getOnFail() { + return onFail; + } + + @Override + public void setOnSuccess(Consumer onSuccess) { + this.onSuccess = onSuccess; + } + + @Override + public Consumer getOnSuccess() { + return onSuccess; + } + + @Override + public void setOnStop(Consumer onStop) { + this.onStop = onStop; + } + + @Override + public Consumer getOnStop() { + return onStop; + } + + @Override + public void setStartDelayTick(int delayTick) { + this.startDelayTick = delayTick; + } + + @Override + public int getStartDelayTick() { + return startDelayTick; + } + + @Override + public void setDoIntervalTick(int intervalTick) { + this.doIntervalTick = intervalTick; + } + + @Override + public int getDoIntervalTick() { + return doIntervalTick; + } + + @Override + public void setDoNumber(int doNumber) { + this.doNumber = doNumber; + } + + @Override + public int getDoNumber() { + return doNumber; + } + + @Override + public int getTickToNext() { + return startDelayTick; + } + + @Override + public int getDoNumberRemaining() { + return doNumber; + } +} diff --git a/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/action/CustomBotAction.java b/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/action/CustomBotAction.java index 713cbc0f..f751e819 100644 --- a/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/action/CustomBotAction.java +++ b/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/action/CustomBotAction.java @@ -7,10 +7,11 @@ import org.leavesmc.leaves.entity.bot.Bot; import java.util.List; + /** * Represents a class which contains methods for a custom bot action */ -public interface CustomBotAction extends BotAction { +public interface CustomBotAction extends BotAction { /** * Executes the action, returning its success. @@ -27,7 +28,7 @@ public interface CustomBotAction extends BotAction { * @param args passed action arguments * @return a new action instance with given args */ - @Nullable CustomBotAction getNew(@Nullable Player player, String[] args); + @Nullable T getNew(@Nullable Player player, String[] args); /** * Requests a list of possible completions for a action argument. diff --git a/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/action/CustomStateBotAction.java b/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/action/CustomStateBotAction.java deleted file mode 100644 index f3807f64..00000000 --- a/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/action/CustomStateBotAction.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.leavesmc.leaves.entity.bot.action; - -public interface CustomStateBotAction extends StateBotAction { - - /** - * Executes the action, returning its success. - * - * @param bot bot of the action - * @return true if once action finish, otherwise false - */ - boolean doTick(org.leavesmc.leaves.entity.bot.Bot bot); - - /** - * Created a new action instance. - * - * @param player player who create this action - * @param args passed action arguments - * @return a new action instance with given args - */ - @org.jetbrains.annotations.Nullable CustomStateBotAction getNew(@org.jetbrains.annotations.Nullable org.bukkit.entity.Player player, String[] args); - - /** - * Requests a list of possible completions for a action argument. - * - * @return A List of a List of possible completions for the argument. - */ - @org.jetbrains.annotations.NotNull java.util.List> getTabComplete(); -} diff --git a/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/action/CustomTimerBotAction.java b/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/action/CustomTimerBotAction.java deleted file mode 100644 index 78b903ed..00000000 --- a/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/action/CustomTimerBotAction.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.leavesmc.leaves.entity.bot.action; - -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.leavesmc.leaves.entity.bot.Bot; - -import java.util.List; - -/** - * Represents a class which contains methods for a custom timer bot action - */ -public interface CustomTimerBotAction extends TimerBotAction { - - /** - * Executes the action, returning its success. - * - * @param bot bot of the action - * @return true if once action finish, otherwise false - */ - boolean doTick(Bot bot); - - /** - * Created a new action instance. - * - * @param player player who create this action - * @param args passed action arguments - * @return a new action instance with given args - */ - @Nullable CustomTimerBotAction getNew(@Nullable Player player, String[] args); - - /** - * Requests a list of possible completions for a action argument. - * - * @return A List of a List of possible completions for the argument. - */ - @NotNull List> getTabComplete(); -} diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/CraftCustomAction.java b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/CraftCustomAction.java index a3411668..31c90deb 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/CraftCustomAction.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/CraftCustomAction.java @@ -4,5 +4,5 @@ import org.bukkit.entity.Player; import org.jetbrains.annotations.Nullable; public interface CraftCustomAction { - public E createCraft(@Nullable Player player, String[] args); + E createCraft(@Nullable Player player, String[] args); } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/CraftCustomBotAction.java b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/CraftCustomBotAction.java index a405176a..de843d67 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/CraftCustomBotAction.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/CraftCustomBotAction.java @@ -5,20 +5,20 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.leavesmc.leaves.bot.ServerBot; import org.leavesmc.leaves.command.CommandArgument; -import org.leavesmc.leaves.entity.bot.action.CustomBotAction; +import org.leavesmc.leaves.entity.bot.action.AbstractCustomBotAction; -public class CraftCustomBotAction extends CraftBotAction implements CraftCustomAction { +public class CraftCustomBotAction extends CraftBotAction implements CraftCustomAction { - private final CustomBotAction realAction; + private final AbstractCustomBotAction realAction; - public CraftCustomBotAction(String name, @NotNull CustomBotAction realAction) { + public CraftCustomBotAction(String name, @NotNull AbstractCustomBotAction realAction) { super(name, CommandArgument.EMPTY, null); this.realAction = realAction; } @Override public CraftCustomBotAction createCraft(@Nullable Player player, String[] args) { - CustomBotAction newRealAction = realAction.getNew(player, args); + AbstractCustomBotAction newRealAction = realAction.getNew(player, args); if (newRealAction != null) { return new CraftCustomBotAction(this.getName(), newRealAction); } @@ -31,7 +31,7 @@ public class CraftCustomBotAction extends CraftBotAction implem } @Override - public Class getInterfaceClass() { + public Class getInterfaceClass() { return null; } } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/CraftCustomStateBotAction.java b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/CraftCustomStateBotAction.java index d17ad4a3..05b705db 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/CraftCustomStateBotAction.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/CraftCustomStateBotAction.java @@ -5,20 +5,20 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.leavesmc.leaves.bot.ServerBot; import org.leavesmc.leaves.command.CommandArgument; -import org.leavesmc.leaves.entity.bot.action.CustomStateBotAction; +import org.leavesmc.leaves.entity.bot.action.AbstractCustomStateBotAction; -public class CraftCustomStateBotAction extends CraftStateBotAction implements CraftCustomAction { +public class CraftCustomStateBotAction extends CraftStateBotAction implements CraftCustomAction { - private final CustomStateBotAction realAction; + private final AbstractCustomStateBotAction realAction; - public CraftCustomStateBotAction(String name, @NotNull CustomStateBotAction realAction) { + public CraftCustomStateBotAction(String name, @NotNull AbstractCustomStateBotAction realAction) { super(name, CommandArgument.EMPTY, null); this.realAction = realAction; } @Override public CraftCustomStateBotAction createCraft(@Nullable Player player, String[] args) { - CustomStateBotAction newRealAction = realAction.getNew(player, args); + AbstractCustomStateBotAction newRealAction = realAction.getNew(player, args); if (newRealAction != null) { return new CraftCustomStateBotAction(this.getName(), newRealAction); } @@ -26,7 +26,7 @@ public class CraftCustomStateBotAction extends CraftStateBotAction getInterfaceClass() { + public Class getInterfaceClass() { return null; } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/CraftCustomTimerBotAction.java b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/CraftCustomTimerBotAction.java index ee6c60e8..9697b3c4 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/CraftCustomTimerBotAction.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/CraftCustomTimerBotAction.java @@ -4,47 +4,31 @@ import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.leavesmc.leaves.bot.ServerBot; -import org.leavesmc.leaves.command.CommandArgument; -import org.leavesmc.leaves.entity.bot.action.CustomTimerBotAction; +import org.leavesmc.leaves.entity.bot.action.AbstractCustomTimerBotAction; -public class CraftCustomTimerBotAction extends CraftTimerBotAction implements CraftCustomAction { +public class CraftCustomTimerBotAction extends CraftTimerBotAction implements CraftCustomAction { - private final CustomTimerBotAction realAction; + private final AbstractCustomTimerBotAction realAction; - public CraftCustomTimerBotAction(String name, @NotNull CustomTimerBotAction realAction) { - super(name, CommandArgument.EMPTY, null); + public CraftCustomTimerBotAction(String name, @NotNull AbstractCustomTimerBotAction realAction) { + super(name, null); this.realAction = realAction; } @Override - public Class getInterfaceClass() { + public Class getInterfaceClass() { return null; } @Override public CraftCustomTimerBotAction createCraft(@Nullable Player player, String[] args) { - CustomTimerBotAction newRealAction = realAction.getNew(player, args); + AbstractCustomTimerBotAction newRealAction = realAction.getNew(player, args); if (newRealAction != null) { return new CraftCustomTimerBotAction(this.getName(), newRealAction); } return null; } - @Override - public int getDoNumber() { - return realAction.getDoNumber(); - } - - @Override - public int getStartDelayTick() { - return realAction.getStartDelayTick(); - } - - @Override - public int getDoIntervalTick() { - return realAction.getDoIntervalTick(); - } - @Override public boolean doTick(@NotNull ServerBot bot) { return realAction.doTick(bot.getBukkitEntity()); diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/CraftStateBotAction.java b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/CraftStateBotAction.java index df1c1b56..68a4aa9e 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/CraftStateBotAction.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/CraftStateBotAction.java @@ -1,10 +1,6 @@ package org.leavesmc.leaves.bot.agent.actions; -import net.minecraft.server.level.ServerPlayer; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.leavesmc.leaves.command.CommandArgument; -import org.leavesmc.leaves.command.CommandArgumentResult; import org.leavesmc.leaves.entity.bot.action.StateBotAction; import java.util.function.Supplier; diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/entity/CraftBot.java b/leaves-server/src/main/java/org/leavesmc/leaves/entity/CraftBot.java index cc9e5364..7bc89710 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/entity/CraftBot.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/entity/CraftBot.java @@ -16,9 +16,9 @@ import org.leavesmc.leaves.bot.agent.actions.CraftCustomStateBotAction; import org.leavesmc.leaves.bot.agent.actions.CraftCustomTimerBotAction; import org.leavesmc.leaves.entity.bot.Bot; import org.leavesmc.leaves.entity.bot.action.BotAction; -import org.leavesmc.leaves.entity.bot.action.CustomBotAction; -import org.leavesmc.leaves.entity.bot.action.CustomStateBotAction; -import org.leavesmc.leaves.entity.bot.action.CustomTimerBotAction; +import org.leavesmc.leaves.entity.bot.action.AbstractCustomBotAction; +import org.leavesmc.leaves.entity.bot.action.AbstractCustomStateBotAction; +import org.leavesmc.leaves.entity.bot.action.AbstractCustomTimerBotAction; import org.leavesmc.leaves.event.bot.BotActionStopEvent; import org.leavesmc.leaves.event.bot.BotRemoveEvent; @@ -49,28 +49,48 @@ public class CraftBot extends CraftPlayer implements Bot { @SuppressWarnings("unchecked") @Override public > void addAction(@NotNull T action) { - CraftBotAction result; Supplier getRegAction = () -> (T) Actions.getForClass(action.getClass()); switch (action) { - case CustomBotAction act -> { + case AbstractCustomBotAction act -> { + CraftBotAction result; T regAction = getRegAction.get(); if (regAction == null) throw new IllegalStateException("Action " + action.getClass().getName() + " is not registered!"); result = new CraftCustomBotAction(regAction.getName(), act); + result.setCancelled(act.isCancelled()); + result.setOnFail(act.getOnFail()); + result.setOnSuccess(act.getOnSuccess()); + result.setOnStop(act.getOnStop()); + this.getHandle().addBotAction(result, null); } - case CustomTimerBotAction act -> { + case AbstractCustomTimerBotAction act -> { + CraftBotAction result; T regAction = getRegAction.get(); if (regAction == null) throw new IllegalStateException("Action " + action.getClass().getName() + " is not registered!"); result = new CraftCustomTimerBotAction(regAction.getName(), act); + result.setCancelled(act.isCancelled()); + result.setOnFail(act.getOnFail()); + result.setOnSuccess(act.getOnSuccess()); + result.setOnStop(act.getOnStop()); + result.setDoNumber0(act.getDoNumber()); + result.setDoIntervalTick0(act.getDoIntervalTick()); + result.setStartDelayTick0(act.getStartDelayTick()); + this.getHandle().addBotAction(result, null); } - case CustomStateBotAction act -> { + case AbstractCustomStateBotAction act -> { + CraftBotAction result; T regAction = getRegAction.get(); if (regAction == null) throw new IllegalStateException("Action " + action.getClass().getName() + " is not registered!"); result = new CraftCustomStateBotAction(regAction.getName(), act); + result.setCancelled(act.isCancelled()); + result.setOnFail(act.getOnFail()); + result.setOnSuccess(act.getOnSuccess()); + result.setOnStop(act.getOnStop()); + this.getHandle().addBotAction(result, null); } - case CraftBotAction craftBotAction -> result = craftBotAction; + case CraftBotAction craftBotAction -> this.getHandle().addBotAction(craftBotAction, null); default -> throw new IllegalArgumentException("Action " + action.getClass().getName() + " is not a valid BotAction type!"); } - this.getHandle().addBotAction(result, null); + } @Override diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/entity/CraftBotManager.java b/leaves-server/src/main/java/org/leavesmc/leaves/entity/CraftBotManager.java index f47db479..b2cafb48 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/entity/CraftBotManager.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/entity/CraftBotManager.java @@ -10,14 +10,18 @@ import org.leavesmc.leaves.bot.BotList; import org.leavesmc.leaves.bot.ServerBot; import org.leavesmc.leaves.bot.agent.Actions; import org.leavesmc.leaves.bot.agent.actions.CraftBotAction; +import org.leavesmc.leaves.bot.agent.actions.CraftCustomAction; import org.leavesmc.leaves.bot.agent.actions.CraftCustomBotAction; +import org.leavesmc.leaves.bot.agent.actions.CraftCustomStateBotAction; +import org.leavesmc.leaves.bot.agent.actions.CraftCustomTimerBotAction; import org.leavesmc.leaves.entity.bot.Bot; import org.leavesmc.leaves.entity.bot.BotCreator; import org.leavesmc.leaves.entity.bot.BotManager; import org.leavesmc.leaves.entity.bot.action.BotAction; +import org.leavesmc.leaves.entity.bot.action.AbstractCustomBotAction; +import org.leavesmc.leaves.entity.bot.action.AbstractCustomStateBotAction; +import org.leavesmc.leaves.entity.bot.action.AbstractCustomTimerBotAction; import org.leavesmc.leaves.entity.bot.action.CustomBotAction; -import org.leavesmc.leaves.entity.bot.action.CustomStateBotAction; -import org.leavesmc.leaves.entity.bot.action.CustomTimerBotAction; import org.leavesmc.leaves.event.bot.BotCreateEvent; import java.lang.reflect.InvocationTargetException; @@ -61,14 +65,20 @@ public class CraftBotManager implements BotManager { } @Override - public boolean registerCustomBotAction(String name, CustomBotAction action) { - return Actions.register(new CraftCustomBotAction(name, action)); + public boolean registerCustomBotAction(CustomBotAction action) { + return switch (action) { + case AbstractCustomBotAction act -> Actions.register(new CraftCustomBotAction(act.getName(), act)); + case AbstractCustomStateBotAction act -> Actions.register(new CraftCustomStateBotAction(act.getName(), act)); + case AbstractCustomTimerBotAction act -> Actions.register(new CraftCustomTimerBotAction(act.getName(), act)); + case CraftCustomBotAction craftAction -> Actions.register(craftAction); + case null, default -> throw new IllegalArgumentException("Unsupported action type: " + action); + }; } @Override public boolean unregisterCustomBotAction(String name) { CraftBotAction action = Actions.getForName(name); - if (action instanceof CraftCustomBotAction) { + if (action instanceof CraftCustomAction) { return Actions.unregister(name); } return false; @@ -77,10 +87,7 @@ public class CraftBotManager implements BotManager { @SuppressWarnings("unchecked") @Override public > T newAction(@NotNull Class type) { - if (type.isAssignableFrom(CustomBotAction.class) - || type.isAssignableFrom(CustomTimerBotAction.class) - || type.isAssignableFrom(CustomStateBotAction.class) - ) try { + if (type.isAssignableFrom(CustomBotAction.class)) try { return type.getConstructor().newInstance(); } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException(e);