13
0

BetterAutoCheck #37

Zusammengeführt
Lixfel hat 2 Commits von BetterAutoCheck nach master 2019-12-28 09:57:41 +01:00 zusammengeführt
10 geänderte Dateien mit 242 neuen und 88 gelöschten Zeilen
Nur Änderungen aus Commit e3d9780df5 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -1,11 +1,9 @@
package de.steamwar.schematicsystem; package de.steamwar.schematicsystem;
import java.util.List;
class CheckSchemType_10 { class CheckSchemType_10 {
private CheckSchemType_10(){} private CheckSchemType_10(){}
static void autoCheck(List<String> errors) { static AutoCheckResult autoCheck() {
errors.add("In der 1.10 können keine Schematics eingesendet werden"); return new AutoCheckResult();
} }
} }

Datei anzeigen

@ -16,6 +16,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
@SuppressWarnings("deprecation")
class CheckSchemType_12 { class CheckSchemType_12 {
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();
@ -66,23 +67,24 @@ class CheckSchemType_12 {
private CheckSchemType_12(){} private CheckSchemType_12(){}
static void autoCheck(Schematic schematic, List<String> errors, List<String> warnings, ICheckSchemType type) { static AutoCheckResult autoCheck(Schematic schematic, ICheckSchemType type) {
AutoCheckResult result = new AutoCheckResult(type);
Clipboard clipboard; Clipboard clipboard;
try { try {
clipboard = schematic.load(); clipboard = schematic.load();
} catch (Schematic.WrongVersionException e) { } catch (Schematic.WrongVersionException e) {
errors.add("Der Schematictyp dieser Schematic kann nicht in dieser Version geändert werden."); result.setWrongVersionException();
return; return result;
} catch (IOException | NoClipboardException e) { } catch (IOException | NoClipboardException e) {
Bukkit.getLogger().log(Level.SEVERE, "Schematic could not be loaded", e); Bukkit.getLogger().log(Level.SEVERE, "Schematic could not be loaded", e);
errors.add("Die Schematic konnte nicht geladen werden"); result.setErrorLoadingSchematic();
return; return result;
} }
Vector dimensions = clipboard.getDimensions(); Vector dimensions = clipboard.getDimensions();
result.setLength(dimensions.getBlockX());
if(dimensions.getBlockX() > type.getWidth() || dimensions.getBlockY() > type.getHeight() || dimensions.getBlockZ() > type.getDepth()) result.setHeight(dimensions.getBlockY());
errors.add("Das " + type.getName() + " überschreitet die Maximalmaße"); result.setWidth(dimensions.getBlockZ());
Region region = clipboard.getRegion(); Region region = clipboard.getRegion();
Vector min = region.getMinimumPoint(); Vector min = region.getMinimumPoint();
@ -108,27 +110,30 @@ class CheckSchemType_12 {
dispenser++; dispenser++;
if(INVENTORY.contains(blockId)){ if(INVENTORY.contains(blockId)){
checkInventory(errors, warnings, block, blockId, type); checkInventory(result, block, blockId, type);
} }
if(type.getForbidden().contains(Material.getMaterial(blockId).name())) result.checkMaterial(Material.getMaterial(blockId).name());
errors.add("Der Block " + Material.getMaterial(blockId).name() + " ist verboten");
} }
} }
} }
type.finalChecks(errors, tnt, slime, dispenser); result.setTNT(tnt);
result.setSlime(slime);
result.setDispenser(dispenser);
return result;
} }
private static void checkInventory(List<String> errors, List<String> warnings, BaseBlock block, int blockId, ICheckSchemType type){ private static void checkInventory(AutoCheckResult result, BaseBlock block, int blockId, ICheckSchemType type){
CompoundTag nbt = block.getNbtData(); CompoundTag nbt = block.getNbtData();
if(nbt == null){ if(nbt == null){
warnings.add("Ein(e) " + Material.getMaterial(blockId).name() + " ist defekt"); result.defunctNbt(Material.getMaterial(blockId).name());
return; return;
} }
if(blockId == JUKEBOX && nbt.getValue().containsKey("RecordItem")){ if(blockId == JUKEBOX && nbt.getValue().containsKey("RecordItem")){
errors.add("Schallplatten sind auch nicht in Schallplattenspielern gestattet"); result.foundRecord();
return; return;
} }
@ -139,7 +144,7 @@ class CheckSchemType_12 {
int counter = 0; int counter = 0;
for(CompoundTag item : items){ for(CompoundTag item : items){
if(!item.containsKey("id")){ if(!item.containsKey("id")){
warnings.add("Ein(e) " + Material.getMaterial(blockId).name() + " ist defekt"); result.defunctNbt(Material.getMaterial(blockId).name());
continue; continue;
} }
@ -152,10 +157,9 @@ class CheckSchemType_12 {
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)))
errors.add("In einem/r " + Material.getMaterial(blockId).name() + " ist das verbotene Item " + itemType); result.foundForbiddenItem(Material.getMaterial(blockId).name(), itemType.name(), item.getByte("Count"));
} }
if(counter > type.getMaxDispenserItems()) result.dispenserItems(counter);
errors.add("Ein Werfer enthält mehr als " + type.getMaxDispenserItems() + " Pfeile und Feuerbälle");
} }
} }

