All the things i try dont work! I just want a list like : FireBeam IceBeam WaterBeam and that if a player right clicks a woodensword he scrolls trough it and if it hits the end and the player right clicks again it will start over! And it will say what spell selected If the player leftclicks (swings with the sword) it will activates the Spell
From what you posted there is one very useful resource for you: http://forums.bukkit.org/forums/plugin-requests.13/
Your thread seems like a request, sorry - I misread it. I'd do it by making a HashMap with String and Integer, then an array showing how many spells there are. Add 1 every time he right clicks and then do checks if(selectedint.contains(5)){ //fire } etc. When the int gets to your arrays size set it to 1 again. My example won't work, I forgot how to get an int from a HashMap and I am on phone
I mean why wouldt this WORK!!!! Code:java public HashMap<Player, Integer> Test = new HashMap<Player, Integer>(); @EventHandler public void MagicTest1 (PlayerInteractEvent event){ if (event.getAction() == Action.RIGHT_CLICK_AIR){ Player p = event.getPlayer(); if (p.getItemInHand().getType() == Material.ENCHANTED_BOOK){ Test.put(p, Test.get(p)+1); p.sendMessage("Test = "+Test.get(p)); } } }
Norbu10 What doesn't work exactly? Do you get an error? Does nothing happen? Are you sure any of that code is executed? Also, it's generally better to store the player's name rather than the Player object.
Norbu10 Try this, and let me know which numbers are said in the console Code: public HashMap<Player, Integer> Test = new HashMap<Player, Integer>(); @EventHandler public void MagicTest1 (PlayerInteractEvent event){ System.out.println("1"); if (event.getAction() == Action.RIGHT_CLICK_AIR){ Player p = event.getPlayer(); System.out.println("2"); if (p.getItemInHand().getType() == Material.ENCHANTED_BOOK){ System.out.println("3"); Test.put(p, Test.get(p)+1); p.sendMessage("Test = "+Test.get(p)); } } } EDIT: Mysticate Why can't you compare with ==?
Norbu10 Do you happen to get any errors in console? Also, you never check if Test contains the player - you just assume that it does (which will most likely cause problems)
Print the hashmap out then and see if you got added to it. Also So instead of doing "Player, Integer" do "String, Integer". Then instead of "p" do "p.getName()".
Norbu10 He's correct, before increasing it by 1 make sure they are in the HashMap. Code example: Code:java if(spells.containsKey(p.getName()){ spells.put(p.getName(), spells.get(p.getName())+1);} else { spells.put(p.getName(), 1);}
I think i made a stupid mistake (It wont say what spell it is It only says : Spell Selected ------------------------) Code:java public HashMap<String, Integer> Test = new HashMap<String, Integer>(); @EventHandler public void MagicTest1 (PlayerInteractEvent event){ System.out.println("1"); if (event.getAction() == Action.RIGHT_CLICK_AIR){ Player p = event.getPlayer(); System.out.println("2"); if (p.getItemInHand().getType() == Material.ENCHANTED_BOOK){ System.out.println("3"); if(Test.containsKey(p.getName())){ if (Test.get(p.getName()) == 2){ Test.put(p.getName(), 1); } else { Test.put(p.getName(), Test.get(p.getName())+1); } } else { Test.put(p.getName(), 1); } p.sendMessage(ChatColor.GOLD+" Spell Selected:"); p.sendMessage(ChatColor.GRAY+""+ChatColor.STRIKETHROUGH+"---------------"); if(Slot.get(p.getName()) == 1){ p.sendMessage(ChatColor.GREEN+"FireBeam"); } else if(Slot.get(p.getName()) == 2){ p.sendMessage(ChatColor.GREEN+"WaterBeam"); } } } } SOLVED! Dont know how to change the status :\ EDIT by Moderator: merged posts, please use the edit button instead of double posting.