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?
Advertisement
Answer
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
andsendRawMessage
. Now to remove the error you only have to implement ‘sendTitle’ as shown in the error.