Datei anzeigen

@ -1,11 +1,9 @@
package de.steamwar.schematicsystem; package de.steamwar.schematicsystem;
import java.util.List;
class CheckSchemType_14 { class CheckSchemType_14 {
private CheckSchemType_14(){} private CheckSchemType_14(){}
static void autoCheck(List<String> errors) { static AutoCheckResult autoCheck() {
errors.add("In der 1.14 können keine Schematics eingesendet werden"); return new AutoCheckResult();
} }
} }

Datei anzeigen

@ -68,23 +68,24 @@ class CheckSchemType_15 {
private CheckSchemType_15(){} private CheckSchemType_15(){}
static void autoCheck(Schematic schematic, List<String> errors, List<String> warnings, ICheckSchemType type) { static AutoCheckResult autoCheck(Schematic schematic, ICheckSchemType type) {
AutoCheckResult result = new AutoCheckResult(type);
Clipboard clipboard; Clipboard clipboard;
try { try {
clipboard = schematic.load(); clipboard = schematic.load();
} catch (Schematic.WrongVersionException e) { } catch (Schematic.WrongVersionException e) {
errors.add("Der Schematictyp dieser Schematic kann nicht in dieser Version geändert werden."); result.setWrongVersionException();
return; return result;
} catch (IOException | NoClipboardException e) { } catch (IOException | NoClipboardException e) {
result.setErrorLoadingSchematic();
Bukkit.getLogger().log(Level.SEVERE, "Schematic could not be loaded", e); Bukkit.getLogger().log(Level.SEVERE, "Schematic could not be loaded", e);
errors.add("Die Schematic konnte nicht geladen werden"); return result;
return;
} }
BlockVector3 dimensions = clipboard.getDimensions(); BlockVector3 dimensions = clipboard.getDimensions();
result.setLength(dimensions.getBlockX());
if(dimensions.getBlockX() > type.getWidth() || dimensions.getBlockY() > type.getHeight() || dimensions.getBlockZ() > type.getDepth()) result.setHeight(dimensions.getBlockY());
errors.add("Das " + type.getName() + " überschreitet die Maximalmaße"); result.setWidth(dimensions.getBlockZ());
Region region = clipboard.getRegion(); Region region = clipboard.getRegion();
BlockVector3 min = region.getMinimumPoint(); BlockVector3 min = region.getMinimumPoint();
@ -110,27 +111,31 @@ class CheckSchemType_15 {
dispenser++; dispenser++;
if(INVENTORY.contains(blockMaterial)){ if(INVENTORY.contains(blockMaterial)){
checkInventory(errors, warnings, block, blockMaterial, type); checkInventory(result, block, blockMaterial, type);
} }
if(type.getForbidden().contains(blockMaterial.name())) assert blockMaterial != null;
errors.add("Der Block " + blockMaterial.name() + " ist verboten"); result.checkMaterial(blockMaterial.name());
} }
} }
} }
type.finalChecks(errors, tnt, slime, dispenser); result.setTNT(tnt);
result.setSlime(slime);
result.setDispenser(dispenser);
return result;
} }
private static void checkInventory(List<String> errors, List<String> warnings, BaseBlock block, Material blockMaterial, ICheckSchemType type){ private static void checkInventory(AutoCheckResult result, BaseBlock block, Material blockMaterial, ICheckSchemType type){
CompoundTag nbt = block.getNbtData(); CompoundTag nbt = block.getNbtData();
if(nbt == null){ if(nbt == null){
warnings.add("Ein(e) " + blockMaterial.name() + " ist defekt"); result.defunctNbt(blockMaterial.name());
return; return;
} }
if(blockMaterial == Material.JUKEBOX && nbt.getValue().containsKey("RecordItem")){ if(blockMaterial == Material.JUKEBOX && nbt.getValue().containsKey("RecordItem")){
errors.add("Schallplatten sind auch nicht in Schallplattenspielern gestattet"); result.foundRecord();
return; return;
} }
@ -141,7 +146,7 @@ class CheckSchemType_15 {
int counter = 0; int counter = 0;
for(CompoundTag item : items){ for(CompoundTag item : items){
if(!item.containsKey("id")){ if(!item.containsKey("id")){
warnings.add("Ein(e) " + blockMaterial.name() + " ist defekt"); result.defunctNbt(blockMaterial.name());
continue; continue;
} }
@ -152,10 +157,9 @@ class CheckSchemType_15 {
if(blockMaterial == Material.DISPENSER && (itemType.equals(Material.FIRE_CHARGE) || itemType.equals(Material.ARROW))) if(blockMaterial == 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 && itemType.equals(Material.TNT))) else if(!FLOWERS.contains(itemType) && !(blockMaterial == Material.CHEST && itemType.equals(Material.TNT)))
errors.add("In einem/r " + blockMaterial.name() + " ist das verbotene Item " + itemType); result.foundForbiddenItem(blockMaterial.name(), itemType.name(), item.getByte("Count"));
} }
if(counter > type.getMaxDispenserItems()) result.dispenserItems(counter);
errors.add("Ein Werfer enthält mehr als " + type.getMaxDispenserItems() + " Pfeile und Feuerbälle");
} }
} }

