How to make subclasses unique

Discussion in 'Plugin Development' started by TheA13X, Nov 14, 2013.

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

    TheA13X

    Hello People,
    I'm working at a little Test for a SpLaG plugin.

    So I made a Class for the shovel and another one for the egg(the projectile, not the Item).
    My idea was, that when you do a rightclick with the shovel an egg should be fired, and the hitted Block disappears.
    Unfortunately it's don't working and I think it's because the Server can't

    distinguish my SpLaG shovel from a normal one.
    That's how it looks like
    Code:java
    1. //SpLaGSpade.java
    2. public class SplagSpade extends ItemStack{
    3. public SplagSpade(){
    4. this.setType(Material.DIAMOND_SPADE);
    5. this.setDurability((short) 50000);
    6. getItemMeta().setDisplayName("SplagSpade");
    7. this.addEnchantment(Enchantment.DURABILITY, 1);
    8. this.setAmount(1);
    9. }
    10. }

    In fact there aren't any differences.

    So the question stands in the title.
    How to make this classes unique?
     
  2. Offline

    adam753

    You can use the instanceof operator to check class type in Java.
    Code:
    if(someitemstack instanceof SplagSpade) {
    }
    
    Be careful though, this does return true for superclasses - so (mysplagspade instanceof ItemStack) is true.
     
  3. Offline

    TheA13X

    Actually I already done that.
    I just forgot to mention it. Sorry
    MultipleListener.java:
    Code:java
    1. @EventHandler
    2. public void SpadeFireListener(PlayerInteractEvent e){
    3. if(e.getPlayer().getItemInHand()instanceof SplagSpade){
    4. e.getPlayer().launchProjectile(SplagEgg.class);
    5. }
    6. }
    7.  
    8. @EventHandler
    9. public void EggCollision(ProjectileHitEvent e){
    10. if(e.getEntity() instanceof SplagEgg){
    11. e.getEntity().getLocation().getBlock().setType(Material.AIR);
    12. }
    13. }


    Oh. And the problem is, that the spade didn't even launch the egg.
     
Thread Status:
Not open for further replies.

Share This Page