如何为 java 插件文本制作工具提示
how to make a tooltip for java plugins text
我正在尝试为 Minecraft 插件文本制作一个工具提示,所以当鼠标悬停时它会在工具上显示 hi 我一直看到人们使用过时的资源,但我在 Webb 上找不到任何新的资源
package ga.harrytubestudios.helloworld.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import ga.harrytubestudios.helloworld.main;
public class hellocomamnd implements CommandExecutor {
private main plugin;
public hellocomamnd(main plugin) {
this.plugin = plugin;
plugin.getCommand("hello").setExecutor(this);
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)){
sender.sendMessage("player only command");
return true;
}
Player p = (Player) sender ;
p.sendMessage("hi");
return true;
}
}
请帮助我,我找不到任何帮助,我希望这可以帮助任何人
龙头中内置了这种格式
TextComponent test= new TextComponent("hi");
shopfood.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,new ComponentBuilder("hi")).create() ));
p.spigot().sendMessage(test);
一些示例代码,当鼠标悬停在文本上时会出现一些文本,这是答案
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)){
sender.sendMessage("player only command");
return true;
}
Player p = (Player) sender ;
TextComponent test= new TextComponent("hi");
shopfood.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,new ComponentBuilder("hi")).create() ));
p.spigot().sendMessage(test);
return true;
}
}
这是一些示例代码
TextComponent enter-var-name-here = new TextComponent(enter first text);
shopfood.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,new ComponentBuilder(enter-hover-text)).create() ));
p.spigot().sendMessage(enter-var-name-here);
我正在尝试为 Minecraft 插件文本制作一个工具提示,所以当鼠标悬停时它会在工具上显示 hi 我一直看到人们使用过时的资源,但我在 Webb 上找不到任何新的资源
package ga.harrytubestudios.helloworld.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import ga.harrytubestudios.helloworld.main;
public class hellocomamnd implements CommandExecutor {
private main plugin;
public hellocomamnd(main plugin) {
this.plugin = plugin;
plugin.getCommand("hello").setExecutor(this);
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)){
sender.sendMessage("player only command");
return true;
}
Player p = (Player) sender ;
p.sendMessage("hi");
return true;
}
}
请帮助我,我找不到任何帮助,我希望这可以帮助任何人
龙头中内置了这种格式
TextComponent test= new TextComponent("hi");
shopfood.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,new ComponentBuilder("hi")).create() ));
p.spigot().sendMessage(test);
一些示例代码,当鼠标悬停在文本上时会出现一些文本,这是答案
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)){
sender.sendMessage("player only command");
return true;
}
Player p = (Player) sender ;
TextComponent test= new TextComponent("hi");
shopfood.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,new ComponentBuilder("hi")).create() ));
p.spigot().sendMessage(test);
return true;
}
}
这是一些示例代码
TextComponent enter-var-name-here = new TextComponent(enter first text);
shopfood.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,new ComponentBuilder(enter-hover-text)).create() ));
p.spigot().sendMessage(enter-var-name-here);