diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandLockschem.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandLockschem.java index 08a4f57..77b1233 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandLockschem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandLockschem.java @@ -21,12 +21,14 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.command.SWCommand; -import de.steamwar.sql.Schematic; +import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserGroup; import org.bukkit.entity.Player; +import java.util.Optional; + public class CommandLockschem extends SWCommand { public CommandLockschem() { @@ -65,15 +67,16 @@ public class CommandLockschem extends SWCommand { p.sendMessage(BauSystem.PREFIX + "Dieser Spieler existiert nicht!"); return; } - Schematic schematic = Schematic.getSchemFromDB(schematicName, schemOwner.getUUID()); - if (schematic == null) { + Optional schematicOpt = SchematicNode.deepGet(schemOwner.getId(), node -> !node.getSchemtype().equals(SchematicType.Normal)).stream().findAny(); + if (!schematicOpt.isPresent()) { p.sendMessage(BauSystem.PREFIX + "Dieser Spieler besitzt keine Schematic mit diesem Namen!"); return; } - p.sendMessage(BauSystem.PREFIX + "Schematic " + schematic.getSchemName() + " von " + - SteamwarUser.get(schematic.getSchemOwner()).getUserName() + " von " + schematic.getSchemType().toString() + + SchematicNode node = schematicOpt.get(); + p.sendMessage(BauSystem.PREFIX + "Schematic " + node .getName() + " von " + + SteamwarUser.get(node.getOwner()).getUserName() + " von " + node.getSchemtype().toString() + " auf NORMAL zurückgesetzt!"); - schematic.setSchemType(SchematicType.Normal); + node.setSchemtype(SchematicType.Normal); } private void sendHelp(Player player) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java index d147462..f97d18e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java @@ -24,7 +24,8 @@ import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.Welt; import de.steamwar.bausystem.world.regions.Region; import de.steamwar.command.SWCommand; -import de.steamwar.sql.Schematic; +import de.steamwar.sql.SchematicNode; +import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -81,7 +82,8 @@ public class CommandProtect extends SWCommand implements Listener { } Region region = regionCheck(p); if (region == null) return; - Schematic schem = Schematic.getSchemFromDB(s, p.getUniqueId()); + SteamwarUser owner = SteamwarUser.get(p.getUniqueId()); + SchematicNode schem = SchematicNode.getNodeFromPath(owner, s); if (schem == null) { p.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden"); return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRegion.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRegion.java index 8dfca32..2efb478 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRegion.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRegion.java @@ -9,7 +9,7 @@ import de.steamwar.bausystem.world.regions.Region; import de.steamwar.bausystem.world.regions.RegionExtensionType; import de.steamwar.bausystem.world.regions.RegionType; import de.steamwar.command.SWCommand; -import de.steamwar.sql.Schematic; +import de.steamwar.sql.SchematicNode; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -94,17 +94,12 @@ public class CommandRegion extends SWCommand { } @Register("restore") - public void schematicRestoreCommand(Player p, String s) { + public void schematicRestoreCommand(Player p, SchematicNode schem) { if (!permissionCheck(p)) return; Region region = Region.getRegion(p.getLocation()); if(checkGlobalRegion(region, p)) return; if (region == null) return; - Schematic schem = Schematic.getSchemFromDB(s, p.getUniqueId()); - if (schem == null) { - p.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden"); - return; - } try { region.reset(schem, true); p.sendMessage(BauSystem.PREFIX + "§7Region zurückgesetzt"); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java index fdc540a..4ec404e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java @@ -25,7 +25,7 @@ import de.steamwar.bausystem.world.Welt; import de.steamwar.bausystem.world.regions.GlobalRegion; import de.steamwar.bausystem.world.regions.Region; import de.steamwar.command.SWCommand; -import de.steamwar.sql.Schematic; +import de.steamwar.sql.SchematicNode; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -59,15 +59,10 @@ public class CommandReset extends SWCommand { } @Register - public void schematicResetCommand(Player p, String s) { + public void schematicResetCommand(Player p, SchematicNode schem) { if (!permissionCheck(p)) return; Region region = regionCheck(p); if (region == null) return; - Schematic schem = Schematic.getSchemFromDB(s, p.getUniqueId()); - if (schem == null) { - p.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden"); - return; - } try { region.reset(schem, false); p.sendMessage(BauSystem.PREFIX + "§7Region zurückgesetzt"); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java index 9a37080..ec206fa 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java @@ -28,7 +28,8 @@ import de.steamwar.bausystem.world.regions.RegionExtensionType; import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; -import de.steamwar.sql.Schematic; +import de.steamwar.sql.SchematicNode; +import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -73,25 +74,20 @@ public class CommandTestblock extends SWCommand { @Register - public void schematicTestblockCommand(Player p, String s) { - schematicTestblockCommand(p, s, RegionExtensionType.NORMAL); + public void schematicTestblockCommand(Player p, SchematicNode schem) { + schematicTestblockCommand(p, schem, RegionExtensionType.NORMAL); } @Register - public void schematicTestblockCommand(Player p, RegionExtensionType regionExtensionType, String s) { - schematicTestblockCommand(p, s, regionExtensionType); + public void schematicTestblockCommand(Player p, RegionExtensionType regionExtensionType, SchematicNode schem) { + schematicTestblockCommand(p, schem, regionExtensionType); } @Register - public void schematicTestblockCommand(Player p, String s, RegionExtensionType regionExtensionType) { + public void schematicTestblockCommand(Player p, SchematicNode schem, RegionExtensionType regionExtensionType) { if (!permissionCheck(p)) return; Region region = regionCheck(p); if (region == null) return; - Schematic schem = Schematic.getSchemFromDB(s, p.getUniqueId()); - if (schem == null) { - p.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden"); - return; - } try { region.resetTestblock(schem, regionExtensionType == RegionExtensionType.EXTENSION); p.sendMessage(BauSystem.PREFIX + "§7Testblock zurückgesetzt"); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ClipboardListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ClipboardListener.java index 72aaebb..6ecdc76 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ClipboardListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ClipboardListener.java @@ -19,15 +19,13 @@ package de.steamwar.bausystem.world; -import de.steamwar.sql.Schematic; -import de.steamwar.sql.SchematicType; +import de.steamwar.sql.SchematicNode; +import de.steamwar.sql.SteamwarUser; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; -import java.util.UUID; - public class ClipboardListener implements Listener { private static final String CLIPBOARD_SCHEMNAME = "//copy"; @@ -35,31 +33,30 @@ public class ClipboardListener implements Listener { @EventHandler public void onLogin(PlayerJoinEvent e) { try { - Schematic schematic = Schematic.getSchemFromDB(CLIPBOARD_SCHEMNAME, e.getPlayer().getUniqueId()); + SchematicNode schematic = SchematicNode.getSchematicNode(SteamwarUser.get(e.getPlayer().getUniqueId()).getId(), CLIPBOARD_SCHEMNAME, 0); if (schematic != null) { schematic.loadToPlayer(e.getPlayer()); } } catch (Exception ex) { - //ignore cause players do all kind of stuff with schematics.... like massively oversized schems + // ignore cause players do all kind of stuff with schematics.... like massively oversized schems } } @EventHandler public void onLogout(PlayerQuitEvent e) { - UUID playerUUID = e.getPlayer().getUniqueId(); - Schematic schematic = Schematic.getSchemFromDB(CLIPBOARD_SCHEMNAME, playerUUID); + SchematicNode schematic = SchematicNode.getSchematicNode(SteamwarUser.get(e.getPlayer().getUniqueId()).getId(), CLIPBOARD_SCHEMNAME, 0); boolean newSchem = false; if (schematic == null) { - Schematic.createSchem(CLIPBOARD_SCHEMNAME, playerUUID, "", SchematicType.Normal); - schematic = Schematic.getSchemFromDB(CLIPBOARD_SCHEMNAME, playerUUID); + schematic = SchematicNode.createSchematic(SteamwarUser.get(e.getPlayer().getUniqueId()).getId(), CLIPBOARD_SCHEMNAME, 0); newSchem = true; } try { schematic.saveFromPlayer(e.getPlayer()); } catch (Exception ex) { - if (newSchem) - schematic.remove(); + if (newSchem) { + schematic.delete(); + } } } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Prototype.java b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Prototype.java index 790d64a..65f59dc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Prototype.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Prototype.java @@ -24,7 +24,7 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.bausystem.WorldeditWrapper; import de.steamwar.bausystem.world.Color; import de.steamwar.sql.NoClipboardException; -import de.steamwar.sql.Schematic; +import de.steamwar.sql.SchematicNode; import org.bukkit.Location; import org.bukkit.configuration.ConfigurationSection; @@ -144,16 +144,16 @@ public class Prototype { } } - public EditSession reset(Region region, Schematic schem, boolean ignoreAir, Color color) throws IOException, NoClipboardException { + public EditSession reset(Region region, SchematicNode schem, boolean ignoreAir, Color color) throws IOException, NoClipboardException { return reset(region, schem, ignoreAir, color, false); } - public EditSession reset(Region region, Schematic schem, boolean ignoreAir, Color color, boolean reset) throws IOException, NoClipboardException { + public EditSession reset(Region region, SchematicNode schem, boolean ignoreAir, Color color, boolean reset) throws IOException, NoClipboardException { PasteOptions pasteOptions; if (reset) { - pasteOptions = new PasteOptions(rotate ^ (schem != null && (schem.getSchemType().fightType() || schem.getSchemType().check())), ignoreAir, color, true, getMinPoint(region, RegionExtensionType.EXTENSION), getMaxPoint(region, RegionExtensionType.EXTENSION), waterLevel); + pasteOptions = new PasteOptions(rotate ^ (schem != null && (schem.getSchemtype().fightType() || schem.getSchemtype().check())), ignoreAir, color, true, getMinPoint(region, RegionExtensionType.EXTENSION), getMaxPoint(region, RegionExtensionType.EXTENSION), waterLevel); } else { - pasteOptions = new PasteOptions(rotate ^ (schem != null && (schem.getSchemType().fightType() || schem.getSchemType().check())), ignoreAir, color); + pasteOptions = new PasteOptions(rotate ^ (schem != null && (schem.getSchemtype().fightType() || schem.getSchemtype().check())), ignoreAir, color); } int x = region.minPoint.getX() + offsetX + sizeX / 2; @@ -170,7 +170,7 @@ public class Prototype { return protectSchematic != null; } - public EditSession protect(Region region, Schematic schem) throws IOException, NoClipboardException { + public EditSession protect(Region region, SchematicNode schem) throws IOException, NoClipboardException { int x = region.minPoint.getX() + offsetX + sizeX / 2; int y = region.minPoint.getY() + testblock.offsetY - 1; int z = region.minPoint.getZ() + offsetZ + sizeZ / 2; @@ -185,7 +185,7 @@ public class Prototype { return testblock != null; } - public EditSession resetTestblock(Region region, Schematic schem, Color color, boolean reset) throws IOException, NoClipboardException { + public EditSession resetTestblock(Region region, SchematicNode schem, Color color, boolean reset) throws IOException, NoClipboardException { return testblock.reset(region, schem, false, color, reset && waterLevel == 0); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java index d9860f3..7b10d91 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java @@ -28,7 +28,7 @@ import de.steamwar.bausystem.commands.CommandTNT.TNTMode; import de.steamwar.bausystem.world.Color; import de.steamwar.bausystem.world.SizedStack; import de.steamwar.sql.NoClipboardException; -import de.steamwar.sql.Schematic; +import de.steamwar.sql.SchematicNode; import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -303,7 +303,7 @@ public class Region { return prototype.buildArea != null; } - public void reset(Schematic schem, boolean ignoreAir) throws IOException, NoClipboardException { + public void reset(SchematicNode schem, boolean ignoreAir) throws IOException, NoClipboardException { initSessions(); undosessions.push(prototype.reset(this, schem, ignoreAir, color)); } @@ -312,7 +312,7 @@ public class Region { return prototype.hasTestblock(); } - public void resetTestblock(Schematic schem, boolean reset) throws IOException, NoClipboardException { + public void resetTestblock(SchematicNode schem, boolean reset) throws IOException, NoClipboardException { initSessions(); undosessions.push(prototype.resetTestblock(this, schem, color, reset)); } @@ -321,7 +321,7 @@ public class Region { return prototype.hasProtection(); } - public void protect(Schematic schem) throws IOException, NoClipboardException { + public void protect(SchematicNode schem) throws IOException, NoClipboardException { initSessions(); undosessions.push(prototype.protect(this, schem)); }