mirror of
https://github.com/YouHaveTrouble/Stand-in.git
synced 2026-05-11 22:16:55 +00:00
exploring dialogs a bit
This commit is contained in:
@@ -0,0 +1,68 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>me.youhavetrouble.standin</groupId>
|
||||||
|
<artifactId>Stand-in</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>Stand-in</name>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<java.version>21</java.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<defaultGoal>clean package</defaultGoal>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.13.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>${java.version}</source>
|
||||||
|
<target>${java.version}</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.5.3</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>papermc-repo</id>
|
||||||
|
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.papermc.paper</groupId>
|
||||||
|
<artifactId>paper-api</artifactId>
|
||||||
|
<version>1.21.10-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
## Stand-in
|
||||||
|
|
||||||
|
Swap armor stands to mannequins or display entities!
|
||||||
|
|
||||||
|
WIP
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package me.youhavetrouble.standin;
|
||||||
|
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
public final class StandIn extends JavaPlugin {
|
||||||
|
|
||||||
|
public static final NamespacedKey KEY = new NamespacedKey("stand-in", "stand-in");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
// Plugin startup logic
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
// Plugin shutdown logic
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package me.youhavetrouble.standin;
|
||||||
|
|
||||||
|
import io.papermc.paper.dialog.Dialog;
|
||||||
|
import io.papermc.paper.registry.data.dialog.ActionButton;
|
||||||
|
import io.papermc.paper.registry.data.dialog.DialogBase;
|
||||||
|
import io.papermc.paper.registry.data.dialog.action.DialogAction;
|
||||||
|
import io.papermc.paper.registry.data.dialog.input.DialogInput;
|
||||||
|
import io.papermc.paper.registry.data.dialog.type.DialogType;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.event.ClickCallback;
|
||||||
|
import net.kyori.adventure.util.TriState;
|
||||||
|
import org.bukkit.entity.ArmorStand;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
|
public class StandinDialog {
|
||||||
|
|
||||||
|
public static void openArmorStandDialog(@NotNull Player player, @NotNull ArmorStand armorStand) {
|
||||||
|
|
||||||
|
if (armorStand.isDead()) return;
|
||||||
|
|
||||||
|
UUID armorStandId = armorStand.getUniqueId();
|
||||||
|
|
||||||
|
List<DialogInput> inputs = new ArrayList<>();
|
||||||
|
|
||||||
|
inputs.add(
|
||||||
|
DialogInput.text("name", Component.text("Display name"))
|
||||||
|
.labelVisible(true)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
inputs.add(
|
||||||
|
DialogInput.bool("invisible", Component.text("Invisible"))
|
||||||
|
.initial(armorStand.isInvisible())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
inputs.add(
|
||||||
|
DialogInput.bool("onFire", Component.text("On fire"))
|
||||||
|
.initial(Boolean.TRUE.equals(armorStand.getVisualFire().toBoolean()))
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
ActionButton saveButton = ActionButton.builder(Component.text("Save")).action(
|
||||||
|
DialogAction.customClick((view, audience) -> {
|
||||||
|
if (!(audience instanceof Player callbackPlayer)) return;
|
||||||
|
Entity entity = callbackPlayer.getWorld().getEntity(armorStandId);
|
||||||
|
if (!(entity instanceof ArmorStand stand)) return;
|
||||||
|
if (stand.isDead()) return;
|
||||||
|
stand.setInvisible(Boolean.TRUE.equals(view.getBoolean("invisible")));
|
||||||
|
stand.setVisualFire(TriState.byBoolean(Boolean.TRUE.equals(view.getBoolean("onFire"))));
|
||||||
|
}, ClickCallback.Options.builder().lifetime(Duration.ofHours(1)).uses(1).build())
|
||||||
|
).build();
|
||||||
|
|
||||||
|
Dialog dialog = Dialog.create(builder -> builder.empty()
|
||||||
|
.base(
|
||||||
|
DialogBase.builder(Component.text("Armor Stand Editor"))
|
||||||
|
.inputs(inputs)
|
||||||
|
.build())
|
||||||
|
.type(DialogType.confirmation(saveButton, ActionButton.builder(Component.text("Cancel")).build()))
|
||||||
|
);
|
||||||
|
|
||||||
|
player.showDialog(dialog);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
name: Stand-in
|
||||||
|
version: '1.0-SNAPSHOT'
|
||||||
|
main: me.youhavetrouble.standin.StandIn
|
||||||
|
api-version: '1.21.7'
|
||||||
Reference in New Issue
Block a user