Swift potion

Discussion in 'Spigot Plugin Development' started by jessegeerts, May 5, 2015.

  1. Hey guys i want to add an item on join that gives you an speed potion that allows to enable and disable the speed potion and sends to the player enabled etc

    This is what i currently have:

    Code (Text):


    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.inventory.meta.ItemMeta;

    public class JoinHandler implements Listener {

        @EventHandler
        public void join(PlayerJoinEvent e) {
         
               Player p = e.getPlayer();
             
               PlayerInventory pi = p.getInventory();
             

               p.teleport(new Location(Bukkit.getWorld("world"), 0.5D, 141.0D, 0.5D));
             

               pi.clear();
             

               ItemStack compass = new ItemStack(Material.COMPASS);
               ItemMeta compassmeta = compass.getItemMeta();
               compassmeta.setDisplayName(ChatColor.DARK_PURPLE + "§lServer Selector");
               compass.setItemMeta(compassmeta);
             
               ItemStack diamond = new ItemStack(Material.DIAMOND);
               ItemMeta diamondmeta = diamond.getItemMeta();
               diamondmeta.setDisplayName(ChatColor.AQUA + "§lServer Store");
               diamond.setItemMeta(diamondmeta);
             
               ItemStack speedpotion = new ItemStack(Material.POTIONS.SWIFT)
             
             
               pi.setItem(0, compass);
             
               {
               e.setJoinMessage(ChatColor.BLUE + "[" + ChatColor.GREEN + "+" + ChatColor.BLUE + "] " + ChatColor.RED +  p.getPlayer().getName());
             
             }
        }
    }
     
    Thanks for advance!
     
  2. What I would do is making methods with Itemstacks and return the itemstack. And the potion I would make with Potion p = new Potion etc..

    Then with a interactevent and a HashMap with String, Boolean. And when he right clicks/left clicks the item add him to to hashmap (enabling) and if he already contains remove him. (disabling)
     
  3. code?
     
  4. @jesseke55
    • Create ItemStack fields for all your ItemStacks you want to give on join.
    • Create a constructor for your class (doesn't have to take any parameters).
    • Create the ItemStacks in the constructor, and assign them to the fields.
    • In the join event handler, give the ItemStacks.
    • In the interact event handler, use ItemStack#isSimilar(ItemStack) or ItemStack#equals(ItemStack) to check if any of the items is used. Then act accordingly (give them the speed potion, etc.)
    Write it yourself, that will teach you more.

    Map<K, Boolean> is just a Set<K>
     
  5. still difficuilt :(
     
  6. Welcome to development. Even if we spoon feed you this problem, you will be stuck with the next. What have you accomplished, and what are you stuck with?
     
  7. Bake me some cookies... aha
     
    • Funny Funny x 1
  8. I am stuck with adding an speed potion as join item that allows to get unlimited time with speed potion 2 and you can turn it on and off but sends an message to the player that is enabled or disabled
     
  9. I'll post my code when i am on my laptop
     
  10. current code of join items:
    Code (Text):

    package nl.CraftedNetworkHub;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.inventory.meta.ItemMeta;

    public class JoinHandler implements Listener {

        @EventHandler
        public void join(PlayerJoinEvent e) {
           
               Player p = e.getPlayer();
               
               PlayerInventory pi = p.getInventory();
               

               p.teleport(new Location(Bukkit.getWorld("world"), 0.5D, 141.0D, 0.5D));
               

               pi.clear();
               

               ItemStack compass = new ItemStack(Material.COMPASS);
               ItemMeta compassmeta = compass.getItemMeta();
               compassmeta.setDisplayName(ChatColor.DARK_PURPLE + "§lServer Selector");
               compass.setItemMeta(compassmeta);
               
               ItemStack diamond = new ItemStack(Material.DIAMOND);
               ItemMeta diamondmeta = diamond.getItemMeta();
               diamondmeta.setDisplayName(ChatColor.AQUA + "§lServer Store");
               diamond.setItemMeta(diamondmeta);
               
               ItemStack speedpotion = new ItemStack(Material.SWIFT_POTION);
               ItemMeta speedpotionmeta = speedpotion.getItemMeta();
               speedpotionmeta.setDisplayName(ChatColor.GREEN + "§lSpeed Boost");
               speedpotion.setItemMeta(speedpotionmeta);
               
               
               pi.setItem(0, compass);
               pi.setItem(1, diamond);
               pi.setItem(2, speedpotion);
               
               {
               e.setJoinMessage(ChatColor.BLUE + "[" + ChatColor.GREEN + "+" + ChatColor.BLUE + "] " + ChatColor.RED +  p.getPlayer().getName());
               
             }
        }
    }
     
     
    • Make a HashMap<String(playerame), Boolean>
    • Make a interactevent
    • Check if the player makes an action on a speedpotion
    • Check if the hashmap value is false > then put it to true en send him a message with speed etc.
    • Else put him in the hashmap with true en send him a message en disable speed.
    This is how I would do it, you need to read JavaDocs (if u dont know) to see how to make a hashmap or how to create a interactevent etc.

    EDIT: Use a Set<String(playername)>
     
    #11 Svenna, May 6, 2015
    Last edited: May 6, 2015
  11. @Svenna read my post above, the part where I quoted you.
     
  12. Oh yeah, shit. That is the same. Dont thaught about that xD