Skip to content

Commit

Permalink
Add mainHand context for spigot
Browse files Browse the repository at this point in the history
  • Loading branch information
boxbeam committed Aug 18, 2022
1 parent 216dcb3 commit c3928b9
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import redempt.ordinate.builder.BuilderOptions;
import redempt.ordinate.builder.CommandBuilder;
import redempt.ordinate.command.ArgType;
import redempt.ordinate.command.Command;
import redempt.ordinate.context.ContextProvider;
import redempt.ordinate.creation.ComponentFactory;
import redempt.ordinate.creation.DefaultComponentFactory;
Expand Down Expand Up @@ -46,6 +45,7 @@ public static Properties getDefaultMessages() {
props.setProperty("invalidSubcommand", "&cInvalid subcommand: %1");
props.setProperty("noPermission", "&cYou do not have permission to do that (%1)");
props.setProperty("playerOnly", "&cThis command must be executed as a player");
props.setProperty("needItem", "&cYou must be holding an item to do this");
props.setProperty("helpFormat", "&e%1 &7%2");
return props;
}
Expand Down Expand Up @@ -181,6 +181,10 @@ private void applyArgTypes(CommandParser<CommandSender> parser) {

private void applyContextProviders(CommandParser<CommandSender> parser) {
parser.addContextProviders(playerContext("self", messages.getFormatter("playerOnly").format(null).toString(), p -> p));
parser.addContextProviders(playerContext("mainHand", messages.getFormatter("needItem").format(null).toString(), p -> {
ItemStack item = p.getInventory().getItemInMainHand();
return item == null || item.getType() == Material.AIR ? null : item;
}));
}

@Override
Expand Down

0 comments on commit c3928b9

Please sign in to comment.