Merge pull request 'Add SchematicSelector AnvilInv returns' (#215) from schem_selector_reusable into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Reviewed-on: #215 Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Commit
02d47a3157
@ -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}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
};
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren