Skip to content

Commit

Permalink
Add /hat command (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
PainOchoco authored May 10, 2024
1 parent 1729e23 commit d6c06ad
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.laboulangerie.laboulangeriecore.betonquest.MayorCondition;
import net.laboulangerie.laboulangeriecore.betonquest.RankCondition;
import net.laboulangerie.laboulangeriecore.commands.CoreCommand;
import net.laboulangerie.laboulangeriecore.commands.HatCommand;
import net.laboulangerie.laboulangeriecore.commands.LinkCommands;
import net.laboulangerie.laboulangeriecore.commands.RealNameCommand;
import net.laboulangerie.laboulangeriecore.commands.SeenCmd;
Expand Down Expand Up @@ -145,6 +146,7 @@ public void onEnable() {
getCommand("event").setExecutor(new EventCmd());
getCommand("speed").setExecutor(new SpeedCommand());
getCommand("realname").setExecutor(new RealNameCommand());
getCommand("hat").setExecutor(new HatCommand());
// Link or simple message commands
getCommand("wiki").setExecutor(new LinkCommands());
getCommand("youtube").setExecutor(new LinkCommands());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package net.laboulangerie.laboulangeriecore.commands;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

public class HatCommand implements CommandExecutor {

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String alias,
@NotNull String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("Vous devez être un joueur pour faire /hat.");
return true;
}

Player player = (Player) sender;
if (player.getInventory().getItemInMainHand().getType().isAir()) {
player.sendMessage("Vous devez tenir un item dans votre main pour faire /hat.");
return true;
}

ItemStack helmet = player.getInventory().getHelmet();
ItemStack item = player.getInventory().getItemInMainHand();

player.getInventory().setHelmet(item);
player.getInventory().setItemInMainHand(helmet);

return true;
}

}

0 comments on commit d6c06ad

Please sign in to comment.