Solved interfaces is my theory fine?

Discussion in 'Plugin Development' started by xize, Aug 17, 2014.

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

    xize

    Hello,

    so I'm trying to make a seperate api of my plugin but I think my theory how interfaces work is wrong or I'm clearly missing something.

    so lets say I got a class from the main plugin not the seperated api:

    Code:
    public class EssentialsPlayer implements InterfacePlayer {
       public void sentHello(String bla) {
                 System.out.println(bla);
       }
    } 
    
    the Interface which I implement is not included in the real plugin but provided through a maven dependency which is suposed to be the api.

    now in the external api I make the interface InterfacePlayer:

    Code:
    public interface InterfacePlayer {
        public void sentHello(String bla);
    }
    
    so if my theory is correct, when a dev uses my external api and compiles it and uses my normal plugin on his server it will autmaticly use EssentialsPlayer even though the interface is not included in the plugin?

    its sort of confusing understanding this principe, if you don't understand what I'm trying to archieve please look how bukkit it does:

    https://github.com/Bukkit/CraftBukk...rg/bukkit/craftbukkit/entity/CraftPlayer.java

    https://github.com/Bukkit/Bukkit/blob/master/src/main/java/org/bukkit/entity/Player.java

    this makes me super confused about interfaces:p

    thanks for the help:)
     
  2. Offline

    AoH_Ruthless

    xize
    To achieve what Bukkit does, I think* that developers using your API need to modify InterfacePlayer. Then in your code, where you implement InterfacePlayer into EssentialsPlayer, those mehtods will be overrided.

    I believe this is what Bukkit API does:
    1. Provides you interface (Player)
    2. You can modify aspects of the Player (i.e setHealth(Double) ... )
    3. When CraftPlayer is created in CB, it modifies according to Player (because CP is an implementation of Player).
    So like I said, to model this means the API should allow access to InterfacePlayer, but not to EssentialsPlayer.

    * If I know what you are talking about correctly.
     
    xize likes this.
  3. Offline

    xize

    AoH_Ruthless

    aha I understand it, I just checked the craftbukkit jar it self and it looks the bukkit api or atleast the Player interface is shaded now I see why it makes sense, because I was seeing imports from the bukkit api in CraftPlayer but I couldn't find the Player interface in the craftbukkit github source, I was worried interfaces worked even when the class didn't existed but I was wrong:p

    thanks for the explanation very appreciated:)
     
Thread Status:
Not open for further replies.

Share This Page