SteamWar/SpigotCore
Archiviert
13
0

Add SchematicSelector AnvilInv returns #215

Zusammengeführt
Lixfel hat 1 Commits von schem_selector_reusable nach master 2022-10-28 10:08:38 +02:00 zusammengeführt
5 geänderte Dateien mit 35 neuen und 3 gelöschten Zeilen
Nur Änderungen aus Commit 7ce6668de4 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -42,6 +42,7 @@ SCHEM_SELECTOR_SORTING_UPDATE=Last update
SCHEM_SELECTOR_SORTING_DIRECTION=§e{0} §7order
SCHEM_SELECTOR_SORTING_ASC=Ascending
SCHEM_SELECTOR_SORTING_DSC=Descending
SCHEM_SELECTOR_CLICK_BACK=§7Click to go back
SCHEM_SELECTOR_ITEM_NAME=§e{0}
SCHEM_SELECTOR_ITEM_NAME_FILTER=§7{0}

Datei anzeigen

@ -42,6 +42,7 @@ SCHEM_SELECTOR_SORTING_UPDATE=Letztes Update
SCHEM_SELECTOR_SORTING_DIRECTION=§7Richtung: §e{0}
SCHEM_SELECTOR_SORTING_ASC=Aufsteigend
SCHEM_SELECTOR_SORTING_DSC=Absteigend
SCHEM_SELECTOR_CLICK_BACK=§7Klicke hier, um zurückzugehen
SCHEM_SELECTOR_CREATE_DIR_TITLE=Ordner erstellen

Datei anzeigen

@ -66,6 +66,10 @@ public class SWAnvilInv {
this.callback = callback;
}
public void addLeftCallback(Runnable callback) {
builder.onLeftInputClick(p -> callback.run());
}
public void addCloseCallback(Runnable callback) {
builder.onClose(p -> callback.run());
}

Datei anzeigen

@ -25,11 +25,13 @@ import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SchematicType;
import de.steamwar.sql.SteamwarUser;
import lombok.*;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.text.MessageFormat;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
public class SchematicSelector {
@ -249,9 +251,23 @@ public class SchematicSelector {
return new SWListInv.SWListEntry<>(item, node);
}
private void addLeftCloseAction(SWAnvilInv inv, Runnable runnable) {
AtomicBoolean wasLeft = new AtomicBoolean(false);
inv.addCloseCallback(() -> {
if(injectable.onAnvilInvCloseAction(this) == SchematicSelectorInjectable.AnvilInvCloseAction.REOPEN && !wasLeft.get()) {
player.closeInventory();
Bukkit.getScheduler().runTaskLater(Core.getInstance(), runnable, 1);
}
});
inv.addLeftCallback(() -> {
wasLeft.set(true);
runnable.run();
});
}
private void createFolderIn(SchematicNode parent) {
SWAnvilInv inv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_CREATE_DIR_TITLE", player));
inv.setItem(Material.CHEST);
inv.setItem(Material.CHEST, Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_CLICK_BACK", player)), false);
inv.setCallback(s -> {
if(!SchematicNode.invalidSchemName(new String[] {s})) {
if(injectable.onFolderCreate(this, s)) {
@ -262,6 +278,7 @@ public class SchematicSelector {
}
player.closeInventory();
});
addLeftCloseAction(inv, this::reOpen);
inv.open();
}
@ -273,11 +290,12 @@ public class SchematicSelector {
openFilter();
} else {
SWAnvilInv swAnvilInv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_ENTER_NAME", player));
swAnvilInv.setItem(Material.NAME_TAG);
swAnvilInv.setItem(Material.NAME_TAG, Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_CLICK_BACK", player)), false);
swAnvilInv.setCallback(s -> {
filter.setName(s);
openFilter();
});
addLeftCloseAction(swAnvilInv, this::openFilter);
swAnvilInv.open();
}
};
@ -293,13 +311,14 @@ public class SchematicSelector {
openFilter();
} else {
SWAnvilInv swAnvilInv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_ENTER_OWNER", player));
swAnvilInv.setItem(SWItem.getMaterial("SKULL_ITEM"), (byte) 3);
swAnvilInv.setItem(SWItem.getMaterial("SKULL_ITEM"), (byte) 3, Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_CLICK_BACK", player)), false);
swAnvilInv.setCallback(s -> {
if(SteamwarUser.get(s) != null) {
filter.setOwner(SteamwarUser.get(s).getId());
}
openFilter();
});
addLeftCloseAction(swAnvilInv, this::openFilter);
swAnvilInv.open();
}
};

Datei anzeigen

@ -45,8 +45,15 @@ public interface SchematicSelectorInjectable {
default void onSelectorOpen(SchematicSelector selector, OpenFrom from) {}
default AnvilInvCloseAction onAnvilInvCloseAction(SchematicSelector selector) {return AnvilInvCloseAction.CLOSE;}
enum OpenFrom {
FRESH,
REOPEN
}
enum AnvilInvCloseAction {
CLOSE,
REOPEN
}
}