SteamWar/BauSystem2.0
Archiviert
12
0

Hotfix RedstoneWireAttribute and RepeaterAttribute
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-12-09 20:00:06 +01:00
Ursprung 6d298e1dec
Commit e7e714f8ee
4 geänderte Dateien mit 28 neuen und 17 gelöschten Zeilen

Datei anzeigen

@ -96,6 +96,9 @@ public class AttributesCopyCommand extends SWCommand {
if (itemStack.getType() == Material.DRAGON_HEAD && block.getType() == Material.DRAGON_WALL_HEAD) return true;
if (itemStack.getType() == Material.SKELETON_SKULL && block.getType() == Material.SKELETON_WALL_SKULL) return true;
if (itemStack.getType() == Material.WITHER_SKELETON_SKULL && block.getType() == Material.WITHER_SKELETON_WALL_SKULL) return true;
if (itemStack.getType() == Material.TORCH && block.getType() == Material.WALL_TORCH) return true;
if (itemStack.getType() == Material.SOUL_TORCH && block.getType() == Material.SOUL_WALL_TORCH) return true;
if (itemStack.getType().name().contains("_BANNER") && block.getType().name().contains("_WALL_BANNER")) return true;
return false;
}
}

Datei anzeigen

@ -19,8 +19,11 @@
package de.steamwar.bausystem.features.attributescopy;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.linkage.Linked;
import de.steamwar.linkage.MinVersion;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.event.EventHandler;
@ -37,7 +40,7 @@ import static de.steamwar.bausystem.features.attributescopy.AttributesCopyComman
@Linked
@MinVersion(18)
public class AttributesCopyListener implements Listener {
public class AttributesPlaceListener implements Listener {
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
@ -49,14 +52,19 @@ public class AttributesCopyListener implements Listener {
if (strings == null) return;
if (strings.isEmpty()) return;
if (!strings.get(0).equals("§eAttributes§8:")) return;
Set<String> attributesToPaste = new HashSet<>(strings);
Block block = event.getBlock();
BlockData blockData = block.getBlockData();
for (BlockAttribute blockAttribute : blockAttributeList) {
if (blockAttribute.type().isInstance(blockData)) {
blockAttribute.paste(attributesToPaste, blockData);
Material type = event.getBlock().getType();
event.setCancelled(true);
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
event.getBlock().setType(type, false);
Set<String> attributesToPaste = new HashSet<>(strings);
Block block = event.getBlock();
BlockData blockData = block.getBlockData();
for (BlockAttribute blockAttribute : blockAttributeList) {
if (blockAttribute.type().isInstance(blockData)) {
blockAttribute.paste(attributesToPaste, blockData);
}
}
}
block.setBlockData(blockData, false);
block.setBlockData(blockData, false);
}, 1);
}
}

Datei anzeigen

@ -40,10 +40,7 @@ public class RedstoneWireAttribute implements BlockAttribute<RedstoneWire> {
@Override
public void copy(List<String> attributes, RedstoneWire blockData) {
for (BlockFace blockFace : blockData.getAllowedFaces()) {
RedstoneWire.Connection connection = blockData.getFace(blockFace);
if (connection != RedstoneWire.Connection.NONE) {
attributes.add(attribute + blockFace.name().toLowerCase() + " " + connection.name().toLowerCase());
}
attributes.add(attribute + blockFace.name().toLowerCase() + " " + blockData.getFace(blockFace).name().toLowerCase());
}
}

Datei anzeigen

@ -29,7 +29,8 @@ import java.util.Set;
@Linked
public class RepeaterAttribute implements BlockAttribute<Repeater> {
private String attribute = "§8-§7 delay ";
private String attribute1 = "§8-§7 delay ";
private String attribute2 = "§8-§7 locked";
@Override
public Class<Repeater> type() {
@ -38,16 +39,18 @@ public class RepeaterAttribute implements BlockAttribute<Repeater> {
@Override
public void copy(List<String> attributes, Repeater blockData) {
attributes.add(attribute + blockData.getDelay());
attributes.add(attribute1 + blockData.getDelay());
if (blockData.isLocked()) attributes.add(attribute2);
}
@Override
public void paste(Set<String> attributes, Repeater blockData) {
attributes.stream()
.filter(s -> s.startsWith(attribute))
.map(s -> s.replace(attribute, ""))
.filter(s -> s.startsWith(attribute1))
.map(s -> s.replace(attribute1, ""))
.map(Integer::parseInt)
.findFirst()
.ifPresent(blockData::setDelay);
blockData.setLocked(attributes.contains(attribute2));
}
}