From e5fdc2a04701f640e70d190164a26c5276d60a8c Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Sat, 20 Apr 2019 18:09:46 +0200 Subject: [PATCH] added config and made it more modular; hotfixes Signed-off-by: yaruma3341 --- src/config.yml | 29 ++++++ .../schematicsystem/SchematicSystem.java | 3 + .../commands/SchematicCommand.java | 95 ++++++++++++++++++- .../listener/PlayerJoinListener.java | 13 ++- .../warking/schematicsystem/utils/Config.java | 75 +++++++++++++++ 5 files changed, 212 insertions(+), 3 deletions(-) create mode 100644 src/config.yml create mode 100644 src/de/warking/schematicsystem/utils/Config.java diff --git a/src/config.yml b/src/config.yml new file mode 100644 index 0000000..154eb46 --- /dev/null +++ b/src/config.yml @@ -0,0 +1,29 @@ +Schematics: + WarGear: + Breite: + Höhe: + Tiefe: + Obsidian: + Bedrock: + ForbiddenIds: + MiniWarGear: + Breite: + Höhe: + Tiefe: + Obsidian: + Bedrock: + ForbiddenIds: + WarShip: + Breite: + Höhe: + Tiefe: + Obsidian: + Bedrock: + ForbiddenIds: + AirShip: + Breite: + Höhe: + Tiefe: + Obsidian: + Bedrock: + ForbiddenIds: \ No newline at end of file diff --git a/src/de/warking/schematicsystem/SchematicSystem.java b/src/de/warking/schematicsystem/SchematicSystem.java index d2bcd81..4843eaf 100644 --- a/src/de/warking/schematicsystem/SchematicSystem.java +++ b/src/de/warking/schematicsystem/SchematicSystem.java @@ -4,6 +4,7 @@ import com.sk89q.worldedit.bukkit.WorldEditPlugin; import de.warking.schematicsystem.commands.SchematicCommand; import de.warking.schematicsystem.listener.PlayerJoinListener; import de.warking.schematicsystem.utils.CommandRemover; +import de.warking.schematicsystem.utils.Config; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -18,6 +19,8 @@ public class SchematicSystem extends JavaPlugin { public void onEnable() { instance = this; + Config.load(); + try { CommandRemover.removeAll("/schematic", "/schem", "//schematic", "//schem"); } catch (Exception ex) { diff --git a/src/de/warking/schematicsystem/commands/SchematicCommand.java b/src/de/warking/schematicsystem/commands/SchematicCommand.java index 7d8b8b8..61ecba2 100644 --- a/src/de/warking/schematicsystem/commands/SchematicCommand.java +++ b/src/de/warking/schematicsystem/commands/SchematicCommand.java @@ -2,20 +2,27 @@ package de.warking.schematicsystem.commands; import com.boydti.fawe.FaweAPI; import com.sk89q.worldedit.EmptyClipboardException; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; +import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.session.ClipboardHolder; import de.warking.hunjy.MySQL.Schematic; import de.warking.hunjy.MySQL.SchematicMember; import de.warking.hunjy.MySQL.SchematicType; import de.warking.hunjy.MySQL.WarkingUser; import de.warking.schematicsystem.SchematicSystem; +import de.warking.schematicsystem.utils.Config; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -281,19 +288,45 @@ public class SchematicCommand implements CommandExecutor { if(args[0].equalsIgnoreCase("changetype")) { Schematic schematic = Schematic.getSchemFromDB(args[1], player.getUniqueId()); if(schematic != null) { + Clipboard clipboard; + try { + clipboard = FaweAPI.load(new File(SchematicSystem.SCHEM_DIR + player.getUniqueId() + "/" + args[1] + ".schematic")).getClipboard(); + } catch (IOException ex) { + player.sendMessage(SchematicSystem.PREFIX + "§cBeim Ausführen des Commands ist ein Fehler aufgetreten!"); + return false; + } + + Vector origin = clipboard.getOrigin(); + Vector dimensions = clipboard.getDimensions(); if(args[2].equalsIgnoreCase("airship")) { + if(dimensions.getBlockX() <= Config.AirShipBreite && dimensions.getBlockY() <= Config.AirShipHöhe && dimensions.getBlockZ() <= Config.AirShipTiefe && checkSchematic(clipboard, Config.AirShipForbiddenIds, true, true, "AirShip")) { + schematic.setSchemType(SchematicType.airship); + player.sendMessage(SchematicSystem.PREFIX + "Schematic Type §6airship §7angefordert!"); + } return false; } if(args[2].equalsIgnoreCase("miniwargear")) { + if(dimensions.getBlockX() <= Config.MiniWarGearBreite && dimensions.getBlockY() <= Config.MiniWarGearHöhe && dimensions.getBlockZ() <= Config.MiniWarGearTiefe && checkSchematic(clipboard, Config.MiniWarGearForbiddenIds, true, true, "MiniWarGear")) { + schematic.setSchemType(SchematicType.miniwargear); + player.sendMessage(SchematicSystem.PREFIX + "Schematic Type §6miniwargear §7angefordert!"); + } return false; } if(args[2].equalsIgnoreCase("wargear")) { + if(dimensions.getBlockX() <= Config.WarGearBreite && dimensions.getBlockY() <= Config.WarGearHöhe && dimensions.getBlockZ() <= Config.WarGearTiefe && checkSchematic(clipboard, Config.WarGearForbiddenIds, true, true, "WarGear")) { + schematic.setSchemType(SchematicType.wargear); + player.sendMessage(SchematicSystem.PREFIX + "Schematic Type §6wargear §7angefordert!"); + } return false; } - if(args[2].equalsIgnoreCase("warships")) { + if(args[2].equalsIgnoreCase("warship")) { + if(dimensions.getBlockX() <= Config.WarShipBreite && dimensions.getBlockY() <= Config.WarShipHöhe && dimensions.getBlockZ() <= Config.WarShipTiefe && checkSchematic(clipboard, Config.WarShipForbiddenIds, true, true, "WarShip")) { + schematic.setSchemType(SchematicType.warship); + player.sendMessage(SchematicSystem.PREFIX + "Schematic Type §6warship §7angefordert!"); + } return false; } @@ -415,7 +448,7 @@ public class SchematicCommand implements CommandExecutor { player.sendMessage("§8/schem list - §6Listet deine Schematics auf"); player.sendMessage("§8/schem load [Besitzer] - §6Du lädst eine Schematic"); player.sendMessage("§8/schem save - §6Du speicherst dein Clipboard als Datei"); - //Kommt später --> player.sendMessage("§8/schem changetype - §6Ändert den Typ deiner Schematic"); + player.sendMessage("§8/schem changetype - §6Ändert den Typ deiner Schematic"); player.sendMessage("§8/schem info - §6Zeigt dir Informationen zu der Schematic"); player.sendMessage("§8/schem delete - §6Löscht eine Schematic"); player.sendMessage("§8/schem addmember - §6Fügt einen Spieler zu einer Schematic hinzu"); @@ -530,4 +563,62 @@ public class SchematicCommand implements CommandExecutor { } else return true; } + + private boolean checkSchematic(Clipboard clipboard, List forbiddenBlocks, boolean obsidianToTnt, boolean slimeToBedrock, String modus) { + Region region = clipboard.getRegion(); + Vector min = region.getMinimumPoint(); + Vector max = region.getMaximumPoint(); + + int obsidian = 0; + int bedrock = 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++) { + Vector vector = new Vector(x, y, z); + if (forbiddenBlocks.contains(clipboard.getBlock(vector).getId())) { + return false; + } + + try { + if(obsidianToTnt && clipboard.getBlock(vector).getId() == 46) { + clipboard.setBlock(vector, new BaseBlock(49)); + obsidian++; + } + if(slimeToBedrock && clipboard.getBlock(vector).getId() == 165) { + clipboard.setBlock(vector, new BaseBlock(7)); + bedrock++; + } + } catch (WorldEditException ex) { + return false; + } + } + } + } + if(modus.equalsIgnoreCase("WarGear")) { + if(Config.WarGearMaxObsidian < obsidian) + return false; + if(Config.WarGearMaxBedrock < bedrock) + return false; + } + if(modus.equalsIgnoreCase("MiniWarGear")) { + if(Config.MiniWarGearMaxObsidian < obsidian) + return false; + if(Config.MiniWarGearMaxBedrock < bedrock) + return false; + } + if(modus.equalsIgnoreCase("WarShip")) { + if(Config.WarShipMaxObsidian < obsidian) + return false; + if(Config.MiniWarGearMaxBedrock < bedrock) + return false; + } + if(modus.equalsIgnoreCase("AirShip")) { + if(Config.AirShipMaxObsidian < obsidian) + return false; + if(Config.MiniWarGearMaxBedrock < bedrock) + return false; + } + return true; + } } diff --git a/src/de/warking/schematicsystem/listener/PlayerJoinListener.java b/src/de/warking/schematicsystem/listener/PlayerJoinListener.java index f0b7308..d19def5 100644 --- a/src/de/warking/schematicsystem/listener/PlayerJoinListener.java +++ b/src/de/warking/schematicsystem/listener/PlayerJoinListener.java @@ -2,6 +2,7 @@ package de.warking.schematicsystem.listener; import de.warking.hunjy.MySQL.Schematic; import de.warking.hunjy.MySQL.SchematicType; +import de.warking.hunjy.MySQL.WarkingUser; import de.warking.schematicsystem.SchematicSystem; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -9,6 +10,8 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import java.io.File; +import java.util.ArrayList; +import java.util.List; public class PlayerJoinListener implements Listener { @@ -19,9 +22,17 @@ public class PlayerJoinListener implements Listener { File[] files = file.listFiles(); if(files == null || files.length == 0) return; + List schematics = Schematic.getSchemsAccessibleByUser(player.getUniqueId()); + List schematicNames = new ArrayList<>(); + + for(Schematic schematic : schematics) { + if(schematic.getSchemOwner() == WarkingUser.get(player.getUniqueId()).getId()) { + schematicNames.add(schematic.getSchemName()); + } + } for(int i = 0; i < files.length; i++) { - if(Schematic.getSchemFromDB(files[i].getName().substring(0, files[i].getName().lastIndexOf(".")), player.getUniqueId()) == null) { + if(!schematicNames.contains(files[i].getName().substring(0, files[i].getName().lastIndexOf(".")))) { String fileName = files[i].getName(); Schematic schematic = new Schematic(fileName.substring(0, fileName.lastIndexOf(".")), player.getUniqueId(), "", SchematicType.normal); } diff --git a/src/de/warking/schematicsystem/utils/Config.java b/src/de/warking/schematicsystem/utils/Config.java new file mode 100644 index 0000000..45926c9 --- /dev/null +++ b/src/de/warking/schematicsystem/utils/Config.java @@ -0,0 +1,75 @@ +package de.warking.schematicsystem.utils; + +import de.warking.schematicsystem.SchematicSystem; +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.FileConfiguration; + +import java.io.File; +import java.util.List; + +public class Config { + + public static double WarGearBreite; + public static double WarGearHöhe; + public static double WarGearTiefe; + public static int WarGearMaxObsidian; + public static int WarGearMaxBedrock; + public static List WarGearForbiddenIds; + + public static double MiniWarGearBreite; + public static double MiniWarGearHöhe; + public static double MiniWarGearTiefe; + public static int MiniWarGearMaxObsidian; + public static int MiniWarGearMaxBedrock; + public static List MiniWarGearForbiddenIds; + + public static double WarShipBreite; + public static double WarShipHöhe; + public static double WarShipTiefe; + public static int WarShipMaxObsidian; + public static int WarShipMaxBedrock; + public static List WarShipForbiddenIds; + + public static double AirShipBreite; + public static double AirShipHöhe; + public static double AirShipTiefe; + public static int AirShipMaxObsidian; + public static int AirShipMaxBedrock; + public static List AirShipForbiddenIds; + + public static void load() { + if (!new File("plugins/" + SchematicSystem.getInstance().getName() + "/config.yml").exists()) { + SchematicSystem.getInstance().saveDefaultConfig(); + System.out.println(SchematicSystem.PREFIX + "config.yml erstellt und geladen!"); + Bukkit.shutdown(); + } + FileConfiguration config = SchematicSystem.getInstance().getConfig(); + + WarGearBreite = config.getDouble("Schematics.WarGear.Breite"); + WarGearHöhe = config.getDouble("Schematics.WarGear.Höhe"); + WarGearTiefe = config.getDouble("Schematics.WarGear.Tiefe"); + WarGearMaxObsidian = config.getInt("Schematics.WarGear.Obsidian"); + WarGearMaxBedrock = config.getInt("Schematics.WarGear.Bedrock"); + WarGearForbiddenIds = config.getIntegerList("Schematics.WarGear.ForbiddenIds"); + + MiniWarGearBreite = config.getDouble("Schematics.MiniWarGear.Breite"); + MiniWarGearHöhe = config.getDouble("Schematics.MiniWarGear.Höhe"); + MiniWarGearTiefe = config.getDouble("Schematics.MiniWarGear.Tiefe"); + MiniWarGearMaxObsidian = config.getInt("Schematics.MiniWarGear.Obsidian"); + MiniWarGearForbiddenIds = config.getIntegerList("Schematics.MiniWarGear.Bedrock"); + + WarShipBreite = config.getDouble("Schematics.WarShip.Breite"); + WarShipHöhe = config.getDouble("Schematics.WarShip.Höhe"); + WarShipTiefe = config.getDouble("Schematics.WarShip.Tiefe"); + WarShipMaxObsidian = config.getInt("Schematics.WarShip.Obsidian"); + WarShipMaxBedrock = config.getInt("Schematics.WarShip.Bedrock"); + WarShipForbiddenIds = config.getIntegerList("Schematics.WarShip.ForbiddenIds"); + + AirShipBreite = config.getDouble("Schematics.AirShip.Breite"); + AirShipHöhe = config.getDouble("Schematics.AirShip.Höhe"); + AirShipTiefe = config.getDouble("Schematics.AirShip.Tiefe"); + AirShipMaxObsidian = config.getInt("Schematics.AirShip.Obsidian"); + AirShipMaxBedrock = config.getInt("Schematics.AirShip.Bedrock"); + AirShipForbiddenIds = config.getIntegerList("Schematics.AirShip.ForbiddenIds"); + } +}