Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command /hat #1

Open
wants to merge 3 commits into
base: 1.13
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/main/java/com/spleefleague/commands/commands/hat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import com.spleefleague.annotations.Endpoint;
import com.spleefleague.annotations.LiteralArg;
import com.spleefleague.core.plugin.CorePlugin;
import com.spleefleague.commands.command.BasicCommand;
import com.spleefleague.core.player.Rank;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;

public class hat extends BasicCommand {

public hat(CorePlugin plugin, String name, String usage) {
super(plugin, new hatDispatcher(), name, usage, Rank.MODERATOR);
}

@Endpoint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@endpoint should specify, that this command is only valid for players (command blocks can't give themselves a hat). See other commands like /tp for example usage.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also add an option to set the hat of other players

public void giveHat(Player p) {
final PlayerInventory inv = p.getInventory();
final ItemStack hand = inv.getItemInMainHand();
final ItemStack head = inv.getHelmet();
if(inv.getItemInMainHand().getType() != Material.AIR) {
inv.setItemInMainHand(head);
inv.setHelmet(hand);
success(p, "Enjoy your new hat!");
}else if(head != null && inv.getItemInMainHand().getType() == Material.AIR) {
inv.setHelmet(new ItemStack(Material.AIR));
inv.setItemInMainHand(head);
success(p, "Your hat has been removed!");
}else{
error(p, "You must be holding something!");
}
}

@Endpoint
public void removeHat(Player p, @LiteralArg(value = "remove") String l) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above

final PlayerInventory inv = p.getInventory();
final ItemStack head = inv.getHelmet();
if(head == null || head.getType() == Material.AIR){
error(p, "You are not wearing a hat!");
return;
}
inv.setHelmet(new ItemStack(Material.AIR));
inv.setItemInMainHand(head);
success(p, "Your hat has been removed!");
}
}
6 changes: 5 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,8 @@ commands:
setcheckpoint:
description: Sets or unsets a checkpoint
usage: |
/<command> <target> [x, y, z, yaw, pitch] [duration]
/<command> <target> [x, y, z, yaw, pitch] [duration]
hat:
description: Puts the item in your hand on your head.
usage: |
/<command> [remove]