Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
cf569d6e76
Commit
3183d71478
39
BauSystem_15/src/de/steamwar/bausystem/utils/PlaceItemWrapper15.java
Normale Datei
39
BauSystem_15/src/de/steamwar/bausystem/utils/PlaceItemWrapper15.java
Normale Datei
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
43
BauSystem_20/src/de/steamwar/bausystem/utils/PlaceItemWrapper20.java
Normale Datei
43
BauSystem_20/src/de/steamwar/bausystem/utils/PlaceItemWrapper20.java
Normale Datei
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -81,26 +81,6 @@ public class PlaceItemUtils {
|
|||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Map<Material, Material> ITEM_MATERIAL_TO_BLOCK_MATERIAL = new HashMap<>();
|
|
||||||
private static final Map<Material, Material> 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 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 Reflection.ConstructorInvoker blockPositionConstructor = Reflection.getConstructor(blockPosition, int.class, int.class, int.class);
|
||||||
private static final Class<?> craftBlock = Reflection.getClass("{obc}.block.CraftBlockState");
|
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
|
// Converting the Item Material to a Block Material
|
||||||
// e.g. Material.REDSTONE -> Material.REDSTONE_WIRE
|
// 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;
|
BlockData blockData = null;
|
||||||
AtomicBoolean usedForcePlace = new AtomicBoolean();
|
AtomicBoolean usedForcePlace = new AtomicBoolean();
|
||||||
if (againstSide == BlockFace.NORTH || againstSide == BlockFace.SOUTH || againstSide == BlockFace.EAST || againstSide == BlockFace.WEST) {
|
if (againstSide == BlockFace.NORTH || againstSide == BlockFace.SOUTH || againstSide == BlockFace.EAST || againstSide == BlockFace.WEST) {
|
||||||
// Try Wall Placement first
|
// 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)) {
|
if (blockData != null && !canPlace(block, blockData, force, usedForcePlace)) {
|
||||||
// Check if default Rotation from input could be valid
|
// Check if default Rotation from input could be valid
|
||||||
BlockFace rotation = getRotation(blockData);
|
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;
|
Directional directional = (Directional) blockData;
|
||||||
if (directional.getFaces().contains(againstSide)) {
|
if (directional.getFaces().contains(againstSide)) {
|
||||||
directional.setFacing(againstSide);
|
directional.setFacing(againstSide);
|
||||||
|
34
BauSystem_Main/src/de/steamwar/bausystem/utils/PlaceItemWrapper.java
Normale Datei
34
BauSystem_Main/src/de/steamwar/bausystem/utils/PlaceItemWrapper.java
Normale Datei
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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<Material, Material> ITEM_MATERIAL_TO_BLOCK_MATERIAL = new HashMap<>();
|
||||||
|
Map<Material, Material> BLOCK_MATERIAL_TO_WALL_BLOCK_MATERIAL = new HashMap<>();
|
||||||
|
|
||||||
|
PlaceItemWrapper impl = VersionDependent.getVersionImpl(BauSystem.getInstance());
|
||||||
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren