Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Ursprung
c4bafb4591
Commit
734de7178b
@ -1 +1 @@
|
|||||||
Subproject commit 8dbf62e560de95615d93057481e8202ec11c85c4
|
Subproject commit 9b53ad748b32cc38ade1ccc606b116c0d6fbf1fb
|
@ -30,7 +30,7 @@ import de.steamwar.bungeecore.network.NetworkReceiver;
|
|||||||
import de.steamwar.bungeecore.network.SWScriptSyntaxForwarder;
|
import de.steamwar.bungeecore.network.SWScriptSyntaxForwarder;
|
||||||
import de.steamwar.sql.Punishment;
|
import de.steamwar.sql.Punishment;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import de.steamwar.bungeecore.sql.UserElo;
|
import de.steamwar.sql.UserElo;
|
||||||
import de.steamwar.bungeecore.tablist.TablistManager;
|
import de.steamwar.bungeecore.tablist.TablistManager;
|
||||||
import de.steamwar.command.SWCommandUtils;
|
import de.steamwar.command.SWCommandUtils;
|
||||||
import de.steamwar.command.SWTypeMapperCreator;
|
import de.steamwar.command.SWTypeMapperCreator;
|
||||||
@ -206,7 +206,7 @@ public class BungeeCore extends Plugin {
|
|||||||
|
|
||||||
getProxy().getScheduler().schedule(this, () -> {
|
getProxy().getScheduler().schedule(this, () -> {
|
||||||
SteamwarUser.clear();
|
SteamwarUser.clear();
|
||||||
UserElo.clearCache();
|
UserElo.clear();
|
||||||
Team.clear();
|
Team.clear();
|
||||||
}, 1, 1, TimeUnit.HOURS);
|
}, 1, 1, TimeUnit.HOURS);
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ package de.steamwar.bungeecore;
|
|||||||
|
|
||||||
import de.steamwar.bungeecore.network.NetworkSender;
|
import de.steamwar.bungeecore.network.NetworkSender;
|
||||||
import de.steamwar.bungeecore.network.handlers.FightInfoHandler;
|
import de.steamwar.bungeecore.network.handlers.FightInfoHandler;
|
||||||
import de.steamwar.bungeecore.sql.IgnoreSystem;
|
import de.steamwar.sql.IgnoreSystem;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import de.steamwar.network.packets.server.StartingServerPacket;
|
import de.steamwar.network.packets.server.StartingServerPacket;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
@ -41,7 +41,7 @@ public class SubserverSystem {
|
|||||||
ProxiedPlayer o = ProxyServer.getInstance().getPlayer(owner);
|
ProxiedPlayer o = ProxyServer.getInstance().getPlayer(owner);
|
||||||
if(o == null)
|
if(o == null)
|
||||||
return;
|
return;
|
||||||
if(IgnoreSystem.isIgnored(o, p)){
|
if(IgnoreSystem.isIgnored(owner, p.getUniqueId())){
|
||||||
Message.send("SERVER_IGNORED", p);
|
Message.send("SERVER_IGNORED", p);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,8 @@ package de.steamwar.bungeecore.bot.listeners;
|
|||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
import de.steamwar.bungeecore.BungeeCore;
|
||||||
import de.steamwar.sql.Punishment;
|
import de.steamwar.sql.Punishment;
|
||||||
import de.steamwar.bungeecore.sql.SchematicNode;
|
import de.steamwar.sql.SchematicData;
|
||||||
|
import de.steamwar.sql.SchematicNode;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent;
|
||||||
@ -66,7 +67,7 @@ public class PrivateMessageListener extends BasicDiscordListener {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
InputStream in = attachment.retrieveInputStream().get();
|
InputStream in = attachment.retrieveInputStream().get();
|
||||||
node.saveFromStream(in, newFormat);
|
new SchematicData(node).saveFromStream(in, newFormat);
|
||||||
in.close();
|
in.close();
|
||||||
event.getMessage().reply("`" + name + "` wurde erfolgreich hochgeladen").queue();
|
event.getMessage().reply("`" + name + "` wurde erfolgreich hochgeladen").queue();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
package de.steamwar.bungeecore.bot.util;
|
package de.steamwar.bungeecore.bot.util;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||||
import de.steamwar.bungeecore.sql.SchematicNode;
|
import de.steamwar.sql.SchematicNode;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
@ -23,7 +23,7 @@ import de.steamwar.bungeecore.Message;
|
|||||||
import de.steamwar.bungeecore.inventory.SWInventory;
|
import de.steamwar.bungeecore.inventory.SWInventory;
|
||||||
import de.steamwar.bungeecore.inventory.SWItem;
|
import de.steamwar.bungeecore.inventory.SWItem;
|
||||||
import de.steamwar.sql.NodeMember;
|
import de.steamwar.sql.NodeMember;
|
||||||
import de.steamwar.bungeecore.sql.SchematicNode;
|
import de.steamwar.sql.SchematicNode;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
package de.steamwar.bungeecore.commands;
|
package de.steamwar.bungeecore.commands;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.*;
|
import de.steamwar.bungeecore.*;
|
||||||
import de.steamwar.bungeecore.sql.IgnoreSystem;
|
import de.steamwar.sql.IgnoreSystem;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import de.steamwar.command.TypeValidator;
|
import de.steamwar.command.TypeValidator;
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
@ -74,7 +74,7 @@ public class ChallengeCommand extends SWCommand {
|
|||||||
messageSender.send("CHALLENGE_SELF");
|
messageSender.send("CHALLENGE_SELF");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (IgnoreSystem.isIgnored(value, (ProxiedPlayer) sender)) {
|
if (IgnoreSystem.isIgnored(value.getUniqueId(), ((ProxiedPlayer) sender).getUniqueId())) {
|
||||||
messageSender.send("CHALLENGE_IGNORED");
|
messageSender.send("CHALLENGE_IGNORED");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,8 @@ package de.steamwar.bungeecore.commands;
|
|||||||
import de.steamwar.bungeecore.*;
|
import de.steamwar.bungeecore.*;
|
||||||
import de.steamwar.bungeecore.bot.util.DiscordSchemAlert;
|
import de.steamwar.bungeecore.bot.util.DiscordSchemAlert;
|
||||||
import de.steamwar.bungeecore.listeners.ConnectionListener;
|
import de.steamwar.bungeecore.listeners.ConnectionListener;
|
||||||
import de.steamwar.bungeecore.sql.CheckedSchematic;
|
import de.steamwar.sql.CheckedSchematic;
|
||||||
import de.steamwar.bungeecore.sql.SchematicNode;
|
import de.steamwar.sql.SchematicNode;
|
||||||
import de.steamwar.sql.SchematicType;
|
import de.steamwar.sql.SchematicType;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
package de.steamwar.bungeecore.commands;
|
package de.steamwar.bungeecore.commands;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.Message;
|
import de.steamwar.bungeecore.Message;
|
||||||
import de.steamwar.bungeecore.sql.IgnoreSystem;
|
import de.steamwar.sql.IgnoreSystem;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import de.steamwar.command.SWCommandUtils;
|
import de.steamwar.command.SWCommandUtils;
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
package de.steamwar.bungeecore.commands;
|
package de.steamwar.bungeecore.commands;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.listeners.ChatListener;
|
import de.steamwar.bungeecore.listeners.ChatListener;
|
||||||
import de.steamwar.bungeecore.sql.IgnoreSystem;
|
import de.steamwar.sql.IgnoreSystem;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import de.steamwar.messages.ChatSender;
|
import de.steamwar.messages.ChatSender;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
@ -47,7 +47,7 @@ public class MsgCommand extends SWCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IgnoreSystem.isIgnored(target, player)) {
|
if (IgnoreSystem.isIgnored(target.getUniqueId(), player.getUniqueId())) {
|
||||||
sender.system("MSG_IGNORED");
|
sender.system("MSG_IGNORED");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ package de.steamwar.bungeecore.commands;
|
|||||||
import de.steamwar.bungeecore.ArenaMode;
|
import de.steamwar.bungeecore.ArenaMode;
|
||||||
import de.steamwar.bungeecore.Message;
|
import de.steamwar.bungeecore.Message;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import de.steamwar.bungeecore.sql.UserElo;
|
import de.steamwar.sql.UserElo;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import de.steamwar.command.SWCommandUtils;
|
import de.steamwar.command.SWCommandUtils;
|
||||||
import de.steamwar.command.TypeMapper;
|
import de.steamwar.command.TypeMapper;
|
||||||
@ -67,10 +67,18 @@ public class RankCommand extends SWCommand {
|
|||||||
} else {
|
} else {
|
||||||
Message.send("RANK_UNPLACED", player);
|
Message.send("RANK_UNPLACED", player);
|
||||||
}
|
}
|
||||||
Message.send("RANK_EMBLEM", player, UserElo.getEmblemProgression(player, mode.getChatName(), user.getId()));
|
Message.send("RANK_EMBLEM", player, getEmblemProgression(player, mode.getChatName(), user.getId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getEmblemProgression(ProxiedPlayer player, String gameMode, int userId) {
|
||||||
|
int fightsOfSeason = UserElo.getFightsOfSeason(userId, gameMode);
|
||||||
|
if (fightsOfSeason < 10)
|
||||||
|
return Message.parse("RANK_NEEDED_FIGHTS_LEFT", player, "§8✧ ✦ ✶ ✷ ✸ ✹ ❂", 10 - fightsOfSeason);
|
||||||
|
|
||||||
|
return UserElo.getEmblemProgression(gameMode, userId);
|
||||||
|
}
|
||||||
|
|
||||||
@Mapper(value = "player", local = true)
|
@Mapper(value = "player", local = true)
|
||||||
public TypeMapper<String> playerTypeMapper() {
|
public TypeMapper<String> playerTypeMapper() {
|
||||||
return SWCommandUtils.createMapper(s -> s, s -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList()));
|
return SWCommandUtils.createMapper(s -> s, s -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList()));
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
package de.steamwar.bungeecore.commands;
|
package de.steamwar.bungeecore.commands;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.Message;
|
import de.steamwar.bungeecore.Message;
|
||||||
import de.steamwar.bungeecore.sql.IgnoreSystem;
|
import de.steamwar.sql.IgnoreSystem;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
@ -23,14 +23,10 @@ import de.steamwar.bungeecore.*;
|
|||||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||||
import de.steamwar.bungeecore.commands.PunishmentCommand;
|
import de.steamwar.bungeecore.commands.PunishmentCommand;
|
||||||
import de.steamwar.bungeecore.network.NetworkSender;
|
import de.steamwar.bungeecore.network.NetworkSender;
|
||||||
import de.steamwar.bungeecore.sql.*;
|
|
||||||
import de.steamwar.bungeecore.util.Chat19;
|
import de.steamwar.bungeecore.util.Chat19;
|
||||||
import de.steamwar.messages.ChatSender;
|
import de.steamwar.messages.ChatSender;
|
||||||
import de.steamwar.network.packets.server.PingPacket;
|
import de.steamwar.network.packets.server.PingPacket;
|
||||||
import de.steamwar.sql.Punishment;
|
import de.steamwar.sql.*;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.sql.Team;
|
|
||||||
import de.steamwar.sql.UserGroup;
|
|
||||||
import net.md_5.bungee.api.*;
|
import net.md_5.bungee.api.*;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.event.ChatEvent;
|
import net.md_5.bungee.api.event.ChatEvent;
|
||||||
@ -48,6 +44,8 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
public class ChatListener extends BasicListener {
|
public class ChatListener extends BasicListener {
|
||||||
|
|
||||||
|
private static final List<String> rankedModes = ArenaMode.getAllModes().stream().filter(ArenaMode::isRanked).map(ArenaMode::getSchemType).collect(Collectors.toList());
|
||||||
|
|
||||||
private static final Set<Integer> coloredTeams = new HashSet<>();
|
private static final Set<Integer> coloredTeams = new HashSet<>();
|
||||||
static {
|
static {
|
||||||
coloredTeams.add(12);
|
coloredTeams.add(12);
|
||||||
@ -179,7 +177,7 @@ public class ChatListener extends BasicListener {
|
|||||||
msgReceiver == null ? receiver : msgReceiver,
|
msgReceiver == null ? receiver : msgReceiver,
|
||||||
highlightMentions(message, group.getChatColorCode(), receiver),
|
highlightMentions(message, group.getChatColorCode(), receiver),
|
||||||
sender.getTeam() == 0 ? "" : "§" + Team.get(sender.getTeam()).getTeamColor() + Team.get(sender.getTeam()).getTeamKuerzel() + " ",
|
sender.getTeam() == 0 ? "" : "§" + Team.get(sender.getTeam()).getTeamColor() + Team.get(sender.getTeam()).getTeamKuerzel() + " ",
|
||||||
UserElo.getEmblem(sender),
|
UserElo.getEmblem(sender, rankedModes),
|
||||||
group.getColorCode(),
|
group.getColorCode(),
|
||||||
group.getChatPrefix().length() == 0 ? "§f" : group.getChatPrefix() + " ",
|
group.getChatPrefix().length() == 0 ? "§f" : group.getChatPrefix() + " ",
|
||||||
group.getChatColorCode()));
|
group.getChatColorCode()));
|
||||||
|
@ -21,7 +21,7 @@ package de.steamwar.bungeecore.listeners;
|
|||||||
|
|
||||||
import de.steamwar.bungeecore.*;
|
import de.steamwar.bungeecore.*;
|
||||||
import de.steamwar.bungeecore.commands.CheckCommand;
|
import de.steamwar.bungeecore.commands.CheckCommand;
|
||||||
import de.steamwar.bungeecore.sql.SchematicNode;
|
import de.steamwar.sql.SchematicNode;
|
||||||
import de.steamwar.sql.SchematicType;
|
import de.steamwar.sql.SchematicType;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
@ -20,12 +20,9 @@
|
|||||||
package de.steamwar.bungeecore.network.handlers;
|
package de.steamwar.bungeecore.network.handlers;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.ArenaMode;
|
import de.steamwar.bungeecore.ArenaMode;
|
||||||
import de.steamwar.bungeecore.sql.*;
|
|
||||||
import de.steamwar.network.packets.PacketHandler;
|
import de.steamwar.network.packets.PacketHandler;
|
||||||
import de.steamwar.network.packets.common.FightEndsPacket;
|
import de.steamwar.network.packets.common.FightEndsPacket;
|
||||||
import de.steamwar.sql.SchemElo;
|
import de.steamwar.sql.*;
|
||||||
import de.steamwar.sql.SchematicType;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -1,123 +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.bungeecore.sql;
|
|
||||||
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.sql.internal.Statement;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class CheckedSchematic {
|
|
||||||
|
|
||||||
private static final Statement checkHistory = new Statement("SELECT * FROM CheckedSchematic WHERE NodeId IN (SELECT NodeId FROM SchematicNode WHERE NodeOwner = ?) AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' AND NodeId is not NULL ORDER BY EndTime DESC");
|
|
||||||
private static final Statement nodeHistory = new Statement("SELECT * FROM CheckedSchematic WHERE NodeId = ? AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC");
|
|
||||||
private static final Statement insert = new Statement("INSERT INTO CheckedSchematic (NodeId, NodeName, NodeOwner, Validator, StartTime, EndTime, DeclineReason) VALUES (?, ?, ?, ?, ?, ?, ?)");
|
|
||||||
|
|
||||||
private final Integer node;
|
|
||||||
private final int validator;
|
|
||||||
private final Timestamp startTime;
|
|
||||||
private final Timestamp endTime;
|
|
||||||
private final String declineReason;
|
|
||||||
|
|
||||||
private CheckedSchematic(ResultSet rs) throws SQLException {
|
|
||||||
this.node = rs.getInt("NodeId");
|
|
||||||
this.validator = rs.getInt("Validator");
|
|
||||||
this.startTime = rs.getTimestamp("StartTime");
|
|
||||||
this.endTime = rs.getTimestamp("EndTime");
|
|
||||||
this.declineReason = rs.getString("DeclineReason");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void create(int nodeId, String name, int owner, int validator, Timestamp startTime, Timestamp endTime, String reason){
|
|
||||||
insert.update(nodeId, name, owner, validator, startTime, endTime, reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void create(SchematicNode node, int validator, Timestamp startTime, Timestamp endTime, String reason){
|
|
||||||
create(node.getId(), node.getName(), node.getOwner(), validator, startTime, endTime, reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<CheckedSchematic> previousChecks(SchematicNode node){
|
|
||||||
return nodeHistory.select(rs -> {
|
|
||||||
List<CheckedSchematic> schematics = new ArrayList<>();
|
|
||||||
while(rs.next())
|
|
||||||
schematics.add(new CheckedSchematic(rs));
|
|
||||||
return schematics;
|
|
||||||
}, node.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<CheckedSchematic> getLastDeclinedOfNode(SchematicNode node){
|
|
||||||
return getLastDeclinedOfNode(node.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<CheckedSchematic> getLastDeclinedOfNode(int node){
|
|
||||||
return nodeHistory.select(rs -> {
|
|
||||||
List<CheckedSchematic> lastDeclined = new ArrayList<>();
|
|
||||||
while(rs.next()){
|
|
||||||
lastDeclined.add(new CheckedSchematic(rs));
|
|
||||||
}
|
|
||||||
return lastDeclined;
|
|
||||||
}, node);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<CheckedSchematic> getLastDeclined(UUID uuid){
|
|
||||||
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));
|
|
||||||
return history;
|
|
||||||
}, schemOwner);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getValidator() {
|
|
||||||
return validator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Timestamp getStartTime() {
|
|
||||||
return startTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Timestamp getEndTime() {
|
|
||||||
return endTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDeclineReason() {
|
|
||||||
return declineReason;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNode() {
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSchemName() {
|
|
||||||
return SchematicNode.getSchematicNode(node).getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSchemOwner() {
|
|
||||||
return SchematicNode.getSchematicNode(node).getId();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,53 +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.bungeecore.sql;
|
|
||||||
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.sql.internal.Statement;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
|
|
||||||
public class IgnoreSystem{
|
|
||||||
|
|
||||||
private static final Statement select = new Statement("SELECT * FROM IgnoredPlayers WHERE Ignorer = ? AND Ignored = ?");
|
|
||||||
private static final Statement insert = new Statement("INSERT INTO IgnoredPlayers (Ignorer, Ignored) VALUES (?, ?)");
|
|
||||||
private static final Statement delete = new Statement("DELETE FROM IgnoredPlayers WHERE Ignorer = ? AND Ignored = ?");
|
|
||||||
|
|
||||||
private IgnoreSystem(){}
|
|
||||||
|
|
||||||
public static boolean isIgnored(ProxiedPlayer ignorer, ProxiedPlayer ignored){
|
|
||||||
SteamwarUser user = SteamwarUser.get(ignorer.getUniqueId());
|
|
||||||
SteamwarUser target = SteamwarUser.get(ignored.getUniqueId());
|
|
||||||
return isIgnored(user, target);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isIgnored(SteamwarUser ignorer, SteamwarUser ignored) {
|
|
||||||
return select.select(ResultSet::next, ignorer.getId(), ignored.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ignore(SteamwarUser ignorer, SteamwarUser ignored) {
|
|
||||||
insert.update(ignorer.getId(), ignored.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void unIgnore(SteamwarUser ignorer, SteamwarUser ignored) {
|
|
||||||
delete.update(ignorer.getId(), ignored.getId());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,507 +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.bungeecore.sql;
|
|
||||||
|
|
||||||
|
|
||||||
import de.steamwar.sql.NodeMember;
|
|
||||||
import de.steamwar.sql.SchematicType;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.sql.internal.Statement;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
public class SchematicNode {
|
|
||||||
private static final Statement createNode = new 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 Statement getSchematicNode_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode is NULL");
|
|
||||||
private static final Statement getSchematicNode = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?");
|
|
||||||
private static final Statement getSchematicsInNode_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode is NULL");
|
|
||||||
private static final Statement getSchematicsInNode = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode = ?");
|
|
||||||
private static final Statement getDirsInNode_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode is NULL AND NodeType is NULL");
|
|
||||||
private static final Statement getDirsInNode = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode = ? AND NodeType is NULL");
|
|
||||||
private static final Statement getSchematicDirectory_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL");
|
|
||||||
private static final Statement getSchematicDirectory = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?");
|
|
||||||
private static final Statement getSchematicNodeO_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL");
|
|
||||||
private static final Statement getSchematicNodeO = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?");
|
|
||||||
private static final Statement getSchematicNodeId = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ?");
|
|
||||||
private static final Statement getAllSchemsOfTypeOwner = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeType = ?");
|
|
||||||
private static final Statement getAllSchemsOfType = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeType = ?");
|
|
||||||
private static final Statement getAccessibleByUser = new Statement("SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode 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 Statement getAccessibleByUserByTypeInNode = new Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode = ?");
|
|
||||||
private static final Statement getAccessibleByUserByTypeInNode_Null = new Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode is null");
|
|
||||||
private static final Statement getAccessibleByUserByType = new Statement("WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ?");
|
|
||||||
private static final Statement getAllSchematicsAccessibleByUser = new Statement("WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN");
|
|
||||||
private static final Statement isSchematicAccessibleForUser = new Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode 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 Statement getAllParentsOfNode = new Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? UNION SELECT SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT * FROM RSN");
|
|
||||||
private static final Statement countNodes = new Statement("SELECT COUNT(NodeId) AS 'count' FROM SchematicNode");
|
|
||||||
private static final Statement updateDB = new Statement("UPDATE SchematicNode SET NodeName = ?, NodeOwner = ?, ParentNode = ?, NodeItem = ?, NodeType = ?, NodeRank = ? WHERE NodeId = ?");
|
|
||||||
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 static final Statement deleteNode = new Statement("DELETE FROM SchematicNode WHERE NodeId = ?");
|
|
||||||
|
|
||||||
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;
|
|
||||||
createNode.update(name, owner, parent, type, item);
|
|
||||||
return getSchematicNode(owner, name, parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Timestamp lastUpdate;
|
|
||||||
|
|
||||||
public static SchematicNode getSchematicNode(int owner, String name, SchematicNode parent) {
|
|
||||||
return getSchematicNode(owner, name, parent.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
private SchematicNode(ResultSet set) throws SQLException {
|
|
||||||
id = set.getInt("NodeId");
|
|
||||||
owner = set.getInt("NodeOwner");
|
|
||||||
name = set.getString("NodeName");
|
|
||||||
parent = set.getInt("ParentNode");
|
|
||||||
if(set.wasNull()) {
|
|
||||||
parent = null;
|
|
||||||
}
|
|
||||||
item = set.getString("NodeItem");
|
|
||||||
type = set.getString("NodeType");
|
|
||||||
lastUpdate = set.getTimestamp("LastUpdate");
|
|
||||||
if (type != null) {
|
|
||||||
isDir = false;
|
|
||||||
rank = set.getInt("NodeRank");
|
|
||||||
schemFormat = set.getBoolean("NodeFormat");
|
|
||||||
} else {
|
|
||||||
isDir = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
Statement.ResultSetUser<SchematicNode> user = rs -> {
|
|
||||||
while (rs.next()) {
|
|
||||||
SchematicNode node = new SchematicNode(rs);
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
if(parent == null) {
|
|
||||||
return getSchematicNode_Null.select(user, owner, name);
|
|
||||||
} else {
|
|
||||||
return getSchematicNode.select(user, owner, name, parent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<SchematicNode> getSchematicNodeInNode(Integer parent) {
|
|
||||||
if(parent != null && parent == 0)
|
|
||||||
parent = null;
|
|
||||||
Statement.ResultSetUser<List<SchematicNode>> user = rs -> {
|
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while (rs.next())
|
|
||||||
nodes.add(new SchematicNode(rs));
|
|
||||||
return nodes;
|
|
||||||
};
|
|
||||||
if(parent == null) {
|
|
||||||
return getSchematicsInNode_Null.select(user);
|
|
||||||
}else {
|
|
||||||
return getSchematicsInNode.select(user, parent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<SchematicNode> getSchematicDirectoryInNode(Integer parent) {
|
|
||||||
if(parent != null && parent == 0)
|
|
||||||
parent = null;
|
|
||||||
Statement.ResultSetUser<List<SchematicNode>> user = rs -> {
|
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while (rs.next())
|
|
||||||
nodes.add(new SchematicNode(rs));
|
|
||||||
return nodes;
|
|
||||||
};
|
|
||||||
if(parent == null) {
|
|
||||||
return getDirsInNode_Null.select(user);
|
|
||||||
}else {
|
|
||||||
return getDirsInNode.select(user, parent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SchematicNode getSchematicDirectory(String name, Integer parent) {
|
|
||||||
if(parent != null && parent == 0)
|
|
||||||
parent = null;
|
|
||||||
Statement.ResultSetUser<SchematicNode> user = rs -> {
|
|
||||||
while (rs.next()) {
|
|
||||||
SchematicNode node = new SchematicNode(rs);
|
|
||||||
if(node.isDir())
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
if(parent == null) {
|
|
||||||
return getSchematicDirectory_Null.select(user, name);
|
|
||||||
}else {
|
|
||||||
return getSchematicDirectory.select(user, name, parent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SchematicNode getSchematicNode(String name, Integer parent) {
|
|
||||||
if(parent != null && parent == 0)
|
|
||||||
parent = null;
|
|
||||||
Statement.ResultSetUser<SchematicNode> user = rs -> {
|
|
||||||
while (rs.next()) {
|
|
||||||
return new SchematicNode(rs);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
if(parent == null) {
|
|
||||||
return getSchematicNodeO_Null.select(user, name);
|
|
||||||
}else {
|
|
||||||
return getSchematicNodeO.select(user, name, parent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SchematicNode getSchematicNode(int id) {
|
|
||||||
return getSchematicNodeId.select(rs -> {
|
|
||||||
if (!rs.next())
|
|
||||||
return null;
|
|
||||||
return new SchematicNode(rs);
|
|
||||||
}, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<SchematicNode> getAccessibleSchematicsOfTypeInParent(int owner, String schemType, Integer parent) {
|
|
||||||
Statement.ResultSetUser<List<SchematicNode>> user = rs -> {
|
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while (rs.next()) {
|
|
||||||
nodes.add(new SchematicNode(rs));
|
|
||||||
}
|
|
||||||
return nodes;
|
|
||||||
};
|
|
||||||
if(parent == null || parent == 0) {
|
|
||||||
return getAccessibleByUserByTypeInNode_Null.select(user, owner, owner, schemType);
|
|
||||||
} else {
|
|
||||||
return getAccessibleByUserByTypeInNode.select(user, owner, owner, schemType, parent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<SchematicNode> getAllAccessibleSchematicsOfType(int user, String schemType) {
|
|
||||||
return getAccessibleByUserByType.select(rs -> {
|
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while (rs.next()) {
|
|
||||||
nodes.add(new SchematicNode(rs));
|
|
||||||
}
|
|
||||||
return nodes;
|
|
||||||
}, user, user, schemType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<SchematicNode> getAllSchematicsOfType(int owner, String schemType) {
|
|
||||||
return getAllSchemsOfTypeOwner.select(rs -> {
|
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while (rs.next())
|
|
||||||
nodes.add(new SchematicNode(rs));
|
|
||||||
return nodes;
|
|
||||||
}, owner, schemType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<SchematicNode> getAllSchematicsOfType(String schemType) {
|
|
||||||
return getAllSchemsOfType.select(rs -> {
|
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while (rs.next())
|
|
||||||
nodes.add(new SchematicNode(rs));
|
|
||||||
return nodes;
|
|
||||||
}, schemType);
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
if (parent != null && parent != 0) {
|
|
||||||
if(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(new SchematicNode(rs));
|
|
||||||
return nodes;
|
|
||||||
}, user, user, user, user);
|
|
||||||
}
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<SchematicNode> getAllSchematicsAccessibleByUser(int user) {
|
|
||||||
return getAllSchematicsAccessibleByUser.select(rs -> {
|
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while(rs.next()) {
|
|
||||||
nodes.add(new SchematicNode(rs));
|
|
||||||
}
|
|
||||||
return nodes;
|
|
||||||
}, user, user);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<SchematicNode> getAllParentsOfNode(SchematicNode node) {
|
|
||||||
return getAllParentsOfNode(node.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<SchematicNode> getAllParentsOfNode(int node) {
|
|
||||||
return getAllParentsOfNode.select(rs -> {
|
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while(rs.next()) {
|
|
||||||
nodes.add(new SchematicNode(rs));
|
|
||||||
}
|
|
||||||
return nodes;
|
|
||||||
}, node);
|
|
||||||
}
|
|
||||||
|
|
||||||
private final int id;
|
|
||||||
private final int owner;
|
|
||||||
private String name;
|
|
||||||
private Integer parent;
|
|
||||||
private String item;
|
|
||||||
private String type;
|
|
||||||
private boolean schemFormat;
|
|
||||||
private int rank;
|
|
||||||
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 countNodes.select(rs -> {
|
|
||||||
if (rs.next()) {
|
|
||||||
return rs.getInt("count");
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
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() {
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setItem(String item) {
|
|
||||||
this.item = item;
|
|
||||||
updateDB();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getType() {
|
|
||||||
if(isDir)
|
|
||||||
throw new SecurityException("Node is Directory");
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRank(int rank) {
|
|
||||||
if(isDir)
|
|
||||||
throw new SecurityException("Node is Directory");
|
|
||||||
this.rank = rank;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SchematicType getSchemtype() {
|
|
||||||
if(isDir())
|
|
||||||
throw new RuntimeException("Is Directory");
|
|
||||||
return SchematicType.fromDB(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
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("/");
|
|
||||||
while (currentNode.getParentNode() != null) {
|
|
||||||
currentNode = currentNode.getParentNode();
|
|
||||||
builder.insert(0, split)
|
|
||||||
.insert(0, currentNode.getName());
|
|
||||||
if (currentNode.getMembers().stream().anyMatch(member -> member.getMember() == user.getId())) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateDB() {
|
|
||||||
updateDB.update(name, owner, parent, item, type, rank, id);
|
|
||||||
this.lastUpdate = Timestamp.from(Instant.now());
|
|
||||||
this.brCache.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void delete() {
|
|
||||||
if (isDir()) {
|
|
||||||
getSchematicNodeInNode(getId()).forEach(SchematicNode::delete);
|
|
||||||
}
|
|
||||||
deleteNode.update(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (!(obj instanceof SchematicNode))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
SchematicNode node = (SchematicNode) obj;
|
|
||||||
return node.getId() == id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void saveFromStream(InputStream stream, boolean newFormat) {
|
|
||||||
if(isDir)
|
|
||||||
throw new SecurityException("Node is Directory");
|
|
||||||
updateDatabase(stream, newFormat);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateDatabase(InputStream blob, boolean newFormat) {
|
|
||||||
updateDatabase.update(blob, newFormat, id);
|
|
||||||
schemFormat = newFormat;
|
|
||||||
}
|
|
||||||
|
|
||||||
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("\"")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if(FORBIDDEN_NAMES.contains(layer.toLowerCase())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,179 +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.bungeecore.sql;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.ArenaMode;
|
|
||||||
import de.steamwar.bungeecore.Message;
|
|
||||||
import de.steamwar.sql.Season;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.sql.internal.Statement;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
public class UserElo {
|
|
||||||
private UserElo() {}
|
|
||||||
|
|
||||||
public static final int ELO_DEFAULT = 1000;
|
|
||||||
|
|
||||||
private static final Map<String, Map<Integer, Optional<Integer>>> gameModeUserEloCache = new ConcurrentHashMap<>();
|
|
||||||
private static final Map<String, Integer> maxEloCache = new ConcurrentHashMap<>();
|
|
||||||
private static final Map<Integer, String> emblemCache = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
private static final Statement elo = new Statement("SELECT Elo FROM UserElo WHERE UserID = ? AND GameMode = ? AND Season = ?");
|
|
||||||
private static final Statement setElo = new Statement("INSERT INTO UserElo (Season, GameMode, UserID, Elo) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE Elo = VALUES(Elo)");
|
|
||||||
private static final Statement maxElo = new Statement("SELECT MAX(Elo) AS MaxElo FROM UserElo WHERE Season = ? AND GameMode = ?");
|
|
||||||
|
|
||||||
private static final Statement place = new Statement("SELECT COUNT(*) AS Place FROM UserElo WHERE GameMode = ? AND Elo > ? AND Season = ?");
|
|
||||||
private static final Statement fightsOfSeason = new Statement("SELECT COUNT(*) AS Fights FROM FightPlayer INNER JOIN Fight F on FightPlayer.FightID = F.FightID WHERE UserID = ? AND GameMode = ? AND UNIX_TIMESTAMP(StartTime) + Duration >= UNIX_TIMESTAMP(?)");
|
|
||||||
|
|
||||||
public static int getEloOrDefault(int userID, String gameMode) {
|
|
||||||
return getElo(userID, gameMode).orElse(ELO_DEFAULT);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Optional<Integer> getElo(int userID, String gameMode) {
|
|
||||||
return gameModeUserEloCache.computeIfAbsent(gameMode, gm -> new HashMap<>()).computeIfAbsent(userID, uid -> elo.select(rs -> {
|
|
||||||
if (rs.next())
|
|
||||||
return Optional.of(rs.getInt("Elo"));
|
|
||||||
return Optional.empty();
|
|
||||||
}, userID, gameMode, Season.getSeason()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getFightsOfSeason(int userID, String gameMode) {
|
|
||||||
return fightsOfSeason.select(rs -> {
|
|
||||||
if (rs.next())
|
|
||||||
return rs.getInt("Fights");
|
|
||||||
return 0;
|
|
||||||
}, userID, gameMode, Season.getSeasonStart());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int getMaxElo(String gameMode) {
|
|
||||||
return maxEloCache.computeIfAbsent(gameMode, gm -> maxElo.select(rs -> {
|
|
||||||
if (rs.next())
|
|
||||||
return rs.getInt("MaxElo");
|
|
||||||
return 0;
|
|
||||||
}, Season.getSeason(), gameMode));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setElo(int userId, String gameMode, int elo) {
|
|
||||||
emblemCache.remove(userId);
|
|
||||||
|
|
||||||
Optional<Integer> oldElo = Optional.ofNullable(gameModeUserEloCache.computeIfAbsent(gameMode, gm -> new HashMap<>()).put(userId, Optional.of(elo))).orElse(Optional.empty());
|
|
||||||
int maxElo = getMaxElo(gameMode);
|
|
||||||
if (elo > maxElo || (oldElo.isPresent() && oldElo.get() == maxElo)) {
|
|
||||||
maxEloCache.remove(gameMode);
|
|
||||||
emblemCache.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
setElo.update(Season.getSeason(), gameMode, userId, elo);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getPlacement(int elo, String gameMode) {
|
|
||||||
return place.select(rs -> {
|
|
||||||
if (rs.next())
|
|
||||||
return rs.getInt("Place") + 1;
|
|
||||||
return -1;
|
|
||||||
}, gameMode, elo, Season.getSeason());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getEmblem(SteamwarUser user) {
|
|
||||||
return emblemCache.computeIfAbsent(user.getId(), userId -> {
|
|
||||||
switch(
|
|
||||||
ArenaMode.getAllModes().stream().filter(
|
|
||||||
ArenaMode::isRanked
|
|
||||||
).filter(
|
|
||||||
mode -> UserElo.getFightsOfSeason(user.getId(), mode.getSchemType()) >= 10
|
|
||||||
).map(
|
|
||||||
mode -> getProgression(user.getId(), mode.getSchemType())
|
|
||||||
).max(Integer::compareTo).orElse(0)
|
|
||||||
) {
|
|
||||||
case 0:
|
|
||||||
return "";
|
|
||||||
case 1:
|
|
||||||
return "§7✧ ";
|
|
||||||
case 2:
|
|
||||||
return "§f✦ ";
|
|
||||||
case 3:
|
|
||||||
return "§e✶ ";
|
|
||||||
case 4:
|
|
||||||
return "§a✷ ";
|
|
||||||
case 5:
|
|
||||||
return "§b✸ ";
|
|
||||||
case 6:
|
|
||||||
return "§c✹ ";
|
|
||||||
case 7:
|
|
||||||
return "§5❂ ";
|
|
||||||
default:
|
|
||||||
throw new SecurityException("Progression out of range");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getEmblemProgression(ProxiedPlayer player, String gameMode, int userId) {
|
|
||||||
int fightsOfSeason = getFightsOfSeason(userId, gameMode);
|
|
||||||
if (fightsOfSeason < 10)
|
|
||||||
return Message.parse("RANK_NEEDED_FIGHTS_LEFT", player, "§8✧ ✦ ✶ ✷ ✸ ✹ ❂", 10 - fightsOfSeason);
|
|
||||||
|
|
||||||
switch (getProgression(userId, gameMode)) {
|
|
||||||
case 0:
|
|
||||||
return "§8✧ ✦ ✶ ✷ ✸ ✹ ❂";
|
|
||||||
case 1:
|
|
||||||
return "§7✧ §8✦ ✶ ✷ ✸ ✹ ❂";
|
|
||||||
case 2:
|
|
||||||
return "§8✧ §f✦ §8✶ ✷ ✸ ✹ ❂";
|
|
||||||
case 3:
|
|
||||||
return "§8✧ ✦ §e✶ §8✷ ✸ ✹ ❂";
|
|
||||||
case 4:
|
|
||||||
return "§8✧ ✦ ✶ §a✷ §8✸ ✹ ❂";
|
|
||||||
case 5:
|
|
||||||
return "§8✧ ✦ ✶ ✷ §b✸ §8✹ ❂";
|
|
||||||
case 6:
|
|
||||||
return "§8✧ ✦ ✶ ✷ ✸ §c✹ §8❂";
|
|
||||||
case 7:
|
|
||||||
return "§8✧ ✦ ✶ ✷ ✸ ✹ §5❂";
|
|
||||||
default:
|
|
||||||
throw new SecurityException("Progression is not in range");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int getProgression(int userId, String gameMode) {
|
|
||||||
int elo = UserElo.getElo(userId, gameMode).orElse(0);
|
|
||||||
if(elo == 0)
|
|
||||||
return 0;
|
|
||||||
int maxElo = UserElo.getMaxElo(gameMode);
|
|
||||||
|
|
||||||
if (elo > maxElo * 0.99) return 7;
|
|
||||||
if (elo > maxElo * 0.97) return 6;
|
|
||||||
if (elo > maxElo * 0.94) return 5;
|
|
||||||
if (elo > maxElo * 0.88) return 4;
|
|
||||||
if (elo > maxElo * 0.76) return 3;
|
|
||||||
if (elo > maxElo * 0.51) return 2;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void clearCache() {
|
|
||||||
gameModeUserEloCache.clear();
|
|
||||||
maxEloCache.clear();
|
|
||||||
emblemCache.clear();
|
|
||||||
}
|
|
||||||
}
|
|
47
src/de/steamwar/sql/SchematicData.java
Normale Datei
47
src/de/steamwar/sql/SchematicData.java
Normale Datei
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 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.SqlTypeMapper;
|
||||||
|
import de.steamwar.sql.internal.Statement;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
|
||||||
|
public class SchematicData {
|
||||||
|
|
||||||
|
static {
|
||||||
|
new SqlTypeMapper<>(BufferedInputStream.class, "BLOB", (rs, identifier) -> { throw new SecurityException("PipedInputStream is write only datatype"); }, PreparedStatement::setBinaryStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement updateDatabase = new Statement("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?");
|
||||||
|
|
||||||
|
private final SchematicNode node;
|
||||||
|
|
||||||
|
public SchematicData(SchematicNode node) {
|
||||||
|
this.node = node;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveFromStream(InputStream blob, boolean newFormat) {
|
||||||
|
updateDatabase.update(new BufferedInputStream(blob), newFormat, node.getId());
|
||||||
|
node.setNodeFormat(newFormat);
|
||||||
|
}
|
||||||
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren