bbruno5
bbruno5

Reputation: 109

error: Class is not abstract and does not override abstract method

Well, I'm trying to compile a java plugin for Bukkit/Spigot, but I'm getting the following error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project Websend: Compilation failure
[ERROR] /home/bruno/spigot/Websend/src/main/java/com/github/websend/WebsendPlayerCommandSender.java:[24,7] error: WebsendPlayerCommandSender is not abstract and does not override abstract method sendTitle(String,String,int,int,int) in Player

The respective parts of the file where's the error (I mean):

public class WebsendPlayerCommandSender implements Player {
/* This class allows tapping into command output from plugins
 * if the output is sent through the commandsender.
 * Note to anyone having compilation problems: Compile against Bukkit, not CraftBukkit.
 *
 * Tap this method(1.6.4): sendRawMessage, sendMessage(String), sendMessage(String[])
 */

    private final Player baseObject;
    private final Plugin commandTargetPlugin;

    public WebsendPlayerCommandSender(Player baseObject, Plugin commandTargetPlugin) {
        this.baseObject = baseObject;
        this.commandTargetPlugin = commandTargetPlugin;
}

    @Override
    public void sendMessage(java.lang.String param0) {
        PluginOutputManager.handleLogRecord(commandTargetPlugin, new LogRecord(Level.INFO, param0));
        baseObject.sendMessage(param0);
    }

    @Override
    public void sendMessage(java.lang.String[] param0) {
        for (String str : param0) {
            PluginOutputManager.handleLogRecord(commandTargetPlugin, new LogRecord(Level.INFO, str));
        }
        baseObject.sendMessage(param0);
    }

    @Override
    public void sendRawMessage(java.lang.String param0) {
        PluginOutputManager.handleLogRecord(commandTargetPlugin, new LogRecord(Level.INFO, param0));
        baseObject.sendRawMessage(param0);
    }

And this:

public void sendTitle(String string, String string1) {
    baseObject.sendTitle(string, string1);
}

The plugin ins't mine, but I need to compile with the correct version of spigot. The problem is that I don't know much about java to solve this error. Can anyone help me?

Upvotes: 1

Views: 10135

Answers (2)

Chandan Purbia
Chandan Purbia

Reputation: 285

If you want to understand the concept then read the whole answer else go to the end and read the block quote for the solution.

An interface in java as its name suggests is just an interface. If we go specifically in java's perspective. Interface are classes with functions declared but not implemented. So when some other class implements that interface that class has to implement all the functions of interface also along with its own functions.

For example

This is an interface in java

public interface Animal {
   public void eat();
   public void travel();
}

This is a class implementing it

public class MammalInt implements Animal {
   @Override
   public void eat() {
      System.out.println("Mammal eats");
   }

   @Override
   public void travel() {
      System.out.println("Mammal travels");
   } 

   public int noOfLegs() {
      return 0;
   }
}

The only rule you should remember when a class implement an interface it has to implement all of the declared functions in interface.

In your code you have already implemented sendMessage and sendRawMessage. Now to remove the error you only have to implement 'sendTitle' as shown in the error.

Upvotes: 5

Malphrush
Malphrush

Reputation: 338

Player is an interface, which contains defined, but unimplemented methods. When

WebsendPlayerCommandSender implements Player

It's basically signing a contract saying that it will implement these methods that Player did not. It seems WebsendPlayerCommandSender has already overidden the sendMessage and sendRawMessage methods within Player. However, there is a method within Player called send Title that looks like this

sendTitle(String string, String string1, int num1, int num2, int num3)

And WebsendPlayerCommandSender has not overridden this method. So you'll have to create something like this:

@Override
public void sendTitle(String string, String string1, int num1, int num2, int num3){
     //Define behavior here
 }

Upvotes: 2

Related Questions