forked from unimatrix/web
Package optional Paper fullscreen Decisions provider
This commit is contained in:
parent
e3c91a6cb2
commit
450fe08df6
7 changed files with 409 additions and 0 deletions
|
|
@ -55,3 +55,16 @@ jobs:
|
|||
name: DuneRealms-Plugins
|
||||
path: plugin-artifacts/
|
||||
if-no-files-found: error
|
||||
|
||||
- uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: '25'
|
||||
- name: Build optional Paper 26.2 fullscreen provider
|
||||
shell: bash
|
||||
run: gradle --no-daemon -p DuneFullscreenPaper test jar
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: DuneRealms-Fullscreen-Paper-Development
|
||||
path: DuneFullscreenPaper/build/libs/DuneFullscreenPaper.jar
|
||||
if-no-files-found: error
|
||||
|
|
|
|||
7
DuneFullscreenPaper/README.md
Normal file
7
DuneFullscreenPaper/README.md
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Optional Paper fullscreen Decisions provider
|
||||
|
||||
DuneGit builds this provider as a separate development artifact. It requires Paper 26.2 build 135 and Java 25. Build `DuneRealmsGUI` first, then run `gradle -p DuneFullscreenPaper test jar` with Java 25 and Gradle 9.2.1.
|
||||
|
||||
The Java Decisions dashboard uses this provider only for UUIDs listed under `development.fullscreen-decisions-viewers` in the DunerealmsGUI config. Keep the allowlist empty on live servers. The existing menu path handles unsupported clients, unavailable providers and documents outside the current six-card development layout.
|
||||
|
||||
The current visual prototype still exposes parts of the vanilla HUD and hand, along with the mount prompt.
|
||||
13
DuneFullscreenPaper/build.gradle.kts
Normal file
13
DuneFullscreenPaper/build.gradle.kts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
plugins {
|
||||
java
|
||||
id("io.papermc.paperweight.userdev") version "2.0.0-beta.23"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
paperweight.paperDevBundle("26.2.build.135-stable")
|
||||
compileOnly(files("../DuneRealmsGUI/build/libs/DunerealmsGUI.jar"))
|
||||
}
|
||||
|
||||
java { toolchain.languageVersion.set(JavaLanguageVersion.of(25)) }
|
||||
tasks.withType<JavaCompile>().configureEach { options.encoding = "UTF-8" }
|
||||
tasks.jar { archiveFileName.set("DuneFullscreenPaper.jar") }
|
||||
7
DuneFullscreenPaper/settings.gradle.kts
Normal file
7
DuneFullscreenPaper/settings.gradle.kts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
}
|
||||
rootProject.name = "DuneFullscreenPaper"
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package com.dunerealms.fullscreen;
|
||||
|
||||
import com.dunerealms.gui.DecisionsViewTransport;
|
||||
import io.papermc.paper.ServerBuildInfo;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class FullscreenProvider extends JavaPlugin {
|
||||
private PaperDecisionsScene scenes;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
var build = ServerBuildInfo.buildInfo();
|
||||
if (!build.minecraftVersionId().equals("26.2") || build.buildNumber().orElse(-1) != 135 ||
|
||||
!build.isBrandCompatible(ServerBuildInfo.BRAND_PAPER_ID)) {
|
||||
getLogger().info("Fullscreen Decisions requires Paper 26.2 build 135.");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
scenes = new PaperDecisionsScene(this);
|
||||
Bukkit.getPluginManager().registerEvents(scenes, this);
|
||||
Bukkit.getServicesManager().register(DecisionsViewTransport.class, scenes, this, ServicePriority.Normal);
|
||||
} catch (LinkageError unavailable) {
|
||||
getLogger().warning("Fullscreen Decisions runtime is unavailable: " + unavailable.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
Bukkit.getServicesManager().unregisterAll(this);
|
||||
if (scenes != null) scenes.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,330 @@
|
|||
package com.dunerealms.fullscreen;
|
||||
|
||||
import com.dunerealms.gui.DecisionsViewTransport;
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.*;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.*;
|
||||
import net.minecraft.core.*;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.protocol.game.*;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.decoration.*;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.saveddata.maps.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.*;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.map.MapPalette;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
final class PaperDecisionsScene implements DecisionsViewTransport, Listener, AutoCloseable {
|
||||
private static final String INPUT = "dune_fullscreen_decisions";
|
||||
private static final int COLS = 11, ROWS = 9;
|
||||
private final Map<UUID, Scene> scenes = new HashMap<>();
|
||||
private final JavaPlugin plugin;
|
||||
// This range is private to each connection and reused on reopen to bound the client map cache.
|
||||
private static final int FIRST_SCENE_MAP = 2_000_000_000;
|
||||
|
||||
PaperDecisionsScene(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
private record Tile(MapId map, BufferedImage normal, BufferedImage focused) {}
|
||||
|
||||
private static final class Scene {
|
||||
final Player viewer;
|
||||
final Location original;
|
||||
final boolean gravity;
|
||||
final Document document;
|
||||
final IntConsumer select;
|
||||
final Runnable dismiss;
|
||||
final List<Entity> entities = new ArrayList<>();
|
||||
final Map<Integer, Tile> buttons = new HashMap<>();
|
||||
Integer focus;
|
||||
int mountId;
|
||||
volatile boolean closed;
|
||||
boolean positioning;
|
||||
|
||||
Scene(Player viewer, Document document, IntConsumer select, Runnable dismiss) {
|
||||
this.viewer = viewer;
|
||||
this.document = document;
|
||||
this.select = select;
|
||||
this.dismiss = dismiss;
|
||||
original = viewer.getLocation();
|
||||
gravity = viewer.hasGravity();
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void close() {
|
||||
List.copyOf(scenes.values()).forEach(scene -> finish(scene, true, true));
|
||||
}
|
||||
|
||||
@Override public boolean open(Player viewer, Document document, IntConsumer select, Runnable dismiss) {
|
||||
if (!(viewer instanceof CraftPlayer player) || !viewer.isOnline() || viewer.isDead() ||
|
||||
viewer.isInsideVehicle() || scenes.containsKey(viewer.getUniqueId()) ||
|
||||
document.cards().isEmpty() || document.cards().size() > 6) return false;
|
||||
var pipeline = player.getHandle().connection.connection.channel.pipeline();
|
||||
if (pipeline.get("packet_handler") == null || pipeline.get(INPUT) != null) return false;
|
||||
|
||||
Scene scene = new Scene(viewer, document, select, dismiss);
|
||||
var origin = scene.original;
|
||||
var viewpoint = new Location(origin.getWorld(), origin.getBlockX() + .5, origin.getBlockY() + 6,
|
||||
origin.getBlockZ() + .5, 0, 0);
|
||||
if (!viewpoint.getBlock().isPassable() || !viewpoint.clone().add(0, 1, 0).getBlock().isPassable()) return false;
|
||||
scenes.put(viewer.getUniqueId(), scene);
|
||||
try {
|
||||
viewer.setGravity(false);
|
||||
scene.positioning = true;
|
||||
if (!viewer.teleport(viewpoint) || !viewer.getLocation().equals(viewpoint)) {
|
||||
finish(scene, false, false);
|
||||
return false;
|
||||
}
|
||||
scene.positioning = false;
|
||||
show(scene);
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> finish(scene, true, true), 2400);
|
||||
return true;
|
||||
} catch (RuntimeException | LinkageError error) {
|
||||
plugin.getLogger().warning("Fullscreen Decisions could not open: " + error.getClass().getSimpleName());
|
||||
finish(scene, true, false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private void show(Scene scene) {
|
||||
var handle = ((CraftPlayer) scene.viewer).getHandle();
|
||||
var level = handle.level();
|
||||
var origin = scene.original;
|
||||
var cards = scene.document.cards();
|
||||
BufferedImage art = artwork(cards);
|
||||
for (int row = 0; row < ROWS; row++) {
|
||||
for (int col = 0; col < COLS; col++) {
|
||||
var pos = new BlockPos(origin.getBlockX() + 5 - col, origin.getBlockY() + 11 - row, origin.getBlockZ() + 2);
|
||||
var frame = new GlowItemFrame(level, pos, Direction.NORTH);
|
||||
frame.setInvisible(true);
|
||||
var map = new MapId(FIRST_SCENE_MAP + row * COLS + col);
|
||||
var item = new net.minecraft.world.item.ItemStack(Items.FILLED_MAP);
|
||||
item.set(DataComponents.MAP_ID, map);
|
||||
frame.setItem(item, false, false);
|
||||
var image = art.getSubimage(col * 128, row * 128, 128, 128);
|
||||
Card card = cardAt(cards, row, col);
|
||||
var tile = new Tile(map, image, card == null ? image : focused(image));
|
||||
if (card != null && card.actionable()) scene.buttons.put(card.slot(), tile);
|
||||
pixels(scene, tile, false);
|
||||
add(scene, frame, Direction.NORTH.get3DDataValue());
|
||||
}
|
||||
}
|
||||
|
||||
var mount = new ArmorStand(level, handle.getX(), handle.getY() - 1.4, handle.getZ());
|
||||
var camera = new ArmorStand(level, handle.getX(), handle.getY(), handle.getZ());
|
||||
for (var stand : List.of(mount, camera)) {
|
||||
stand.setInvisible(true);
|
||||
stand.setNoGravity(true);
|
||||
add(scene, stand, 0);
|
||||
}
|
||||
scene.mountId = mount.getId();
|
||||
handle.connection.send(passengers(scene.mountId, handle.getId()));
|
||||
handle.connection.send(new ClientboundSetCameraPacket(camera));
|
||||
var channel = handle.connection.connection.channel;
|
||||
var ids = scene.entities.stream().map(Entity::getId).collect(java.util.stream.Collectors.toUnmodifiableSet());
|
||||
channel.pipeline().addBefore("packet_handler", INPUT, new ChannelInboundHandlerAdapter() {
|
||||
private Integer focus;
|
||||
@Override public void channelRead(ChannelHandlerContext context, Object input) throws Exception {
|
||||
if (!scene.closed) {
|
||||
if (input instanceof ServerboundMovePlayerPacket move && move.hasRotation()) {
|
||||
Integer target = target(cards, move.getYRot(0), move.getXRot(0));
|
||||
if (!Objects.equals(target, focus)) {
|
||||
focus = target;
|
||||
Bukkit.getScheduler().runTask(plugin, () -> focus(scene, target));
|
||||
}
|
||||
}
|
||||
if (input instanceof ServerboundInteractPacket use && ids.contains(use.entityId())) {
|
||||
Integer target = focus;
|
||||
if (use.hand() == net.minecraft.world.InteractionHand.MAIN_HAND)
|
||||
Bukkit.getScheduler().runTask(plugin, () -> select(scene, target));
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.channelRead(context, input);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void add(Scene scene, Entity entity, int extra) {
|
||||
var connection = ((CraftPlayer) scene.viewer).getHandle().connection;
|
||||
scene.entities.add(entity);
|
||||
if (entity instanceof ItemFrame) {
|
||||
connection.send(new ClientboundAddEntityPacket(entity, extra, entity.blockPosition()));
|
||||
} else {
|
||||
connection.send(new ClientboundAddEntityPacket(entity.getId(), entity.getUUID(), entity.getX(), entity.getY(),
|
||||
entity.getZ(), entity.getXRot(), entity.getYRot(), entity.getType(), extra,
|
||||
net.minecraft.world.phys.Vec3.ZERO, entity.getYHeadRot()));
|
||||
}
|
||||
var data = entity.getEntityData().getNonDefaultValues();
|
||||
if (data != null) connection.send(new ClientboundSetEntityDataPacket(entity.getId(), data));
|
||||
}
|
||||
|
||||
private ClientboundSetPassengersPacket passengers(int mount, int... riders) {
|
||||
var buffer = new FriendlyByteBuf(Unpooled.buffer());
|
||||
try {
|
||||
buffer.writeVarInt(mount);
|
||||
buffer.writeVarIntArray(riders);
|
||||
return ClientboundSetPassengersPacket.STREAM_CODEC.decode(buffer);
|
||||
} finally {
|
||||
buffer.release();
|
||||
}
|
||||
}
|
||||
|
||||
private void pixels(Scene scene, Tile tile, boolean focused) {
|
||||
byte[] image = MapPalette.imageToBytes(focused ? tile.focused : tile.normal);
|
||||
var patch = new MapItemSavedData.MapPatch(0, 0, 128, 128, image);
|
||||
((CraftPlayer) scene.viewer).getHandle().connection.send(
|
||||
new ClientboundMapItemDataPacket(tile.map, (byte) 0, true, List.of(), patch));
|
||||
}
|
||||
|
||||
private static Card cardAt(List<Card> cards, int row, int col) {
|
||||
if (row < 3 || row > 5 || (col != 4 && col != 6)) return null;
|
||||
int index = (row - 3) * 2 + (col == 4 ? 0 : 1);
|
||||
return index < cards.size() ? cards.get(index) : null;
|
||||
}
|
||||
|
||||
private static Integer target(List<Card> cards, float yaw, float pitch) {
|
||||
if (!Float.isFinite(yaw) || !Float.isFinite(pitch) || Math.abs(yaw) > 45 || Math.abs(pitch) > 40) return null;
|
||||
double x = -Math.tan(Math.toRadians(yaw)) * 2.46;
|
||||
double y = Math.tan(Math.toRadians(pitch)) * 2.46;
|
||||
if (Math.abs(x) < .5 || Math.abs(x) > 1.5) return null;
|
||||
Card card = cardAt(cards, 4 + (int) Math.round(y), x > 0 ? 4 : 6);
|
||||
return card != null && card.actionable() ? card.slot() : null;
|
||||
}
|
||||
|
||||
private void focus(Scene scene, Integer slot) {
|
||||
if (scene.closed || Objects.equals(scene.focus, slot)) return;
|
||||
scene.focus = slot;
|
||||
scene.buttons.forEach((action, tile) -> pixels(scene, tile, action.equals(slot)));
|
||||
}
|
||||
|
||||
private void select(Scene scene, Integer slot) {
|
||||
if (scene.closed || slot == null || !scene.buttons.containsKey(slot)) return;
|
||||
finish(scene, true, false);
|
||||
scene.select.accept(slot);
|
||||
}
|
||||
|
||||
@EventHandler public void swap(PlayerSwapHandItemsEvent event) {
|
||||
var scene = scenes.get(event.getPlayer().getUniqueId());
|
||||
if (scene == null) return;
|
||||
event.setCancelled(true);
|
||||
finish(scene, true, true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void teleport(PlayerTeleportEvent event) {
|
||||
interrupt(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler public void changedWorld(PlayerChangedWorldEvent event) {
|
||||
interrupt(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler public void death(org.bukkit.event.entity.PlayerDeathEvent event) {
|
||||
interrupt(event.getEntity());
|
||||
}
|
||||
|
||||
@EventHandler public void quit(PlayerQuitEvent event) {
|
||||
var scene = scenes.get(event.getPlayer().getUniqueId());
|
||||
if (scene != null) finish(scene, true, true);
|
||||
}
|
||||
|
||||
private void interrupt(Player viewer) {
|
||||
var scene = scenes.get(viewer.getUniqueId());
|
||||
if (scene != null && !scene.positioning) finish(scene, false, true);
|
||||
}
|
||||
|
||||
private void finish(Scene scene, boolean restoreLocation, boolean dismiss) {
|
||||
if (scene.closed) return;
|
||||
scene.closed = true;
|
||||
scenes.remove(scene.viewer.getUniqueId(), scene);
|
||||
Player viewer = scene.viewer;
|
||||
var handle = ((CraftPlayer) viewer).getHandle();
|
||||
var connection = handle.connection;
|
||||
var pipeline = connection.connection.channel.pipeline();
|
||||
try {
|
||||
if (pipeline.get(INPUT) != null) pipeline.remove(INPUT);
|
||||
if (viewer.isOnline() && !scene.entities.isEmpty()) {
|
||||
connection.send(new ClientboundSetCameraPacket(handle));
|
||||
if (scene.mountId != 0) connection.send(passengers(scene.mountId));
|
||||
connection.send(new ClientboundRemoveEntitiesPacket(scene.entities.stream().mapToInt(Entity::getId).toArray()));
|
||||
}
|
||||
} finally {
|
||||
viewer.setGravity(scene.gravity);
|
||||
if (restoreLocation) viewer.teleport(scene.original);
|
||||
if (dismiss) scene.dismiss.run();
|
||||
}
|
||||
}
|
||||
|
||||
private BufferedImage artwork(List<Card> cards) {
|
||||
var image = new BufferedImage(COLS * 128, ROWS * 128, BufferedImage.TYPE_INT_RGB);
|
||||
var draw = image.createGraphics();
|
||||
try {
|
||||
draw.setColor(new Color(25, 40, 46));
|
||||
draw.fillRect(0, 0, image.getWidth(), image.getHeight());
|
||||
draw.setColor(new Color(237, 199, 105));
|
||||
draw.setStroke(new BasicStroke(7));
|
||||
draw.drawRect(445, 335, 518, 455);
|
||||
draw.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 38));
|
||||
draw.drawString("YOUR DECISIONS", 523, 372);
|
||||
for (int index = 0; index < cards.size(); index++) {
|
||||
Card card = cards.get(index);
|
||||
int x = (index % 2 == 0 ? 4 : 6) * 128;
|
||||
int y = (3 + index / 2) * 128;
|
||||
draw.setColor(card.actionable() ? new Color(52, 93, 107) : new Color(55, 63, 66));
|
||||
draw.fillRect(x, y + 3, 128, 122);
|
||||
draw.setColor(Color.WHITE);
|
||||
draw.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 14));
|
||||
writeWrapped(draw, card.title(), x + 7, y + 25, 114, 3);
|
||||
if (!card.lore().isEmpty()) {
|
||||
draw.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
|
||||
writeWrapped(draw, card.lore().getFirst(), x + 7, y + 76, 114, 3);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
draw.dispose();
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
private static void writeWrapped(java.awt.Graphics2D draw, String text, int x, int y, int width, int lines) {
|
||||
var metrics = draw.getFontMetrics();
|
||||
String remaining = text.strip();
|
||||
for (int line = 0; line < lines && !remaining.isEmpty(); line++) {
|
||||
int end = remaining.length();
|
||||
while (end > 1 && metrics.stringWidth(remaining.substring(0, end)) > width) end--;
|
||||
if (end < remaining.length()) {
|
||||
int wordBreak = remaining.lastIndexOf(' ', end);
|
||||
if (wordBreak > 0) end = wordBreak;
|
||||
}
|
||||
draw.drawString(remaining.substring(0, end), x, y + line * metrics.getHeight());
|
||||
remaining = remaining.substring(end).stripLeading();
|
||||
}
|
||||
}
|
||||
private BufferedImage focused(BufferedImage normal) {
|
||||
var image = new BufferedImage(128, 128, BufferedImage.TYPE_INT_RGB);
|
||||
var draw = image.createGraphics();
|
||||
try {
|
||||
draw.drawImage(normal, 0, 0, null);
|
||||
draw.setColor(new Color(250, 224, 152));
|
||||
draw.setStroke(new BasicStroke(8));
|
||||
draw.drawRect(5, 5, 117, 117);
|
||||
} finally {
|
||||
draw.dispose();
|
||||
}
|
||||
return image;
|
||||
}
|
||||
}
|
||||
5
DuneFullscreenPaper/src/main/resources/plugin.yml
Normal file
5
DuneFullscreenPaper/src/main/resources/plugin.yml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
name: DuneFullscreenPaper
|
||||
main: com.dunerealms.fullscreen.FullscreenProvider
|
||||
version: 0.1.0
|
||||
api-version: '26.2'
|
||||
depend: [DunerealmsGUI]
|
||||
Loading…
Reference in a new issue

Staff