Add /shareitem

This commit is contained in:
zontreck 2025-03-30 12:21:20 -07:00
parent b53c2d905c
commit 90b90ea53c
3 changed files with 96 additions and 47 deletions

View file

@ -6,6 +6,7 @@ import dev.zontreck.ase.commands.homes.DelHomeCommand;
import dev.zontreck.ase.commands.homes.HomeCommand;
import dev.zontreck.ase.commands.homes.HomesCommand;
import dev.zontreck.ase.commands.homes.SetHomeCommand;
import dev.zontreck.ase.commands.misc.ShareItemCommand;
import dev.zontreck.ase.commands.tpa.TPACancelCommand;
import dev.zontreck.ase.commands.tpa.TPACommand;
import dev.zontreck.ase.commands.tpa.TPAHereCommand;
@ -16,58 +17,70 @@ import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
public class CommandRegistry {
public static void register(Commands cmds) {
cmds.register(Commands.literal("homes").requires(x -> x.getSender().hasPermission(HomesCommand.PERMISSION))
.executes(ctx -> HomesCommand.execute(ctx)).build());
cmds.register(Commands.literal("sethome")
.requires(x -> x.getSender().hasPermission(SetHomeCommand.PERMISSION))
.executes(ctx -> SetHomeCommand.execute(ctx, "Default"))
.then(Commands.argument("name", StringArgumentType.string())
.executes(ctx -> SetHomeCommand.execute(ctx, StringArgumentType.getString(ctx, "name"))))
.build());
public static void register(Commands cmds) {
cmds.register(Commands.literal("homes")
.requires(x -> x.getSender().isPermissionSet(HomesCommand.PERMISSION))
.executes(ctx -> HomesCommand.execute(ctx)).build());
cmds.register(Commands.literal("sethome")
.requires(x -> x.getSender().isPermissionSet(SetHomeCommand.PERMISSION))
.executes(ctx -> SetHomeCommand.execute(ctx, "Default"))
.then(Commands.argument("name", StringArgumentType.string())
.executes(ctx -> SetHomeCommand.execute(ctx,
StringArgumentType.getString(ctx, "name"))))
.build());
cmds.register(Commands.literal("home")
.requires(x -> x.getSender().hasPermission(HomeCommand.PERMISSION))
.executes(ctx -> HomeCommand.execute(ctx, "Default"))
.then(Commands.argument("name", StringArgumentType.string())
.executes(ctx -> HomeCommand.execute(ctx, StringArgumentType.getString(ctx, "name"))))
.build());
cmds.register(Commands.literal("home")
.requires(x -> x.getSender().isPermissionSet(HomeCommand.PERMISSION))
.executes(ctx -> HomeCommand.execute(ctx, "Default"))
.then(Commands.argument("name", StringArgumentType.string())
.executes(ctx -> HomeCommand.execute(ctx,
StringArgumentType.getString(ctx, "name"))))
.build());
cmds.register(Commands.literal("delhome")
.requires(x -> x.getSender().hasPermission(DelHomeCommand.PERMISSION))
.executes(ctx -> DelHomeCommand.execute(ctx, "Default"))
.then(Commands.argument("name", StringArgumentType.string())
.executes(ctx -> DelHomeCommand.execute(ctx, StringArgumentType.getString(ctx, "name"))))
.build());
cmds.register(Commands.literal("delhome")
.requires(x -> x.getSender().isPermissionSet(DelHomeCommand.PERMISSION))
.executes(ctx -> DelHomeCommand.execute(ctx, "Default"))
.then(Commands.argument("name", StringArgumentType.string())
.executes(ctx -> DelHomeCommand.execute(ctx,
StringArgumentType.getString(ctx, "name"))))
.build());
cmds.register(Commands.literal("tpa")
.requires(x -> x.getSender().hasPermission(TPACommand.PERMISSION))
.executes(ctx -> TPACommand.usage(ctx.getSource()))
.then(Commands.argument("player", ArgumentTypes.player())
.executes(ctx -> TPACommand.execute(ctx.getSource(),
ctx.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(ctx.getSource())
.getFirst())))
.build());
cmds.register(Commands.literal("tpa")
.requires(x -> x.getSender().isPermissionSet(TPACommand.PERMISSION))
.executes(ctx -> TPACommand.usage(ctx.getSource()))
.then(Commands.argument("player", ArgumentTypes.player())
.executes(ctx -> TPACommand.execute(ctx.getSource(),
ctx.getArgument("player",
PlayerSelectorArgumentResolver.class)
.resolve(ctx.getSource())
.getFirst())))
.build());
cmds.register(Commands.literal("tpahere")
.requires(x -> x.getSender().hasPermission(TPAHereCommand.PERMISSION))
.executes(ctx -> TPAHereCommand.usage(ctx.getSource()))
.then(Commands.argument("player", ArgumentTypes.player())
.executes(ctx -> TPAHereCommand.execute(ctx.getSource(),
ctx.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(ctx.getSource())
.getFirst())))
.build());
cmds.register(Commands.literal("tpahere")
.requires(x -> x.getSender().isPermissionSet(TPAHereCommand.PERMISSION))
.executes(ctx -> TPAHereCommand.usage(ctx.getSource()))
.then(Commands.argument("player", ArgumentTypes.player())
.executes(ctx -> TPAHereCommand.execute(ctx.getSource(),
ctx.getArgument("player",
PlayerSelectorArgumentResolver.class)
.resolve(ctx.getSource())
.getFirst())))
.build());
cmds.register(Commands.literal("tpacancel")
.requires(x -> x.getSender().hasPermission(TPACancelCommand.PERMISSION))
.executes(ctx -> TPACancelCommand.execute(ctx.getSource())).build());
cmds.register(Commands.literal("tpacancel")
.requires(x -> x.getSender().isPermissionSet(TPACancelCommand.PERMISSION))
.executes(ctx -> TPACancelCommand.execute(ctx.getSource())).build());
cmds.register(Commands.literal("tpaccept")
.requires(x -> x.getSender().hasPermission(TPAcceptCommand.PERMISSION))
.executes(ctx -> TPAcceptCommand.execute(ctx.getSource())).build());
cmds.register(Commands.literal("tpaccept")
.requires(x -> x.getSender().isPermissionSet(TPAcceptCommand.PERMISSION))
.executes(ctx -> TPAcceptCommand.execute(ctx.getSource())).build());
cmds.register(Commands.literal("tpdeny")
.requires(x -> x.getSender().hasPermission(TPDenyCommand.PERMISSION))
.executes(ctx -> TPDenyCommand.execute(ctx.getSource())).build());
}
cmds.register(Commands.literal("tpdeny")
.requires(x -> x.getSender().isPermissionSet(TPDenyCommand.PERMISSION))
.executes(ctx -> TPDenyCommand.execute(ctx.getSource())).build());
cmds.register(Commands.literal("shareitem")
.requires(x -> x.getSender().isPermissionSet(ShareItemCommand.PERMISSION))
.executes(ctx -> ShareItemCommand.execute(ctx.getSource())).build());
}
}

