From 8bbdc6a01b68b7a5e7fe0960df6ce1bc94527393 Mon Sep 17 00:00:00 2001 From: ThiagoROX <51332006+SrBedrock@users.noreply.github.com> Date: Mon, 12 Feb 2024 15:15:39 -0300 Subject: [PATCH] Melhoria do comando /chaves ver --- paper/run/server.properties | 2 +- .../commands/subs/BaseKeyCommand.java | 37 ++++++++++--------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/paper/run/server.properties b/paper/run/server.properties index 3c9cb80b0..80deaac3b 100644 --- a/paper/run/server.properties +++ b/paper/run/server.properties @@ -1,5 +1,5 @@ #Minecraft server properties -#Mon Feb 12 11:36:14 GMT-03:00 2024 +#Mon Feb 12 15:13:53 GMT-03:00 2024 enable-jmx-monitoring=false rcon.port=25575 level-seed= diff --git a/paper/src/main/java/com/badbones69/crazycrates/commands/subs/BaseKeyCommand.java b/paper/src/main/java/com/badbones69/crazycrates/commands/subs/BaseKeyCommand.java index 626da7af5..eae219a64 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/commands/subs/BaseKeyCommand.java +++ b/paper/src/main/java/com/badbones69/crazycrates/commands/subs/BaseKeyCommand.java @@ -2,7 +2,7 @@ import ch.jalu.configme.SettingsManager; import com.badbones69.crazycrates.CrazyCrates; -import com.badbones69.crazycrates.api.EventLogger; +import com.badbones69.crazycrates.api.EventManager; import com.badbones69.crazycrates.api.enums.Messages; import com.badbones69.crazycrates.api.events.PlayerReceiveKeyEvent; import com.badbones69.crazycrates.api.objects.Crate; @@ -13,8 +13,11 @@ import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.annotation.Command; import dev.triumphteam.cmd.core.annotation.Default; +import dev.triumphteam.cmd.core.annotation.Description; +import dev.triumphteam.cmd.core.annotation.Optional; import dev.triumphteam.cmd.core.annotation.SubCommand; import dev.triumphteam.cmd.core.annotation.Suggestion; +import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -34,9 +37,6 @@ public class BaseKeyCommand extends BaseCommand { @NotNull private final CrateManager crateManager = this.plugin.getCrateManager(); - @NotNull - private final EventLogger eventLogger = this.plugin.getEventLogger(); - @NotNull private final SettingsManager config = this.plugin.getConfigManager().getConfig(); @@ -51,21 +51,22 @@ public void viewPersonal(@NotNull Player player) { @SubCommand("ver") @Permission("crazycrates.command.player.key.others") - public void viewOthers(CommandSender sender, @Suggestion("online-players") Player target) { - if (target == sender) { - sender.sendMessage(Messages.same_player.getString()); - return; + public void viewOthers(CommandSender sender, @Optional @Suggestion("online-players") CrateBaseCommand.CustomPlayer target) { + if (target == null) { + target = new CrateBaseCommand.CustomPlayer(sender.getName()); } + OfflinePlayer player = target.getOfflinePlayer(); + HashMap placeholders = new HashMap<>(); - placeholders.put("%player%", target.getName()); - placeholders.put("%crates_opened%", String.valueOf(this.plugin.getCrazyHandler().getUserManager().getTotalCratesOpened(target.getUniqueId()))); + placeholders.put("%player%", player.getName()); + placeholders.put("%crates_opened%", String.valueOf(this.plugin.getCrazyHandler().getUserManager().getTotalCratesOpened(player.getUniqueId()))); String header = Messages.other_player_no_keys_header.getMessage(placeholders).toString(); - String otherPlayer = Messages.other_player_no_keys.getMessage("%player%", target.getName()).toString(); + String otherPlayer = Messages.other_player_no_keys.getMessage("%player%", player.getName()).toString(); - getKeys(target, sender, header, otherPlayer); + getKeys(player, sender, header, otherPlayer); } @SubCommand("transferir") @@ -105,7 +106,7 @@ public void onPlayerTransferKeys(Player sender, @Suggestion("crates") String cra HashMap placeholders = new HashMap<>(); placeholders.put("%crate%", crate.getName()); - placeholders.put("%key%", crate.getKey().getItemMeta().getDisplayName()); + placeholders.put("%key%", crate.getKeyName()); placeholders.put("%amount%", String.valueOf(amount)); placeholders.put("%player%", player.getName()); @@ -115,18 +116,18 @@ public void onPlayerTransferKeys(Player sender, @Suggestion("crates") String cra player.sendMessage(Messages.transfer_received_keys.getMessage(placeholders).toString()); - this.eventLogger.logKeyEvent(player, sender, crate, KeyType.virtual_key, EventLogger.KeyEventType.KEY_EVENT_RECEIVED, this.config.getProperty(ConfigKeys.log_to_file), this.config.getProperty(ConfigKeys.log_to_console)); + EventManager.logKeyEvent(player, sender, crate, KeyType.virtual_key, EventManager.KeyEventType.KEY_EVENT_RECEIVED, this.config.getProperty(ConfigKeys.log_to_file), this.config.getProperty(ConfigKeys.log_to_console)); } /** * Get keys from player or sender or other player. * - * @param player player to get keys. - * @param sender sender to send message to. - * @param header header of the message. + * @param player player to get keys. + * @param sender sender to send message to. + * @param header header of the message. * @param messageContent content of the message. */ - private void getKeys(Player player, CommandSender sender, String header, String messageContent) { + private void getKeys(OfflinePlayer player, CommandSender sender, String header, String messageContent) { List message = Lists.newArrayList(); message.add(header);