13
0

Early AutoChecker Version
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Chaoscaot 2022-11-20 23:56:43 +01:00
Ursprung 149a2e9a27
Commit fd66be9b37
13 geänderte Dateien mit 350 neuen und 319 gelöschten Zeilen

Datei anzeigen

@ -1,36 +1,18 @@
/* package de.steamwar.schematicsystem.autocheck;
This file is a part of the SteamWar software.
Copyright (C) 2020 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;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import de.steamwar.schematicsystem.CheckSchemType;
import org.bukkit.Material; import org.bukkit.Material;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
public class CheckSchemType15 implements CheckSchemType.ICheckSchemType { public class AutoChecker15 implements AutoChecker.IAutoChecker {
private static final Set<Material> INVENTORY = EnumSet.of( private static final Set<Material> INVENTORY = EnumSet.of(
Material.BARREL, Material.BARREL,
Material.BLAST_FURNACE, Material.BLAST_FURNACE,
@ -85,48 +67,41 @@ public class CheckSchemType15 implements CheckSchemType.ICheckSchemType {
Material.HONEY_BOTTLE); Material.HONEY_BOTTLE);
@Override @Override
public void autoCheck(AutoCheckResult result, Clipboard clipboard) { public AutoChecker.BlockScanResult scan(Clipboard clipboard, CheckSchemType type) {
BlockVector3 dimensions = clipboard.getDimensions(); AutoChecker.BlockScanResult result = new AutoChecker.BlockScanResult();
result.setLength(dimensions.getBlockX()); BlockVector3 min = clipboard.getMinimumPoint();
result.setHeight(dimensions.getBlockY()); BlockVector3 max = clipboard.getMaximumPoint();
result.setWidth(dimensions.getBlockZ());
Region region = clipboard.getRegion();
BlockVector3 min = region.getMinimumPoint();
BlockVector3 max = region.getMaximumPoint();
int blocks = 0;
for(int x = min.getBlockX(); x <= max.getBlockX(); x++){ for(int x = min.getBlockX(); x <= max.getBlockX(); x++){
for(int y = min.getBlockY(); y <= max.getBlockY(); y++) { for(int y = min.getBlockY(); y <= max.getBlockY(); y++) {
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) { for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
final BlockPos pos = new BlockPos(x, y, z);
final BaseBlock block = clipboard.getFullBlock(BlockVector3.at(x, y, z)); final BaseBlock block = clipboard.getFullBlock(BlockVector3.at(x, y, z));
final Material blockMaterial = Material.matchMaterial(block.getBlockType().getId()); final Material material = Material.matchMaterial(block.getBlockType().getId());
if(blockMaterial == null) if(material == null) {
continue; continue;
}
result.checkMaterial(blockMaterial.name()); result.getBlockCounts().merge(material, 1, Integer::sum);
if(blockMaterial != Material.AIR) if(INVENTORY.contains(material)) {
blocks++; checkInventory(result, block, material, pos);
if(INVENTORY.contains(blockMaterial))
checkInventory(result, block, blockMaterial);
} }
} }
} }
}
result.setBlocks(blocks); return result;
} }
private static void checkInventory(AutoCheckResult result, BaseBlock block, Material blockMaterial) { private void checkInventory(AutoChecker.BlockScanResult result, BaseBlock block, Material material, BlockPos pos) {
CompoundTag nbt = block.getNbtData(); CompoundTag nbt = block.getNbtData();
if(nbt == null) { if(nbt == null) {
result.defunctNbt(blockMaterial.name()); result.getDefunctNbt().add(pos);
return; return;
} }
if(blockMaterial == Material.JUKEBOX && nbt.getValue().containsKey("RecordItem")){
result.foundRecord(); if(material == Material.JUKEBOX && nbt.getValue().containsKey("RecordItem")){
result.getRecords().add(pos);
return; return;
} }
@ -137,7 +112,7 @@ public class CheckSchemType15 implements CheckSchemType.ICheckSchemType {
int counter = 0; int counter = 0;
for(CompoundTag item : items){ for(CompoundTag item : items){
if(!item.containsKey("id")){ if(!item.containsKey("id")){
result.defunctNbt(blockMaterial.name()); result.getDefunctNbt().add(pos);
continue; continue;
} }
@ -145,14 +120,14 @@ public class CheckSchemType15 implements CheckSchemType.ICheckSchemType {
if(itemType == null) //Leere Slots if(itemType == null) //Leere Slots
continue; continue;
if(blockMaterial == Material.DISPENSER && (itemType.equals(Material.FIRE_CHARGE) || itemType.equals(Material.ARROW))) if(material == Material.DISPENSER && (itemType.equals(Material.FIRE_CHARGE) || itemType.equals(Material.ARROW))) {
counter += item.getByte("Count"); counter += item.getByte("Count");
else if(!FLOWERS.contains(itemType) && !((blockMaterial == Material.CHEST || blockMaterial == Material.BARREL) && itemType.equals(Material.TNT))) } else if(!FLOWERS.contains(itemType) && !((material == Material.CHEST || material == Material.BARREL) && itemType.equals(Material.TNT))) {
result.foundForbiddenItem(blockMaterial.name(), itemType.name(), item.getByte("Count")); result.getForbiddenItems().computeIfAbsent(pos, blockVector3 -> new HashSet<>()).add(itemType);
else if(item.containsKey("tag")) }else if(item.containsKey("tag")) {
result.foundItemWithTag(blockMaterial.name(), itemType.name(), item.getByte("Count")); result.getForbiddenNbt().computeIfAbsent(pos, blockVector3 -> new HashSet<>()).add(itemType);
} }
}
result.dispenserItems(counter); result.getDispenserItems().put(pos, counter);
} }
} }

Datei anzeigen

@ -1,29 +1,11 @@
/* package de.steamwar.schematicsystem.autocheck;
This file is a part of the SteamWar software.
Copyright (C) 2020 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;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import de.steamwar.schematicsystem.CheckSchemType;
import org.bukkit.Material; import org.bukkit.Material;
import java.util.HashSet; import java.util.HashSet;
@ -31,7 +13,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class CheckSchemType8 implements CheckSchemType.ICheckSchemType { public class AutoChecker8 implements AutoChecker.IAutoChecker {
private static final int TNT = Material.TNT.getId(); private static final int TNT = Material.TNT.getId();
private static final int SLIME = Material.SLIME_BLOCK.getId(); private static final int SLIME = Material.SLIME_BLOCK.getId();
private static final int OBSIDIAN = Material.OBSIDIAN.getId(); private static final int OBSIDIAN = Material.OBSIDIAN.getId();
@ -68,13 +50,7 @@ public class CheckSchemType8 implements CheckSchemType.ICheckSchemType {
FLOWERS = flowers; FLOWERS = flowers;
} }
@Override public void scan(AutoChecker.BlockScanResult result, Clipboard clipboard) {
public void autoCheck(AutoCheckResult result, Clipboard clipboard) {
Vector dimensions = clipboard.getDimensions();
result.setLength(dimensions.getBlockX());
result.setHeight(dimensions.getBlockY());
result.setWidth(dimensions.getBlockZ());
Region region = clipboard.getRegion(); Region region = clipboard.getRegion();
Vector min = region.getMinimumPoint(); Vector min = region.getMinimumPoint();
Vector max = region.getMaximumPoint(); Vector max = region.getMaximumPoint();
@ -86,30 +62,28 @@ public class CheckSchemType8 implements CheckSchemType.ICheckSchemType {
final BaseBlock block = clipboard.getBlock(new Vector(x, y, z)); final BaseBlock block = clipboard.getBlock(new Vector(x, y, z));
final int blockId = block.getId(); final int blockId = block.getId();
result.checkMaterial(Material.getMaterial(blockId).name()); result.getBlockCounts().merge(Material.getMaterial(blockId), 1, Integer::sum);
if (blockId != AIR) if (blockId != AIR)
blocks++; blocks++;
if(INVENTORY.contains(blockId)){ if(INVENTORY.contains(blockId)){
checkInventory(result, block, blockId); checkInventory(result, block, blockId, new BlockPos(x, y, z));
}
} }
} }
} }
} }
result.setBlocks(blocks); private static void checkInventory(AutoChecker.BlockScanResult result, BaseBlock block, int blockId, BlockPos pos) {
}
private static void checkInventory(AutoCheckResult result, BaseBlock block, int blockId) {
CompoundTag nbt = block.getNbtData(); CompoundTag nbt = block.getNbtData();
if(nbt == null){ if(nbt == null){
result.defunctNbt(Material.getMaterial(blockId).name()); result.getDefunctNbt().add(pos);
return; return;
} }
if(blockId == JUKEBOX && nbt.getValue().containsKey("RecordItem")){ if(blockId == JUKEBOX && nbt.getValue().containsKey("RecordItem")){
result.foundRecord(); result.getRecords().add(pos);
return; return;
} }
@ -120,7 +94,7 @@ public class CheckSchemType8 implements CheckSchemType.ICheckSchemType {
int counter = 0; int counter = 0;
for(CompoundTag item : items){ for(CompoundTag item : items){
if(!item.containsKey("id")){ if(!item.containsKey("id")){
result.defunctNbt(Material.getMaterial(blockId).name()); result.getDefunctNbt().add(pos);
continue; continue;
} }
@ -136,12 +110,19 @@ public class CheckSchemType8 implements CheckSchemType.ICheckSchemType {
if(blockId == DISPENSER && (itemType.equals(Material.FIREBALL) || itemType.equals(Material.ARROW))) if(blockId == DISPENSER && (itemType.equals(Material.FIREBALL) || itemType.equals(Material.ARROW)))
counter += item.getByte("Count"); counter += item.getByte("Count");
else if(!FLOWERS.contains(itemType) && !(blockId == CHEST && itemType.equals(Material.TNT))) else if(!FLOWERS.contains(itemType) && !(blockId == CHEST && itemType.equals(Material.TNT))) {
result.foundForbiddenItem(Material.getMaterial(blockId).name(), itemType.name(), item.getByte("Count")); result.getForbiddenItems().computeIfAbsent(pos, blockPos -> new HashSet<>()).add(Material.getMaterial(blockId));
else if(item.containsKey("tag")) }
result.foundItemWithTag(Material.getMaterial(blockId).name(), itemType.name(), item.getByte("Count")); else if(item.containsKey("tag")) {
result.getForbiddenNbt().computeIfAbsent(pos, blockPos -> new HashSet<>()).add(Material.getMaterial(blockId));
}
} }
result.dispenserItems(counter); result.getDispenserItems().put(pos, counter);
}
@Override
public AutoChecker.BlockScanResult scan(Clipboard clipboard, CheckSchemType type) {
return null;
} }
} }

Datei anzeigen

@ -209,3 +209,18 @@ SAFE_NODE_INVALID_NAME=§cThis name is illegal
SAFE_NODE_NOT_OWNER=§cYou are not the owner of this schematic SAFE_NODE_NOT_OWNER=§cYou are not the owner of this schematic
DOWNLOAD_ERROR=§cAn error occurred while uploading the schematic DOWNLOAD_ERROR=§cAn error occurred while uploading the schematic
AUTO_CHECKER_RESULT_HEADER=§7---=== (§eAuto-Check: {0}§7) ===---
AUTO_CHECKER_RESULT_WIDTH =§7Width: §c{0}§7, Max: §e{1}
AUTO_CHECKER_RESULT_LENGTH=§7Length: §c{0}§7, Max: §e{1}
AUTO_CHECKER_RESULT_HEIGHT=§7Height: §c{0}§7, Max: §e{1}
AUTO_CHECKER_RESULT_BLOCKS=§7Blocks: §c{0}§7, Max: §e{1}
AUTO_CHECKER_RESULT_UNKNOWN_MATERIAL=§7Unknown block: §c{0}
AUTO_CHECKER_RESULT_TOO_MANY_BLOCK=§7{0}: {1}{2}§7, Max: §e{3}
AUTO_CHECKER_RESULT_FORBIDDEN_ITEM=§7Forbidden Item: [{0}, {1}, {2}] -> §c{3}
AUTO_CHECKER_RESULT_DEFUNCT_NBT=§7Defunct NBT: §7[{0}, {1}, {2}]
AUTO_CHECKER_RESULT_RECORD=§7Record: §c[{0}, {1}, {2}]
AUTO_CHECKER_RESULT_TOO_MANY_DISPENSER_ITEMS=§7Dispenser: §c[{0}, {1}, {2}]§7, §c{3} §7items, Max: §e{4}
AUTO_CHECKER_RESULT_FORBIDDEN_ITEM_NBT=§7Forbidden Item NBT: [{0}, {1}, {2}] -> §c{3}
AUTO_CHECKER_RESULT_TELEPORT_HERE=§7Teleport to block
AUTO_CHECKER_RESULT_AFTER_DEADLINE=§cThe deadline has expired: {0}

Datei anzeigen

@ -192,3 +192,18 @@ SAFE_NODE_INVALID_NAME=§cDieser Name ist unzulässig
SAFE_NODE_NOT_OWNER=§cDu bist nicht der Besitzer dieser Schematic SAFE_NODE_NOT_OWNER=§cDu bist nicht der Besitzer dieser Schematic
DOWNLOAD_ERROR=§cFehler beim Hochladen deines Clipboards DOWNLOAD_ERROR=§cFehler beim Hochladen deines Clipboards
AUTO_CHECKER_RESULT_HEADER=§7---=== (§eAutoPrüfer: {0}§7) ===---
AUTO_CHECKER_RESULT_WIDTH=§7Breite: §c{0}§7, Max: §e{1}
AUTO_CHECKER_RESULT_LENGTH=§7Länge: §c{0}§7, Max: §e{1}
AUTO_CHECKER_RESULT_HEIGHT=§7Höhe: §c{0}§7, Max: §e{1}
AUTO_CHECKER_RESULT_BLOCKS=§7Blöcke: §c{0}§7, Max: §e{1}
AUTO_CHECKER_RESULT_UNKNOWN_MATERIAL=§7Unbekannter Block: §c{0}
AUTO_CHECKER_RESULT_TOO_MANY_BLOCK=§7{0}: §c{1}§7, Max: §e{2}
AUTO_CHECKER_RESULT_FORBIDDEN_ITEM=§7Verbotener gegenstand: [{0}, {1}, {2}] -> §c{3}
AUTO_CHECKER_RESULT_DEFUNCT_NBT=§7Keine NBT-Daten: §c[{0}, {1}, {2}]
AUTO_CHECKER_RESULT_RECORD=§7Schallplatte: §c[{0}, {1}, {2}]
AUTO_CHECKER_RESULT_TOO_MANY_DISPENSER_ITEMS=§7Dispenser: §c[{0}, {1}, {2}]§7, §c{3} §7gegenstände, Max: §e{4}
AUTO_CHECKER_RESULT_FORBIDDEN_ITEM_NBT=§7Verbotene NBT-Daten: [{0}, {1}, {2}] -> §c{3}
AUTO_CHECKER_RESULT_TELEPORT_HERE=§7Zum block teleportieren
AUTO_CHECKER_RESULT_AFTER_DEADLINE=§cDer einsendeschluss ist bereits vorbei: {0}

Datei anzeigen

@ -1,168 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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;
import java.util.*;
public class AutoCheckResult {
private final CheckSchemType type;
private boolean errorLoadingSchematic = false;
private int width = 0;
private int height = 0;
private int length = 0;
private int blocks = 0;
private final Map<Set<String>, Integer> limitedMaterials;
private final Map<String, Integer> defunctNbt = new HashMap<>(); // Amount of defect NBT-Blocks with material name
private int records = 0; // Amount of found records
private final Map<String, Map<String, Integer>> forbiddenItems = new HashMap<>(); // Amount forbidden items per inventory block
private final Map<String, Map<String, Integer>> itemsWithTag = new HashMap<>(); // Amount of items with forbidden nbt tags
private int tooManyDispenserItems = 0; // Amount of dispensers with too many items
public AutoCheckResult(CheckSchemType type) {
this.type = type;
this.limitedMaterials = type.getLimits();
}
public Map<String, Object[]> errors() {
Map<String, Object[]> errors = new HashMap<>();
if(errorLoadingSchematic) {
errors.put("AUTO_CHECK_RESULT_NOT_LOAD", new Object[0]);
}
assert type != null;
// SW Quality Code, Check the Comments!
if(width > type.getDepth())
// Width
errors.put("AUTO_CHECK_RESULT_TOO_WIDE", new Object[]{width, type.getDepth()});
if(length > type.getWidth())
// Length
errors.put("AUTO_CHECK_RESULT_TOO_LONG", new Object[]{width, type.getWidth()});
if(height > type.getHeight())
errors.put("AUTO_CHECK_RESULT_TOO_HIGH", new Object[]{height, type.getHeight()});
for(Map.Entry<Set<String>, Integer> entry : limitedMaterials.entrySet()) {
if(entry.getValue() < 0) {
errors.put((entry.getKey().size() == 1 ? "AUTO_CHECK_RESULT_TOO_MANY_BLOCK" : "AUTO_CHECK_RESULT_TOO_MANY_BLOCKS"), new Object[]{String.join(" ", entry.getKey()), -entry.getValue()});
}
}
if(type.getMaxBlocks() != 0 && blocks > type.getMaxBlocks()) {
errors.put("AUTO_CHECK_RESULT_TOO_MANY_ALL_BLOCKS", new Object[]{blocks, type.getMaxBlocks()});
}
if(records > 0) {
errors.put("AUTO_CHECK_RESULT_TOO_MANY_RECORDS", new Object[]{records});
}
for(Map.Entry<String, Map<String, Integer>> block : forbiddenItems.entrySet()) {
for (Map.Entry<String, Integer> item : block.getValue().entrySet()) {
errors.put("AUTO_CHECK_RESULT_FORBIDDEN_ITEM", new Object[]{block.getKey(), item.getKey(), item.getValue()});
}
}
for(Map.Entry<String, Map<String, Integer>> block : itemsWithTag.entrySet()) {
for (Map.Entry<String, Integer> item : block.getValue().entrySet()) {
errors.put("AUTO_CHECK_RESULT_FORBIDDEN_ITEM_NBT", new Object[]{block.getKey(), item.getKey(), item.getValue()});
}
}
if(tooManyDispenserItems == 1) {
errors.put("AUTO_CHECK_RESULT_TOO_MANY_DISPENSER_ITEMS", new Object[]{type.getMaxDispenserItems()});
}
else if(tooManyDispenserItems > 1) {
errors.put("AUTO_CHECK_RESULT_TOO_MANY_DISPENSERS_ITEMS", new Object[]{tooManyDispenserItems, type.getMaxDispenserItems()});
}
return errors;
}
public Map<String, Object[]> warnings(){
Map<String, Object[]> warnings = new HashMap<>();
for(Map.Entry<String, Integer> nbtBlock : defunctNbt.entrySet()){
if(nbtBlock.getValue() > 1) {
warnings.put("AUTO_CHECK_RESULT_NBTS_WARNING", new Object[]{nbtBlock.getValue(), nbtBlock.getKey()});
} else {
warnings.put("AUTO_CHECK_RESULT_NBT_WARNING", new Object[]{nbtBlock.getKey()});
}
}
return warnings;
}
void setErrorLoadingSchematic(){
errorLoadingSchematic = true;
}
void setWidth(int width){
this.width = width;
}
void setLength(int length){
this.length = length;
}
void setHeight(int height){
this.height = height;
}
void setBlocks(int blocks) {
this.blocks = blocks;
}
void checkMaterial(String name){
for(Map.Entry<Set<String>, Integer> entry : limitedMaterials.entrySet()) {
if(entry.getKey().contains(name))
entry.setValue(entry.getValue() - 1);
}
}
void defunctNbt(String name){
defunctNbt.compute(name, (k, v) -> v == null ? 1 : v+1);
}
void foundRecord(){
records++;
}
void foundForbiddenItem(String material, String item, int count){
forbiddenItems.compute(material, (k1, v) -> {
if(v == null)
v = new HashMap<>();
v.compute(item, (k2, v2) -> v2 == null ? count : v2 + count);
return v;
});
}
void foundItemWithTag(String material, String item, int count){
itemsWithTag.compute(material, (k1, v) -> {
if(v == null)
v = new HashMap<>();
v.compute(item, (k2, v2) -> v2 == null ? count : v2 + count);
return v;
});
}
void dispenserItems(int counter){
assert type != null;
if(counter > type.getMaxDispenserItems())
tooManyDispenserItems++;
}
}

Datei anzeigen

@ -21,21 +21,16 @@ package de.steamwar.schematicsystem;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.core.VersionDependent; import de.steamwar.core.VersionDependent;
import de.steamwar.sql.NoClipboardException;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SchematicType; import de.steamwar.sql.SchematicType;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.Instant; import java.time.Instant;
import java.util.*; import java.util.*;
import java.util.logging.Level;
public class CheckSchemType { public class CheckSchemType {
@ -105,21 +100,6 @@ public class CheckSchemType {
return types.get(type); return types.get(type);
} }
public AutoCheckResult autoCheck(SchematicNode schematic) {
AutoCheckResult result = new AutoCheckResult(this);
Clipboard clipboard;
try {
clipboard = schematic.load();
} catch (IOException | NoClipboardException e) {
Bukkit.getLogger().log(Level.SEVERE, "Schematic could not be loaded", e);
result.setErrorLoadingSchematic();
return result;
}
impl.autoCheck(result, clipboard);
return result;
}
public int getWidth() { public int getWidth() {
return width; return width;
} }
@ -148,14 +128,7 @@ public class CheckSchemType {
return deadline != null && deadline.before(Date.from(Instant.now())); return deadline != null && deadline.before(Date.from(Instant.now()));
} }
public String getDeadline() { public Date getDeadline() {
return DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.GERMAN).format(deadline); return deadline;
}
public static final ICheckSchemType impl = VersionDependent.getVersionImpl(SchematicSystem.getInstance());
public interface ICheckSchemType {
void autoCheck(AutoCheckResult result, Clipboard clipboard);
} }
} }

Datei anzeigen

@ -0,0 +1,54 @@
package de.steamwar.schematicsystem.autocheck;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.core.VersionDependent;
import de.steamwar.schematicsystem.CheckSchemType;
import de.steamwar.schematicsystem.SchematicSystem;
import lombok.Getter;
import org.bukkit.Material;
import java.util.*;
public class AutoChecker {
public static AutoCheckerResult check(Clipboard clipboard, CheckSchemType type) {
BlockScanResult blockScanResult = impl.scan(clipboard, type);
return AutoCheckerResult.builder()
.type(type)
.height(clipboard.getDimensions().getBlockY())
.width(clipboard.getDimensions().getBlockX())
.depth(clipboard.getDimensions().getBlockZ())
.blockCounts(blockScanResult.getBlockCounts())
.defunctNbt(blockScanResult.getDefunctNbt())
.dispenserItems(blockScanResult.getDispenserItems())
.records(blockScanResult.getRecords())
.forbiddenItems(blockScanResult.getForbiddenItems())
.forbiddenNbt(blockScanResult.getForbiddenNbt())
.build();
}
public static AutoCheckerResult sizeCheck(Clipboard clipboard, CheckSchemType type) {
return AutoCheckerResult.builder()
.type(type)
.height(clipboard.getDimensions().getBlockY())
.width(clipboard.getDimensions().getBlockX())
.depth(clipboard.getDimensions().getBlockZ())
.build();
}
private static final IAutoChecker impl = VersionDependent.getVersionImpl(SchematicSystem.getInstance());
public interface IAutoChecker {
BlockScanResult scan(Clipboard clipboard, CheckSchemType type);
}
@Getter
public static class BlockScanResult {
private final Map<Material, Integer> blockCounts = new EnumMap<>(Material.class);
private final List<BlockPos> defunctNbt = new ArrayList<>();
private final List<BlockPos> records = new ArrayList<>();
private final Map<BlockPos, Integer> dispenserItems = new HashMap<>();
private final Map<BlockPos, Set<Material>> forbiddenItems = new HashMap<>();
private final Map<BlockPos, Set<Material>> forbiddenNbt = new HashMap<>();
}
}

Datei anzeigen

@ -0,0 +1,138 @@
package de.steamwar.schematicsystem.autocheck;
import de.steamwar.schematicsystem.CheckSchemType;
import de.steamwar.schematicsystem.SchematicSystem;
import lombok.Builder;
import lombok.Getter;
import lombok.ToString;
import net.md_5.bungee.api.chat.ClickEvent;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
@Builder
@Getter
@ToString
public class AutoCheckerResult {
private final CheckSchemType type;
private final int width;
private final int height;
private final int depth;
private final Map<Material, Integer> blockCounts;
private final List<BlockPos> defunctNbt;
private final Map<BlockPos, Integer> dispenserItems;
private final List<BlockPos> records;
private final Map<BlockPos, Set<Material>> forbiddenItems;
private final Map<BlockPos, Set<Material>> forbiddenNbt;
public boolean isOk() {
return records.isEmpty() &&
forbiddenItems.isEmpty() &&
forbiddenNbt.isEmpty() &&
isSizeOk() &&
isBlockCountOk() &&
isLimitedBlocksOK() &&
isDispenserItemsOK() &&
!type.isAfterDeadline();
}
public boolean fastOk() {
return isSizeOk() &&
!type.isAfterDeadline();
}
public boolean isDispenserItemsOK() {
return dispenserItems.values().stream().allMatch(i -> i <= type.getMaxDispenserItems());
}
public boolean hasWarnings() {
return defunctNbt.isEmpty();
}
public boolean isSizeOk() {
return !isTooWide() && !isTooHigh() && !isTooDeep();
}
public boolean isTooWide() {
return width > type.getWidth();
}
public boolean isTooHigh() {
return height > type.getHeight();
}
public boolean isTooDeep() {
return depth > type.getDepth();
}
public boolean isBlockCountOk() {
return type.getMaxBlocks() == 0 || blockCounts.values().stream().reduce(Integer::sum).map(i -> i <= type.getMaxBlocks()).orElse(false);
}
public boolean isLimitedBlocksOK() {
try {
return type.getLimits().entrySet().stream()
.map(setIntegerEntry -> setIntegerEntry.getKey().stream().map(Material::getMaterial).map(blockCounts::get).map(i -> i == null || i <= setIntegerEntry.getValue()).reduce(Boolean::logicalAnd).orElse(false))
.reduce(Boolean::logicalAnd).orElse(true);
} catch (NullPointerException e) {
return false;
}
}
public void sendErrorMessage(Player p, String schemName) {
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_HEADER", p, schemName);
if(isTooWide()) SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_WIDTH", p, width, type.getWidth());
if(isTooHigh()) SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_HEIGHT", p, height, type.getHeight());
if(isTooDeep()) SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_LENGTH", p, depth, type.getDepth());
if(type.getMaxBlocks() != 0 && !isBlockCountOk()) {
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_BLOCKS", p, blockCounts.values().stream().reduce(Integer::sum).orElse(0), type.getMaxBlocks());
}
if(!isLimitedBlocksOK()) {
type.getLimits().forEach((strings, integer) -> {
for (String string : strings) {
Material mat = Material.getMaterial(string);
if(mat == null) {
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_UNKNOWN_MATERIAL", p, string);
} else if(blockCounts.getOrDefault(mat, 0) > integer) {
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_TOO_MANY_BLOCK", p, mat.name());
}
}
});
}
dispenserItems.entrySet().stream().filter(blockVector3IntegerEntry -> blockVector3IntegerEntry.getValue() > type.getMaxBlocks()).forEach(blockVector3IntegerEntry -> {
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_TOO_MANY_DISPENSER_ITEMS", p, SchematicSystem.MESSAGE.parse("AUTO_CHECKER_RESULT_TELEPORT_HERE", p), tpCommandTo(blockVector3IntegerEntry.getKey()),
blockVector3IntegerEntry.getKey().getBlockX(),
blockVector3IntegerEntry.getKey().getBlockY(),
blockVector3IntegerEntry.getKey().getBlockZ(),
blockVector3IntegerEntry.getValue(),
type.getMaxDispenserItems());
});
records.forEach(blockVector3 -> {
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_RECORD", p, SchematicSystem.MESSAGE.parse("AUTO_CHECKER_RESULT_TELEPORT_HERE", p), tpCommandTo(blockVector3), blockVector3.getBlockX(), blockVector3.getBlockY(), blockVector3.getBlockZ());
});
forbiddenItems.forEach((blockVector3, materials) -> {
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_FORBIDDEN_ITEM", p, SchematicSystem.MESSAGE.parse("AUTO_CHECKER_RESULT_TELEPORT_HERE", p), tpCommandTo(blockVector3), blockVector3.getX(), blockVector3.getY(), blockVector3.getZ(), setToString(materials));
});
forbiddenNbt.forEach((blockVector3, materials) -> {
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_FORBIDDEN_ITEM_NBT", p, SchematicSystem.MESSAGE.parse("AUTO_CHECKER_RESULT_TELEPORT_HERE", p), tpCommandTo(blockVector3), blockVector3.getX(), blockVector3.getY(), blockVector3.getZ(), setToString(materials));
});
defunctNbt.forEach(blockVector3 -> {
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_DEFUNCT_NBT", p, SchematicSystem.MESSAGE.parse("AUTO_CHECKER_RESULT_TELEPORT_HERE", p), tpCommandTo(blockVector3), blockVector3.getX(), blockVector3.getY(), blockVector3.getZ());
});
if(type.isAfterDeadline()) {
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_AFTER_DEADLINE", p, type.getDeadline());
}
}
private static ClickEvent tpCommandTo(BlockPos pos) {
return new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tp " + pos.getBlockX() + " " + pos.getBlockY() + " " + pos.getBlockZ());
}
private static String setToString(Collection<Material> set) {
return set.stream().map(material -> material.getKey().getKey()).reduce((s, s2) -> s + "§7, §c" + s2).orElse("");
}
}

Datei anzeigen

@ -0,0 +1,27 @@
package de.steamwar.schematicsystem.autocheck;
import lombok.AllArgsConstructor;
import lombok.Getter;
/*
* Can be removed with 1.12 support removal
*/
@Getter
@AllArgsConstructor
public class BlockPos {
private int x;
private int y;
private int z;
public int getBlockX() {
return x;
}
public int getBlockY() {
return y;
}
public int getBlockZ() {
return z;
}
}

