SteamWar/BauSystem2.0
Archiviert
12
0

Fix LanternBoundingBox
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Add LaufbauSettings gui working

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-02-07 19:54:28 +01:00
Ursprung 5095decb37
Commit c878a6a183
7 geänderte Dateien mit 126 neuen und 24 gelöschten Zeilen

Datei anzeigen

@ -1127,12 +1127,15 @@ LAUFBAU_STATE_FILTERING_TRACES = Traces filtern
LAUFBAU_STATE_PROCESSING_TRACES = Traces verbinden LAUFBAU_STATE_PROCESSING_TRACES = Traces verbinden
LAUFBAU_STATE_EXPANDING_TRACES = Traces aufblähen LAUFBAU_STATE_EXPANDING_TRACES = Traces aufblähen
LAUFBAU_STATE_SPLITTING_POINTS = Punkte trennen LAUFBAU_STATE_SPLITTING_POINTS = Punkte trennen
LAUFBAU_STATE_SHRINKING_POINTS = Punkte ausdünnen
LAUFBAU_STATE_CREATING_INNER_BLOCKS = Innenraum füllen LAUFBAU_STATE_CREATING_INNER_BLOCKS = Innenraum füllen
LAUFBAU_STATE_CREATING_OUTER_BLOCKS = Mantel bauen LAUFBAU_STATE_CREATING_OUTER_BLOCKS = Mantel bauen
LAUFBAU_SIMPLE_PROGRESS = §e{0}§8: §e{1}§8/§e{2} LAUFBAU_SIMPLE_PROGRESS = §e{0}§8: §e{1}§8/§e{2}
LAUFBAU_DONE = §aZuende gebaut LAUFBAU_DONE = §aZuende gebaut
LAUFBAU_SETTING_GUI_NAME = §eLaufbau LAUFBAU_SETTINGS_GUI_NAME = §eLaufbau
LAUFBAU_SETTINGS_ACTIVE = §aAktiv
LAUFBAU_SETTINGS_INACTIVE = §cInaktiv
LAUFBAU_BLOCK_GRASS_PATH = §eGrass Path LAUFBAU_BLOCK_GRASS_PATH = §eGrass Path
LAUFBAU_BLOCK_SOUL_SAND = §eSoul Sand LAUFBAU_BLOCK_SOUL_SAND = §eSoul Sand

Datei anzeigen

@ -31,6 +31,7 @@ import org.bukkit.util.Vector;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class Laufbau { public class Laufbau {
@ -48,12 +49,12 @@ public class Laufbau {
private CreatingInnerBlocksState creatingInnerBlocksState = null; private CreatingInnerBlocksState creatingInnerBlocksState = null;
private CreatingOuterBlocksState creatingOuterBlocksState = null; private CreatingOuterBlocksState creatingOuterBlocksState = null;
private List<BlockBoundingBox> elements = new ArrayList<>(BlockBoundingBox.elements); private List<BlockBoundingBox> elements;
@Getter @Getter
private EditSession editSession; private EditSession editSession;
public Laufbau(Location pos1, Location pos2, boolean preferingBlastResistance) { public Laufbau(Player player, Location pos1, Location pos2, boolean preferingBlastResistance) {
this.world = pos1.getWorld(); this.world = pos1.getWorld();
this.pos1 = new Location(world, Math.min(pos1.getBlockX(), pos2.getBlockX()), Math.min(pos1.getBlockY(), pos2.getBlockY()), Math.min(pos1.getBlockZ(), pos2.getBlockZ())); this.pos1 = new Location(world, Math.min(pos1.getBlockX(), pos2.getBlockX()), Math.min(pos1.getBlockY(), pos2.getBlockY()), Math.min(pos1.getBlockZ(), pos2.getBlockZ()));
this.pos2 = new Location(world, Math.max(pos1.getBlockX(), pos2.getBlockX()), Math.max(pos1.getBlockY(), pos2.getBlockY()), Math.max(pos1.getBlockZ(), pos2.getBlockZ())); this.pos2 = new Location(world, Math.max(pos1.getBlockX(), pos2.getBlockX()), Math.max(pos1.getBlockY(), pos2.getBlockY()), Math.max(pos1.getBlockZ(), pos2.getBlockZ()));
@ -64,6 +65,9 @@ public class Laufbau {
editSession = WorldEditUtils.getEditSession(world); editSession = WorldEditUtils.getEditSession(world);
elements = BlockBoundingBox.elements.stream().filter(blockBoundingBox -> {
return !LaufbauUtils.isDeactivated(player, blockBoundingBox);
}).collect(Collectors.toList());
if (preferingBlastResistance) { if (preferingBlastResistance) {
elements.sort((o1, o2) -> { elements.sort((o1, o2) -> {
int compared = Double.compare(o1.blockData.getMaterial().getBlastResistance(), o2.blockData.getMaterial().getBlastResistance()); int compared = Double.compare(o1.blockData.getMaterial().getBlastResistance(), o2.blockData.getMaterial().getBlastResistance());

Datei anzeigen

@ -57,7 +57,7 @@ public class LaufbauCommand extends SWCommand {
BauSystem.MESSAGE.send("LAUFBAU_NO_WORLDEDIT", player); BauSystem.MESSAGE.send("LAUFBAU_NO_WORLDEDIT", player);
return; return;
} }
Laufbau laufbau = new Laufbau(selection.getKey(), selection.getValue(), preferingBlastResistance); Laufbau laufbau = new Laufbau(player, selection.getKey(), selection.getValue(), preferingBlastResistance);
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
public void run() { public void run() {

Datei anzeigen

@ -20,8 +20,10 @@
package de.steamwar.bausystem.features.slaves.laufbau; package de.steamwar.bausystem.features.slaves.laufbau;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv; import de.steamwar.inventory.SWListInv;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -32,13 +34,31 @@ public class LaufbauSettings {
public LaufbauSettings(Player p) { public LaufbauSettings(Player p) {
this.p = p; this.p = p;
open();
}
public void open() {
List<SWListInv.SWListEntry<BlockBoundingBox>> list = new ArrayList<>(); List<SWListInv.SWListEntry<BlockBoundingBox>> list = new ArrayList<>();
for (BlockBoundingBox bb : BlockBoundingBox.elements) { for (BlockBoundingBox bb : BlockBoundingBox.elements) {
if (bb.getSwItem() == null) continue; if (bb.getSwItem() == null) continue;
list.add(new SWListInv.SWListEntry<>(LaufbauUtils.translateItem(bb.getSwItem(), p), bb)); SWItem swItem = LaufbauUtils.translateItem(bb.getSwItem(), p);
ItemMeta itemMeta = swItem.getItemMeta();
if (itemMeta.getLore() != null) {
List<String> 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_SETTING_GUI_NAME", p), false, list, (clickType, blockBoundingBox) -> { SWListInv<BlockBoundingBox> inv = new SWListInv<>(p, BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_GUI_NAME", p), false, list, (clickType, blockBoundingBox) -> {
p.sendMessage(LaufbauUtils.identifier(blockBoundingBox.getSwItem())); LaufbauUtils.toggle(p, blockBoundingBox);
open();
}); });
inv.open(); inv.open();
} }

Datei anzeigen

@ -20,19 +20,64 @@
package de.steamwar.bausystem.features.slaves.laufbau; package de.steamwar.bausystem.features.slaves.laufbau;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
import lombok.experimental.UtilityClass; import de.steamwar.sql.UserConfig;
import lombok.Cleanup;
import lombok.SneakyThrows;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import yapion.hierarchy.output.StreamOutput;
import yapion.hierarchy.types.YAPIONObject;
import yapion.parser.YAPIONParser;
import java.util.ArrayList; import java.io.ByteArrayInputStream;
import java.util.Arrays; import java.io.ByteArrayOutputStream;
import java.util.List; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
@UtilityClass @Linked(LinkageType.LISTENER)
public class LaufbauUtils { public class LaufbauUtils implements Listener {
private static Map<Player, YAPIONObject> yapionObjectMap = new HashMap<>();
@EventHandler
@SneakyThrows
public void onPlayerJoin(PlayerJoinEvent event) {
String config = UserConfig.getConfig(event.getPlayer().getUniqueId(), "bausystem-laufbau");
if (config == null) {
return;
}
byte[] bytes = Base64.getDecoder().decode(config);
@Cleanup GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(bytes));
YAPIONObject yapionObject = new YAPIONParser(gzipInputStream, true).parse().result();
yapionObjectMap.put(event.getPlayer(), yapionObject);
}
@EventHandler
@SneakyThrows
public void onPlayerQuit(PlayerQuitEvent event) {
YAPIONObject yapionObject = yapionObjectMap.get(event.getPlayer());
if (yapionObject == null) {
return;
}
if (yapionObject.isEmpty()) {
UserConfig.removePlayerConfig(event.getPlayer().getUniqueId(), "bausystem-laufbau");
return;
}
@Cleanup ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
@Cleanup GZIPOutputStream gzipOutputStream = new GZIPOutputStream(byteArrayOutputStream);
yapionObject.toYAPION(new StreamOutput(gzipOutputStream)).close();
UserConfig.updatePlayerConfig(event.getPlayer().getUniqueId(), "bausystem-laufbau", Base64.getEncoder().encodeToString(byteArrayOutputStream.toByteArray()));
}
public static Cuboid pixelCuboid(double pixelX, double pixelY, double pixelZ, double pixelDX, double pixelDY, double pixelDZ) { public static Cuboid pixelCuboid(double pixelX, double pixelY, double pixelZ, double pixelDX, double pixelDY, double pixelDZ) {
return new Cuboid(pixelToBlock(pixelX), pixelToBlock(pixelY), pixelToBlock(pixelZ), pixelToBlock(pixelDX), pixelToBlock(pixelDY), pixelToBlock(pixelDZ)); return new Cuboid(pixelToBlock(pixelX), pixelToBlock(pixelY), pixelToBlock(pixelZ), pixelToBlock(pixelDX), pixelToBlock(pixelDY), pixelToBlock(pixelDZ));
@ -57,23 +102,51 @@ public class LaufbauUtils {
}); });
} }
public static String identifier(SWItem item) { public static String identifier(BlockBoundingBox bb) {
if (bb.getSwItem() == null) {
return null;
}
SWItem item = bb.getSwItem();
ItemMeta itemMeta = item.getItemMeta(); ItemMeta itemMeta = item.getItemMeta();
List<String> lore = new ArrayList<>(); List<String> lore = new ArrayList<>();
if (itemMeta.getLore() != null) { if (itemMeta.getLore() != null) {
lore = itemMeta.getLore() lore = itemMeta.getLore()
.stream() .stream()
.map(s -> s.substring(8)) .map(s -> s.substring(8))
.map(s -> {
return s.replace("ATTACHMENT", "*")
.replace("CONNECTION", "CON")
.replace("FACING", "*")
.replace("LAYERS", "*")
.replace("SHAPE", "*");
})
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
String name = itemMeta.getDisplayName().substring(14); String name = itemMeta.getDisplayName().substring(14);
return name + "[" + String.join(",", lore) + "]"; return name + "[" + String.join(",", lore) + "]";
} }
@SneakyThrows
public static boolean isDeactivated(Player p, BlockBoundingBox bb) {
if (bb.getSwItem() == null) {
return false;
}
String identifier = identifier(bb);
YAPIONObject yapionObject = yapionObjectMap.get(p);
if (yapionObject == null) {
return false;
}
return yapionObject.containsKey(identifier);
}
@SneakyThrows
public static void toggle(Player p, BlockBoundingBox bb) {
if (bb.getSwItem() == null) {
return;
}
String identifier = identifier(bb);
YAPIONObject yapionObject = yapionObjectMap.get(p);
if (yapionObject == null) {
yapionObject = new YAPIONObject();
yapionObjectMap.put(p, yapionObject);
}
if (yapionObject.containsKey(identifier)) {
yapionObject.remove(identifier);
} else {
yapionObject.put(identifier, new YAPIONObject());
}
}
} }

Datei anzeigen

@ -48,15 +48,15 @@ public class LanternBoundingBox implements Enable {
List<Cuboid> cuboidList = new ArrayList<>(); List<Cuboid> cuboidList = new ArrayList<>();
cuboidList.add(pixelCuboid(5, 0, 5, 6, 7, 6)); cuboidList.add(pixelCuboid(5, 0, 5, 6, 7, 6));
cuboidList.add(pixelCuboid(6, 7, 6, 4, 2, 4)); cuboidList.add(pixelCuboid(6, 7, 6, 4, 2, 4));
new BlockBoundingBox(lantern, cuboidList, createItem("LAUFBAU_BLOCK_LANTERN", Material.LANTERN, "LAUFBAU_HANGING")); new BlockBoundingBox(lantern, cuboidList, createItem("LAUFBAU_BLOCK_LANTERN", Material.LANTERN));
} }
public void hangingLantern() { public void hangingLantern() {
Lantern lantern = (Lantern) Material.LANTERN.createBlockData(); Lantern lantern = (Lantern) Material.LANTERN.createBlockData();
lantern.setHanging(false); lantern.setHanging(true);
List<Cuboid> cuboidList = new ArrayList<>(); List<Cuboid> cuboidList = new ArrayList<>();
cuboidList.add(pixelCuboid(5, 1, 5, 6, 7, 6)); cuboidList.add(pixelCuboid(5, 1, 5, 6, 7, 6));
cuboidList.add(pixelCuboid(6, 8, 6, 4, 2, 4)); cuboidList.add(pixelCuboid(6, 8, 6, 4, 2, 4));
new BlockBoundingBox(lantern, cuboidList, createItem("LAUFBAU_BLOCK_LANTERN", Material.LANTERN)); new BlockBoundingBox(lantern, cuboidList, createItem("LAUFBAU_BLOCK_LANTERN", Material.LANTERN, "LAUFBAU_HANGING"));
} }
} }

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.bausystem.linkage; package de.steamwar.bausystem.linkage;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.configplayer.Config;
import de.steamwar.bausystem.utils.FlatteningWrapper; import de.steamwar.bausystem.utils.FlatteningWrapper;
import de.steamwar.bausystem.utils.NMSWrapper; import de.steamwar.bausystem.utils.NMSWrapper;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
@ -42,6 +43,7 @@ public class LinkageUtils {
private Set<Field> fieldsToLink = new HashSet<>(); private Set<Field> fieldsToLink = new HashSet<>();
{ {
objectMap.put(Config.class, Config.getInstance());
objectMap.put(BauSystem.class, BauSystem.getInstance()); objectMap.put(BauSystem.class, BauSystem.getInstance());
objectMap.put(FlatteningWrapper.IFlatteningWrapper.class, FlatteningWrapper.impl); objectMap.put(FlatteningWrapper.IFlatteningWrapper.class, FlatteningWrapper.impl);
objectMap.put(NMSWrapper.INMSWrapper.class, NMSWrapper.impl); objectMap.put(NMSWrapper.INMSWrapper.class, NMSWrapper.impl);