英文:
how to make a tooltip for java plugins text
问题
I'm trying to make a tooltip for a Minecraft plugin text so when hover it shows the hi on the tool I keep seeing people using out of date resources and I can't find any new this on the 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;
}
}
Please help me; I can't find any help, and I hope this can help anyone.
英文:
I'm trying to make a tooltip for a Minecraft plugin text so when hover it shows the hi on the tool I keep seeing people using out of date resources and I can't find any new this on the 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;
}
}
please help me I can't find any help and I hope this can help any one
答案1
得分: 0
以下是翻译好的代码部分:
// 这里内置了一个格式
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("仅限玩家使用的命令");
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);
希望这些翻译对您有所帮助。
英文:
there's this format built into the spigot
TextComponent test= new TextComponent("hi");
shopfood.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,new ComponentBuilder("hi")).create() ));
p.spigot().sendMessage(test);
some sample code and it will so some text when hover on the text and heres the anwser
@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;
}
}
here's some sample code
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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论