Stop Iris commands from reading WorldEdit selections

Iris commands acted on whatever WorldEdit selection a player had when no Iris wand was held. Only Iris wands count now, and the worldEditWandCUI setting is gone. The dedicated /object we command still grabs a WorldEdit selection.

Upstream: c53e9f826
This commit is contained in:
piexel committed 2026-11-10 01:23:58 +01:00
1 parent e3dd61c177
commit af72e33a1b
4 files changed
+121 -30

No files matched your search

@@ -520,21 +520,19 @@ public class CommandObject implements DirectorExecutor {
return;
}
if (WandSVC.isHoldingIrisWand(player)) {
Location[] g = WandSVC.getCuboid(player);
Location[] g = WandSVC.getCuboid(player);
if (g == null) {
return;
}
if (!here) {
// TODO: WARNING HEIGHT
g[0] = player.getTargetBlock(null, 256).getLocation().clone();
} else {
g[0] = player.getLocation().getBlock().getLocation().clone().add(0, -1, 0);
}
player.getInventory().setItemInMainHand(WandSVC.createWand(g[0], g[1]));
if (g == null) {
return;
}
if (!here) {
// TODO: WARNING HEIGHT
g[0] = player.getTargetBlock(null, 256).getLocation().clone();
} else {
g[0] = player.getLocation().getBlock().getLocation().clone().add(0, -1, 0);
}
player.getInventory().setItemInMainHand(WandSVC.createWand(g[0], g[1]));
});
}
@@ -27,11 +27,9 @@ import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.World;
import art.arcane.iris.Iris;
import art.arcane.iris.core.IrisSettings;
import art.arcane.iris.core.localization.IrisLanguage;
import art.arcane.iris.core.localization.RuntimeUiMessages;
import art.arcane.iris.core.edit.DustRevealer;
import art.arcane.iris.core.link.WorldEditLink;
import art.arcane.iris.core.wand.WandSelection;
import art.arcane.iris.engine.object.prefab.IrisObject;
import art.arcane.iris.util.project.matter.WorldMatter;
@@ -333,26 +331,14 @@ public class WandSVC implements IrisService {
}
public static Location[] getCuboid(Player p) {
if (isHoldingIrisWand(p)) {
if (isHoldingWand(p)) {
return getCuboidFromItem(p.getInventory().getItemInMainHand());
}
if (IrisSettings.get().getWorld().worldEditWandCUI) {
Cuboid c = WorldEditLink.getSelection(p);
if (c != null) {
return new Location[]{c.getLowerNE(), c.getUpperSW()};
}
}
return null;
}
public static boolean isHoldingWand(Player p) {
return isHoldingIrisWand(p) || (IrisSettings.get().getWorld().worldEditWandCUI && WorldEditLink.getSelection(p) != null);
}
public static boolean isHoldingIrisWand(Player p) {
ItemStack is = p.getInventory().getItemInMainHand();
return is != null && isWand(is);
}
@@ -567,7 +553,7 @@ public class WandSVC implements IrisService {
if (e.getHand() != EquipmentSlot.HAND)
return;
try {
if (isHoldingIrisWand(e.getPlayer())) {
if (isHoldingWand(e.getPlayer())) {
activePlayers.put(e.getPlayer().getUniqueId(), e.getPlayer());
if (e.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
e.setCancelled(true);
@@ -0,0 +1,108 @@
package art.arcane.iris.core.service;
import art.arcane.iris.Iris;
import art.arcane.iris.core.link.WorldEditLink;
import art.arcane.volmlib.util.bukkit.WorldIdentity;
import art.arcane.volmlib.util.data.Cuboid;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockedStatic;
import java.util.List;
import java.util.Optional;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;
public class WandSVCTest {
private Iris previousPlugin;
private Player player;
private PlayerInventory inventory;
@Before
public void installPlugin() {
previousPlugin = Iris.instance;
Iris plugin = mock(Iris.class);
when(plugin.namespace()).thenReturn("iris");
Iris.instance = plugin;
player = mock(Player.class);
inventory = mock(PlayerInventory.class);
when(player.getInventory()).thenReturn(inventory);
}
@After
public void restorePlugin() {
Iris.instance = previousPlugin;
}
@Test
public void ignoresWorldEditSelectionWhileHoldingAnOrdinaryAxe() {
ItemStack axe = wandItem(false);
when(inventory.getItemInMainHand()).thenReturn(axe);
Cuboid selection = mock(Cuboid.class);
try (MockedStatic<WorldEditLink> worldEdit = mockStatic(WorldEditLink.class)) {
worldEdit.when(() -> WorldEditLink.getSelection(player)).thenReturn(selection);
assertFalse(WandSVC.isHoldingWand(player));
assertNull(WandSVC.getCuboid(player));
}
}
@Test
public void ignoresWorldEditSelectionWithAnEmptyHand() {
Cuboid selection = mock(Cuboid.class);
try (MockedStatic<WorldEditLink> worldEdit = mockStatic(WorldEditLink.class)) {
worldEdit.when(() -> WorldEditLink.getSelection(player)).thenReturn(selection);
assertFalse(WandSVC.isHoldingWand(player));
assertNull(WandSVC.getCuboid(player));
}
}
@Test
public void readsSelectionFromAnIrisMarkedWand() {
ItemStack wand = wandItem(true);
when(inventory.getItemInMainHand()).thenReturn(wand);
World world = mock(World.class);
try (MockedStatic<WorldIdentity> worlds = mockStatic(WorldIdentity.class)) {
worlds.when(() -> WorldIdentity.resolve("minecraft:overworld")).thenReturn(Optional.of(world));
assertTrue(WandSVC.isHoldingWand(player));
assertArrayEquals(new Location[]{new Location(world, 1D, 64D, 2D), new Location(world, 3D, 68D, 4D)},
WandSVC.getCuboid(player));
}
}
private ItemStack wandItem(boolean marked) {
ItemStack item = mock(ItemStack.class);
ItemMeta meta = mock(ItemMeta.class);
PersistentDataContainer data = mock(PersistentDataContainer.class);
when(item.getType()).thenReturn(marked ? Material.BLAZE_ROD : Material.WOODEN_AXE);
when(item.getItemMeta()).thenReturn(meta);
when(meta.getPersistentDataContainer()).thenReturn(data);
when(meta.getLore()).thenReturn(List.of("1,64,2 in minecraft:overworld", "3,68,4 in minecraft:overworld"));
if (marked) {
when(data.get(new NamespacedKey("iris", "wand"), PersistentDataType.BYTE)).thenReturn((byte) 1);
}
return item;
}
}
@@ -200,7 +200,6 @@ public class IrisSettings {
public double targetSpawnEntitiesPerChunk = 0.95;
public boolean markerEntitySpawningSystem = true;
public boolean effectSystem = true;
public boolean worldEditWandCUI = true;
public boolean globalPregenCache = false;
}