feat(prompt): sign not working properly due to synchronization issues
This commit is contained in:
parent
dc36a0148e
commit
197f4f3259
2 changed files with 34 additions and 36 deletions
|
@ -68,7 +68,6 @@ tasks {
|
||||||
relocate("redis.clients", "xyz.ineanto.nicko.libs.redis")
|
relocate("redis.clients", "xyz.ineanto.nicko.libs.redis")
|
||||||
relocate("com.google.gson", "xyz.ineanto.nicko.libs.gson")
|
relocate("com.google.gson", "xyz.ineanto.nicko.libs.gson")
|
||||||
relocate("org.apache.commons.pool2", "xyz.ineanto.nicko.libs.pool2")
|
relocate("org.apache.commons.pool2", "xyz.ineanto.nicko.libs.pool2")
|
||||||
relocate("org.bstats", "xyz.ineanto.nicko.libs.bstats")
|
|
||||||
|
|
||||||
// EXCLUSIONS
|
// EXCLUSIONS
|
||||||
exclude("colors.bin")
|
exclude("colors.bin")
|
||||||
|
@ -89,7 +88,7 @@ tasks {
|
||||||
// MINIFY
|
// MINIFY
|
||||||
minimize {
|
minimize {
|
||||||
exclude(dependency("xyz.xenondevs.invui:.*"))
|
exclude(dependency("xyz.xenondevs.invui:.*"))
|
||||||
exclude(dependency("org.bstats:.*"))
|
exclude(dependency("de.rapha149.signgui:.*"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import de.rapha149.signgui.SignGUIAction;
|
||||||
import de.rapha149.signgui.exception.SignGUIVersionException;
|
import de.rapha149.signgui.exception.SignGUIVersionException;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import xyz.ineanto.nicko.Nicko;
|
||||||
import xyz.ineanto.nicko.language.LanguageKey;
|
import xyz.ineanto.nicko.language.LanguageKey;
|
||||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||||
|
|
||||||
|
@ -12,7 +13,6 @@ 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.atomic.AtomicReference;
|
|
||||||
|
|
||||||
public class SignPrompt implements Prompt {
|
public class SignPrompt implements Prompt {
|
||||||
private final Player player;
|
private final Player player;
|
||||||
|
@ -26,8 +26,8 @@ public class SignPrompt implements Prompt {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
private final AtomicReference<Optional<String>> name = new AtomicReference<>();
|
private String name = null;
|
||||||
private final AtomicReference<Optional<String>> skin = new AtomicReference<>();
|
private String skin = null;
|
||||||
|
|
||||||
public SignPrompt(Player player, PlayerLanguage playerLanguage) {
|
public SignPrompt(Player player, PlayerLanguage playerLanguage) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
@ -36,64 +36,63 @@ public class SignPrompt implements Prompt {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String[]> displayNameThenSkinPrompt() {
|
public Optional<String[]> displayNameThenSkinPrompt() {
|
||||||
try {
|
displayNamePrompt();
|
||||||
final SignGUI gui = SignGUI.builder()
|
displaySkinPrompt();
|
||||||
.setLines(lines.toArray(new String[0]))
|
|
||||||
.setType(Material.OAK_SIGN)
|
|
||||||
.setHandler((_, result) -> {
|
|
||||||
String internalLine2 = result.getLineWithoutColor(2);
|
|
||||||
|
|
||||||
if (internalLine2.isEmpty()) {
|
if (skin == null || name == null) {
|
||||||
return List.of(SignGUIAction.displayNewLines(lines.toArray(new String[0])));
|
|
||||||
}
|
|
||||||
|
|
||||||
name.set(Optional.of(internalLine2));
|
|
||||||
return Collections.emptyList();
|
|
||||||
})
|
|
||||||
.build();
|
|
||||||
|
|
||||||
gui.open(player);
|
|
||||||
return Optional.of(new String[]{name.get().orElse(player.getName()), skin.get().orElse(player.getName())});
|
|
||||||
} catch (SignGUIVersionException exception) {
|
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Optional.of(new String[]{name, skin});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> displaySkinPrompt() {
|
public Optional<String> displaySkinPrompt() {
|
||||||
this.lines.set(1, playerLanguage.translate(LanguageKey.GUI.NEW_SKIN, false));
|
this.lines.set(1, playerLanguage.translate(LanguageKey.GUI.NEW_SKIN, false));
|
||||||
return displaySign(skin);
|
displaySign(true);
|
||||||
|
|
||||||
|
if (skin == null) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Optional.of(skin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> displayNamePrompt() {
|
public Optional<String> displayNamePrompt() {
|
||||||
this.lines.set(1, playerLanguage.translate(LanguageKey.GUI.NEW_NAME, false));
|
this.lines.set(1, playerLanguage.translate(LanguageKey.GUI.NEW_NAME, false));
|
||||||
return displaySign(name);
|
displaySign(false);
|
||||||
|
|
||||||
|
if (name == null) {
|
||||||
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<String> displaySign(AtomicReference<Optional<String>> reference) {
|
return Optional.of(skin);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void displaySign(boolean isSkin) {
|
||||||
try {
|
try {
|
||||||
final SignGUI gui = SignGUI.builder()
|
final SignGUI gui = SignGUI.builder()
|
||||||
.setLines(lines.toArray(new String[0]))
|
.setLines(lines.toArray(new String[0]))
|
||||||
.setLine(2, null)
|
|
||||||
.setType(Material.OAK_SIGN)
|
.setType(Material.OAK_SIGN)
|
||||||
|
.callHandlerSynchronously(Nicko.getInstance())
|
||||||
.setHandler((_, result) -> {
|
.setHandler((_, result) -> {
|
||||||
final String internalLine2 = result.getLineWithoutColor(2);
|
final String internalLine1 = result.getLineWithoutColor(1);
|
||||||
|
|
||||||
if (internalLine2.isEmpty()) {
|
if (internalLine1.isEmpty()) {
|
||||||
return List.of(SignGUIAction.displayNewLines(lines.toArray(new String[0])));
|
return List.of(SignGUIAction.displayNewLines(lines.toArray(new String[0])));
|
||||||
}
|
}
|
||||||
|
|
||||||
reference.set(Optional.of(internalLine2));
|
if (isSkin) {
|
||||||
|
skin = internalLine1;
|
||||||
|
} else {
|
||||||
|
name = internalLine1;
|
||||||
|
}
|
||||||
|
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
})
|
})
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
gui.open(player);
|
gui.open(player);
|
||||||
return reference.get();
|
} catch (SignGUIVersionException _) { }
|
||||||
} catch (SignGUIVersionException exception) {
|
|
||||||
exception.printStackTrace();
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue