diff --git a/SchematicSystem_14/pom.xml b/SchematicSystem_14/pom.xml index 746d6d8..98a4957 100644 --- a/SchematicSystem_14/pom.xml +++ b/SchematicSystem_14/pom.xml @@ -4,15 +4,15 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - SchematicSystem_14 - 1.0 - steamwar SchematicSystem 1.0 + SchematicSystem_14 + 1.0 + src diff --git a/SchematicSystem_14/src/de/steamwar/schematicsystem/CheckSchemType_14.java b/SchematicSystem_14/src/de/steamwar/schematicsystem/CheckSchemType_14.java index b778591..bae671f 100644 --- a/SchematicSystem_14/src/de/steamwar/schematicsystem/CheckSchemType_14.java +++ b/SchematicSystem_14/src/de/steamwar/schematicsystem/CheckSchemType_14.java @@ -1,143 +1,11 @@ package de.steamwar.schematicsystem; -import com.sk89q.jnbt.CompoundTag; -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_14 { - private static final Set INVENTORY = EnumSet.of( - Material.CHEST, - Material.TRAPPED_CHEST, - Material.HOPPER, - Material.FURNACE, - Material.DROPPER, - Material.JUKEBOX, - Material.DISPENSER, - Material.ANVIL, - Material.BREWING_STAND, - Material.BLACK_SHULKER_BOX, - Material.RED_SHULKER_BOX, - Material.WHITE_SHULKER_BOX, - Material.ORANGE_SHULKER_BOX, - Material.BLUE_SHULKER_BOX, - Material.LIGHT_BLUE_SHULKER_BOX, - Material.YELLOW_SHULKER_BOX, - Material.GREEN_SHULKER_BOX, - Material.BROWN_SHULKER_BOX, - Material.CYAN_SHULKER_BOX, - Material.GRAY_SHULKER_BOX, - Material.LIGHT_GRAY_SHULKER_BOX, - Material.LIME_SHULKER_BOX, - Material.MAGENTA_SHULKER_BOX, - Material.PINK_SHULKER_BOX, - Material.PURPLE_SHULKER_BOX); - //TODO: New Inventory Items - //TODO: Adding flowers - private static final Set FLOWERS = EnumSet.of( - Material.CORNFLOWER); - private CheckSchemType_14(){} - static void autoCheck(Schematic schematic, List errors, List warnings, ICheckSchemType type) { - Clipboard clipboard; - try { - clipboard = schematic.load(); - } catch (Schematic.WrongVersionException e) { - errors.add("Der Schematictyp dieser Schematic kann nicht in dieser Version geändert werden."); - return; - } catch (IOException | NoClipboardException e) { - Bukkit.getLogger().log(Level.SEVERE, "Schematic could not be loaded", e); - errors.add("Die Schematic konnte nicht geladen werden"); - return; - } - - BlockVector3 dimensions = clipboard.getDimensions(); - - if(dimensions.getBlockX() > type.getWidth() || dimensions.getBlockY() > type.getHeight() || dimensions.getBlockZ() > type.getDepth()) - errors.add("Das " + type.getName() + " überschreitet die Maximalmaße"); - - Region region = clipboard.getRegion(); - BlockVector3 min = region.getMinimumPoint(); - BlockVector3 max = region.getMaximumPoint(); - - int tnt = 0; - int slime = 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.getFullBlock(BlockVector3.at(x, y, z)); - final Material blockMaterial = Material.matchMaterial(block.getBlockType().getId()); - - if(blockMaterial == Material.TNT || blockMaterial == Material.OBSIDIAN) - tnt++; - - if(blockMaterial == Material.SLIME_BLOCK || blockMaterial == Material.BEDROCK) - slime++; - - if(blockMaterial == Material.DISPENSER) - dispenser++; - - if(INVENTORY.contains(blockMaterial)){ - checkInventory(errors, warnings, block, blockMaterial, type); - } - - if(type.getForbidden().contains(blockMaterial.name())) - errors.add("Der Block " + blockMaterial.name() + " ist verboten"); - } - } - } - - type.finalChecks(errors, tnt, slime, dispenser); - } - - private static void checkInventory(List errors, List warnings, BaseBlock block, Material blockMaterial, ICheckSchemType type){ - CompoundTag nbt = block.getNbtData(); - if(nbt == null){ - warnings.add("Ein(e) " + blockMaterial.name() + " ist defekt"); - return; - } - - if(blockMaterial == Material.JUKEBOX && nbt.getValue().containsKey("RecordItem")){ - errors.add("Schallplatten sind auch nicht in Schallplattenspielern gestattet"); - return; - } - - List 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) " + blockMaterial.name() + " ist defekt"); - continue; - } - - Material t = Material.matchMaterial(item.getString("id")); - if(t == null) //Leere Slots - continue; - - if(blockMaterial == Material.DISPENSER && (t.equals(Material.FIRE_CHARGE) || t.equals(Material.ARROW))) - counter += item.getByte("Count"); - else if(!FLOWERS.contains(t) && !(blockMaterial == Material.CHEST && t.equals(Material.TNT))) - errors.add("In einem/r " + blockMaterial.name() + " ist das verbotene Item " + t); - } - - if(counter > type.getMaxDispenserItems()) - errors.add("Ein Werfer enthält mehr als " + type.getMaxDispenserItems() + " Pfeile und Feuerbälle"); + static void autoCheck(List errors) { + errors.add("In der 1.14 können keine Schematics eingesendet werden"); } } diff --git a/SchematicSystem_15/pom.xml b/SchematicSystem_15/pom.xml new file mode 100644 index 0000000..365f874 --- /dev/null +++ b/SchematicSystem_15/pom.xml @@ -0,0 +1,53 @@ + + + 4.0.0 + + SchematicSystem_15 + 1.0 + + + steamwar + SchematicSystem + 1.0 + + + + src + + + src + + **/*.java + **/*.kt + + + + + + + + steamwar + SchematicSystem_API + 1.0 + + + steamwar + SchematicSystem_14 + 1.0 + + + steamwar + Spigot + 1.15 + provided + + + steamwar + FAWE + 1.14 + provided + + + \ No newline at end of file diff --git a/SchematicSystem_15/src/de/steamwar/schematicsystem/CheckSchemType_15.java b/SchematicSystem_15/src/de/steamwar/schematicsystem/CheckSchemType_15.java new file mode 100644 index 0000000..a9bf3e4 --- /dev/null +++ b/SchematicSystem_15/src/de/steamwar/schematicsystem/CheckSchemType_15.java @@ -0,0 +1,161 @@ +package de.steamwar.schematicsystem; + +import com.sk89q.jnbt.CompoundTag; +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 { + private static final Set INVENTORY = EnumSet.of( + Material.CHEST, + Material.TRAPPED_CHEST, + Material.HOPPER, + Material.FURNACE, + Material.DROPPER, + Material.JUKEBOX, + Material.DISPENSER, + Material.ANVIL, + Material.BREWING_STAND, + Material.BLACK_SHULKER_BOX, + Material.RED_SHULKER_BOX, + Material.WHITE_SHULKER_BOX, + Material.ORANGE_SHULKER_BOX, + Material.BLUE_SHULKER_BOX, + Material.LIGHT_BLUE_SHULKER_BOX, + Material.YELLOW_SHULKER_BOX, + Material.GREEN_SHULKER_BOX, + Material.BROWN_SHULKER_BOX, + Material.CYAN_SHULKER_BOX, + Material.GRAY_SHULKER_BOX, + Material.LIGHT_GRAY_SHULKER_BOX, + Material.LIME_SHULKER_BOX, + Material.MAGENTA_SHULKER_BOX, + Material.PINK_SHULKER_BOX, + Material.PURPLE_SHULKER_BOX, + Material.LECTERN, + Material.BEACON, + Material.BARREL); + + private static final Set FLOWERS = EnumSet.of( + Material.CORNFLOWER, + Material.FERN, + Material.DANDELION, + Material.POPPY, + Material.BLUE_ORCHID, + Material.ALLIUM, + Material.AZURE_BLUET, + Material.RED_TULIP, + Material.ORANGE_TULIP, + Material.WHITE_TULIP, + Material.PINK_TULIP, + Material.OXEYE_DAISY, + Material.CORNFLOWER, + Material.LILY_OF_THE_VALLEY, + Material.WITHER_ROSE, + Material.BROWN_MUSHROOM, + Material.RED_MUSHROOM); + + private CheckSchemType_15(){} + + static void autoCheck(Schematic schematic, List errors, List warnings, ICheckSchemType type) { + Clipboard clipboard; + try { + clipboard = schematic.load(); + } catch (Schematic.WrongVersionException e) { + errors.add("Der Schematictyp dieser Schematic kann nicht in dieser Version geändert werden."); + return; + } catch (IOException | NoClipboardException e) { + Bukkit.getLogger().log(Level.SEVERE, "Schematic could not be loaded", e); + errors.add("Die Schematic konnte nicht geladen werden"); + return; + } + + BlockVector3 dimensions = clipboard.getDimensions(); + + if(dimensions.getBlockX() > type.getWidth() || dimensions.getBlockY() > type.getHeight() || dimensions.getBlockZ() > type.getDepth()) + errors.add("Das " + type.getName() + " überschreitet die Maximalmaße"); + + Region region = clipboard.getRegion(); + BlockVector3 min = region.getMinimumPoint(); + BlockVector3 max = region.getMaximumPoint(); + + int tnt = 0; + int slime = 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.getFullBlock(BlockVector3.at(x, y, z)); + final Material blockMaterial = Material.matchMaterial(block.getBlockType().getId()); + + if(blockMaterial == Material.TNT || blockMaterial == Material.OBSIDIAN) + tnt++; + + if(blockMaterial == Material.SLIME_BLOCK || blockMaterial == Material.BEDROCK) + slime++; + + if(blockMaterial == Material.DISPENSER) + dispenser++; + + if(INVENTORY.contains(blockMaterial)){ + checkInventory(errors, warnings, block, blockMaterial, type); + } + + if(type.getForbidden().contains(blockMaterial.name())) + errors.add("Der Block " + blockMaterial.name() + " ist verboten"); + } + } + } + + type.finalChecks(errors, tnt, slime, dispenser); + } + + private static void checkInventory(List errors, List warnings, BaseBlock block, Material blockMaterial, ICheckSchemType type){ + CompoundTag nbt = block.getNbtData(); + if(nbt == null){ + warnings.add("Ein(e) " + blockMaterial.name() + " ist defekt"); + return; + } + + if(blockMaterial == Material.JUKEBOX && nbt.getValue().containsKey("RecordItem")){ + errors.add("Schallplatten sind auch nicht in Schallplattenspielern gestattet"); + return; + } + + List 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) " + blockMaterial.name() + " ist defekt"); + continue; + } + + Material t = Material.matchMaterial(item.getString("id")); + if(t == null) //Leere Slots + continue; + + if(blockMaterial == Material.DISPENSER && (t.equals(Material.FIRE_CHARGE) || t.equals(Material.ARROW))) + counter += item.getByte("Count"); + else if(!FLOWERS.contains(t) && !(blockMaterial == Material.CHEST && t.equals(Material.TNT))) + errors.add("In einem/r " + blockMaterial.name() + " ist das verbotene Item " + t); + } + + if(counter > type.getMaxDispenserItems()) + errors.add("Ein Werfer enthält mehr als " + type.getMaxDispenserItems() + " Pfeile und Feuerbälle"); + } +} diff --git a/SchematicSystem_15/src/de/steamwar/schematicsystem/WorldEdit_15.java b/SchematicSystem_15/src/de/steamwar/schematicsystem/WorldEdit_15.java new file mode 100644 index 0000000..6fcc4a4 --- /dev/null +++ b/SchematicSystem_15/src/de/steamwar/schematicsystem/WorldEdit_15.java @@ -0,0 +1,16 @@ +package de.steamwar.schematicsystem; + +import com.sk89q.worldedit.EditSession; +import de.steamwar.sql.NoClipboardException; +import de.steamwar.sql.Schematic; +import org.bukkit.entity.Player; + +import java.io.IOException; + +class WorldEdit_15 { + private WorldEdit_15(){} + + static EditSession pasteSchematic(Player player, Schematic schematic) throws Schematic.WrongVersionException, IOException, NoClipboardException { + return WorldEdit_14.pasteSchematic(player, schematic); + } +} diff --git a/SchematicSystem_Main/pom.xml b/SchematicSystem_Main/pom.xml index d65b137..7f5ab24 100644 --- a/SchematicSystem_Main/pom.xml +++ b/SchematicSystem_Main/pom.xml @@ -62,6 +62,12 @@ 1.0 provided + + steamwar + SchematicSystem_15 + 1.0 + compile + steamwar SchematicSystem_14 diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/CheckSchemType.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/CheckSchemType.java index de6f1ba..dcf94ca 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/CheckSchemType.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/CheckSchemType.java @@ -60,8 +60,11 @@ public class CheckSchemType implements ICheckSchemType { public void autoCheck(Schematic schematic, List errors, List warnings) { switch(Core.getVersion()){ + case 15: + CheckSchemType_15.autoCheck(schematic, errors, warnings, this); + break; case 14: - CheckSchemType_14.autoCheck(schematic, errors, warnings, this); + CheckSchemType_14.autoCheck(errors); break; default: CheckSchemType_12.autoCheck(schematic, errors, warnings, this); diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/WorldEdit.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/WorldEdit.java index f7ac14f..10bec52 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/WorldEdit.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/WorldEdit.java @@ -13,6 +13,8 @@ public class WorldEdit { public static EditSession pasteSchematic(Player player, Schematic schematic) throws Schematic.WrongVersionException, IOException, NoClipboardException { switch(Core.getVersion()){ + case 15: + return WorldEdit_15.pasteSchematic(player, schematic); case 14: return WorldEdit_14.pasteSchematic(player, schematic); default: diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java index c605b95..fac69a7 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java @@ -126,6 +126,10 @@ class GUI { p.closeInventory(); changeType(p, schem); }); + inv.setItem(5, SWItem.getMaterial("MAGENTA_GLAZED_TERRACOTTA"), "§eDownload", click -> { + p.closeInventory(); + SchematicCommand.download(p, schem); + }); inv.setItem(6, SWItem.getMaterial("SKULL_ITEM"), "§eMitglieder", click -> { p.closeInventory(); delmembers(p, schem); diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index af2ed7c..8014119 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -64,6 +64,9 @@ public class SchematicCommand implements CommandExecutor { case "delmember": delmember(player, args); break; + case "download": + download(player, args); + break; default: help(player); } @@ -281,6 +284,13 @@ public class SchematicCommand implements CommandExecutor { } player.spigot().sendMessage(type); + if(SteamwarUser.get(schematic.getSchemOwner()).getUUID().equals(player.getUniqueId())){ + TextComponent download = new TextComponent("§eDownload Schematic"); + download.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§eGeneriere Downloadlink"))); + download.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem download " + schematic.getSchemName())); + player.spigot().sendMessage(download); + } + List checkedSchematics = CheckedSchematic.getLastDeclined(player.getUniqueId()); for(int i = checkedSchematics.size() -1; i >= 0; i--) { if(checkedSchematics.get(i).getSchemName().equals(schematic.getSchemName()) && @@ -308,6 +318,28 @@ public class SchematicCommand implements CommandExecutor { } } + private void download(Player player, String[] args){ + if(args.length < 2){ + help(player); + return; + } + + Schematic schematic = getSchem(player, args[1]); + if(schematic == null) + return; + + download(player, schematic); + } + + static void download(Player player, Schematic schematic){ + if(schematic.getSchemOwner() != SteamwarUser.get(player.getUniqueId()).getId()){ + player.sendMessage("§cDu darfst nur deine eigenen Schematics herunterladen!"); + return; + } + + player.sendMessage(DownloadSchematic.getLink(schematic)); + } + private void addmember(Player player, String[] args){ if(args.length < 3){ help(player); @@ -400,6 +432,7 @@ public class SchematicCommand implements CommandExecutor { player.sendMessage("§8/§eschem changetype §8[§7Schematic§8] - §7Ändert die Art deiner Schematic"); player.sendMessage("§8/§eschem delete §8[§7Schematic§8] - §7Löscht eine Schematic"); player.sendMessage("§8/§eschem info §8[§7Schematic§8] - §7Zeigt dir Informationen zur Schematic"); + player.sendMessage("§8/§eschem download §8[§7Schematic§8] - §7Gibt dir einen Downloadlink (1 min gültig)"); player.sendMessage("§8/§eschem addmember §8[§7Schematic§8] §8[§7Spieler§8] - §7Fügt einen Spieler zu einer Schematic hinzu"); player.sendMessage("§8/§eschem delmember §8[§7Schematic§8] §8[§7Spieler§8] - §7Entfernt einen Spieler von einer Schematic"); } diff --git a/SchematicSystem_Main/src/plugin.yml b/SchematicSystem_Main/src/plugin.yml index ce8624a..654bc59 100644 --- a/SchematicSystem_Main/src/plugin.yml +++ b/SchematicSystem_Main/src/plugin.yml @@ -3,6 +3,7 @@ version: "1.0" authors: [Yaruma3341, Lixfel] depend: [SpigotCore, WorldEdit] main: de.steamwar.schematicsystem.SchematicSystem +api-version: "1.13" commands: schem: diff --git a/pom.xml b/pom.xml index 8cf978c..89f08c6 100644 --- a/pom.xml +++ b/pom.xml @@ -38,6 +38,7 @@ SchematicSystem_12 SchematicSystem_14 + SchematicSystem_15 SchematicSystem_API SchematicSystem_Main