0

Note: I will provide bits and pieces of code along with psuedocode. If this is not enough information let me now and I can link the full code.

I am attempting to create a sort of event that fires when a player incants a spell (full disclosure: I am coding this for Minecraft). My plan is to make a spell interface, then have each spell implement that interface. Spells might be things like LeapSpell HealSpell and RunAwaySpell.

The Spell (it is not actually called spell for style reasons) interface is fairly simple:

public interface Flashpaper {
    public void use(Player p);
    public int getCost();
}

I will add more methods as I get farther into the spell utilities, but for now the ability to be cast, and the ability to return the spells Mana cost is good enough.

The issues start to pile up though when I try and USE the spell.

In the class that handles events (how I get this line of code to fire has been omitted as it is not relevant) I write this:

LeapFlashpaper.use((Player) event.getPlayer());

The class LeapFlashpaper is one of those "spells" that extends the original Flashpaper interface. The issue is that now eclipse complains, saying that the method should be made Static.

Changing the method to static breaks the interface, as despite running java8 eclipse won't allow static methods inside interfaces.

Am I misunderstanding interfaces? This is my first time using one, and I thought this was a good opportunity to use one. Each time I make a new spell, the basic methods will all be there. This was my way of making sure each new spell has the correct methods.

So I ask again: am I misunderstanding something here? Am I trying to use interfaces for something they were not meant to be used for... or... yeah, whats my issue?

Please make any comments you like as I am sort of lost on whether I am doing something really idiotic or not...

SirLich
  • 79
  • 1
  • 12
  • 1
    You are using the class directly. `LeapFlashpaper...` you should instance it first then use the method I take that it is something like `public class LeapFlashpaper implements Flashpaper` so you need: `Flashpaper leapFlashpaper = new LeapFlashpaper();` then use the method with this instance – Jorge Campos Mar 04 '17 at 01:08
  • 1
    You need to create an instance of LeapFlashpaper – Jared Rummler Mar 04 '17 at 01:08
  • 2
    _"If this is not enough information let me now and I can link the full code."_ -- If your code is too large to post, create a [mcve] demonstrating your issue. You will probably figure out the problem while creating the MCVE. – Jim Garrison Mar 04 '17 at 02:18
  • All good suggestions! Thank you. Unless anybody has any objections, I shall answer my own question and accept it as correct so as to help anyone else who wanders here. – SirLich Mar 04 '17 at 02:24

0 Answers0