Skip to content

Commit

Permalink
moved responsibility of plugin caching to the user
Browse files Browse the repository at this point in the history
  • Loading branch information
codejanovic committed May 13, 2024
1 parent 71b34f6 commit f5023ea
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Release artifact
<dependency>
<groupId>com.github.zrdj</groupId>
<artifactId>javachord</artifactId>
<version>3.8.0.13</version>
<version>3.8.0.14</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.zrdj</groupId>
<artifactId>javachord</artifactId>
<version>3.8.0.13</version>
<version>3.8.0.14</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ abstract class ApplicationCommandBehavior implements ApplicationCommand, SlashCo
protected final String _name;
protected final String _description;
protected final Optional<ApplicationCommandGroup> _parentCommand;
private ApplicationCommandAccessPlugin _accessPlugin;
private ApplicationCommandTriggerPlugin _triggerPlugin;
private final List<ApplicationCommandOption<?>> _options;

ApplicationCommandBehavior(final String name, final String description, ApplicationCommandGroup parentCommand, List<ApplicationCommandOption<?>> options) {
Expand Down Expand Up @@ -72,27 +70,20 @@ public final SlashCommandBuilder toSlashCommand() {
@Override
public final void onSlashCommandCreate(final SlashCommandCreateEvent event) {
ensurePlugins();
if (!_triggerPlugin.triggered(event.getSlashCommandInteraction())) {
if (!triggerPlugin().triggered(event.getSlashCommandInteraction())) {
return;
}
if (!_accessPlugin.authorized(event.getInteraction().getUser(), this)) {
if (!accessPlugin().authorized(event.getInteraction().getUser(), this)) {
return;
}
onSlashCommandTriggered(event);
}

private void ensurePlugins() {
if (_triggerPlugin != null && _accessPlugin != null) {
return;
}

_triggerPlugin = triggerPlugin();
_accessPlugin = accessPlugin();

if (_triggerPlugin == null) {
if (triggerPlugin() == null) {
throw new JavachordConstraintError("Trigger plugin has not been defined. Did you forget to provide a valid Plugin while overriding triggerPlugin()?");
}
if (_accessPlugin == null) {
if (accessPlugin() == null) {
throw new JavachordConstraintError("Access plugin has not been defined. Did you forget to provide a valid Plugin while overriding accessPlugin()?");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
public abstract class MessageComponentBehavior implements MessageComponent, MessageComponentCreateListener {
protected final String _identifier;
protected boolean _disabled = false;
private MessageComponentTriggerPlugin _triggerPlugin;

public MessageComponentBehavior(final String identifier) {
_identifier = identifier;
Expand All @@ -25,13 +24,7 @@ protected MessageComponentTriggerPlugin triggerPlugin() {
}

private void ensurePlugins() {
if (_triggerPlugin != null) {
return;
}

_triggerPlugin = triggerPlugin();

if (_triggerPlugin == null) {
if (triggerPlugin() == null) {
throw new JavachordConstraintError("Trigger plugin has not been defined. Did you forget to provide a valid Plugin while overriding triggerPlugin()?");
}
}
Expand All @@ -49,7 +42,7 @@ public final void disabled() {
@Override
public final void onComponentCreate(final MessageComponentCreateEvent event) {
ensurePlugins();
if (_triggerPlugin.triggered(event.getMessageComponentInteraction())) {
if (triggerPlugin().triggered(event.getMessageComponentInteraction())) {
onInteraction(event.getMessageComponentInteraction());
}
}
Expand Down

0 comments on commit f5023ea

Please sign in to comment.