Automatic Inventory checking + Multiple Autocheck errors
Dieser Commit ist enthalten in:
Ursprung
875eb2d5bd
Commit
4d6b3ef738
@ -1,7 +1,9 @@
|
|||||||
package de.steamwar.schematicsystem;
|
package de.steamwar.schematicsystem;
|
||||||
|
|
||||||
import com.boydti.fawe.FaweAPI;
|
import com.boydti.fawe.FaweAPI;
|
||||||
|
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.extent.clipboard.Clipboard;
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import de.warking.hunjy.MySQL.Schematic;
|
import de.warking.hunjy.MySQL.Schematic;
|
||||||
@ -21,6 +23,48 @@ public class CheckSchemType {
|
|||||||
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 DISPENSER = Material.DISPENSER.getId();
|
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;
|
||||||
|
private static final Set<Material> FLOWERS;
|
||||||
|
|
||||||
|
static{
|
||||||
|
Set<Integer> inventory = new HashSet<>();
|
||||||
|
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());
|
||||||
|
inventory.add(Material.BLACK_SHULKER_BOX.getId());
|
||||||
|
inventory.add(Material.RED_SHULKER_BOX.getId());
|
||||||
|
inventory.add(Material.WHITE_SHULKER_BOX.getId());
|
||||||
|
inventory.add(Material.ORANGE_SHULKER_BOX.getId());
|
||||||
|
inventory.add(Material.BLUE_SHULKER_BOX.getId());
|
||||||
|
inventory.add(Material.LIGHT_BLUE_SHULKER_BOX.getId());
|
||||||
|
inventory.add(Material.YELLOW_SHULKER_BOX.getId());
|
||||||
|
inventory.add(Material.GREEN_SHULKER_BOX.getId());
|
||||||
|
inventory.add(Material.BROWN_SHULKER_BOX.getId());
|
||||||
|
inventory.add(Material.CYAN_SHULKER_BOX.getId());
|
||||||
|
inventory.add(Material.GRAY_SHULKER_BOX.getId());
|
||||||
|
inventory.add(Material.SILVER_SHULKER_BOX.getId());
|
||||||
|
inventory.add(Material.LIME_SHULKER_BOX.getId());
|
||||||
|
inventory.add(Material.MAGENTA_SHULKER_BOX.getId());
|
||||||
|
inventory.add(Material.PINK_SHULKER_BOX.getId());
|
||||||
|
inventory.add(Material.PURPLE_SHULKER_BOX.getId());
|
||||||
|
INVENTORY = inventory;
|
||||||
|
|
||||||
|
Set<Material> flowers = new HashSet<>();
|
||||||
|
flowers.add(Material.CHORUS_FLOWER);
|
||||||
|
flowers.add(Material.YELLOW_FLOWER);
|
||||||
|
flowers.add(Material.RED_ROSE);
|
||||||
|
flowers.add(Material.DOUBLE_PLANT);
|
||||||
|
FLOWERS = flowers;
|
||||||
|
}
|
||||||
|
|
||||||
private static final Map<SchematicType, CheckSchemType> types = new EnumMap<>(SchematicType.class);
|
private static final Map<SchematicType, CheckSchemType> types = new EnumMap<>(SchematicType.class);
|
||||||
|
|
||||||
@ -34,6 +78,7 @@ public class CheckSchemType {
|
|||||||
private final int maxSlime;
|
private final int maxSlime;
|
||||||
private final int maxTNTSlime;
|
private final int maxTNTSlime;
|
||||||
private final int maxDispenser;
|
private final int maxDispenser;
|
||||||
|
private final int maxDispenserItems;
|
||||||
private final List<Integer> forbiddenIds;
|
private final List<Integer> forbiddenIds;
|
||||||
private final LinkedList<String> checkList;
|
private final LinkedList<String> checkList;
|
||||||
|
|
||||||
@ -47,6 +92,7 @@ public class CheckSchemType {
|
|||||||
maxSlime = section.getInt("maxSlime");
|
maxSlime = section.getInt("maxSlime");
|
||||||
maxTNTSlime = section.getInt("maxTNTSlime");
|
maxTNTSlime = section.getInt("maxTNTSlime");
|
||||||
maxDispenser = section.getInt("maxDispenser");
|
maxDispenser = section.getInt("maxDispenser");
|
||||||
|
maxDispenserItems = section.getInt("maxDispenserItems");
|
||||||
|
|
||||||
forbiddenIds = section.getIntegerList("forbiddenIds");
|
forbiddenIds = section.getIntegerList("forbiddenIds");
|
||||||
checkList = new LinkedList<>(section.getStringList("checkList"));
|
checkList = new LinkedList<>(section.getStringList("checkList"));
|
||||||
@ -66,7 +112,7 @@ public class CheckSchemType {
|
|||||||
return SchematicType.fromDB(name);
|
return SchematicType.fromDB(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String autoCheck(Schematic schematic) {
|
public void autoCheck(Schematic schematic, List<String> errors, List<String> warnings) {
|
||||||
Clipboard clipboard;
|
Clipboard clipboard;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -75,13 +121,14 @@ public class CheckSchemType {
|
|||||||
throw new IOException();
|
throw new IOException();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Schematic could not be loaded", e);
|
Bukkit.getLogger().log(Level.SEVERE, "Schematic could not be loaded", e);
|
||||||
return "Die Schematic konnte nicht geladen werden";
|
errors.add("Die Schematic konnte nicht geladen werden");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector dimensions = clipboard.getDimensions();
|
Vector dimensions = clipboard.getDimensions();
|
||||||
|
|
||||||
if(dimensions.getBlockX() > width || dimensions.getBlockY() > height || dimensions.getBlockZ() > depth)
|
if(dimensions.getBlockX() > width || dimensions.getBlockY() > height || dimensions.getBlockZ() > depth)
|
||||||
return "Das " + name + " überschreitet die Maximalmaße";
|
errors.add("Das " + name + " überschreitet die Maximalmaße");
|
||||||
|
|
||||||
Region region = clipboard.getRegion();
|
Region region = clipboard.getRegion();
|
||||||
Vector min = region.getMinimumPoint();
|
Vector min = region.getMinimumPoint();
|
||||||
@ -94,8 +141,8 @@ public class CheckSchemType {
|
|||||||
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++){
|
||||||
Vector vector = new Vector(x, y, z);
|
final BaseBlock block = clipboard.getBlock(new Vector(x, y, z));
|
||||||
final int blockId = clipboard.getBlock(vector).getId();
|
final int blockId = block.getId();
|
||||||
|
|
||||||
if(blockId == TNT)
|
if(blockId == TNT)
|
||||||
tnt++;
|
tnt++;
|
||||||
@ -106,22 +153,67 @@ public class CheckSchemType {
|
|||||||
if(blockId == DISPENSER)
|
if(blockId == DISPENSER)
|
||||||
dispenser++;
|
dispenser++;
|
||||||
|
|
||||||
|
if(INVENTORY.contains(blockId)){
|
||||||
|
checkInventory(errors, warnings, block, blockId);
|
||||||
|
}
|
||||||
|
|
||||||
if(forbiddenIds.contains(blockId))
|
if(forbiddenIds.contains(blockId))
|
||||||
return "Der Block " + Material.getMaterial(blockId).name() + " ist verboten";
|
errors.add("Der Block " + Material.getMaterial(blockId).name() + " ist verboten");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
finalChecks(errors, tnt, slime, dispenser);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkInventory(List<String> errors, List<String> warnings, BaseBlock block, int blockId){
|
||||||
|
CompoundTag nbt = block.getNbtData();
|
||||||
|
if(nbt == null){
|
||||||
|
warnings.add("Ein(e) " + Material.getMaterial(blockId).name() + " ist defekt");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(blockId == JUKEBOX && nbt.getValue().containsKey("RecordItem")){
|
||||||
|
errors.add("Schallplatten sind auch nicht in Schallplattenspielern gestattet");
|
||||||
|
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")){
|
||||||
|
warnings.add("Ein(e) " + Material.getMaterial(blockId).name() + " ist defekt");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Material type = Material.getMaterial(item.getString("id").split(":")[1].toUpperCase());
|
||||||
|
if(type == null && item.getString("id").equals("minecraft:fire_charge"))
|
||||||
|
type = Material.FIREBALL;
|
||||||
|
if(type == null) //Leere Slots
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(blockId == DISPENSER && (type.equals(Material.FIREBALL) || type.equals(Material.ARROW)))
|
||||||
|
counter += item.getByte("Count");
|
||||||
|
else if(!FLOWERS.contains(type) && !(blockId == CHEST && type.equals(Material.TNT)))
|
||||||
|
errors.add("In einem/r " + Material.getMaterial(blockId).name() + " ist das verbotene Item " + type);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(counter > maxDispenserItems)
|
||||||
|
errors.add("Ein Werfer enthält mehr als " + maxDispenserItems + " Pfeile und Feuerbälle");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void finalChecks(List<String> errors, int tnt, int slime, int dispenser){
|
||||||
int tntSlime = tnt + slime;
|
int tntSlime = tnt + slime;
|
||||||
if(maxTNT != 0 && tnt > maxTNT)
|
if(maxTNT != 0 && tnt > maxTNT)
|
||||||
return "Zu viele TNT-Blöcke";
|
errors.add("Zu viele TNT-Blöcke");
|
||||||
if(maxSlime != 0 && slime > maxSlime)
|
if(maxSlime != 0 && slime > maxSlime)
|
||||||
return "Zu viele Schleim-Blöcke";
|
errors.add("Zu viele Schleim-Blöcke");
|
||||||
if(maxDispenser != 0 && dispenser > maxDispenser)
|
if(maxDispenser != 0 && dispenser > maxDispenser)
|
||||||
return "Zu viele Werfer";
|
errors.add("Zu viele Werfer");
|
||||||
if(maxTNTSlime != 0 && tntSlime > maxTNTSlime)
|
if(maxTNTSlime != 0 && tntSlime > maxTNTSlime)
|
||||||
return "Zu viel Schleim+TNT";
|
errors.add("Zu viel Schleim+TNT");
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.attribute.PosixFilePermission;
|
import java.nio.file.attribute.PosixFilePermission;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
@ -281,14 +282,22 @@ public class SchematicCommand implements CommandExecutor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String reason = CheckSchemType.get(type).autoCheck(schematic);
|
List<String> errors = new LinkedList<>();
|
||||||
if(reason != null){
|
List<String> warnings = new LinkedList<>();
|
||||||
player.sendMessage(SchematicSystem.PREFIX + "§c" + reason);
|
CheckSchemType.get(type).autoCheck(schematic, errors, warnings);
|
||||||
|
for(String warning : warnings){
|
||||||
|
player.sendMessage(" §e" + warning);
|
||||||
|
}
|
||||||
|
for(String error : errors){
|
||||||
|
player.sendMessage(" §c" + error);
|
||||||
|
}
|
||||||
|
if(!errors.isEmpty()){
|
||||||
|
player.sendMessage(SchematicSystem.PREFIX + "§cDie Schematic ist nicht regelkonform");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
schematic.setSchemType(type.checkType());
|
schematic.setSchemType(type.checkType());
|
||||||
player.sendMessage(SchematicSystem.PREFIX + "§aDie Schematic wird zeitnah auf Regelkonformität überprüft");
|
player.sendMessage(SchematicSystem.PREFIX + "§aDie Schematic wird zeitnah überprüft");
|
||||||
CheckUtils.sendTeamMembersCSchematics(SchematicSystem.PREFIX + player.getName() + " §7hat ein " + type.name() + " eingesendet");
|
CheckUtils.sendTeamMembersCSchematics(SchematicSystem.PREFIX + player.getName() + " §7hat ein " + type.name() + " eingesendet");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren