Skip to content

Commit

Permalink
added configurable name and aliases to command; bumped artifact-version
Browse files Browse the repository at this point in the history
  • Loading branch information
BlvckBytes committed Oct 10, 2024
1 parent 5c6fdbc commit a75f3a4
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 9 deletions.
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>me.blvckbytes</groupId>
<artifactId>ItemPredicateParser</artifactId>
<version>0.0.9</version>
<version>0.0.10</version>

<properties>
<compileSource>17</compileSource>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package me.blvckbytes.item_predicate_parser;

import me.blvckbytes.bukkitevaluable.ConfigKeeper;
import me.blvckbytes.item_predicate_parser.config.MainSection;
import org.bukkit.command.Command;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -13,9 +15,9 @@ public class CommandSendListener implements Listener {
private final String lowerPluginName;
private final Command ippCommand;

public CommandSendListener(JavaPlugin plugin) {
public CommandSendListener(JavaPlugin plugin, ConfigKeeper<MainSection> config) {
this.lowerPluginName = plugin.getName().toLowerCase();
this.ippCommand = Objects.requireNonNull(plugin.getCommand(ItemPredicateParserCommand.COMMAND_NAME));
this.ippCommand = Objects.requireNonNull(plugin.getCommand(config.rootSection.commands.itemPredicateParser.evaluatedName));
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public static EnumPredicate<CommandAction> makeFilter(Player player) {
}
}

public static final String COMMAND_NAME = "itempredicateparser";

private final PredicateHelper predicateHelper;
private final ConfigKeeper<MainSection> config;
private final Logger logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package me.blvckbytes.item_predicate_parser;

import me.blvckbytes.bukkitevaluable.CommandUpdater;
import me.blvckbytes.bukkitevaluable.ConfigKeeper;
import me.blvckbytes.bukkitevaluable.ConfigManager;
import me.blvckbytes.item_predicate_parser.config.ItemPredicateParserCommandSection;
import me.blvckbytes.item_predicate_parser.config.MainSection;
import me.blvckbytes.item_predicate_parser.translation.LanguageRegistry;
import me.blvckbytes.item_predicate_parser.translation.resolver.PluginTranslationResolver;
Expand All @@ -28,11 +30,20 @@ public void onEnable() {
var languageRegistry = new LanguageRegistry(this, new PluginTranslationResolver(this));
this.predicateHelper = new PredicateHelper(languageRegistry, config);

Objects.requireNonNull(getCommand(ItemPredicateParserCommand.COMMAND_NAME)).setExecutor(
new ItemPredicateParserCommand(predicateHelper, config, logger)
);
var commandUpdater = new CommandUpdater(this);
var command = Objects.requireNonNull(getCommand(ItemPredicateParserCommandSection.INITIAL_NAME));

Bukkit.getServer().getPluginManager().registerEvents(new CommandSendListener(this), this);
command.setExecutor(new ItemPredicateParserCommand(predicateHelper, config, logger));

Runnable updateCommands = () -> {
config.rootSection.commands.itemPredicateParser.apply(command, commandUpdater);
commandUpdater.trySyncCommands();
};

updateCommands.run();
config.registerReloadListener(updateCommands);

Bukkit.getServer().getPluginManager().registerEvents(new CommandSendListener(this, config), this);

instance = this;
} catch (Throwable e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package me.blvckbytes.item_predicate_parser.config;

import me.blvckbytes.bbconfigmapper.sections.AConfigSection;
import me.blvckbytes.bbconfigmapper.sections.CSAlways;
import me.blvckbytes.gpeee.interpreter.EvaluationEnvironmentBuilder;

@CSAlways
public class CommandsSection extends AConfigSection {

public ItemPredicateParserCommandSection itemPredicateParser;

public CommandsSection(EvaluationEnvironmentBuilder baseEnvironment) {
super(baseEnvironment);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package me.blvckbytes.item_predicate_parser.config;

import me.blvckbytes.bukkitevaluable.section.ACommandSection;
import me.blvckbytes.gpeee.interpreter.EvaluationEnvironmentBuilder;

public class ItemPredicateParserCommandSection extends ACommandSection {

public static final String INITIAL_NAME = "itempredicateparser";

public ItemPredicateParserCommandSection(EvaluationEnvironmentBuilder baseEnvironment) {
super(INITIAL_NAME, baseEnvironment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class MainSection extends AConfigSection {
public @Nullable BukkitEvaluable maxCompletionsExceeded;
public @Nullable BukkitEvaluable inputNonHighlightPrefix;
public @Nullable BukkitEvaluable inputHighlightPrefix;
public @CSAlways CommandsSection commands;
public Map<String, BukkitEvaluable> parseConflicts;

@CSAlways
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ playerMessages:
missingPermissionIppTestCommand$: 'lut["MESSAGE_PREFIX"] & "&cYou don''t have the permission to use the test sub-command."'
missingPermissionIppReloadCommand$: 'lut["MESSAGE_PREFIX"] & "&cYou don''t have the permission to use the reload sub-command."'

commands:
itempredicateparser:
name: itempredicateparser
aliases:
- ipp

# File-global lookup table
lut:
MESSAGE_PREFIX: '&7[&6ItemPredicateParser&7] '

0 comments on commit a75f3a4

Please sign in to comment.