From 812b16e4be590aa05f50d06af1a7ce0f574abb1d Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Tue, 31 Dec 2024 18:15:09 +0100 Subject: [PATCH] Click to copy repeater Also added translation for copying --- .../java/eu/m724/tweaks/auth/AuthCommands.java | 3 ++- .../m724/tweaks/redstone/RedstoneListener.java | 16 ++++++++++++++-- src/main/resources/strings.properties | 4 +++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/eu/m724/tweaks/auth/AuthCommands.java b/src/main/java/eu/m724/tweaks/auth/AuthCommands.java index 5463fb4..d33767c 100644 --- a/src/main/java/eu/m724/tweaks/auth/AuthCommands.java +++ b/src/main/java/eu/m724/tweaks/auth/AuthCommands.java @@ -6,6 +6,7 @@ package eu.m724.tweaks.auth; +import eu.m724.tweaks.Language; import eu.m724.tweaks.TweaksConfig; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.BaseComponent; @@ -50,7 +51,7 @@ public class AuthCommands implements CommandExecutor { .underlined(true) .color(ChatColor.GRAY) .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(); sender.spigot().sendMessage(component); } else { diff --git a/src/main/java/eu/m724/tweaks/redstone/RedstoneListener.java b/src/main/java/eu/m724/tweaks/redstone/RedstoneListener.java index 1883a49..7cd1ffd 100644 --- a/src/main/java/eu/m724/tweaks/redstone/RedstoneListener.java +++ b/src/main/java/eu/m724/tweaks/redstone/RedstoneListener.java @@ -7,6 +7,12 @@ package eu.m724.tweaks.redstone; 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.Listener; import org.bukkit.event.block.Action; @@ -45,13 +51,19 @@ public class RedstoneListener implements Listener { @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; - if (event.getClickedBlock() == null) return; + if (!event.getPlayer().isSneaking()) return; var id = redstoneRepeaters.getId(event.getClickedBlock()); if (id == Integer.MIN_VALUE) return; // 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 diff --git a/src/main/resources/strings.properties b/src/main/resources/strings.properties index 2be019e..41529fa 100644 --- a/src/main/resources/strings.properties +++ b/src/main/resources/strings.properties @@ -30,4 +30,6 @@ authKickWrongKey = You're connecting to the wrong server address. You must conne # If force is enabled and player is not registered. Changing this reveals you're using this plugin authKickUnregistered = You are not whitelisted on this server! -retstoneBlockItem = Online redstone block \ No newline at end of file +retstoneBlockItem = Online redstone block + +clickToCopy = Click to copy to clipboard \ No newline at end of file