From 0d2c4c0825172e7173f36c960bbfdd59b4dd1b9a Mon Sep 17 00:00:00 2001 From: N0tMyFaultOG Date: Fri, 13 Nov 2020 21:54:46 +0100 Subject: [PATCH] Make block positions copy on click for //size 6925d3715a6c6992d01ab1d4b5564bb9535b6711 Co-Authored-By: Lewis B <17665267+lewisjb@users.noreply.github.com> --- .../java/com/sk89q/worldedit/math/BlockVector2.java | 8 ++++++++ .../java/com/sk89q/worldedit/math/BlockVector3.java | 8 ++++++++ .../main/java/com/sk89q/worldedit/math/Vector2.java | 8 ++++++++ .../main/java/com/sk89q/worldedit/math/Vector3.java | 8 ++++++++ .../regions/selector/CuboidRegionSelector.java | 10 ++++++++-- .../regions/selector/CylinderRegionSelector.java | 7 ++++++- .../regions/selector/EllipsoidRegionSelector.java | 6 +++++- 7 files changed, 51 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 390e4fd87..48c579ac8 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 @@ -610,4 +610,12 @@ public class BlockVector2 { 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 6cd3600c0..801cdece1 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 @@ -787,6 +787,14 @@ public abstract class BlockVector3 { return "(" + getX() + ", " + getY() + ", " + getZ() + ")"; } + /** + * Returns a string representation that is supported by the parser. + * @return string + */ + public String toParserString() { + return getX() + "," + getY() + "," + getZ(); + } + //Used by VS fork public BlockVector3 plus(BlockVector3 other) { return add(other); 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 3eabbcf40..f2e418b4d 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 @@ -478,4 +478,12 @@ public final class Vector2 { 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 11ef929c3..79469ae54 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 @@ -639,4 +639,12 @@ public abstract class Vector3 { return "(" + x + ", " + y + ", " + z + ")"; } + /** + * Returns a string representation that is supported by the parser. + * @return string + */ + public String toParserString() { + return getX() + "," + getY() + "," + getZ(); + } + } 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 20759cd1a..cb90aacd3 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.regions.selector.limit.SelectorLimits; 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; @@ -256,11 +258,15 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion { 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 444b7c0cd..43df6ef09 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.regions.selector.limit.SelectorLimits; 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; @@ -249,7 +251,10 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion { 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.regions.selector.limit.SelectorLimits; 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 class EllipsoidRegionSelector implements RegionSelector, CUIRegion { 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();