diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java b/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java index 8d8cdc8..5f35f55 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java @@ -19,7 +19,6 @@ package de.steamwar.inventory; -import de.steamwar.sql.Schematic; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; import org.bukkit.Bukkit; @@ -116,34 +115,12 @@ public class SWListInv extends SWInventory { return onlinePlayers; } - public static List> getSchemList(SchematicType type, int steamwarUserId){ - List> schemList = new ArrayList<>(); - - List schems; - if(type == null) - schems = Schematic.getSchemsAccessibleByUser(steamwarUserId); - else - schems = Schematic.getSchemsOfType(steamwarUserId, type); - - for(Schematic s : schems){ - Material m; - if(s.getItem().isEmpty()) - m = SWItem.getMaterial("CAULDRON_ITEM"); - else - m = SWItem.getMaterial(s.getItem()); - SWItem item = new SWItem(m,"§e" + s.getSchemName()); - item.setEnchanted(s.getSchemType().fightType()); - schemList.add(new SWListEntry<>(item, s)); - } - return schemList; - } - public static List> getSchemnodeList(SchematicType type, int steamwarUserId){ List> schemList = new ArrayList<>(); List schems; if(type == null) - schems = SchematicNode.getSchematicsAccessibleByUser(steamwarUserId, 0); + schems = SchematicNode.filterSchems(steamwarUserId, node -> true); else schems = SchematicNode.getSchematicsOfType(steamwarUserId, type.toDB(), 0); diff --git a/SpigotCore_Main/src/de/steamwar/sql/DownloadSchematic.java b/SpigotCore_Main/src/de/steamwar/sql/DownloadSchematic.java index 0bda812..e941b8d 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/DownloadSchematic.java +++ b/SpigotCore_Main/src/de/steamwar/sql/DownloadSchematic.java @@ -45,8 +45,4 @@ public class DownloadSchematic { SQL.update("INSERT INTO SchemDownload (SchemID, Link) VALUES (?, ?) ON DUPLICATE KEY UPDATE Link = VALUES(Link)", schem.getId(), hash); return BASE + hash; } - - public static String getLink(Schematic schematic) { - return getLink(SchematicNode.getSchematicNode(schematic.getSchemID())); - } } diff --git a/SpigotCore_Main/src/de/steamwar/sql/Schematic.java b/SpigotCore_Main/src/de/steamwar/sql/Schematic.java deleted file mode 100644 index 1439379..0000000 --- a/SpigotCore_Main/src/de/steamwar/sql/Schematic.java +++ /dev/null @@ -1,159 +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.sql; - -import com.sk89q.worldedit.extent.clipboard.Clipboard; -import org.bukkit.entity.Player; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -public class Schematic { - - private SchematicNode node; - - private Schematic(SchematicNode node) { - this.node = node; - } - - public static void createSchem(String schemName, UUID schemOwner, String item, SchematicType schemType){ - createSchem(schemName, SteamwarUser.get(schemOwner).getId(), item, schemType); - } - - public static void createSchem(String schemName, int schemOwner, String item, SchematicType schemType){ - SchematicNode.createSchematicNode(schemOwner, schemName, 0, schemType.toDB(), item); - } - - public static Schematic getSchemFromDB(String schemName, UUID schemOwner){ - return getSchemFromDB(schemName, SteamwarUser.get(schemOwner).getId()); - } - - public static Schematic getSchemFromDB(String schemName, int schemOwner){ - SchematicNode node = SchematicNode.getSchematicNode(schemOwner, schemName, (Integer) null); - if(node == null) - return null; - return new Schematic(node); - } - - public static Schematic getSchemFromDB(int schemID){ - return new Schematic(SchematicNode.getSchematicNode(schemID)); - } - - public static List getSchemsAccessibleByUser(UUID schemOwner){ - return getSchemsAccessibleByUser(SteamwarUser.get(schemOwner).getId()); - } - - public static List getSchemsAccessibleByUser(int schemOwner){ - List nodes = SchematicNode.getSchematicsAccessibleByUser(schemOwner, 0); - List schematics = new ArrayList<>(); - nodes.forEach(node1 -> { - if (!node1.isDir()) schematics.add(new Schematic(node1)); - }); - return schematics; - } - - public static List getSchemsOfType(UUID schemOwner, SchematicType schemType){ - return getSchemsOfType(SteamwarUser.get(schemOwner).getId(), schemType); - } - - public static List getSchemsOfType(int schemOwner, SchematicType schemType){ - //Unsauber, dafür auch geaddede Schematics dabei - List schems = getSchemsAccessibleByUser(schemOwner); - for(int i = schems.size()-1; i >= 0; i--) - if(!schems.get(i).getSchemType().equals(schemType)) - schems.remove(i); - return schems; - } - - public static List getAllSchemsOfType(SchematicType schemType){ - List nodes = SchematicNode.getAllSchematicsOfType(schemType.toDB()); - List schematics = new ArrayList<>(); - nodes.forEach(node1 -> schematics.add(new Schematic(node1))); - return schematics; - } - - public int getSchemID() { - return node.getId(); - } - - public String getSchemName() { - return node.getName(); - } - - public int getSchemOwner() { - return node.getOwner(); - } - - public int getRank(){ - return node.getRank(); - } - - public String getItem() { - return node.getItem(); - } - - public void setItem(String item) { - node.setItem(item); - } - - public void setRank(int rank){ - node.setRank(rank); - } - - public SchematicType getSchemType() { - return node.getSchemtype(); - } - - public void setSchemType(SchematicType schemType) { - node.setType(schemType.toDB()); - } - - public boolean availible(){ - return true; - } - - public Clipboard load() throws IOException, NoClipboardException { - return node.load(); - } - - public void loadToPlayer(Player player) throws IOException, NoClipboardException { - node.loadToPlayer(player); - } - - public void saveOldFormatFromPlayer(Player player) throws IOException, NoClipboardException { - node.saveOldFormatFromPlayer(player); - } - - public void saveFromPlayer(Player player) throws IOException, NoClipboardException { - node.saveFromPlayer(player); - } - - public void saveFromBytes(byte[] bytes, boolean newFormat) { - node.saveFromBytes(bytes, newFormat); - } - - public void remove(){ - node.delete(); - } - - public static class WrongVersionException extends Exception{} -} diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicMember.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicMember.java deleted file mode 100644 index fedd0a6..0000000 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicMember.java +++ /dev/null @@ -1,103 +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.sql; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.UUID; -import java.util.stream.Collectors; - -public class SchematicMember { - - private NodeMember member; - - private SchematicMember(SchematicNode node, int user, boolean updateDB){ - if(updateDB) { - member = NodeMember.createNodeMember(node.getId(), user); - }else { - member = NodeMember.getNodeMember(node.getId(), user); - } - } - - public SchematicMember(String schemName, int schemOwner, int schemMember, boolean updateDb){ - this(SchematicNode.getSchematicNode(schemOwner, schemName, 0), schemMember, updateDb); - } - - public SchematicMember(String schemName, UUID schemOwner, UUID schemMember){ - this(schemName, SteamwarUser.get(schemOwner).getId(), SteamwarUser.get(schemMember).getId(), true); - } - - public static SchematicMember getSchemMemberFromDB(String schemName, UUID schemOwner, UUID schemMember){ - return getSchemMemberFromDB(schemName, SteamwarUser.get(schemOwner).getId(), SteamwarUser.get(schemMember).getId()); - } - - public static SchematicMember getSchemMemberFromDB(String schemName, int schemOwner, int schemMember) { - return getSchemMemberFromDB(schemName, schemOwner, schemMember, 0); - } - - public static SchematicMember getSchemMemberFromDB(String schemName, int schemOwner, int schemMember, int parent) { - SchematicNode node = SchematicNode.getSchematicNode(schemOwner, schemName, parent); - NodeMember member = NodeMember.getNodeMember(node.getId(), schemMember); - return member == null?null:new SchematicMember(node, schemMember, false); - } - - public static SchematicMember getMemberBySchematic(String schemName, int schemMember){ - return new SchematicMember(SchematicNode.getSchematicNode(NodeMember.getSchematics(schemMember).stream().filter(member1 -> SchematicNode.getSchematicNode(member1.getNode()).getName().equals(schemName)).limit(1).collect(Collectors.toList()).get(0).node), schemMember, false); - } - - public static List getSchemMembers(String schemName, UUID schemOwner){ - return getSchemMembers(schemName, SteamwarUser.get(schemOwner).getId()); - } - - public static List getSchemMembers(String schemName, int schemOwner){ - SchematicNode node = SchematicNode.getSchematicNode(schemOwner, schemName, 0); - Set members = NodeMember.getNodeMembers(node.getId()); - List retMembers = new ArrayList<>(); - members.forEach(member1 -> retMembers.add(new SchematicMember(node, member1.member, false))); - return retMembers; - } - - public static List getAccessibleSchems(UUID schemMember){ - return getAccessibleSchems(SteamwarUser.get(schemMember).getId()); - } - - public static List getAccessibleSchems(int schemMember){ - List members = new ArrayList<>(); - NodeMember.getSchematics(schemMember).forEach(member1 -> members.add(new SchematicMember(SchematicNode.getSchematicNode(member1.node), member1.member, false))); - return members; - } - - public int getSchemOwner() { - return SchematicNode.getSchematicNode(member.getNode()).getOwner(); - } - - public String getSchemName() { - return SchematicNode.getSchematicNode(member.getNode()).getName(); - } - - public int getMember() { - return member.getMember(); - } - - public void remove(){ - member.delete(); - } -} diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java index f3d7389..b8cc085 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java @@ -515,4 +515,13 @@ public class SchematicNode { SQL.update("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?", blob, newFormat, id); schemFormat = newFormat; } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof SchematicNode)) + return false; + + SchematicNode node = (SchematicNode) obj; + return node.getId() == id; + } }