YeetAPION #176
@ -59,7 +59,7 @@ public class Laufbau {
|
|||||||
editSession = WorldEditUtils.getEditSession(player);
|
editSession = WorldEditUtils.getEditSession(player);
|
||||||
|
|
||||||
elements = BlockBoundingBox.elements.stream().filter(blockBoundingBox -> {
|
elements = BlockBoundingBox.elements.stream().filter(blockBoundingBox -> {
|
||||||
return !LaufbauUtils.isDeactivated(player, blockBoundingBox);
|
return !LaufbauUtils.get(player).isDeactivated(blockBoundingBox);
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
if (preferingBlastResistance) {
|
if (preferingBlastResistance) {
|
||||||
elements.sort((o1, o2) -> {
|
elements.sort((o1, o2) -> {
|
||||||
|
@ -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) -> {
|
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) {
|
if (entry.getValue().size() == 1) {
|
||||||
LaufbauUtils.toggle(p, entry.getValue().get(0));
|
LaufbauUtils.get(p).toggle(entry.getValue().get(0));
|
||||||
open();
|
open();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -80,13 +80,13 @@ public class LaufbauSettings {
|
|||||||
lore = itemMeta.getLore();
|
lore = itemMeta.getLore();
|
||||||
}
|
}
|
||||||
lore.add("");
|
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);
|
itemMeta.setLore(lore);
|
||||||
swItem.setItemMeta(itemMeta);
|
swItem.setItemMeta(itemMeta);
|
||||||
list.add(new SWListInv.SWListEntry<>(swItem, bb));
|
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) -> {
|
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);
|
open(key);
|
||||||
});
|
});
|
||||||
inv.setItem(49, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_GUI_BACK", p), clickType -> {
|
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 = itemMeta.getLore();
|
||||||
}
|
}
|
||||||
lore.add("");
|
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("");
|
||||||
lore.add(BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_TOGGLE", p));
|
lore.add(BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_TOGGLE", p));
|
||||||
itemMeta.setLore(lore);
|
itemMeta.setLore(lore);
|
||||||
swItem.setItemMeta(itemMeta);
|
swItem.setItemMeta(itemMeta);
|
||||||
return swItem;
|
return swItem;
|
||||||
} else {
|
} 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) {
|
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 -> {});
|
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) {
|
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()) {
|
if (count != blockBoundingBoxes.size()) {
|
||||||
blockBoundingBoxes.forEach(bb -> {
|
blockBoundingBoxes.forEach(bb -> {
|
||||||
if (!LaufbauUtils.isDeactivated(p, bb)) {
|
if (!LaufbauUtils.get(p).isDeactivated(bb)) {
|
||||||
LaufbauUtils.toggle(p, bb);
|
LaufbauUtils.get(p).toggle(bb);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
blockBoundingBoxes.forEach(bb -> {
|
blockBoundingBoxes.forEach(bb -> {
|
||||||
LaufbauUtils.toggle(p, bb);
|
LaufbauUtils.get(p).toggle(bb);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,63 +20,28 @@
|
|||||||
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.config.ConfigField;
|
||||||
|
import de.steamwar.bausystem.config.YamlConfig;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import de.steamwar.sql.UserConfig;
|
import de.steamwar.sql.UserConfig;
|
||||||
import lombok.Cleanup;
|
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
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 yapion.parser.options.StreamOptions;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.zip.GZIPInputStream;
|
|
||||||
import java.util.zip.GZIPOutputStream;
|
|
||||||
|
|
||||||
@Linked
|
public class LaufbauUtils extends YamlConfig {
|
||||||
public class LaufbauUtils implements Listener {
|
|
||||||
|
|
||||||
private static Map<Player, YAPIONObject> yapionObjectMap = new HashMap<>();
|
private static final Map<Player, LaufbauUtils> utilsMap = new HashMap<>();
|
||||||
|
public static LaufbauUtils get(Player p) {
|
||||||
@EventHandler
|
return utilsMap.computeIfAbsent(p, player -> new LaufbauUtils(fromUserConfig(player.getUniqueId(), "bausystem-laufbau")));
|
||||||
@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()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
@ -119,34 +84,42 @@ public class LaufbauUtils implements Listener {
|
|||||||
return name + "[" + String.join(",", lore) + "]";
|
return name + "[" + String.join(",", lore) + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@ConfigField
|
||||||
public static boolean isDeactivated(Player p, BlockBoundingBox bb) {
|
private final List<String> deactivated = new ArrayList<>();
|
||||||
if (bb.getSwItem() == null) {
|
|
||||||
return false;
|
public LaufbauUtils(ConfigurationSection config) {
|
||||||
}
|
super(config);
|
||||||
String identifier = identifier(bb);
|
|
||||||
YAPIONObject yapionObject = yapionObjectMap.get(p);
|
|
||||||
if (yapionObject == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return yapionObject.containsKey(identifier);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static void toggle(Player p, BlockBoundingBox bb) {
|
public boolean isDeactivated(BlockBoundingBox bb) {
|
||||||
if (bb.getSwItem() == null) {
|
if (bb.getSwItem() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return deactivated.contains(identifier(bb));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
public void toggle(BlockBoundingBox bb) {
|
||||||
|
if (bb.getSwItem() == null)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
String identifier = identifier(bb);
|
String identifier = identifier(bb);
|
||||||
YAPIONObject yapionObject = yapionObjectMap.get(p);
|
if(deactivated.remove(identifier))
|
||||||
if (yapionObject == null) {
|
return;
|
||||||
yapionObject = new YAPIONObject();
|
deactivated.add(identifier);
|
||||||
yapionObjectMap.put(p, yapionObject);
|
|
||||||
}
|
}
|
||||||
if (yapionObject.containsKey(identifier)) {
|
|
||||||
yapionObject.remove(identifier);
|
@Linked
|
||||||
} else {
|
public static class LaufbauUtilListener implements Listener {
|
||||||
yapionObject.put(identifier, new YAPIONObject());
|
|
||||||
|
@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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren