From 85d8675b4ca775753032fdebeb5a5087389a0281 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 21 Nov 2021 10:37:44 +0100 Subject: [PATCH] Changing to SchematicNodes (Requires SchematicSystem) --- .../fightsystem/utils/WorldeditWrapper14.java | 4 ++-- .../fightsystem/utils/WorldeditWrapper8.java | 4 ++-- .../de/steamwar/fightsystem/FightSystem.java | 6 ++--- .../de/steamwar/fightsystem/commands/GUI.java | 23 ++++++------------- .../commands/LockschemCommand.java | 4 ++-- .../fightsystem/fight/FightSchematic.java | 10 ++++---- .../steamwar/fightsystem/fight/FightTeam.java | 11 +++++---- .../steamwar/fightsystem/listener/Check.java | 6 ++--- .../fightsystem/listener/PrepareSchem.java | 8 +++---- .../fightsystem/record/PacketProcessor.java | 6 ++--- .../steamwar/fightsystem/record/Recorder.java | 4 ++-- .../fightsystem/utils/FightStatistics.java | 6 ++--- .../fightsystem/utils/WorldeditWrapper.java | 4 ++-- pom.xml | 7 ++++++ 14 files changed, 51 insertions(+), 52 deletions(-) diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java index fe5bc06..402c587 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java @@ -41,7 +41,7 @@ import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockTypes; import de.steamwar.fightsystem.FightSystem; -import de.steamwar.sql.Schematic; +import de.steamwar.sql.SchematicNode; import org.bukkit.Bukkit; import org.bukkit.DyeColor; import org.bukkit.Location; @@ -122,7 +122,7 @@ public class WorldeditWrapper14 implements WorldeditWrapper.IWorldeditWrapper { } @Override - public void saveSchem(Schematic schem, Region region, int minY) throws WorldEditException { + public void saveSchem(SchematicNode schem, Region region, int minY) throws WorldEditException { World w = new BukkitWorld(Bukkit.getWorlds().get(0)); BlockVector3 min = BlockVector3.at(region.getMinX(), minY, region.getMinZ()); CuboidRegion cuboidRegion = new CuboidRegion(w, min, BlockVector3.at(region.getMaxX(), region.getMaxY(), region.getMaxZ()).subtract(BlockVector3.ONE)); diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java index a4856bb..3d7fb2a 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java @@ -38,7 +38,7 @@ import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; import de.steamwar.fightsystem.FightSystem; -import de.steamwar.sql.Schematic; +import de.steamwar.sql.SchematicNode; import org.bukkit.Bukkit; import org.bukkit.DyeColor; import org.bukkit.Location; @@ -121,7 +121,7 @@ public class WorldeditWrapper8 implements WorldeditWrapper.IWorldeditWrapper { } @Override - public void saveSchem(Schematic schem, Region region, int minY) throws WorldEditException { + public void saveSchem(SchematicNode schem, Region region, int minY) throws WorldEditException { World w = new BukkitWorld(Bukkit.getWorlds().get(0)); Vector min = new Vector(region.getMinX(), minY, region.getMinZ()); CuboidRegion cuboidRegion = new CuboidRegion(w, min, new Vector(region.getMaxX(), region.getMaxY(), region.getMaxZ()).subtract(Vector.ONE)); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 1ef5115..254a67e 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -33,7 +33,7 @@ import de.steamwar.fightsystem.utils.*; import de.steamwar.fightsystem.winconditions.*; import de.steamwar.message.Message; import de.steamwar.sql.EventFight; -import de.steamwar.sql.Schematic; +import de.steamwar.sql.SchematicNode; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; @@ -140,9 +140,9 @@ public class FightSystem extends JavaPlugin { if(Config.mode == ArenaMode.EVENT) { setPreSchemState(); }else if(Config.mode == ArenaMode.CHECK){ - Fight.getBlueTeam().setSchem(Schematic.getSchemFromDB(Config.CheckSchemID)); + Fight.getBlueTeam().setSchem(SchematicNode.getSchematicNode(Config.CheckSchemID)); }else if(Config.mode == ArenaMode.PREPARE) { - Fight.getUnrotated().setSchem(Schematic.getSchemFromDB(Config.PrepareSchemID)); + Fight.getUnrotated().setSchem(SchematicNode.getSchematicNode(Config.PrepareSchemID)); }else if(Config.mode == ArenaMode.REPLAY) { FightWorld.forceLoad(); FileSource.startReplay(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java index bd9794e..1d1713a 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java @@ -32,8 +32,9 @@ import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; import de.steamwar.message.Message; +import de.steamwar.schematicsystem.util.SchematicSelector; import de.steamwar.sql.PersonalKit; -import de.steamwar.sql.Schematic; +import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.api.ChatMessageType; import org.bukkit.Bukkit; @@ -173,7 +174,7 @@ public class GUI { }); if(Fight.getMaxRank() == 0){ inv.setItem(0, SWItem.getDye(8), (byte)8, msg.parse("SCHEM_PRIVATE_FORBIDDEN", p, Config.GameName), (ClickType click)->{}); - }else if(Schematic.getSchemsOfType(p.getUniqueId(), Config.SchematicType).isEmpty() && !Config.test()){ + }else if(SchematicNode.getAllAccessibleSchematicsOfType(SteamwarUser.get(p.getUniqueId()).getId(), Config.SchematicType.toDB()).isEmpty() && !Config.test()){ inv.setItem(0, SWItem.getDye(8), (byte)8, msg.parse("SCHEM_NO_PRIVATE", p, Config.GameName), (ClickType click)->{}); }else{ inv.setItem(0, SWItem.getMaterial("CAULDRON_ITEM"), msg.parse("SCHEM_PRIVATE", p, Config.GameName), (ClickType click) -> { @@ -186,25 +187,15 @@ public class GUI { } private static void schemDialog(Player p, boolean publicSchems){ - List> schems; - if(publicSchems) - schems = SWListInv.getSchemList(Config.SchematicType, 0); - else if(Config.test()) - schems = SWListInv.getSchemList(null, SteamwarUser.get(p.getUniqueId()).getId()); - else{ - schems = SWListInv.getSchemList(Config.SchematicType, SteamwarUser.get(p.getUniqueId()).getId()); - schems.removeIf(schem -> schem.getObject().getRank() > Fight.getMaxRank()); - } - - SWListInv inv = new SWListInv<>(p, msg.parse("SCHEM_TITLE", p, Config.GameName), schems, (ClickType click, Schematic s) -> { + SchematicSelector selector = new SchematicSelector(p, SchematicSelector.selectSchematicType(Config.SchematicType), node -> { FightTeam fightTeam = Fight.getPlayerTeam(p); if(fightTeam == null) return; if(Config.test() || FightState.getFightState() != FightState.POST_SCHEM_SETUP) - fightTeam.pasteSchem(s); + fightTeam.pasteSchem(node); p.closeInventory(); }); - inv.setCallback(-999, (ClickType click) -> p.closeInventory()); - inv.open(); + selector.setPublicMode(publicSchems?SchematicSelector.PublicMode.PUBLIC_ONLY:SchematicSelector.PublicMode.PRIVATE_ONLY); + selector.open(); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/LockschemCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/LockschemCommand.java index 9e7fff3..1780470 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/LockschemCommand.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/LockschemCommand.java @@ -25,7 +25,7 @@ import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentCommand; -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; @@ -67,7 +67,7 @@ public class LockschemCommand implements CommandExecutor { return false; } - Schematic.getSchemFromDB(fightTeam.getSchematic()).setSchemType(SchematicType.Normal); + SchematicNode.getSchematicNode(fightTeam.getSchematic()).setType(SchematicType.Normal.toDB()); FightSystem.getMessage().sendPrefixless("LOCKSCHEM_LOCKED", player, ChatMessageType.ACTION_BAR); fightTeam.broadcastSystem("LOCKSCHEM_LOCKED_BY", player.getName()); return false; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index 0d7643d..ce4dc0e 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -31,7 +31,7 @@ import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.utils.ColorConverter; import de.steamwar.fightsystem.utils.Region; import de.steamwar.fightsystem.utils.WorldeditWrapper; -import de.steamwar.sql.Schematic; +import de.steamwar.sql.SchematicNode; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.event.HandlerList; @@ -67,13 +67,13 @@ public class FightSchematic extends StateDependent { return schematic; } - public void setSchematic(Schematic schem) { - schematic = schem.getSchemID(); + public void setSchematic(SchematicNode schem) { + schematic = schem.getId(); try { clipboard = schem.load(); } catch (IOException e) { team.broadcastSystem("SCHEMATIC_UNLOADABLE"); - Bukkit.getLogger().log(Level.SEVERE, e, () -> "Couldn't load Schematic " + schem.getSchemName()); + Bukkit.getLogger().log(Level.SEVERE, e, () -> "Couldn't load Schematic " + schem.getName()); } } @@ -93,7 +93,7 @@ public class FightSchematic extends StateDependent { return; if(clipboard == null){ - List publics = Schematic.getSchemsOfType(0, Config.SchematicType); + List publics = SchematicNode.getAllSchematicsOfType(0, Config.SchematicType.toDB()); if(publics.isEmpty()) return; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 83bcffa..f88a616 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -32,7 +32,8 @@ import de.steamwar.fightsystem.states.OneShotStateDependent; import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.utils.*; import de.steamwar.inventory.SWItem; -import de.steamwar.sql.Schematic; +import de.steamwar.sql.SchematicNode; +import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.api.ChatMessageType; import org.bukkit.*; import org.bukkit.enchantments.Enchantment; @@ -281,7 +282,7 @@ public class FightTeam { if(!silent) FightUI.addSubtitle("UI_LEADER_JOINS", prefix, leader.getPlayer().getName()); - Optional maxRank = Schematic.getSchemsOfType(leader.getPlayer().getUniqueId(), Config.SchematicType).stream().map(Schematic::getRank).max(Integer::compare); + Optional maxRank = SchematicNode.getAllAccessibleSchematicsOfType(SteamwarUser.get(leader.getPlayer().getUniqueId()).getId(), Config.SchematicType.toDB()).stream().map(SchematicNode::getRank).max(Integer::compare); if(Config.RanksEnabled) schemRank = maxRank.orElse(1); else @@ -320,7 +321,7 @@ public class FightTeam { return ready; } - public void pasteSchem(Schematic schematic){ + public void pasteSchem(SchematicNode schematic){ setSchem(schematic); testPasteAction(); } @@ -342,9 +343,9 @@ public class FightTeam { schematic.pasteTeamName(); } - public void setSchem(Schematic schematic){ + public void setSchem(SchematicNode schematic){ this.schematic.setSchematic(schematic); - broadcast("SCHEMATIC_CHOSEN", Config.GameName, schematic.getSchemName()); + broadcast("SCHEMATIC_CHOSEN", Config.GameName, schematic.getName()); } public void setReady(boolean ready) { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Check.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Check.java index a12b187..a33d52c 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Check.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Check.java @@ -24,7 +24,7 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; -import de.steamwar.sql.Schematic; +import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserGroup; import org.bukkit.Bukkit; @@ -50,8 +50,8 @@ public class Check implements Listener { if(allowedToCheck(user)) return; - Schematic schem = Schematic.getSchemFromDB(Config.CheckSchemID); - if(user.getId() == schem.getSchemOwner()) + SchematicNode schem = SchematicNode.getSchematicNode(Config.CheckSchemID); + if(user.getId() == schem.getOwner()) return; FightSystem.getMessage().send("CHECK_JOIN_DENIED", player); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java index 8efd4ad..e90d823 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java @@ -30,7 +30,7 @@ import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.utils.FlatteningWrapper; import de.steamwar.fightsystem.utils.Region; import de.steamwar.fightsystem.utils.WorldeditWrapper; -import de.steamwar.sql.Schematic; +import de.steamwar.sql.SchematicNode; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.Player; @@ -49,9 +49,9 @@ public class PrepareSchem implements Listener { Region region = Fight.getUnrotated().getExtendRegion(); int minY = Fight.getUnrotated().getSchemRegion().getMinY(); - Schematic schem; + SchematicNode schem; try{ - schem = Schematic.getSchemFromDB(Config.PrepareSchemID); + schem = SchematicNode.getSchematicNode(Config.PrepareSchemID); }catch(SecurityException e){ FightSystem.getMessage().broadcast("PREPARE_SCHEM_DELETED"); Bukkit.shutdown(); @@ -78,7 +78,7 @@ public class PrepareSchem implements Listener { throw new SecurityException("Could not save schem", e); } - schem.setSchemType(Config.SchematicType.checkType()); + schem.setType(Config.SchematicType.checkType().toDB()); FightSystem.getMessage().broadcast("PREPARE_SENT_IN"); Bukkit.shutdown(); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index 23e937a..73be48d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -32,7 +32,7 @@ import de.steamwar.fightsystem.fight.FreezeWorld; import de.steamwar.fightsystem.listener.FightScoreboard; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.utils.*; -import de.steamwar.sql.Schematic; +import de.steamwar.sql.SchematicNode; import de.steamwar.sql.Team; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.BaseComponent; @@ -374,12 +374,12 @@ public class PacketProcessor { private void pasteSchem(FightTeam team) throws IOException { int schemId = source.readInt(); - execSync(() -> team.pasteSchem(Schematic.getSchemFromDB(schemId))); + execSync(() -> team.pasteSchem(SchematicNode.getSchematicNode(schemId))); } private void pasteEmbeddedSchem(FightTeam team) throws IOException { int schemId = source.readInt(); - Clipboard clipboard = Schematic.clipboardFromStream(source, Core.getVersion() > 12); + Clipboard clipboard = SchematicNode.clipboardFromStream(source, Core.getVersion() > 12); execSync(() -> team.pasteSchem(schemId, clipboard)); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java index e4e4ee0..a654108 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java @@ -29,7 +29,7 @@ import de.steamwar.fightsystem.utils.BlockIdWrapper; import de.steamwar.fightsystem.utils.CraftbukkitWrapper; import de.steamwar.fightsystem.utils.Message; import de.steamwar.fightsystem.utils.SWSound; -import de.steamwar.sql.Schematic; +import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -275,7 +275,7 @@ public interface Recorder { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); try{ - copy(Schematic.getSchemFromDB(schemId).schemData(), buffer); + copy(SchematicNode.getSchematicNode(schemId).schemData(), buffer); }catch (EOFException e) { Bukkit.getLogger().log(Level.INFO, "EOFException ignored"); } catch (IOException e) { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java index 25bef85..09ef089 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -31,7 +31,7 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.OneShotStateDependent; import de.steamwar.fightsystem.winconditions.Wincondition; import de.steamwar.sql.Elo; -import de.steamwar.sql.Schematic; +import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; @@ -91,12 +91,12 @@ public class FightStatistics { Integer blueSchem; Integer redSchem; try{ - blueSchem = Schematic.getSchemFromDB(Fight.getBlueTeam().getSchematic()).getSchemID(); + blueSchem = SchematicNode.getSchematicNode(Fight.getBlueTeam().getSchematic()).getId(); }catch(SecurityException e){ blueSchem = null; } try{ - redSchem = Schematic.getSchemFromDB(Fight.getRedTeam().getSchematic()).getSchemID(); + redSchem = SchematicNode.getSchematicNode(Fight.getRedTeam().getSchematic()).getId(); }catch(SecurityException e){ redSchem = null; } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java index 35f3d37..4f19e69 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java @@ -24,7 +24,7 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.math.transform.AffineTransform; import de.steamwar.core.VersionDependent; import de.steamwar.fightsystem.FightSystem; -import de.steamwar.sql.Schematic; +import de.steamwar.sql.SchematicNode; import org.bukkit.DyeColor; import org.bukkit.Location; import org.bukkit.util.Vector; @@ -42,6 +42,6 @@ public class WorldeditWrapper { void pasteClipboard(Clipboard clipboard, Location position, Vector offset, AffineTransform aT); Vector getDimensions(Clipboard clipboard); Clipboard loadChar(String charName) throws IOException; - void saveSchem(Schematic schem, Region region, int minY) throws WorldEditException; + void saveSchem(SchematicNode schem, Region region, int minY) throws WorldEditException; } } diff --git a/pom.xml b/pom.xml index 35a72ae..4056ded 100644 --- a/pom.xml +++ b/pom.xml @@ -69,6 +69,13 @@ system ${main.basedir}/lib/SpigotCore.jar + + steamwar + SchematicSystem + 1.0 + system + ${main.basedir}/lib/SchematicSystem.jar +