diff --git a/API/src/main/java/fr/maxlego08/essentials/api/commands/Permission.java b/API/src/main/java/fr/maxlego08/essentials/api/commands/Permission.java index 7f03a17b..4ecf06bd 100644 --- a/API/src/main/java/fr/maxlego08/essentials/api/commands/Permission.java +++ b/API/src/main/java/fr/maxlego08/essentials/api/commands/Permission.java @@ -244,8 +244,10 @@ public enum Permission { ESSENTIALS_SUDO, ESSENTIALS_SUDO_BYPASS, ESSENTIALS_MAIL_GIVE, + ESSENTIALS_MAIL_GIVE_HAND, ESSENTIALS_MAIL_CLEAR, ESSENTIALS_MAIL_GIVEALL, + ESSENTIALS_MAIL_GIVEALL_HAND, ESSENTIALS_WORLDEDIT_USE, ESSENTIALS_WORLDEDIT_GIVE, ESSENTIALS_WORLDEDIT_SET, diff --git a/API/src/main/java/fr/maxlego08/essentials/api/messages/Message.java b/API/src/main/java/fr/maxlego08/essentials/api/messages/Message.java index 0487fbb1..a4531968 100644 --- a/API/src/main/java/fr/maxlego08/essentials/api/messages/Message.java +++ b/API/src/main/java/fr/maxlego08/essentials/api/messages/Message.java @@ -302,8 +302,10 @@ public enum Message { DESCRIPTION_MAIL("Open mailbox"), DESCRIPTION_MAIL_OPEN("Open player's mailbox"), DESCRIPTION_MAIL_GIVE("Give an item to player's mailbox"), + DESCRIPTION_MAIL_GIVE_HAND("Send the item in your hand to a player's mailbox"), DESCRIPTION_MAIL_CLEAR("Removes items from the player’s mailbox"), DESCRIPTION_MAIL_GIVEALL("Give an items to players mailbox"), + DESCRIPTION_MAIL_GIVEALL_HAND("Send the item in your hand to players mailboxes"), DESCRIPTION_RULES("Read server rules"), DESCRIPTION_SUICIDE("Kill yourself"), DESCRIPTION_HOLOGRAM("Show hologram commands"), @@ -738,6 +740,8 @@ public enum Message { MAILBOX_GIVE_ERROR("Can’t find the item &f%item%."), MAILBOX_GIVE("You just gave &n&fx%amount% %item%&r to player &f%player% mailbox."), MAILBOX_GIVE_ALL("You just gave &n&fx%amount% %item%&r to online player mailbox."), + MAILBOX_GIVE_HAND("You just sent the item in your hand to &f%player%'s mailbox (&fx%amount% %item%)."), + MAILBOX_GIVE_ALL_HAND("You just sent the item in your hand (&fx%amount% %item%) to every online player's mailbox."), MAILBOX_CLEAR("You have just cleared the mailbox of &f%player%."), diff --git a/src/main/java/fr/maxlego08/essentials/commands/commands/mail/CommandMail.java b/src/main/java/fr/maxlego08/essentials/commands/commands/mail/CommandMail.java index bb2e560d..8baf2312 100644 --- a/src/main/java/fr/maxlego08/essentials/commands/commands/mail/CommandMail.java +++ b/src/main/java/fr/maxlego08/essentials/commands/commands/mail/CommandMail.java @@ -15,7 +15,9 @@ public CommandMail(EssentialsPlugin plugin) { this.setPermission(Permission.ESSENTIALS_MAIL); this.addSubCommand(new CommandMailOpen(plugin)); this.addSubCommand(new CommandMailGive(plugin)); + this.addSubCommand(new CommandMailGiveHand(plugin)); this.addSubCommand(new CommandMailGiveAll(plugin)); + this.addSubCommand(new CommandMailGiveAllHand(plugin)); this.addSubCommand(new CommandMailClear(plugin)); this.onlyPlayers(); } diff --git a/src/main/java/fr/maxlego08/essentials/commands/commands/mail/CommandMailGiveAllHand.java b/src/main/java/fr/maxlego08/essentials/commands/commands/mail/CommandMailGiveAllHand.java new file mode 100644 index 00000000..cc1a890c --- /dev/null +++ b/src/main/java/fr/maxlego08/essentials/commands/commands/mail/CommandMailGiveAllHand.java @@ -0,0 +1,36 @@ +package fr.maxlego08.essentials.commands.commands.mail; + +import fr.maxlego08.essentials.api.EssentialsPlugin; +import fr.maxlego08.essentials.api.commands.CommandResultType; +import fr.maxlego08.essentials.api.commands.Permission; +import fr.maxlego08.essentials.api.messages.Message; +import fr.maxlego08.essentials.module.modules.MailBoxModule; +import fr.maxlego08.essentials.zutils.utils.commands.VCommand; +import org.bukkit.inventory.ItemStack; + +public class CommandMailGiveAllHand extends VCommand { + + public CommandMailGiveAllHand(EssentialsPlugin plugin) { + super(plugin); + this.setModule(MailBoxModule.class); + this.setDescription(Message.DESCRIPTION_MAIL_GIVEALL_HAND); + this.setPermission(Permission.ESSENTIALS_MAIL_GIVEALL_HAND); + this.addSubCommand("giveall-hand"); + this.onlyPlayers(); + } + + @Override + protected CommandResultType perform(EssentialsPlugin plugin) { + + ItemStack itemStack = this.player.getInventory().getItemInMainHand(); + if (itemStack == null || itemStack.getType().isAir()) { + message(this.sender, Message.COMMAND_ITEM_EMPTY); + return CommandResultType.DEFAULT; + } + + var module = plugin.getModuleManager().getModule(MailBoxModule.class); + module.giveAllItemFromHand(this.sender, itemStack.clone()); + + return CommandResultType.SUCCESS; + } +} diff --git a/src/main/java/fr/maxlego08/essentials/commands/commands/mail/CommandMailGiveHand.java b/src/main/java/fr/maxlego08/essentials/commands/commands/mail/CommandMailGiveHand.java new file mode 100644 index 00000000..08381a0f --- /dev/null +++ b/src/main/java/fr/maxlego08/essentials/commands/commands/mail/CommandMailGiveHand.java @@ -0,0 +1,40 @@ +package fr.maxlego08.essentials.commands.commands.mail; + +import fr.maxlego08.essentials.api.EssentialsPlugin; +import fr.maxlego08.essentials.api.commands.CommandResultType; +import fr.maxlego08.essentials.api.commands.Permission; +import fr.maxlego08.essentials.api.messages.Message; +import fr.maxlego08.essentials.module.modules.MailBoxModule; +import fr.maxlego08.essentials.zutils.utils.commands.VCommand; +import org.bukkit.inventory.ItemStack; + +public class CommandMailGiveHand extends VCommand { + + public CommandMailGiveHand(EssentialsPlugin plugin) { + super(plugin); + this.setModule(MailBoxModule.class); + this.setDescription(Message.DESCRIPTION_MAIL_GIVE_HAND); + this.setPermission(Permission.ESSENTIALS_MAIL_GIVE_HAND); + this.addSubCommand("give-hand"); + this.addRequireOfflinePlayerNameArg(); + this.onlyPlayers(); + } + + @Override + protected CommandResultType perform(EssentialsPlugin plugin) { + + ItemStack itemStack = this.player.getInventory().getItemInMainHand(); + if (itemStack == null || itemStack.getType().isAir()) { + message(this.sender, Message.COMMAND_ITEM_EMPTY); + return CommandResultType.DEFAULT; + } + + String username = this.argAsString(0); + ItemStack itemToGive = itemStack.clone(); + + var module = plugin.getModuleManager().getModule(MailBoxModule.class); + this.fetchUniqueId(username, uuid -> module.giveItemFromHand(this.sender, uuid, username, itemToGive)); + + return CommandResultType.SUCCESS; + } +} diff --git a/src/main/java/fr/maxlego08/essentials/module/modules/MailBoxModule.java b/src/main/java/fr/maxlego08/essentials/module/modules/MailBoxModule.java index bfe37264..90d8ef5a 100644 --- a/src/main/java/fr/maxlego08/essentials/module/modules/MailBoxModule.java +++ b/src/main/java/fr/maxlego08/essentials/module/modules/MailBoxModule.java @@ -195,6 +195,51 @@ public void giveAllItem(CommandSender sender, String itemName, int amount) { message(sender, Message.MAILBOX_GIVE_ALL, "%item%", itemName, "%amount%", amount); } + public void giveItemFromHand(CommandSender sender, UUID uuid, String username, ItemStack itemStack) { + + if (itemStack == null || itemStack.getType().isAir()) { + message(sender, Message.COMMAND_ITEM_EMPTY); + return; + } + + ItemStack clonedItemStack = itemStack.clone(); + addItemAndFix(uuid, clonedItemStack); + + message(sender, Message.MAILBOX_GIVE_HAND, + "%item%", getItemName(clonedItemStack), + "%player%", username, + "%amount%", clonedItemStack.getAmount()); + } + + public void giveAllItemFromHand(CommandSender sender, ItemStack itemStack) { + + if (itemStack == null || itemStack.getType().isAir()) { + message(sender, Message.COMMAND_ITEM_EMPTY); + return; + } + + String itemName = getItemName(itemStack); + int amount = itemStack.getAmount(); + + for (Player player : Bukkit.getOnlinePlayers()) { + addItemAndFix(player.getUniqueId(), itemStack.clone()); + } + + message(sender, Message.MAILBOX_GIVE_ALL_HAND, + "%item%", itemName, + "%amount%", amount); + } + + private String getItemName(ItemStack itemStack) { + if (itemStack.hasItemMeta()) { + var itemMeta = itemStack.getItemMeta(); + if (itemMeta != null && itemMeta.hasDisplayName()) { + return itemMeta.getDisplayName(); + } + } + return name(itemStack.getType().name()); + } + public void clear(CommandSender sender, UUID uuid, String username) { getStorage().clearMailBox(uuid); var user = getUser(uuid); diff --git a/src/main/resources/messages/message_zh.yml b/src/main/resources/messages/message_zh.yml index c10dc3a0..e5ccf4b2 100644 --- a/src/main/resources/messages/message_zh.yml +++ b/src/main/resources/messages/message_zh.yml @@ -412,7 +412,9 @@ description-balance-top: 显示财富排行榜 description-balance-top-refresh: 刷新财富排行榜 description-mail-open: 打开玩家的邮箱 description-mail-give: 给玩家的邮箱赠送一个物品 +description-mail-give-hand: 将你手中的物品发送到玩家的邮箱 description-mail-giveall: 给所有玩家的邮箱赠送物品 +description-mail-giveall-hand: 将你手中的物品发送到所有在线玩家的邮箱 description-voteparty-information: 显示投票派对 description-voteparty-set: 设置投票派对所需的票数 description-voteparty-add: 向投票派对添加票数 @@ -820,6 +822,8 @@ mailbox-add: mailbox-give-error: 找不到物品 &f%item%。 mailbox-give: 你刚刚给了 &n&fx%amount% %item%&r 给玩家 &f%player%的邮箱。 mailbox-give-all: 你刚刚给了 &n&fx%amount% %item%&r 给在线玩家的邮箱。 +mailbox-give-hand: 你已将手中的物品发送到 &f%player% 的邮箱 (&fx%amount% %item%)。 +mailbox-give-all-hand: 你已将手中的物品 (&fx%amount% %item%) 发送到所有在线玩家的邮箱。 hologram-create-error: 全息图 &f%name% 已经存在。 hologram-create: type: WITHOUT_PREFIX diff --git a/src/main/resources/messages/messages.yml b/src/main/resources/messages/messages.yml index 551fa6c9..76ec4650 100644 --- a/src/main/resources/messages/messages.yml +++ b/src/main/resources/messages/messages.yml @@ -418,7 +418,9 @@ description-balance-top: "Show baltop" description-balance-top-refresh: "Refresh baltop" description-mail-open: "Open player's mailbox" description-mail-give: "Give an item to player's mailbox" +description-mail-give-hand: "Send the item in your hand to a player's mailbox" description-mail-giveall: "Give items to players' mailboxes" +description-mail-giveall-hand: "Send the item in your hand to players' mailboxes" description-mail-clear: "Removes items from the player’s mailbox" description-voteparty-information: "Show the vote party" description-voteparty-set: "Set the number of votes in the vote party" @@ -815,6 +817,8 @@ mailbox-add: mailbox-give-error: "Can’t find the item &f%item%." mailbox-give: "You just gave &n&fx%amount% %item%&r to player &f%player%'s mailbox." mailbox-give-all: "You just gave &n&fx%amount% %item%&r to online players' mailboxes." +mailbox-give-hand: "You just sent the item in your hand to &f%player%'s mailbox (&fx%amount% %item%)." +mailbox-give-all-hand: "You just sent the item in your hand (&fx%amount% %item%) to every online player's mailbox." mailbox-clear: "You have just cleared the mailbox of &f%player%." diff --git a/src/main/resources/messages/messages_de.yml b/src/main/resources/messages/messages_de.yml index 03e50beb..54aa719f 100644 --- a/src/main/resources/messages/messages_de.yml +++ b/src/main/resources/messages/messages_de.yml @@ -388,7 +388,9 @@ description-balance-top: "Baltop anzeigen" description-balance-top-refresh: "Baltop aktualisieren" description-mail-open: "Postfach eines Spielers öffnen" description-mail-give: "Einem Spieler einen Gegenstand ins Postfach legen" +description-mail-give-hand: "Den Gegenstand in deiner Hand in das Postfach eines Spielers senden" description-mail-giveall: "Gegenstände in die Postfächer der Spieler legen" +description-mail-giveall-hand: "Den Gegenstand in deiner Hand in die Postfächer der Spieler senden" description-voteparty-information: "Stimmenparty anzeigen" description-voteparty-set: "Anzahl der Stimmen in der Stimmenparty festlegen" description-voteparty-add: "Zur Stimmenparty hinzufügen" @@ -753,6 +755,8 @@ mailbox-add: mailbox-give-error: "Der Gegenstand &f%item% konnte nicht gefunden werden." mailbox-give: "Du hast gerade &n&fx%amount% %item%&r an das Postfach von &f%player% gegeben." mailbox-give-all: "Du hast gerade &n&fx%amount% %item%&r an die Postfächer aller Online-Spieler gegeben." +mailbox-give-hand: "Du hast den Gegenstand in deiner Hand an das Postfach von &f%player% gesendet (&fx%amount% %item%)." +mailbox-give-all-hand: "Du hast den Gegenstand in deiner Hand (&fx%amount% %item%) an die Postfächer aller Online-Spieler gesendet." diff --git a/src/main/resources/messages/messages_es.yml b/src/main/resources/messages/messages_es.yml index 5691bd83..b87b6151 100644 --- a/src/main/resources/messages/messages_es.yml +++ b/src/main/resources/messages/messages_es.yml @@ -370,7 +370,9 @@ description-balance-top: "Mostrar el top de balance" description-balance-top-refresh: "Actualizar el top de balance" description-mail-open: "Abrir el buzón del jugador" description-mail-give: "Dar un objeto al buzón del jugador" +description-mail-give-hand: "Enviar el objeto en tu mano al buzón de un jugador" description-mail-giveall: "Dar objetos a los buzones de los jugadores" +description-mail-giveall-hand: "Enviar el objeto en tu mano a los buzones de los jugadores conectados" description-voteparty-information: "Mostrar la fiesta de votación" description-voteparty-set: "Establecer el número de votos en la fiesta de votación" description-voteparty-add: "Agregar a la fiesta de votación" @@ -712,6 +714,8 @@ mailbox-add: mailbox-give-error: "No se puede encontrar el objeto &f%item%." mailbox-give: "Acabas de dar &n&fx%amount% %item%&r al buzón del jugador &f%player%." mailbox-give-all: "Acabas de dar &n&fx%amount% %item%&r a los buzones de los jugadores en línea." +mailbox-give-hand: "Acabas de enviar el objeto en tu mano al buzón de &f%player% (&fx%amount% %item%)." +mailbox-give-all-hand: "Acabas de enviar el objeto en tu mano (&fx%amount% %item%) a los buzones de todos los jugadores conectados." hologram-create-error: "El holograma &f%name% ya existe." hologram-create: diff --git a/src/main/resources/messages/messages_fr.yml b/src/main/resources/messages/messages_fr.yml index bec1f881..153c4932 100644 --- a/src/main/resources/messages/messages_fr.yml +++ b/src/main/resources/messages/messages_fr.yml @@ -409,7 +409,9 @@ description-balance-top: "Afficher le classement des soldes" description-balance-top-refresh: "Actualiser le classement des soldes" description-mail-open: "Ouvrir la boite mail d'un joueur" description-mail-give: "Donner un objet à la boîte aux lettres du joueur" +description-mail-give-hand: "Envoyer l'objet dans votre main dans la boîte aux lettres d'un joueur" description-mail-giveall: "Donner des objets aux boîtes aux lettres des joueurs" +description-mail-giveall-hand: "Envoyer l'objet dans votre main dans la boîte aux lettres des joueurs connectés" description-mail-clear: "Removes items from the player’s mailbox" description-voteparty-information: "Afficher le vote party" description-voteparty-set: "Définir le nombre de votes dans le vote party" @@ -778,6 +780,8 @@ mailbox-add: mailbox-give-error: "Impossible de trouver l'objet &f%item%." mailbox-give: "Vous venez de donner &n&fx%amount% %item%&r à la boîte aux lettres du joueur &f%player%." mailbox-give-all: "Vous venez de donner &n&fx%amount% %item%&r aux boîtes aux lettres des joueurs en ligne." +mailbox-give-hand: "Vous venez d'envoyer l'objet dans votre main dans la boîte aux lettres de &f%player% (&fx%amount% %item%)." +mailbox-give-all-hand: "Vous venez d'envoyer l'objet dans votre main (&fx%amount% %item%) dans la boîte aux lettres de tous les joueurs connectés." mailbox-clear: "Vous venez d’effacer la boîte aux lettres de &f%player%." hologram-create-error: "Le hologramme &f%name% existe déjà." diff --git a/src/main/resources/messages/messages_it.yml b/src/main/resources/messages/messages_it.yml index ea408a8f..e6e6a155 100644 --- a/src/main/resources/messages/messages_it.yml +++ b/src/main/resources/messages/messages_it.yml @@ -366,7 +366,9 @@ description-balance-top: "Mostra il baltop" description-balance-top-refresh: "Aggiorna il baltop" description-mail-open: "Apre la mailbox del giocatore" description-mail-give: "Da un oggetto nella mailbox del giocatore" +description-mail-give-hand: "Invia l'oggetto nella tua mano alla mailbox di un giocatore" description-mail-giveall: "Dai un oggetto nella mailbox di tutti i giocatori" +description-mail-giveall-hand: "Invia l'oggetto nella tua mano alle mailbox dei giocatori online" description-voteparty-information: "Mostra il vote party" description-voteparty-set: "Imposta il numero di voti nel vote party" description-voteparty-add: "Aggiungi voti al vote party" @@ -710,6 +712,8 @@ mailbox-add: mailbox-give-error: "Non si riesce a trovare l'oggetto &f%item%." mailbox-give: "Hai dato &n&fx%amount% %item%&r alla mailbox di &f%player%." mailbox-give-all: "Hai dato &n&fx%amount% %item%&r a tutte le mailbox dei giocatori online." +mailbox-give-hand: "Hai inviato l'oggetto nella tua mano alla mailbox di &f%player% (&fx%amount% %item%)." +mailbox-give-all-hand: "Hai inviato l'oggetto nella tua mano (&fx%amount% %item%) alle mailbox di tutti i giocatori online." hologram-create-error: "Ologramma di nome &f%name% esiste già." diff --git a/src/main/resources/messages/messages_nl.yml b/src/main/resources/messages/messages_nl.yml index 07e54285..5e3ce801 100644 --- a/src/main/resources/messages/messages_nl.yml +++ b/src/main/resources/messages/messages_nl.yml @@ -412,7 +412,9 @@ description-balance-top: "Toon de baltop" description-balance-top-refresh: "Vernieuw de baltop" description-mail-open: "Open de mailbox van een speler" description-mail-give: "Geef een item aan een speler hun postbus" +description-mail-give-hand: "Stuur het item in je hand naar de mailbox van een speler" description-mail-giveall: "Geef items aan spelers hun postbus" +description-mail-giveall-hand: "Stuur het item in je hand naar de mailboxes van online spelers" description-voteparty-information: "Toon de vote party" description-voteparty-set: "Stel het aantal stemmen in de vote party in" description-voteparty-add: "Voeg toe aan de vote party" @@ -791,6 +793,8 @@ mailbox-add: mailbox-give-error: "Kan het item &f%item% niet vinden." mailbox-give: "Je hebt zojuist &n&fx%amount% %item%&r gegeven aan de mailbox van speler &f%player%." mailbox-give-all: "Je hebt zojuist &n&fx%amount% %item%&r gegeven aan de mailboxes van alle online spelers." +mailbox-give-hand: "Je hebt het item in je hand naar de mailbox van &f%player% gestuurd (&fx%amount% %item%)." +mailbox-give-all-hand: "Je hebt het item in je hand (&fx%amount% %item%) naar de mailboxes van alle online spelers gestuurd." hologram-create-error: "Hologram &f%name% bestaat al."