Datei anzeigen

@ -1,11 +1,9 @@
package de.steamwar.schematicsystem; package de.steamwar.schematicsystem;
import java.util.List;
class CheckSchemType_8 { class CheckSchemType_8 {
private CheckSchemType_8(){} private CheckSchemType_8(){}
static void autoCheck(List<String> errors) { static AutoCheckResult autoCheck() {
errors.add("In der 1.8 können keine Schematics eingesendet werden"); return new AutoCheckResult();
} }
} }

Datei anzeigen

@ -1,11 +1,9 @@
package de.steamwar.schematicsystem; package de.steamwar.schematicsystem;
import java.util.List;
class CheckSchemType_9 { class CheckSchemType_9 {
private CheckSchemType_9(){} private CheckSchemType_9(){}
static void autoCheck(List<String> errors) { static AutoCheckResult autoCheck() {
errors.add("In der 1.9 können keine Schematics eingesendet werden"); return new AutoCheckResult();
} }
} }

Datei anzeigen

@ -0,0 +1,151 @@
package de.steamwar.schematicsystem;
import de.steamwar.core.Core;
import java.util.*;
public class AutoCheckResult {
private final ICheckSchemType type;
private final boolean noChecksInThisVersion;
private boolean wrongVersionException = false; // Schematic nicht in der Version ladbar
private boolean errorLoadingSchematic = false; // Schematic irgendwie invalide
private int width = 0;
private int height = 0;
private int length = 0;
private int tnt = 0;
private int slime = 0;
private int dispenser = 0;
private Map<String, Integer> forbiddenMaterials = new HashMap<>(); // Anzahl verbotener Blöcke nach Material
private Map<String, Integer> defunctNbt = new HashMap<>(); // Anzahl an defekten NBT-Blöcken nach Materialname
private int records = 0; // Gefundene Schallplatten
private Map<String, Map<String, Integer>> forbiddenItems = new HashMap<>(); // Anzahl verbotener Items nach Inventartyp
private int tooManyDispenserItems = 0; // Gefundene Überschreitungen von DispenserItems
AutoCheckResult(ICheckSchemType type){
this.type = type;
noChecksInThisVersion = false;
}
AutoCheckResult(){
type = null;
noChecksInThisVersion = true;
}
public Collection<String> errors(){
List<String> errors = new LinkedList<>();
if(noChecksInThisVersion){
errors.add("In der 1." + Core.getVersion() + " können keine Schematics eingesendet werden");
return errors;
}
if(wrongVersionException)
errors.add("Diese Schematic kann nicht in dieser Version geändert werden");
if(errorLoadingSchematic)
errors.add("Die Schematic konnte nicht geladen werden");
assert type != null;
if(width > type.getDepth())
errors.add("Die Schematic ist zu breit (" + width + " > " + type.getDepth() + ")");
if(length > type.getWidth())
errors.add("Die Schematic ist zu lang (" + length + " > " + type.getWidth() + ")");
if(height > type.getHeight())
errors.add("Die Schematic ist zu hoch (" + height + " > " + type.getHeight() + ")");
int errorTNTSlime = slime + tnt;
if(type.getMaxTNT() != 0 && tnt > type.getMaxTNT())
errors.add("Zu viele TNT-Blöcke (" + tnt + " > " + type.getMaxTNT() + ")");
if(type.getMaxSlime() != 0 && slime > type.getMaxSlime())
errors.add("Zu viele Schleim-Blöcke (" + slime + " > " + type.getMaxSlime() + ")");
if(type.getMaxDispenser() != 0 && dispenser > type.getMaxDispenser())
errors.add("Zu viele Werfer (" + dispenser + " > " + type.getMaxDispenser() + ")");
if(type.getMaxTNTSlime() != 0 && errorTNTSlime > type.getMaxTNTSlime())
errors.add("Zu viel Schleim+TNT" + errorTNTSlime + " > " + type.getMaxTNTSlime() + ")");
for(Map.Entry<String, Integer> block : forbiddenMaterials.entrySet())
errors.add("Der Block " + block.getKey() + " ist verboten (" + block.getValue() + " verbaut)");
if(records > 0)
errors.add("Keine Schallplatten erlaubt (" + records + " gefunden)");
for(Map.Entry<String, Map<String, Integer>> block : forbiddenItems.entrySet())
for(Map.Entry<String, Integer> item : block.getValue().entrySet())
errors.add("In " + block.getKey() + "s wurde das verbotene Item " + item.getKey() + " " + item.getValue() + " mal gefunden");
if(tooManyDispenserItems == 1)
errors.add("Ein Werfer enthält mehr als " + type.getMaxDispenserItems() + " Pfeile und Feuerbälle");
else if(tooManyDispenserItems > 1)
errors.add(tooManyDispenserItems + " Werfer enthalten mehr als " + type.getMaxDispenserItems() + " Pfeile und Feuerbälle");
return errors;
}
public Collection<String> warnings(){
List<String> warnings = new LinkedList<>();
for(Map.Entry<String, Integer> nbtBlock : defunctNbt.entrySet()){
if(nbtBlock.getValue() > 1)
warnings.add(nbtBlock.getValue() + " " + nbtBlock.getKey() + "s enthalten keine oder inkorrekte NBT-Daten");
else
warnings.add("Ein(e) " + nbtBlock.getKey() + " enthält keine oder inkorrekte NBT-Daten");
}
return warnings;
}
void setWrongVersionException(){
wrongVersionException = true;
}
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 setTNT(int tnt){
this.tnt = tnt;
}
void setSlime(int slime){
this.slime = slime;
}
void setDispenser(int dispenser){
this.dispenser = dispenser;
}
void checkMaterial(String name){
assert type != null;
if(type.getForbidden().contains(name))
forbiddenMaterials.compute(name, (k, v) -> v == null ? 1 : v+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 dispenserItems(int counter){
assert type != null;
if(counter > type.getMaxDispenserItems())
tooManyDispenserItems++;
}
}

Datei anzeigen

@ -9,8 +9,10 @@ interface ICheckSchemType {
int getHeight(); int getHeight();
int getDepth(); int getDepth();
int getMaxDispenserItems(); int getMaxDispenserItems();
int getMaxDispenser();
int getMaxTNT();
int getMaxTNTSlime();
int getMaxSlime();
List<String> getForbidden(); List<String> getForbidden();
void finalChecks(List<String> errors, int tnt, int slime, int dispenser);
} }

Datei anzeigen

@ -58,41 +58,23 @@ public class CheckSchemType implements ICheckSchemType {
return SchematicType.fromDB(name); return SchematicType.fromDB(name);
} }
public void autoCheck(Schematic schematic, List<String> errors, List<String> warnings) { public AutoCheckResult autoCheck(Schematic schematic) {
switch(Core.getVersion()){ switch(Core.getVersion()){
case 15: case 15:
CheckSchemType_15.autoCheck(schematic, errors, warnings, this); return CheckSchemType_15.autoCheck(schematic, this);
break;
case 14: case 14:
CheckSchemType_14.autoCheck(errors); return CheckSchemType_14.autoCheck();
break;
case 10: case 10:
CheckSchemType_10.autoCheck(errors); return CheckSchemType_10.autoCheck();
break;
case 9: case 9:
CheckSchemType_9.autoCheck(errors); return CheckSchemType_9.autoCheck();
break;
case 8: case 8:
CheckSchemType_8.autoCheck(errors); return CheckSchemType_8.autoCheck();
break;
default: default:
CheckSchemType_12.autoCheck(schematic, errors, warnings, this); return CheckSchemType_12.autoCheck(schematic, this);
} }
} }
@Override
public void finalChecks(List<String> errors, int tnt, int slime, int dispenser){
int tntSlime = tnt + slime;
if(maxTNT != 0 && tnt > maxTNT)
errors.add("Zu viele TNT-Blöcke");
if(maxSlime != 0 && slime > maxSlime)
errors.add("Zu viele Schleim-Blöcke");
if(maxDispenser != 0 && dispenser > maxDispenser)
errors.add("Zu viele Werfer");
if(maxTNTSlime != 0 && tntSlime > maxTNTSlime)
errors.add("Zu viel Schleim+TNT");
}
@Override @Override
public String getName() { public String getName() {
return name; return name;
@ -118,6 +100,26 @@ public class CheckSchemType implements ICheckSchemType {
return maxDispenserItems; return maxDispenserItems;
} }
@Override
public int getMaxDispenser() {
return maxDispenser;
}
@Override
public int getMaxTNT() {
return maxTNT;
}
@Override
public int getMaxTNTSlime() {
return maxTNTSlime;
}
@Override
public int getMaxSlime() {
return maxSlime;
}
@Override @Override
public List<String> getForbidden() { public List<String> getForbidden() {
return forbiddenMaterials; return forbiddenMaterials;

Datei anzeigen

@ -1,5 +1,6 @@
package de.steamwar.schematicsystem.commands; package de.steamwar.schematicsystem.commands;
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.check.CheckUtils; import de.steamwar.schematicsystem.check.CheckUtils;
@ -17,7 +18,7 @@ import org.bukkit.entity.Player;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
@ -245,13 +246,12 @@ public class SchematicCommand implements CommandExecutor {
return; return;
} }
List<String> errors = new LinkedList<>(); AutoCheckResult result = CheckSchemType.get(type).autoCheck(schematic);
List<String> warnings = new LinkedList<>(); Collection<String> errors = result.errors();
CheckSchemType.get(type).autoCheck(schematic, errors, warnings); for(String warning : errors){
for(String warning : warnings){
player.sendMessage(" §e" + warning); player.sendMessage(" §e" + warning);
} }
for(String error : errors){ for(String error : result.warnings()){
player.sendMessage(" §c" + error); player.sendMessage(" §c" + error);
} }
if(!errors.isEmpty()){ if(!errors.isEmpty()){
@ -261,7 +261,6 @@ public class SchematicCommand implements CommandExecutor {
schematic.setSchemType(type.checkType()); schematic.setSchemType(type.checkType());
player.sendMessage(SchematicSystem.PREFIX + "§aDie Schematic wird zeitnah überprüft"); player.sendMessage(SchematicSystem.PREFIX + "§aDie Schematic wird zeitnah überprüft");
CheckUtils.sendTeamMembersCSchematics(SchematicSystem.PREFIX + player.getName() + " §7hat ein " + type.name() + " eingesendet");
} }
} }