Bow changer

Discussion in 'Plugin Development' started by PHILLIPS_71, Jun 30, 2013.

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

    PHILLIPS_71

    How would I get a bow to cycle on effects eg: if i were to press shift an left click it would cycle through arrow types like lightning arrow, explosive arrows, flame arrows.
     
  2. Offline

    creatorfromhell

    I would suggest putting all the effects you want as a possibility in an array and then going through each value when they click a certain key or left click(PlayerInteractEvent). Of course, you'd need to add methods to get the effects, then add them, etc.
     
  3. Offline

    CubixCoders

    Code:java
    1.  
    2. //First thing is the hashmap to store the data per player
    3. public Map<String, EnumTypes> current = new HashMap<String, EnumTypes>();
    4. //The class EnumTypes is something you have to make, it's an easy way to keep track of the names and such, or you can just replace EnumTypes with String if you want to use "Fire" instead of EnumTypes.Fire
    5. //Next thing is the method
    6.  
    7. public EnumTypes /*Or String */ cycle(Player player /*The player who is cycling*/){
    8. //Just to make sure the map contains the player
    9. if(!current.containsKey(player.getName()))current.put(player.getName(), EnumTypes.Fire /*Or "Fire" or whatever your types are*/);
    10. //Now the map definitly contains the player
    11. //Let's get what mode the player is on, in case they're not on "Fire"
    12. EnumTypes mode = current.get(player.getName());
    13. //Now we have their mode
    14. //Now we can use this to compare and figure out what to switch it to
    15. if(mode == EnumTypes.Fire){
    16. //They have fire mode
    17. current.put(player.getName(), EnumTypes.Slow);
    18. //Put their mode to Slow
    19. return EnumTypes.Slow;
    20. //Return the current type so that it will stop the method
    21. }
    22. //You can add as many of these checks to change as you want, but i will just use two
    23. //The last one has to return it back to the first mode, or fire for me.
    24. if(mode == EnumTypes.Slow){
    25. current.put(player.getName(), EnumTypes.Fire);
    26. return EnumTypes.Fire;
    27. }
    28.  
    29. //Now just listen for PlayerInteractEvent and check if they are sneaking! (player.isSneaking()) then call this method
    30. }
    31.  

    Hope i helped!
     
Thread Status:
Not open for further replies.

Share This Page