SteamWar/BauSystem2.0
Archiviert
12
0

YeetAPION: Laufbau
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Dieser Commit ist enthalten in:
Lixfel 2023-05-15 09:23:32 +02:00
Ursprung 19b23da6d0
Commit 1fbcef67ad
3 geänderte Dateien mit 47 neuen und 74 gelöschten Zeilen

Datei anzeigen

@ -59,7 +59,7 @@ public class Laufbau {
editSession = WorldEditUtils.getEditSession(player);
elements = BlockBoundingBox.elements.stream().filter(blockBoundingBox -> {
return !LaufbauUtils.isDeactivated(player, blockBoundingBox);
return !LaufbauUtils.get(player).isDeactivated(blockBoundingBox);
}).collect(Collectors.toList());
if (preferingBlastResistance) {
elements.sort((o1, o2) -> {

Datei anzeigen

@ -55,7 +55,7 @@ public class LaufbauSettings {
}
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));
LaufbauUtils.get(p).toggle(entry.getValue().get(0));
open();
return;
}
@ -80,13 +80,13 @@ public class LaufbauSettings {
lore = itemMeta.getLore();
}
lore.add("");
lore.add(BauSystem.MESSAGE.parse(LaufbauUtils.isDeactivated(p, bb) ? "LAUFBAU_SETTINGS_INACTIVE" : "LAUFBAU_SETTINGS_ACTIVE", p));
lore.add(BauSystem.MESSAGE.parse(LaufbauUtils.get(p).isDeactivated(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);
LaufbauUtils.get(p).toggle(blockBoundingBox);
open(key);
});
inv.setItem(49, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_GUI_BACK", p), clickType -> {
@ -105,14 +105,14 @@ public class LaufbauSettings {
lore = itemMeta.getLore();
}
lore.add("");
lore.add(BauSystem.MESSAGE.parse(LaufbauUtils.isDeactivated(p, bb) ? "LAUFBAU_SETTINGS_INACTIVE" : "LAUFBAU_SETTINGS_ACTIVE", p));
lore.add(BauSystem.MESSAGE.parse(LaufbauUtils.get(p).isDeactivated(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();
long count = blockBoundingBoxes.stream().filter(bb -> LaufbauUtils.get(p).isDeactivated(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 -> {});
}
@ -124,16 +124,16 @@ public class LaufbauSettings {
}
public void toggle(List<BlockBoundingBox> blockBoundingBoxes) {
long count = blockBoundingBoxes.stream().filter(bb -> LaufbauUtils.isDeactivated(p, bb)).count();
long count = blockBoundingBoxes.stream().filter(bb -> LaufbauUtils.get(p).isDeactivated(bb)).count();
if (count != blockBoundingBoxes.size()) {
blockBoundingBoxes.forEach(bb -> {
if (!LaufbauUtils.isDeactivated(p, bb)) {
LaufbauUtils.toggle(p, bb);
if (!LaufbauUtils.get(p).isDeactivated(bb)) {
LaufbauUtils.get(p).toggle(bb);
}
});
} else {
blockBoundingBoxes.forEach(bb -> {
LaufbauUtils.toggle(p, bb);
LaufbauUtils.get(p).toggle(bb);
});
}
}

Datei anzeigen

@ -20,63 +20,28 @@
package de.steamwar.bausystem.features.slaves.laufbau;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.config.ConfigField;
import de.steamwar.bausystem.config.YamlConfig;
import de.steamwar.inventory.SWItem;
import de.steamwar.linkage.Linked;
import de.steamwar.sql.UserConfig;
import lombok.Cleanup;
import lombok.SneakyThrows;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
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 yapion.hierarchy.output.StreamOutput;
import yapion.hierarchy.types.YAPIONObject;
import yapion.parser.YAPIONParser;
import yapion.parser.options.StreamOptions;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.*;
import java.util.stream.Collectors;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
@Linked
public class LaufbauUtils implements Listener {
public class LaufbauUtils extends YamlConfig {
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, new StreamOptions().stopOnStreamEnd(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()));
private static final Map<Player, LaufbauUtils> utilsMap = new HashMap<>();
public static LaufbauUtils get(Player p) {
return utilsMap.computeIfAbsent(p, player -> new LaufbauUtils(fromUserConfig(player.getUniqueId(), "bausystem-laufbau")));
}
public static Cuboid pixelCuboid(double pixelX, double pixelY, double pixelZ, double pixelDX, double pixelDY, double pixelDZ) {
@ -119,34 +84,42 @@ public class LaufbauUtils implements Listener {
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);
@ConfigField
private final List<String> deactivated = new ArrayList<>();
public LaufbauUtils(ConfigurationSection config) {
super(config);
}
@SneakyThrows
public static void toggle(Player p, BlockBoundingBox bb) {
public boolean isDeactivated(BlockBoundingBox bb) {
if (bb.getSwItem() == null) {
return false;
}
return deactivated.contains(identifier(bb));
}
@SneakyThrows
public void toggle(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(deactivated.remove(identifier))
return;
deactivated.add(identifier);
}
if (yapionObject.containsKey(identifier)) {
yapionObject.remove(identifier);
} else {
yapionObject.put(identifier, new YAPIONObject());
@Linked
public static class LaufbauUtilListener implements Listener {
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
LaufbauUtils util = utilsMap.remove(event.getPlayer());
if(util == null)
return;
UserConfig.updatePlayerConfig(event.getPlayer().getUniqueId(), "bausystem-laufbau", util.toYaml().saveToString());
}
}
}