mirror of
https://github.com/darksaid98/nightcore-spigot.git
synced 2026-12-04 06:28:51 +00:00
Fixed 1.21.3 menu incompatibility.
Fixed Dialog time display.
This commit is contained in:
1 parent
92267220e0
commit
d226c7891f
3 files changed
+22
-9
No files matched your search
@@ -7,7 +7,6 @@ import su.nightexpress.nightcore.core.CoreLang;
|
|||||||
import su.nightexpress.nightcore.language.entry.LangString;
|
import su.nightexpress.nightcore.language.entry.LangString;
|
||||||
import su.nightexpress.nightcore.ui.menu.Menu;
|
import su.nightexpress.nightcore.ui.menu.Menu;
|
||||||
import su.nightexpress.nightcore.ui.menu.MenuViewer;
|
import su.nightexpress.nightcore.ui.menu.MenuViewer;
|
||||||
import su.nightexpress.nightcore.util.TimeUtil;
|
|
||||||
import su.nightexpress.nightcore.util.text.TextRoot;
|
import su.nightexpress.nightcore.util.text.TextRoot;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -24,27 +23,31 @@ public class Dialog {
|
|||||||
private final DialogHandler handler;
|
private final DialogHandler handler;
|
||||||
private final List<String> suggestions;
|
private final List<String> suggestions;
|
||||||
private final boolean suggestionAutoRun;
|
private final boolean suggestionAutoRun;
|
||||||
private final long timeoutDate;
|
|
||||||
|
|
||||||
private Menu lastMenu;
|
private Menu lastMenu;
|
||||||
private int lastPage;
|
private int lastPage;
|
||||||
|
private int lifetime;
|
||||||
|
|
||||||
public Dialog(@NotNull Player player,
|
public Dialog(@NotNull Player player,
|
||||||
@NotNull String prompt,
|
@NotNull String prompt,
|
||||||
@NotNull DialogHandler handler,
|
@NotNull DialogHandler handler,
|
||||||
@Nullable List<String> suggestions,
|
@Nullable List<String> suggestions,
|
||||||
boolean suggestionAutoRun,
|
boolean suggestionAutoRun,
|
||||||
long timeoutDate) {
|
int lifetime) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.prompt = prompt;
|
this.prompt = prompt;
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
this.suggestions = suggestions == null ? null : suggestions.stream().sorted(String::compareTo).collect(Collectors.toCollection(ArrayList::new));
|
this.suggestions = suggestions == null ? null : suggestions.stream().sorted(String::compareTo).collect(Collectors.toCollection(ArrayList::new));
|
||||||
this.suggestionAutoRun = suggestionAutoRun;
|
this.suggestionAutoRun = suggestionAutoRun;
|
||||||
this.timeoutDate = timeoutDate;
|
this.lifetime = lifetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tick() {
|
||||||
|
this.lifetime--;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isExpired() {
|
public boolean isExpired() {
|
||||||
return TimeUtil.isPassed(this.timeoutDate);
|
return this.lifetime <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -91,8 +94,17 @@ public class Dialog {
|
|||||||
return this.suggestionAutoRun;
|
return this.suggestionAutoRun;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public long getTimeoutDate() {
|
public long getTimeoutDate() {
|
||||||
return this.timeoutDate;
|
return this.lifetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLifetime() {
|
||||||
|
return this.lifetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLifetimeMillis() {
|
||||||
|
return this.getLifetime() * 1000L;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -139,7 +151,7 @@ public class Dialog {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Dialog build() {
|
public Dialog build() {
|
||||||
return new Dialog(this.player, this.prompt, this.handler, this.suggestions, this.suggestionAutoRun, TimeUtil.createFutureTimestamp(this.timeout));
|
return new Dialog(this.player, this.prompt, this.handler, this.suggestions, this.suggestionAutoRun, this.timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
|
|||||||
@@ -44,11 +44,12 @@ public class DialogManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
displayPrompt(dialog, 0);
|
displayPrompt(dialog, 0);
|
||||||
|
dialog.tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void displayPrompt(@NotNull Dialog dialog, int fade) {
|
private static void displayPrompt(@NotNull Dialog dialog, int fade) {
|
||||||
Player player = dialog.getPlayer();
|
Player player = dialog.getPlayer();
|
||||||
String title = NightMessage.asLegacy(CoreLang.DIALOG_HEADER.getString().replace(Placeholders.GENERIC_TIME, TimeUtil.formatDuration(dialog.getTimeoutDate())));
|
String title = NightMessage.asLegacy(CoreLang.DIALOG_HEADER.getString().replace(Placeholders.GENERIC_TIME, TimeUtil.formatTime(dialog.getLifetimeMillis())));
|
||||||
String sub = NightMessage.asLegacy(dialog.getPrompt());
|
String sub = NightMessage.asLegacy(dialog.getPrompt());
|
||||||
|
|
||||||
player.sendTitle(title, sub, fade, 40, 20);
|
player.sendTitle(title, sub, fade, 40, 20);
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ public abstract class AbstractMenu<P extends NightPlugin> implements Menu {
|
|||||||
linked.getCache().addAnchor(player);
|
linked.getCache().addAnchor(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Version.isAtLeast(Version.MC_1_21_3)) {
|
if (Version.isAtLeast(Version.MC_1_21_4)) {
|
||||||
var builder = this.menuType.typed().builder();
|
var builder = this.menuType.typed().builder();
|
||||||
// Stupid hack to bypass 9X3 (and probably other container-based) menu types to be bound to real container(s) at player's location.
|
// Stupid hack to bypass 9X3 (and probably other container-based) menu types to be bound to real container(s) at player's location.
|
||||||
if (builder instanceof LocationInventoryViewBuilder<?> locationBuilder) {
|
if (builder instanceof LocationInventoryViewBuilder<?> locationBuilder) {
|
||||||
|
|||||||
Reference in new issue
Block a user