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
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.
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.
Ok so here's the bows method that just returns the bow itemstacks: Code:java public ItemStack getBow(Integer bownumber, Player p){ if(bownumber == 1){ if(p.hasPermission("bow.1")){ ItemStack is = new ItemStack(Material.BOW, 1); is.addEnchantment(Enchantment.ARROW_DAMAGE, 1); return is; } } if(bownumber == 2){ if(p.hasPermission("bow.2")){ ItemStack is = new ItemStack(Material.BOW, 1); is.addEnchantment(Enchantment.ARROW_FIRE, 1); return is; } } return new ItemStack(Material.BOW, 1); } And here's the looper through it that can be called on the player left clicking: Code:java for(int i = 0; i < 3; i++){ //replace < 3 with <#ofbows if(p.getItemInHand() == getBow(1, p)){ i = 1; } if(p.getItemInHand() == getBow(2, p)){ i = 2; } if(p.getItemInHand() != getBow(1, p) && p.getItemInHand() != getBow(2, p)){ i = 0; } getBow(i++, p); //get's the next bow break; } 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.
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 public class Stuff { static List<BowType> types = new ArrayList<BowType>(Arrays.asList(BowType.values())); static HashMap<UUID, BowType> playersCurrentBowType = new HashMap<UUID, BowType>(); public static BowType getNextBowType(Player player) { BowType type = playersCurrentBowType.get(player.getUUID()); // Get player's current bow type int index = types.indexOf(type); // Index of current bow type final int startIndex = index; // Start index index = (index == types.size() - 1) ? 0 : index + 1; // Set next index while (!player.hasPermision( "myplugin.bowtype." + (type = types.get(index)).getTypeName() )) { // While player does not have permission for the next bow type index = (index == types.size() - 1) ? 0 : index + 1; // Set next index if (index == startIndex) { return null; // No next bow type, player only has one allowed bow type } } playersCurrentBowType.put(player.getUUID(), type); return type; }}enum BowType { TYPE_1, TYPE_2, TYPE_3, TYPE_4, TYPE_5 ; public String getTypeName() { return this.toString(); } }
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.