diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/PlaceItemWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/PlaceItemWrapper15.java new file mode 100644 index 00000000..d0828173 --- /dev/null +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/PlaceItemWrapper15.java @@ -0,0 +1,39 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.utils; + +import org.bukkit.Material; + +public class PlaceItemWrapper15 implements PlaceItemWrapper { + + public PlaceItemWrapper15() { + for (Material material : Material.values()) { + if (!material.isBlock()) continue; + if (material.isLegacy()) continue; + + String nonWall = material.name().replace("_WALL_", "").replace("WALL_", "").replace("_WALL", ""); + Material nonWallMaterial = Material.valueOf(nonWall); + if (nonWallMaterial != material) { + BLOCK_MATERIAL_TO_WALL_BLOCK_MATERIAL.put(nonWallMaterial, material); + } + } + ITEM_MATERIAL_TO_BLOCK_MATERIAL.put(Material.REDSTONE, Material.REDSTONE_WIRE); + } +} diff --git a/BauSystem_20/src/de/steamwar/bausystem/utils/PlaceItemWrapper20.java b/BauSystem_20/src/de/steamwar/bausystem/utils/PlaceItemWrapper20.java new file mode 100644 index 00000000..e9fc1b0d --- /dev/null +++ b/BauSystem_20/src/de/steamwar/bausystem/utils/PlaceItemWrapper20.java @@ -0,0 +1,43 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.utils; + +import org.bukkit.Material; +import org.bukkit.block.data.BlockData; + +public class PlaceItemWrapper20 implements PlaceItemWrapper { + + public PlaceItemWrapper20() { + for (Material material : Material.values()) { + if (!material.isBlock()) continue; + if (material.isLegacy()) continue; + BlockData blockData = material.createBlockData(); + Material placementMaterial = blockData.getPlacementMaterial(); + if (material == placementMaterial) continue; + if (placementMaterial == Material.AIR) continue; + if (placementMaterial.isItem() && !placementMaterial.isBlock()) { + ITEM_MATERIAL_TO_BLOCK_MATERIAL.put(placementMaterial, material); + } + if (material.name().contains("WALL")) { + BLOCK_MATERIAL_TO_WALL_BLOCK_MATERIAL.put(placementMaterial, material); + } + } + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/PlaceItemUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/PlaceItemUtils.java index 2f83c416..8fb4519d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/PlaceItemUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/PlaceItemUtils.java @@ -81,26 +81,6 @@ public class PlaceItemUtils { .collect(Collectors.toSet()); } - private static final Map ITEM_MATERIAL_TO_BLOCK_MATERIAL = new HashMap<>(); - private static final Map BLOCK_MATERIAL_TO_WALL_BLOCK_MATERIAL = new HashMap<>(); - - static { - for (Material material : Material.values()) { - if (!material.isBlock()) continue; - if (material.isLegacy()) continue; - BlockData blockData = material.createBlockData(); - Material placementMaterial = blockData.getPlacementMaterial(); - if (material == placementMaterial) continue; - if (placementMaterial == Material.AIR) continue; - if (placementMaterial.isItem() && !placementMaterial.isBlock()) { - ITEM_MATERIAL_TO_BLOCK_MATERIAL.put(placementMaterial, material); - } - if (material.name().contains("WALL")) { - BLOCK_MATERIAL_TO_WALL_BLOCK_MATERIAL.put(placementMaterial, material); - } - } - } - private static final Class blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); private static final Reflection.ConstructorInvoker blockPositionConstructor = Reflection.getConstructor(blockPosition, int.class, int.class, int.class); private static final Class craftBlock = Reflection.getClass("{obc}.block.CraftBlockState"); @@ -141,13 +121,13 @@ public class PlaceItemUtils { // Converting the Item Material to a Block Material // e.g. Material.REDSTONE -> Material.REDSTONE_WIRE - Material typeToPlace = ITEM_MATERIAL_TO_BLOCK_MATERIAL.getOrDefault(itemStack.getType(), itemStack.getType()); + Material typeToPlace = PlaceItemWrapper.ITEM_MATERIAL_TO_BLOCK_MATERIAL.getOrDefault(itemStack.getType(), itemStack.getType()); BlockData blockData = null; AtomicBoolean usedForcePlace = new AtomicBoolean(); if (againstSide == BlockFace.NORTH || againstSide == BlockFace.SOUTH || againstSide == BlockFace.EAST || againstSide == BlockFace.WEST) { // Try Wall Placement first - blockData = toBlockData(player, blockDataMeta, BLOCK_MATERIAL_TO_WALL_BLOCK_MATERIAL.getOrDefault(typeToPlace, typeToPlace)); + blockData = toBlockData(player, blockDataMeta, PlaceItemWrapper.BLOCK_MATERIAL_TO_WALL_BLOCK_MATERIAL.getOrDefault(typeToPlace, typeToPlace)); if (blockData != null && !canPlace(block, blockData, force, usedForcePlace)) { // Check if default Rotation from input could be valid BlockFace rotation = getRotation(blockData); @@ -243,7 +223,7 @@ public class PlaceItemUtils { } } } - if (force && blockData instanceof Directional && !(blockData instanceof FaceAttachable) && BLOCK_MATERIAL_TO_WALL_BLOCK_MATERIAL.containsValue(blockData.getMaterial())) { + if (force && blockData instanceof Directional && !(blockData instanceof FaceAttachable) && PlaceItemWrapper.BLOCK_MATERIAL_TO_WALL_BLOCK_MATERIAL.containsValue(blockData.getMaterial())) { Directional directional = (Directional) blockData; if (directional.getFaces().contains(againstSide)) { directional.setFacing(againstSide); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/PlaceItemWrapper.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/PlaceItemWrapper.java new file mode 100644 index 00000000..d518adbc --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/PlaceItemWrapper.java @@ -0,0 +1,34 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.utils; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.core.VersionDependent; +import org.bukkit.Material; + +import java.util.HashMap; +import java.util.Map; + +public interface PlaceItemWrapper { + Map ITEM_MATERIAL_TO_BLOCK_MATERIAL = new HashMap<>(); + Map BLOCK_MATERIAL_TO_WALL_BLOCK_MATERIAL = new HashMap<>(); + + PlaceItemWrapper impl = VersionDependent.getVersionImpl(BauSystem.getInstance()); +}