Code to switch hats repetitively

Discussion in 'Plugin Development' started by kreashenz, Jan 30, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    kreashenz

    Looking for a code to switch hats repetitively and quickly, switching from red-wool to blue-wool to something else etc. and also where that would lie in this code. Run through a command, also.
    Code:
    package me.kreashenz.PartyHats;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Hats extends JavaPlugin implements Listener {
        String prefix;
        @Override
        public void onEnable(){
            this.getServer().getPluginManager().registerEvents(this, this);
            getLogger().info(ChatColor.BLACK + "[" + ChatColor.GOLD + "HardHat" + ChatColor.BLACK + "] " + ChatColor.YELLOW + "has been enabled.");
        this.prefix = (ChatColor.BLACK + "[" + ChatColor.GOLD + "HardHat" + ChatColor.BLACK + "] " + ChatColor.YELLOW);
        }
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (cmd.getName().equalsIgnoreCase("partyhats")){
            if (args.length == 0) {
                sendHelp((Player)sender);
            }
            else if (args.length == 1) {
                if (args[0].equalsIgnoreCase("partyhat2")) {
        }
        return true;
        }
    public void sendHelp(Player player) {
        player.sendMessage(ChatColor.AQUA + "----------------------" + ChatColor.GOLD + "PartyHats" + ChatColor.AQUA + "----------------------");
        player.sendMessage(this.prefix + "/partyhat1 :" + ChatColor.GOLD + " wear your party hat!");
    }
    }
     
  2. Offline

    chasechocolate

    Probably not the best way to do it, but this is what I can think up right now :p
    Code:java
    1. public void addPartyHat(final Player player){
    2. new BukkitRunnable(){
    3. int i = 0;
    4. @Override
    5. public void run(){
    6. PlayerInventory playerInv = player.getInventory();
    7. if(i == 0){
    8. playerInv.setHelmet(<your itemstack>);
    9. i = 1;
    10. } else if(i == 1){
    11. player.Inv.setHelmet(<your itemstack>);
    12. i = 0;
    13. }
    14. }
    15. }.runTaskTimer(<plugin instance>, 0L, <delay in ticks>);
    16. }
     
  3. Offline

    kreashenz

    chasechocolate That didnt work, it had a bunch of errors , I tried fixing but nothing.. and yes, I did replace <itemstack> to what i wanted and the <delay> to what i wanted.
     
  4. Offline

    chasechocolate

    What errors do you get? I wrote the code without an IDE, so it may not be perfect.
     
  5. Offline

    ImTheFool

    May want to add
    Code:
    if (player.isValid())
    to that. Also, change
    Code:
    player.Inv.setHelmet
    to
    Code:
    playerInv.setHelmet
    I think.
     
  6. Offline

    kreashenz

    I'm currently editting it a bit, so i lost the errors, but so far, it was things about extra } and missed brackets and stuff..
     
Thread Status:
Not open for further replies.

Share This Page