SteamWar/BauSystem2.0
Archiviert
12
0

Hotfix MultipleFacingAttribute and AttributesPlaceListener and AttributesCopyCommand
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:24:48 +01:00
Ursprung e7e714f8ee
Commit 6a52a319ab
3 geänderte Dateien mit 43 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -62,6 +62,9 @@ public class AttributesCopyCommand extends SWCommand {
} }
BlockData blockData = block.getBlockData(); BlockData blockData = block.getBlockData();
List<String> attributesToCopy = new ArrayList<>(); List<String> attributesToCopy = new ArrayList<>();
if (needsType(block)) {
attributesToCopy.add("§8-§7 type " + block.getType().name().toLowerCase());
}
for (BlockAttribute blockAttribute : blockAttributeList) { for (BlockAttribute blockAttribute : blockAttributeList) {
if (blockAttribute.type().isInstance(blockData)) { if (blockAttribute.type().isInstance(blockData)) {
blockAttribute.copy(attributesToCopy, blockData); blockAttribute.copy(attributesToCopy, blockData);
@ -98,7 +101,23 @@ public class AttributesCopyCommand extends SWCommand {
if (itemStack.getType() == Material.WITHER_SKELETON_SKULL && block.getType() == Material.WITHER_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.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() == Material.SOUL_TORCH && block.getType() == Material.SOUL_WALL_TORCH) return true;
if (itemStack.getType() == Material.REDSTONE_TORCH && block.getType() == Material.REDSTONE_WALL_TORCH) return true;
if (itemStack.getType().name().contains("_BANNER") && block.getType().name().contains("_WALL_BANNER")) return true; if (itemStack.getType().name().contains("_BANNER") && block.getType().name().contains("_WALL_BANNER")) return true;
return false; return false;
} }
private boolean needsType(Block block) {
if (block.getType().name().contains("WALL")) return true;
if (block.getType() == Material.PLAYER_HEAD) return true;
if (block.getType() == Material.ZOMBIE_HEAD) return true;
if (block.getType() == Material.CREEPER_HEAD) return true;
if (block.getType() == Material.DRAGON_HEAD) return true;
if (block.getType() == Material.SKELETON_SKULL) return true;
if (block.getType() == Material.WITHER_SKELETON_SKULL) return true;
if (block.getType() == Material.TORCH) return true;
if (block.getType() == Material.SOUL_TORCH) return true;
if (block.getType() == Material.REDSTONE_TORCH) return true;
if (block.getType().name().contains("_BANNER")) return true;
return false;
}
} }

Datei anzeigen

@ -24,13 +24,16 @@ import de.steamwar.linkage.Linked;
import de.steamwar.linkage.MinVersion; import de.steamwar.linkage.MinVersion;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.Skull;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.profile.PlayerProfile;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -53,12 +56,32 @@ public class AttributesPlaceListener implements Listener {
if (strings.isEmpty()) return; if (strings.isEmpty()) return;
if (!strings.get(0).equals("§eAttributes§8:")) return; if (!strings.get(0).equals("§eAttributes§8:")) return;
Material type = event.getBlock().getType(); Material type = event.getBlock().getType();
OfflinePlayer offlinePlayer = null;
if (event.getBlock().getState() instanceof Skull) {
Skull skull = (Skull) event.getBlock().getState();
offlinePlayer = skull.getOwningPlayer();
}
OfflinePlayer finalPlayerProfile = offlinePlayer;
event.setCancelled(true); event.setCancelled(true);
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
event.getBlock().setType(type, false); Material material = strings.stream()
.filter(s -> s.startsWith("§8-§7 type "))
.map(s -> s.replace("§8-§7 type ", ""))
.map(String::toUpperCase)
.map(Material::valueOf)
.findFirst()
.orElse(type);
event.getBlock().setType(material, false);
Set<String> attributesToPaste = new HashSet<>(strings); Set<String> attributesToPaste = new HashSet<>(strings);
Block block = event.getBlock(); Block block = event.getBlock();
BlockData blockData = block.getBlockData(); BlockData blockData = block.getBlockData();
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
if (block.getState() instanceof Skull && finalPlayerProfile != null) {
Skull skull = (Skull) block.getState();
skull.setOwningPlayer(finalPlayerProfile);
skull.update(true, false);
}
}, 1);
for (BlockAttribute blockAttribute : blockAttributeList) { for (BlockAttribute blockAttribute : blockAttributeList) {
if (blockAttribute.type().isInstance(blockData)) { if (blockAttribute.type().isInstance(blockData)) {
blockAttribute.paste(attributesToPaste, blockData); blockAttribute.paste(attributesToPaste, blockData);

Datei anzeigen

@ -47,7 +47,6 @@ public class MultipleFacingAttribute implements BlockAttribute<MultipleFacing> {
@Override @Override
public void paste(Set<String> attributes, MultipleFacing blockData) { public void paste(Set<String> attributes, MultipleFacing blockData) {
for (BlockFace blockFace : BlockFace.values()) { for (BlockFace blockFace : BlockFace.values()) {
if (!blockData.getAllowedFaces().contains(blockFace)) continue;
blockData.setFace(blockFace, attributes.contains(attribute + blockFace.name().toLowerCase())); blockData.setFace(blockFace, attributes.contains(attribute + blockFace.name().toLowerCase()));
} }
} }