SteamWar/SpigotCore
Archiviert
13
0

Add Schematic SchematicNode Wrapper
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
Chaoscaot 2021-11-03 17:14:45 +01:00
Ursprung de6d8bbb10
Commit 37f11e4723
7 geänderte Dateien mit 342 neuen und 39 gelöschten Zeilen

Datei anzeigen

@ -21,6 +21,7 @@ package de.steamwar.comms.packets;
import com.google.common.io.ByteArrayDataOutput;
import de.steamwar.comms.PacketIdManager;
import de.steamwar.sql.Schematic;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SchematicType;
import de.steamwar.sql.SteamwarUser;
@ -37,6 +38,13 @@ public class PrepareSchemPacket extends SpigotPacket{
this.schematicType = schematicType;
}
@Deprecated
public PrepareSchemPacket(SteamwarUser user, Schematic schematic, SchematicType schematicType) {
this.user = user;
this.schematic = schematic.getNode();
this.schematicType = schematicType;
}
@Override
public int getName() {
return PacketIdManager.PREPARE_SCHEM;

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.inventory;
import de.steamwar.sql.Schematic;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SchematicType;
import org.bukkit.Bukkit;
@ -27,6 +28,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import java.util.*;
import java.util.stream.Collectors;
public class SWListInv<T> extends SWInventory {
@ -136,6 +138,11 @@ public class SWListInv<T> extends SWInventory {
}
return schemList;
}
@Deprecated
public static List<SWListEntry<Schematic>> getSchemList(SchematicType type, int steamwarUserId){
return getSchemnodeList(type, steamwarUserId).stream().map(schematicNodeSWListEntry -> new SWListEntry<Schematic>(schematicNodeSWListEntry.getItem(), Schematic.wrap(schematicNodeSWListEntry.getObject()))).collect(Collectors.toList());
}
private boolean sizeBiggerMax(){
return dynamicSize ? elements.size() > 54 : elements.size() > 45;

Datei anzeigen

@ -24,6 +24,7 @@ import org.bukkit.Bukkit;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
@ -32,6 +33,9 @@ import java.util.logging.Level;
public class CheckedSchematic {
private static final SQL.Statement checkHistory = new SQL.Statement("SELECT * FROM CheckedSchematic WHERE NodeId IN (SELECT NodeId FROM SchematicNode WHERE NodeOwner = ?) AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC");
private static final SQL.Statement nodeHistory = new SQL.Statement("SELECT * FROM CheckedSchematic WHERE NodeId = ? AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC");
private final int node;
private final int validator;
private final Timestamp startTime;
@ -62,43 +66,35 @@ public class CheckedSchematic {
node, validator, startTime, endTime, declineReason);
}
public static List<CheckedSchematic> getLastDeclined(SchematicNode node){
return getLastDeclined(node.getId());
public static List<CheckedSchematic> getLastDeclinedOfNode(SchematicNode node){
return getLastDeclinedOfNode(node.getId());
}
public static List<CheckedSchematic> getLastDeclined(int node){
List<CheckedSchematic> lastDeclined = new LinkedList<>();
try{
ResultSet lastRS = SQL.select("SELECT * FROM CheckedSchematic WHERE NodeId = ? AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC", node);
while(lastRS.next()){
int validator = lastRS.getInt("Validator");
Timestamp startTime = lastRS.getTimestamp("StartTime");
Timestamp endTime = lastRS.getTimestamp("EndTime");
String declineReason = lastRS.getString("DeclineReason");
public static List<CheckedSchematic> getLastDeclinedOfNode(int node){
return nodeHistory.select(rs -> {
List<CheckedSchematic> lastDeclined = new ArrayList<>();
while(rs.next()){
int validator = rs.getInt("Validator");
Timestamp startTime = rs.getTimestamp("StartTime");
Timestamp endTime = rs.getTimestamp("EndTime");
String declineReason = rs.getString("DeclineReason");
lastDeclined.add(new CheckedSchematic(node, validator, startTime, endTime, declineReason, false));
}
}catch(SQLException e){
Bukkit.getLogger().log(Level.SEVERE, "getLastDeclined failed", e);
}
return lastDeclined;
return lastDeclined;
}, node);
}
public static List<CheckedSchematic> getLastDeclined(UUID uuid){
List<CheckedSchematic> lastDeclined = new LinkedList<>();
try{
ResultSet lastRS = SQL.select("SELECT * FROM CheckedSchematic WHERE NodeId IN (SELECT NodeId FROM SchematicNode WHERE NodeOwner = ?) AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC", SteamwarUser.get(uuid).getId());
while(lastRS.next()){
int node = lastRS.getInt("NodeId");
int validator = lastRS.getInt("Validator");
Timestamp startTime = lastRS.getTimestamp("StartTime");
Timestamp endTime = lastRS.getTimestamp("EndTime");
String declineReason = lastRS.getString("DeclineReason");
lastDeclined.add(new CheckedSchematic(node, validator, startTime, endTime, declineReason, false));
}
}catch(SQLException e){
Bukkit.getLogger().log(Level.SEVERE, "getLastDeclined failed", e);
}
return lastDeclined;
return getLastDelined(SteamwarUser.get(uuid).getId());
}
public static List<CheckedSchematic> getLastDelined(int schemOwner){
return checkHistory.select(rs -> {
List<CheckedSchematic> history = new ArrayList<>();
while(rs.next())
history.add(new CheckedSchematic(rs.getInt("NodeId"), rs.getInt("Validator"), rs.getTimestamp("StartTime"), rs.getTimestamp("EndTime"), rs.getString("DeclineReason"), false));
return history;
}, schemOwner);
}
public void remove() {

Datei anzeigen

@ -28,6 +28,9 @@ import java.time.Instant;
public class DownloadSchematic {
private DownloadSchematic(){}
private static final SQL.Statement createLink = new SQL.Statement("INSERT INTO SchemDownload (SchemID, Link) VALUES (?, ?) ON DUPLICATE KEY UPDATE Link = VALUES(Link)");
private static final String BASE = "https://steamwar.de/download.php?schem=";
public static String getLink(SchematicNode schem){
@ -42,7 +45,12 @@ public class DownloadSchematic {
digest.reset();
digest.update((Instant.now().toString() + schem.getOwner() + schem.getId()).getBytes());
String hash = BaseEncoding.base16().encode(digest.digest());
SQL.update("INSERT INTO SchemDownload (SchemID, Link) VALUES (?, ?) ON DUPLICATE KEY UPDATE Link = VALUES(Link)", schem.getId(), hash);
createLink.update(schem.getId(), hash);
return BASE + hash;
}
@Deprecated
public static String getLink(Schematic schem){
return getLink(schem.getNode());
}
}

Datei anzeigen

@ -0,0 +1,193 @@
/*
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 de.steamwar.core.Core;
import de.steamwar.core.WorldEditWrapper;
import org.bukkit.entity.Player;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@Deprecated
public class Schematic {
private static final SQL.Statement getSchemsOfType = new SQL.Statement("SELECT DISTINCT s.SchemID, s.SchemName, s.SchemOwner, s.Item, s.SchemType, s.Rank, s.SchemFormat FROM Schematic s LEFT JOIN SchemMember sm ON sm.SchemName = s.SchemName AND sm.SchemOwner = s.SchemOwner WHERE s.SchemType = ? AND (s.SchemOwner = ? OR sm.Member = ?) ORDER BY s.SchemName");
private final SchematicNode node;
private Schematic(SchematicNode node) {
this.node = node;
}
public static Schematic wrap(SchematicNode node) {
return new Schematic(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, null, 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, 0);
if(node != null) {
return new Schematic(node);
}
return null;
}
public static Schematic getSchemFromDB(int schemID){
SchematicNode node = SchematicNode.getSchematicNode(schemID);
if(node != null) {
return new Schematic(node);
} else {
throw new SecurityException("Failed to load Schematics");
}
}
public static List<Schematic> getSchemsAccessibleByUser(UUID schemOwner){
return getSchemsAccessibleByUser(SteamwarUser.get(schemOwner).getId());
}
public static List<Schematic> getSchemsAccessibleByUser(int schemOwner){
List<Schematic> schematics = new ArrayList<>();
SchematicNode.getSchematicsAccessibleByUser(schemOwner, null)
.forEach(node1 -> 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){
List<Schematic> schematics = new ArrayList<>();
SchematicNode.getSchematicsOfType(schemOwner, schemType.toDB(), null)
.forEach(node1 -> schematics.add(new Schematic(node1)));
return schematics;
}
public static List<Schematic> getAllSchemsOfType(SchematicType schemType){
List<Schematic> schematics = new ArrayList<>();
SchematicNode.getAllSchematicsOfType(schemType.toDB())
.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 InputStream schemData() throws IOException {
return node.schemData();
}
public static Clipboard clipboardFromStream(InputStream is, boolean schemFormat) {
try {
return WorldEditWrapper.impl.getClipboard(is, schemFormat);
} catch (IOException e) {
throw new SecurityException("Could not read schem", e);
}
}
public Clipboard load() throws IOException, NoClipboardException {
return clipboardFromStream(schemData(), node.getSchemFormat());
}
public void loadToPlayer(Player player) throws IOException, NoClipboardException {
InputStream is = schemData();
WorldEditWrapper.impl.setPlayerClipboard(player, is, node.getSchemFormat());
}
public void saveOldFormatFromPlayer(Player player) throws IOException, NoClipboardException {
saveFromPlayer(player, false);
}
public void saveFromPlayer(Player player) throws IOException, NoClipboardException {
saveFromPlayer(player, Core.getVersion() > 12);
}
public void saveFromBytes(byte[] bytes, boolean newFormat) {
node.saveFromBytes(bytes, newFormat);
}
private void saveFromPlayer(Player player, boolean newFormat) throws IOException, NoClipboardException {
node.saveFromPlayer(player, newFormat);
}
public void remove(){
node.delete();
}
public SchematicNode getNode() {
return node;
}
@Deprecated
public static class WrongVersionException extends Exception{}
}

Datei anzeigen

@ -0,0 +1,96 @@
/*
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.Optional;
import java.util.UUID;
@Deprecated
public class SchematicMember {
private final NodeMember member;
private SchematicMember(NodeMember member){
this.member = member;
}
public SchematicMember(String schemName, int schemOwner, int schemMember){
this(NodeMember.createNodeMember(Schematic.getSchemFromDB(schemName, schemOwner).getSchemID(), schemMember));
}
public SchematicMember(String schemName, UUID schemOwner, UUID schemMember){
this(NodeMember.createNodeMember(Schematic.getSchemFromDB(schemName, schemOwner).getSchemID(), SteamwarUser.get(schemMember).getId()));
}
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){
NodeMember member = NodeMember.getNodeMember(Schematic.getSchemFromDB(schemName, schemOwner).getSchemID(), schemMember);
if(member == null) {
return null;
}
return new SchematicMember(member);
}
public static SchematicMember getMemberBySchematic(String schemName, int schemMember){
Optional<NodeMember> nodeMember = NodeMember.getSchematics(schemMember)
.stream().filter(member1 -> SchematicNode.getSchematicNode(member1.getNode()).getName().equalsIgnoreCase(schemName)).findFirst();
return nodeMember.map(SchematicMember::new).orElse(null);
}
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){
List<SchematicMember> members = new ArrayList<>();
NodeMember.getNodeMembers(Schematic.getSchemFromDB(schemName, schemOwner).getSchemID())
.forEach(member1 -> members.add(new SchematicMember(member1)));
return members;
}
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(member1)));
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

@ -20,6 +20,7 @@
package de.steamwar.sql;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.core.Core;
import de.steamwar.core.VersionedCallable;
import de.steamwar.core.VersionedRunnable;
import de.steamwar.core.WorldEditWrapper;
@ -462,16 +463,10 @@ public class SchematicNode {
WorldEditWrapper.impl.setPlayerClipboard(player, schemData(), schemFormat);
}
public void saveOldFormatFromPlayer(Player player) throws IOException, NoClipboardException {
if(isDir)
throw new SecurityException("Node is Directory");
saveFromPlayer(player, false);
}
public void saveFromPlayer(Player player) throws IOException, NoClipboardException {
if(isDir)
throw new SecurityException("Node is Directory");
saveFromPlayer(player, true);
saveFromPlayer(player, Core.getVersion() > 12);
}
public void saveFromBytes(byte[] bytes, boolean newFormat) {
@ -480,7 +475,7 @@ public class SchematicNode {
updateDatabase(new ByteArrayInputStream(bytes), newFormat);
}
private void saveFromPlayer(Player player, boolean newFormat) throws IOException, NoClipboardException {
public void saveFromPlayer(Player player, boolean newFormat) throws IOException, NoClipboardException {
if(isDir)
throw new SecurityException("Node is Directory");
updateDatabase(WorldEditWrapper.impl.getPlayerClipboard(player, newFormat), newFormat);