Skip to content

Commit

Permalink
Melhoria do comando /chaves ver
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBedrock committed Feb 12, 2024
1 parent 14a02d7 commit 8bbdc6a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion paper/run/server.properties
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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();

Expand All @@ -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<String, String> 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")
Expand Down Expand Up @@ -105,7 +106,7 @@ public void onPlayerTransferKeys(Player sender, @Suggestion("crates") String cra
HashMap<String, String> 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());

Expand All @@ -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<String> message = Lists.newArrayList();

message.add(header);
Expand Down

0 comments on commit 8bbdc6a

Please sign in to comment.