mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Let a tool world refuse to close and hear that it is closing, and tell middle clicks apart
ToolWorldListener gets closeRefusal() and closing(by) so a tool world that holds the studio slot can keep its owner's work safe. MenuClick tells a middle click from a left or right one.
This commit is contained in:
1 parent
3691611c6c
commit
18c6b189d1
8 files changed
+43
-412
No files matched your search
+1
-1
@@ -48,7 +48,7 @@ types that carry them and lists what the Iris adapter still owes.
|
||||
| Sparse geometry | `GeneratedObject` |
|
||||
| Studio views of what a module builds | `com.volmit.tooling`: `ModuleSetup.tooling()` (`ToolingRegistry.registerView`), sealed `StudioView` (`SceneView` with `SceneEntry`, `PatternView` with `PatternEntry`, `PatternArea`, `BlockPattern`), `EditableSceneView` (`SceneFile`, `NodeGraph`, `GraphNode` with `Link`, `NodeSettings`, `Edits`, `Addition`), `JsonText`, `JsonPath` (`Key`, `Index`), host `StudioViewRegistration` |
|
||||
| Commands of a module | `com.volmit.tooling`: `ToolingRegistry.registerCommand`, immutable `Command` (`named`, `alias`, `describe`, `child`, `argument`, `runs`, `openToEveryone`), typed `Argument` (`word`, `text`, `integer`, `decimal`, `flag`, `choice`, `resource`, `registered`, `orElse`, `suggesting`), `CommandAction`, `CommandContext` (`get`, `sender`, `pack`, `world`, `platform`), plain-text `Sender` (with `player()`), `ToolPack` (`edit` with `PackEdit`, `outputFolder`, `objects` with `ObjectCodec`, `worlds`, `services`), host `CommandRegistration` in `FeatureCatalog.commands()` |
|
||||
| Worlds a tool opens | `com.volmit.tooling.world`, exposed to pack modules by host `ExposedPackages`: `ToolWorlds` (`open`, `find`) with `ToolWorldSpec`, `ChunkPainter` and `ChunkCanvas`, `ToolWorld` (`players`, `owns`, `run`, `call`, `block`, `blockEntity`, `setBlock`, `repaint`, `close`), `ToolPlayer` (`teleport`, `creative`, `actionBar`, `sound`, `sidebar`, `particles`, `give`, `held`, `openMenu`), `ToolItem`, `ToolMenu` with `MenuButton` and `MenuClick`, `Particle`, `ToolWorldListener` (`entered`, `left`, `moved`, `sneakToggled`, `used` with `ToolUse`, `blockChanging` with `BlockChange.Cause`, `command`, `chunkLoaded`, `closed`), `com.volmit.geometry.ChunkPos`; every Y is the world's own; implemented by each platform adapter (Bukkit; modded adapters answer with a failed `open`) |
|
||||
| Worlds a tool opens | `com.volmit.tooling.world`, exposed to pack modules by host `ExposedPackages`: `ToolWorlds` (`open`, `find`) with `ToolWorldSpec`, `ChunkPainter` and `ChunkCanvas`, `ToolWorld` (`players`, `owns`, `run`, `call`, `block`, `blockEntity`, `setBlock`, `repaint`, `close`), `ToolPlayer` (`teleport`, `creative`, `actionBar`, `sound`, `sidebar`, `particles`, `give`, `held`, `openMenu`), `ToolItem`, `ToolMenu` with `MenuButton` and `MenuClick`, `Particle`, `ToolWorldListener` (`entered`, `left`, `moved`, `sneakToggled`, `used` with `ToolUse`, `blockChanging` with `BlockChange.Cause`, `command`, `chunkLoaded`, `closeRefusal`, `closing`, `closed`), `com.volmit.geometry.ChunkPos`; a tool world takes the pack's studio slot, so the host asks `closeRefusal` before it closes the world for another studio, the studio close command or a server stop, and waits for `closing` when another studio replaces it; every Y is the world's own; implemented by each platform adapter (Bukkit; modded adapters answer with a failed `open`) |
|
||||
| Buffered placement writes | `PlacementRequest`, `PlacementAccess`, host-owned `PlacementEdit` |
|
||||
| Typed generation and persistent storage | `mantle` package |
|
||||
|
||||
|
||||
@@ -611,6 +611,10 @@ worlds.open(new ToolWorldSpec("scratch", painter, new ToolWorldListener() { }))
|
||||
`Cause`). Each method returns `true` to allow or `false` to cancel where it decides, and `blockChanging` freezes the
|
||||
world unless the tool overrides it. Calls come on the thread that owns the player or the position, and must return
|
||||
quickly.
|
||||
- A tool world takes the pack's studio slot: opening another studio, the studio close command and a server stop go
|
||||
through the world. `closeRefusal()` lets the tool veto such a close with a message (an unsaved edit, a running
|
||||
save), and `closing(by)` lets it finish its work before another studio replaces it; the host closes the world when
|
||||
that future completes.
|
||||
- On a platform that splits a world across threads (Folia), `ToolWorld.owns(at)` says whether the calling thread may
|
||||
touch the block, `run`/`call` get a task there, and `block`, `blockEntity` and `setBlock` fail with
|
||||
`IllegalStateException` elsewhere. `ToolPlayer` readers are valid on the player's own thread (`ToolPlayer.run`); its
|
||||
|
||||
@@ -3,12 +3,18 @@ package com.volmit.tooling.world;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* A click on a {@link MenuButton}. A left click has {@code right} false; holding shift is {@code shift}.
|
||||
* A click on a {@link MenuButton}. A left click has {@code right} false; holding shift is {@code shift}; the middle
|
||||
* mouse button is {@code middle}, with {@code right} and {@code shift} false.
|
||||
*
|
||||
* @param player the player who clicked
|
||||
*/
|
||||
public record MenuClick(ToolPlayer player, boolean right, boolean shift) {
|
||||
public record MenuClick(ToolPlayer player, boolean right, boolean shift, boolean middle) {
|
||||
public MenuClick {
|
||||
Objects.requireNonNull(player, "player");
|
||||
}
|
||||
|
||||
/** A left or right click, with or without shift. */
|
||||
public MenuClick(ToolPlayer player, boolean right, boolean shift) {
|
||||
this(player, right, shift, false);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.volmit.tooling.world;
|
||||
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* What a tool hears about its world. Every method has a default that does nothing, so a tool implements only the ones
|
||||
@@ -52,6 +53,26 @@ public interface ToolWorldListener {
|
||||
default void chunkLoaded(int chunkX, int chunkZ) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the host may close the world now, asked before the host closes it for any reason other than the tool's own
|
||||
* {@link ToolWorld#close()}: another studio opening, the studio close command, the server stopping. A tool world takes
|
||||
* the pack's studio slot, so those paths go through the world. Return a message for the user to veto the close, such
|
||||
* as "autosave is still running"; empty lets it happen. Asked on any thread, and must return quickly.
|
||||
*/
|
||||
default Optional<String> closeRefusal() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Another studio wants this world's slot. Get the world ready to close, such as finishing a save, and complete the
|
||||
* future when it is ready; the host then closes the world. Complete it exceptionally to refuse, with a message for the
|
||||
* user. {@code by} is the player who asked, empty when the console did. Called on any thread; the future may complete
|
||||
* on any thread.
|
||||
*/
|
||||
default CompletableFuture<Void> closing(Optional<ToolPlayer> by) {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
/** The world was unloaded and is gone; nothing can be done with it any more. */
|
||||
default void closed() {
|
||||
}
|
||||
|
||||
@@ -37,6 +37,15 @@ class ToolWorldRecordsTest {
|
||||
assertThrows(NullPointerException.class, () -> new ToolWorldSpec("name", painter, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aListenerThatSaysNothingAboutClosingLetsTheWorldCloseAtOnce() {
|
||||
var listener = new ToolWorldListener() { };
|
||||
|
||||
assertEquals(java.util.Optional.empty(), listener.closeRefusal());
|
||||
assertEquals(true, listener.closing(java.util.Optional.empty()).isDone());
|
||||
assertEquals(false, listener.closing(java.util.Optional.empty()).isCompletedExceptionally());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aToolItemKeepsItsOwnCopyOfTheLore() {
|
||||
var lore = new ArrayList<>(List.of("one"));
|
||||
|
||||
Reference in new issue
Block a user