Datei anzeigen

@ -19,18 +19,23 @@
package de.steamwar.schematicsystem.commands; package de.steamwar.schematicsystem.commands;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.core.Core; import de.steamwar.core.Core;
import de.steamwar.inventory.*; import de.steamwar.inventory.*;
import de.steamwar.schematicsystem.CheckSchemType;
import de.steamwar.schematicsystem.SafeSchematicNode; import de.steamwar.schematicsystem.SafeSchematicNode;
import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.schematicsystem.autocheck.AutoChecker;
import de.steamwar.sql.*; import de.steamwar.sql.*;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import static de.steamwar.schematicsystem.commands.SchematicCommandUtils.*; import static de.steamwar.schematicsystem.commands.SchematicCommandUtils.*;
@ -199,17 +204,17 @@ public class GUI {
} }
static void changeType(Player p, SchematicNode schem){ static void changeType(Player p, SchematicNode schem){
List<SWListInv.SWListEntry<SchematicType>> types = new LinkedList<>(); Clipboard clipboard = null;
for(SchematicType type : SchematicType.values()){ try {
if(!type.isAssignable()) clipboard = new SchematicData(schem).load();
continue; } catch (IOException ignored) { }
SWItem item = new SWItem(type.getMaterial(), type.name()); Clipboard finalClipboard = clipboard;
if(type.fightType()) List<SWListInv.SWListEntry<SchematicType>> types = SchematicType.values().parallelStream()
item.setEnchanted(true); .filter(SchematicType::isAssignable)
.filter(type -> finalClipboard == null || CheckSchemType.get(type) == null || AutoChecker.sizeCheck(finalClipboard, CheckSchemType.get(type)).fastOk())
types.add(new SWListInv.SWListEntry<>(item, type)); .map(type -> new SWListInv.SWListEntry<>(new SWItem(type.getMaterial(), type.name(), Collections.emptyList(), type.fightType(), null), type))
} .collect(Collectors.toList());
SWListInv<SchematicType> inv = new SWListInv<>(p, SchematicSystem.MESSAGE.parse("GUI_CHANGE_TYPE", p), types, (clickType, schematicType) -> { SWListInv<SchematicType> inv = new SWListInv<>(p, SchematicSystem.MESSAGE.parse("GUI_CHANGE_TYPE", p), types, (clickType, schematicType) -> {
p.closeInventory(); p.closeInventory();

Datei anzeigen

@ -19,12 +19,15 @@
package de.steamwar.schematicsystem.commands; package de.steamwar.schematicsystem.commands;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.command.*; import de.steamwar.command.*;
import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SchematicSelector; import de.steamwar.inventory.SchematicSelector;
import de.steamwar.providers.BauServerInfo; import de.steamwar.providers.BauServerInfo;
import de.steamwar.schematicsystem.CheckSchemType;
import de.steamwar.schematicsystem.SafeSchematicNode; import de.steamwar.schematicsystem.SafeSchematicNode;
import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.schematicsystem.autocheck.AutoChecker;
import de.steamwar.sql.*; import de.steamwar.sql.*;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
@ -35,6 +38,7 @@ import org.bukkit.Material;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.io.IOException;
import java.time.Instant; import java.time.Instant;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
@ -378,14 +382,24 @@ public class SchematicCommand extends SWCommand {
SteamwarUser user = getUser(player); SteamwarUser user = getUser(player);
TextComponent base = new TextComponent(); TextComponent base = new TextComponent();
SchematicType.values().forEach(type -> { Clipboard clipboard = null;
if (!type.isAssignable()) return; try {
clipboard = new SchematicData(node).load();
} catch (IOException ignored) { }
Clipboard finalClipboard = clipboard;
String breadcrumb = node.generateBreadcrumbs(user);
SchematicType.values().parallelStream()
.filter(SchematicType::isAssignable)
.filter(type -> finalClipboard == null || CheckSchemType.get(type) == null || AutoChecker.sizeCheck(finalClipboard, CheckSchemType.get(type)).fastOk())
.forEachOrdered(type -> {
TextComponent component = new TextComponent(type.name() + " "); TextComponent component = new TextComponent(type.name() + " ");
component.setColor(ChatColor.GRAY); component.setColor(ChatColor.GRAY);
component.setBold(true); component.setBold(true);
component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(SchematicSystem.MESSAGE.parse("COMMAND_CHANGE_TYPE_SELECT", player)))); component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(SchematicSystem.MESSAGE.parse("COMMAND_CHANGE_TYPE_SELECT", player))));
component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem changetype " + node.generateBreadcrumbs(user) + " " + type.name())); component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem changetype " + breadcrumb + " " + type.name()));
base.addExtra(component); base.addExtra(component);
}); });

Datei anzeigen

@ -24,9 +24,10 @@ import de.steamwar.inventory.SWItem;
import de.steamwar.network.NetworkSender; import de.steamwar.network.NetworkSender;
import de.steamwar.network.packets.client.PrepareSchemPacket; import de.steamwar.network.packets.client.PrepareSchemPacket;
import de.steamwar.providers.BauServerInfo; import de.steamwar.providers.BauServerInfo;
import de.steamwar.schematicsystem.AutoCheckResult;
import de.steamwar.schematicsystem.CheckSchemType; import de.steamwar.schematicsystem.CheckSchemType;
import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.schematicsystem.autocheck.AutoChecker;
import de.steamwar.schematicsystem.autocheck.AutoCheckerResult;
import de.steamwar.sql.*; import de.steamwar.sql.*;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
@ -40,6 +41,7 @@ import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.function.IntFunction; import java.util.function.IntFunction;
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;
@ -430,16 +432,17 @@ public class SchematicCommandUtils {
return; return;
} }
AutoCheckResult result = checkSchemType.autoCheck(node); AutoCheckerResult result = null;
Map<String, Object[]> errors = result.errors(); try {
for (Map.Entry<String, Object[]> warning : result.warnings().entrySet()) { result = AutoChecker.check(new SchematicData(node).load(), checkSchemType);
SchematicSystem.MESSAGE.sendPrefixless(warning.getKey(), player, warning.getValue()); } catch (IOException e) {
SchematicSystem.MESSAGE.send("UTIL_LOAD_ERROR", player);
SchematicSystem.getInstance().getLogger().throwing(SchematicCommandUtils.class.getName(), "changeType", e);
return;
} }
for (Map.Entry<String, Object[]> error : errors.entrySet()) { if (!result.isOk()) {
SchematicSystem.MESSAGE.sendPrefixless(error.getKey(), player, error.getValue());
}
if (!errors.isEmpty()) {
SchematicSystem.MESSAGE.send("UTIL_TYPE_ERROR", player); SchematicSystem.MESSAGE.send("UTIL_TYPE_ERROR", player);
result.sendErrorMessage(player, node.getName());
return; return;
} }

Datei anzeigen

@ -82,7 +82,6 @@ mainClassName = ''
allprojects { allprojects {
repositories { repositories {
mavenCentral() mavenCentral()
jcenter()
maven { maven {
url = uri("https://repo.codemc.io/repository/maven-snapshots/") url = uri("https://repo.codemc.io/repository/maven-snapshots/")