From ec74037f0504a40bf8fad09adebb592de32a0cf7 Mon Sep 17 00:00:00 2001 From: Vatuu <21113232+Vatuu@users.noreply.github.com> Date: Thu, 26 May 2022 21:48:46 +0200 Subject: [PATCH] Added ability to create Iris Wand from WorldEdit selection. --- build.gradle | 2 ++ .../iris/core/commands/CommandObject.java | 27 ++++++++++++---- .../volmit/iris/core/link/WorldEditLink.java | 32 +++++++++++++++++++ .../volmit/iris/core/tools/IrisToolbelt.java | 9 ++---- src/main/resources/plugin.yml | 2 +- 5 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 src/main/java/com/volmit/iris/core/link/WorldEditLink.java diff --git a/build.gradle b/build.gradle index 82e60860b..e5346f5d5 100644 --- a/build.gradle +++ b/build.gradle @@ -74,6 +74,7 @@ repositories { } } maven { url "https://dl.cloudsmith.io/public/arcane/archive/maven/" } + maven { url "https://maven.enginehub.org/repo/" } mavenCentral() mavenLocal() maven { url "https://jitpack.io"} @@ -128,6 +129,7 @@ dependencies { implementation 'io.th0rgal:oraxen:1.94.0' implementation 'org.bukkit:craftbukkit:1.18.2-R0.1-SNAPSHOT:remapped-mojang' implementation 'com.github.LoneDev6:api-itemsadder:3.1.0b' + implementation 'com.sk89q.worldedit:worldedit-bukkit:7.2.9' // Shaded implementation 'com.dfsek:Paralithic:0.4.0' diff --git a/src/main/java/com/volmit/iris/core/commands/CommandObject.java b/src/main/java/com/volmit/iris/core/commands/CommandObject.java index 0bf075bb5..a2c07c359 100644 --- a/src/main/java/com/volmit/iris/core/commands/CommandObject.java +++ b/src/main/java/com/volmit/iris/core/commands/CommandObject.java @@ -18,7 +18,9 @@ package com.volmit.iris.core.commands; +import com.mojang.datafixers.util.Pair; import com.volmit.iris.Iris; +import com.volmit.iris.core.link.WorldEditLink; import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.core.service.ObjectSVC; import com.volmit.iris.core.service.StudioSVC; @@ -41,12 +43,7 @@ import com.volmit.iris.util.format.C; import com.volmit.iris.util.math.Direction; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.scheduling.Queue; -import org.bukkit.ChatColor; -import org.bukkit.HeightMap; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.World; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.block.TileState; @@ -426,6 +423,24 @@ public class CommandObject implements DecreeExecutor { sender().sendMessage("Reverted " + actualReverts + " pastes!"); } + @Decree(description = "Gets an object wand and grabs the current WorldEdit selection.", aliases = "we", origin = DecreeOrigin.PLAYER, studio = true) + public void we() { + if(!Bukkit.getPluginManager().isPluginEnabled("WorldEdit")) { + sender().sendMessage(C.RED + "You can't get a WorldEdit selection without WorldEdit, you know."); + return; + } + + Pair locs = WorldEditLink.getSelection(sender().player()); + if(locs.getFirst() == null) + sender().sendMessage(C.RED + "You don't have a WorldEdit selection!"); + else if(locs.getSecond() == null) + sender().sendMessage(C.RED + "You need a valid WorldRegion selection in the current world!"); + else { + sender().player().getInventory().addItem(WandSVC.createWand(locs.getFirst(), locs.getSecond())); + sender().sendMessage(C.GREEN + "A fresh wand with your current WorldEdit selection on it!"); + } + } + @Decree(description = "Get an object wand", sync = true) public void wand() { player().getInventory().addItem(WandSVC.createWand()); diff --git a/src/main/java/com/volmit/iris/core/link/WorldEditLink.java b/src/main/java/com/volmit/iris/core/link/WorldEditLink.java new file mode 100644 index 000000000..eaebb1810 --- /dev/null +++ b/src/main/java/com/volmit/iris/core/link/WorldEditLink.java @@ -0,0 +1,32 @@ +package com.volmit.iris.core.link; + +import com.mojang.datafixers.util.Pair; +import com.sk89q.worldedit.IncompleteRegionException; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.Region; +import com.sk89q.worldedit.session.MissingSessionException; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +public class WorldEditLink { + + public static Pair getSelection(Player p) { + LocalSession session = WorldEdit.getInstance().getSessionManager().getIfPresent(BukkitAdapter.adapt(p)); + try { + if(session == null) + throw new MissingSessionException(); + Region r = session.getSelection(BukkitAdapter.adapt(p.getWorld())); + BlockVector3 p1 = r.getMinimumPoint(); + BlockVector3 p2 = r.getMaximumPoint(); + return new Pair<>(new Location(p.getWorld(), p1.getX(), p1.getY(), p1.getZ()), new Location(p.getWorld(), p2.getX(), p2.getY(), p2.getZ())); + } catch(MissingSessionException e) { + return new Pair<>(null, new Location(null, 0, 0, 0)); + } catch(IncompleteRegionException e) { + return new Pair<>(new Location(null, 0, 0, 0), null); + } + + } +} diff --git a/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java b/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java index fba7fc07a..ece0c942d 100644 --- a/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java +++ b/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java @@ -233,20 +233,17 @@ public class IrisToolbelt { return isIrisWorld(i) && access(i).isStudio(); } - public static void retainMantleDataForSlice(String className) - { + public static void retainMantleDataForSlice(String className) { toolbeltConfiguration.put("retain.mantle." + className, true); } - public static T getMantleData(World world, int x, int y, int z, Class of) - { + public static T getMantleData(World world, int x, int y, int z, Class of) { PlatformChunkGenerator e = access(world); if(e == null) {return null;} return e.getEngine().getMantle().getMantle().get(x, y - world.getMinHeight(), z, of); } - public static void deleteMantleData(World world, int x, int y, int z, Class of) - { + public static void deleteMantleData(World world, int x, int y, int z, Class of) { PlatformChunkGenerator e = access(world); if(e == null) {return;} e.getEngine().getMantle().getMantle().remove(x, y - world.getMinHeight(), z, of); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 90814f4b2..bdc0fb9c9 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -22,4 +22,4 @@ commands: aliases: [ ir, irs ] api-version: ${apiversion} hotload-dependencies: false -softdepend: [ "Oraxen", "ItemsAdder", "IrisFeller"] \ No newline at end of file +softdepend: [ "Oraxen", "ItemsAdder", "IrisFeller", "WorldEdit"] \ No newline at end of file