Click to copy repeater

Also added translation for copying
This commit is contained in:
Minecon724 2024-12-31 18:15:09 +01:00
parent 1acfcd273d
commit 812b16e4be
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
3 changed files with 19 additions and 4 deletions

View file

@ -6,6 +6,7 @@
package eu.m724.tweaks.auth; package eu.m724.tweaks.auth;
import eu.m724.tweaks.Language;
import eu.m724.tweaks.TweaksConfig; import eu.m724.tweaks.TweaksConfig;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.BaseComponent;
@ -50,7 +51,7 @@ public class AuthCommands implements CommandExecutor {
.underlined(true) .underlined(true)
.color(ChatColor.GRAY) .color(ChatColor.GRAY)
.event(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, hostname)) .event(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, hostname))
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("Click to copy"))) .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(Language.getString("clickToCopy"))))
.build(); .build();
sender.spigot().sendMessage(component); sender.spigot().sendMessage(component);
} else { } else {

View file

@ -7,6 +7,12 @@
package eu.m724.tweaks.redstone; package eu.m724.tweaks.redstone;
import eu.m724.tweaks.DebugLogger; import eu.m724.tweaks.DebugLogger;
import eu.m724.tweaks.Language;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.hover.content.Text;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
@ -45,13 +51,19 @@ public class RedstoneListener implements Listener {
@EventHandler @EventHandler
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
if (event.getClickedBlock() == null) return; if (!event.getPlayer().isSneaking()) return;
var id = redstoneRepeaters.getId(event.getClickedBlock()); var id = redstoneRepeaters.getId(event.getClickedBlock());
if (id == Integer.MIN_VALUE) return; if (id == Integer.MIN_VALUE) return;
// TODO find a less lame way of showing ID // TODO find a less lame way of showing ID
event.getPlayer().sendMessage("Repeater ID: " + id); var component = new ComponentBuilder("Repeater ID: ").color(ChatColor.GOLD)
.append(String.valueOf(id)).color(ChatColor.AQUA)
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(Language.getString("clickToCopy"))))
.event(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, String.valueOf(id)))
.build();
event.getPlayer().spigot().sendMessage(component);
} }
@EventHandler @EventHandler

View file

@ -31,3 +31,5 @@ authKickWrongKey = You're connecting to the wrong server address. You must conne
authKickUnregistered = You are not whitelisted on this server! authKickUnregistered = You are not whitelisted on this server!
retstoneBlockItem = Online redstone block retstoneBlockItem = Online redstone block
clickToCopy = Click to copy to clipboard