feat: add chat prompt because nothing reliably works
This commit is contained in:
parent
1a792112cc
commit
d30f433527
3 changed files with 92 additions and 9 deletions
|
@ -1,15 +1,6 @@
|
||||||
1.3.0-RC1: Update n°13 (XX/XX/25)
|
1.3.0-RC1: Update n°13 (XX/XX/25)
|
||||||
[FEATURES]
|
[FEATURES]
|
||||||
- Players are now able to mark disguises as favorites.
|
- Players are now able to mark disguises as favorites.
|
||||||
- Modernized the messages and added various sound effects upon interacting with the plugin.
|
|
||||||
- Made GUIs names cleaner.
|
|
||||||
|
|
||||||
[FIXES]
|
|
||||||
- Fixed an oversight preventing the configuration from properly being migrated.
|
|
||||||
- Fixed the placeholder item in the skin cache invalidation not being translated.
|
|
||||||
|
|
||||||
[LANGUAGE]
|
|
||||||
- Moved the prefix to the language file.
|
|
||||||
|
|
||||||
1.2.0-RC1: Update n°12 (XX/XX/25)
|
1.2.0-RC1: Update n°12 (XX/XX/25)
|
||||||
[FEATURES]
|
[FEATURES]
|
||||||
|
|
70
src/main/java/xyz/ineanto/nicko/gui/prompt/ChatPrompt.java
Normal file
70
src/main/java/xyz/ineanto/nicko/gui/prompt/ChatPrompt.java
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
package xyz.ineanto.nicko.gui.prompt;
|
||||||
|
|
||||||
|
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||||
|
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import xyz.ineanto.nicko.Nicko;
|
||||||
|
import xyz.ineanto.nicko.language.LanguageKey;
|
||||||
|
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class ChatPrompt implements Prompt {
|
||||||
|
private final Player player;
|
||||||
|
private final PlayerLanguage playerLanguage;
|
||||||
|
|
||||||
|
private String name = null;
|
||||||
|
private String skin = null;
|
||||||
|
|
||||||
|
public ChatPrompt(Player player, PlayerLanguage playerLanguage) {
|
||||||
|
this.player = player;
|
||||||
|
this.playerLanguage = playerLanguage;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<String[]> displayNameThenSkinPrompt() {
|
||||||
|
displayNamePrompt();
|
||||||
|
displaySkinPrompt();
|
||||||
|
|
||||||
|
if (skin == null || name == null) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Optional.of(new String[]{name, skin});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<String> displaySkinPrompt() {
|
||||||
|
promptInChat(true);
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<String> displayNamePrompt() {
|
||||||
|
promptInChat(false);
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void promptInChat(boolean isSkin) {
|
||||||
|
player.sendMessage(playerLanguage.translate(isSkin ? LanguageKey.GUI.NEW_SKIN : LanguageKey.GUI.NEW_NAME, false));
|
||||||
|
//player.sendMessage(playerLanguage.translate(LanguageKey.GUI.ENTER_IN_CHAT, false));
|
||||||
|
|
||||||
|
Nicko.getInstance().getServer().getPluginManager().registerEvents(new Listener() {
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerChat(AsyncChatEvent event) {
|
||||||
|
if (event.getPlayer().equals(player)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
final String plain = PlainTextComponentSerializer.plainText().serialize(event.originalMessage());
|
||||||
|
|
||||||
|
if (isSkin) {
|
||||||
|
skin = plain;
|
||||||
|
} else {
|
||||||
|
name = plain;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, Nicko.getInstance());
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,8 +13,12 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
public class SignPrompt implements Prompt {
|
public class SignPrompt implements Prompt {
|
||||||
|
private final CompletableFuture<Void> future = new CompletableFuture<>();
|
||||||
|
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final PlayerLanguage playerLanguage;
|
private final PlayerLanguage playerLanguage;
|
||||||
private final ArrayList<String> lines = new ArrayList<>(
|
private final ArrayList<String> lines = new ArrayList<>(
|
||||||
|
@ -51,6 +55,14 @@ public class SignPrompt implements Prompt {
|
||||||
this.lines.set(1, playerLanguage.translate(LanguageKey.GUI.NEW_SKIN, false));
|
this.lines.set(1, playerLanguage.translate(LanguageKey.GUI.NEW_SKIN, false));
|
||||||
displaySign(true);
|
displaySign(true);
|
||||||
|
|
||||||
|
synchronized (future) {
|
||||||
|
try {
|
||||||
|
future.get();
|
||||||
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (skin == null) {
|
if (skin == null) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
@ -63,6 +75,14 @@ public class SignPrompt implements Prompt {
|
||||||
this.lines.set(1, playerLanguage.translate(LanguageKey.GUI.NEW_NAME, false));
|
this.lines.set(1, playerLanguage.translate(LanguageKey.GUI.NEW_NAME, false));
|
||||||
displaySign(false);
|
displaySign(false);
|
||||||
|
|
||||||
|
synchronized (future) {
|
||||||
|
try {
|
||||||
|
future.get();
|
||||||
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
@ -89,9 +109,11 @@ public class SignPrompt implements Prompt {
|
||||||
name = internalLine1;
|
name = internalLine1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
future.complete(null);
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
})
|
})
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
gui.open(player);
|
gui.open(player);
|
||||||
} catch (SignGUIVersionException _) { }
|
} catch (SignGUIVersionException _) { }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue