Add SchematicSystem module

This commit is contained in:
2024-08-05 11:49:36 +02:00
parent 90a3375ac6
commit 71a3d84386
34 changed files with 4225 additions and 0 deletions
@@ -0,0 +1,58 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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/>.
*/
plugins {
id("java")
id("base")
}
group = "de.steamwar"
version = ""
tasks.compileJava {
options.encoding = "UTF-8"
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
sourceSets {
main {
java {
srcDirs("src/")
}
resources {
srcDirs("src/")
exclude("**/*.java", "**/*.kt")
}
}
}
dependencies {
compileOnly("org.projectlombok:lombok:1.18.32")
annotationProcessor("org.projectlombok:lombok:1.18.32")
compileOnly(project(":SchematicSystem:SchematicSystem_Core"))
compileOnly(project(":SpigotCore"))
compileOnly("de.steamwar:spigot:1.8")
compileOnly("de.steamwar:worldedit:1.12")
}
@@ -0,0 +1,174 @@
/*
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.schematicsystem.autocheck;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.regions.Region;
import de.steamwar.schematicsystem.CheckSchemType;
import org.bukkit.Material;
import java.util.*;
import java.util.stream.Collectors;
@SuppressWarnings("deprecation")
public class AutoChecker8 implements AutoChecker.IAutoChecker {
private static final int DISPENSER = Material.DISPENSER.getId();
private static final int JUKEBOX = Material.JUKEBOX.getId();
private static final int CHEST = Material.CHEST.getId();
private static final Set<Integer> INVENTORY = new HashSet<>();
private static final Set<Material> FLOWERS;
static{
INVENTORY.add(CHEST);
INVENTORY.add(Material.TRAPPED_CHEST.getId());
INVENTORY.add(Material.HOPPER.getId());
INVENTORY.add(Material.FURNACE.getId());
INVENTORY.add(Material.BURNING_FURNACE.getId());
INVENTORY.add(JUKEBOX); //RecordItem
INVENTORY.add(DISPENSER);
INVENTORY.add(Material.DROPPER.getId());
INVENTORY.add(Material.ANVIL.getId());
INVENTORY.add(Material.BREWING_STAND.getId());
for(int i = 219; i <= 234; i++) {
INVENTORY.add(i); // ShulkerBoxes
}
Set<Material> flowers = new HashSet<>();
flowers.add(Material.YELLOW_FLOWER);
flowers.add(Material.RED_ROSE);
flowers.add(Material.DOUBLE_PLANT);
flowers.add(Material.DIAMOND_BARDING);
flowers.add(Material.IRON_BARDING);
flowers.add(Material.GOLD_BARDING);
FLOWERS = flowers;
}
public void scan(AutoChecker.BlockScanResult result, Clipboard clipboard) {
Region region = clipboard.getRegion();
Vector min = region.getMinimumPoint();
Vector max = region.getMaximumPoint();
for(int x = min.getBlockX(); x <= max.getBlockX(); x++){
for(int y = min.getBlockY(); y <= max.getBlockY(); y++){
for(int z = min.getBlockZ(); z <= max.getBlockZ(); z++){
final BaseBlock block = clipboard.getBlock(new Vector(x, y, z));
final int blockId = block.getId();
final Material material = Material.getMaterial(blockId);
result.getBlockCounts().merge(material, 1, Integer::sum);
if(INVENTORY.contains(blockId)){
checkInventory(result, block, blockId, new BlockPos(x, y, z));
}
if(x == 0 || x == max.getBlockX() - 1 || y == max.getBlockY() - 1 || z == 0 || z == max.getBlockZ() - 1) {
result.getDesignBlocks().computeIfAbsent(material, m -> new ArrayList<>()).add(new BlockPos(x, y, z));
}
}
}
}
}
private static final Map<Material, EnumSet<Material>> itemsInInv = new EnumMap<>(Material.class);
static {
itemsInInv.put(Material.BUCKET, EnumSet.of(Material.DISPENSER));
itemsInInv.put(Material.TNT, EnumSet.of(Material.CHEST));
itemsInInv.put(Material.FIREBALL, EnumSet.of(Material.DISPENSER));
itemsInInv.put(Material.ARROW, EnumSet.of(Material.DISPENSER));
FLOWERS.forEach(material -> itemsInInv.put(material, INVENTORY.stream().map(Material::getMaterial).collect(Collectors.toCollection(() -> EnumSet.noneOf(Material.class)))));
}
private static void checkInventory(AutoChecker.BlockScanResult result, BaseBlock block, int blockId, BlockPos pos) {
CompoundTag nbt = block.getNbtData();
if(nbt == null){
result.getDefunctNbt().add(pos);
return;
}
if(blockId == JUKEBOX && nbt.getValue().containsKey("RecordItem")){
result.getRecords().add(pos);
return;
}
List<CompoundTag> items = nbt.getList("Items", CompoundTag.class);
if(items.isEmpty())
return; //Leeres Inventar
int counter = 0;
for(CompoundTag item : items){
if(!item.containsKey("id")){
result.getDefunctNbt().add(pos);
continue;
}
String materialName = item.getString("id");
if(materialName.contains(":"))
materialName = materialName.split(":")[1];
materialName = materialName.toUpperCase().replace("SHOVEL", "SPADE");
Material itemType = Material.getMaterial(materialName);
if(itemType == null && item.getString("id").equals("minecraft:fire_charge"))
itemType = Material.FIREBALL;
if(itemType == null) //Leere Slots
continue;
if(!itemsInInv.getOrDefault(itemType, EnumSet.noneOf(Material.class)).contains(Material.getMaterial(blockId))) {
result.getForbiddenItems().computeIfAbsent(pos, blockPos -> new HashSet<>()).add(Material.getMaterial(blockId));
} else if(blockId == DISPENSER && (itemType.equals(Material.FIREBALL) || itemType.equals(Material.ARROW))) {
counter += item.getByte("Count");
}
if(item.containsKey("tag")) {
result.getForbiddenNbt().computeIfAbsent(pos, blockPos -> new HashSet<>()).add(Material.getMaterial(blockId));
}
}
result.getDispenserItems().put(pos, counter);
}
@Override
public AutoCheckerResult check(Clipboard clipboard, CheckSchemType type) {
AutoChecker.BlockScanResult blockScanResult = new AutoChecker.BlockScanResult();
scan(blockScanResult, clipboard);
return AutoCheckerResult.builder()
.type(type)
.height(clipboard.getDimensions().getBlockY())
.width(clipboard.getDimensions().getBlockX())
.depth(clipboard.getDimensions().getBlockZ())
.blockScanResult(blockScanResult)
.entities(clipboard.getEntities().stream().map(Entity::getLocation).map(blockVector3 -> new BlockPos(blockVector3.getBlockX(), blockVector3.getBlockY(), blockVector3.getBlockZ())).collect(Collectors.toList()))
.build();
}
@Override
public AutoCheckerResult sizeCheck(Clipboard clipboard, CheckSchemType type) {
return AutoCheckerResult.builder()
.type(type)
.height(clipboard.getDimensions().getBlockY())
.width(clipboard.getDimensions().getBlockX())
.depth(clipboard.getDimensions().getBlockZ())
.build();
}
}
@@ -0,0 +1,42 @@
/*
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.schematicsystem.commands.schematiccommand;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operations;
import de.steamwar.schematicsystem.CheckSchemType;
import de.steamwar.schematicsystem.autocheck.AutoCheckerResult;
import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommand;
public class SchematicCommand8 implements SchematicCommand.ISchematicCommand {
@Override
public Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, CheckSchemType type) throws Exception {
return null;
}
@Override
public void createCopy(EditSession editSession, Clipboard clipboard) throws WorldEditException {
Operations.complete(new ForwardExtentCopy(editSession, clipboard.getRegion(), clipboard, clipboard.getMinimumPoint()));
}
}