From 863ef9cc2a17afaa906cc4d4e9774776b55e690d Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 12 Nov 2021 14:54:54 +0100 Subject: [PATCH 1/2] New config format, usage of new apis Signed-off-by: Lixfel --- SchematicSystem_15/pom.xml | 2 +- ...chemType_15.java => CheckSchemType15.java} | 42 +----- .../pom.xml | 8 +- .../schematicsystem/CheckSchemType8.java | 89 +++-------- .../schematicsystem/ICheckSchemType.java | 38 ----- .../pom.xml | 33 ++++- .../schematicsystem/AutoCheckResult.java | 74 +++------- .../schematicsystem/CheckSchemType.java | 138 ++++++++++++++++++ .../schematicsystem/SchematicSystem.java | 16 +- .../schematicsystem/commands/GUI.java | 0 .../commands/SchematicCommand.java | 0 .../src/plugin.yml | 3 +- SchematicSystem_Main/pom.xml | 41 +----- .../schematicsystem/CheckSchemType.java | 138 ------------------ pom.xml | 4 +- 15 files changed, 232 insertions(+), 394 deletions(-) rename SchematicSystem_15/src/de/steamwar/schematicsystem/{CheckSchemType_15.java => CheckSchemType15.java} (81%) rename {SchematicSystem_12 => SchematicSystem_8}/pom.xml (87%) rename SchematicSystem_12/src/de/steamwar/schematicsystem/CheckSchemType_12.java => SchematicSystem_8/src/de/steamwar/schematicsystem/CheckSchemType8.java (64%) delete mode 100644 SchematicSystem_API/src/de/steamwar/schematicsystem/ICheckSchemType.java rename {SchematicSystem_API => SchematicSystem_Core}/pom.xml (51%) rename {SchematicSystem_API => SchematicSystem_Core}/src/de/steamwar/schematicsystem/AutoCheckResult.java (62%) create mode 100644 SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemType.java rename {SchematicSystem_Main => SchematicSystem_Core}/src/de/steamwar/schematicsystem/SchematicSystem.java (78%) rename {SchematicSystem_Main => SchematicSystem_Core}/src/de/steamwar/schematicsystem/commands/GUI.java (100%) rename {SchematicSystem_Main => SchematicSystem_Core}/src/de/steamwar/schematicsystem/commands/SchematicCommand.java (100%) rename {SchematicSystem_Main => SchematicSystem_Core}/src/plugin.yml (91%) delete mode 100644 SchematicSystem_Main/src/de/steamwar/schematicsystem/CheckSchemType.java diff --git a/SchematicSystem_15/pom.xml b/SchematicSystem_15/pom.xml index 0074fa1..e23f79a 100644 --- a/SchematicSystem_15/pom.xml +++ b/SchematicSystem_15/pom.xml @@ -33,7 +33,7 @@ steamwar - SchematicSystem_API + SchematicSystem_Core 1.0 diff --git a/SchematicSystem_15/src/de/steamwar/schematicsystem/CheckSchemType_15.java b/SchematicSystem_15/src/de/steamwar/schematicsystem/CheckSchemType15.java similarity index 81% rename from SchematicSystem_15/src/de/steamwar/schematicsystem/CheckSchemType_15.java rename to SchematicSystem_15/src/de/steamwar/schematicsystem/CheckSchemType15.java index dbfe37a..0d4c79c 100644 --- a/SchematicSystem_15/src/de/steamwar/schematicsystem/CheckSchemType_15.java +++ b/SchematicSystem_15/src/de/steamwar/schematicsystem/CheckSchemType15.java @@ -24,18 +24,13 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.world.block.BaseBlock; -import de.steamwar.sql.NoClipboardException; -import de.steamwar.sql.Schematic; -import org.bukkit.Bukkit; import org.bukkit.Material; -import java.io.IOException; import java.util.EnumSet; import java.util.List; import java.util.Set; -import java.util.logging.Level; -class CheckSchemType_15 { +public class CheckSchemType15 implements CheckSchemType.ICheckSchemType { private static final Set INVENTORY = EnumSet.of( Material.BARREL, Material.BLAST_FURNACE, @@ -89,19 +84,10 @@ class CheckSchemType_15 { Material.GOLDEN_HORSE_ARMOR, Material.HONEY_BOTTLE); - private CheckSchemType_15(){} - - static AutoCheckResult autoCheck(Schematic schematic, ICheckSchemType type) { - AutoCheckResult result = new AutoCheckResult(type); - Clipboard clipboard; - try { - clipboard = schematic.load(); - } catch (IOException | NoClipboardException e) { - result.setErrorLoadingSchematic(); - Bukkit.getLogger().log(Level.SEVERE, "Schematic could not be loaded", e); - return result; - } + private CheckSchemType15(){} + @Override + public void autoCheck(AutoCheckResult result, Clipboard clipboard) { BlockVector3 dimensions = clipboard.getDimensions(); result.setLength(dimensions.getBlockX()); result.setHeight(dimensions.getBlockY()); @@ -111,11 +97,7 @@ class CheckSchemType_15 { BlockVector3 min = region.getMinimumPoint(); BlockVector3 max = region.getMaximumPoint(); - int tnt = 0; - int slime = 0; - int dispenser = 0; int blocks = 0; - 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++){ @@ -126,15 +108,6 @@ class CheckSchemType_15 { result.checkMaterial(blockMaterial.name()); - if(blockMaterial == Material.TNT || blockMaterial == Material.OBSIDIAN) - tnt++; - - if(blockMaterial == Material.SLIME_BLOCK || blockMaterial == Material.HONEY_BLOCK || blockMaterial == Material.BEDROCK) - slime++; - - if(blockMaterial == Material.DISPENSER) - dispenser++; - if(blockMaterial != Material.AIR) blocks++; @@ -144,15 +117,10 @@ class CheckSchemType_15 { } } - result.setTNT(tnt); - result.setSlime(slime); - result.setDispenser(dispenser); result.setBlocks(blocks); - - return result; } - private static void checkInventory(AutoCheckResult result, BaseBlock block, Material blockMaterial){ + private static void checkInventory(AutoCheckResult result, BaseBlock block, Material blockMaterial) { CompoundTag nbt = block.getNbtData(); if(nbt == null){ result.defunctNbt(blockMaterial.name()); diff --git a/SchematicSystem_12/pom.xml b/SchematicSystem_8/pom.xml similarity index 87% rename from SchematicSystem_12/pom.xml rename to SchematicSystem_8/pom.xml index 5143fee..109833f 100644 --- a/SchematicSystem_12/pom.xml +++ b/SchematicSystem_8/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - SchematicSystem_12 + SchematicSystem_8 1.0 @@ -34,9 +34,9 @@ steamwar Spigot - 1.12 + 1.8 system - ${main.basedir}/lib/Spigot-1.12.jar + ${main.basedir}/lib/Spigot-1.8.jar steamwar @@ -47,7 +47,7 @@ steamwar - SchematicSystem_API + SchematicSystem_Core 1.0 diff --git a/SchematicSystem_12/src/de/steamwar/schematicsystem/CheckSchemType_12.java b/SchematicSystem_8/src/de/steamwar/schematicsystem/CheckSchemType8.java similarity index 64% rename from SchematicSystem_12/src/de/steamwar/schematicsystem/CheckSchemType_12.java rename to SchematicSystem_8/src/de/steamwar/schematicsystem/CheckSchemType8.java index 45d198a..6335f23 100644 --- a/SchematicSystem_12/src/de/steamwar/schematicsystem/CheckSchemType_12.java +++ b/SchematicSystem_8/src/de/steamwar/schematicsystem/CheckSchemType8.java @@ -24,19 +24,14 @@ import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.regions.Region; -import de.steamwar.sql.NoClipboardException; -import de.steamwar.sql.Schematic; -import org.bukkit.Bukkit; import org.bukkit.Material; -import java.io.IOException; import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.logging.Level; @SuppressWarnings("deprecation") -class CheckSchemType_12 { +public class CheckSchemType8 implements CheckSchemType.ICheckSchemType { private static final int TNT = Material.TNT.getId(); private static final int SLIME = Material.SLIME_BLOCK.getId(); private static final int OBSIDIAN = Material.OBSIDIAN.getId(); @@ -45,38 +40,23 @@ class CheckSchemType_12 { private static final int AIR = Material.AIR.getId(); private static final int JUKEBOX = Material.JUKEBOX.getId(); private static final int CHEST = Material.CHEST.getId(); - private static final Set INVENTORY; + private static final Set INVENTORY = new HashSet<>(); private static final Set FLOWERS; static{ - Set 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; + 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 flowers = new HashSet<>(); flowers.add(Material.YELLOW_FLOWER); @@ -88,19 +68,10 @@ class CheckSchemType_12 { FLOWERS = flowers; } - private CheckSchemType_12(){} - - static AutoCheckResult autoCheck(Schematic schematic, ICheckSchemType type) { - AutoCheckResult result = new AutoCheckResult(type); - 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; - } + private CheckSchemType8(){} + @Override + public void autoCheck(AutoCheckResult result, Clipboard clipboard) { Vector dimensions = clipboard.getDimensions(); result.setLength(dimensions.getBlockX()); result.setHeight(dimensions.getBlockY()); @@ -110,47 +81,29 @@ class CheckSchemType_12 { Vector min = region.getMinimumPoint(); Vector max = region.getMaximumPoint(); - int tnt = 0; - int slime = 0; int blocks = 0; - int dispenser = 0; - 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(); - if(blockId == TNT || blockId == OBSIDIAN) - tnt++; - - if(blockId == SLIME || blockId == BEDROCK) - slime++; - - if(blockId == DISPENSER) - dispenser++; + result.checkMaterial(Material.getMaterial(blockId).name()); if (blockId != AIR) blocks++; if(INVENTORY.contains(blockId)){ - checkInventory(result, block, blockId, type); + checkInventory(result, block, blockId); } - - result.checkMaterial(Material.getMaterial(blockId).name()); } } } - result.setTNT(tnt); - result.setSlime(slime); - result.setDispenser(dispenser); result.setBlocks(blocks); - - return result; } - private static void checkInventory(AutoCheckResult result, BaseBlock block, int blockId, ICheckSchemType type){ + private static void checkInventory(AutoCheckResult result, BaseBlock block, int blockId) { CompoundTag nbt = block.getNbtData(); if(nbt == null){ result.defunctNbt(Material.getMaterial(blockId).name()); diff --git a/SchematicSystem_API/src/de/steamwar/schematicsystem/ICheckSchemType.java b/SchematicSystem_API/src/de/steamwar/schematicsystem/ICheckSchemType.java deleted file mode 100644 index bc58010..0000000 --- a/SchematicSystem_API/src/de/steamwar/schematicsystem/ICheckSchemType.java +++ /dev/null @@ -1,38 +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 . -*/ - -package de.steamwar.schematicsystem; - -import java.util.List; - -interface ICheckSchemType { - String getName(); - - int getWidth(); - int getHeight(); - int getDepth(); - int getMaxDispenserItems(); - int getMaxDispenser(); - int getMaxTNT(); - int getMaxTNTSlime(); - int getMaxSlime(); - int getMaxBlocks(); - - List getForbidden(); -} diff --git a/SchematicSystem_API/pom.xml b/SchematicSystem_Core/pom.xml similarity index 51% rename from SchematicSystem_API/pom.xml rename to SchematicSystem_Core/pom.xml index e6ef4f8..cb1732d 100644 --- a/SchematicSystem_API/pom.xml +++ b/SchematicSystem_Core/pom.xml @@ -14,8 +14,9 @@ ${project.basedir}/.. - SchematicSystem_API + SchematicSystem_Core 1.0 + jar src @@ -30,13 +31,39 @@ + + + + maven-restlet + Public online Restlet repository + http://maven.restlet.org + + + steamwar Spigot - 1.12 + 1.15 system - ${main.basedir}/lib/Spigot-1.12.jar + ${main.basedir}/lib/Spigot-1.15.jar + + + steamwar + WorldEdit + 1.15 + system + ${main.basedir}/lib/WorldEdit-1.15.jar + + + org.apache.httpcomponents + httpclient + 4.5.13 + + + org.apache.httpcomponents + httpmime + 4.5.13 \ No newline at end of file diff --git a/SchematicSystem_API/src/de/steamwar/schematicsystem/AutoCheckResult.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/AutoCheckResult.java similarity index 62% rename from SchematicSystem_API/src/de/steamwar/schematicsystem/AutoCheckResult.java rename to SchematicSystem_Core/src/de/steamwar/schematicsystem/AutoCheckResult.java index 317df27..d3760a9 100644 --- a/SchematicSystem_API/src/de/steamwar/schematicsystem/AutoCheckResult.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/AutoCheckResult.java @@ -19,54 +19,37 @@ package de.steamwar.schematicsystem; -import de.steamwar.core.Core; - import java.util.*; public class AutoCheckResult { - private final ICheckSchemType type; + private final CheckSchemType type; - private final boolean noChecksInThisVersion; - private boolean wrongVersionException = false; // Schematic nicht in der Version ladbar - private boolean errorLoadingSchematic = false; // Schematic irgendwie invalide + private boolean errorLoadingSchematic = false; 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 int blocks = 0; - private Map forbiddenMaterials = new HashMap<>(); // Anzahl verbotener Blöcke nach Material + private final Map, Integer> limitedMaterials; - private Map defunctNbt = new HashMap<>(); // Anzahl an defekten NBT-Blöcken nach Materialname - private int records = 0; // Gefundene Schallplatten - private Map> forbiddenItems = new HashMap<>(); // Anzahl verbotener Items nach Inventartyp - private Map> itemsWithTag = new HashMap<>(); // Anzahl an Items mit Tag nach Inventartyp - private int tooManyDispenserItems = 0; // Gefundene Überschreitungen von DispenserItems + private final Map defunctNbt = new HashMap<>(); // Amount of defect NBT-Blocks with material name - AutoCheckResult(ICheckSchemType type){ + private int records = 0; // Amount of found records + private final Map> forbiddenItems = new HashMap<>(); // Amount forbidden items per inventory block + private final Map> 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; - noChecksInThisVersion = false; + this.limitedMaterials = type.getLimits(); } - AutoCheckResult(){ - type = null; - noChecksInThisVersion = true; - } - - public Collection errors(){ + public Collection errors() { List 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"); @@ -78,22 +61,15 @@ public class AutoCheckResult { 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/Honig-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, Integer> entry : limitedMaterials.entrySet()) { + if(entry.getValue() < 0) + errors.add((entry.getKey().size() == 1 ? "Der Block " : "Die Blockkombination") + String.join(" ", entry.getKey()) + " wurde " + (-entry.getValue()) + " mal zu häufig verbaut"); + } + if(type.getMaxBlocks() != 0 && blocks > type.getMaxBlocks()) { errors.add("Zu viele Blöcke (" + blocks + " > " + type.getMaxBlocks() + ")"); } - for(Map.Entry 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> block : forbiddenItems.entrySet()) @@ -137,23 +113,15 @@ public class AutoCheckResult { 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 setBlocks(int blocks) { this.blocks = blocks; } void checkMaterial(String name){ - assert type != null; - if(type.getForbidden().contains(name)) - forbiddenMaterials.compute(name, (k, v) -> v == null ? 1 : v+1); + for(Map.Entry, Integer> entry : limitedMaterials.entrySet()) { + if(entry.getKey().contains(name)) + entry.setValue(entry.getValue() - 1); + } } void defunctNbt(String name){ diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemType.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemType.java new file mode 100644 index 0000000..2991f08 --- /dev/null +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemType.java @@ -0,0 +1,138 @@ +/* + 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 . +*/ + +package de.steamwar.schematicsystem; + +import com.sk89q.worldedit.extent.clipboard.Clipboard; +import de.steamwar.core.Core; +import de.steamwar.core.VersionDependent; +import de.steamwar.sql.NoClipboardException; +import de.steamwar.sql.Schematic; +import de.steamwar.sql.SchematicType; +import org.bukkit.Bukkit; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.File; +import java.io.IOException; +import java.util.*; +import java.util.logging.Level; + +public class CheckSchemType { + + private static final Map types = new HashMap<>(); + + private final int width; + private final int height; + private final int depth; + private final int maxDispenserItems; + + private final Map, Integer> limits; + private final int maxBlocks; + + private CheckSchemType(ConfigurationSection section) { + String name = section.getString("Schematic.Type"); + width = section.getInt("Schematic.Size.x"); + height = section.getInt("Schematic.Size.y"); + depth = section.getInt("Schematic.Size.z"); + + maxDispenserItems = section.getInt("Schematic.MaxDispenserItems", 128); + maxBlocks = section.getInt("Schematic.MaxBlocks", 0); + + //TODO: Materials in Config required in style of 1.8-1.12 and 1.13-1.15 + + limits = new HashMap<>(); + for(Map entry : section.getMapList("Schematic.Limited")) { + int amount = (Integer) entry.get("Amount"); + Set materials = new HashSet<>((List) entry.get("Materials")); + if(amount == 0) { + materials.forEach(material -> limits.put(Collections.singleton(material), 0)); + } else { + limits.put(materials, amount); + } + } + + types.put(SchematicType.fromDB(name.toLowerCase()), this); + types.put(SchematicType.fromDB("c" + name.toLowerCase()), this); + } + + static { + File folder = new File(Core.getInstance().getDataFolder().getParentFile(), "FightSystem"); + + if(folder.exists()) { + for(File configFile : folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))) { + YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); + if (!config.isConfigurationSection("CheckQuestions")) + continue; + + new CheckSchemType(config); + } + } + } + + public static CheckSchemType get(SchematicType type){ + return types.get(type); + } + + public AutoCheckResult autoCheck(Schematic 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() { + return width; + } + + public int getHeight() { + return height; + } + + public int getDepth() { + return depth; + } + + public int getMaxDispenserItems() { + return maxDispenserItems; + } + + public int getMaxBlocks(){ + return maxBlocks; + } + + public Map, Integer> getLimits() { + return new HashMap<>(limits); + } + + + public static final ICheckSchemType impl = VersionDependent.getVersionImpl(SchematicSystem.getInstance()); + + public interface ICheckSchemType { + void autoCheck(AutoCheckResult result, Clipboard clipboard); + } +} diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/SchematicSystem.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java similarity index 78% rename from SchematicSystem_Main/src/de/steamwar/schematicsystem/SchematicSystem.java rename to SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java index ddb8d6c..935e9e5 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/SchematicSystem.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java @@ -20,23 +20,21 @@ package de.steamwar.schematicsystem; import de.steamwar.schematicsystem.commands.SchematicCommand; -import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; -import java.io.File; -import java.util.logging.Level; - public class SchematicSystem extends JavaPlugin { public static final String PREFIX = "§eSchematic§8» §7"; + private static SchematicSystem instance; + @Override public void onEnable() { - if (!new File(getDataFolder(), "config.yml").exists()) { - saveDefaultConfig(); - Bukkit.getLogger().log(Level.SEVERE, "config.yml erstellt und geladen!"); - } + instance = this; - CheckSchemType.init(getConfig()); getCommand("schem").setExecutor(new SchematicCommand()); } + + public static SchematicSystem getInstance() { + return instance; + } } diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java similarity index 100% rename from SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java rename to SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java similarity index 100% rename from SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java rename to SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java diff --git a/SchematicSystem_Main/src/plugin.yml b/SchematicSystem_Core/src/plugin.yml similarity index 91% rename from SchematicSystem_Main/src/plugin.yml rename to SchematicSystem_Core/src/plugin.yml index 654bc59..35345c4 100644 --- a/SchematicSystem_Main/src/plugin.yml +++ b/SchematicSystem_Core/src/plugin.yml @@ -10,5 +10,4 @@ commands: aliases: - schematic - /schematic - - /schem - check: \ No newline at end of file + - /schem \ No newline at end of file diff --git a/SchematicSystem_Main/pom.xml b/SchematicSystem_Main/pom.xml index ef5a40d..154470e 100644 --- a/SchematicSystem_Main/pom.xml +++ b/SchematicSystem_Main/pom.xml @@ -16,19 +16,8 @@ SchematicSystem_Main 1.0 - jar - src - - - src - - **/*.java - **/*.kt - - - org.apache.maven.plugins @@ -47,23 +36,7 @@ schematicsystem - - - - maven-restlet - Public online Restlet repository - http://maven.restlet.org - - - - - steamwar - Spigot - 1.15 - system - ${main.basedir}/lib/Spigot-1.15.jar - steamwar SchematicSystem_15 @@ -72,25 +45,15 @@ steamwar - SchematicSystem_12 + SchematicSystem_8 1.0 compile steamwar - SchematicSystem_API + SchematicSystem_Core 1.0 compile - - org.apache.httpcomponents - httpclient - 4.5.13 - - - org.apache.httpcomponents - httpmime - 4.5.13 - \ No newline at end of file diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/CheckSchemType.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/CheckSchemType.java deleted file mode 100644 index 9ed619a..0000000 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/CheckSchemType.java +++ /dev/null @@ -1,138 +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 . -*/ - -package de.steamwar.schematicsystem; - -import de.steamwar.core.VersionedCallable; -import de.steamwar.sql.Schematic; -import de.steamwar.sql.SchematicType; -import org.bukkit.configuration.ConfigurationSection; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class CheckSchemType implements ICheckSchemType { - - private static final Map types = new HashMap<>(); - - private final String name; - - private final int width; - private final int height; - private final int depth; - private final int maxDispenserItems; - private final List forbiddenMaterials; - - private final int maxTNT; - private final int maxSlime; - private final int maxTNTSlime; - private final int maxDispenser; - private final int maxBlocks; - - private CheckSchemType(ConfigurationSection section) { - name = section.getName(); - width = section.getInt("width"); - height = section.getInt("height"); - depth = section.getInt("depth"); - - maxTNT = section.getInt("maxTNT"); - maxSlime = section.getInt("maxSlime"); - maxTNTSlime = section.getInt("maxTNTSlime"); - maxDispenser = section.getInt("maxDispenser"); - maxDispenserItems = section.getInt("maxDispenserItems"); - maxBlocks = section.getInt("maxBlocks"); - - forbiddenMaterials = section.getStringList("forbiddenMaterials"); - types.put(SchematicType.fromDB(name), this); - types.put(SchematicType.fromDB("c" + name), this); - } - - static void init(ConfigurationSection config){ - ConfigurationSection types = config.getConfigurationSection("Schematics"); - for(String sectionName : types.getKeys(false)) - new CheckSchemType(types.getConfigurationSection(sectionName)); - } - - public static CheckSchemType get(SchematicType type){ - return types.get(type); - } - - public AutoCheckResult autoCheck(Schematic schematic) { - return VersionedCallable.call(new VersionedCallable<>(AutoCheckResult::new, 8), - new VersionedCallable<>(() -> CheckSchemType_12.autoCheck(schematic, this), 12), - new VersionedCallable<>(AutoCheckResult::new, 13), - new VersionedCallable<>(() -> CheckSchemType_15.autoCheck(schematic, this), 15)); - } - - @Override - public String getName() { - return name; - } - - @Override - public int getWidth() { - return width; - } - - @Override - public int getHeight() { - return height; - } - - @Override - public int getDepth() { - return depth; - } - - @Override - public int getMaxDispenserItems() { - 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 - public int getMaxBlocks(){ - return maxBlocks; - } - - @Override - public List getForbidden() { - return forbiddenMaterials; - } -} diff --git a/pom.xml b/pom.xml index 6d47c51..27a550f 100644 --- a/pom.xml +++ b/pom.xml @@ -30,10 +30,10 @@ - SchematicSystem_12 + SchematicSystem_8 SchematicSystem_15 - SchematicSystem_API SchematicSystem_Main + SchematicSystem_Core From 07e10c86d9140ae8f4b7df481893e2793af0aa81 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 2 Dec 2021 14:48:37 +0100 Subject: [PATCH 2/2] Fix bugs Signed-off-by: Lixfel --- .../src/de/steamwar/schematicsystem/CheckSchemType15.java | 2 -- .../src/de/steamwar/schematicsystem/CheckSchemType8.java | 2 -- .../src/de/steamwar/schematicsystem/CheckSchemType.java | 4 +--- .../src/de/steamwar/schematicsystem/commands/GUI.java | 6 ------ 4 files changed, 1 insertion(+), 13 deletions(-) diff --git a/SchematicSystem_15/src/de/steamwar/schematicsystem/CheckSchemType15.java b/SchematicSystem_15/src/de/steamwar/schematicsystem/CheckSchemType15.java index 0d4c79c..e0640c9 100644 --- a/SchematicSystem_15/src/de/steamwar/schematicsystem/CheckSchemType15.java +++ b/SchematicSystem_15/src/de/steamwar/schematicsystem/CheckSchemType15.java @@ -84,8 +84,6 @@ public class CheckSchemType15 implements CheckSchemType.ICheckSchemType { Material.GOLDEN_HORSE_ARMOR, Material.HONEY_BOTTLE); - private CheckSchemType15(){} - @Override public void autoCheck(AutoCheckResult result, Clipboard clipboard) { BlockVector3 dimensions = clipboard.getDimensions(); diff --git a/SchematicSystem_8/src/de/steamwar/schematicsystem/CheckSchemType8.java b/SchematicSystem_8/src/de/steamwar/schematicsystem/CheckSchemType8.java index 6335f23..c5fa415 100644 --- a/SchematicSystem_8/src/de/steamwar/schematicsystem/CheckSchemType8.java +++ b/SchematicSystem_8/src/de/steamwar/schematicsystem/CheckSchemType8.java @@ -68,8 +68,6 @@ public class CheckSchemType8 implements CheckSchemType.ICheckSchemType { FLOWERS = flowers; } - private CheckSchemType8(){} - @Override public void autoCheck(AutoCheckResult result, Clipboard clipboard) { Vector dimensions = clipboard.getDimensions(); diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemType.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemType.java index 2991f08..f3c3a01 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemType.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemType.java @@ -55,8 +55,6 @@ public class CheckSchemType { maxDispenserItems = section.getInt("Schematic.MaxDispenserItems", 128); maxBlocks = section.getInt("Schematic.MaxBlocks", 0); - //TODO: Materials in Config required in style of 1.8-1.12 and 1.13-1.15 - limits = new HashMap<>(); for(Map entry : section.getMapList("Schematic.Limited")) { int amount = (Integer) entry.get("Amount"); @@ -78,7 +76,7 @@ public class CheckSchemType { if(folder.exists()) { for(File configFile : folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))) { YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); - if (!config.isConfigurationSection("CheckQuestions")) + if (!config.isList("CheckQuestions")) continue; new CheckSchemType(config); diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java index 15d1a4a..c9bf36e 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java @@ -60,12 +60,6 @@ class GUI { inv.setItem(0, SWItem.getDye(1), (byte) 1, "§eLöschen", click -> { schem.remove(); - List checkedSchematics = CheckedSchematic.getLastDeclined(p.getUniqueId()); - for(CheckedSchematic checkedSchematic : checkedSchematics) { - if(checkedSchematic.getSchemOwner() == schem.getSchemOwner() && - checkedSchematic.getSchemName().equals(schem.getSchemName())) - checkedSchematic.remove(); - } p.sendMessage(SchematicSystem.PREFIX + "Schematic §e" + schem.getSchemName() + " §7gelöscht"); p.closeInventory(); });