Help with plugin

Discussion in 'Plugin Development' started by PimpDuck, May 18, 2014.

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

    PimpDuck

    Okay, so the plugin I'm making is on left click with a bow it loops through different types of bowtypes. But if the player only has permission for one bowtype, I need to make the loop only between the normal bow and the bow they have permission for. How would i do this?

    Main: http://paste.md-5.net/cosovefebo.java

    PlayerListener: http://paste.md-5.net/fuyenalevo.avrasm

    Please help :D
     
  2. Offline

    JBoss925

    Create a method that returns the itemstack of your bows based on a number you put in. Then you can easily use a for loop to loop through the bows and see if the player has permission for the bow. Then all you must do is start from a given bow to go to the next and when the bow reaches the last one repeat it by setting the number back to the original bow. When you check for the permissions though if they do have permission make sure that you break after it returns the correct bow or else it infinitely loop.
     
  3. Offline

    PimpDuck

    Could I get an example of this using one of the bows, then I'll do the rest from that example? I understand what you're saying, I'm just not sure how I would do the loops.

    JBoss925

    it doesn't change the bow, if you look at the code it changes the arrow JBoss925

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  4. Offline

    JBoss925

    Ok so here's the bows method that just returns the bow itemstacks:
    Code:java
    1. public ItemStack getBow(Integer bownumber, Player p){
    2. if(bownumber == 1){
    3. if(p.hasPermission("bow.1")){
    4. ItemStack is = new ItemStack(Material.BOW, 1);
    5. is.addEnchantment(Enchantment.ARROW_DAMAGE, 1);
    6. return is;
    7. }
    8. }
    9. if(bownumber == 2){
    10. if(p.hasPermission("bow.2")){
    11. ItemStack is = new ItemStack(Material.BOW, 1);
    12. is.addEnchantment(Enchantment.ARROW_FIRE, 1);
    13. return is;
    14. }
    15. }
    16. return new ItemStack(Material.BOW, 1);
    17. }

    And here's the looper through it that can be called on the player left clicking:
    Code:java
    1. for(int i = 0; i < 3; i++){ //replace < 3 with <#ofbows
    2. if(p.getItemInHand() == getBow(1, p)){
    3. i = 1;
    4. }
    5. if(p.getItemInHand() == getBow(2, p)){
    6. i = 2;
    7. }
    8. if(p.getItemInHand() != getBow(1, p) && p.getItemInHand() != getBow(2, p)){
    9. i = 0;
    10. }
    11. getBow(i++, p); //get's the next bow
    12. break;
    13. }


    This particular example uses only 3 bows, the default, the bow1 and bow2.

    Yes I know that, so I just changed the enchantment on the bow that affected the arrows.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  5. Offline

    Polaris29

    I don't really want to read your code because that would take too long, but here's a working example that may help.

    It just loops over the arraylist of bow types until it finds a bow type that the player has permission for
    Code:java
    1.  
    2. public class Stuff {
    3. static List<BowType> types = new ArrayList<BowType>(Arrays.asList(BowType.values()));
    4. static HashMap<UUID, BowType> playersCurrentBowType = new HashMap<UUID, BowType>();
    5.  
    6. public static BowType getNextBowType(Player player) {
    7. BowType type = playersCurrentBowType.get(player.getUUID()); // Get player's current bow type
    8. int index = types.indexOf(type); // Index of current bow type
    9. final int startIndex = index; // Start index
    10. index = (index == types.size() - 1) ? 0 : index + 1; // Set next index
    11.  
    12. while (!player.hasPermision( "myplugin.bowtype." + (type = types.get(index)).getTypeName() )) { // While player does not have permission for the next bow type
    13. index = (index == types.size() - 1) ? 0 : index + 1; // Set next index
    14. if (index == startIndex) {
    15. return null; // No next bow type, player only has one allowed bow type
    16. }
    17. }
    18. playersCurrentBowType.put(player.getUUID(), type);
    19. return type;
    20. }
    21. }
    22. enum BowType {
    23. TYPE_1,
    24. TYPE_2,
    25. TYPE_3,
    26. TYPE_4,
    27. TYPE_5
    28. ;
    29.  
    30. public String getTypeName() {
    31. return this.toString();
    32. }
    33.  
    34. }
    35.  
     
  6. Offline

    PimpDuck

    JBoss925 This isn't working for some reason http://paste.md-5.net/yitosohino.avrasm

    Neither of these codes are working with my code... Can somebody help, please?

    Bump. Anyone? :/

    Can someone please help me :/

    Still need help :/

    Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
Thread Status:
Not open for further replies.

Share This Page