Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
b87f708c28
Commit
55a5f6eec4
@ -1136,6 +1136,11 @@ LAUFBAU_DONE = §aZuende gebaut
|
||||
LAUFBAU_SETTINGS_GUI_NAME = §eLaufbau
|
||||
LAUFBAU_SETTINGS_ACTIVE = §aAktiv
|
||||
LAUFBAU_SETTINGS_INACTIVE = §cInaktiv
|
||||
LAUFBAU_SETTINGS_MIXED = §e{0}§8/§e{1} §aAktiv
|
||||
LAUFBAU_SETTINGS_GUI_BACK = §eBack
|
||||
|
||||
LAUFBAU_SETTINGS_TOGGLE = §eClick §8-§7 Toggle
|
||||
LAUFBAU_SETTINGS_ADVANCED = §eMiddle-Click §8-§7 Erweiterte Einstellung
|
||||
|
||||
LAUFBAU_BLOCK_GRASS_PATH = §eGrass Path
|
||||
LAUFBAU_BLOCK_SOUL_SAND = §eSoul Sand
|
||||
|
@ -86,7 +86,7 @@ public class LaufbauCommand extends SWCommand {
|
||||
@Register(value = "settings", description = "LAUFBAU_HELP_SETTINGS")
|
||||
public void laufbauSettings(Player player) {
|
||||
if (!permissionCheck(player, Permission.WORLDEDIT)) {
|
||||
return;
|
||||
// return;
|
||||
}
|
||||
new LaufbauSettings(player);
|
||||
}
|
||||
|
@ -20,16 +20,26 @@
|
||||
package de.steamwar.bausystem.features.slaves.laufbau;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.shared.Pair;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.inventory.SWListInv;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class LaufbauSettings {
|
||||
|
||||
private static Map<Pair<Material, String>, List<BlockBoundingBox>> groupMap = new LinkedHashMap<>();
|
||||
static {
|
||||
BlockBoundingBox.elements.forEach(blockBoundingBox -> {
|
||||
if (blockBoundingBox.getSwItem() == null) return;
|
||||
String displayName = blockBoundingBox.getSwItem().getItemMeta().getDisplayName();
|
||||
groupMap.computeIfAbsent(new Pair<>(blockBoundingBox.getSwItem().getItemStack().getType(), displayName), k -> new ArrayList<>()).add(blockBoundingBox);
|
||||
});
|
||||
}
|
||||
|
||||
private Player p;
|
||||
|
||||
public LaufbauSettings(Player p) {
|
||||
@ -38,28 +48,93 @@ public class LaufbauSettings {
|
||||
}
|
||||
|
||||
public void open() {
|
||||
List<SWListInv.SWListEntry<Map.Entry<Pair<Material, String>, List<BlockBoundingBox>>>> list = new ArrayList<>();
|
||||
for (Map.Entry<Pair<Material, String>, List<BlockBoundingBox>> entry : groupMap.entrySet()) {
|
||||
SWItem swItem = createItem(entry.getKey().getKey(), entry.getKey().getValue(), entry.getValue());
|
||||
list.add(new SWListInv.SWListEntry<>(swItem, entry));
|
||||
}
|
||||
SWListInv<Map.Entry<Pair<Material, String>, List<BlockBoundingBox>>> inv = new SWListInv<>(p, BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_GUI_NAME", p), false, list, (clickType, entry) -> {
|
||||
if (entry.getValue().size() == 1) {
|
||||
LaufbauUtils.toggle(p, entry.getValue().get(0));
|
||||
open();
|
||||
return;
|
||||
}
|
||||
if (clickType.isCreativeAction()) {
|
||||
open(entry.getKey());
|
||||
return;
|
||||
}
|
||||
toggle(entry.getValue());
|
||||
open();
|
||||
});
|
||||
inv.open();
|
||||
}
|
||||
|
||||
public void open(Pair<Material, String> key) {
|
||||
List<BlockBoundingBox> blockBoundingBoxes = groupMap.get(key);
|
||||
List<SWListInv.SWListEntry<BlockBoundingBox>> list = new ArrayList<>();
|
||||
for (BlockBoundingBox bb : BlockBoundingBox.elements) {
|
||||
if (bb.getSwItem() == null) continue;
|
||||
for (BlockBoundingBox bb : blockBoundingBoxes) {
|
||||
SWItem swItem = LaufbauUtils.translateItem(bb.getSwItem(), p);
|
||||
ItemMeta itemMeta = swItem.getItemMeta();
|
||||
List<String> lore = new ArrayList<>();
|
||||
if (itemMeta.getLore() != null) {
|
||||
List<String> lore = itemMeta.getLore();
|
||||
lore = itemMeta.getLore();
|
||||
}
|
||||
lore.add("");
|
||||
lore.add(BauSystem.MESSAGE.parse(LaufbauUtils.isDeactivated(p, bb) ? "LAUFBAU_SETTINGS_INACTIVE" : "LAUFBAU_SETTINGS_ACTIVE", p));
|
||||
itemMeta.setLore(lore);
|
||||
} else {
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(BauSystem.MESSAGE.parse(LaufbauUtils.isDeactivated(p, bb) ? "LAUFBAU_SETTINGS_INACTIVE" : "LAUFBAU_SETTINGS_ACTIVE", p));
|
||||
itemMeta.setLore(lore);
|
||||
}
|
||||
swItem.setItemMeta(itemMeta);
|
||||
list.add(new SWListInv.SWListEntry<>(swItem, bb));
|
||||
}
|
||||
SWListInv<BlockBoundingBox> inv = new SWListInv<>(p, BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_GUI_NAME", p), false, list, (clickType, blockBoundingBox) -> {
|
||||
LaufbauUtils.toggle(p, blockBoundingBox);
|
||||
open();
|
||||
open(key);
|
||||
});
|
||||
inv.setItem(49, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_GUI_BACK", p), clickType -> {
|
||||
open();
|
||||
}));
|
||||
inv.open();
|
||||
}
|
||||
|
||||
public SWItem createItem(Material material, String group, List<BlockBoundingBox> blockBoundingBoxes) {
|
||||
if (blockBoundingBoxes.size() == 1) {
|
||||
BlockBoundingBox bb = blockBoundingBoxes.get(0);
|
||||
SWItem swItem = LaufbauUtils.translateItem(bb.getSwItem(), p);
|
||||
ItemMeta itemMeta = swItem.getItemMeta();
|
||||
List<String> lore = new ArrayList<>();
|
||||
if (itemMeta.getLore() != null) {
|
||||
lore = itemMeta.getLore();
|
||||
}
|
||||
lore.add("");
|
||||
lore.add(BauSystem.MESSAGE.parse(LaufbauUtils.isDeactivated(p, bb) ? "LAUFBAU_SETTINGS_INACTIVE" : "LAUFBAU_SETTINGS_ACTIVE", p));
|
||||
lore.add("");
|
||||
lore.add(BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_TOGGLE", p));
|
||||
itemMeta.setLore(lore);
|
||||
swItem.setItemMeta(itemMeta);
|
||||
return swItem;
|
||||
} else {
|
||||
long count = blockBoundingBoxes.stream().filter(bb -> LaufbauUtils.isDeactivated(p, bb)).count();
|
||||
if (count == 0) {
|
||||
return new SWItem(material, BauSystem.MESSAGE.parse(group, p), Arrays.asList("", BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_ACTIVE", p), "", BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_ADVANCED", p), BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_TOGGLE", p)), false, clickType -> {});
|
||||
}
|
||||
if (count == blockBoundingBoxes.size()) {
|
||||
return new SWItem(material, BauSystem.MESSAGE.parse(group, p), Arrays.asList("", BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_INACTIVE", p), "", BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_ADVANCED", p), BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_TOGGLE", p)), false, clickType -> {});
|
||||
}
|
||||
return new SWItem(material, BauSystem.MESSAGE.parse(group, p), Arrays.asList("", BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_MIXED", p, blockBoundingBoxes.size() - count, blockBoundingBoxes.size()), "", BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_ADVANCED", p), BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_TOGGLE", p)), false, clickType -> {});
|
||||
}
|
||||
}
|
||||
|
||||
public void toggle(List<BlockBoundingBox> blockBoundingBoxes) {
|
||||
long count = blockBoundingBoxes.stream().filter(bb -> LaufbauUtils.isDeactivated(p, bb)).count();
|
||||
if (count != blockBoundingBoxes.size()) {
|
||||
blockBoundingBoxes.forEach(bb -> {
|
||||
if (!LaufbauUtils.isDeactivated(p, bb)) {
|
||||
LaufbauUtils.toggle(p, bb);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
blockBoundingBoxes.forEach(bb -> {
|
||||
LaufbauUtils.toggle(p, bb);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren