如何为Java插件文本制作工具提示。

huangapple go评论78阅读模式
英文:

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);

huangapple
  • 本文由 发表于 2020年8月13日 22:51:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/63397692.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定