I’m actually coding a plugin, in a command it prompts a confirmation message and I want to click a button (on the chat text) for confirming and cancellating. I don’t like to copying and pasting code from others, and I don’t want to use classes from others too. I am trying to use TextComponents but I can’t make it work. Here is the command code
JavaScript
x
package myPackage;
import java.awt.TextComponent;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class InfoCommand implements CommandExecutor {
public TextComponent TextComponent;
@Override
public boolean onCommand(CommandSender sender, Command cmnd, String alias, String[] args) {
if (!(sender instanceof Player)) {
return false;
}
Player player = (Player) sender;
player.sendMessage(new String[] {
"Confirmation message.",
"Do you want to confirm?"});
TextComponent message = new TextComponent ("Yes");
message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/command"));
return true;
}
}
It trows me 3 errors:
TextComponent(String) is not public in TextComponent; cannot be accesed from outside package
(In the line where I define TextComponent)
Cannot find symbol
(In the ClickEvent line)
Package ClickEvent does not exist
(In the ClickEvent line)
How can I solve the errors? There is an easier way to do a clickable buttons (without other classes or copying/pasting)?
Advertisement
Answer
You have 2 problems.
- You’re missing a dependency. Add the following dependency to your pom.xml:
JavaScript
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version><!--change this value depending on the version-->
<type>jar</type>
<scope>provided</scope>
</dependency>
- You have imported
java.awt.TextComponent
in yourInfoCommand
class, which is wrong. So remove that import and add these instead:
JavaScript
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;