feat: trying to circumvent AnvilGUI
This commit is contained in:
parent
d30f433527
commit
63f2e7f699
11 changed files with 125 additions and 21 deletions
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
|
@ -5,7 +5,6 @@
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
<option name="gradleJvm" value="22" />
|
|
||||||
<option name="modules">
|
<option name="modules">
|
||||||
<set>
|
<set>
|
||||||
<option value="$PROJECT_DIR$" />
|
<option value="$PROJECT_DIR$" />
|
||||||
|
|
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
|
@ -4,7 +4,7 @@
|
||||||
<component name="PWA">
|
<component name="PWA">
|
||||||
<option name="wasEnabledAtLeastOnce" value="true" />
|
<option name="wasEnabledAtLeastOnce" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" project-jdk-name="azul-17.0.10" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_22" project-jdk-name="graal-22" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
|
@ -29,7 +29,7 @@ repositories {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
paperweight.paperDevBundle("1.21.4-R0.1-SNAPSHOT")
|
paperweight.paperDevBundle("1.21.5-R0.1-SNAPSHOT")
|
||||||
|
|
||||||
compileOnly("me.clip:placeholderapi:2.11.5")
|
compileOnly("me.clip:placeholderapi:2.11.5")
|
||||||
compileOnly("net.kyori:adventure-api:4.17.0")
|
compileOnly("net.kyori:adventure-api:4.17.0")
|
||||||
|
@ -100,6 +100,6 @@ tasks {
|
||||||
url("https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/build/libs/ProtocolLib.jar")
|
url("https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/build/libs/ProtocolLib.jar")
|
||||||
}
|
}
|
||||||
|
|
||||||
minecraftVersion("1.21.4")
|
minecraftVersion("1.21.5")
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -10,6 +10,7 @@ import xyz.ineanto.nicko.config.Configuration;
|
||||||
import xyz.ineanto.nicko.config.ConfigurationManager;
|
import xyz.ineanto.nicko.config.ConfigurationManager;
|
||||||
import xyz.ineanto.nicko.event.PlayerJoinListener;
|
import xyz.ineanto.nicko.event.PlayerJoinListener;
|
||||||
import xyz.ineanto.nicko.event.PlayerQuitListener;
|
import xyz.ineanto.nicko.event.PlayerQuitListener;
|
||||||
|
import xyz.ineanto.nicko.event.PromptCloseListener;
|
||||||
import xyz.ineanto.nicko.language.CustomLanguage;
|
import xyz.ineanto.nicko.language.CustomLanguage;
|
||||||
import xyz.ineanto.nicko.language.Language;
|
import xyz.ineanto.nicko.language.Language;
|
||||||
import xyz.ineanto.nicko.migration.ConfigurationMigrator;
|
import xyz.ineanto.nicko.migration.ConfigurationMigrator;
|
||||||
|
@ -111,6 +112,7 @@ public class Nicko extends JavaPlugin {
|
||||||
|
|
||||||
getServer().getPluginManager().registerEvents(new PlayerJoinListener(), this);
|
getServer().getPluginManager().registerEvents(new PlayerJoinListener(), this);
|
||||||
getServer().getPluginManager().registerEvents(new PlayerQuitListener(), this);
|
getServer().getPluginManager().registerEvents(new PlayerQuitListener(), this);
|
||||||
|
getServer().getPluginManager().registerEvents(new PromptCloseListener(), this);
|
||||||
|
|
||||||
getLogger().info("Nicko has been enabled.");
|
getLogger().info("Nicko has been enabled.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package xyz.ineanto.nicko.event;
|
||||||
|
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import xyz.ineanto.nicko.event.custom.PromptCloseEvent;
|
||||||
|
|
||||||
|
public class PromptCloseListener implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void onPromptClose(PromptCloseEvent event) {
|
||||||
|
String playerName = event.getPlayer().getName();
|
||||||
|
String skin = event.getSkin().orElse("No skin selected");
|
||||||
|
String name = event.getName().orElse("No name selected");
|
||||||
|
|
||||||
|
System.out.println("Player " + playerName + " closed the prompt with skin: " + skin + " and name: " + name);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package xyz.ineanto.nicko.event.custom;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class PromptCloseEvent extends Event implements Cancellable {
|
||||||
|
private static final HandlerList HANDLERS_LIST = new HandlerList();
|
||||||
|
|
||||||
|
private boolean isCancelled;
|
||||||
|
private final Player player;
|
||||||
|
private final String skin, name;
|
||||||
|
|
||||||
|
public PromptCloseEvent(Player player, String skin, String name) {
|
||||||
|
this.player = player;
|
||||||
|
this.skin = skin;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return isCancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean isCancelled) {
|
||||||
|
this.isCancelled = isCancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() { return HANDLERS_LIST; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull HandlerList getHandlers() {
|
||||||
|
return HANDLERS_LIST;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<String> getSkin() {
|
||||||
|
return Optional.ofNullable(skin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<String> getName() {
|
||||||
|
return Optional.ofNullable(name);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,15 +1,21 @@
|
||||||
package xyz.ineanto.nicko.gui.prompt;
|
package xyz.ineanto.nicko.gui.prompt;
|
||||||
|
|
||||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import xyz.ineanto.nicko.Nicko;
|
import xyz.ineanto.nicko.Nicko;
|
||||||
|
import xyz.ineanto.nicko.event.custom.PromptCloseEvent;
|
||||||
import xyz.ineanto.nicko.language.LanguageKey;
|
import xyz.ineanto.nicko.language.LanguageKey;
|
||||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ChatPrompt implements Prompt {
|
public class ChatPrompt implements Prompt {
|
||||||
private final Player player;
|
private final Player player;
|
||||||
|
@ -17,6 +23,7 @@ public class ChatPrompt implements Prompt {
|
||||||
|
|
||||||
private String name = null;
|
private String name = null;
|
||||||
private String skin = null;
|
private String skin = null;
|
||||||
|
private final List<UUID> inPrompt = new ArrayList<>();
|
||||||
|
|
||||||
public ChatPrompt(Player player, PlayerLanguage playerLanguage) {
|
public ChatPrompt(Player player, PlayerLanguage playerLanguage) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
@ -25,8 +32,7 @@ public class ChatPrompt implements Prompt {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String[]> displayNameThenSkinPrompt() {
|
public Optional<String[]> displayNameThenSkinPrompt() {
|
||||||
displayNamePrompt();
|
promptInChat(false, false);
|
||||||
displaySkinPrompt();
|
|
||||||
|
|
||||||
if (skin == null || name == null) {
|
if (skin == null || name == null) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
@ -37,32 +43,58 @@ public class ChatPrompt implements Prompt {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> displaySkinPrompt() {
|
public Optional<String> displaySkinPrompt() {
|
||||||
promptInChat(true);
|
promptInChat(true, true);
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> displayNamePrompt() {
|
public Optional<String> displayNamePrompt() {
|
||||||
promptInChat(false);
|
promptInChat(false, true);
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void promptInChat(boolean isSkin) {
|
private void promptInChat(boolean isSkin, boolean last) {
|
||||||
player.sendMessage(playerLanguage.translate(isSkin ? LanguageKey.GUI.NEW_SKIN : LanguageKey.GUI.NEW_NAME, false));
|
// what the HELL did I wrote (Ineanto)
|
||||||
//player.sendMessage(playerLanguage.translate(LanguageKey.GUI.ENTER_IN_CHAT, false));
|
// TODO (Ineanto, 11/05/2025): Doesn't work, the event is registered multiple times and thus is breaking the logic.
|
||||||
|
if (!inPrompt.contains(player.getUniqueId())) {
|
||||||
|
Bukkit.broadcast(Component.text("WAS NOT IN"));
|
||||||
|
inPrompt.add(player.getUniqueId());
|
||||||
|
Bukkit.getScheduler().runTaskLaterAsynchronously(Nicko.getInstance(), () -> inPrompt.remove(player.getUniqueId()), 20 * 15L);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSkin) {
|
||||||
|
player.sendMessage(playerLanguage.translate(LanguageKey.Event.Appearance.Set.CHAT_PROMPT, true, "skin"));
|
||||||
|
} else {
|
||||||
|
player.sendMessage(playerLanguage.translate(LanguageKey.Event.Appearance.Set.CHAT_PROMPT, true, "name"));
|
||||||
|
}
|
||||||
|
|
||||||
Nicko.getInstance().getServer().getPluginManager().registerEvents(new Listener() {
|
Nicko.getInstance().getServer().getPluginManager().registerEvents(new Listener() {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerChat(AsyncChatEvent event) {
|
public void onPlayerChat(AsyncChatEvent event) {
|
||||||
if (event.getPlayer().equals(player)) {
|
if (!inPrompt.contains(event.getPlayer().getUniqueId())) {
|
||||||
event.setCancelled(true);
|
Bukkit.broadcast(Component.text("IS NOT IN (chat)"));
|
||||||
final String plain = PlainTextComponentSerializer.plainText().serialize(event.originalMessage());
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (isSkin) {
|
event.setCancelled(true);
|
||||||
skin = plain;
|
final String plain = PlainTextComponentSerializer.plainText().serialize(event.originalMessage());
|
||||||
} else {
|
|
||||||
name = plain;
|
if (isSkin) {
|
||||||
}
|
skin = plain;
|
||||||
|
} else {
|
||||||
|
name = plain;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (last) {
|
||||||
|
Bukkit.broadcast(Component.text("WAS LAST"));
|
||||||
|
inPrompt.remove(event.getPlayer().getUniqueId());
|
||||||
|
Bukkit.getScheduler().runTask(Nicko.getInstance(), () -> Bukkit
|
||||||
|
.getPluginManager()
|
||||||
|
.callEvent(new PromptCloseEvent(event.getPlayer(), skin, name))
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
Bukkit.broadcast(Component.text("PROMPTING FOR SKIN NOW"));
|
||||||
|
promptInChat(true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, Nicko.getInstance());
|
}, Nicko.getInstance());
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class PromptManager {
|
||||||
final Optional<NickoProfile> optionalProfile = dataStore.getData(player.getUniqueId());
|
final Optional<NickoProfile> optionalProfile = dataStore.getData(player.getUniqueId());
|
||||||
this.profile = optionalProfile.orElse(NickoProfile.EMPTY_PROFILE.clone());
|
this.profile = optionalProfile.orElse(NickoProfile.EMPTY_PROFILE.clone());
|
||||||
this.appearanceManager = new AppearanceManager(player);
|
this.appearanceManager = new AppearanceManager(player);
|
||||||
this.prompt = new SignPrompt(player, playerLanguage);
|
this.prompt = new ChatPrompt(player, playerLanguage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void displayNameThenSkinPrompt() {
|
public void displayNameThenSkinPrompt() {
|
||||||
|
|
|
@ -48,6 +48,8 @@ public class LanguageKey {
|
||||||
|
|
||||||
public static final String OK = SET_KEY + "ok";
|
public static final String OK = SET_KEY + "ok";
|
||||||
public static final String ERROR = SET_KEY + "error";
|
public static final String ERROR = SET_KEY + "error";
|
||||||
|
|
||||||
|
public static final String CHAT_PROMPT = SET_KEY + "chat_prompt";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Remove {
|
public static class Remove {
|
||||||
|
|
|
@ -13,7 +13,7 @@ public class NickoPluginLoader implements PluginLoader {
|
||||||
final MavenLibraryResolver resolver = new MavenLibraryResolver();
|
final MavenLibraryResolver resolver = new MavenLibraryResolver();
|
||||||
|
|
||||||
resolver.addRepository(new RemoteRepository.Builder("xenondevs", "default", "https://repo.xenondevs.xyz/releases/").build());
|
resolver.addRepository(new RemoteRepository.Builder("xenondevs", "default", "https://repo.xenondevs.xyz/releases/").build());
|
||||||
resolver.addDependency(new Dependency(new DefaultArtifact("xyz.xenondevs.invui:invui:pom:1.44"), null));
|
resolver.addDependency(new Dependency(new DefaultArtifact("xyz.xenondevs.invui:invui:pom:1.45"), null));
|
||||||
|
|
||||||
pluginClasspathBuilder.addLibrary(resolver);
|
pluginClasspathBuilder.addLibrary(resolver);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ event:
|
||||||
set:
|
set:
|
||||||
error: "<gray>Wasn''t able to apply your disguise! ({0})</gray>"
|
error: "<gray>Wasn''t able to apply your disguise! ({0})</gray>"
|
||||||
ok: "<gray>You''re now disguised.</gray>"
|
ok: "<gray>You''re now disguised.</gray>"
|
||||||
|
chat_prompt: "<gray>Please enter your new {0} in chat.</gray>"
|
||||||
restore:
|
restore:
|
||||||
error: "<gray>Wasn''t able to apply the previous disguise! ({0})</gray>"
|
error: "<gray>Wasn''t able to apply the previous disguise! ({0})</gray>"
|
||||||
ok: "<gray>Previous disguise restored.</gray>"
|
ok: "<gray>Previous disguise restored.</gray>"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue