May I suggest using something like "<yourplugin>.Events.HeroSword" etc. And then do your onRightClick(), onLeftClick() Or <yourplugin>.Events.SpecialSwords, <yourplugin>.Events.SpecialPicks, etc. And have your custom Items in each class, sorted by the items type? Just some ideas!
You should look into polymorphism http://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html More info http://docs.oracle.com/javase/tutorial/java/concepts/index.html
Derpiee Thanks. I read it, and understood a bit. But would be much faster, if you could give me example like main class "Scroll" (item that you right click and it does something) , that i could use it to extend it. Would be great if i could get full example. (Main class and the sub(item) class). I made abstract main, and sub class, that has "onRightClick" method. How should i call method, from each class based on item. Should i create hashmap, and store all item instances, and key would be its displayName? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
HariHD I wrote it by my self, thnx to Derpiee, now i need suggestion, how to finish it. How should i call events (onRightClick) from each item class, based on the item. I had idea, to store all items instances to hashmap, and use key it's unique displayname. That i could point in event to the class.
I wrote a quick example Main.java Code:java package com.derpiee.swords; import org.bukkit.Bukkit;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.entity.EntityDamageByEntityEvent;import org.bukkit.plugin.java.JavaPlugin; public class Main extends JavaPlugin implements Listener{ public void onEnable() {//Register Events and call addSwordsBukkit.getPluginManager().registerEvents(this, this);addSwords();} public void addSwords() {//Add the subclasses to the arraylistSword.swords.add(new AmazingSword());} @EventHandlerpublic void onPlayerHitPlayer(EntityDamageByEntityEvent event) {//Check if the one that caused the damage is a playerif(event.getDamager() instanceof Player) {//Grab the one that caused the damagePlayer p = (Player) event.getDamager();//Iterate through all the swordsfor(Sword sword : Sword.swords) {//Check to see if the item in hand is one of the sword types we haveif(p.getItemInHand().getType().equals(sword.getSwordType())){//Checks to see if the item has item meta(Custom name)if(p.getItemInHand().hasItemMeta()){//Checks to see if the display name of the item is one that we have in our Swordsif(p.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase(sword.getName())) {//Call the method onPlayerHitsword.onPlayerHit(event);}}}}} }} Sword.java Code:java package com.derpiee.swords; import java.util.ArrayList; import org.bukkit.Material;import org.bukkit.event.entity.EntityDamageByEntityEvent; public abstract class Sword { //Sword Namepublic String name; //Sword Type (Diamond, Iron, Wood, etc..)public Material swordType; //Array List containing all of the subclassespublic static ArrayList<Sword> swords = new ArrayList<Sword>(); public Sword(String name, Material swordType) {this.name = name;this.swordType = swordType;} //Abstract method for when hitting an entitypublic abstract void onPlayerHit(EntityDamageByEntityEvent event); //Get the sword namepublic String getName() {return name;} //Get the sword typepublic Material getSwordType() {return swordType;}} AmazingSword.java Code:java package com.derpiee.swords; import org.bukkit.Material;import org.bukkit.entity.Entity;import org.bukkit.event.entity.EntityDamageByEntityEvent; public class AmazingSword extends Sword { public AmazingSword() {super("Amazing", Material.DIAMOND_SWORD);} @Overridepublic void onPlayerHit(EntityDamageByEntityEvent event) {//Get the damaged entityEntity entity = event.getEntity(); //Create an explosion (0F so the explosion does no damage to the world)entity.getWorld().createExplosion(entity.getLocation(), 0F);} }