Dieser Commit ist enthalten in:
Ursprung
9a4e85d749
Commit
5b41b2112d
@ -1 +1 @@
|
||||
Subproject commit c1e175c3e84280c160ae5c7f84e44805f159bbf3
|
||||
Subproject commit 1758fc4297da23f6cae2e69115b510a6fb7d4aeb
|
@ -31,6 +31,7 @@ import de.steamwar.core.events.PlayerJoinedEvent;
|
||||
import de.steamwar.core.events.WorldLoadEvent;
|
||||
import de.steamwar.message.Message;
|
||||
import de.steamwar.network.NetworkReceiver;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import de.steamwar.sql.internal.Statement;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -121,6 +122,7 @@ public class Core extends JavaPlugin{
|
||||
new PartialChunkFixer();
|
||||
|
||||
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), SteamwarUser::clear, 72000, 72000);
|
||||
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), SchematicNode::clear, 20L * 30, 20L * 30);
|
||||
|
||||
if(Core.getVersion() >= 19)
|
||||
//new ServerDataHandler();
|
||||
|
@ -21,8 +21,10 @@ package de.steamwar.core.events;
|
||||
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import de.steamwar.sql.UserGroup;
|
||||
import de.steamwar.sql.internal.Statement;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
@ -30,9 +32,12 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class PlayerJoinedEvent implements Listener{
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
private void onJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if(!Statement.productionDatabase()) {
|
||||
SteamwarUser.createOrUpdateUsername(player.getUniqueId(), player.getName());
|
||||
}
|
||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||
|
||||
if(user.getUserGroup() != UserGroup.Member) {
|
||||
|
@ -1,75 +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 de.steamwar.sql.internal.Field;
|
||||
import de.steamwar.sql.internal.SelectStatement;
|
||||
import de.steamwar.sql.internal.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class CheckedSchematic {
|
||||
|
||||
private static final Table<CheckedSchematic> table = new Table<>(CheckedSchematic.class);
|
||||
private static final SelectStatement<CheckedSchematic> statusOfNode = new SelectStatement<>(table, "SELECT * FROM CheckedSchematic WHERE NodeId = ? AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC");
|
||||
|
||||
public static List<CheckedSchematic> getLastDeclinedOfNode(SchematicNode node){
|
||||
return getLastDeclinedOfNode(node.getId());
|
||||
}
|
||||
|
||||
public static List<CheckedSchematic> getLastDeclinedOfNode(int node){
|
||||
return statusOfNode.listSelect(node);
|
||||
}
|
||||
|
||||
@Field(nullable = true)
|
||||
private final Integer nodeId;
|
||||
@Field
|
||||
private final int nodeOwner;
|
||||
@Field
|
||||
private final String nodeName;
|
||||
@Getter
|
||||
@Field
|
||||
private final int validator;
|
||||
@Getter
|
||||
@Field
|
||||
private final Timestamp startTime;
|
||||
@Getter
|
||||
@Field
|
||||
private final Timestamp endTime;
|
||||
@Getter
|
||||
@Field
|
||||
private final String declineReason;
|
||||
|
||||
public int getNode() {
|
||||
return nodeId;
|
||||
}
|
||||
|
||||
public String getSchemName() {
|
||||
return nodeName;
|
||||
}
|
||||
|
||||
public int getSchemOwner() {
|
||||
return nodeOwner;
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2021 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.google.common.io.BaseEncoding;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.time.Instant;
|
||||
|
||||
public class NodeDownload {
|
||||
private NodeDownload() {}
|
||||
|
||||
private static final String BASE = "https://steamwar.de/download.php?schem=";
|
||||
|
||||
public static String getLink(SchematicNode schem){
|
||||
if(schem.isDir())
|
||||
throw new SecurityException("Can not Download Directorys");
|
||||
MessageDigest digest;
|
||||
try {
|
||||
digest = MessageDigest.getInstance("SHA-1");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new SecurityException(e);
|
||||
}
|
||||
digest.reset();
|
||||
digest.update((Instant.now().toString() + schem.getOwner() + schem.getId()).getBytes());
|
||||
String hash = BaseEncoding.base16().encode(digest.digest());
|
||||
Provider.impl.createDownloadLink(schem.getId(), hash);
|
||||
return BASE + hash;
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2022 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.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public interface Provider {
|
||||
Provider impl = new SQLProvider();
|
||||
|
||||
boolean hasEventTeam(int teamID, int eventID);
|
||||
Set<Team> getEventTeams(int eventID);
|
||||
Set<Event> getTeamEvents(int teamID);
|
||||
|
||||
void createDownloadLink(int nodeId, String hash);
|
||||
|
||||
Punishment getPunishmentOfPlayer(int user, Punishment.PunishmentType type);
|
||||
Map<Punishment.PunishmentType, Punishment> getPunishmentsOfPlayer(int user);
|
||||
|
||||
void logException(String server, String message, String stacktrace);
|
||||
|
||||
Team getTeam(int id);
|
||||
List<Integer> getTeamMembers(Team team);
|
||||
|
||||
String getConfig(int player, String config);
|
||||
void updatePlayerConfig(int id, String config, String value);
|
||||
void removePlayerConfig(int id, String config);
|
||||
|
||||
void createSchematicNode(int owner, String name, Integer parent, String type, String item);
|
||||
SchematicNode getSchematicNode(int owner, String name, Integer parent);
|
||||
List<SchematicNode> getSchematicNodeInNode(Integer parent);
|
||||
List<SchematicNode> getSchematicDirectoryInNode(Integer parent);
|
||||
SchematicNode getSchematicDirectory(String name, Integer parent);
|
||||
SchematicNode getSchematicNode(String name, Integer parent);
|
||||
SchematicNode getSchematicNode(int id);
|
||||
List<SchematicNode> getAccessibleSchematicsOfTypeInParent(int owner, String schemType, Integer parent);
|
||||
List<SchematicNode> getAllAccessibleSchematicsOfType(int user, String schemType);
|
||||
List<SchematicNode> getAllSchematicsOfType(int owner, String schemType);
|
||||
List<SchematicNode> getAllSchematicsOfType(String schemType);
|
||||
List<SchematicNode> getSchematicsAccessibleByUser(int user, Integer parent);
|
||||
List<SchematicNode> getAllSchematicsAccessibleByUser(int user);
|
||||
List<SchematicNode> getAllParentsOfNode(int node);
|
||||
Integer countNodes();
|
||||
void updateSchematicNode(SchematicNode node);
|
||||
void deleteSchematicNode(SchematicNode node);
|
||||
InputStream getSchematicData(SchematicNode node) throws IOException;
|
||||
void saveSchematicNode(SchematicNode node, InputStream blob, boolean newFormat);
|
||||
int getSchematicElo(SchematicNode node, int season);
|
||||
}
|
@ -1,128 +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 lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class Punishment {
|
||||
|
||||
|
||||
public static Punishment getPunishmentOfPlayer(int user, PunishmentType type) {
|
||||
return Provider.impl.getPunishmentOfPlayer(user, type);
|
||||
}
|
||||
|
||||
public static Map<PunishmentType, Punishment> getPunishmentsOfPlayer(int user) {
|
||||
return Provider.impl.getPunishmentsOfPlayer(user);
|
||||
}
|
||||
|
||||
public static boolean isPunished(SteamwarUser user, Punishment.PunishmentType type, Consumer<Punishment> callback) {
|
||||
Punishment punishment = Punishment.getPunishmentOfPlayer(user.getId(), type);
|
||||
if(punishment == null || !punishment.isCurrent()) {
|
||||
return false;
|
||||
} else {
|
||||
callback.accept(punishment);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private final int user;
|
||||
private final int punisher;
|
||||
private final PunishmentType type;
|
||||
private final Timestamp startTime;
|
||||
private final Timestamp endTime;
|
||||
private final boolean perma;
|
||||
private final String reason;
|
||||
|
||||
public Punishment(int user, int punisher, PunishmentType type, Timestamp startTime, Timestamp endTime, boolean perma, String reason) {
|
||||
this.user = user;
|
||||
this.punisher = punisher;
|
||||
this.type = type;
|
||||
this.startTime = startTime;
|
||||
this.endTime = endTime;
|
||||
this.perma = perma;
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
public Timestamp getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public Timestamp getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public PunishmentType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public String getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
public int getPunisher() {
|
||||
return punisher;
|
||||
}
|
||||
|
||||
public boolean isPerma() {
|
||||
return perma;
|
||||
}
|
||||
|
||||
public String getBantime(Timestamp endTime, boolean perma) {
|
||||
if (perma) {
|
||||
return "permanent";
|
||||
} else {
|
||||
return endTime.toLocalDateTime().format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm"));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCurrent() {
|
||||
return isPerma() || getEndTime().after(new Date());
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum PunishmentType {
|
||||
Ban(false, "BAN_TEAM", "BAN_PERMA", "BAN_UNTIL", "UNBAN_ERROR", "UNBAN"),
|
||||
Mute( false, "MUTE_TEAM", "MUTE_PERMA", "MUTE_UNTIL", "UNMUTE_ERROR", "UNMUTE"),
|
||||
NoSchemReceiving(false, "NOSCHEMRECEIVING_TEAM", "NOSCHEMRECEIVING_PERMA", "NOSCHEMRECEIVING_UNTIL", "UNNOSCHEMRECEIVING_ERROR", "UNNOSCHEMRECEIVING"),
|
||||
NoSchemSharing(false, "NOSCHEMSHARING_TEAM", "NOSCHEMSHARING_PERMA", "NOSCHEMSHARING_UNTIL", "UNNOSCHEMSHARING_ERROR", "UNNOSCHEMSHARING"),
|
||||
NoSchemSubmitting(true, "NOSCHEMSUBMITTING_TEAM", "NOSCHEMSUBMITTING_PERMA", "NOSCHEMSUBMITTING_UNTIL", "UNNOSCHEMSUBMITTING_ERROR", "UNNOSCHEMSUBMITTING"),
|
||||
NoDevServer(true, "NODEVSERVER_TEAM", "NODEVSERVER_PERMA", "NODEVSERVER_UNTIL", "UNNODEVSERVER_ERROR", "UNNODEVSERVER");
|
||||
|
||||
private final boolean needsAdmin;
|
||||
private final String teamMessage;
|
||||
private final String playerMessagePerma;
|
||||
private final String playerMessageUntil;
|
||||
private final String usageNotPunished;
|
||||
private final String unpunishmentMessage;
|
||||
}
|
||||
}
|
@ -1,397 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2022 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 de.steamwar.sql.internal.Statement;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.Blob;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class SQLProvider implements Provider {
|
||||
|
||||
private static final de.steamwar.sql.internal.Statement hasEventTeam = new de.steamwar.sql.internal.Statement("SELECT * FROM TeamTeilnahme WHERE TeamID = ? AND EventID = ?");
|
||||
@Override
|
||||
public boolean hasEventTeam(int teamID, int eventID) {
|
||||
return hasEventTeam.select(ResultSet::next, teamID, eventID);
|
||||
}
|
||||
|
||||
private static final de.steamwar.sql.internal.Statement eventTeams = new de.steamwar.sql.internal.Statement("SELECT * FROM TeamTeilnahme WHERE EventID = ?");
|
||||
@Override
|
||||
public Set<Team> getEventTeams(int eventID) {
|
||||
return eventTeams.select(rs -> {
|
||||
Set<Team> teams = new HashSet<>();
|
||||
while(rs.next())
|
||||
teams.add(Team.get(rs.getInt("TeamID")));
|
||||
return teams;
|
||||
}, eventID);
|
||||
}
|
||||
|
||||
private static final de.steamwar.sql.internal.Statement eventsTeam = new de.steamwar.sql.internal.Statement("SELECT * FROM TeamTeilnahme WHERE TeamID = ?");
|
||||
@Override
|
||||
public Set<Event> getTeamEvents(int teamID) {
|
||||
return eventsTeam.select(rs -> {
|
||||
Set<Event> events = new HashSet<>();
|
||||
while(rs.next())
|
||||
events.add(Event.get(rs.getInt("EventID")));
|
||||
return events;
|
||||
}, teamID);
|
||||
}
|
||||
|
||||
private static final de.steamwar.sql.internal.Statement createLink = new de.steamwar.sql.internal.Statement("INSERT INTO NodeDownload (NodeId, Link) VALUES (?, ?) ON DUPLICATE KEY UPDATE Link = VALUES(Link)");
|
||||
@Override
|
||||
public void createDownloadLink(int nodeId, String hash) {
|
||||
createLink.update(nodeId, hash);
|
||||
}
|
||||
|
||||
private static final de.steamwar.sql.internal.Statement getPunishment = new de.steamwar.sql.internal.Statement("SELECT * FROM Punishments WHERE UserId = ? AND Type = ? ORDER BY PunishmentId DESC LIMIT 1");
|
||||
@Override
|
||||
public Punishment getPunishmentOfPlayer(int user, Punishment.PunishmentType type) {
|
||||
return getPunishment.select(rs -> {
|
||||
if (rs.next())
|
||||
return newPunishment(rs);
|
||||
return null;
|
||||
}, user, type.name());
|
||||
}
|
||||
|
||||
private Punishment newPunishment(ResultSet rs) throws SQLException {
|
||||
return new Punishment(rs.getInt("UserId"), rs.getInt("Punisher"), Punishment.PunishmentType.valueOf(rs.getString("Type")), rs.getTimestamp("StartTime"), rs.getTimestamp("EndTime"), rs.getBoolean("Perma"), rs.getString("Reason"));
|
||||
}
|
||||
|
||||
private static final de.steamwar.sql.internal.Statement getPunishments = new de.steamwar.sql.internal.Statement("SELECT * FROM Punishments WHERE PunishmentId IN (SELECT MAX(PunishmentId) FROM Punishments WHERE UserId = ? GROUP BY Type)");
|
||||
@Override
|
||||
public Map<Punishment.PunishmentType, Punishment> getPunishmentsOfPlayer(int user) {
|
||||
return getPunishments.select(rs -> {
|
||||
Map<Punishment.PunishmentType, Punishment> punishments = new HashMap<>();
|
||||
while (rs.next())
|
||||
punishments.put(Punishment.PunishmentType.valueOf(rs.getString("Type")), newPunishment(rs));
|
||||
return punishments;
|
||||
}, user);
|
||||
}
|
||||
|
||||
private static final de.steamwar.sql.internal.Statement insert = new de.steamwar.sql.internal.Statement("INSERT INTO Exception (server, message, stacktrace) VALUES (?, ?, ?)");
|
||||
@Override
|
||||
public void logException(String server, String message, String stacktrace) {
|
||||
insert.update(server, message, stacktrace);
|
||||
}
|
||||
|
||||
private static final de.steamwar.sql.internal.Statement getTeam = new de.steamwar.sql.internal.Statement("SELECT * FROM Team WHERE TeamID = ?");
|
||||
@Override
|
||||
public Team getTeam(int id) {
|
||||
return getTeam.select(rs -> {
|
||||
rs.next();
|
||||
return new Team(rs.getInt("TeamID"), rs.getString("TeamKuerzel"), rs.getString("TeamName"), rs.getString("TeamColor"));
|
||||
}, id);
|
||||
}
|
||||
|
||||
private static final de.steamwar.sql.internal.Statement getTeamMembers = new de.steamwar.sql.internal.Statement("SELECT id FROM UserData WHERE Team = ?");
|
||||
@Override
|
||||
public List<Integer> getTeamMembers(Team team) {
|
||||
return getTeamMembers.select(rs -> {
|
||||
List<Integer> members = new ArrayList<>();
|
||||
while(rs.next())
|
||||
members.add(rs.getInt("id"));
|
||||
return members;
|
||||
}, team.getTeamId());
|
||||
}
|
||||
|
||||
private static final de.steamwar.sql.internal.Statement getConfig = new de.steamwar.sql.internal.Statement("SELECT Value FROM UserConfig WHERE User = ? AND Config = ?");
|
||||
@Override
|
||||
public String getConfig(int player, String config) {
|
||||
return getConfig.select(rs -> {
|
||||
if(rs.next())
|
||||
return rs.getString("Value");
|
||||
return null;
|
||||
}, player, config);
|
||||
}
|
||||
|
||||
private static final de.steamwar.sql.internal.Statement setConfig = new de.steamwar.sql.internal.Statement("INSERT INTO UserConfig (User, Config, Value) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Value = VALUES(Value)");
|
||||
@Override
|
||||
public void updatePlayerConfig(int id, String config, String value) {
|
||||
setConfig.update(id, config, value);
|
||||
}
|
||||
|
||||
private static final de.steamwar.sql.internal.Statement deleteConfig = new de.steamwar.sql.internal.Statement("DELETE FROM UserConfig WHERE User = ? AND Config = ?");
|
||||
@Override
|
||||
public void removePlayerConfig(int id, String config) {
|
||||
deleteConfig.update(id, config);
|
||||
}
|
||||
|
||||
private static final String[] nodeSelect = {"NodeId", "NodeName", "NodeOwner", "ParentNode", "NodeType", "NodeItem", "NodeRank", "NodeFormat", "LastUpdate", "ReplaceColor", "AllowReplay"};
|
||||
private static String nodeSelectCreator(String itemPrefix) {
|
||||
return "SELECT " + Arrays.stream(nodeSelect).map(s -> itemPrefix + s).collect(Collectors.joining(", ")) + " FROM SchematicNode ";
|
||||
}
|
||||
private static final de.steamwar.sql.internal.Statement createNode = new de.steamwar.sql.internal.Statement("INSERT INTO SchematicNode (NodeName, NodeOwner, ParentNode, NodeType, NodeItem) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE NodeName = VALUES(NodeName), ParentNode = VALUES(ParentNode), NodeItem = VALUES(NodeItem), NodeType = VALUES(NodeType), NodeItem = VALUES(NodeItem)");
|
||||
private static final de.steamwar.sql.internal.Statement getSchematicNode_Null = new de.steamwar.sql.internal.Statement(nodeSelectCreator("") + "WHERE NodeOwner = ? AND NodeName = ? AND ParentNode is NULL");
|
||||
private static final de.steamwar.sql.internal.Statement getSchematicNode = new de.steamwar.sql.internal.Statement(nodeSelectCreator("") + "WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?");
|
||||
private static final de.steamwar.sql.internal.Statement getSchematicsInNode_Null = new de.steamwar.sql.internal.Statement(nodeSelectCreator("") + "WHERE ParentNode is NULL ORDER BY NodeName");
|
||||
private static final de.steamwar.sql.internal.Statement getSchematicsInNode = new de.steamwar.sql.internal.Statement(nodeSelectCreator("") + "WHERE ParentNode = ? ORDER BY NodeName");
|
||||
private static final de.steamwar.sql.internal.Statement getDirsInNode_Null = new de.steamwar.sql.internal.Statement(nodeSelectCreator("") + "WHERE ParentNode is NULL AND NodeType is NULL ORDER BY NodeName");
|
||||
private static final de.steamwar.sql.internal.Statement getDirsInNode = new de.steamwar.sql.internal.Statement(nodeSelectCreator("") + "WHERE ParentNode = ? AND NodeType is NULL ORDER BY NodeName");
|
||||
private static final de.steamwar.sql.internal.Statement getSchematicDirectory_Null = new de.steamwar.sql.internal.Statement(nodeSelectCreator("") + "WHERE NodeName = ? AND ParentNode is NULL ORDER BY NodeName");
|
||||
private static final de.steamwar.sql.internal.Statement getSchematicDirectory = new de.steamwar.sql.internal.Statement(nodeSelectCreator("") + "WHERE NodeName = ? AND ParentNode = ? ORDER BY NodeName");
|
||||
private static final de.steamwar.sql.internal.Statement getSchematicNodeO_Null = new de.steamwar.sql.internal.Statement(nodeSelectCreator("") + "WHERE NodeName = ? AND ParentNode is NULL ");
|
||||
private static final de.steamwar.sql.internal.Statement getSchematicNodeO = new de.steamwar.sql.internal.Statement(nodeSelectCreator("") + "WHERE NodeName = ? AND ParentNode = ? ORDER BY NodeName");
|
||||
private static final de.steamwar.sql.internal.Statement getSchematicNodeId = new de.steamwar.sql.internal.Statement(nodeSelectCreator("") + "WHERE NodeId = ?");
|
||||
private static final de.steamwar.sql.internal.Statement getAllSchemsOfTypeOwner = new de.steamwar.sql.internal.Statement( nodeSelectCreator("") + "WHERE NodeOwner = ? AND NodeType = ? ORDER BY NodeName");
|
||||
private static final de.steamwar.sql.internal.Statement getAllSchemsOfType = new de.steamwar.sql.internal.Statement(nodeSelectCreator("") + "WHERE NodeType = ? ORDER BY NodeName");
|
||||
private static final de.steamwar.sql.internal.Statement getAccessibleByUser = new de.steamwar.sql.internal.Statement(nodeSelectCreator("s.") + "s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) AND ((s.NodeOwner = ? AND s.ParentNode IS NULL) OR NOT s.NodeOwner = ?) GROUP BY s.NodeId ORDER BY s.NodeName");
|
||||
private static final de.steamwar.sql.internal.Statement getAccessibleByUserByTypeInNode = new de.steamwar.sql.internal.Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (" + nodeSelectCreator("s.") + "s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId UNION " + nodeSelectCreator("SN.") + "AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? UNION " + nodeSelectCreator("SN.") + "AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode = ? ORDER BY NodeName");
|
||||
private static final de.steamwar.sql.internal.Statement getAccessibleByUserByTypeInNode_Null = new de.steamwar.sql.internal.Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (" + nodeSelectCreator("s.") + "s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId UNION " + nodeSelectCreator("SN.") + "AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? UNION " + nodeSelectCreator("SN.") + "AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode is null ORDER BY NodeName");
|
||||
private static final de.steamwar.sql.internal.Statement getAccessibleByUserByType = new de.steamwar.sql.internal.Statement("WITH RECURSIVE RSN as (" + nodeSelectCreator("s.") + "s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId UNION " + nodeSelectCreator("SN.") + "AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? ORDER BY NodeName");
|
||||
private static final de.steamwar.sql.internal.Statement getAllSchematicsAccessibleByUser = new de.steamwar.sql.internal.Statement("WITH RECURSIVE RSN as (" + nodeSelectCreator("s.") + "s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId UNION " + nodeSelectCreator("SN.") + "AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN ORDER BY NodeName");
|
||||
private static final de.steamwar.sql.internal.Statement isSchematicAccessibleForUser = new de.steamwar.sql.internal.Statement("WITH RECURSIVE RSN AS (" + nodeSelectCreator("") + "WHERE NodeId = ? UNION " + nodeSelectCreator("SN.") + "SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT COUNT(RSN.NodeId) AS `Accessible` FROM RSN LEFT Join NodeMember NM On NM.NodeId = RSN.NodeId WHERE NodeOwner = ? OR UserId = ? LIMIT 1");
|
||||
private static final de.steamwar.sql.internal.Statement getAllParentsOfNode = new de.steamwar.sql.internal.Statement("WITH RECURSIVE RSN AS (" + nodeSelectCreator("") + "WHERE NodeId = ? UNION " + nodeSelectCreator("SN.") + "SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT * FROM RSN ORDER BY NodeName");
|
||||
private static final de.steamwar.sql.internal.Statement countNodes = new de.steamwar.sql.internal.Statement("SELECT COUNT(NodeId) AS 'count' FROM SchematicNode");
|
||||
private static final de.steamwar.sql.internal.Statement updateDB = new de.steamwar.sql.internal.Statement("UPDATE SchematicNode SET NodeName = ?, NodeOwner = ?, ParentNode = ?, NodeItem = ?, NodeType = ?, NodeRank = ?, ReplaceColor = ?, AllowReplay = ? WHERE NodeId = ?");
|
||||
private static final de.steamwar.sql.internal.Statement updateDatabase = new de.steamwar.sql.internal.Statement("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?");
|
||||
private static final de.steamwar.sql.internal.Statement selSchemData = new de.steamwar.sql.internal.Statement("SELECT NodeData FROM SchematicNode WHERE NodeId = ?");
|
||||
private static final de.steamwar.sql.internal.Statement deleteNode = new de.steamwar.sql.internal.Statement("DELETE FROM SchematicNode WHERE NodeId = ?");
|
||||
private static final de.steamwar.sql.internal.Statement schemElo = new de.steamwar.sql.internal.Statement("SELECT Elo FROM SchemElo WHERE SchemId = ? AND Season = ?");
|
||||
|
||||
private static final de.steamwar.sql.internal.Statement.ResultSetUser<List<SchematicNode>> toSchematicList = rs -> {
|
||||
List<SchematicNode> nodes = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
nodes.add(nodeFromResultSet(rs));
|
||||
}
|
||||
return nodes;
|
||||
};
|
||||
private static final de.steamwar.sql.internal.Statement.ResultSetUser<SchematicNode> toSchematicNode = rs -> {
|
||||
if (rs.next()) {
|
||||
return nodeFromResultSet(rs);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
private static SchematicNode nodeFromResultSet(ResultSet rs) throws SQLException {
|
||||
Integer parent = rs.getInt("ParentNode");
|
||||
if(rs.wasNull()) {
|
||||
parent = null;
|
||||
}
|
||||
String type = rs.getString("NodeType");
|
||||
return new SchematicNode(
|
||||
rs.getInt("NodeId"),
|
||||
rs.getInt("NodeOwner"),
|
||||
rs.getString("NodeName"),
|
||||
parent,
|
||||
rs.getString("NodeItem"),
|
||||
type,
|
||||
type == null,
|
||||
rs.getInt("NodeRank"),
|
||||
rs.getTimestamp("LastUpdate"),
|
||||
rs.getBoolean("NodeFormat"),
|
||||
rs.getBoolean("ReplaceColor"),
|
||||
rs.getBoolean("AllowReplay")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createSchematicNode(int owner, String name, Integer parent, String type, String item) {
|
||||
createNode.update(name, owner, parent, type, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchematicNode getSchematicNode(int owner, String name, Integer parent) {
|
||||
|
||||
if(parent == null) {
|
||||
return getSchematicNode_Null.select(toSchematicNode, owner, name);
|
||||
} else {
|
||||
return getSchematicNode.select(toSchematicNode, owner, name, parent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SchematicNode> getSchematicNodeInNode(Integer parent) {
|
||||
if(parent == null) {
|
||||
return getSchematicsInNode_Null.select(toSchematicList);
|
||||
}else {
|
||||
return getSchematicsInNode.select(toSchematicList, parent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SchematicNode> getSchematicDirectoryInNode(Integer parent) {
|
||||
if(parent == null) {
|
||||
return getDirsInNode_Null.select(toSchematicList);
|
||||
}else {
|
||||
return getDirsInNode.select(toSchematicList, parent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchematicNode getSchematicDirectory(String name, Integer parent) {
|
||||
Statement.ResultSetUser<SchematicNode> user = rs -> {
|
||||
while (rs.next()) {
|
||||
SchematicNode node = nodeFromResultSet(rs);
|
||||
if(node.isDir())
|
||||
return node;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
if(parent == null) {
|
||||
return getSchematicDirectory_Null.select(user, name);
|
||||
}else {
|
||||
return getSchematicDirectory.select(user, name, parent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchematicNode getSchematicNode(String name, Integer parent) {
|
||||
if(parent == null) {
|
||||
return getSchematicNodeO_Null.select(toSchematicNode, name);
|
||||
}else {
|
||||
return getSchematicNodeO.select(toSchematicNode, name, parent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchematicNode getSchematicNode(int id) {
|
||||
return getSchematicNodeId.select(rs -> {
|
||||
if (!rs.next())
|
||||
return null;
|
||||
return nodeFromResultSet(rs);
|
||||
}, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SchematicNode> getAccessibleSchematicsOfTypeInParent(int owner, String schemType, Integer parent) {
|
||||
if(parent == null || parent == 0) {
|
||||
return getAccessibleByUserByTypeInNode_Null.select(toSchematicList, owner, owner, schemType);
|
||||
} else {
|
||||
return getAccessibleByUserByTypeInNode.select(toSchematicList, owner, owner, schemType, parent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SchematicNode> getAllAccessibleSchematicsOfType(int user, String schemType) {
|
||||
return getAccessibleByUserByType.select(toSchematicList, user, user, schemType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SchematicNode> getAllSchematicsOfType(int owner, String schemType) {
|
||||
return getAllSchemsOfTypeOwner.select(toSchematicList, owner, schemType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SchematicNode> getAllSchematicsOfType(String schemType) {
|
||||
return getAllSchemsOfType.select(toSchematicList, schemType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SchematicNode> getSchematicsAccessibleByUser(int user, Integer parent) {
|
||||
if (parent != null && parent != 0) {
|
||||
if(Boolean.TRUE.equals(isSchematicAccessibleForUser.select(rs -> {
|
||||
rs.next();
|
||||
return rs.getInt("Accessible") > 0;
|
||||
}, parent, user, user))) {
|
||||
return getSchematicNodeInNode(parent);
|
||||
}
|
||||
} else {
|
||||
return getAccessibleByUser.select(rs -> {
|
||||
List<SchematicNode> nodes = new ArrayList<>();
|
||||
while(rs.next())
|
||||
nodes.add(nodeFromResultSet(rs));
|
||||
return nodes;
|
||||
}, user, user, user, user);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SchematicNode> getAllSchematicsAccessibleByUser(int user) {
|
||||
return getAllSchematicsAccessibleByUser.select(toSchematicList, user, user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SchematicNode> getAllParentsOfNode(int node) {
|
||||
return getAllParentsOfNode.select(toSchematicList, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer countNodes() {
|
||||
return countNodes.select(rs -> {
|
||||
if (rs.next()) {
|
||||
return rs.getInt("count");
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSchematicNode(SchematicNode node) {
|
||||
updateDB.update(
|
||||
node.getName(),
|
||||
node.getOwner(),
|
||||
node.getParent(),
|
||||
node.getItem(),
|
||||
node.getType(),
|
||||
node.getRankUnsafe(),
|
||||
node.replaceColor(),
|
||||
node.allowReplay(),
|
||||
node.getId()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteSchematicNode(SchematicNode node) {
|
||||
deleteNode.update(node.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getSchematicData(SchematicNode node) throws IOException {
|
||||
try {
|
||||
return selSchemData.select(rs -> {
|
||||
rs.next();
|
||||
Blob schemData = rs.getBlob("NodeData");
|
||||
if(schemData == null) {
|
||||
throw new SecurityException("SchemData is null");
|
||||
}
|
||||
try {
|
||||
return new GZIPInputStream(schemData.getBinaryStream());
|
||||
} catch (IOException e) {
|
||||
throw new SecurityException("SchemData is wrong", e);
|
||||
}
|
||||
}, node.getId());
|
||||
} catch (Exception e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveSchematicNode(SchematicNode node, InputStream blob, boolean newFormat) {
|
||||
updateDatabase.update(blob, newFormat, node.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSchematicElo(SchematicNode node, int season) {
|
||||
return schemElo.select(rs -> {
|
||||
if(rs.next()) {
|
||||
return rs.getInt("Elo");
|
||||
}
|
||||
return 0;
|
||||
}, node.getId(), season);
|
||||
}
|
||||
}
|
@ -20,7 +20,10 @@
|
||||
package de.steamwar.sql;
|
||||
|
||||
import de.steamwar.core.Core;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
@ -60,4 +63,17 @@ public class SQLWrapperImpl implements SQLWrapper {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final String SERVER_VERSION = Bukkit.getServer().getVersion();
|
||||
|
||||
@Override
|
||||
public void additionalExceptionMetadata(StringBuilder builder) {
|
||||
builder.append("\nPlayers: ");
|
||||
for(Player player : Bukkit.getOnlinePlayers())
|
||||
builder.append(player.getName()).append(" ");
|
||||
builder.append("\nWorlds: ");
|
||||
for(World world : Bukkit.getWorlds())
|
||||
builder.append(world.getName()).append(" ");
|
||||
builder.append("\nServer: ").append(SERVER_VERSION);
|
||||
}
|
||||
}
|
||||
|
@ -1,47 +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 org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class SWException {
|
||||
private SWException(){}
|
||||
|
||||
private static final String serverVersion = Bukkit.getServer().getVersion();
|
||||
private static final String cwd = System.getProperty("user.dir");
|
||||
private static final String server = new File(cwd).getName();
|
||||
|
||||
public static void log(String message, String stacktrace){
|
||||
StringBuilder msgBuilder = new StringBuilder(message).append("\nPlayers: ");
|
||||
for(Player player : Bukkit.getOnlinePlayers())
|
||||
msgBuilder.append(player.getName()).append(" ");
|
||||
msgBuilder.append("\nWorlds: ");
|
||||
for(World world : Bukkit.getWorlds())
|
||||
msgBuilder.append(world.getName()).append(" ");
|
||||
msgBuilder.append("\nServer: ").append(serverVersion);
|
||||
msgBuilder.append("\nCWD: ").append(cwd);
|
||||
|
||||
Provider.impl.logException(server, msgBuilder.toString(), stacktrace);
|
||||
}
|
||||
}
|
99
SpigotCore_Main/src/de/steamwar/sql/SchematicData.java
Normale Datei
99
SpigotCore_Main/src/de/steamwar/sql/SchematicData.java
Normale Datei
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2022 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 de.steamwar.sql.internal.Statement;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.Blob;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class SchematicData {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private static final Statement updateDatabase = new Statement("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?");
|
||||
private static final Statement selSchemData = new Statement("SELECT NodeData FROM SchematicNode WHERE NodeId = ?");
|
||||
|
||||
private final SchematicNode node;
|
||||
|
||||
public SchematicData(SchematicNode node) {
|
||||
this.node = node;
|
||||
if(node.isDir())
|
||||
throw new SecurityException("Node is Directory");
|
||||
}
|
||||
|
||||
public InputStream schemData() throws IOException {
|
||||
try {
|
||||
return selSchemData.select(rs -> {
|
||||
rs.next();
|
||||
Blob schemData = rs.getBlob("NodeData");
|
||||
if(schemData == null) {
|
||||
throw new SecurityException("SchemData is null");
|
||||
}
|
||||
try {
|
||||
return new GZIPInputStream(schemData.getBinaryStream());
|
||||
} catch (IOException e) {
|
||||
throw new SecurityException("SchemData is wrong", e);
|
||||
}
|
||||
}, node.getId());
|
||||
} catch (Exception e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Clipboard load() throws IOException, NoClipboardException {
|
||||
return WorldEditWrapper.impl.getClipboard(schemData(), node.getSchemFormat());
|
||||
}
|
||||
|
||||
public void loadToPlayer(Player player) throws IOException, NoClipboardException {
|
||||
WorldEditWrapper.impl.setPlayerClipboard(player, schemData(), node.getSchemFormat());
|
||||
}
|
||||
|
||||
public void saveFromPlayer(Player player) throws IOException, NoClipboardException {
|
||||
saveFromPlayer(player, Core.getVersion() > 12);
|
||||
}
|
||||
|
||||
public void saveFromPlayer(Player player, boolean newFormat) throws IOException, NoClipboardException {
|
||||
updateDatabase(WorldEditWrapper.impl.getPlayerClipboard(player, newFormat), newFormat);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void saveFromBytes(byte[] bytes, boolean newFormat) {
|
||||
updateDatabase(new ByteArrayInputStream(bytes), newFormat);
|
||||
}
|
||||
|
||||
private void updateDatabase(InputStream blob, boolean newFormat) {
|
||||
updateDatabase.update(blob, newFormat, node.getId());
|
||||
node.setNodeFormat(newFormat);
|
||||
}
|
||||
}
|
@ -1,528 +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 de.steamwar.core.Core;
|
||||
import de.steamwar.core.WorldEditWrapper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class SchematicNode {
|
||||
|
||||
public static SchematicNode createSchematic(int owner, String name, Integer parent) {
|
||||
return createSchematicNode(owner, name, parent, SchematicType.Normal.toDB(), "");
|
||||
}
|
||||
|
||||
public static SchematicNode createSchematicDirectory(int owner, String name, Integer parent) {
|
||||
return createSchematicNode(owner, name, parent, null, "");
|
||||
}
|
||||
|
||||
public static SchematicNode createSchematicNode(int owner, String name, Integer parent, String type, String item) {
|
||||
if (parent != null && parent == 0)
|
||||
parent = null;
|
||||
Provider.impl.createSchematicNode(owner, name, parent, type, item);
|
||||
return getSchematicNode(owner, name, parent);
|
||||
}
|
||||
|
||||
public static SchematicNode getSchematicNode(int owner, String name, SchematicNode parent) {
|
||||
return getSchematicNode(owner, name, parent.getId());
|
||||
}
|
||||
|
||||
public SchematicNode(
|
||||
int id,
|
||||
int owner,
|
||||
String name,
|
||||
Integer parent,
|
||||
String item,
|
||||
String type,
|
||||
boolean isDir,
|
||||
int rank,
|
||||
Timestamp lastUpdate,
|
||||
boolean schemFormat,
|
||||
boolean replaceColor,
|
||||
boolean allowReplay
|
||||
) {
|
||||
this.id = id;
|
||||
this.owner = owner;
|
||||
this.name = name;
|
||||
this.parent = parent;
|
||||
this.item = item;
|
||||
this.type = type;
|
||||
this.lastUpdate = lastUpdate;
|
||||
this.isDir = isDir;
|
||||
if (!isDir) {
|
||||
this.schemFormat = schemFormat;
|
||||
this.rank = rank;
|
||||
this.replaceColor = replaceColor;
|
||||
this.allowReplay = allowReplay;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<SchematicNode> getSchematicNodeInNode(SchematicNode parent) {
|
||||
return getSchematicNodeInNode(parent.getId());
|
||||
}
|
||||
|
||||
public static SchematicNode getSchematicDirectory(String name, SchematicNode parent) {
|
||||
return getSchematicDirectory(name, parent.getId());
|
||||
}
|
||||
|
||||
public static SchematicNode getSchematicNode(int owner, String name, Integer parent) {
|
||||
if (parent != null && parent == 0) {
|
||||
parent = null;
|
||||
}
|
||||
return Provider.impl.getSchematicNode(owner, name, parent);
|
||||
}
|
||||
|
||||
public static List<SchematicNode> getSchematicNodeInNode(Integer parent) {
|
||||
if(parent != null && parent == 0) {
|
||||
parent = null;
|
||||
}
|
||||
return Provider.impl.getSchematicNodeInNode(parent);
|
||||
}
|
||||
|
||||
public static List<SchematicNode> getSchematicDirectoryInNode(Integer parent) {
|
||||
if(parent != null && parent == 0) {
|
||||
parent = null;
|
||||
}
|
||||
return Provider.impl.getSchematicDirectoryInNode(parent);
|
||||
}
|
||||
|
||||
public static SchematicNode getSchematicDirectory(String name, Integer parent) {
|
||||
if(parent != null && parent == 0) {
|
||||
parent = null;
|
||||
}
|
||||
return Provider.impl.getSchematicDirectory(name, parent);
|
||||
}
|
||||
|
||||
public static SchematicNode getSchematicNode(String name, Integer parent) {
|
||||
if(parent != null && parent == 0) {
|
||||
parent = null;
|
||||
}
|
||||
return Provider.impl.getSchematicNode(name, parent);
|
||||
}
|
||||
|
||||
public static SchematicNode getSchematicNode(int id) {
|
||||
return Provider.impl.getSchematicNode(id);
|
||||
}
|
||||
|
||||
public static List<SchematicNode> getAccessibleSchematicsOfTypeInParent(int owner, String schemType, Integer parent) {
|
||||
return Provider.impl.getAccessibleSchematicsOfTypeInParent(owner, schemType, parent);
|
||||
}
|
||||
|
||||
public static List<SchematicNode> getAllAccessibleSchematicsOfType(int user, String schemType) {
|
||||
return Provider.impl.getAllAccessibleSchematicsOfType(user, schemType);
|
||||
}
|
||||
|
||||
public static List<SchematicNode> getAllSchematicsOfType(int owner, String schemType) {
|
||||
return Provider.impl.getAllSchematicsOfType(owner, schemType);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static List<SchematicNode> getAllSchematicsOfType(String schemType) {
|
||||
return Provider.impl.getAllSchematicsOfType(schemType);
|
||||
}
|
||||
|
||||
public static List<SchematicNode> getAllSchematicsOfType(SchematicType schemType) {
|
||||
return Provider.impl.getAllSchematicsOfType(schemType.toDB());
|
||||
}
|
||||
|
||||
public static List<SchematicNode> deepGet(Integer parent, Predicate<SchematicNode> filter) {
|
||||
List<SchematicNode> finalList = new ArrayList<>();
|
||||
List<SchematicNode> nodes = SchematicNode.getSchematicNodeInNode(parent);
|
||||
nodes.forEach(node -> {
|
||||
if (node.isDir()) {
|
||||
finalList.addAll(deepGet(node.getId(), filter));
|
||||
} else {
|
||||
if (filter.test(node))
|
||||
finalList.add(node);
|
||||
}
|
||||
});
|
||||
return finalList;
|
||||
}
|
||||
|
||||
public static List<SchematicNode> getSchematicsAccessibleByUser(int user, Integer parent) {
|
||||
return Provider.impl.getSchematicsAccessibleByUser(user, parent);
|
||||
}
|
||||
|
||||
public static List<SchematicNode> getAllSchematicsAccessibleByUser(int user) {
|
||||
return Provider.impl.getAllSchematicsAccessibleByUser(user);
|
||||
}
|
||||
|
||||
public static List<SchematicNode> getAllParentsOfNode(SchematicNode node) {
|
||||
return getAllParentsOfNode(node.getId());
|
||||
}
|
||||
|
||||
public static List<SchematicNode> getAllParentsOfNode(int node) {
|
||||
return Provider.impl.getAllParentsOfNode(node);
|
||||
}
|
||||
|
||||
public static SchematicNode getNodeFromPath(SteamwarUser user, String s) {
|
||||
if (s.startsWith("/")) {
|
||||
s = s.substring(1);
|
||||
}
|
||||
if (s.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
if (s.contains("/")) {
|
||||
String[] layers = s.split("/");
|
||||
SchematicNode currentNode = null;
|
||||
for (int i = 0; i < layers.length; i++) {
|
||||
int finalI = i;
|
||||
Optional<SchematicNode> node;
|
||||
if (currentNode == null) {
|
||||
node = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node1 -> node1.getName().equals(layers[finalI])).findAny();
|
||||
} else {
|
||||
node = Optional.ofNullable(SchematicNode.getSchematicNode(layers[i], currentNode.getId()));
|
||||
}
|
||||
if (!node.isPresent()) {
|
||||
return null;
|
||||
} else {
|
||||
currentNode = node.get();
|
||||
if (!currentNode.isDir() && i != layers.length - 1) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return currentNode;
|
||||
} else {
|
||||
String finalS = s;
|
||||
return SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node1 -> node1.getName().equals(finalS)).findAny().orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
private final int id;
|
||||
private final int owner;
|
||||
private String name;
|
||||
private Integer parent;
|
||||
private String item;
|
||||
private String type;
|
||||
private boolean replaceColor;
|
||||
private boolean allowReplay;
|
||||
private boolean schemFormat;
|
||||
private int rank;
|
||||
private Timestamp lastUpdate;
|
||||
private final boolean isDir;
|
||||
private Map<Integer, String> brCache = new HashMap<>();
|
||||
|
||||
public static List<SchematicNode> filterSchems(int user, Predicate<SchematicNode> filter) {
|
||||
List<SchematicNode> finalList = new ArrayList<>();
|
||||
List<SchematicNode> nodes = SchematicNode.getSchematicsAccessibleByUser(user, null);
|
||||
nodes.forEach(node -> {
|
||||
if (node.isDir()) {
|
||||
finalList.addAll(deepGet(node.getId(), filter));
|
||||
} else {
|
||||
if (filter.test(node))
|
||||
finalList.add(node);
|
||||
}
|
||||
});
|
||||
return finalList;
|
||||
}
|
||||
|
||||
public static Integer countNodes() {
|
||||
return Provider.impl.countNodes();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
updateDB();
|
||||
}
|
||||
|
||||
public Integer getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(Integer parent) {
|
||||
this.parent = parent;
|
||||
updateDB();
|
||||
}
|
||||
|
||||
public String getItem() {
|
||||
if (item.isEmpty()) {
|
||||
return isDir ? "CHEST" : "CAULDRON_ITEM";
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public void setItem(String item) {
|
||||
this.item = item;
|
||||
updateDB();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setType(String type) {
|
||||
if(isDir)
|
||||
throw new SecurityException("Node is Directory");
|
||||
this.type = type;
|
||||
updateDB();
|
||||
}
|
||||
|
||||
public boolean isDir() {
|
||||
return isDir;
|
||||
}
|
||||
|
||||
public boolean getSchemFormat() {
|
||||
if(isDir)
|
||||
throw new SecurityException("Node is Directory");
|
||||
return schemFormat;
|
||||
}
|
||||
|
||||
public int getRank() {
|
||||
if(isDir)
|
||||
throw new SecurityException("Node is Directory");
|
||||
return rank;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getRankUnsafe() {
|
||||
return rank;
|
||||
}
|
||||
|
||||
public void setRank(int rank) {
|
||||
if(isDir)
|
||||
throw new SecurityException("Node is Directory");
|
||||
this.rank = rank;
|
||||
}
|
||||
|
||||
public SchematicType getSchemtype() {
|
||||
if(isDir())
|
||||
throw new SecurityException("Is Directory");
|
||||
return SchematicType.fromDB(type);
|
||||
}
|
||||
|
||||
public void setSchemtype(SchematicType type) {
|
||||
if(isDir())
|
||||
throw new SecurityException("Is Directory");
|
||||
this.type = type.toDB();
|
||||
updateDB();
|
||||
}
|
||||
|
||||
public SchematicNode getParentNode() {
|
||||
if(parent == null) return null;
|
||||
return SchematicNode.getSchematicNode(parent);
|
||||
}
|
||||
|
||||
public boolean accessibleByUser(int user) {
|
||||
return NodeMember.getNodeMember(id, user) != null;
|
||||
}
|
||||
|
||||
public Set<NodeMember> getMembers() {
|
||||
return NodeMember.getNodeMembers(id);
|
||||
}
|
||||
|
||||
public Timestamp getLastUpdate() {
|
||||
return lastUpdate;
|
||||
}
|
||||
|
||||
public String generateBreadcrumbs(SteamwarUser user) {
|
||||
return brCache.computeIfAbsent(user.getId(), integer -> generateBreadcrumbs("/", user));
|
||||
}
|
||||
|
||||
public String generateBreadcrumbs(String split, SteamwarUser user) {
|
||||
StringBuilder builder = new StringBuilder(getName());
|
||||
SchematicNode currentNode = this;
|
||||
if (currentNode.isDir()) builder.append("/");
|
||||
final Set<NodeMember> nodeMembers = NodeMember.getSchematics(user.getId());
|
||||
AtomicInteger i = new AtomicInteger();
|
||||
i.set(currentNode.getId());
|
||||
while (currentNode.getParentNode() != null && nodeMembers.stream().noneMatch(nodeMember -> nodeMember.getNode() == i.get())) {
|
||||
currentNode = currentNode.getParentNode();
|
||||
i.set(currentNode.getId());
|
||||
builder.insert(0, split)
|
||||
.insert(0, currentNode.getName());
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private void updateDB() {
|
||||
Provider.impl.updateSchematicNode(this);
|
||||
this.lastUpdate = Timestamp.from(Instant.now());
|
||||
this.brCache.clear();
|
||||
TAB_CACHE.clear();
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
Provider.impl.deleteSchematicNode(this);
|
||||
}
|
||||
|
||||
public InputStream schemData() throws IOException {
|
||||
return Provider.impl.getSchematicData(this);
|
||||
}
|
||||
|
||||
public Clipboard load() throws IOException, NoClipboardException {
|
||||
if(isDir)
|
||||
throw new SecurityException("Node is Directory");
|
||||
return WorldEditWrapper.impl.getClipboard(schemData(), schemFormat);
|
||||
}
|
||||
|
||||
public void loadToPlayer(Player player) throws IOException, NoClipboardException {
|
||||
if(isDir)
|
||||
throw new SecurityException("Node is Directory");
|
||||
WorldEditWrapper.impl.setPlayerClipboard(player, schemData(), schemFormat);
|
||||
}
|
||||
|
||||
public void saveFromPlayer(Player player) throws IOException, NoClipboardException {
|
||||
if(isDir)
|
||||
throw new SecurityException("Node is Directory");
|
||||
saveFromPlayer(player, Core.getVersion() > 12);
|
||||
}
|
||||
|
||||
public void saveFromBytes(byte[] bytes, boolean newFormat) {
|
||||
if(isDir)
|
||||
throw new SecurityException("Node is Directory");
|
||||
updateDatabase(new ByteArrayInputStream(bytes), newFormat);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private void updateDatabase(InputStream blob, boolean newFormat) {
|
||||
Provider.impl.saveSchematicNode(this, blob, newFormat);
|
||||
schemFormat = newFormat;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof SchematicNode))
|
||||
return false;
|
||||
|
||||
SchematicNode node = (SchematicNode) obj;
|
||||
return node.getId() == id;
|
||||
}
|
||||
|
||||
protected static final Map<Integer, Map<String, List<String>>> TAB_CACHE = new HashMap<>();
|
||||
|
||||
static {
|
||||
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), TAB_CACHE::clear, 20L * 30, 20L * 30);
|
||||
}
|
||||
|
||||
public static List<String> getNodeTabcomplete(SteamwarUser user, String s) {
|
||||
boolean sws = s.startsWith("/");
|
||||
if (sws) {
|
||||
s = s.substring(1);
|
||||
}
|
||||
int index = s.lastIndexOf("/");
|
||||
String cacheKey = index == -1 ? "" : s.substring(0, index);
|
||||
if(TAB_CACHE.containsKey(user.getId()) && TAB_CACHE.get(user.getId()).containsKey(cacheKey)) {
|
||||
return new ArrayList<>(TAB_CACHE.get(user.getId()).get(cacheKey));
|
||||
}
|
||||
List<String> list = new ArrayList<>();
|
||||
if (s.contains("/")) {
|
||||
String preTab = s.substring(0, s.lastIndexOf("/") + 1);
|
||||
SchematicNode pa = SchematicNode.getNodeFromPath(user, preTab);
|
||||
if (pa == null) return Collections.emptyList();
|
||||
List<SchematicNode> nodes = SchematicNode.getSchematicNodeInNode(pa);
|
||||
nodes.forEach(node -> list.add((sws ? "/" : "") + node.generateBreadcrumbs(user)));
|
||||
} else {
|
||||
List<SchematicNode> nodes = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0);
|
||||
nodes.forEach(node -> list.add((sws ? "/" : "") + node.getName() + (node.isDir() ? "/" : "")));
|
||||
}
|
||||
list.remove("//copy");
|
||||
TAB_CACHE.computeIfAbsent(user.getId(), integer -> new HashMap<>()).putIfAbsent(cacheKey, list);
|
||||
return list;
|
||||
}
|
||||
|
||||
private static final List<String> FORBIDDEN_NAMES = Collections.unmodifiableList(Arrays.asList("public"));
|
||||
public static boolean invalidSchemName(String[] layers) {
|
||||
for (String layer : layers) {
|
||||
if (layer.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
if (layer.contains("/") ||
|
||||
layer.contains("\\") ||
|
||||
layer.contains("<") ||
|
||||
layer.contains(">") ||
|
||||
layer.contains("^") ||
|
||||
layer.contains("°") ||
|
||||
layer.contains("'") ||
|
||||
layer.contains("\"") ||
|
||||
layer.contains(" ")) {
|
||||
return true;
|
||||
}
|
||||
if(FORBIDDEN_NAMES.contains(layer.toLowerCase())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean replaceColor() {
|
||||
return replaceColor;
|
||||
}
|
||||
|
||||
public void setReplaceColor(boolean replaceColor) {
|
||||
if(isDir())
|
||||
throw new SecurityException("Is Directory");
|
||||
this.replaceColor = replaceColor;
|
||||
updateDB();
|
||||
}
|
||||
|
||||
public boolean allowReplay() {
|
||||
return allowReplay;
|
||||
}
|
||||
|
||||
public void setAllowReplay(boolean allowReplay) {
|
||||
if(isDir())
|
||||
throw new SecurityException("Is Directory");
|
||||
this.allowReplay = allowReplay;
|
||||
updateDB();
|
||||
}
|
||||
|
||||
public int getElo(int season) {
|
||||
return Provider.impl.getSchematicElo(this, season);
|
||||
}
|
||||
}
|
@ -1,54 +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.Calendar;
|
||||
|
||||
public class Season {
|
||||
private Season() {}
|
||||
|
||||
public static int getSeason() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
int yearIndex = calendar.get(Calendar.MONTH) / 4;
|
||||
return (calendar.get(Calendar.YEAR) * 3 + yearIndex);
|
||||
}
|
||||
|
||||
public static String getSeasonStart() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
return calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) / 4 * 3 + 1) + "-1";
|
||||
}
|
||||
|
||||
public static String convertSeasonToString(int season){
|
||||
if (season == -1) return "";
|
||||
int yearSeason = season % 3;
|
||||
int year = (season - yearSeason) / 3;
|
||||
return String.format("%d-%d", year, yearSeason);
|
||||
}
|
||||
|
||||
public static int convertSeasonToNumber(String season){
|
||||
if (season.isEmpty()) return -1;
|
||||
String[] split = season.split("-");
|
||||
try {
|
||||
return Integer.parseInt(split[0]) * 3 + Integer.parseInt(split[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,294 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2022 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 de.steamwar.core.WorldEditWrapper;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class StandaloneProvider implements Provider {
|
||||
public StandaloneProvider() {
|
||||
nodesToPath.put(-1, schematicDir.toPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasEventTeam(int teamID, int eventID) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Team> getEventTeams(int eventID) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Event> getTeamEvents(int teamID) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createDownloadLink(int nodeId, String hash) {}
|
||||
|
||||
@Override
|
||||
public Punishment getPunishmentOfPlayer(int user, Punishment.PunishmentType type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Punishment.PunishmentType, Punishment> getPunishmentsOfPlayer(int user) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logException(String server, String message, String stacktrace) {}
|
||||
|
||||
@Override
|
||||
public Team getTeam(int id) {
|
||||
return new Team(0, "TEST", "TestAlliancePleaseIgnore", "c");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getTeamMembers(Team team) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private final Map<Integer, Map<String, String>> configs = new HashMap<>();
|
||||
@Override
|
||||
public String getConfig(int player, String config) {
|
||||
return configs.computeIfAbsent(player, player1 -> new HashMap<>()).get(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePlayerConfig(int id, String config, String value) {
|
||||
configs.computeIfAbsent(id, player -> new HashMap<>()).put(config, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePlayerConfig(int id, String config) {
|
||||
configs.computeIfAbsent(id, player -> new HashMap<>()).remove(config);
|
||||
}
|
||||
|
||||
private int nodeId = 1;
|
||||
private final File schematicDir = WorldEditWrapper.getWorldEditPlugin().getWorldEdit().getWorkingDirectoryFile(WorldEditWrapper.getWorldEditPlugin().getWorldEdit().getConfiguration().saveDir);
|
||||
private final Map<Integer, SchematicNode> nodeById = new HashMap<>();
|
||||
private final Map<Integer, List<SchematicNode>> nodesByParent = new HashMap<>();
|
||||
private final Map<Integer, Path> nodesToPath = new HashMap<>();
|
||||
|
||||
private List<SchematicNode> mapDir(Integer id) {
|
||||
try (Stream<Path> stream = Files.list(id==null?schematicDir.toPath():nodesToPath.get(id))) {
|
||||
List<SchematicNode> list = stream.map(path -> {
|
||||
File file = path.toFile();
|
||||
SchematicNode node = new SchematicNode(
|
||||
nodeId++,
|
||||
0,
|
||||
file.isDirectory()?file.getName():file.getName().substring(file.getName().lastIndexOf(".")),
|
||||
null,
|
||||
"",
|
||||
"normal",
|
||||
file.isDirectory(),
|
||||
0,
|
||||
Timestamp.from(Instant.now()),
|
||||
file.getName().endsWith(".schem"),
|
||||
false,
|
||||
false
|
||||
);
|
||||
nodesToPath.put(node.getId(), path);
|
||||
nodeById.put(node.getId(), node);
|
||||
return node;
|
||||
}).collect(Collectors.toList());
|
||||
nodesByParent.putIfAbsent(id == null?-1:id, list);
|
||||
return list;
|
||||
} catch (IOException e) {
|
||||
throw new SecurityException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createSchematicNode(int owner, String name, Integer parent, String type, String item) {
|
||||
boolean isDir = type == null;
|
||||
Path p = null;
|
||||
try {
|
||||
if(isDir) {
|
||||
p = Files.createDirectory(new File(nodesToPath.get(parent == null?-1:parent).toFile(), name).toPath());
|
||||
} else {
|
||||
p = Files.createFile(new File(nodesToPath.get(parent == null?-1:parent).toFile(), name + ".schem").toPath());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new SecurityException(e);
|
||||
}
|
||||
|
||||
File file = p.toFile();
|
||||
int id = nodeId++;
|
||||
nodesToPath.put(id, p);
|
||||
SchematicNode node = new SchematicNode(
|
||||
nodeId++,
|
||||
0,
|
||||
file.isDirectory()?file.getName():file.getName().substring(file.getName().lastIndexOf(".")),
|
||||
null,
|
||||
"",
|
||||
"normal",
|
||||
file.isDirectory(),
|
||||
0,
|
||||
Timestamp.from(Instant.now()),
|
||||
file.getName().endsWith(".schem"),
|
||||
true,
|
||||
true
|
||||
);
|
||||
nodeById.put(id, node);
|
||||
nodesByParent.get(parent == null?-1:parent).add(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchematicNode getSchematicNode(int owner, String name, Integer parent) {
|
||||
return nodesByParent.get(parent).stream().filter(node -> node.getName().equals(name)).findAny().orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SchematicNode> getSchematicNodeInNode(Integer parent) {
|
||||
return nodesByParent.computeIfAbsent(parent==null?-1:parent, integer -> mapDir(parent));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SchematicNode> getSchematicDirectoryInNode(Integer parent) {
|
||||
return getSchematicNodeInNode(parent).stream().filter(SchematicNode::isDir).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchematicNode getSchematicDirectory(String name, Integer parent) {
|
||||
return getSchematicDirectoryInNode(parent).stream().filter(node -> node.getName().equals(name)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchematicNode getSchematicNode(String name, Integer parent) {
|
||||
return getSchematicNodeInNode(parent).stream().filter(node -> name.equals(node.getName())).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchematicNode getSchematicNode(int id) {
|
||||
return nodeById.getOrDefault(id, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SchematicNode> getAccessibleSchematicsOfTypeInParent(int ignored, String schemType, Integer parent) {
|
||||
return getSchematicDirectoryInNode(parent).stream().filter(node -> node.getType().equals(schemType)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SchematicNode> getAllAccessibleSchematicsOfType(int ignored, String schemType) {
|
||||
return getAllSchematicsAccessibleByUser(ignored).stream().filter(node -> schemType.equals(node.getType())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SchematicNode> getAllSchematicsOfType(int ignored, String schemType) {
|
||||
return getAllAccessibleSchematicsOfType(ignored, schemType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SchematicNode> getAllSchematicsOfType(String schemType) {
|
||||
return getAllAccessibleSchematicsOfType(-1, schemType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SchematicNode> getSchematicsAccessibleByUser(int ignored, Integer parent) {
|
||||
return getSchematicNodeInNode(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SchematicNode> getAllSchematicsAccessibleByUser(int user) {
|
||||
return nodesByParent.values().stream().reduce((schematicNodes, schematicNodes2) -> {
|
||||
schematicNodes.addAll(schematicNodes2);
|
||||
return schematicNodes;
|
||||
}).orElse(new ArrayList<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SchematicNode> getAllParentsOfNode(int node) {
|
||||
List<SchematicNode> allSchematicsAccessibleByUser = getAllSchematicsAccessibleByUser(node);
|
||||
allSchematicsAccessibleByUser.remove(getSchematicNode(node));
|
||||
return allSchematicsAccessibleByUser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer countNodes() {
|
||||
return nodesByParent.values().stream().map(List::size).reduce((Integer::sum)).orElse(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSchematicNode(SchematicNode node) {
|
||||
try {
|
||||
Path newPath = new File(nodesToPath.get(node.getParent() == null?-1:node.getParent()).toFile(), node.getName() + (node.getSchemFormat()?".schem":".schematic")).toPath();
|
||||
Files.move(nodesToPath.get(node.getId()), newPath);
|
||||
nodesToPath.put(node.getId(), newPath);
|
||||
} catch (IOException e) {
|
||||
throw new SecurityException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteSchematicNode(SchematicNode node) {
|
||||
try {
|
||||
Files.deleteIfExists(nodesToPath.get(node.getId()));
|
||||
nodeById.remove(node.getId());
|
||||
nodesByParent.get(node.getParent() == null?-1:node.getId()).remove(node);
|
||||
nodesToPath.remove(node.getId());
|
||||
} catch (IOException e) {
|
||||
throw new SecurityException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getSchematicData(SchematicNode node) throws IOException {
|
||||
return new GZIPInputStream(Files.newInputStream(nodesToPath.get(node.getId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveSchematicNode(SchematicNode node, InputStream blob, boolean newFormat) {
|
||||
try (FileOutputStream stream = new FileOutputStream(nodesToPath.get(node.getId()).toFile())) {
|
||||
byte[] bucket = new byte[1024];
|
||||
int nReadBytes;
|
||||
|
||||
while((nReadBytes = blob.read(bucket, 0, bucket.length)) !=-1){
|
||||
stream.write(bucket, 0, nReadBytes);
|
||||
}
|
||||
|
||||
if(newFormat != node.getSchemFormat()) {
|
||||
nodesToPath.get(node.getId()).toFile().renameTo(new File(nodesToPath.get(node.getId()).toFile().getParentFile(), node.getName() + "." + (newFormat?".schem":"schematic")));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new SecurityException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSchematicElo(SchematicNode node, int season) {
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -1,65 +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.List;
|
||||
|
||||
public class Team {
|
||||
|
||||
private final int teamId;
|
||||
private final String teamKuerzel;
|
||||
private final String teamName;
|
||||
private final String teamColor;
|
||||
|
||||
private static final Team pub = new Team(0, "PUB", "Öffentlich", "8");
|
||||
|
||||
public Team(int teamId, String teamKuerzel, String teamName, String teamColor) {
|
||||
this.teamId = teamId;
|
||||
this.teamKuerzel = teamKuerzel;
|
||||
this.teamName = teamName;
|
||||
this.teamColor = teamColor;
|
||||
}
|
||||
|
||||
public static Team get(int id){
|
||||
if(id == 0)
|
||||
return pub;
|
||||
return Provider.impl.getTeam(id);
|
||||
}
|
||||
|
||||
public int getTeamId() {
|
||||
return teamId;
|
||||
}
|
||||
|
||||
public String getTeamKuerzel() {
|
||||
return teamKuerzel;
|
||||
}
|
||||
|
||||
public String getTeamName() {
|
||||
return teamName;
|
||||
}
|
||||
|
||||
public String getTeamColor() {
|
||||
return teamColor;
|
||||
}
|
||||
|
||||
public List<Integer> getMembers(){
|
||||
return Provider.impl.getTeamMembers(this);
|
||||
}
|
||||
}
|
@ -1,39 +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.Set;
|
||||
|
||||
public class TeamTeilnahme {
|
||||
private TeamTeilnahme(){}
|
||||
|
||||
|
||||
public static boolean nimmtTeil(int teamID, int eventID){
|
||||
return Provider.impl.hasEventTeam(teamID, eventID);
|
||||
}
|
||||
|
||||
public static Set<Team> getTeams(int eventID){
|
||||
return Provider.impl.getEventTeams(eventID);
|
||||
}
|
||||
|
||||
public static Set<Event> getEvents(int teamID){
|
||||
return Provider.impl.getTeamEvents(teamID);
|
||||
}
|
||||
}
|
@ -1,54 +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.UUID;
|
||||
|
||||
public class UserConfig {
|
||||
private UserConfig() {}
|
||||
|
||||
public static String getConfig(UUID player, String config) {
|
||||
return getConfig(SteamwarUser.get(player).getId(), config);
|
||||
}
|
||||
|
||||
public static String getConfig(int player, String config) {
|
||||
return Provider.impl.getConfig(player, config);
|
||||
}
|
||||
|
||||
public static void updatePlayerConfig(UUID uuid, String config, String value) {
|
||||
updatePlayerConfig(SteamwarUser.get(uuid).getId(), config, value);
|
||||
}
|
||||
|
||||
public static void updatePlayerConfig(int id, String config, String value) {
|
||||
if (value == null) {
|
||||
removePlayerConfig(id, config);
|
||||
return;
|
||||
}
|
||||
Provider.impl.updatePlayerConfig(id, config, value);
|
||||
}
|
||||
|
||||
public static void removePlayerConfig(UUID uuid, String config) {
|
||||
removePlayerConfig(SteamwarUser.get(uuid).getId(), config);
|
||||
}
|
||||
|
||||
public static void removePlayerConfig(int id, String config) {
|
||||
Provider.impl.removePlayerConfig(id, config);
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren