From 6925d3715a6c6992d01ab1d4b5564bb9535b6711 Mon Sep 17 00:00:00 2001 From: Lewis B Date: Sun, 4 Oct 2020 16:08:21 +1000 Subject: [PATCH] Make block positions copy on click for //size (#1546) * Make block positions copy on click for //size * PR feedback --- .../java/com/sk89q/worldedit/math/BlockVector2.java | 8 ++++++++ .../java/com/sk89q/worldedit/math/BlockVector3.java | 7 +++++++ .../main/java/com/sk89q/worldedit/math/Vector2.java | 7 +++++++ .../main/java/com/sk89q/worldedit/math/Vector3.java | 7 +++++++ .../regions/selector/CuboidRegionSelector.java | 10 ++++++++-- .../regions/selector/CylinderRegionSelector.java | 7 ++++++- .../regions/selector/EllipsoidRegionSelector.java | 6 +++++- 7 files changed, 48 insertions(+), 4 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector2.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector2.java index ecc45d40c..aa020ce49 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector2.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector2.java @@ -556,4 +556,12 @@ public int hashCode() { public String toString() { return "(" + x + ", " + z + ")"; } + + /** + * Returns a string representation that is supported by the parser. + * @return string + */ + public String toParserString() { + return x + "," + z; + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java index b9cc8a263..f746c034e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java @@ -705,4 +705,11 @@ public String toString() { return "(" + x + ", " + y + ", " + z + ")"; } + /** + * Returns a string representation that is supported by the parser. + * @return string + */ + public String toParserString() { + return x + "," + y + "," + z; + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector2.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector2.java index a99c9994a..f511f18d2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector2.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector2.java @@ -481,4 +481,11 @@ public String toString() { return "(" + x + ", " + z + ")"; } + /** + * Returns a string representation that is supported by the parser. + * @return string + */ + public String toParserString() { + return x + "," + z; + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java index a9dc8f05c..e100aedea 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java @@ -612,4 +612,11 @@ public String toString() { return "(" + x + ", " + y + ", " + z + ")"; } + /** + * Returns a string representation that is supported by the parser. + * @return string + */ + public String toParserString() { + return x + "," + y + "," + z; + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java index f0398c790..05b1061ec 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java @@ -33,6 +33,8 @@ import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; +import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; import com.sk89q.worldedit.world.World; import java.util.ArrayList; @@ -255,11 +257,15 @@ public List getSelectionInfoLines() { final List lines = new ArrayList<>(); if (position1 != null) { - lines.add(TranslatableComponent.of("worldedit.selection.cuboid.info.pos1", TextComponent.of(position1.toString()))); + lines.add(TranslatableComponent.of("worldedit.selection.cuboid.info.pos1", TextComponent.of(position1.toString()) + .clickEvent(ClickEvent.of(ClickEvent.Action.COPY_TO_CLIPBOARD, position1.toParserString())) + .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to copy"))))); } if (position2 != null) { - lines.add(TranslatableComponent.of("worldedit.selection.cuboid.info.pos2", TextComponent.of(position2.toString()))); + lines.add(TranslatableComponent.of("worldedit.selection.cuboid.info.pos2", TextComponent.of(position2.toString()) + .clickEvent(ClickEvent.of(ClickEvent.Action.COPY_TO_CLIPBOARD, position2.toParserString())) + .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to copy"))))); } return lines; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CylinderRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CylinderRegionSelector.java index 59368998b..9a3409e39 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CylinderRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CylinderRegionSelector.java @@ -37,6 +37,8 @@ import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; +import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; import com.sk89q.worldedit.world.World; import java.text.NumberFormat; @@ -244,7 +246,10 @@ public List getSelectionInfoLines() { final List lines = new ArrayList<>(); if (!region.getCenter().equals(Vector3.ZERO)) { - lines.add(TranslatableComponent.of("worldedit.selection.cylinder.info.center", TextComponent.of(region.getCenter().toString()))); + Vector3 center = region.getCenter(); + lines.add(TranslatableComponent.of("worldedit.selection.cylinder.info.center", TextComponent.of(center.toString()) + .clickEvent(ClickEvent.of(ClickEvent.Action.COPY_TO_CLIPBOARD, center.toParserString())) + .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to copy"))))); } if (!region.getRadius().equals(Vector2.ZERO)) { lines.add(TranslatableComponent.of("worldedit.selection.cylinder.info.radius", TextComponent.of(region.getRadius().toString()))); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/EllipsoidRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/EllipsoidRegionSelector.java index e16a1f30b..93b0cf8b2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/EllipsoidRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/EllipsoidRegionSelector.java @@ -34,6 +34,8 @@ import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; +import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; import com.sk89q.worldedit.world.World; import java.util.ArrayList; @@ -225,7 +227,9 @@ public List getSelectionInfoLines() { final Vector3 center = region.getCenter(); if (center.lengthSq() > 0) { - lines.add(TranslatableComponent.of("worldedit.selection.ellipsoid.info.center", TextComponent.of(center.toString()))); + lines.add(TranslatableComponent.of("worldedit.selection.ellipsoid.info.center", TextComponent.of(center.toString()) + .clickEvent(ClickEvent.of(ClickEvent.Action.COPY_TO_CLIPBOARD, center.toParserString())) + .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to copy"))))); } final Vector3 radius = region.getRadius();