Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Ursprung
be14a8cfcc
Commit
871e45ffbb
@ -1 +1 @@
|
|||||||
Subproject commit fca45b084e22653391b526d57396ec386fa7444f
|
Subproject commit d439ecb8d01d576310766e497c970bce7eb1db2f
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore;
|
package de.steamwar.bungeecore;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.sql.SchematicType;
|
import de.steamwar.sql.SchematicType;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.config.Configuration;
|
import net.md_5.bungee.config.Configuration;
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||||||
|
@ -22,7 +22,7 @@ package de.steamwar.bungeecore.bot.events;
|
|||||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||||
import de.steamwar.bungeecore.sql.EventFight;
|
import de.steamwar.bungeecore.sql.EventFight;
|
||||||
import de.steamwar.bungeecore.sql.Team;
|
import de.steamwar.sql.Team;
|
||||||
import de.steamwar.sql.TeamTeilnahme;
|
import de.steamwar.sql.TeamTeilnahme;
|
||||||
import de.steamwar.sql.Event;
|
import de.steamwar.sql.Event;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
|
@ -32,6 +32,7 @@ import de.steamwar.command.TypeValidator;
|
|||||||
import de.steamwar.messages.ChatSender;
|
import de.steamwar.messages.ChatSender;
|
||||||
import de.steamwar.network.packets.server.BaumemberUpdatePacket;
|
import de.steamwar.network.packets.server.BaumemberUpdatePacket;
|
||||||
import de.steamwar.bungeecore.util.BauLockState;
|
import de.steamwar.bungeecore.util.BauLockState;
|
||||||
|
import de.steamwar.sql.BauweltMember;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
@ -122,7 +123,7 @@ public class BauCommand extends SWCommand {
|
|||||||
|
|
||||||
@Register(value = "addmember", description = "BAU_ADDMEMBER_USAGE")
|
@Register(value = "addmember", description = "BAU_ADDMEMBER_USAGE")
|
||||||
public void addmember(ProxiedPlayer p, @Validator("addMemberTarget") SteamwarUser target) {
|
public void addmember(ProxiedPlayer p, @Validator("addMemberTarget") SteamwarUser target) {
|
||||||
new BauweltMember(p.getUniqueId(), target.getUuid(), false, false);
|
BauweltMember.addMember(p.getUniqueId(), target.getUuid());
|
||||||
Message.send("BAU_ADDMEMBER_ADDED", p);
|
Message.send("BAU_ADDMEMBER_ADDED", p);
|
||||||
|
|
||||||
ProxiedPlayer z = ProxyServer.getInstance().getPlayer(target.getUuid());
|
ProxiedPlayer z = ProxyServer.getInstance().getPlayer(target.getUuid());
|
||||||
|
@ -24,11 +24,10 @@ 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.bungeecore.sql.CheckedSchematic;
|
||||||
import de.steamwar.bungeecore.sql.SchematicNode;
|
import de.steamwar.bungeecore.sql.SchematicNode;
|
||||||
import de.steamwar.bungeecore.sql.SchematicType;
|
import de.steamwar.sql.SchematicType;
|
||||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
@ -37,12 +36,12 @@ import net.md_5.bungee.config.Configuration;
|
|||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class CheckCommand extends SWCommand {
|
public class CheckCommand extends SWCommand {
|
||||||
|
private static final Map<SchematicType, SchematicType> fightTypes = new HashMap<>();
|
||||||
private static Map<SchematicType, List<String>> checkQuestions = new HashMap<>();
|
private static Map<SchematicType, List<String>> checkQuestions = new HashMap<>();
|
||||||
private static Map<SchematicType, List<String>> ranks = new HashMap<>();
|
private static Map<SchematicType, List<String>> ranks = new HashMap<>();
|
||||||
|
|
||||||
@ -55,6 +54,10 @@ public class CheckCommand extends SWCommand {
|
|||||||
ranks.put(checkType, config.getStringList("Ranks"));
|
ranks.put(checkType, config.getStringList("Ranks"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void addFightType(SchematicType checkType, SchematicType fightType) {
|
||||||
|
fightTypes.put(checkType, fightType);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isChecking(ProxiedPlayer player){
|
public static boolean isChecking(ProxiedPlayer player){
|
||||||
return currentCheckers.containsKey(player.getUniqueId());
|
return currentCheckers.containsKey(player.getUniqueId());
|
||||||
}
|
}
|
||||||
@ -215,7 +218,7 @@ public class CheckCommand extends SWCommand {
|
|||||||
this.checkList = checkQuestions.get(schematic.getSchemtype()).listIterator();
|
this.checkList = checkQuestions.get(schematic.getSchemtype()).listIterator();
|
||||||
|
|
||||||
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
|
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
|
||||||
ArenaMode mode = ArenaMode.getBySchemType(schematic.getSchemtype().fightType());
|
ArenaMode mode = ArenaMode.getBySchemType(fightTypes.get(schematic.getSchemtype()));
|
||||||
if(new ServerStarter().test(mode, mode.getRandomMap(), checker).check(schematic.getId()).start() == null) {
|
if(new ServerStarter().test(mode, mode.getRandomMap(), checker).check(schematic.getId()).start() == null) {
|
||||||
remove();
|
remove();
|
||||||
return;
|
return;
|
||||||
@ -273,7 +276,7 @@ public class CheckCommand extends SWCommand {
|
|||||||
schematic.setRank(rank);
|
schematic.setRank(rank);
|
||||||
}
|
}
|
||||||
|
|
||||||
schematic.setType(schematic.getSchemtype().fightType().toDB());
|
schematic.setType(fightTypes.get(schematic.getSchemtype()).toDB());
|
||||||
CheckedSchematic.create(schematic, SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "freigegeben");
|
CheckedSchematic.create(schematic, SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "freigegeben");
|
||||||
SteamwarUser user = SteamwarUser.get(schematic.getOwner());
|
SteamwarUser user = SteamwarUser.get(schematic.getOwner());
|
||||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid());
|
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid());
|
||||||
|
@ -21,8 +21,8 @@ package de.steamwar.bungeecore.commands;
|
|||||||
|
|
||||||
import de.steamwar.bungeecore.*;
|
import de.steamwar.bungeecore.*;
|
||||||
import de.steamwar.bungeecore.sql.EventFight;
|
import de.steamwar.bungeecore.sql.EventFight;
|
||||||
import de.steamwar.bungeecore.sql.SchematicType;
|
import de.steamwar.sql.SchematicType;
|
||||||
import de.steamwar.bungeecore.sql.Team;
|
import de.steamwar.sql.Team;
|
||||||
import de.steamwar.sql.TeamTeilnahme;
|
import de.steamwar.sql.TeamTeilnahme;
|
||||||
import de.steamwar.sql.Event;
|
import de.steamwar.sql.Event;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
@ -88,7 +88,7 @@ public class EventCommand extends BasicCommand {
|
|||||||
String schemType = e.getSchemType();
|
String schemType = e.getSchemType();
|
||||||
if (schemType != null) {
|
if (schemType != null) {
|
||||||
SchematicType schematicType = SchematicType.fromDB(schemType);
|
SchematicType schematicType = SchematicType.fromDB(schemType);
|
||||||
if (schematicType != null && schematicType.deadline() != null && now.isBefore(schematicType.deadline().toInstant())) {
|
if (schematicType != null && schematicType.getDeadline() != null && now.isBefore(schematicType.getDeadline().toInstant())) {
|
||||||
Message.send("EVENT_COMING_SCHEM_DEADLINE", player, e.getDeadline());
|
Message.send("EVENT_COMING_SCHEM_DEADLINE", player, e.getDeadline());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.BauweltMember;
|
import de.steamwar.sql.BauweltMember;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
|
@ -25,7 +25,7 @@ import de.steamwar.bungeecore.inventory.SWListInv;
|
|||||||
import de.steamwar.bungeecore.inventory.SWStreamInv;
|
import de.steamwar.bungeecore.inventory.SWStreamInv;
|
||||||
import de.steamwar.bungeecore.sql.Fight;
|
import de.steamwar.bungeecore.sql.Fight;
|
||||||
import de.steamwar.bungeecore.sql.Punishment;
|
import de.steamwar.bungeecore.sql.Punishment;
|
||||||
import de.steamwar.bungeecore.sql.SchematicType;
|
import de.steamwar.sql.SchematicType;
|
||||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import de.steamwar.messages.ChatSender;
|
import de.steamwar.messages.ChatSender;
|
||||||
|
@ -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.BauweltMember;
|
import de.steamwar.sql.BauweltMember;
|
||||||
import de.steamwar.bungeecore.sql.Punishment;
|
import de.steamwar.bungeecore.sql.Punishment;
|
||||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
import de.steamwar.bungeecore.sql.Team;
|
import de.steamwar.bungeecore.sql.Team;
|
||||||
|
@ -22,7 +22,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.bungeecore.sql.SchematicNode;
|
||||||
import de.steamwar.bungeecore.sql.SchematicType;
|
import de.steamwar.sql.SchematicType;
|
||||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||||
|
@ -23,6 +23,7 @@ import de.steamwar.bungeecore.ArenaMode;
|
|||||||
import de.steamwar.bungeecore.sql.*;
|
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.SchematicType;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -21,7 +21,7 @@ package de.steamwar.bungeecore.network.handlers;
|
|||||||
|
|
||||||
import de.steamwar.bungeecore.ArenaMode;
|
import de.steamwar.bungeecore.ArenaMode;
|
||||||
import de.steamwar.bungeecore.ServerStarter;
|
import de.steamwar.bungeecore.ServerStarter;
|
||||||
import de.steamwar.bungeecore.sql.SchematicType;
|
import de.steamwar.sql.SchematicType;
|
||||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
import de.steamwar.network.packets.PacketHandler;
|
import de.steamwar.network.packets.PacketHandler;
|
||||||
import de.steamwar.network.packets.client.PrepareSchemPacket;
|
import de.steamwar.network.packets.client.PrepareSchemPacket;
|
||||||
|
@ -1,118 +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.internal.Statement;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class BauweltMember{
|
|
||||||
|
|
||||||
private static final Statement delete = new Statement("DELETE FROM BauweltMember WHERE BauweltID = ? AND MemberID = ?");
|
|
||||||
private static final Statement update = new Statement("INSERT INTO BauweltMember (BauweltID, MemberID, WorldEdit, World) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE WorldEdit = VALUES(WorldEdit), World = VALUES(World)");
|
|
||||||
private static final Statement getMember = new Statement("SELECT * FROM BauweltMember WHERE BauweltID = ? AND MemberID = ?");
|
|
||||||
private static final Statement getMembers = new Statement("SELECT * FROM BauweltMember WHERE BauweltID = ?");
|
|
||||||
|
|
||||||
private final int bauweltID;
|
|
||||||
private final int memberID;
|
|
||||||
private boolean worldEdit;
|
|
||||||
private boolean world;
|
|
||||||
|
|
||||||
|
|
||||||
private BauweltMember(int ownerID, int memberID, boolean worldEdit, boolean world, boolean updateDB){
|
|
||||||
bauweltID = ownerID;
|
|
||||||
this.memberID = memberID;
|
|
||||||
this.worldEdit = worldEdit;
|
|
||||||
this.world = world;
|
|
||||||
if(updateDB)
|
|
||||||
updateDB();
|
|
||||||
}
|
|
||||||
|
|
||||||
public BauweltMember(int ownerID, int memberID, boolean worldEdit, boolean world){
|
|
||||||
this(ownerID, memberID, worldEdit, world, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BauweltMember(UUID ownerID, UUID memberID, boolean worldEdit, boolean world){
|
|
||||||
this(SteamwarUser.get(ownerID).getId(), SteamwarUser.get(memberID).getId(), worldEdit, world);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void remove(){
|
|
||||||
delete.update(bauweltID, memberID);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateDB(){
|
|
||||||
update.update(bauweltID, memberID, worldEdit, world);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BauweltMember getBauMember(UUID ownerID, UUID memberID){
|
|
||||||
return getBauMember(SteamwarUser.get(ownerID).getId(), SteamwarUser.get(memberID).getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BauweltMember getBauMember(int ownerID, int memberID){
|
|
||||||
return getMember.select(rs -> {
|
|
||||||
if(!rs.next())
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return new BauweltMember(ownerID, memberID, rs.getBoolean("WorldEdit"), rs.getBoolean("World"), false);
|
|
||||||
}, ownerID, memberID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<BauweltMember> getMembers(UUID bauweltID){
|
|
||||||
return getMembers(SteamwarUser.get(bauweltID).getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<BauweltMember> getMembers(int bauweltID){
|
|
||||||
return getMembers.select(rs -> {
|
|
||||||
List<BauweltMember> members = new ArrayList<>();
|
|
||||||
while(rs.next()){
|
|
||||||
members.add(new BauweltMember(bauweltID, rs.getInt("MemberID"), rs.getBoolean("WorldEdit"), rs.getBoolean("World"), false));
|
|
||||||
}
|
|
||||||
return members;
|
|
||||||
}, bauweltID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getBauweltID() {
|
|
||||||
return bauweltID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMemberID() {
|
|
||||||
return memberID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isWorldEdit() {
|
|
||||||
return worldEdit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setWorldEdit(boolean worldEdit) {
|
|
||||||
this.worldEdit = worldEdit;
|
|
||||||
updateDB();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isWorld() {
|
|
||||||
return world;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setWorld(boolean world) {
|
|
||||||
this.world = world;
|
|
||||||
updateDB();
|
|
||||||
}
|
|
||||||
}
|
|
@ -20,6 +20,7 @@
|
|||||||
package de.steamwar.bungeecore.sql;
|
package de.steamwar.bungeecore.sql;
|
||||||
|
|
||||||
import de.steamwar.sql.FightPlayer;
|
import de.steamwar.sql.FightPlayer;
|
||||||
|
import de.steamwar.sql.SchematicType;
|
||||||
import de.steamwar.sql.internal.Statement;
|
import de.steamwar.sql.internal.Statement;
|
||||||
import de.steamwar.bungeecore.ArenaMode;
|
import de.steamwar.bungeecore.ArenaMode;
|
||||||
|
|
||||||
@ -91,8 +92,8 @@ public class Fight {
|
|||||||
return fights;
|
return fights;
|
||||||
}
|
}
|
||||||
|
|
||||||
public de.steamwar.bungeecore.sql.SchematicType getSchemType() {
|
public SchematicType getSchemType() {
|
||||||
return de.steamwar.bungeecore.sql.SchematicType.fromDB(gameMode);
|
return SchematicType.fromDB(gameMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArenaMode getGameMode() {
|
public ArenaMode getGameMode() {
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package de.steamwar.bungeecore.sql;
|
package de.steamwar.bungeecore.sql;
|
||||||
|
|
||||||
|
|
||||||
|
import de.steamwar.sql.SchematicType;
|
||||||
import de.steamwar.sql.internal.Statement;
|
import de.steamwar.sql.internal.Statement;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -1,177 +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.commands.CheckCommand;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.config.Configuration;
|
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class SchematicType {
|
|
||||||
public static final SchematicType Normal = new SchematicType("Normal", "", null, Type.NORMAL, null, null); //Has to stay publicly availible
|
|
||||||
|
|
||||||
private static final Map<String, SchematicType> fromDB;
|
|
||||||
private static final Map<SchematicType, SchematicType> fightType;
|
|
||||||
private static final List<SchematicType> types;
|
|
||||||
|
|
||||||
static {
|
|
||||||
File folder = new File(ProxyServer.getInstance().getPluginsFolder(), "FightSystem");
|
|
||||||
|
|
||||||
List<SchematicType> tmpTypes = new LinkedList<>();
|
|
||||||
Map<String, SchematicType> tmpFromDB = new HashMap<>();
|
|
||||||
Map<SchematicType, SchematicType> tmpFightType = new HashMap<>();
|
|
||||||
|
|
||||||
tmpTypes.add(Normal);
|
|
||||||
tmpFromDB.put(Normal.name().toLowerCase(), Normal);
|
|
||||||
|
|
||||||
if(folder.exists()) {
|
|
||||||
for(File configFile : folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))) {
|
|
||||||
Configuration config;
|
|
||||||
try {
|
|
||||||
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new SecurityException("Could not load SchematicTypes", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!config.contains("Schematic"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
String type = config.getString("Schematic.Type");
|
|
||||||
assert type != null;
|
|
||||||
String shortcut = config.getString("Schematic.Shortcut");
|
|
||||||
if(tmpFromDB.containsKey(type.toLowerCase()))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
String material = config.getString("Schematic.Material");
|
|
||||||
|
|
||||||
SchematicType checktype = null;
|
|
||||||
if(!config.getStringList("CheckQuestions").isEmpty()) {
|
|
||||||
checktype = new SchematicType("C" + type, "C" + shortcut, material, Type.CHECK_TYPE, null, null);
|
|
||||||
tmpTypes.add(checktype);
|
|
||||||
tmpFromDB.put(checktype.toDB(), checktype);
|
|
||||||
CheckCommand.setCheckQuestions(checktype, config);
|
|
||||||
}
|
|
||||||
|
|
||||||
Date deadline;
|
|
||||||
String deadlineString = config.getString("deadline", null);
|
|
||||||
if (deadlineString != null) {
|
|
||||||
try {
|
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
|
||||||
deadline = dateFormat.parse(deadlineString);
|
|
||||||
} catch (ParseException e) {
|
|
||||||
throw new SecurityException(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
deadline = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
SchematicType current = new SchematicType(type, shortcut, material, config.getKeys().contains("Server") ? Type.FIGHT_TYPE : Type.NORMAL, checktype, deadline);
|
|
||||||
if(checktype != null)
|
|
||||||
tmpFightType.put(checktype, current);
|
|
||||||
tmpFromDB.put(type.toLowerCase(), current);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fromDB = Collections.unmodifiableMap(tmpFromDB);
|
|
||||||
fightType = Collections.unmodifiableMap(tmpFightType);
|
|
||||||
types = Collections.unmodifiableList(tmpTypes);
|
|
||||||
}
|
|
||||||
|
|
||||||
private final String name;
|
|
||||||
private final String kuerzel;
|
|
||||||
private final String material;
|
|
||||||
private final Type type;
|
|
||||||
private final SchematicType checkType;
|
|
||||||
private final Date deadline;
|
|
||||||
|
|
||||||
private SchematicType(String name, String kuerzel, String material, Type type, SchematicType checkType, Date deadline){
|
|
||||||
this.name = name;
|
|
||||||
this.kuerzel = kuerzel;
|
|
||||||
this.material = material != null && !"".equals(material) ? material : "STONE_BUTTON";
|
|
||||||
this.type = type;
|
|
||||||
this.checkType = checkType;
|
|
||||||
this.deadline = deadline;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isAssignable(){
|
|
||||||
return type == Type.NORMAL || (type == Type.FIGHT_TYPE && checkType != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SchematicType checkType(){
|
|
||||||
return checkType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SchematicType fightType(){
|
|
||||||
return fightType.get(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean check(){
|
|
||||||
return type == Type.CHECK_TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean fight(){
|
|
||||||
return type == Type.FIGHT_TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean writeable(){
|
|
||||||
return type == Type.NORMAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String name(){
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMaterial() {
|
|
||||||
return material;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getKuerzel() {
|
|
||||||
return kuerzel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toDB(){
|
|
||||||
return name.toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date deadline() {
|
|
||||||
return deadline;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SchematicType fromDB(String input){
|
|
||||||
return fromDB.getOrDefault(input.toLowerCase(), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<SchematicType> values(){
|
|
||||||
return types;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum Type{
|
|
||||||
NORMAL,
|
|
||||||
CHECK_TYPE,
|
|
||||||
FIGHT_TYPE
|
|
||||||
}
|
|
||||||
}
|
|
@ -20,6 +20,7 @@
|
|||||||
package de.steamwar.sql;
|
package de.steamwar.sql;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
import de.steamwar.bungeecore.BungeeCore;
|
||||||
|
import de.steamwar.bungeecore.commands.CheckCommand;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
@ -29,12 +30,28 @@ import net.md_5.bungee.config.YamlConfiguration;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class SQLWrapperImpl implements SQLWrapper {
|
public class SQLWrapperImpl implements SQLWrapper {
|
||||||
|
|
||||||
|
private static final SimpleDateFormat deadlineFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
||||||
|
private static Date parseDeadline(String deadline) {
|
||||||
|
if(deadline == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
return deadlineFormat.parse(deadline);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
throw new SecurityException(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadSchemTypes(List<SchematicType> tmpTypes, Map<String, SchematicType> tmpFromDB) {
|
public void loadSchemTypes(List<SchematicType> tmpTypes, Map<String, SchematicType> tmpFromDB) {
|
||||||
File folder = new File(BungeeCore.get().getDataFolder().getParentFile(), "FightSystem");
|
File folder = new File(BungeeCore.get().getDataFolder().getParentFile(), "FightSystem");
|
||||||
@ -63,11 +80,14 @@ public class SQLWrapperImpl implements SQLWrapper {
|
|||||||
checktype = new SchematicType("C" + type, "C" + shortcut, SchematicType.Type.CHECK_TYPE, null, material);
|
checktype = new SchematicType("C" + type, "C" + shortcut, SchematicType.Type.CHECK_TYPE, null, material);
|
||||||
tmpTypes.add(checktype);
|
tmpTypes.add(checktype);
|
||||||
tmpFromDB.put(checktype.toDB(), checktype);
|
tmpFromDB.put(checktype.toDB(), checktype);
|
||||||
|
CheckCommand.setCheckQuestions(checktype, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
SchematicType current = new SchematicType(type, shortcut, !config.contains("Server") ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material);
|
SchematicType current = new SchematicType(type, shortcut, !config.contains("Server") ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material, parseDeadline(config.getString("deadline", null)));
|
||||||
tmpTypes.add(current);
|
tmpTypes.add(current);
|
||||||
tmpFromDB.put(type.toLowerCase(), current);
|
tmpFromDB.put(type.toLowerCase(), current);
|
||||||
|
if(checktype != null)
|
||||||
|
CheckCommand.addFightType(checktype, current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren