SteamWar/SpigotCore
Archiviert
13
0

More Improvements!

Dieser Commit ist enthalten in:
Chaoscaot 2021-07-18 19:37:33 +02:00
Ursprung 3aa896771e
Commit f29309f3ec
5 geänderte Dateien mit 10 neuen und 290 gelöschten Zeilen

Datei anzeigen

@ -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<T> extends SWInventory {
return onlinePlayers;
}
public static List<SWListEntry<Schematic>> getSchemList(SchematicType type, int steamwarUserId){
List<SWListEntry<Schematic>> schemList = new ArrayList<>();
List<Schematic> 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<SWListEntry<SchematicNode>> getSchemnodeList(SchematicType type, int steamwarUserId){
List<SWListEntry<SchematicNode>> schemList = new ArrayList<>();
List<SchematicNode> schems;
if(type == null)
schems = SchematicNode.getSchematicsAccessibleByUser(steamwarUserId, 0);
schems = SchematicNode.filterSchems(steamwarUserId, node -> true);
else
schems = SchematicNode.getSchematicsOfType(steamwarUserId, type.toDB(), 0);

Datei anzeigen

@ -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()));
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<Schematic> getSchemsAccessibleByUser(UUID schemOwner){
return getSchemsAccessibleByUser(SteamwarUser.get(schemOwner).getId());
}
public static List<Schematic> getSchemsAccessibleByUser(int schemOwner){
List<SchematicNode> nodes = SchematicNode.getSchematicsAccessibleByUser(schemOwner, 0);
List<Schematic> schematics = new ArrayList<>();
nodes.forEach(node1 -> {
if (!node1.isDir()) schematics.add(new Schematic(node1));
});
return schematics;
}
public static List<Schematic> getSchemsOfType(UUID schemOwner, SchematicType schemType){
return getSchemsOfType(SteamwarUser.get(schemOwner).getId(), schemType);
}
public static List<Schematic> getSchemsOfType(int schemOwner, SchematicType schemType){
//Unsauber, dafür auch geaddede Schematics dabei
List<Schematic> 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<Schematic> getAllSchemsOfType(SchematicType schemType){
List<SchematicNode> nodes = SchematicNode.getAllSchematicsOfType(schemType.toDB());
List<Schematic> 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{}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<SchematicMember> getSchemMembers(String schemName, UUID schemOwner){
return getSchemMembers(schemName, SteamwarUser.get(schemOwner).getId());
}
public static List<SchematicMember> getSchemMembers(String schemName, int schemOwner){
SchematicNode node = SchematicNode.getSchematicNode(schemOwner, schemName, 0);
Set<NodeMember> members = NodeMember.getNodeMembers(node.getId());
List<SchematicMember> retMembers = new ArrayList<>();
members.forEach(member1 -> retMembers.add(new SchematicMember(node, member1.member, false)));
return retMembers;
}
public static List<SchematicMember> getAccessibleSchems(UUID schemMember){
return getAccessibleSchems(SteamwarUser.get(schemMember).getId());
}
public static List<SchematicMember> getAccessibleSchems(int schemMember){
List<SchematicMember> 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();
}
}

Datei anzeigen

@ -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;
}
}