View file

@ -0,0 +1,29 @@
package dev.zontreck.ase.commands.misc;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.mojang.brigadier.Command;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
public class ShareItemCommand {
public static final String PERMISSION = "ase.commands.shareitem";
public static int execute(CommandSourceStack ctx) {
Player player = (Player) ctx.getSender();
ItemStack hand = player.getActiveItem();
if (hand.isEmpty()) {
player.sendMessage(
Component.text("You cannot share air in chat.", NamedTextColor.DARK_RED));
} else {
player.getServer().broadcast(Component.text(player.getName(), NamedTextColor.DARK_PURPLE).append(Component
.text(" has shared an item in chat. [Hover your mouse here to see it]", NamedTextColor.DARK_GREEN)
.hoverEvent(hand.asHoverEvent())));
}
return Command.SINGLE_SUCCESS;
}
}

View file

@ -33,6 +33,9 @@ commands:
tpahere:
description: Request a player to teleport to you
usage: "- /tpahere [player] -"
shareitem:
description: Shares the item in your hand with everyone in chat
usage: "- /shareitem -"
permissions:
ase.commands.*:
description: Allow all commands
@ -47,6 +50,7 @@ permissions:
ase.commands.tpdeny: true
ase.commands.tpacancel: true
ase.commands.tpahere: true
ase.commands.shareitem: true
ase.commands.home:
description: Allows usage of the /home command
default: true
@ -74,3 +78,6 @@ permissions:
ase.commands.tpahere:
description: Allow usage of /tpahere
default: true
ase.commands.shareitem:
description: Allow /shareitem
default: true