**" + event.getUser().getName() + "**: Ticket geschlossen";
- if(stringBuilders.getLast().length() + footer.length() > 4090) {
- stringBuilders.add(new StringBuilder(footer));
- } else {
- stringBuilders.getLast().append(footer);
- }
-
- EmbedBuilder embedBuilder = new EmbedBuilder();
- embedBuilder.setColor(Color.GREEN);
- User user = event.getJDA().retrieveUserById(event.getTextChannel().getTopic()).complete();
- SteamwarUser swuser = SteamwarUser.get(user.getIdLong());
-
- embedBuilder.setAuthor(user.getName(), swuser==null?"https://steamwar.de/":("https://steamwar.de/users/" + swuser.getUserName().toLowerCase() + "/"), user.getAvatarUrl());
- embedBuilder.setTimestamp(Instant.now());
- embedBuilder.setTitle(event.getTextChannel().getName());
- stringBuilders.forEach(stringBuilder -> {
- embedBuilder.setDescription(stringBuilder.toString());
- MessageBuilder builder = new MessageBuilder();
- builder.setEmbeds(embedBuilder.build());
-
- logChannel.sendMessage(builder.build()).queue();
- });
-
- Message.team("DISCORD_TICKET_CLOSED", event.getTextChannel().getName());
- event.getTextChannel().delete().reason("Closed").queue();
- }
- }
- }
-
- @Override
- public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
- if(event.getChannel().getParent() != null && event.getChannel().getParent().getId().equals(SteamwarDiscordBotConfig.TICKET_CATEGORY)) {
- if(!event.getChannel().getId().equals(SteamwarDiscordBotConfig.TICKET_CHANNEL) && !event.getChannel().getId().equals(SteamwarDiscordBotConfig.TICKET_LOG)) {
- BungeeCore.get().getProxy().getPlayers().forEach(player -> {
- if(event.getAuthor().isBot() || event.getAuthor().isSystem()) return;
- SteamwarUser user = SteamwarUser.get(player.getUniqueId());
- boolean sendMessage;
- if(user.getDiscordId() == null) {
- sendMessage = user.hasPerm(UserPerm.CHECK);
- } else {
- if(event.getAuthor().getId().equals(user.getDiscordId())) return;
- sendMessage = user.getDiscordId().equals(event.getChannel().getTopic()) || user.hasPerm(UserPerm.CHECK);
- }
- if(sendMessage) {
- Message.sendPrefixless("DISCORD_TICKET_MESSAGE", player, "Zur nachricht", new ClickEvent(ClickEvent.Action.OPEN_URL, event.getMessage().getJumpUrl()), event.getChannel().getName(), event.getAuthor().getName(), event.getMessage().getContentRaw());
- }
- });
- }
- }
- }
-}
diff --git a/src/de/steamwar/bungeecore/bot/listeners/PrivateMessageListener.java b/src/de/steamwar/bungeecore/bot/listeners/PrivateMessageListener.java
deleted file mode 100644
index 58800d0..0000000
--- a/src/de/steamwar/bungeecore/bot/listeners/PrivateMessageListener.java
+++ /dev/null
@@ -1,80 +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 .
- */
-
-package de.steamwar.bungeecore.bot.listeners;
-
-import de.steamwar.bungeecore.BungeeCore;
-import de.steamwar.sql.NodeData;
-import de.steamwar.sql.Punishment;
-import de.steamwar.sql.SchematicNode;
-import de.steamwar.sql.SteamwarUser;
-import net.dv8tion.jda.api.entities.Message;
-import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent;
-
-import java.io.InputStream;
-
-public class PrivateMessageListener extends BasicDiscordListener {
-
- @Override
- public void onPrivateMessageReceived(PrivateMessageReceivedEvent event) {
- if(!event.getMessage().getAttachments().isEmpty()) {
- SteamwarUser user = SteamwarUser.get(event.getAuthor().getIdLong());
- if (user == null) {
- event.getMessage().reply("Du must dein Minecraft Account mit dem Bot verbinden, gehe dazu auf dem SteamWar Discord in den `regeln-infos` Channel und Klicke auf `Minecraft Verknüpfen`").complete();
- return;
- }
-
- if(user.isPunished(Punishment.PunishmentType.NoSchemReceiving)) {
- event.getMessage().reply("Du darfst keine Schematics hochladen").complete();
- return;
- }
-
- for (Message.Attachment attachment : event.getMessage().getAttachments()) {
- if(attachment.getFileExtension() == null ||
- (!attachment.getFileExtension().equalsIgnoreCase("schem") &&
- !attachment.getFileExtension().equalsIgnoreCase("schematic"))) {
- event.getMessage().reply("`" + attachment.getFileName() + "` wird ignoriert, da die Datei keine Schematic ist").queue();
- continue;
- }
-
- boolean newFormat = attachment.getFileExtension().equalsIgnoreCase("schem");
- int dot = attachment.getFileName().lastIndexOf(".");
- String name = attachment.getFileName().substring(0, dot);
- if(SchematicNode.invalidSchemName(new String[] {name})) {
- event.getMessage().reply("`" + name + "` hat nicht zugelassene Zeichen im Namen").queue();
- continue;
- }
-
- SchematicNode node = SchematicNode.getSchematicNode(user.getId(), name, (Integer) null);
- if(node == null) {
- node = SchematicNode.createSchematic(user.getId(), name, null);
- }
-
- try {
- InputStream in = attachment.retrieveInputStream().get();
- NodeData.get(node).saveFromStream(in, newFormat);
- in.close();
- event.getMessage().reply("`" + name + "` wurde erfolgreich hochgeladen").queue();
- } catch (Exception e) {
- event.getMessage().reply("`" + name + "` konnte nicht hochgeladen werden, bitte versuche es später nochmal oder wende dich an einen Developer").queue();
- BungeeCore.log("Could not Upload Schem \"" + name + "\" from User \"" + user.getUserName() + "\"", e);
- }
- }
- }
- }
-}
diff --git a/src/de/steamwar/bungeecore/bot/listeners/RolesInteractionButtonListener.java b/src/de/steamwar/bungeecore/bot/listeners/RolesInteractionButtonListener.java
deleted file mode 100644
index ae0e44d..0000000
--- a/src/de/steamwar/bungeecore/bot/listeners/RolesInteractionButtonListener.java
+++ /dev/null
@@ -1,42 +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 .
- */
-
-package de.steamwar.bungeecore.bot.listeners;
-
-import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
-import net.dv8tion.jda.api.entities.ChannelType;
-import net.dv8tion.jda.api.events.interaction.GenericComponentInteractionCreateEvent;
-import net.dv8tion.jda.api.interactions.InteractionType;
-import org.jetbrains.annotations.NotNull;
-
-public class RolesInteractionButtonListener extends BasicDiscordListener {
-
- @Override
- public void onGenericComponentInteractionCreate(@NotNull GenericComponentInteractionCreateEvent event) {
- if(event.getType() == InteractionType.COMPONENT && event.getChannelType() == ChannelType.TEXT && event.getTextChannel().getId().equals(SteamwarDiscordBotConfig.ROLES_CHANNEL) && SteamwarDiscordBotConfig.ROLES.stream().anyMatch(discordRole -> discordRole.getRoleId().equals(event.getComponentId()))) {
- if (event.getMember().getRoles().stream().anyMatch(role -> role.getId().equals(event.getComponentId()))) {
- event.getGuild().removeRoleFromMember(event.getMember(), event.getGuild().getRoleById(event.getComponentId())).complete();
- event.reply(SteamwarDiscordBotConfig.ROLES_REMOVED.replace("%role%", event.getGuild().getRoleById(event.getComponentId()).getAsMention())).setEphemeral(true).queue();
- } else {
- event.getGuild().addRoleToMember(event.getMember(), event.getGuild().getRoleById(event.getComponentId())).complete();
- event.reply(SteamwarDiscordBotConfig.ROLES_ADDED.replace("%role%", event.getGuild().getRoleById(event.getComponentId()).getAsMention())).setEphemeral(true).queue();
- }
- }
- }
-}
diff --git a/src/de/steamwar/bungeecore/bot/listeners/SlashCommandListener.java b/src/de/steamwar/bungeecore/bot/listeners/SlashCommandListener.java
deleted file mode 100644
index 565ca44..0000000
--- a/src/de/steamwar/bungeecore/bot/listeners/SlashCommandListener.java
+++ /dev/null
@@ -1,32 +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 .
- */
-
-package de.steamwar.bungeecore.bot.listeners;
-
-import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
-import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
-import org.jetbrains.annotations.NotNull;
-
-public class SlashCommandListener extends BasicDiscordListener {
-
- @Override
- public void onSlashCommand(@NotNull SlashCommandEvent event) {
- SteamwarDiscordBot.getDiscordCommandMap().get(event.getName()).run(event);
- }
-}
diff --git a/src/de/steamwar/bungeecore/bot/util/DiscordRanks.java b/src/de/steamwar/bungeecore/bot/util/DiscordRanks.java
deleted file mode 100644
index f62dea0..0000000
--- a/src/de/steamwar/bungeecore/bot/util/DiscordRanks.java
+++ /dev/null
@@ -1,69 +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 .
- */
-
-package de.steamwar.bungeecore.bot.util;
-
-import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
-import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
-import de.steamwar.sql.SteamwarUser;
-import lombok.experimental.UtilityClass;
-import net.dv8tion.jda.api.entities.Guild;
-import net.dv8tion.jda.api.entities.Role;
-import net.dv8tion.jda.api.exceptions.ErrorResponseException;
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-@UtilityClass
-public class DiscordRanks {
-
- public void update(SteamwarUser steamwarUser) {
- if (steamwarUser.getDiscordId() == null) {
- return;
- }
- Guild guild = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD);
- guild.retrieveMemberById(steamwarUser.getDiscordId()).queue(member -> {
- List roleList = member.getRoles();
- Set strings = new HashSet<>(SteamwarDiscordBotConfig.RANKS.values());
- String needed = SteamwarDiscordBotConfig.RANKS.get(steamwarUser.prefix());
- for (Role role : roleList) {
- if (!strings.contains(role.getId())) {
- continue;
- }
- if (role.getId().equals(needed)) {
- needed = "";
- continue;
- }
- guild.removeRoleFromMember(member, role).complete();
- }
-
- if (needed != null && !needed.isEmpty()) {
- guild.addRoleToMember(member, guild.getRoleById(needed)).complete();
- }
- }, throwable -> {
- if(throwable instanceof ErrorResponseException) {
- ErrorResponseException e = (ErrorResponseException) throwable;
- if(e.getErrorCode() == 10007) {
- steamwarUser.setDiscordId(null);
- }
- }
- });
- }
-}
diff --git a/src/de/steamwar/bungeecore/bot/util/DiscordRolesMessage.java b/src/de/steamwar/bungeecore/bot/util/DiscordRolesMessage.java
deleted file mode 100644
index 1486deb..0000000
--- a/src/de/steamwar/bungeecore/bot/util/DiscordRolesMessage.java
+++ /dev/null
@@ -1,61 +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 .
- */
-
-package de.steamwar.bungeecore.bot.util;
-
-import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
-import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
-import lombok.experimental.UtilityClass;
-import net.dv8tion.jda.api.MessageBuilder;
-import net.dv8tion.jda.api.entities.Message;
-import net.dv8tion.jda.api.entities.TextChannel;
-import net.dv8tion.jda.api.interactions.components.ActionRow;
-import net.dv8tion.jda.api.interactions.components.Button;
-
-import java.util.ArrayList;
-import java.util.List;
-
-@UtilityClass
-public class DiscordRolesMessage {
-
-
- public void sendMessage() {
- TextChannel channel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.ROLES_CHANNEL);
- assert channel != null;
-
- MessageBuilder builder = new MessageBuilder();
- builder.setContent(SteamwarDiscordBotConfig.ROLES_BASE_MESSAGE);
- List buttons = new ArrayList<>();
- SteamwarDiscordBotConfig.ROLES.forEach(discordRole -> buttons.add(discordRole.toButton()));
- builder.setActionRows(ActionRow.of(buttons));
-
- if(channel.hasLatestMessage()) {
- channel.getIterableHistory().queue(messages -> {
- Message message = messages.stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null);
- if (message != null) {
- message.editMessage(builder.build()).queue();
- } else {
- channel.sendMessage(builder.build()).queue();
- }
- });
- } else {
- channel.sendMessage(builder.build()).queue();
- }
- }
-}
diff --git a/src/de/steamwar/bungeecore/bot/util/DiscordRulesMessage.java b/src/de/steamwar/bungeecore/bot/util/DiscordRulesMessage.java
deleted file mode 100644
index a061d66..0000000
--- a/src/de/steamwar/bungeecore/bot/util/DiscordRulesMessage.java
+++ /dev/null
@@ -1,68 +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 .
- */
-
-package de.steamwar.bungeecore.bot.util;
-
-import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
-import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
-import lombok.experimental.UtilityClass;
-import net.dv8tion.jda.api.EmbedBuilder;
-import net.dv8tion.jda.api.MessageBuilder;
-import net.dv8tion.jda.api.entities.Emoji;
-import net.dv8tion.jda.api.entities.Message;
-import net.dv8tion.jda.api.entities.TextChannel;
-import net.dv8tion.jda.api.interactions.components.ActionRow;
-import net.dv8tion.jda.api.interactions.components.Button;
-
-import java.awt.*;
-import java.util.ArrayList;
-import java.util.List;
-
-@UtilityClass
-public class DiscordRulesMessage {
-
- public void sendMessage() {
- TextChannel channel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.RULES_CHANNEL);
- assert channel != null;
- Message message = null;
- if(channel.hasLatestMessage()) {
- message = channel.getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null);
- }
-
- EmbedBuilder builder = new EmbedBuilder();
- builder.setDescription(SteamwarDiscordBotConfig.RULES_RULES.stream().reduce((s, s2) -> s + "\n" + s2).get());
- builder.setColor(Color.GRAY);
- builder.setAuthor("SteamWar", "https://www.steamwar.de");
- builder.setTitle(SteamwarDiscordBotConfig.RULES_TITLE);
-
- List buttons = new ArrayList<>();
- SteamwarDiscordBotConfig.RULES_LINKS.forEach(discordRulesLink -> buttons.add(discordRulesLink.toButton()));
-
- Button authButton = Button.primary("auth", Emoji.fromUnicode("U+2705")).withLabel("Minecraft verknüpfen");
-
- MessageBuilder messageBuilder = new MessageBuilder();
- messageBuilder.setEmbeds(builder.build());
- messageBuilder.setActionRows(ActionRow.of(buttons), ActionRow.of(authButton));
- if (message != null) {
- message.editMessage(messageBuilder.build()).queue();
- } else {
- channel.sendMessage(messageBuilder.build()).queue();
- }
- }
-}
diff --git a/src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java b/src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java
deleted file mode 100644
index b0f48eb..0000000
--- a/src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java
+++ /dev/null
@@ -1,79 +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 .
- */
-
-package de.steamwar.bungeecore.bot.util;
-
-import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
-import de.steamwar.sql.SchematicNode;
-import de.steamwar.sql.SteamwarUser;
-import lombok.experimental.UtilityClass;
-import net.dv8tion.jda.api.EmbedBuilder;
-import net.dv8tion.jda.api.MessageBuilder;
-import net.dv8tion.jda.api.entities.Emoji;
-import net.dv8tion.jda.api.entities.User;
-import net.dv8tion.jda.api.interactions.components.ActionRow;
-import net.dv8tion.jda.api.interactions.components.Button;
-
-import java.awt.*;
-import java.time.Instant;
-
-@UtilityClass
-public class DiscordSchemAlert {
-
- public void sendDecline(SchematicNode schematic, SteamwarUser user, String reason) {
- if(user.getDiscordId() != null) {
- User dcUser = SteamwarDiscordBot.instance().getJda().retrieveUserById(user.getDiscordId()).complete();
- EmbedBuilder builder = new EmbedBuilder();
- builder.setAuthor("SteamWar", "https://steamwar.de", "https://cdn.discordapp.com/app-icons/869606970099904562/60c884000407c02671d91d8e7182b8a1.png");
- builder.setColor(Color.RED);
- builder.setTitle("SteamWar-Schematic Info");
- builder.setDescription("Deine Schematic **" + schematic.getName() + "** wurde abgelehnt. **Grund:** \n" + reason);
- builder.setTimestamp(Instant.now());
-
- MessageBuilder messageBuilder = new MessageBuilder();
- messageBuilder.setEmbeds(builder.build());
- try {
- dcUser.openPrivateChannel().complete().sendMessage(messageBuilder.build()).queue();
- } catch (Exception e) {
- // Ignored
- }
- }
- }
-
- public void sendAccept(SchematicNode schematic, SteamwarUser user) {
- if(user.getDiscordId() != null) {
- User dcUser = SteamwarDiscordBot.instance().getJda().retrieveUserById(user.getDiscordId()).complete();
- EmbedBuilder builder = new EmbedBuilder();
- builder.setAuthor("SteamWar", "https://steamwar.de", "https://cdn.discordapp.com/app-icons/869606970099904562/60c884000407c02671d91d8e7182b8a1.png");
- builder.setColor(Color.GREEN);
- builder.setTitle("SteamWar-Schematic Info");
- builder.setDescription("Deine Schematic **" + schematic.getName() + "** wurde angenommen.");
- builder.setTimestamp(Instant.now());
-
- MessageBuilder messageBuilder = new MessageBuilder();
- messageBuilder.setEmbeds(builder.build());
- messageBuilder.setActionRows(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389"))));
- try {
- dcUser.openPrivateChannel().complete().sendMessage(messageBuilder.build()).queue();
- } catch (Exception e) {
- // Ignored
- }
- }
- }
-}
diff --git a/src/de/steamwar/bungeecore/bot/util/DiscordTicketMessage.java b/src/de/steamwar/bungeecore/bot/util/DiscordTicketMessage.java
deleted file mode 100644
index 21ebded..0000000
--- a/src/de/steamwar/bungeecore/bot/util/DiscordTicketMessage.java
+++ /dev/null
@@ -1,76 +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 .
- */
-
-package de.steamwar.bungeecore.bot.util;
-
-import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
-import de.steamwar.bungeecore.bot.config.DiscordTicketType;
-import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
-import lombok.experimental.UtilityClass;
-import net.dv8tion.jda.api.EmbedBuilder;
-import net.dv8tion.jda.api.MessageBuilder;
-import net.dv8tion.jda.api.entities.Message;
-import net.dv8tion.jda.api.entities.TextChannel;
-import net.dv8tion.jda.api.interactions.components.ActionRow;
-import net.dv8tion.jda.api.interactions.components.Button;
-
-import java.awt.*;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Collectors;
-
-@UtilityClass
-public class DiscordTicketMessage {
-
- public void sendMessage() {
- TextChannel channel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.TICKET_CHANNEL);
- assert channel != null;
- Message message = null;
- if(channel.hasLatestMessage()) {
- message = channel.getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null);
- }
-
- EmbedBuilder builder = new EmbedBuilder();
- builder.setDescription(SteamwarDiscordBotConfig.TICKET_MESSAGE);
- builder.setTitle("Steamwar-Tickets");
- builder.setColor(Color.RED);
-
- List> buttons = new ArrayList<>();
- chunked(new ArrayList<>(SteamwarDiscordBotConfig.TICKET_TYPES.values()), 5).forEach(discordTicketTypes -> {
- buttons.add(discordTicketTypes.stream().map(DiscordTicketType::toButton).collect(Collectors.toList()));
- });
-
- MessageBuilder messageBuilder = new MessageBuilder();
- messageBuilder.setEmbeds(builder.build());
- messageBuilder.setActionRows(buttons.stream().map(ActionRow::of).collect(Collectors.toList()));
- if (message != null) {
- message.editMessage(messageBuilder.build()).queue();
- } else {
- channel.sendMessage(messageBuilder.build()).queue();
- }
- }
-
- private static List> chunked(List list, int chunkSize) {
- List> chunks = new ArrayList<>();
- for (int i = 0; i < list.size(); i += chunkSize) {
- chunks.add(list.subList(i, Math.min(i + chunkSize, list.size())));
- }
- return chunks;
- }
-}
diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java
deleted file mode 100644
index 9981b71..0000000
--- a/src/de/steamwar/bungeecore/commands/BauCommand.java
+++ /dev/null
@@ -1,340 +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 .
-*/
-
-package de.steamwar.bungeecore.commands;
-
-import de.steamwar.bungeecore.*;
-import de.steamwar.bungeecore.inventory.SWInventory;
-import de.steamwar.bungeecore.inventory.SWItem;
-import de.steamwar.bungeecore.network.NetworkSender;
-import de.steamwar.bungeecore.util.BauLock;
-import de.steamwar.bungeecore.util.BauLockState;
-import de.steamwar.bungeecore.util.Chat19;
-import de.steamwar.command.PreviousArguments;
-import de.steamwar.command.SWCommand;
-import de.steamwar.command.TypeMapper;
-import de.steamwar.command.TypeValidator;
-import de.steamwar.network.packets.server.BaumemberUpdatePacket;
-import de.steamwar.sql.BauweltMember;
-import de.steamwar.sql.SteamwarUser;
-import net.md_5.bungee.api.CommandSender;
-import net.md_5.bungee.api.ProxyServer;
-import net.md_5.bungee.api.config.ServerInfo;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-public class BauCommand extends SWCommand {
-
- private final HelpCommand command;
-
- public BauCommand(HelpCommand command){
- super("bau", null, "b", "build", "gs");
- this.command = command;
- }
-
- @Register(noTabComplete = true)
- public void genericHelp(ProxiedPlayer p, String... args) {
- this.command.sendBauHelp(p);
- }
-
- @Register
- public void toBau(ProxiedPlayer p, @Mapper("version") @OptionalValue(value = "", onlyUINIG = true) ServerStarter.Version version) {
- new ServerStarter().build(version, p.getUniqueId()).send(p).start();
- }
-
- @Mapper(value = "version", local = true)
- public TypeMapper versionMapper() {
- Map versionMap = new HashMap<>();
- versionMap.put("20", ServerStarter.Version.PAPER_20);
- versionMap.put("1.20", ServerStarter.Version.PAPER_20);
- versionMap.put("as", ServerStarter.Version.PAPER_20);
- versionMap.put("airship", ServerStarter.Version.PAPER_20);
- versionMap.put("wg", ServerStarter.Version.PAPER_20);
- versionMap.put("wargear", ServerStarter.Version.PAPER_20);
- versionMap.put("ws", ServerStarter.Version.PAPER_20);
- versionMap.put("warship", ServerStarter.Version.PAPER_20);
-
- versionMap.put("19", ServerStarter.Version.PAPER_19);
- versionMap.put("1.19", ServerStarter.Version.PAPER_19);
- versionMap.put("mwg", ServerStarter.Version.PAPER_19);
- versionMap.put("miniwargear", ServerStarter.Version.PAPER_19);
-
- versionMap.put("15", ServerStarter.Version.SPIGOT_15);
- versionMap.put("1.15", ServerStarter.Version.SPIGOT_15);
-
- versionMap.put("12", ServerStarter.Version.SPIGOT_12);
- versionMap.put("1.12", ServerStarter.Version.SPIGOT_12);
-
- return new TypeMapper() {
- @Override
- public ServerStarter.Version map(CommandSender commandSender, String[] previousArguments, String s) {
- if (commandSender == null) return null;
- ProxiedPlayer player = (ProxiedPlayer) commandSender;
- if (s.isEmpty()) {
- int version = player.getPendingConnection().getVersion();
- if (version > 762) { // Version > 1.19.4
- return ServerStarter.Version.PAPER_20;
- } else if (version > 578) { // Version > 1.15.2
- return ServerStarter.Version.PAPER_19;
- } else if (version > 340) { // Version > 1.12.2
- return ServerStarter.Version.SPIGOT_15;
- } else {
- return ServerStarter.Version.SPIGOT_12;
- }
- }
- return versionMap.get(s.toLowerCase());
- }
-
- @Override
- public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) {
- return versionMap.keySet();
- }
- };
- }
-
- @Register(value = "addmember", description = "BAU_ADDMEMBER_USAGE")
- public void addmember(ProxiedPlayer p, @Validator("addMemberTarget") SteamwarUser target) {
- BauweltMember.addMember(p.getUniqueId(), target.getUUID());
- Message.send("BAU_ADDMEMBER_ADDED", p);
-
- ProxiedPlayer z = ProxyServer.getInstance().getPlayer(target.getUUID());
- if(z != null)
- Message.send("BAU_ADDMEMBER_ADDED_TARGET", z, p.getName());
- }
-
- @Validator(value = "addMemberTarget", local = true)
- public TypeValidator addMemberTargetValidator() {
- return (sender, value, messageSender) -> {
- if (value == null) {
- messageSender.send("UNKNOWN_PLAYER");
- return false;
- }
- if (((ProxiedPlayer) sender).getUniqueId().equals(value.getUUID())) {
- messageSender.send("BAU_ADDMEMBER_SELFADD");
- return false;
- }
- if (BauweltMember.getBauMember(((ProxiedPlayer) sender).getUniqueId(), value.getUUID()) != null) {
- messageSender.send("BAU_ADDMEMBER_ISADDED");
- return false;
- }
- return true;
- };
- }
-
- @Register(value = "tp", description = "BAU_TP_USAGE")
- @Register("teleport")
- public void teleport(ProxiedPlayer p, @Validator("teleportTarget") SteamwarUser worldOwner, @Mapper("version") @OptionalValue(value = "", onlyUINIG = true) ServerStarter.Version version) {
- new ServerStarter().build(version, worldOwner.getUUID()).send(p).start();
- }
-
- @Validator(value = "teleportTarget", local = true)
- public TypeValidator teleportTargetValidator() {
- return (sender, value, messageSender) -> {
- if (value == null) {
- messageSender.send("UNKNOWN_PLAYER");
- return false;
- }
- ProxiedPlayer p = (ProxiedPlayer) sender;
- if (!p.getUniqueId().equals(value.getUUID()) && BauweltMember.getBauMember(value.getUUID(), p.getUniqueId()) == null) {
- SubserverSystem.sendDeniedMessage(p, value.getUUID());
- messageSender.send("BAU_TP_NOALLOWED");
- return false;
- }
- return !BauLock.checkNotifyLocked(value, p);
- };
- }
-
- @Register("info")
- public void info(ProxiedPlayer p) {
- Chat19.chat(p, "/bauinfo");
- }
-
- @Register("setspectator")
- public void setSpectator(ProxiedPlayer p, @Mapper("addedUsers") @AllowNull @OptionalValue("") SteamwarUser user) {
- if (user == null) {
- Message.send("BAU_MEMBER_SET_USAGE", p, "setspectator");
- return;
- }
- BauweltMember target = member(p, user);
- if (target == null)
- return;
-
- target.setBuild(false);
- target.setSupervisor(false);
- clearMembercache(p);
- sendPermissionUpdate(p, target, "BAU_MEMBER_SET_SPECTATOR");
- }
-
- @Register("setbuild")
- public void setBuild(ProxiedPlayer p, @Mapper("addedUsers") @AllowNull @OptionalValue("") SteamwarUser user) {
- if (user == null) {
- Message.send("BAU_MEMBER_SET_USAGE", p, "setbuild");
- return;
- }
- BauweltMember target = member(p, user);
- if (target == null)
- return;
-
- target.setBuild(true);
- target.setSupervisor(false);
- clearMembercache(p);
- sendPermissionUpdate(p, target, "BAU_MEMBER_SET_BUILDER");
- }
-
- @Register("setsupervisor")
- public void setSupervisor(ProxiedPlayer p, @Mapper("addedUsers") @AllowNull @OptionalValue("") SteamwarUser user) {
- if (user == null) {
- Message.send("BAU_MEMBER_SET_USAGE", p, "setsupervisor");
- return;
- }
- BauweltMember target = member(p, user);
- if (target == null)
- return;
-
- target.setBuild(true);
- target.setSupervisor(true);
- clearMembercache(p);
- sendPermissionUpdate(p, target, "BAU_MEMBER_SET_SUPERVISOR");
- }
-
- private static void clearMembercache(ProxiedPlayer p){
- for(ServerInfo info : ProxyServer.getInstance().getServers().values()){
- Subserver server = Subserver.getSubserver(info);
- if(server != null && server.getType() == Servertype.BAUSERVER && ((Bauserver)server).getOwner().equals(p.getUniqueId())){
- info.getPlayers().stream().findAny().ifPresent(player -> NetworkSender.send(player, new BaumemberUpdatePacket()));
- break;
- }
- }
- }
-
- @Register(value = "delmember", description = "BAU_DELMEMBER_USAGE")
- public void delmember(ProxiedPlayer p, @Mapper("addedUsers") SteamwarUser user) {
- BauweltMember target = member(p, user);
- if (target == null)
- return;
-
- if(SteamwarUser.get(target.getMemberID()).getUUID().equals(p.getUniqueId())) {
- Message.send("BAU_DELMEMBER_SELFDEL", p);
- return;
- }
-
- target.remove();
- ProxiedPlayer toRemove = ProxyServer.getInstance().getPlayer(SteamwarUser.get(target.getMemberID()).getUUID());
- if(toRemove != null){
- Message.send("BAU_DELMEMBER_DELETED_TARGET", toRemove, p.getName());
- Subserver currentServer = Subserver.getSubserver(toRemove.getServer().getInfo());
- if (currentServer != null && currentServer.getType() == Servertype.BAUSERVER && ((Bauserver) currentServer).getOwner().equals(p.getUniqueId())) {
- toRemove.connect(ProxyServer.getInstance().getServerInfo(BungeeCore.LOBBY_SERVER));
- }
- }
- Message.send("BAU_DELMEMBER_DELETED", p);
- }
-
- @Mapper(value = "addedUsers", local = true)
- public TypeMapper addedUsers() {
- return new TypeMapper() {
- @Override
- public SteamwarUser map(CommandSender commandSender, String[] previousArguments, String s) {
- return SteamwarUser.get(s);
- }
-
- @Override
- public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
- if (!(sender instanceof ProxiedPlayer)) return Collections.emptyList();
- return BauweltMember.getMembers(((ProxiedPlayer) sender).getUniqueId()).stream()
- .map(bauweltMember -> SteamwarUser.get(bauweltMember.getMemberID()))
- .map(steamwarUser -> steamwarUser.getUserName())
- .collect(Collectors.toList());
- }
- };
- }
-
- @Register("resetall")
- @Register("delete")
- public void delete(ProxiedPlayer p, @Mapper("version") @OptionalValue(value = "", onlyUINIG = true) ServerStarter.Version version) {
- deleteConfirmation(p, () -> deleteWorld(p, version.getWorldFolder(ServerStarter.WORLDS_BASE_PATH) + (version != ServerStarter.Version.SPIGOT_12 ? SteamwarUser.get(p.getUniqueId()).getId() : p.getUniqueId().toString())));
- }
-
- private static void deleteConfirmation(ProxiedPlayer p, Runnable worldDeletion) {
- SWInventory inventory = new SWInventory(p, 9, Message.parse("BAU_DELETE_GUI_NAME", p));
- inventory.addItem(8, new SWItem(Message.parse("BAU_DELETE_GUI_CANCEL", p), 1), click ->
- inventory.close()
- );
- inventory.addItem(0, new SWItem(Message.parse("BAU_DELETE_GUI_DELETE", p), 10), click -> {
- worldDeletion.run();
- inventory.close();
- });
- inventory.open();
- }
-
- private static void deleteWorld(ProxiedPlayer player, String world) {
- ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
- Bauserver subserver = Bauserver.get(player.getUniqueId());
- if(subserver != null)
- subserver.stop();
-
- SubserverSystem.deleteFolder(BungeeCore.local, world);
- Message.send("BAU_DELETE_DELETED", player);
- });
- }
-
- @Register("test")
- @Register("testarena")
- public void testarena(ProxiedPlayer p, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) {
- FightCommand.createArena(p, "/bau testarena ", false, arenaMode, map, false, (player, mode, m) -> {
- ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> new ServerStarter().test(mode, m, p).start());
- });
- }
-
- @Register(value = "lock", description = "BAU_LOCKED_OPTIONS")
- public void lock(ProxiedPlayer p, BauLockState bauLockState) {
- BauLock.setLocked(p, bauLockState);
- }
-
- @Register("unlock")
- public void unlock(ProxiedPlayer p) {
- BauLock.setLocked(p, BauLockState.OPEN);
- }
-
- private static BauweltMember member(ProxiedPlayer p, SteamwarUser member){
- if (member == null) {
- Message.send("UNKNOWN_PLAYER", p);
- return null;
- }
-
- BauweltMember target = BauweltMember.getBauMember(p.getUniqueId(), member.getUUID());
- if (target == null) {
- Message.send("BAU_MEMBER_NOMEMBER", p);
- return null;
- }
- return target;
- }
-
- private static void sendPermissionUpdate(ProxiedPlayer p, BauweltMember target, String what){
- ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(target.getMemberID()).getUUID());
- if(player != null)
- Message.send("BAU_MEMBER_SET_TARGET", player, p.getName(), Message.parse(what, player));
- Message.send("BAU_MEMBER_SET", p, Message.parse(what, p));
- }
-}
diff --git a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java
deleted file mode 100644
index 90eb22f..0000000
--- a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java
+++ /dev/null
@@ -1,174 +0,0 @@
-package de.steamwar.bungeecore.commands;
-
-import de.steamwar.bungeecore.ArenaMode;
-import de.steamwar.bungeecore.BungeeCore;
-import de.steamwar.bungeecore.ServerStarter;
-import de.steamwar.bungeecore.listeners.ConnectionListener;
-import de.steamwar.command.SWCommand;
-import de.steamwar.command.TypeMapper;
-import de.steamwar.messages.ChatSender;
-import net.md_5.bungee.api.CommandSender;
-import net.md_5.bungee.api.ProxyServer;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.util.*;
-import java.util.stream.Collectors;
-
-public class BuilderCloudCommand extends SWCommand {
-
- private final Map versionMap = new HashMap<>();
-
- public BuilderCloudCommand() {
- super("buildercloud", ConnectionListener.BUILDERCLOUD_PERMISSION, "builder");
-
- versionMap.put("15", ServerStarter.Version.SPIGOT_15);
- versionMap.put("1.15", ServerStarter.Version.SPIGOT_15);
- versionMap.put("1.15.2", ServerStarter.Version.SPIGOT_15);
- versionMap.put("19", ServerStarter.Version.PAPER_19);
- versionMap.put("1.19", ServerStarter.Version.PAPER_19);
- versionMap.put("1.19.2", ServerStarter.Version.PAPER_19);
- versionMap.put("20", ServerStarter.Version.PAPER_20);
- versionMap.put("1.20", ServerStarter.Version.PAPER_20);
- versionMap.put("1.20.1", ServerStarter.Version.PAPER_20);
- }
-
- @Register(value = "create", description = "BUILDERCLOUD_CREATE_USAGE")
- public void create(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String map, @OptionalValue("") @Mapper("generator") @AllowNull File generator) {
- mapFile(version, map).mkdir();
- new ServerStarter().builder(version, map, generator).send(player).start();
- }
-
- @Register(description = "BUILDERCLOUD_USAGE")
- public void start(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String map) {
- if(!mapFile(version, map).exists()) {
- ChatSender.of(player).system("BUILDERCLOUD_UNKNOWN_MAP");
- return;
- }
-
- new ServerStarter().builder(version, map, null).send(player).start();
- }
-
- @Register(value = "rename", description = "BUILDERCLOUD_RENAME_USAGE")
- public void rename(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String oldName, String newName) {
- File oldMap = mapFile(version, oldName);
- if(!oldMap.exists()) {
- ChatSender.of(player).system("BUILDERCLOUD_UNKNOWN_MAP");
- return;
- }
-
- File newMap = mapFile(version, newName);
- if(newMap.exists()) {
- ChatSender.of(player).system("BUILDERCLOUD_EXISTING_MAP");
- return;
- }
-
- try {
- Files.move(oldMap.toPath(), newMap.toPath());
- } catch (IOException e) {
- throw new SecurityException(e);
- }
-
- ChatSender.of(player).system("BUILDERCLOUD_RENAMED");
- }
-
- @Register(value = "deploy", description = "BUILDERCLOUD_DEPLOY_USAGE")
- public void deploy(ProxiedPlayer player, @Mapper("nonHistoricArenaMode") ArenaMode arenaMode, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String map) {
- if(!mapFile(version, map).exists()) {
- ChatSender.of(player).system("BUILDERCLOUD_UNKNOWN_MAP");
- return;
- }
-
- ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
- BungeeCore.local.execute("/binarys/deployarena.py", arenaMode.getConfig(), Integer.toString(version.getVersionSuffix()), map);
- ArenaMode.init();
- ChatSender.of(player).system("BUILDERCLOUD_DEPLOY_FINISHED");
- });
- }
-
- @ClassMapper(value = ServerStarter.Version.class, local = true)
- private TypeMapper versionTypeMapper() {
- return new TypeMapper() {
- @Override
- public ServerStarter.Version map(CommandSender commandSender, String[] previousArguments, String s) {
- return versionMap.get(s);
- }
-
- @Override
- public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) {
- return versionMap.keySet();
- }
- };
- }
-
- @Cached(global = true)
- @Mapper(value = "map", local = true)
- private TypeMapper mapTypeMapper() {
-
- return new TypeMapper() {
- @Override
- public String map(CommandSender commandSender, String[] previousArguments, String s) {
- return s;
- }
-
- @Override
- public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) {
- File folder = getWorldFolder(previousArguments, 1);
-
- String[] files;
- if(folder == null || (files = folder.list()) == null)
- return Collections.emptyList();
-
- return Arrays.stream(files).filter(file -> new File(folder, file).isDirectory()).filter(file -> s.startsWith(".") || !file.startsWith(".")).collect(Collectors.toList());
- }
- };
- }
-
- @Cached(global = true)
- @Mapper(value = "generator", local = true)
- private TypeMapper generatorTypeMapper() {
-
- return new TypeMapper() {
- @Override
- public File map(CommandSender commandSender, String[] previousArguments, String s) {
- if(s.equals(""))
- return null;
-
- File folder = getWorldFolder(previousArguments, 2);
-
- if(folder == null)
- throw new SecurityException();
-
- File generator = new File(folder, s + ".dat");
- if(!generator.exists() || !generator.isFile())
- throw new SecurityException();
-
- return generator;
- }
-
- @Override
- public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) {
- File folder = getWorldFolder(previousArguments, 2);
-
- String[] files;
- if(folder == null || (files = folder.list()) == null)
- return Collections.emptyList();
-
- return Arrays.stream(files).filter(file -> new File(folder, file).isFile()).filter(file -> file.endsWith(".dat")).map(file -> file.substring(0, file.length() - 4)).collect(Collectors.toList());
- }
- };
- }
-
- private File mapFile(ServerStarter.Version version, String map) {
- return new File(version.getWorldFolder(ServerStarter.BUILDER_BASE_PATH), map);
- }
-
- private File getWorldFolder(String[] previousArguments, int offset) {
- ServerStarter.Version v = versionMap.get(previousArguments[previousArguments.length - offset]);
- if(v == null)
- return null;
- return new File(v.getWorldFolder(ServerStarter.BUILDER_BASE_PATH));
- }
-}
diff --git a/src/de/steamwar/bungeecore/commands/CheckCommand.java b/src/de/steamwar/bungeecore/commands/CheckCommand.java
deleted file mode 100644
index 82ebaa6..0000000
--- a/src/de/steamwar/bungeecore/commands/CheckCommand.java
+++ /dev/null
@@ -1,340 +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 .
-*/
-
-package de.steamwar.bungeecore.commands;
-
-import de.steamwar.bungeecore.*;
-import de.steamwar.bungeecore.bot.util.DiscordSchemAlert;
-import de.steamwar.bungeecore.listeners.ConnectionListener;
-import de.steamwar.sql.*;
-import de.steamwar.command.SWCommand;
-import net.md_5.bungee.api.ChatColor;
-import net.md_5.bungee.api.ProxyServer;
-import net.md_5.bungee.api.chat.ClickEvent;
-import net.md_5.bungee.api.chat.TextComponent;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-import net.md_5.bungee.config.Configuration;
-
-import java.sql.Timestamp;
-import java.time.Instant;
-import java.util.*;
-import java.util.concurrent.TimeUnit;
-import java.util.logging.Level;
-
-public class CheckCommand extends SWCommand {
- private static final Map fightTypes = new HashMap<>();
- private static Map> checkQuestions = new HashMap<>();
- private static Map> ranks = new HashMap<>();
-
- private static Map currentCheckers = new HashMap<>();
- private static Map currentSchems = new HashMap<>();
-
- public static void setCheckQuestions(SchematicType checkType, Configuration config) {
- checkQuestions.put(checkType, config.getStringList("CheckQuestions"));
- if(!config.getStringList("Ranks").isEmpty())
- ranks.put(checkType, config.getStringList("Ranks"));
- }
-
- public static void addFightType(SchematicType checkType, SchematicType fightType) {
- fightTypes.put(checkType, fightType);
- }
-
- public static boolean isChecking(ProxiedPlayer player){
- return currentCheckers.containsKey(player.getUniqueId());
- }
-
- public static SchematicNode getCheckingSchem(ProxiedPlayer player) {
- return currentCheckers.get(player.getUniqueId()).schematic;
- }
-
- public CheckCommand() {
- super("check", ConnectionListener.CHECK_PERMISSION);
-
- ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
- List schematics = getSchemsToCheck();
- if(schematics.size() != currentCheckers.size())
- Message.team("CHECK_REMINDER", "CHECK_REMINDER_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check list"), schematics.size() - currentCheckers.size());
- }, 10, 10, TimeUnit.MINUTES);
- }
- public static void sendReminder(ProxiedPlayer player) {
- List schematics = getSchemsToCheck();
- if(schematics.size() != currentCheckers.size())
- Message.send("CHECK_REMINDER", player, Message.parse("CHECK_REMINDER_HOVER", player), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check list"), schematics.size() - currentCheckers.size());
- }
-
- @Register(value = "list", description = "CHECK_HELP_LIST")
- public void list(ProxiedPlayer player) {
- List schematicList = getSchemsToCheck();
-
- Message.sendPrefixless("CHECK_LIST_HEADER", player, schematicList.size());
-
- for (SchematicNode schematic : schematicList) {
- CheckSession current = currentSchems.get(schematic.getId());
- long waitedMillis = Timestamp.from(Instant.now()).getTime() - schematic.getLastUpdate().getTime();
- String color = waitedMillis > 14400000 ? (waitedMillis > 86400000 ? "§c" : "§e") : "§a";
- long hours = waitedMillis / 3600000;
- long minutes = (waitedMillis - hours * 3600000) / 60000;
- String waitTime = color + Message.parse("CHECK_LIST_WAIT", player, hours, (minutes < 10) ? "0" + minutes : minutes);
- if (current == null) {
- Message.sendPrefixless("CHECK_LIST_TO_CHECK", player,
- Message.parse("CHECK_LIST_TO_CHECK_HOVER", player),
- new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check schematic " + schematic.getId()),
- waitTime,
- schematic.getSchemtype().getKuerzel(), SteamwarUser.get(schematic.getOwner()).getUserName(), schematic.getName());
- } else {
- Message.sendPrefixless("CHECK_LIST_CHECKING", player,
- Message.parse("CHECK_LIST_CHECKING_HOVER", player),
- new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + current.checker.getName()),
- waitTime,
- schematic.getSchemtype().getKuerzel(), SteamwarUser.get(schematic.getOwner()).getUserName(), schematic.getName(), current.checker.getName());
- }
- }
- }
-
- @Register(value = "schematic", noTabComplete = true)
- public void schematic(ProxiedPlayer player, String schemID) {
- if(isChecking(player)){
- Message.send("CHECK_SCHEMATIC_ALREADY_CHECKING", player);
- return;
- }
-
- SteamwarUser checkingUser = SteamwarUser.get(player.getUniqueId());
- SchematicNode schem = SchematicNode.getSchematicNode(Integer.parseInt(schemID));
- if(!schem.getSchemtype().check()){
- ProxyServer.getInstance().getLogger().log(Level.SEVERE, player.getName() + " tried to check an uncheckable schematic!");
- return;
- }else if(schem.getOwner() == checkingUser.getId()) {
- Message.send("CHECK_SCHEMATIC_OWN", player);
- return;
- }
-
- int playerTeam = checkingUser.hasPerm(UserPerm.MODERATION) ? 0 : checkingUser.getTeam();
- if (playerTeam != 0 && SteamwarUser.get(schem.getOwner()).getTeam() == playerTeam) {
- Message.send("CHECK_SCHEMATIC_OWN_TEAM", player);
- return;
- }
- new CheckSession(player, schem);
- }
-
- @Register(value = "cancel", description = "CHECK_HELP_CANCEL")
- @Register("abort")
- public void abortCommand(ProxiedPlayer player) {
- abort(player);
- }
-
- public static void abort(ProxiedPlayer player) {
- if(notChecking(player))
- return;
-
- Message.send("CHECK_ABORT", player);
- currentCheckers.get(player.getUniqueId()).abort();
- }
-
- @Register(value = "next", description = "CHECK_HELP_NEXT")
- public void next(ProxiedPlayer player) {
- next(player, new String[0]);
- }
-
- @Register(value = "accept")
- public void accept(ProxiedPlayer player, @OptionalValue("") String rank) {
- if (rank.equals("")) {
- next(player, new String[0]);
- } else {
- next(player, new String[]{rank});
- }
- }
-
- @Register(value = "decline", description = "CHECK_HELP_DECLINE")
- public void decline(ProxiedPlayer player, String... message) {
- if(notChecking(player))
- return;
-
- currentCheckers.get(player.getUniqueId()).decline(String.join(" ", message));
- }
-
- public static List getSchemsToCheck(){
- List schematicList = new LinkedList<>();
-
- for (SchematicType type : SchematicType.values()) {
- if (type.check())
- schematicList.addAll(SchematicNode.getAllSchematicsOfType(type.toDB()));
- }
- return schematicList;
- }
-
- public static String getChecker(SchematicNode schematic) {
- if (currentSchems.get(schematic.getId()) == null) return null;
- return currentSchems.get(schematic.getId()).checker.getName();
- }
-
- private static boolean notChecking(ProxiedPlayer player){
- if(!isChecking(player)){
- Message.send("CHECK_NOT_CHECKING", player);
- return true;
- }
- return false;
- }
-
- private void next(ProxiedPlayer player, String[] args){
- if(notChecking(player))
- return;
-
- int rank = 0;
- if(args.length > 0){
- try{
- rank = Integer.parseInt(args[0]);
- }catch(NumberFormatException e){
- Message.send("CHECK_INVALID_RANK", player);
- return;
- }
- }
-
- currentCheckers.get(player.getUniqueId()).next(rank);
- }
-
- private static class CheckSession{
- private final ProxiedPlayer checker;
- private final SchematicNode schematic;
- private final Timestamp startTime;
- private final ListIterator checkList;
-
- private CheckSession(ProxiedPlayer checker, SchematicNode schematic){
- this.checker = checker;
- this.schematic = schematic;
- this.startTime = Timestamp.from(Instant.now());
- this.checkList = checkQuestions.get(schematic.getSchemtype()).listIterator();
-
- ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
- ArenaMode mode = ArenaMode.getBySchemType(fightTypes.get(schematic.getSchemtype()));
- if(!new ServerStarter().test(mode, mode.getRandomMap(), checker).check(schematic.getId()).start()) {
- remove();
- return;
- }
-
- currentCheckers.put(checker.getUniqueId(), this);
- currentSchems.put(schematic.getId(), this);
- for(CheckedSchematic previous : CheckedSchematic.previousChecks(schematic))
- Message.sendPrefixless("CHECK_SCHEMATIC_PREVIOUS", checker, previous.getEndTime(), SteamwarUser.get(previous.getValidator()).getUserName(), previous.getDeclineReason());
- next(0);
- });
- }
-
- private void next(int rank) {
- if(!checkList.hasNext()){
- accept(rank);
- return;
- }
-
- checker.sendMessage(TextComponent.fromLegacyText(checkList.next()));
-
- TextComponent next = new TextComponent();
- next.setColor(ChatColor.GREEN);
- if(checkList.hasNext()){
- next.setText(Message.parse("CHECK_NEXT", checker));
- next.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check next"));
- }else if(ranks.containsKey(schematic.getSchemtype())){
- List r = ranks.get(schematic.getSchemtype());
- for(int i = 0; i < r.size(); i++){
- Message.sendPrefixless("CHECK_RANK", checker,
- Message.parse("CHECK_RANK_HOVER", checker),
- new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check accept " + (i+1)),
- i+1, r.get(i));
- Message.sendPrefixless("SPACER", checker);
- }
- }else{
- next.setText(Message.parse("CHECK_ACCEPT", checker));
- next.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check accept"));
- }
-
- TextComponent decline = new TextComponent(" " + Message.parse("CHECK_DECLINE", checker));
- decline.setColor(ChatColor.RED);
- decline.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/check decline "));
-
- next.addExtra(decline);
- checker.sendMessage(next);
- }
-
- private void accept(int rank){
- if(createLog("freigegeben")) {
- if(ranks.containsKey(schematic.getSchemtype())){
- if(rank <= 0 || ranks.get(schematic.getSchemtype()).size() < rank){
- Message.send("CHECK_INVALID_RANK", checker);
- return;
- }
- schematic.setRank(rank);
- }
-
- schematic.setType(fightTypes.get(schematic.getSchemtype()).toDB());
- SteamwarUser user = SteamwarUser.get(schematic.getOwner());
- ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUUID());
- if(player != null) {
- Message.send("CHECK_ACCEPTED", player, schematic.getSchemtype().name(), schematic.getName());
- } else {
- DiscordSchemAlert.sendAccept(schematic, user);
- }
- Message.team("CHECK_ACCEPTED_TEAM", schematic.getName(), user.getUserName());
- }
- stop();
- }
-
- private void decline(String reason){
- if(createLog(reason)) {
- SteamwarUser user = SteamwarUser.get(schematic.getOwner());
- ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUUID());
- if(player != null) {
- Message.send("CHECK_DECLINED", player, schematic.getSchemtype().name(), schematic.getName(), reason);
- } else {
- DiscordSchemAlert.sendDecline(schematic, user, reason);
- }
- Message.team("CHECK_DECLINED_TEAM", schematic.getName(), user.getUserName(), reason);
- schematic.setType(SchematicType.Normal.toDB());
- }
-
- stop();
- }
-
- private void abort(){
- createLog("Prüfvorgang abgebrochen");
- stop();
- }
-
- private void stop(){
- currentCheckers.remove(checker.getUniqueId());
- currentSchems.remove(schematic.getId());
- ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
- Bauserver subserver = Bauserver.get(checker.getUniqueId());
- if(subserver != null)
- subserver.stop();
- });
- }
-
- private void remove() {
- currentCheckers.remove(checker.getUniqueId());
- currentSchems.remove(schematic.getId());
- }
-
- private boolean createLog(String reason) {
- if(SchematicNode.getSchematicNode(schematic.getId()) == null) // Schematic was deleted
- return false;
-
- CheckedSchematic.create(schematic, SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), reason);
- return true;
- }
- }
-}
diff --git a/src/de/steamwar/bungeecore/commands/EventCommand.java b/src/de/steamwar/bungeecore/commands/EventCommand.java
deleted file mode 100644
index fe197e7..0000000
--- a/src/de/steamwar/bungeecore/commands/EventCommand.java
+++ /dev/null
@@ -1,138 +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 .
-*/
-
-package de.steamwar.bungeecore.commands;
-
-import de.steamwar.bungeecore.*;
-import de.steamwar.messages.ChatSender;
-import de.steamwar.sql.*;
-import de.steamwar.command.SWCommand;
-import de.steamwar.command.SWCommandUtils;
-import de.steamwar.command.TypeMapper;
-import de.steamwar.command.TypeValidator;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-
-import java.time.Instant;
-import java.time.format.DateTimeFormatter;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-public class EventCommand extends SWCommand {
-
- public EventCommand() {
- super("event");
- }
-
- @Validator("noEvent")
- public TypeValidator noEventValidator() {
- return (sender, value, messageSender) -> Event.get() == null;
- }
-
- @Register
- public void noCurrentEvent(@Validator("noEvent") ProxiedPlayer player){
- Message.send("EVENT_NO_CURRENT", player);
- List coming = Event.getComing();
- Instant now = Instant.now();
- if(!coming.isEmpty()){
- DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern(Message.parse("EVENT_DATE_FORMAT", player));
- Message.send("EVENT_COMING", player);
- for(Event e : coming){
- Message.send("EVENT_COMING_EVENT", player, e.getStart().toLocalDateTime().format(dateFormat), e.getEnd().toLocalDateTime().format(dateFormat), e.getEventName());
- Set teams = TeamTeilnahme.getTeams(e.getEventID());
- if(now.isBefore(e.getDeadline().toInstant())) {
- Message.send("EVENT_COMING_DEADLINE", player, e.getDeadline());
- }
- SchematicType schemType = e.getSchematicType();
- if (schemType != null) {
- if (schemType.getDeadline() != null && now.isBefore(schemType.getDeadline().toInstant())) {
- Message.send("EVENT_COMING_SCHEM_DEADLINE", player, e.getDeadline());
- }
- }
- if(!teams.isEmpty()){
- StringBuilder tline = new StringBuilder();
- for(Team t : teams){
- tline.append(' ').append(Message.parse("EVENT_COMING_TEAM", player, t.getTeamColor(), t.getTeamKuerzel()));
- }
- Message.send("EVENT_COMING_TEAMS", player, tline.toString());
- }
- }
- }
- }
-
- @Register
- public void eventOverview(@Validator(value = "noEvent", invert = true) ProxiedPlayer player) {
- Event currentEvent = Event.get();
- Message.send("EVENT_USAGE", player);
-
- List fights = EventFight.getEvent(currentEvent.getEventID());
-
- Message.send("EVENT_CURRENT_EVENT", player, currentEvent.getEventName());
-
- DateTimeFormatter timeFormat = DateTimeFormatter.ofPattern(Message.parse("EVENT_TIME_FORMAT", player));
- for(EventFight fight : fights){
- Team blue = Team.get(fight.getTeamBlue());
- Team red = Team.get(fight.getTeamRed());
- StringBuilder fline = new StringBuilder(Message.parse("EVENT_CURRENT_FIGHT", player, fight.getStartTime().toLocalDateTime().format(timeFormat), blue.getTeamColor(), blue.getTeamKuerzel(),
- red.getTeamColor(), red.getTeamKuerzel()));
-
- if(fight.hasFinished()){
- switch(fight.getErgebnis()){
- case 1:
- fline.append(Message.parse("EVENT_CURRENT_FIGHT_WIN", player, blue.getTeamColor(), blue.getTeamKuerzel()));
- break;
- case 2:
- fline.append(Message.parse("EVENT_CURRENT_FIGHT_WIN", player, red.getTeamColor(), red.getTeamKuerzel()));
- break;
- default:
- fline.append(Message.parse("EVENT_CURRENT_FIGHT_DRAW", player));
- }
- }
-
- BungeeCore.send(player, fline.toString());
- }
- }
-
- @Register
- public void eventWithTeam(@Validator(value = "noEvent", invert = true) ProxiedPlayer player, @ErrorMessage("EVENT_NO_TEAM") Team team) {
- Subserver eventArena = EventStarter.getEventServer().get(team.getTeamId());
- if(eventArena == null || !Subserver.getServerList().contains(eventArena)){
- Message.send("EVENT_NO_FIGHT_TEAM", player);
- return;
- }
- ChatSender sender = ChatSender.of(player);
- if (!PunishmentCommand.isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer)) {
- SubserverSystem.sendPlayer(eventArena, player);
- }
- }
-
- @ClassMapper(Team.class)
- @Cached(cacheDuration = 10, global = true)
- public TypeMapper teamMapper() {
- return SWCommandUtils.createMapper(Team::get, s -> EventStarter.getEventServer()
- .keySet()
- .stream()
- .map(Team::get)
- .map(t -> Arrays.asList(t.getTeamKuerzel(), t.getTeamColor()))
- .flatMap(Collection::stream)
- .collect(Collectors.toList()));
- }
-}
diff --git a/src/de/steamwar/bungeecore/commands/FightCommand.java b/src/de/steamwar/bungeecore/commands/FightCommand.java
deleted file mode 100644
index a397d97..0000000
--- a/src/de/steamwar/bungeecore/commands/FightCommand.java
+++ /dev/null
@@ -1,175 +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 .
-*/
-
-package de.steamwar.bungeecore.commands;
-
-import de.steamwar.bungeecore.*;
-import de.steamwar.bungeecore.inventory.SWInventory;
-import de.steamwar.bungeecore.inventory.SWItem;
-import de.steamwar.command.SWCommand;
-import de.steamwar.messages.ChatSender;
-import net.md_5.bungee.api.ChatColor;
-import net.md_5.bungee.api.ChatMessageType;
-import net.md_5.bungee.api.chat.ClickEvent;
-import net.md_5.bungee.api.chat.HoverEvent;
-import net.md_5.bungee.api.chat.TextComponent;
-import net.md_5.bungee.api.chat.hover.content.Text;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-
-/**
- * Jeder Fightcommand (auch bau testarena und challenge) haben folgende Optionskette:
- *
- * [ArenaMode] [Map]
- *
- * Sollte der ArenaMode fehlen, kann er mit getMode() bestimmt werden.
- * Sollte die Map fehlen, kann sie mit getMap() bestimmt werden.
- */
-
-public class FightCommand extends SWCommand {
-
- public FightCommand() {
- super("fight", "", "f");
- }
-
- private static ArenaMode getMode(ChatSender sender, String arg){
- ArenaMode mode = ArenaMode.getByChat(arg);
- if(mode != null)
- return mode;
-
- sender.system("FIGHT_UNKNOWN_GAMEMODE", arg);
- return null;
- }
-
- private static String getMap(ChatSender sender, ArenaMode mode, String arg){
- String realMap = mode.hasMap(arg.toLowerCase());
- if(realMap != null)
- return realMap;
- if(arg.equalsIgnoreCase("Random"))
- return mode.getRandomMap();
-
- sender.system("FIGHT_UNKNOWN_ARENA");
- return null;
- }
-
- private static void getModes(ChatSender sender, String precommand, boolean historic){
- TextComponent start = new TextComponent();
- TextComponent current = start;
- for(ArenaMode mode : ArenaMode.getAllModes()){
- if(mode.withoutChatName() || mode.isHistoric() != historic)
- continue;
- String command = precommand + mode.getChatName();
- current.setBold(true);
- current.setColor(ChatColor.GRAY);
- current.setText(mode.getChatName() + " ");
- current.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("§e" + command)));
- current.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
- if(current != start)
- start.addExtra(current);
- current = new TextComponent();
- }
-
- sender.sendMessage(ChatMessageType.SYSTEM, start);
- }
-
- private static boolean alreadyInArena(ProxiedPlayer player){
- Subserver subserver = Subserver.getSubserver(player);
- if(subserver != null && subserver.getType() == Servertype.ARENA){
- Message.send("FIGHT_IN_ARENA", player);
- return true;
- }
-
- return false;
- }
-
- static void createArena(ProxiedPlayer player, String precommand, boolean allowMerging, ArenaMode arenaMode, String map, boolean historic, FightCallback callback) {
- ChatSender sender = ChatSender.of(player);
-
- if(alreadyInArena(player))
- return;
-
- if (arenaMode == null) {
- getModes(sender, precommand, historic);
- return;
- }
-
- if (map == null)
- map = arenaMode.getRandomMap();
-
- if (!allowMerging) {
- callback.run(player, arenaMode, map);
- } else {
- suggestMerging(player, arenaMode, map, callback);
- }
- }
-
- public static void suggestMerging(ProxiedPlayer player, ArenaMode mode, String map, FightCallback declineMerge) {
- Arenaserver mergable = null;
- synchronized (Subserver.getServerList()) {
- for (Subserver subserver : Subserver.getServerList()) {
- if(subserver instanceof Arenaserver) {
- Arenaserver arenaserver = (Arenaserver) subserver;
- if(mode.getInternalName().equals(arenaserver.getMode()) && arenaserver.isAllowMerge() && arenaserver.getServer().getPlayers().size() == 1) {
- mergable = arenaserver;
- break;
- }
- }
- }
- }
-
- if(mergable == null) {
- declineMerge.run(player, mode, map);
- return;
- }
-
- SWInventory inventory = new SWInventory(player, 9, Message.parse("FIGHT_MERGE_TITLE", player));
- inventory.addItem(0, new SWItem(Message.parse("FIGHT_MERGE_DECLINE", player), 1), click -> {
- inventory.close();
- declineMerge.run(player, mode, map);
- });
- Arenaserver finalMergable = mergable;
- SWItem item = new SWItem(Message.parse("FIGHT_MERGE_INFO", player, mode.getDisplayName(), finalMergable.getMap()), 11);
- item.addLore(Message.parse("FIGHT_MERGE_INFO_LORE_1", player, finalMergable.getServer().getPlayers().toArray(new ProxiedPlayer[1])[0].getName()));
- inventory.addItem(4, item, click -> {});
- inventory.addItem(8, new SWItem(Message.parse("FIGHT_MERGE_ACCEPT", player), 10), click -> {
- if(Subserver.getServerList().contains(finalMergable)) {
- finalMergable.sendPlayer(player);
- } else {
- Message.send("FIGHT_MERGE_OFFLINE", player);
- declineMerge.run(player, mode, map);
- }
- });
- inventory.open();
- }
-
- @Register
- public void fight(@Validator("arenaPlayer") ProxiedPlayer player, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) {
- createArena(player, "/fight ", true, arenaMode, map, false,
- (p, mode, m) -> new ServerStarter().arena(mode, m).blueLeader(p).callback(
- arena -> Message.broadcast("FIGHT_BROADCAST", "FIGHT_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName())
- ).start()
- );
- }
-
- /**
- * Is called when arena parameters are clear.
- */
- interface FightCallback {
- void run(ProxiedPlayer player, ArenaMode mode, String map);
- }
-}
diff --git a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java
deleted file mode 100644
index 54d4bec..0000000
--- a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java
+++ /dev/null
@@ -1,68 +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 .
-*/
-
-package de.steamwar.bungeecore.commands;
-
-import de.steamwar.bungeecore.Message;
-import de.steamwar.bungeecore.Subserver;
-import de.steamwar.command.SWCommand;
-import de.steamwar.command.TypeValidator;
-import de.steamwar.sql.SteamwarUser;
-import de.steamwar.sql.UserPerm;
-import net.md_5.bungee.api.chat.ClickEvent;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-
-public class JoinmeCommand extends SWCommand {
-
- public JoinmeCommand() {
- super("joinme");
- }
-
- @Register(description = "JOINME_USAGE")
- public void genericCommand(ProxiedPlayer player) {
- if (!SteamwarUser.get(player.getUniqueId()).hasPerm(UserPerm.TEAM)) {
- Message.send("JOINME_USAGE", player);
- return;
- }
- Message.broadcast("JOINME_BROADCAST", "JOINME_BROADCAST_HOVER",
- new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()), player.getName(), player.getServer().getInfo().getName());
- }
-
- @Register
- public void genericCommand(ProxiedPlayer player, @Validator ProxiedPlayer target) {
- if (target.equals(player)){
- Message.send("JOINME_PLAYER_SELF", player);
- return;
- }
-
- Subserver subserver = Subserver.getSubserver(target);
- TpCommand.teleport(player, subserver != null ? subserver.getServer() : target.getServer().getInfo());
- }
-
- @ClassValidator(ProxiedPlayer.class)
- public TypeValidator playerMapper() {
- return (sender, value, messageSender) -> {
- if (value == null || !value.isConnected()) {
- messageSender.send("JOINME_PLAYER_OFFLINE", sender);
- return false;
- }
- return true;
- };
- }
-}
diff --git a/src/de/steamwar/bungeecore/commands/ListCommand.java b/src/de/steamwar/bungeecore/commands/ListCommand.java
deleted file mode 100644
index 6caa4a1..0000000
--- a/src/de/steamwar/bungeecore/commands/ListCommand.java
+++ /dev/null
@@ -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 .
- */
-
-package de.steamwar.bungeecore.commands;
-
-import de.steamwar.bungeecore.Message;
-import de.steamwar.bungeecore.Servertype;
-import de.steamwar.bungeecore.Subserver;
-import de.steamwar.command.SWCommand;
-import net.md_5.bungee.api.CommandSender;
-import net.md_5.bungee.api.ProxyServer;
-import net.md_5.bungee.api.config.ServerInfo;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-import net.md_5.bungee.api.connection.Server;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.TreeMap;
-import java.util.stream.Collectors;
-
-public class ListCommand extends SWCommand {
-
- public ListCommand() {
- super("list", "");
- }
-
- public static synchronized TreeMap> getCustomTablist(){
- TreeMap> playerMap = new TreeMap<>();
- for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
- Server pserver = player.getServer();
- if (pserver == null) //Happens temporarily
- continue;
-
- ServerInfo server = pserver.getInfo();
- String serverName = server.getName();
-
- Subserver subserver = Subserver.getSubserver(server);
- if (subserver != null && subserver.getType() == Servertype.BAUSERVER) {
- playerMap.computeIfAbsent("Bau", s -> new ArrayList<>()).add(player);
- } else {
- playerMap.computeIfAbsent(serverName, s -> new ArrayList<>()).add(player);
- }
- }
- playerMap.forEach((server, players) -> players.sort((proxiedPlayer, t1) -> proxiedPlayer.getName().compareToIgnoreCase(t1.getName())));
- return playerMap;
- }
-
- @Register
- public void genericCommand(CommandSender commandSender) {
- TreeMap> playerMap = getCustomTablist();
- for (String server : playerMap.navigableKeySet()) {
- String serverName = server;
- if (server.equals("Bau")) {
- serverName = Message.parse("TABLIST_BAU", commandSender);
- }
- Message.send("LIST_COMMAND", commandSender, serverName, playerMap.get(server).stream().map(CommandSender::getName).collect(Collectors.joining(", ")));
- }
- }
-}
diff --git a/src/de/steamwar/bungeecore/commands/ModCommand.java b/src/de/steamwar/bungeecore/commands/ModCommand.java
deleted file mode 100644
index e82b1b4..0000000
--- a/src/de/steamwar/bungeecore/commands/ModCommand.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- 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 .
-*/
-
-package de.steamwar.bungeecore.commands;
-
-import de.steamwar.bungeecore.Message;
-import de.steamwar.bungeecore.inventory.SWInventory;
-import de.steamwar.bungeecore.inventory.SWItem;
-import de.steamwar.bungeecore.inventory.SWListInv;
-import de.steamwar.bungeecore.inventory.SWStreamInv;
-import de.steamwar.bungeecore.listeners.ConnectionListener;
-import de.steamwar.command.SWCommand;
-import de.steamwar.sql.Mod;
-import net.md_5.bungee.api.chat.ClickEvent;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-public class ModCommand extends SWCommand {
-
- public ModCommand() {
- super("mod", ConnectionListener.MOD_PERMISSION, "mods");
- }
-
- public static final Map playerFilterType = new HashMap<>();
-
- @Register
- public void genericCommand(ProxiedPlayer p) {
- playerFilterType.putIfAbsent(p,Mod.ModType.UNKLASSIFIED);
- openGui(p);
- }
-
- private void openGui(ProxiedPlayer p) {
- SWStreamInv swStreamInv = new SWStreamInv<>(p,Message.parse("MOD_COMMAND_GUI_TITLE",p), (click, element) -> {
- openClassificationGui(p,element);
- },page -> {
- Mod.ModType filtertype = playerFilterType.get(p);
- return Mod.getAllModsFiltered(page,45, filtertype).stream().map(mod -> new SWListInv.SWListEntry<>(getModItem(mod),mod)).collect(Collectors.toList());
- });
-
- swStreamInv.addItem(52,new SWItem("NAME_TAG","Filter"), click -> {
- swStreamInv.close();
- openFilterGui(p);
- });
-
- swStreamInv.open();
- }
-
- public void updateAndCloseGui(Mod.ModType modType, Mod mod, SWInventory toClose, ProxiedPlayer p) {
- mod.setModType(modType);
- toClose.close();
- openGui(p);
- }
-
- private void openFilterGui(ProxiedPlayer p) {
- SWInventory inv = new SWInventory(p, 9, "Filter");
-
- inv.addItem(1, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), click -> playerFilterType.replace(p, Mod.ModType.UNKLASSIFIED));
- inv.addItem(2, new SWItem(Message.parse("MOD_ALLOWED",p),2), click -> playerFilterType.replace(p, Mod.ModType.GREEN));
- inv.addItem(3, new SWItem(Message.parse("MOD_FORBIDDEN",p), 11), click -> playerFilterType.replace(p, Mod.ModType.YELLOW));
- inv.addItem(4, new SWItem(Message.parse("MOD_AUTOBAN",p),1), click -> playerFilterType.replace(p, Mod.ModType.RED));
- inv.addItem(5, new SWItem(Message.parse("MOD_YT",p),13), click -> playerFilterType.replace(p, Mod.ModType.YOUTUBER_ONLY));
-
- inv.addItem(8, new SWItem("ARROW", Message.parse("MOD_ITEM_BACK",p)), click -> {
- inv.close();
- openGui(p);
- });
-
- inv.open();
- }
-
- private void openClassificationGui(ProxiedPlayer p,Mod element) {
- SWInventory swInventory = new SWInventory(p,9,Message.parse("MOD_COMMAND_CLASSICIATION_GUI",p));
-
- swInventory.addItem(2, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), (click1 -> updateAndCloseGui(Mod.ModType.UNKLASSIFIED,element,swInventory,p)));
- swInventory.addItem(3, new SWItem(Message.parse("MOD_ALLOWED",p), 2), (click1 -> updateAndCloseGui(Mod.ModType.GREEN,element,swInventory,p)));
- swInventory.addItem(4, new SWItem(Message.parse("MOD_FORBIDDEN",p), 11), (click1 -> updateAndCloseGui(Mod.ModType.YELLOW,element,swInventory,p)));
- swInventory.addItem(5, new SWItem(Message.parse("MOD_AUTOBAN",p),1), (click1 -> updateAndCloseGui(Mod.ModType.RED,element,swInventory,p)));
- swInventory.addItem(6, new SWItem(Message.parse("MOD_YT",p), 13), (click1 -> updateAndCloseGui(Mod.ModType.YOUTUBER_ONLY,element,swInventory,p)));
-
- swInventory.addItem(8,new SWItem("ARROW",Message.parse("MOD_ITEM_BACK",p)), click1 -> {
- swInventory.close();
- openGui(p);
- });
-
- swInventory.open();
- }
-
- private SWItem getModItem(Mod modEntry) {
- SWItem item = new SWItem("NAME_TAG", modEntry.getModName());
-
- item.addLore(modEntry.getPlatform().name());
-
- return item;
- }
-
- @Register(value = {"set"},description = "MOD_COMMAND_SET_USAGE")
- public void set(ProxiedPlayer p,String modName,Mod.Platform platform,Mod.ModType newModType) {
- Mod mod = Mod.get(modName, platform);
- if(mod == null) {
- Message.send("MOD_COMMAND_NOT_FOUND_IN_DATABASE",p,modName, platform.name());
- return;
- }
-
- mod.setModType(newModType);
- Message.send("MOD_CHANGED_TYPE",p,modName,platform.name(),newModType.name());
- }
-
- @Register(value = {"get"},description = "MOD_COMMAND_GET_USAGE")
- public void get(ProxiedPlayer p,String modName,Mod.Platform platform) {
- Mod mod = Mod.get(modName, platform);
- if(mod == null) {
- Message.send("MOD_COMMAND_NOT_FOUND_IN_DATABASE", p, modName, platform.name());
- return;
- }
-
- Message.send("MOD_COMMAND_INFO", p, modName, platform.name(), mod.getModType().name());
- }
-
- @Register(value = {"next"})
- public void next(ProxiedPlayer p) {
- Mod mod = Mod.findFirstMod();
- if(mod == null) {
- Message.send("MOD_NO_MORE_UNCLASSIFIED_MODS",p);
- return;
- }
-
- Message.send("MOD_FOUND_NEXT_MOD",p,"MOD_OPEN_GUI",new ClickEvent(ClickEvent.Action.RUN_COMMAND,""),mod.getModName(),mod.getPlatform().name());
- }
-}
diff --git a/src/de/steamwar/bungeecore/commands/RegelnCommand.java b/src/de/steamwar/bungeecore/commands/RegelnCommand.java
deleted file mode 100644
index bb1f3b0..0000000
--- a/src/de/steamwar/bungeecore/commands/RegelnCommand.java
+++ /dev/null
@@ -1,42 +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 .
-*/
-
-package de.steamwar.bungeecore.commands;
-
-import de.steamwar.bungeecore.Message;
-import de.steamwar.command.SWCommand;
-import net.md_5.bungee.api.chat.ClickEvent;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-
-public class RegelnCommand extends SWCommand {
- public RegelnCommand() {
- super("regeln", null, "rules");
- }
-
- @Register
- public void genericCommand(ProxiedPlayer player) {
- Message.send("REGELN_RULES", player);
- Message.sendPrefixless("REGELN_AS", player, Message.parse("REGELN_AS_HOVER", player), new ClickEvent(ClickEvent.Action.OPEN_URL, Message.parse("REGELN_AS_URL", player)));
- Message.sendPrefixless("REGELN_MWG", player, Message.parse("REGELN_MWG_HOVER", player), new ClickEvent(ClickEvent.Action.OPEN_URL, Message.parse("REGELN_MWG_URL", player)));
- Message.sendPrefixless("REGELN_WG", player, Message.parse("REGELN_WG_HOVER", player), new ClickEvent(ClickEvent.Action.OPEN_URL, Message.parse("REGELN_WG_URL", player)));
- Message.sendPrefixless("REGELN_WS", player, Message.parse("REGELN_WS_HOVER", player), new ClickEvent(ClickEvent.Action.OPEN_URL, Message.parse("REGELN_WS_URL", player)));
- Message.sendPrefixless("REGELN_QG", player, Message.parse("REGELN_QG_HOVER", player), new ClickEvent(ClickEvent.Action.OPEN_URL, Message.parse("REGELN_QG_URL", player)));
- Message.sendPrefixless("REGELN_CONDUCT", player, Message.parse("REGELN_CONDUCT_HOVER", player), new ClickEvent(ClickEvent.Action.OPEN_URL, Message.parse("REGELN_CONDUCT_URL", player)));
- }
-}
diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java
deleted file mode 100644
index fe738a9..0000000
--- a/src/de/steamwar/bungeecore/commands/TeamCommand.java
+++ /dev/null
@@ -1,725 +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 .
-*/
-
-package de.steamwar.bungeecore.commands;
-
-import de.steamwar.bungeecore.Message;
-import de.steamwar.bungeecore.Storage;
-import de.steamwar.bungeecore.inventory.SWItem;
-import de.steamwar.bungeecore.inventory.SWListInv;
-import de.steamwar.command.PreviousArguments;
-import de.steamwar.command.SWCommand;
-import de.steamwar.command.TypeMapper;
-import de.steamwar.command.TypeValidator;
-import de.steamwar.messages.ChatSender;
-import de.steamwar.sql.*;
-import net.md_5.bungee.BungeeCord;
-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.ServerConnectRequest;
-import net.md_5.bungee.api.chat.ClickEvent;
-import net.md_5.bungee.api.chat.ComponentBuilder;
-import net.md_5.bungee.api.chat.HoverEvent;
-import net.md_5.bungee.api.chat.TextComponent;
-import net.md_5.bungee.api.config.ServerInfo;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-import net.md_5.bungee.api.event.ServerConnectEvent;
-
-import java.net.*;
-import java.time.Instant;
-import java.time.format.DateTimeFormatter;
-import java.util.*;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import static de.steamwar.bungeecore.Storage.teamInvitations;
-
-public class TeamCommand extends SWCommand {
-
- private static final List> COLOR_CODES = new ArrayList<>();
-
- static {
- addColor("4", 1);
- addColor("c", 15);
- addColor("6", 14);
- addColor("e", 11);
- addColor("2", 2);
- addColor("a", 10);
- addColor("b", 12);
- addColor("3", 6);
- addColor("1", 4);
- addColor("9", 6);
- addColor("d", 9);
- addColor("5", 5);
- addColor("f", 15);
- addColor("7", 7);
- addColor("8", 8);
- addColor("0", 16);
- }
-
- private static void addColor(String color, int colorCode) {
- COLOR_CODES.add(new SWListInv.SWListEntry(new SWItem("§" + color, colorCode), color));
- }
-
- public TeamCommand() {
- super("team");
- }
-
- @Register(noTabComplete = true)
- public void help(CommandSender sender, String... args){
- Message.send("TEAM_HELP_HEADER", sender);
- Message.send("TEAM_HELP_LIST", sender);
- Message.send("TEAM_HELP_INFO", sender);
- if(!(sender instanceof ProxiedPlayer))
- return;
- Message.send("TEAM_HELP_TP", sender);
-
- ProxiedPlayer player = (ProxiedPlayer) sender;
- SteamwarUser user = SteamwarUser.get(player.getUniqueId());
- if(user.getTeam() == 0) {
- Message.send("TEAM_HELP_CREATE", sender);
- Message.send("TEAM_HELP_JOIN", sender);
- }else{
- Message.send("TEAM_HELP_CHAT", sender);
- Message.send("TEAM_HELP_EVENT", sender);
- Message.send("TEAM_HELP_LEAVE", sender);
-
- if(user.isLeader()){
- Message.send("TEAM_HELP_INVITE", sender);
- Message.send("TEAM_HELP_REMOVE", sender);
- Message.send("TEAM_HELP_KUERZEL", sender);
- Message.send("TEAM_HELP_NAME", sender);
- Message.send("TEAM_HELP_COLOR", sender);
- Message.send("TEAM_HELP_LEADER", sender);
- Message.send("TEAM_HELP_STEP_BACK", sender);
- Message.send("TEAM_HELP_SERVER", sender);
- }
- }
- }
-
- @Register(value = "create", description = "TEAM_CREATE_USAGE")
- public void create(@Validator("isNotInTeam") ProxiedPlayer player, @Length(min = 2, max = 4) @ErrorMessage("TEAM_KUERZEL_LENGTH") String kuerzel, @Length(min = 4, max = 15) @ErrorMessage("TEAM_NAME_LENGTH") String name){
- SteamwarUser user = SteamwarUser.get(player.getUniqueId());
- Team team = Team.get(user.getTeam());
-
- if(checkTeamKuerzel(player, team, kuerzel))
- return;
-
- if(checkTeamName(player, team, name))
- return;
-
- Team.create(kuerzel, name);
- user.setTeam(Team.get(kuerzel).getTeamId());
- user.setLeader(true);
- Message.send("TEAM_CREATE_CREATED", player, name);
- }
-
- @Register("join")
- public void join(@Validator("isNotInTeam") ProxiedPlayer player, String... args){
- SteamwarUser user = SteamwarUser.get(player.getUniqueId());
-
- if(notDuringEvent(player))
- return;
-
- if(!teamInvitations.containsKey(user.getId())){
- Message.send("TEAM_JOIN_NO_INVITE", player);
- return;
- }
-
- List invs = teamInvitations.get(user.getId());
- Integer t = null;
-
- if(invs.size() == 1){
- t = invs.get(0);
- }else{
- if(args.length != 1){
- Message.send("TEAM_JOIN_USAGE", player);
- StringBuilder sb = new StringBuilder();
- for(int inv : invs){
- Team team = Team.get(inv);
- sb.append(team.getTeamName()).append(" ");
- }
- Message.send("TEAM_JOIN_INVITED", player, sb.toString());
- return;
- }
-
- for(int inv : invs){
- Team team = Team.get(inv);
- if(team.getTeamKuerzel().equalsIgnoreCase(args[0]) || team.getTeamName().equalsIgnoreCase(args[0])){
- t = inv;
- break;
- }
- }
-
- if(t == null){
- Message.send("TEAM_JOIN_NOT_BY_TEAM", player);
- return;
- }
- }
-
- user.setTeam(t);
- teamInvitations.remove(user.getId());
- Message.send("TEAM_JOIN_JOINED", player, Team.get(t).getTeamName());
- }
-
- @Register("stepback")
- public void stepBack(@Validator("isLeader") ProxiedPlayer player) {
- SteamwarUser user = SteamwarUser.get(player.getUniqueId());
- Team team = Team.get(user.getTeam());
-
- if(noRemainingLeaders(team, user)){
- Message.send("TEAM_OTHER_LEADER_REQUIRED", player);
- return;
- }
-
- user.setLeader(false);
- Message.send("TEAM_STEP_BACK", player);
- }
-
- @Register("leave")
- public void leave(@Validator("isInTeam") ProxiedPlayer player){
- SteamwarUser user = SteamwarUser.get(player.getUniqueId());
- Team team = Team.get(user.getTeam());
-
- int teamSize = team.size();
- if(teamSize > 1 && user.isLeader() && noRemainingLeaders(team, user)) {
- Message.send("TEAM_OTHER_LEADER_REQUIRED", player);
- return;
- }
-
- user.setTeam(0);
-
- if(teamSize == 1){
- team.disband(user);
- }
-
- Message.send("TEAM_LEAVE_LEFT", player);
- }
-
- private boolean noRemainingLeaders(Team team, SteamwarUser except) {
- return SteamwarUser.getTeam(team.getTeamId()).stream().filter(member -> except.getId() != member.getId()).noneMatch(SteamwarUser::isLeader);
- }
-
-
- @Register(value = "invite", description = "TEAM_INVITE_USAGE")
- public void invite(@Validator("isLeader") ProxiedPlayer player, @AllowNull SteamwarUser target){
- SteamwarUser user = SteamwarUser.get(player.getUniqueId());
- Team team = Team.get(user.getTeam());
-
- if(notDuringEvent(player))
- return;
-
- if(target == null){
- Message.send("TEAM_INVITE_NO_PLAYER", player);
- return;
- }else if(target.getTeam() != 0){
- Message.send("TEAM_INVITE_IN_TEAM", player);
- return;
- }
-
- if(!teamInvitations.containsKey(target.getId()))
- teamInvitations.put(target.getId(), new LinkedList<>());
-
- if(teamInvitations.get(target.getId()).contains(team.getTeamId())){
- Message.send("TEAM_INVITE_ALREADY_INVITED", player);
- return;
- }
-
- teamInvitations.get(target.getId()).add(team.getTeamId());
-
- Message.send("TEAM_INVITE_INVITED", player, target.getUserName());
- ProxiedPlayer p = ProxyServer.getInstance().getPlayer(target.getUUID());
- if(p != null)
- Message.send("TEAM_INVITE_INVITED_TARGET", p, team.getTeamColor(), team.getTeamName());
- }
-
- @Register(value = "remove", description = "TEAM_REMOVE_USAGE")
- public void remove(@Validator("isLeader") ProxiedPlayer player, @AllowNull @Mapper("memberList") SteamwarUser target){
- SteamwarUser user = SteamwarUser.get(player.getUniqueId());
- Team team = Team.get(user.getTeam());
-
- if(target == null){
- Message.send("TEAM_REMOVE_NOT_PLAYER", player);
- return;
- }
-
- if (target.isLeader()) {
- Message.send("TEAM_REMOVE_NOT_LEADER", player);
- return;
- }
-
- if(teamInvitations.containsKey(target.getId())){
- if(teamInvitations.get(target.getId()).remove((Integer) team.getTeamId())){
- Message.send("TEAM_REMOVE_INVITE", player);
- if(teamInvitations.get(target.getId()).isEmpty())
- teamInvitations.remove(target.getId());
- }else{
- Message.send("TEAM_REMOVE_NO_INVITE", player);
- }
- return;
- }
-
- if(target.getTeam() != user.getTeam()){
- Message.send("TEAM_REMOVE_NOT_IN_TEAM", player);
- return;
- }
-
- target.setTeam(0);
-
- Message.send("TEAM_REMOVE_REMOVED", player);
- ProxiedPlayer p = ProxyServer.getInstance().getPlayer(target.getUUID());
- if(p != null)
- Message.send("TEAM_REMOVE_REMOVED_TARGET", player);
- }
-
- @Mapper(value = "memberList", local = true)
- public TypeMapper memberList() {
- return new TypeMapper() {
- @Override
- public SteamwarUser map(CommandSender commandSender, String[] previousArguments, String s) {
- return SteamwarUser.get(s);
- }
-
- @Override
- public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
- if (!(sender instanceof ProxiedPlayer)) return Collections.emptyList();
- ProxiedPlayer player = (ProxiedPlayer) sender;
- Team team = Team.get(SteamwarUser.get(player.getUniqueId()).getTeam());
- return team.getMembers().stream()
- .map(SteamwarUser::get)
- .map(SteamwarUser::getUserName)
- .collect(Collectors.toList());
- }
- };
- }
-
- @Register(value = "changekurzel", description = "TEAM_KUERZEL_USAGE")
- public void changekuerzel(@Validator("isLeader") ProxiedPlayer player, @Length(min = 2, max = 4) @ErrorMessage("TEAM_KUERZEL_LENGTH") String kuerzel){
- SteamwarUser user = SteamwarUser.get(player.getUniqueId());
- Team team = Team.get(user.getTeam());
-
- if(notDuringEvent(player))
- return;
-
- if(checkTeamKuerzel(player, team, kuerzel))
- return;
-
- team.setTeamKuerzel(kuerzel);
- Message.send("TEAM_KUERZEL_CHANGED", player);
- }
-
- @Register(value = "changename", description = "TEAM_NAME_USAGE")
- public void changename(@Validator("isLeader") ProxiedPlayer player, @Length(min = 4, max = 15) @ErrorMessage("TEAM_NAME_LENGTH") String name){
- SteamwarUser user = SteamwarUser.get(player.getUniqueId());
- Team team = Team.get(user.getTeam());
-
- if(notDuringEvent(player))
- return;
-
- if(checkTeamName(player, team, name))
- return;
-
- team.setTeamName(name);
- Message.send("TEAM_NAME_CHANGED", player);
- }
-
- @Register(value = "promote", description = "TEAM_LEADER_USAGE")
- public void promote(@Validator("isLeader") ProxiedPlayer player, @AllowNull @Mapper("memberList") SteamwarUser target){
- SteamwarUser user = SteamwarUser.get(player.getUniqueId());
-
- if(notDuringEvent(player))
- return;
-
- if(target == null){
- Message.send("TEAM_LEADER_NOT_USER", player);
- return;
- }
-
- if(target.getTeam() != user.getTeam()){
- Message.send("TEAM_LEADER_NOT_MEMBER", player);
- return;
- }
-
- target.setLeader(true);
- Message.send("TEAM_LEADER_PROMOTED", player, target.getUserName());
- }
-
- private String playerName(SteamwarUser user){
- return ProxyServer.getInstance().getPlayer(user.getUUID()) != null ? "§a" + user.getUserName() : "§e" + user.getUserName();
- }
-
- @Register("info")
- public void info(@Validator("isInTeam") ProxiedPlayer player){
- SteamwarUser user = SteamwarUser.get(player.getUniqueId());
- Team team = Team.get(user.getTeam());
- info(player, team);
- }
-
- @Register(value = "info", description = "TEAM_INFO_USAGE")
- public void info(ProxiedPlayer player, @ErrorMessage("UNKNOWN_TEAM") Team team){
- SteamwarUser user = SteamwarUser.get(player.getUniqueId());
- Message.sendPrefixless("TEAM_INFO_TEAM", player, team.getTeamName(), team.getTeamColor(), team.getTeamKuerzel());
-
- List users = team.getMembers().stream().map(SteamwarUser::get).collect(Collectors.toList());
-
- Message.sendPrefixless("TEAM_INFO_LEADER", player, users.stream().filter(SteamwarUser::isLeader).count(), getMemberList(users, true));
-
- String members = getMemberList(users, false);
-
- if(members.length() > 0) {
- Message.sendPrefixless("TEAM_INFO_MEMBER", player, users.stream().filter(u -> !u.isLeader()).count(), members);
- }
-
- Set events = TeamTeilnahme.getEvents(team.getTeamId());
- if(!events.isEmpty()){
- Message.sendPrefixless("TEAM_INFO_EVENTS", player, events.stream().map(Event::getEventName).collect(Collectors.joining(", ")));
- }
- }
-
- private String getMemberList(List users, boolean leaders) {
- StringBuilder sb = new StringBuilder();
- for(SteamwarUser user : users) {
- if(user.isLeader() == leaders) {
- sb.append(playerName(user)).append(" ");
- }
- }
- return sb.toString();
- }
-
- @Register("list")
- public void list(ProxiedPlayer player, @Min(intValue = 1) @OptionalValue("1") @ErrorMessage("TEAM_LIST_NOT_PAGE") int page){
- final int TEAMS_PER_PAGE = 10;
-
- List all = Team.getAll();
- final int lastPage = ((all.size() - 1) / 10) + 1;
- if(page < 1 || page > lastPage){
- Message.send("TEAM_LIST_UNKNOWN_PAGE", player);
- return;
- }
-
- Message.sendPrefixless("TEAM_LIST_HEADER", player, page, lastPage);
-
- for(int i = (page-1) * TEAMS_PER_PAGE; i < (page-1) * TEAMS_PER_PAGE + TEAMS_PER_PAGE && i < all.size(); i++){
- Team tm = all.get(i);
-
- Message.sendPrefixless("TEAM_LIST_TEAM", player, Message.parse("TEAM_LIST_TEAM_HOVER", player),
- new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team info " + tm.getTeamKuerzel()), tm.getTeamColor(), tm.getTeamKuerzel(), tm.getTeamName());
- }
-
- TextComponent beforePage = new TextComponent("««");
- if(page > 1){
- beforePage.setColor(ChatColor.YELLOW);
- beforePage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(Message.parse("TEAM_LIST_PREV", player)).create()));
- beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team list " + (page - 1)));
- }else
- beforePage.setColor(ChatColor.DARK_GRAY);
-
- TextComponent nextPage = new TextComponent(" " + Message.parse("TEAM_LIST_PAGE", player) +" »»");
- if(page < lastPage){
- nextPage.setColor(ChatColor.YELLOW);
- nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(Message.parse("TEAM_LIST_NEXT", player)).create()));
- nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team list " + (page + 1)));
- }else
- nextPage.setColor(ChatColor.DARK_GRAY);
-
- beforePage.addExtra(nextPage);
- player.sendMessage(beforePage);
- }
-
- @Register("event")
- public void event(@Validator("isInTeam") ProxiedPlayer player) {
- SteamwarUser user = SteamwarUser.get(player.getUniqueId());
- Team team = Team.get(user.getTeam());
-
- Message.send("TEAM_EVENT_USAGE", player);
- Set events = TeamTeilnahme.getEvents(team.getTeamId());
- if(!events.isEmpty()){
- Message.send("TEAM_EVENT_HEADER", player);
- DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern(Message.parse("EVENT_DATE_FORMAT", player));
- for(Event e : events)
- Message.sendPrefixless("TEAM_EVENT_EVENT", player, e.getStart().toLocalDateTime().format(dateFormat), e.getEventName());
- }
- }
-
- @Register("event")
- public void event(@Validator("isLeader") ProxiedPlayer player, Event event){
- SteamwarUser user = SteamwarUser.get(player.getUniqueId());
- Team team = Team.get(user.getTeam());
-
- if(notDuringEvent(player))
- return;
-
- if(Instant.now().isAfter(event.getDeadline().toInstant())){
- Message.send("TEAM_EVENT_OVER", player);
- return;
- }
-
- if(TeamTeilnahme.nimmtTeil(team.getTeamId(), event.getEventID())){
- TeamTeilnahme.notTeilnehmen(team.getTeamId(), event.getEventID());
- Message.send("TEAM_EVENT_LEFT", player);
- }else{
- TeamTeilnahme.teilnehmen(team.getTeamId(), event.getEventID());
- Message.send("TEAM_EVENT_JOINED", player, event.getEventName());
- Message.sendPrefixless("TEAM_EVENT_HOW_TO_LEAVE", player);
- }
- }
-
- @Register("tp")
- public void tp(@Validator("isInTeam") ProxiedPlayer player) {
- SteamwarUser user = SteamwarUser.get(player.getUniqueId());
- Team team = Team.get(user.getTeam());
- tp(player, team);
- }
-
- @Register("tp")
- public void tp(ProxiedPlayer player, @ErrorMessage("TEAM_TP_NO_TEAM") @Mapper("teamWithTeamServer") Team targetTeam) {
- if (targetTeam.getAddress() == null || targetTeam.getAddress().isEmpty()) {
- Message.send("TEAM_NO_ADDRESS", player);
- return;
- }
-
- InetSocketAddress address = new InetSocketAddress(targetTeam.getAddress(), targetTeam.getPort());
- ServerInfo serverInfo = Storage.teamServers.computeIfAbsent(targetTeam.getTeamId(), integer -> {
- ServerInfo info = ProxyServer.getInstance().constructServerInfo("Team " + targetTeam.getTeamKuerzel(), address, "SteamWar.de - Teamserver", false);
- ProxyServer.getInstance().getServers().put(info.getName(), info);
- return info;
- });
-
- if (!address.equals(serverInfo.getSocketAddress())) {
- serverInfo = Storage.teamServers.remove(targetTeam.getTeamId());
- ProxyServer.getInstance().getServers().remove(serverInfo.getName());
- tp(player, targetTeam);
- return;
- }
-
- player.connect(ServerConnectRequest.builder()
- .target(serverInfo)
- .connectTimeout(BungeeCord.getInstance().getConfig().getServerConnectTimeout())
- .retry(false)
- .reason(ServerConnectEvent.Reason.PLUGIN)
- .callback((success, error) -> {
- if (error != null) {
- Message.send("TEAM_OFFLINE", player);
- }
- })
- .build());
- /*
- ((UserConnection) player).connect(serverInfo, (success, error) -> {
- if (error != null) {
- Message.send("TEAM_OFFLINE", player);
- }
- }, false, ServerConnectEvent.Reason.PLUGIN, BungeeCord.getInstance().getConfig().getServerConnectTimeout(), false);
- */
- }
-
- @Register(value = "server", description = "TEAM_SERVER_USAGE")
- public void server(@Validator("isLeader") ProxiedPlayer player, String server, @Min(intValue = 1) @Max(intValue = 65535) @ErrorMessage("TEAM_SERVER_PORT_INVALID") int port){
- SteamwarUser user = SteamwarUser.get(player.getUniqueId());
- Team team = Team.get(user.getTeam());
- if (PunishmentCommand.isPunishedWithMessage(ChatSender.of(player), Punishment.PunishmentType.NoTeamServer)) {
- return;
- }
-
- try {
- if (isLocalhost(InetAddress.getByName(server))) {
- Message.send("TEAM_SERVER_ADDRESS_INVALID", player);
- return;
- }
- } catch (UnknownHostException e) {
- Message.send("TEAM_SERVER_ADDRESS_INVALID", player);
- return;
- }
-
- team.setAddress(server);
- team.setPort(port);
- Storage.teamServers.remove(team.getTeamId());
- Message.send("TEAM_SERVER_SET", player);
- }
-
- public static boolean isLocalhost(InetAddress addr) {
- // Check if the address is a valid special local or loop back
- if (addr.isAnyLocalAddress() || addr.isLoopbackAddress())
- return true;
-
- // Check if the address is defined on any interface
- try {
- return NetworkInterface.getByInetAddress(addr) != null;
- } catch (SocketException e) {
- return false;
- }
- }
-
- @Register("color")
- public void changeColor(@Validator("isLeader") ProxiedPlayer player) {
- SteamwarUser user = SteamwarUser.get(player.getUniqueId());
- Team team = Team.get(user.getTeam());
-
- if(notDuringEvent(player))
- return;
-
- List> colors = new ArrayList<>();
- COLOR_CODES.forEach(stringSWListEntry -> {
- SWItem item = stringSWListEntry.getItem().clone();
- item.setName(stringSWListEntry.getItem().getTitle() + Team.get(user.getTeam()).getTeamKuerzel());
- colors.add(new SWListInv.SWListEntry<>(item, stringSWListEntry.getObject()));
- });
-
- SWListInv inv = new SWListInv<>(player, Message.parse("TEAM_COLOR_TITLE", player), colors, (click, element) -> {});
- inv.setCallback((click, element) -> {
- inv.close();
- team.setTeamColor(element);
- });
- inv.open();
- }
-
- @ClassMapper(Event.class)
- public TypeMapper eventTypeMapper() {
- return new TypeMapper() {
- @Override
- public Event map(CommandSender commandSender, String[] previousArguments, String s) {
- return Event.get(s);
- }
-
- @Override
- public boolean validate(CommandSender sender, Event value, MessageSender messageSender) {
- if (value == null) {
- messageSender.send("TEAM_EVENT_NO_EVENT", sender);
- return false;
- } else {
- return true;
- }
- }
-
- @Override
- public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
- return Event.getComing().stream().map(Event::getEventName).collect(Collectors.toList());
- }
- };
- }
-
- @Validator(value = "isNotInTeam", local = true)
- public TypeValidator isNotInTeamValidator() {
- return (sender, value, messageSender) -> {
- if (!(sender instanceof ProxiedPlayer)) return false;
- ProxiedPlayer player = (ProxiedPlayer) sender;
- SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId());
- if (steamwarUser.getTeam() != 0) {
- messageSender.send("TEAM_IN_TEAM");
- return false;
- }
- return true;
- };
- }
-
- @Validator(value = "isInTeam", local = true)
- public TypeValidator isInTeamValidator() {
- return (sender, value, messageSender) -> {
- if (!(sender instanceof ProxiedPlayer)) return false;
- ProxiedPlayer player = (ProxiedPlayer) sender;
- SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId());
- if (steamwarUser.getTeam() == 0) {
- messageSender.send("TEAM_NOT_IN_TEAM");
- return false;
- }
- return true;
- };
- }
-
- @Validator(value = "isLeader", local = true)
- public TypeValidator isLeaderValidator() {
- return (sender, value, messageSender) -> {
- if (!(sender instanceof ProxiedPlayer)) return false;
- ProxiedPlayer player = (ProxiedPlayer) sender;
- SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId());
- if (steamwarUser.getTeam() == 0) {
- messageSender.send("TEAM_NOT_IN_TEAM");
- return false;
- }
- if (!steamwarUser.isLeader()) {
- messageSender.send("TEAM_NOT_LEADER");
- return false;
- }
- return true;
- };
- }
-
- @ClassMapper(Team.class)
- @Cached(global = true, cacheDuration = 60)
- public TypeMapper team() {
- return new TypeMapper() {
- @Override
- public Team map(CommandSender commandSender, String[] previousArguments, String s) {
- return Team.get(s);
- }
-
- @Override
- public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
- return Team.getAll().stream()
- .flatMap(team -> Stream.of(team.getTeamName(), team.getTeamKuerzel()))
- .collect(Collectors.toList());
- }
- };
- }
-
- @Mapper(value = "teamWithTeamServer", local = true)
- @Cached(global = true, cacheDuration = 60)
- public TypeMapper teamWithTeamServer() {
- return new TypeMapper() {
- @Override
- public Team map(CommandSender commandSender, String[] previousArguments, String s) {
- return Team.get(s);
- }
-
- @Override
- public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
- return Team.getAll().stream()
- .filter(team -> team.getAddress() != null && !team.getAddress().isEmpty())
- .flatMap(team -> Stream.of(team.getTeamName(), team.getTeamKuerzel()))
- .collect(Collectors.toList());
- }
- };
- }
-
- private boolean checkTeamName(ProxiedPlayer player, Team team, String arg){
- Team t = Team.get(arg);
- if(t != null && t.getTeamId() != team.getTeamId()){
- Message.send("TEAM_NAME_TAKEN", player);
- return true;
- }
- return false;
- }
-
- private boolean checkTeamKuerzel(ProxiedPlayer player, Team team, String arg){
- Team t = Team.get(arg);
- if(t != null && (team == null || t.getTeamId() != team.getTeamId())){
- Message.send("TEAM_KUERZEL_TAKEN", player);
- return true;
- }
- return false;
- }
-
- private boolean notDuringEvent(ProxiedPlayer player){
- if(Event.get() != null){
- Message.send("TEAM_NOT_IN_EVENT", player);
- return true;
- }
- return false;
- }
-}
diff --git a/src/de/steamwar/bungeecore/commands/TutorialCommand.java b/src/de/steamwar/bungeecore/commands/TutorialCommand.java
deleted file mode 100644
index d7bce43..0000000
--- a/src/de/steamwar/bungeecore/commands/TutorialCommand.java
+++ /dev/null
@@ -1,168 +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 .
- */
-
-package de.steamwar.bungeecore.commands;
-
-import de.steamwar.bungeecore.*;
-import de.steamwar.bungeecore.inventory.SWInventory;
-import de.steamwar.bungeecore.inventory.SWItem;
-import de.steamwar.bungeecore.inventory.SWListInv;
-import de.steamwar.bungeecore.inventory.SWStreamInv;
-import de.steamwar.bungeecore.util.Chat19;
-import de.steamwar.command.SWCommand;
-import de.steamwar.command.TypeValidator;
-import de.steamwar.sql.SteamwarUser;
-import de.steamwar.sql.Tutorial;
-import de.steamwar.sql.UserPerm;
-import net.md_5.bungee.api.ProxyServer;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
-
-public class TutorialCommand extends SWCommand {
-
- public TutorialCommand() {
- super("tutorial", null);
- }
-
- @Register
- public void genericCommand(ProxiedPlayer player) {
- openInventory(player, true, false);
- }
-
- @Register("rate")
- public void rate(ProxiedPlayer player) {
- Chat19.chat(player, "/tutorial rate");
- }
-
- @Register("rate")
- public void rate(ProxiedPlayer player, int id) {
- Tutorial tutorial = Tutorial.get(id);
- if(tutorial == null) {
- Chat19.chat(player, "/tutorial rate"); // Catch players manually entering numbers
- return;
- }
-
- rate(player, tutorial);
- }
-
- @Register(value = "create", description = "TUTORIAL_CREATE_HELP")
- public void create(ProxiedPlayer player, String material, String... name) {
- create(player, String.join(" ", name), material.toUpperCase());
- }
-
- @Register("own")
- public void own(ProxiedPlayer player) {
- openInventory(player, false, true);
- }
-
- @Register("unreleased")
- public void unreleased(@Validator("unreleased") ProxiedPlayer player) {
- openInventory(player, false, false);
- }
-
- @Validator("unreleased")
- public TypeValidator unreleasedChecker() {
- return (sender, value, messageSender) -> (SteamwarUser.get((value).getUniqueId()).hasPerm(UserPerm.TEAM));
- }
-
- private void openInventory(ProxiedPlayer player, boolean released, boolean own) {
- SteamwarUser user = SteamwarUser.get(player.getUniqueId());
-
- new SWStreamInv<>(
- player,
- Message.parse("TUTORIAL_TITLE", player),
- (click, tutorial) -> {
- if(!released && click.isShiftClick() && user.hasPerm(UserPerm.TEAM) && user.getId() != tutorial.getCreator()) {
- tutorial.release();
- openInventory(player, released, own);
- return;
- } else if(own && click.isShiftClick() && click.isRightClick()) {
- tutorial.delete();
- SubserverSystem.deleteFolder(BungeeCore.local, world(tutorial).getPath());
- openInventory(player, released, own);
- return;
- }
-
- new ServerStarter().tutorial(player, tutorial).start();
- },
- page -> (own ? Tutorial.getOwn(user.getId(), page, 45) : Tutorial.getPage(page, 45, released)).stream().map(tutorial -> new SWListInv.SWListEntry<>(getTutorialItem(player, tutorial, own), tutorial)).collect(Collectors.toList())
- ).open();
- }
-
- private SWItem getTutorialItem(ProxiedPlayer player, Tutorial tutorial, boolean personalHighlights) {
- SWItem item = new SWItem(tutorial.getItem(), Message.parse("TUTORIAL_NAME", player, tutorial.getName()));
- item.setHideAttributes(true);
-
- List lore = new ArrayList<>();
- lore.add(Message.parse("TUTORIAL_BY", player, SteamwarUser.get(tutorial.getCreator()).getUserName()));
- lore.add(Message.parse("TUTORIAL_STARS", player, String.format("%.1f", tutorial.getStars())));
-
- if (personalHighlights)
- lore.add(Message.parse("TUTORIAL_DELETE", player));
-
- item.setLore(lore);
-
- if (personalHighlights && tutorial.isReleased())
- item.setEnchanted(true);
-
- return item;
- }
-
- private void rate(ProxiedPlayer player, Tutorial tutorial) {
- SteamwarUser user = SteamwarUser.get(player.getUniqueId());
- int[] rates = new int[]{1, 2, 3, 4, 5};
-
- new SWListInv<>(player, Message.parse("TUTORIAL_RATE_TITLE", player), Arrays.stream(rates).mapToObj(rate -> new SWListInv.SWListEntry<>(new SWItem("NETHER_STAR", Message.parse("TUTORIAL_RATE", player, rate)), rate)).collect(Collectors.toList()), (click, rate) -> {
- tutorial.rate(user.getId(), rate);
- SWInventory.close(player);
- }).open();
- }
-
- private void create(ProxiedPlayer player, String name, String item) {
- Subserver subserver = Subserver.getSubserver(player);
- SteamwarUser user = SteamwarUser.get(player.getUniqueId());
- File tempWorld = new File(ServerStarter.TEMP_WORLD_PATH, ServerStarter.serverToWorldName(ServerStarter.bauServerName(user)));
-
- if(subserver == null || !subserver.hasStarted() || subserver.getType() != Servertype.BAUSERVER || !tempWorld.exists()) {
- Message.send("TUTORIAL_CREATE_MISSING", player);
- return;
- }
-
- subserver.execute("save-all");
- ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
- Tutorial tutorial = Tutorial.create(user.getId(), name, item);
- File tutorialWorld = world(tutorial);
-
- if (tutorialWorld.exists())
- SubserverSystem.deleteFolder(BungeeCore.local, tutorialWorld.getPath());
- ServerStarter.copyWorld(BungeeCore.local, tempWorld.getPath(), tutorialWorld.getPath());
- Message.send("TUTORIAL_CREATED", player);
- }, 1, TimeUnit.SECONDS);
- }
-
- private File world(Tutorial tutorial) {
- return new File(ServerStarter.TUTORIAL_PATH, String.valueOf(tutorial.getTutorialId()));
- }
-}
diff --git a/src/de/steamwar/bungeecore/inventory/SWInventory.java b/src/de/steamwar/bungeecore/inventory/SWInventory.java
deleted file mode 100644
index 637668c..0000000
--- a/src/de/steamwar/bungeecore/inventory/SWInventory.java
+++ /dev/null
@@ -1,158 +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 .
-*/
-
-package de.steamwar.bungeecore.inventory;
-
-import de.steamwar.bungeecore.network.NetworkSender;
-import de.steamwar.bungeecore.network.handlers.InventoryCallbackHandler;
-import de.steamwar.sql.SteamwarUser;
-import de.steamwar.network.packets.server.CloseInventoryPacket;
-import de.steamwar.network.packets.server.InventoryPacket;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.function.BiFunction;
-
-public class SWInventory {
-
- private final Map itemMap;
- private InvCallback close;
- private ProxiedPlayer player;
- private int size;
- private String title;
- private boolean next;
-
- private final AtomicBoolean processingClick = new AtomicBoolean();
-
- public SWInventory(ProxiedPlayer proxiedPlayer, int size, String title) {
- itemMap = new HashMap<>();
- InventoryCallbackHandler.inventoryHashMap.put(SteamwarUser.get(proxiedPlayer.getUniqueId()).getId(), this);
- this.player = proxiedPlayer;
- this.size = size;
- this.title = title;
- next = false;
- }
-
- public void addItem(int pos, SWItem item, InvCallback callback) {
- addItem(pos, item, new ArrayList<>(), callback);
- }
-
- public void addItem(int pos, SWItem item, List lore, InvCallback callback) {
- item.setCallback(callback);
- item.setLore(lore);
- itemMap.put(pos, item);
- }
-
- public void addItem(int pos, SWItem item) {
- itemMap.put(pos, item);
- }
-
- public void addItem(int pos, SWItem item, String name, InvCallback callback) {
- item.setName(name);
- item.setCallback(callback);
- itemMap.put(pos, item);
- }
-
- public void removeItem(int position) {
- itemMap.remove(position);
- }
-
- public int getSize() {
- return size;
- }
-
- public void setSize(int size) {
- this.size = size;
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- public void setCallback(int pos, InvCallback callback) {
- itemMap.get(pos).setCallback(callback);
- }
-
- public void setNext(boolean next) {
- this.next = next;
- }
-
- public boolean isNext() {
- return next;
- }
-
- public Map getItems() {
- return itemMap;
- }
-
- public void handleCallback(InvCallback.ClickType type, int pos) {
- if(processingClick.compareAndSet(false, true)) {
- itemMap.get(pos).getCallback().clicked(type);
- processingClick.set(false);
- }
- }
-
- public void handleClose() {
- if(processingClick.compareAndSet(false, true)) {
- InventoryCallbackHandler.inventoryHashMap.remove(SteamwarUser.get(player.getUniqueId()).getId(), this);
- if(close != null)
- close.clicked(null);
- processingClick.set(false);
- }
- }
-
- public void open() {
- InventoryPacket inv = new InventoryPacket(title, SteamwarUser.get(player.getUniqueId()).getId(), size, map(itemMap, (integer, swItem) -> swItem.writeToString(integer).toString()));
- NetworkSender.send(player, inv);
- }
-
- private static Map map(Map map, BiFunction function) {
- Map result = new HashMap<>();
- map.forEach((key, value) -> result.put(key, function.apply(key, value)));
- return result;
- }
-
- public void close() {
- close(player);
- }
-
- public static void close(ProxiedPlayer player) {
- NetworkSender.send(player, new CloseInventoryPacket(SteamwarUser.get(player.getUniqueId()).getId()));
- }
-
- public void setClose(InvCallback close) {
- this.close = close;
- }
-
- public ProxiedPlayer getPlayer() {
- return player;
- }
-
- public void setPlayer(ProxiedPlayer player) {
- this.player = player;
- }
-
- public String getTitle() {
- return title;
- }
-}
diff --git a/src/de/steamwar/bungeecore/inventory/SWItem.java b/src/de/steamwar/bungeecore/inventory/SWItem.java
deleted file mode 100644
index f5a4476..0000000
--- a/src/de/steamwar/bungeecore/inventory/SWItem.java
+++ /dev/null
@@ -1,173 +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 .
-*/
-
-package de.steamwar.bungeecore.inventory;
-
-import com.google.gson.JsonArray;
-import com.google.gson.JsonObject;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class SWItem {
-
- private String material, title, skullOwner;
- private boolean enchanted, hideAttributes;
- private List lore;
- private InvCallback callback;
- private int color;
-
- public SWItem(String material, String title) {
- this.material = material.toUpperCase();
- lore = new ArrayList<>();
- this.title = title;
- color = 0;
- }
-
- public SWItem(String title, int color) {
- this.material = "DYE";
- lore = new ArrayList<>();
- this.title = title;
- this.color = color;
- }
-
- public static SWItem getSkull(String skullOwner) {
- SWItem item = new SWItem("SKULL", skullOwner);
- item.setSkullOwner(skullOwner);
- return item;
- }
-
- public void setCallback(InvCallback callback) {
- this.callback = callback;
- }
-
- public void setColor(int color) {
- this.color = color;
- }
-
- public InvCallback getCallback() {
- return callback;
- }
-
- public String getMaterial() {
- return material;
- }
-
- public void setMaterial(String material) {
- this.material = material.toUpperCase();
- }
-
- public String getSkullOwner() {
- return skullOwner;
- }
-
- public void setSkullOwner(String skullOwner) {
- this.skullOwner = skullOwner;
- }
-
- public boolean isEnchanted() {
- return enchanted;
- }
-
- public void setEnchanted(boolean enchanted) {
- this.enchanted = enchanted;
- }
-
- public boolean isHideAttributes() {
- return hideAttributes;
- }
-
- public void setHideAttributes(boolean hideAttributes) {
- this.hideAttributes = hideAttributes;
- }
-
- public SWItem setName(String name) {
- title = name;
- return this;
- }
-
- public String getTitle() {
- return title;
- }
-
- public void addLore(String lore) {
- this.lore.add(lore);
- }
-
- public JsonObject writeToString(int position) {
- JsonObject object = new JsonObject();
- object.addProperty("material", material);
- object.addProperty("position", position);
- object.addProperty("title", title);
- if(skullOwner != null)
- object.addProperty("skullOwner", skullOwner);
- if(enchanted)
- object.addProperty("enchanted", true);
- if(hideAttributes)
- object.addProperty("hideAttributes", true);
- if(color != 0)
- object.addProperty("color", color);
- if(lore != null) {
- JsonArray array = new JsonArray();
- for (String lores:
- lore) {
- array.add(lores);
- }
- object.add("lore", array);
- }
-
- return object;
- }
-
- @Override
- public boolean equals(Object o) {
- if(!(o instanceof SWItem))
- return false;
- SWItem item = (SWItem) o;
- if(item.enchanted != enchanted)
- return false;
- if(item.hideAttributes != hideAttributes)
- return false;
- if(!item.material.equals(material))
- return false;
- if(!item.lore.equals(lore))
- return false;
- if(!item.skullOwner.equals(skullOwner))
- return false;
- return true;
- }
-
- public void setLore(List lore) {
- this.lore = lore;
- }
-
- public SWItem clone() {
- SWItem item;
- if(color != 0) {
- item = new SWItem(title, color);
- }else {
- item = new SWItem(material, title);
- }
- item.setLore(lore);
- item.setCallback(callback);
- item.setEnchanted(enchanted);
- item.setHideAttributes(hideAttributes);
- return item;
- }
-}
diff --git a/src/de/steamwar/bungeecore/inventory/SWListInv.java b/src/de/steamwar/bungeecore/inventory/SWListInv.java
deleted file mode 100644
index 8636054..0000000
--- a/src/de/steamwar/bungeecore/inventory/SWListInv.java
+++ /dev/null
@@ -1,121 +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 .
-*/
-
-package de.steamwar.bungeecore.inventory;
-
-import net.md_5.bungee.BungeeCord;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-
-import java.util.*;
-
-public class SWListInv extends SWInventory {
- private ListCallback callback;
- private List> elements;
- private int page;
-
- public SWListInv(ProxiedPlayer p, String t, List> l, ListCallback c){
- super(p, (l.size()>45) ? 54 : (l.size() + 9-l.size()%9), t);
- callback = c;
- elements = l;
- page = 0;
- }
-
- @Override
- public void open(){
- if(elements.size() > 54){
- if(page != 0)
- addItem(45, new SWItem("§eSeite zurück", 10), (InvCallback.ClickType click) -> {
- page--;
- open();
- });
- else
- addItem(45, new SWItem("§7Seite zurück", 8), (InvCallback.ClickType click) -> {});
- if(page < elements.size()/45)
- addItem(53, new SWItem("§eSeite vor", 10), "§eSeite vor", (InvCallback.ClickType click) -> {
- page++;
- open();
- });
- else
- addItem(53, new SWItem("§eSeite vor", 8), (InvCallback.ClickType click) -> {});
- }
-
- int ipageLimit = elements.size() - page*45;
- if(ipageLimit > 45 && elements.size() > 54){
- ipageLimit = 45;
- }
- int i = page*45;
- for(int ipage=0; ipage < ipageLimit; ipage++ ){
- SWItem e = elements.get(i).getItem();
-
- final int pos = i;
- addItem(ipage, e);
- setCallback(ipage, (InvCallback.ClickType click) -> callback.clicked(click, elements.get(pos).getObject()));
- i++;
- }
- super.open();
- }
-
- public void setCallback(ListCallback c){
- callback = c;
- }
-
- public interface ListCallback{
- void clicked(InvCallback.ClickType click, T element);
- }
-
- public static List> createPlayerList(UUID without){
- List> onlinePlayers = new ArrayList<>();
- for(ProxiedPlayer player : BungeeCord.getInstance().getPlayer(without).getServer().getInfo().getPlayers()){
- if(without != null && player.getUniqueId().equals(without))
- continue;
-
- onlinePlayers.add(new SWListEntry<>(SWItem.getSkull(player.getName()), player.getUniqueId()));
- }
- return onlinePlayers;
- }
-
- public static List> createGlobalPlayerList(UUID without){
- List> onlinePlayers = new ArrayList<>();
- for(ProxiedPlayer player : BungeeCord.getInstance().getPlayers()){
- if(without != null && player.getUniqueId().equals(without))
- continue;
-
- onlinePlayers.add(new SWListEntry<>(SWItem.getSkull(player.getName()), player.getUniqueId()));
- }
- return onlinePlayers;
- }
-
- public static class SWListEntry{
- final SWItem item;
- final T object;
-
- public SWListEntry(SWItem item, T object){
- this.item = item;
- this.object = object;
- }
-
- public SWItem getItem(){
- return item;
- }
-
- public T getObject(){
- return object;
- }
- }
-}
diff --git a/src/de/steamwar/bungeecore/inventory/SWStreamInv.java b/src/de/steamwar/bungeecore/inventory/SWStreamInv.java
deleted file mode 100644
index 1235de0..0000000
--- a/src/de/steamwar/bungeecore/inventory/SWStreamInv.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package de.steamwar.bungeecore.inventory;
-
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-
-import java.util.List;
-import java.util.function.Function;
-
-public class SWStreamInv extends SWInventory {
- private final SWListInv.ListCallback callback;
- private final Function>> constructor;
- private int page;
-
- public SWStreamInv(ProxiedPlayer proxiedPlayer, String title, SWListInv.ListCallback callback, Function>> constructor) {
- super(proxiedPlayer, 54, title);
- this.callback = callback;
- this.constructor = constructor;
- page = 0;
- }
-
- @Override
- public void open(){
- List> entries = constructor.apply(page);
-
- if(page != 0)
- addItem(45, new SWItem("§eSeite zurück", 10), (InvCallback.ClickType click) -> {
- page--;
- open();
- });
- else
- addItem(45, new SWItem("§7Seite zurück", 8), (InvCallback.ClickType click) -> {});
-
- if(entries.size() == 45)
- addItem(53, new SWItem("§eSeite vor", 10), (InvCallback.ClickType click) -> {
- page++;
- open();
- });
- else
- addItem(53, new SWItem("§7Seite vor", 8), (InvCallback.ClickType click) -> {});
-
- for(int i = 0; i < entries.size(); i++) {
- SWListInv.SWListEntry item = entries.get(i);
- addItem(i, item.getItem());
- setCallback(i, (InvCallback.ClickType click) -> {
- close();
- callback.clicked(click, item.getObject());
- });
- }
-
- super.open();
- }
-}
diff --git a/src/de/steamwar/bungeecore/listeners/BanListener.java b/src/de/steamwar/bungeecore/listeners/BanListener.java
deleted file mode 100644
index 3cb9f0f..0000000
--- a/src/de/steamwar/bungeecore/listeners/BanListener.java
+++ /dev/null
@@ -1,94 +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 .
-*/
-
-package de.steamwar.bungeecore.listeners;
-
-import de.steamwar.bungeecore.BungeeCore;
-import de.steamwar.bungeecore.Message;
-import de.steamwar.bungeecore.commands.PunishmentCommand;
-import de.steamwar.bungeecore.commands.WebpasswordCommand;
-import de.steamwar.messages.ChatSender;
-import de.steamwar.sql.BannedUserIPs;
-import de.steamwar.sql.Punishment;
-import de.steamwar.sql.SteamwarUser;
-import net.md_5.bungee.api.ProxyServer;
-import net.md_5.bungee.api.chat.ClickEvent;
-import net.md_5.bungee.api.connection.PendingConnection;
-import net.md_5.bungee.api.event.LoginEvent;
-import net.md_5.bungee.event.EventHandler;
-
-import java.sql.Timestamp;
-import java.time.format.DateTimeFormatter;
-import java.util.List;
-import java.util.stream.Collectors;
-
-public class BanListener extends BasicListener {
-
- @EventHandler
- public void onLogin(LoginEvent event) {
- event.registerIntent(BungeeCore.get());
- ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
- PendingConnection connection = event.getConnection();
- SteamwarUser user = SteamwarUser.getOrCreate(connection.getUniqueId(), connection.getName(), ConnectionListener::newPlayer, WebpasswordCommand::changeUsername);
- String ip = IPSanitizer.getTrueAddress(connection).getHostAddress();
- if (user.isPunished(Punishment.PunishmentType.Ban)) {
- event.setCancelled(true);
- BannedUserIPs.banIP(user.getId(), ip);
- ChatSender.of(event).system(PunishmentCommand.punishmentMessage(user, Punishment.PunishmentType.Ban));
- event.completeIntent(BungeeCore.get());
- return;
- }
-
- List ips = BannedUserIPs.get(ip);
- if(!ips.isEmpty()){
- Timestamp highestBan = ips.get(0).getTimestamp();
- boolean perma = false;
- for(BannedUserIPs banned : ips) {
- SteamwarUser bannedUser = SteamwarUser.get(banned.getUserID());
- if (bannedUser.isPunished(Punishment.PunishmentType.Ban)) {
- Punishment ban = bannedUser.getPunishment(Punishment.PunishmentType.Ban);
- if(ban.isPerma()) {
- perma = true;
- break;
- }
- if(ban.getEndTime().after(highestBan))
- highestBan = ban.getEndTime();
- }
- }
- ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ban " + user.getUserName() + " "
- + (perma?"perma":highestBan.toLocalDateTime().format(DateTimeFormatter.ofPattern("dd.MM.yyyy_HH:mm")))
- + " Ban Evasion - Bannumgehung");
-
- ChatSender.serverteamReceivers().forEach(sender -> sender.system(
- "BAN_AVOIDING_ALERT",
- new Message("BAN_AVOIDING_BAN_HOVER"),
- clickEvent,
- user.getUserName(),
- ips.stream().map(banned -> {
- SteamwarUser bannedUser = SteamwarUser.get(banned.getUserID());
- return sender.parseToLegacy("BAN_AVOIDING_LIST", bannedUser.getUserName(),
- banned.getTimestamp().toLocalDateTime().format(DateTimeFormatter.ofPattern(sender.parseToPlain("TIMEFORMAT"))));
- }).collect(Collectors.joining(" "))
- ));
- }
-
- event.completeIntent(BungeeCore.get());
- });
- }
-}
diff --git a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java
deleted file mode 100644
index 6cafdb0..0000000
--- a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java
+++ /dev/null
@@ -1,162 +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 .
-*/
-
-package de.steamwar.bungeecore.listeners;
-
-import de.steamwar.bungeecore.BungeeCore;
-import de.steamwar.bungeecore.Message;
-import de.steamwar.bungeecore.Servertype;
-import de.steamwar.bungeecore.Subserver;
-import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
-import de.steamwar.bungeecore.bot.util.DiscordRanks;
-import de.steamwar.bungeecore.commands.ChallengeCommand;
-import de.steamwar.bungeecore.commands.CheckCommand;
-import de.steamwar.bungeecore.commands.ModCommand;
-import de.steamwar.bungeecore.commands.MsgCommand;
-import de.steamwar.bungeecore.mods.ModUtils;
-import de.steamwar.sql.SteamwarUser;
-import de.steamwar.sql.UserPerm;
-import net.md_5.bungee.api.AbstractReconnectHandler;
-import net.md_5.bungee.api.ProxyServer;
-import net.md_5.bungee.api.chat.ClickEvent;
-import net.md_5.bungee.api.config.ServerInfo;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-import net.md_5.bungee.api.event.PlayerDisconnectEvent;
-import net.md_5.bungee.api.event.PostLoginEvent;
-import net.md_5.bungee.api.event.ServerKickEvent;
-import net.md_5.bungee.event.EventHandler;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.UUID;
-
-public class ConnectionListener extends BasicListener {
-
- public static final String ALERT_PERMISSION = "bungeecore.alert";
- public static final String BAN_PERMISSION = "bungeecore.ban";
- public static final String BUILDERCLOUD_PERMISSION = "bungeecore.buildercloud";
- public static final String CHECK_PERMISSION = "bungeecore.check";
- public static final String EVENTRELOAD_PERMISSION = "bungeecore.eventreload";
- public static final String KICK_PERMISSION = "bungeecore.kick";
- public static final String POLLRESULT_PERMISSION = "bungeecore.pollresult";
- public static final String SOFTRELOAD_PERMISSION = "bungeecore.softreload";
- public static final String TEAMCHAT_PERMISSION = "bungeecore.teamchat";
- public static final String MOD_PERMISSION = "bungeecore.mod";
-
- private static final Set newPlayers = new HashSet<>();
-
- public static void newPlayer(UUID player){
- newPlayers.add(player);
- }
-
- @EventHandler
- public void onPostLogin(PostLoginEvent event) {
- ProxiedPlayer player = event.getPlayer();
- SteamwarUser user = SteamwarUser.get(player.getUniqueId());
-
- if(user.hasPerm(UserPerm.ADMINISTRATION)) {
- player.setPermission("bungeecord.command.end", true);
- player.setPermission("bungeecord.command.reload", true);
- player.setPermission("bungeecord.command.ip", true);
- player.setPermission(SOFTRELOAD_PERMISSION, true);
- }
-
- if(user.hasPerm(UserPerm.MODERATION)) {
- player.setPermission(ALERT_PERMISSION, true);
- player.setPermission(KICK_PERMISSION, true);
- player.setPermission(POLLRESULT_PERMISSION, true);
- player.setPermission(EVENTRELOAD_PERMISSION, true);
- player.setPermission(MOD_PERMISSION, true);
- }
-
- if(user.hasPerm(UserPerm.TEAM)) {
- player.setPermission("bungeecord.command.list", true);
- player.setPermission("bungeecord.command.send", true);
- player.setPermission("bungeecord.command.server", true);
- player.setPermission(TEAMCHAT_PERMISSION, true);
- player.setPermission(BAN_PERMISSION, true);
- }
-
- if(user.hasPerm(UserPerm.CHECK)) {
- CheckCommand.sendReminder(player);
- player.setPermission(CHECK_PERMISSION, true);
- }
-
- if(user.hasPerm(UserPerm.BUILD)) {
- player.setPermission(BUILDERCLOUD_PERMISSION, true);
- }
-
- for(Subserver subserver : Subserver.getServerList()){
- if(subserver.getType() == Servertype.ARENA){
- Iterator it = subserver.getServer().getPlayers().iterator();
- if(it.hasNext()){
- Message.send("JOIN_ARENA", player, Message.parse("JOIN_ARENA_HOVER", player),
- new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + it.next().getName()), subserver.getServer().getName());
- }
- }
- }
-
- if(newPlayers.contains(player.getUniqueId())){
- Message.broadcast("JOIN_FIRST", player.getName());
- newPlayers.remove(player.getUniqueId());
- }
-
- if(SteamwarDiscordBotConfig.loaded)
- DiscordRanks.update(user);
- }
-
- /** To redirect players to the lobby in case of server closure. */
- @EventHandler
- public void onServerKickEvent(ServerKickEvent ev)
- {
- if(!ev.getPlayer().isConnected())
- return;
-
- ServerInfo kickedFrom;
-
- if (ev.getPlayer().getServer() != null){
- kickedFrom = ev.getPlayer().getServer().getInfo();
- }else if (ProxyServer.getInstance().getReconnectHandler() != null){
- kickedFrom = ProxyServer.getInstance().getReconnectHandler().getServer(ev.getPlayer());
- }else{
- kickedFrom = AbstractReconnectHandler.getForcedHost(ev.getPlayer().getPendingConnection());
- if (kickedFrom == null){
- kickedFrom = ProxyServer.getInstance().getServerInfo(ev.getPlayer().getPendingConnection().getListener().getDefaultServer());
- }
- }
-
- ServerInfo kickTo = ProxyServer.getInstance().getServerInfo(BungeeCore.LOBBY_SERVER);
-
- if (kickedFrom != null && kickedFrom.equals(kickTo)) {
- return;
- }
-
- ev.setCancelled(true);
- ev.setCancelServer(kickTo);
- }
-
- @EventHandler
- public void onDisconnect(PlayerDisconnectEvent e){
- ChallengeCommand.remove(e.getPlayer());
- MsgCommand.remove(e.getPlayer());
- ModUtils.getPlayerModMap().remove(e.getPlayer().getUniqueId());
- ModCommand.playerFilterType.remove(e.getPlayer());
- }
-}
diff --git a/src/de/steamwar/bungeecore/listeners/EventModeListener.java b/src/de/steamwar/bungeecore/listeners/EventModeListener.java
deleted file mode 100644
index c221dba..0000000
--- a/src/de/steamwar/bungeecore/listeners/EventModeListener.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package de.steamwar.bungeecore.listeners;
-
-import de.steamwar.bungeecore.Message;
-import de.steamwar.sql.*;
-import net.md_5.bungee.api.chat.TextComponent;
-import net.md_5.bungee.api.event.PostLoginEvent;
-import net.md_5.bungee.event.EventHandler;
-
-public class EventModeListener extends BasicListener {
-
- @EventHandler
- public void onPostLogin(PostLoginEvent e) {
- SteamwarUser user = SteamwarUser.get(e.getPlayer().getUniqueId());
-
- Event event = Event.get();
- if(event == null){
- e.getPlayer().disconnect(TextComponent.fromLegacyText(Message.parse("EVENTMODE_KICK", e.getPlayer())));
- return;
- }
-
- if(TeamTeilnahme.nimmtTeil(user.getTeam(), event.getEventID()))
- return;
-
- if(Referee.get(event.getEventID()).contains(user.getId()))
- return;
-
- e.getPlayer().disconnect(TextComponent.fromLegacyText(Message.parse("EVENTMODE_KICK", e.getPlayer())));
- }
-}
diff --git a/src/de/steamwar/bungeecore/listeners/IPSanitizer.java b/src/de/steamwar/bungeecore/listeners/IPSanitizer.java
deleted file mode 100644
index 9396a27..0000000
--- a/src/de/steamwar/bungeecore/listeners/IPSanitizer.java
+++ /dev/null
@@ -1,66 +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 .
- */
-
-package de.steamwar.bungeecore.listeners;
-
-import de.steamwar.bungeecore.BungeeCore;
-import net.md_5.bungee.api.connection.PendingConnection;
-import net.md_5.bungee.api.event.LoginEvent;
-import net.md_5.bungee.connection.InitialHandler;
-import net.md_5.bungee.event.EventHandler;
-import net.md_5.bungee.netty.ChannelWrapper;
-
-import java.lang.reflect.Field;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.util.logging.Level;
-
-public class IPSanitizer extends BasicListener {
-
- private static final Field initialHandlerCh;
- static {
- try {
- initialHandlerCh = InitialHandler.class.getDeclaredField("ch");
- } catch (NoSuchFieldException e) {
- throw new SecurityException("Could not initialize Reflection", e);
- }
- initialHandlerCh.setAccessible(true);
- }
-
- public static ChannelWrapper getChannelWrapper(PendingConnection connection) {
- try {
- return (ChannelWrapper) initialHandlerCh.get(connection);
- } catch (IllegalAccessException e) {
- throw new SecurityException("Could not get channel wrapper", e);
- }
- }
-
- public static InetAddress getTrueAddress(PendingConnection connection) {
- return ((InetSocketAddress) getChannelWrapper(connection).getHandle().remoteAddress()).getAddress();
- }
-
-
- private final InetSocketAddress sanitized = new InetSocketAddress("127.127.127.127", 25565);
-
- @EventHandler
- public void loginEvent(LoginEvent e) {
- BungeeCore.get().getLogger().log(Level.INFO, e.getConnection().getSocketAddress() + " has logged in with user name " + e.getConnection().getName());
- getChannelWrapper(e.getConnection()).setRemoteAddress(sanitized);
- }
-}
diff --git a/src/de/steamwar/bungeecore/listeners/PluginMessage.java b/src/de/steamwar/bungeecore/listeners/PluginMessage.java
deleted file mode 100644
index e04723d..0000000
--- a/src/de/steamwar/bungeecore/listeners/PluginMessage.java
+++ /dev/null
@@ -1,322 +0,0 @@
-/*
- * This file is a part of the SteamWar software.
- *
- * Copyright (C) 2024 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 .
- */
-
-package de.steamwar.bungeecore.listeners;
-
-import com.lunarclient.apollo.ApolloManager;
-import de.steamwar.bungeecore.BungeeCore;
-import de.steamwar.bungeecore.Message;
-import de.steamwar.bungeecore.commands.TeamCommand;
-import de.steamwar.bungeecore.mods.*;
-import de.steamwar.bungeecore.network.ServerMetaInfo;
-import de.steamwar.messages.ChatSender;
-import de.steamwar.network.packets.NetworkPacket;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.ByteBufAllocator;
-import io.netty.buffer.Unpooled;
-import net.md_5.bungee.api.ChatMessageType;
-import net.md_5.bungee.api.ProxyServer;
-import net.md_5.bungee.api.chat.TextComponent;
-import net.md_5.bungee.api.connection.Connection;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-import net.md_5.bungee.api.connection.Server;
-import net.md_5.bungee.api.event.PluginMessageEvent;
-import net.md_5.bungee.connection.InitialHandler;
-import net.md_5.bungee.event.EventHandler;
-import net.md_5.bungee.protocol.DefinedPacket;
-
-import java.io.ByteArrayOutputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.*;
-import java.util.function.Consumer;
-import java.util.logging.Level;
-
-public class PluginMessage extends BasicListener {
-
- public static void send(ProxiedPlayer player, String legacyChannel, String channel, byte[] data) {
- // 1.12 format change
- send(player, player.getPendingConnection().getVersion() > 340 ? channel : legacyChannel, data);
- }
-
- public static void send(ProxiedPlayer player, String channel, byte[] data) {
- if(((InitialHandler)player.getPendingConnection()).getRegisteredChannels().contains(channel))
- player.sendData(channel, data);
- }
-
- public static byte[] genBufPacket(Consumer generator) {
- ByteBuf buf = Unpooled.buffer();
- generator.accept(buf);
-
- byte[] packet = new byte[buf.readableBytes()];
- buf.readBytes(packet);
- return packet;
- }
-
- public static byte[] genStreamPacket(StreamConsumer generator) {
- ByteArrayOutputStream stream = new ByteArrayOutputStream();
- DataOutputStream out = new DataOutputStream(stream);
-
- try {
- generator.accept(out);
- } catch (IOException e) {
- throw new SecurityException("Could not create PluginMessage packet", e);
- }
-
- return stream.toByteArray();
- }
-
- public interface StreamConsumer {
- void accept(DataOutputStream out) throws IOException;
- }
-
- private static final Parser UNKNOWN = event -> BungeeCore.get().getLogger().log(Level.WARNING, () -> "Undefined PluginMessage on channel " + event.getTag() + " from " + event.getSender() + " received.\n" + new String(event.getData()) + "\n" + Arrays.toString(event.getData()));
- private static final Parser PASS_THROUGH = event -> event.setCancelled(false);
- private static final Parser DROP = event -> {};
-
- private final Lunar lunar = new Lunar();
-
- private final Set knownBrands = new HashSet<>();
- private final Map> channelRegisterHandlers = new HashMap<>();
- private final Map handlers = new HashMap<>();
-
- public PluginMessage() {
- //TODO interface generalisation
- LabyMod labyMod = new LabyMod();
- WorldDownloader wdl = new WorldDownloader();
-
- knownBrands.addAll(Arrays.asList("vanilla", "fabric", "quilt", "forge", "optifine", "Geyser", "labymod", "Feather Fabric"));
-
- for(String channel : Arrays.asList(
- "fabric:container/open", "fabric:registry/sync/direct", "fabric:registry/sync",
- "fabric-screen-handler-api-v1:open_screen",
-
- FML.CHANNEL, "fml:loginwrapper", "fml:handshake", "fml:play", "forge:tier_sorting", "forge:split",
- "forge:login", "forge:handshake",
-
- "labymod3:main", "labymod:neo",
-
- "floodgate:skin", "floodgate:form", "floodgate:transfer", "floodgate:packet",
-
- "Replay|Restrict", "replaymod:restrict",
- "WDL|CONTROL", "wdl:control",
- "tpshud:handshake", "tpshud:tps", //https://github.com/mooziii/tpshud-fabric/tree/main
- "methane_server:statepacket", //https://modrinth.com/mod/methane
- "servux:structures", //https://modrinth.com/mod/servux
- "architectury:spawn_entity_packet", //https://modrinth.com/mod/architectury-api
- "jei:channel", //https://modrinth.com/mod/jei
- "shulkerboxtooltip:s2c_handshake", "shulkerboxtooltip:ec_update", //https://modrinth.com/mod/shulkerboxtooltip
- "owo:local_packet", "owo:sync_screen_handler_properties", //https://modrinth.com/mod/owo-lib
- "essential:", //https://essential.gg/
- "libgui:screen_message_s2c", //https://github.com/CottonMC/LibGui
- "minecraft:intave", //https://intave.ac seems to be a client side integration of intave with labymod 4
- "midnightcontrols:feature", "midnightcontrols:controls_mode", //https://modrinth.com/mod/midnightcontrols
- "controlify:vibrate_from_origin", "controlify:vibration", "controlify:vibrate_from_entity",
- "carpet:structures", //https://modrinth.com/mod/carpet
- "appleskin:exhaustion_sync", "appleskin:saturation_sync", //https://modrinth.com/mod/appleskin
- "puzzleslib:1/1", //https://modrinth.com/mod/puzzles-lib
- "pickupnotifier:1/1", //https://modrinth.com/mod/pick-up-notifier
- "plasmo:voice/v2/installed", "plasmo:voice/v2", //https://modrinth.com/plugin/plasmo-voice
- "whereisit:s2c_founditem", //https://modrinth.com/mod/where-is-it (needs server side component to work)
- "inventorysorter:sync_blacklist_packet", //https://github.com/cpw/inventorysorter (needs server side component to work)
-
- //https://github.com/bernie-g/geckolib
- "geckolib:block_entity_anim_trigger_sync", "geckolib:entity_anim_trigger_sync",
- "geckolib:block_entity_anim_data_sync", "geckolib:anim_data_sync",
- "geckolib:entity_anim_data_sync", "geckolib:anim_trigger_sync",
-
- //https://github.com/Noxcrew/noxesium
- "noxesium-v1:reset", "noxesium-v1:change_server_rules", "noxesium-v1:server_info",
- "noxesium-v1:mcc_server", "noxesium-v1:mcc_game_state", "noxesium-v1:reset_server_rules",
- "noxesium-v1:stop_sound", "noxesium-v1:start_sound", "noxesium-v1:modify_sound"
- ))
- channelRegisterHandlers.put(channel, player -> {});
-
- channelRegisterHandlers.put(ApolloManager.PLUGIN_MESSAGE_CHANNEL, lunar::sendRestrictions);
- channelRegisterHandlers.put(Feather.CHANNEL, new Feather()::sendRestrictions);
- channelRegisterHandlers.put("xaerominimap:main", player -> player.sendMessage(ChatMessageType.SYSTEM, new TextComponent("§n§o§m§i§n§i§m§a§p"))); //https://www.curseforge.com/minecraft/mc-mods/xaeros-minimap
- channelRegisterHandlers.put("litemoretica:init_easy_place", player -> player.disconnect(ChatSender.of(player).parseToComponent(false, new Message("MOD_YELLOW_SING", "litematica")))); //https://github.com/Earthcomputer/litemoretica/tree/master
- channelRegisterHandlers.put("voxelmap:settings", player -> player.disconnect(ChatSender.of(player).parseToComponent(false, new Message("MOD_YELLOW_SING", "voxelmap")))); //https://modrinth.com/mod/voxelmap-updated undocumented
- channelRegisterHandlers.put("worldinfo:world_id", player -> player.disconnect(ChatSender.of(player).parseToComponent(false, new Message("MOD_YELLOW_SING", "minimap")))); // JourneyMap and VoxelMap
- channelRegisterHandlers.put(Controlify.CHANNEL, new Controlify()::onRegister);
-
- registerBiDirPassthrough("worldedit:cui");
-
- registerPassthroughToClient(
- "axiom:enable", "axiom:initialize_hotbars",
- "axiom:response_chunk_data", "axiom:register_world_properties", "axiom:set_world_property",
- "axiom:ack_world_properties", "axiom:restrictions", "axiom:marker_data", "axiom:marker_nbt_response",
- "axiom:custom_blocks", "axiom:editor_warning", "axiom:blueprint_manifest", "axiom:response_blueprint"
- );
- registerBiDirPassthrough("axiom:handle_big_payload", "axiom:set_editor_views");
- registerPassthroughToServer(
- "axiom:hello", "axiom:set_gamemode", "axiom:set_fly_speed", "axiom:set_world_time",
- "axiom:set_world_property", "axiom:set_block", "axiom:set_hotbar_slot", "axiom:switch_active_hotbar",
- "axiom:teleport", "axiom:request_chunk_data", "axiom:spawn_entity",
- "axiom:manipulate_entity", "axiom:delete_entity", "axiom:marker_nbt_request", "axiom:set_buffer"
- );
-
- for(String channel : Arrays.asList(
- "UNREGISTER", "minecraft:unregister", // used by carpet and servux
- "WDL|REQUEST", "wdl:request",
- "minecraft:intave", //undocumented, byte stringlength, clientconfig, byte length, json {"legacySneakHeight":false,"legacyOldRange":false,"legacyOldSlowdown":false}
- "waila:entity", "waila:block",
- "lambdacontrols:hello",
- "midnightcontrols:controls_mode",
- "inventorysorter:sync_settings_packet",
- "voicechat:request_secret", "voicechat:update_state", //https://modrinth.com/plugin/simple-voice-chat
- "shulkerboxtooltip:c2s_handshake"
- ))
- register(channel, false, directional(UNKNOWN, DROP));
-
- register("REGISTER", false, directional(this::serverRegistersChannel, this::clientRegistersChannel));
- register("minecraft:register", false, directional(this::serverRegistersChannel, this::clientRegistersChannel));
-
- register("BungeeCord", false, onlySWSource(PASS_THROUGH));
- register("bungeecord:main", false, onlySWSource(PASS_THROUGH));
- register("MC|Brand", false, directional(this::steamWarBrand, this::userBrand));
- register("minecraft:brand", false, directional(this::steamWarBrand, this::userBrand));
-
- //Needs to be registered cause paper refuses to send PluginMessages on unregistered channels...
- register("sw:bridge", true, directional(onlySWSource(async(event -> NetworkPacket.handle(new ServerMetaInfo(((Server) event.getSender()).getInfo()), event.getData()))), UNKNOWN));
- register("sw:hotkeys", false, directional(UNKNOWN, PASS_THROUGH));
- register("fabricmodsender:mods", true, directional(UNKNOWN, async(new FabricModSender()::handlePluginMessage)));
-
- register("WDL|INIT", true, directional(UNKNOWN, wdl::handlePluginMessage));
- register("wdl:init", true, directional(UNKNOWN, wdl::handlePluginMessage));
-
- register(ApolloManager.PLUGIN_MESSAGE_CHANNEL, true, async(lunar::handlePluginMessage));
- register("LMC", true, directional(UNKNOWN, async(labyMod::handlePluginMessage)));
- register("labymod3:main", true, directional(UNKNOWN, async(labyMod::handlePluginMessage)));
- register("labymod:neo", false, directional(UNKNOWN, DROP)); //undocumented, JSON format "0" byte, packetlängen byte, {"version":"4.1.25"}
- register(FML.CHANNEL, true, directional(UNKNOWN, async(new FML()::handlePluginMessage)));
-
- //vanilla does not register any channels (sends only one minecraft:brand vanilla, nothing else (potential spoofed client detection))
- //Forge interestingly registers all channels the server registers
- //meteor https://github.com/MeteorDevelopment/meteor-client/blob/master/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/ServerSpoof.java https://github.com/MeteorDevelopment/meteor-client/blob/master/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/DiscordPresence.java
- //litematica/malilib https://github.com/maruohon/litematica/issues/75 https://github.com/maruohon/malilib/blob/liteloader_1.12.2/src/main/java/malilib/network/message/ConfigLockPacketHandler.java#L65
- // Hackclientlike modsuppressor for labymod: https://github.com/Neocraftr/LabyMod-NeoEssentials (Potentially recognizable from NO Addons/NO Mods?) https://github.com/Neocraftr/LabyMod-NeoEssentials/blob/master/src/main/java/de/neocraftr/neoessentials/utils/BytecodeMethods.java
- }
-
- @EventHandler
- public void onPluginMessage(PluginMessageEvent event) {
- event.setCancelled(true);
-
- try {
- handlers.getOrDefault(event.getTag(), UNKNOWN).handle(event);
- } catch (Exception e) {
- throw new SecurityException("PluginMessage handling exception: " + event + "\n" + Arrays.toString(event.getData()), e);
- }
- }
-
- private void registerPassthroughToClient(String... channels) {
- for(String channel : channels) {
- channelRegisterHandlers.put(channel, player -> {});
- register(channel, false, directional(PASS_THROUGH, UNKNOWN));
- }
- }
-
- private void registerPassthroughToServer(String... channels) {
- for(String channel : channels)
- register(channel, false, directional(UNKNOWN, PASS_THROUGH));
- }
-
- private void registerBiDirPassthrough(String... channels) {
- for(String channel : channels) {
- channelRegisterHandlers.put(channel, player -> {});
- register(channel, false, PASS_THROUGH);
- }
- }
-
- private void register(String channel, boolean clientSideRegister, Parser handler) {
- handlers.put(channel, handler);
- if(clientSideRegister)
- ProxyServer.getInstance().registerChannel(channel);
- }
-
- private void clientRegistersChannel(PluginMessageEvent event) {
- ProxiedPlayer player = (ProxiedPlayer) event.getSender();
-
- for(String channel : new String(event.getData()).split("\0")) {
- channelRegisterHandlers.getOrDefault(channel, p -> BungeeCore.get().getLogger().log(Level.WARNING, () -> p.getName() + " registered unknown channel " + channel)).accept(player);
- }
-
- PASS_THROUGH.handle(event);
- }
-
- private void serverRegistersChannel(PluginMessageEvent event) {
- ProxiedPlayer player = (ProxiedPlayer)event.getReceiver();
-
- List channels = new ArrayList<>(Arrays.asList(new String(event.getData()).split("\0")));
- channels.removeIf(channel -> channel.equals("sw:bridge"));
- player.sendData((player).getPendingConnection().getVersion() > 340 ? "minecraft:register" : "REGISTER", String.join("\0", channels).getBytes());
- }
-
- private void userBrand(PluginMessageEvent event) {
- ProxiedPlayer player = (ProxiedPlayer) event.getSender();
- ByteBuf buf = Unpooled.wrappedBuffer(event.getData());
- String brand = DefinedPacket.readString(buf);
- boolean lunarclient = brand.startsWith("lunarclient:");
-
- BungeeCore.get().getLogger().log(knownBrands.contains(brand) || lunarclient ? Level.INFO : Level.WARNING, () -> player.getName() + " joins with brand: " + brand);
- if(lunarclient)
- lunar.sendRestrictions(player);
-
- PASS_THROUGH.handle(event);
- }
-
- private void steamWarBrand(PluginMessageEvent event) {
- ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
- String brandString = ChatSender.of(player).parseToLegacy("STEAMWAR_BRAND", ProxyServer.getInstance().getName(), player.getServer().getInfo().getName(), new String(event.getData(), 1, event.getData().length - 1));
-
- ByteBuf brand = ByteBufAllocator.DEFAULT.heapBuffer();
- DefinedPacket.writeString(brandString, brand);
- player.sendData(event.getTag(), DefinedPacket.toArray(brand));
- brand.release();
- }
-
-
- private Parser directional(Parser fromServer, Parser fromPlayer) {
- return event -> {
- if(event.getSender() instanceof ProxiedPlayer)
- fromPlayer.handle(event);
- else
- fromServer.handle(event);
- };
- }
-
- @SuppressWarnings("deprecation")
- private Parser onlySWSource(Parser parser) {
- return event -> {
- Connection sender = event.getSender();
- if(TeamCommand.isLocalhost(sender instanceof ProxiedPlayer ? IPSanitizer.getTrueAddress(((ProxiedPlayer) sender).getPendingConnection()) : sender.getAddress().getAddress()))
- parser.handle(event);
- else
- UNKNOWN.handle(event);
- };
- }
-
- private Parser async(Parser parser) {
- return event -> ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> parser.handle(event));
- }
-
- private interface Parser {
- void handle(PluginMessageEvent event);
- }
-}
diff --git a/src/de/steamwar/bungeecore/listeners/PollSystem.java b/src/de/steamwar/bungeecore/listeners/PollSystem.java
deleted file mode 100644
index b0bf952..0000000
--- a/src/de/steamwar/bungeecore/listeners/PollSystem.java
+++ /dev/null
@@ -1,82 +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 .
-*/
-
-package de.steamwar.bungeecore.listeners;
-
-import de.steamwar.bungeecore.Message;
-import de.steamwar.sql.PollAnswer;
-import de.steamwar.sql.SteamwarUser;
-import net.md_5.bungee.api.chat.ClickEvent;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-import net.md_5.bungee.api.event.PostLoginEvent;
-import net.md_5.bungee.event.EventHandler;
-
-import java.util.List;
-
-public class PollSystem extends BasicListener {
-
- private static String question;
- private static List answers;
-
- public static void init(String question, List answers){
- PollSystem.question = question;
- PollSystem.answers = answers;
-
- if(noCurrentPoll())
- return;
-
- PollAnswer.setCurrentPoll(question);
- new PollSystem();
- }
-
- @EventHandler
- public void onPostLogin(PostLoginEvent event){
- ProxiedPlayer player = event.getPlayer();
- SteamwarUser user = SteamwarUser.get(player.getUniqueId());
-
- PollAnswer answer = PollAnswer.get(user.getId());
- if(answer.hasAnswered())
- return;
-
- sendPoll(player);
- }
-
- public static void sendPoll(ProxiedPlayer player){
- Message.send("POLL_HEADER", player);
- Message.sendPrefixless("POLL_HEADER2", player);
- Message.sendPrefixless("POLL_QUESTION", player, question);
-
- for(int i = 1; i <= answers.size(); i++){
- Message.send("POLL_ANWSER", player, Message.parse("POLL_ANWSER_HOVER", player, answers.get(i-1)),
- new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/poll " + i), answers.get(i-1));
- }
- }
-
- public static boolean noCurrentPoll(){
- return question == null || question.equals("");
- }
-
- public static int answers(){
- return answers.size();
- }
-
- public static String getAnswer(int i) {
- return answers.get(i);
- }
-}
diff --git a/src/de/steamwar/bungeecore/mods/FML2.java b/src/de/steamwar/bungeecore/mods/FML2.java
deleted file mode 100644
index 68699ad..0000000
--- a/src/de/steamwar/bungeecore/mods/FML2.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * This file is a part of the SteamWar software.
- *
- * Copyright (C) 2024 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 .
- */
-
-package de.steamwar.bungeecore.mods;
-
-import de.steamwar.bungeecore.BungeeCore;
-import de.steamwar.bungeecore.listeners.BasicListener;
-import de.steamwar.bungeecore.listeners.IPSanitizer;
-import de.steamwar.bungeecore.listeners.PluginMessage;
-import de.steamwar.sql.Mod;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
-import net.md_5.bungee.api.chat.TextComponent;
-import net.md_5.bungee.api.connection.PendingConnection;
-import net.md_5.bungee.api.event.LoginEvent;
-import net.md_5.bungee.event.EventHandler;
-import net.md_5.bungee.netty.HandlerBoss;
-import net.md_5.bungee.netty.PacketHandler;
-import net.md_5.bungee.protocol.DefinedPacket;
-import net.md_5.bungee.protocol.packet.LoginPayloadRequest;
-import net.md_5.bungee.protocol.packet.LoginPayloadResponse;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
-import java.util.logging.Level;
-
-public class FML2 extends BasicListener {
- // FML2: https://wiki.vg/Minecraft_Forge_Handshake#FML2_protocol_.281.13_-_Current.29
- // FML3: https://github.com/adde0109/Ambassador/tree/non-api/src/main/java/org/adde0109/ambassador/forge
-
- // FORGE: https://github.com/MinecraftForge/MinecraftForge/blob/1.20.x/src/main/java/net/minecraftforge/network/NetworkInitialization.java
- // FORGE: https://github.com/MinecraftForge/MinecraftForge/blob/1.20.x/src/main/java/net/minecraftforge/network/ForgePacketHandler.java
- // FORGE: https://github.com/MinecraftForge/MinecraftForge/blob/1.20.x/src/main/java/net/minecraftforge/network/packets/ModVersions.java
-
- private final byte[] fml2ModListPacket;
- private final byte[] fml3ModListPacket;
- private final byte[] forgeModListPacket;
-
- public FML2() {
- fml2ModListPacket = generateModListPacket(false);
- fml3ModListPacket = generateModListPacket(true);
- forgeModListPacket = PluginMessage.genBufPacket(buf -> {
- buf.writeByte(0); // Login wrapper packet
- DefinedPacket.writeString("forge:handshake", buf);
-
- ByteBuf packet = Unpooled.buffer();
- packet.writeByte(1); // Mod list packet
- DefinedPacket.writeVarInt(0, packet); // Mod amount
-
- DefinedPacket.writeVarInt(packet.readableBytes(), buf);
- buf.writeBytes(packet);
- });
- }
-
- @EventHandler
- public void onLogin(LoginEvent event) {
- PendingConnection connection = event.getConnection();
-
- boolean fml2 = FML.isFML(connection, "FML2\0");
- boolean fml3 = FML.isFML(connection, "FML3\0");
- boolean forge = FML.isFML(connection, "FORGE");
- if(!fml2 && !fml3 && !forge)
- return;
-
- IPSanitizer.getChannelWrapper(connection).getHandle().pipeline().get(HandlerBoss.class).setHandler(new FML2LoginHandler(event));
-
- event.registerIntent(BungeeCore.get());
- if(forge)
- connection.unsafe().sendPacket(new LoginPayloadRequest(1, "forge:login", forgeModListPacket));
- else
- connection.unsafe().sendPacket(new LoginPayloadRequest(1, "fml:loginwrapper", fml3 ? fml3ModListPacket : fml2ModListPacket));
- }
-
- private byte[] generateModListPacket(boolean fml3) {
- return PluginMessage.genBufPacket(buf -> {
- DefinedPacket.writeString("fml:handshake", buf);
-
- ByteBuf packet = Unpooled.buffer();
- packet.writeByte(1); // Mod list packet
- DefinedPacket.writeVarInt(0, packet); // Mod amount
-
- if(fml3) {
- DefinedPacket.writeVarInt(1, packet); // Channel amount
- DefinedPacket.writeString("forge:tier_sorting", packet);
- DefinedPacket.writeString("1.0", packet);
- } else {
- DefinedPacket.writeVarInt(0, packet); // Channel amount
- }
-
- DefinedPacket.writeVarInt(0, packet); // Registries amount
- if(fml3)
- DefinedPacket.writeVarInt(0, packet); // DataPacks amount
-
- DefinedPacket.writeVarInt(packet.readableBytes(), buf);
- buf.writeBytes(packet);
- });
- }
-
- private static class FML2LoginHandler extends PacketHandler {
- private final LoginEvent event;
-
- public FML2LoginHandler(LoginEvent event) {
- this.event = event;
- }
-
- @Override
- public String toString() {
- return "SteamWar Forge Handler";
- }
-
- @Override
- public void handle(LoginPayloadResponse response) {
- boolean forge = FML.isFML(event.getConnection(), "FORGE");
- byte[] data = response.getData();
- if(data == null) {
- abort(response, "Not FML2/3 client");
- return;
- }
-
- ByteBuf buf = Unpooled.wrappedBuffer(data);
- if(forge && buf.readByte() != 0) {
- abort(response, "Not FORGE login wrapper");
- return;
- }
-
- if(!DefinedPacket.readString(buf).equals(forge ? "forge:handshake" : "fml:handshake")) {
- abort(response, "Not FML2/3/FORGE handshake response");
- return;
- }
-
- if(DefinedPacket.readVarInt(buf) != buf.readableBytes()) {
- abort(response, "FML2/3/FORGE packet size mismatch");
- return;
- }
-
- if(DefinedPacket.readVarInt(buf) != (forge ? /* Mod Versions */ 1 : /* Mod List Reply */ 2)) {
- abort(response, "Not FML2/3/FORGE mod list reply");
- return;
- }
-
- List mods = new ArrayList<>();
-
- int modCount = DefinedPacket.readVarInt(buf);
- for(int i = 0; i < modCount; i++) {
- mods.add(Mod.getOrCreate(DefinedPacket.readString(buf), Mod.Platform.FORGE));
-
- if(forge) {
- DefinedPacket.readString(buf); // Human readable name
- DefinedPacket.readString(buf); // Version
- }
- }
-
- if(!ModUtils.handleMods(event.getConnection().getUniqueId(), Locale.getDefault(), event::setReason, mods))
- event.setCancelled(true);
-
- event.completeIntent(BungeeCore.get());
- }
-
- private void abort(LoginPayloadResponse response, String error) {
- event.setReason(TextComponent.fromLegacy(error));
- event.setCancelled(true);
- event.completeIntent(BungeeCore.get());
- BungeeCore.get().getLogger().log(Level.SEVERE, () -> error + "\n" + response);
- }
- }
-}
diff --git a/src/de/steamwar/bungeecore/mods/Hostname.java b/src/de/steamwar/bungeecore/mods/Hostname.java
deleted file mode 100644
index 79b8ebe..0000000
--- a/src/de/steamwar/bungeecore/mods/Hostname.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * This file is a part of the SteamWar software.
- *
- * Copyright (C) 2024 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 .
- */
-
-package de.steamwar.bungeecore.mods;
-
-import de.steamwar.bungeecore.BungeeCore;
-import de.steamwar.bungeecore.listeners.BasicListener;
-import net.md_5.bungee.api.event.PlayerHandshakeEvent;
-import net.md_5.bungee.connection.InitialHandler;
-import net.md_5.bungee.event.EventHandler;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.logging.Level;
-
-public class Hostname extends BasicListener {
-
- private final Set knownHostnames = new HashSet<>();
- private final Set knownExtraData = new HashSet<>();
-
- public Hostname() {
- knownHostnames.add("steamwar.de");
- knownHostnames.add("78.31.71.136");
- knownHostnames.add("memewar.de"); // Chaoscaot
- knownHostnames.add("dampfkrieg.de"); // Chaoscaot
- knownHostnames.add("127.0.0.1"); // Geyser
-
- knownHostnames.add("@mat:matdoes.dev "); //https://github.com/mat-1/matscan
- knownHostnames.add("wtf.mynx.lol"); //https://discord.com/invite/serverseeker
- knownHostnames.add("masscan");
- knownHostnames.add("aaa");
-
- knownExtraData.add("");
- knownExtraData.add("\0FML\0");
- knownExtraData.add("\0FML2\0");
- knownExtraData.add("\0FML3\0");
- knownExtraData.add("\0FORGE");
- }
-
- @EventHandler
- public void onHandshake(PlayerHandshakeEvent event) {
- String hostname = event.getHandshake().getHost().toLowerCase();
- String extraDataInHandshake = ((InitialHandler) event.getConnection()).getExtraDataInHandshake();
- if (!knownHostnames.contains(hostname) && !hostname.endsWith(".steamwar.de")) {
- BungeeCore.get().getLogger().log(Level.WARNING, () -> event.getConnection().getSocketAddress() + " connected with unknown hostname " + event.getHandshake() + " " + extraDataInHandshake);
- } else if (!knownExtraData.contains(extraDataInHandshake)) {
- BungeeCore.get().getLogger().log(Level.WARNING, () -> event.getConnection().getSocketAddress() + " connected with unknown extra data " + event.getHandshake() + " " + extraDataInHandshake);
- }
- }
-}
diff --git a/src/de/steamwar/bungeecore/mods/ServerListPing.java b/src/de/steamwar/bungeecore/mods/ServerListPing.java
deleted file mode 100644
index e774794..0000000
--- a/src/de/steamwar/bungeecore/mods/ServerListPing.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * This file is a part of the SteamWar software.
- *
- * Copyright (C) 2024 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 .
- */
-
-package de.steamwar.bungeecore.mods;
-
-import com.google.gson.*;
-import de.steamwar.bungeecore.listeners.BasicListener;
-import net.md_5.bungee.BungeeCord;
-import net.md_5.bungee.api.ServerPing;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Type;
-
-public class ServerListPing extends BasicListener implements JsonSerializer, JsonDeserializer {
- // https://github.com/Aizistral-Studios/No-Chat-Reports/discussions/206
- // https://github.com/Aizistral-Studios/No-Chat-Reports/wiki/How-to-Get-Safe-Server-Status
-
- private final Gson gson;
-
- public ServerListPing() {
- BungeeCord bungeeCord = BungeeCord.getInstance();
- gson = bungeeCord.gson;
-
- try {
- Field gsonField = BungeeCord.class.getDeclaredField("gson");
- gsonField.setAccessible(true);
- gsonField.set(bungeeCord, gson.newBuilder().registerTypeAdapter(ServerPing.class, this).create());
- } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
- throw new SecurityException("Failed to inject ServerListPing", e);
- }
- }
-
- @Override
- public JsonElement serialize(ServerPing ping, Type type, JsonSerializationContext context) {
- JsonElement element = gson.toJsonTree(ping, type);
-
- JsonObject object = element.getAsJsonObject();
- object.addProperty("preventsChatReports", true);
-
- return element;
- }
-
- @Override
- public ServerPing deserialize(JsonElement element, Type type, JsonDeserializationContext context) throws JsonParseException {
- return gson.fromJson(element, ServerPing.class);
- }
-}
diff --git a/src/de/steamwar/bungeecore/network/BungeeNetworkHandler.java b/src/de/steamwar/bungeecore/network/BungeeNetworkHandler.java
deleted file mode 100644
index 220220b..0000000
--- a/src/de/steamwar/bungeecore/network/BungeeNetworkHandler.java
+++ /dev/null
@@ -1,36 +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 .
- */
-
-package de.steamwar.bungeecore.network;
-
-import de.steamwar.bungeecore.network.handlers.*;
-import lombok.experimental.UtilityClass;
-
-@UtilityClass
-public class BungeeNetworkHandler {
- public static void register() {
- new EloPlayerHandler().register();
- new EloSchemHandler().register();
- new ExecuteCommandHandler().register();
- new FightInfoHandler().register();
- new ImALobbyHandler().register();
- new InventoryCallbackHandler().register();
- new PrepareSchemHandler().register();
- }
-}
diff --git a/src/de/steamwar/bungeecore/network/handlers/FightInfoHandler.java b/src/de/steamwar/bungeecore/network/handlers/FightInfoHandler.java
deleted file mode 100644
index 3f4bff2..0000000
--- a/src/de/steamwar/bungeecore/network/handlers/FightInfoHandler.java
+++ /dev/null
@@ -1,66 +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 .
-*/
-
-package de.steamwar.bungeecore.network.handlers;
-
-import de.steamwar.bungeecore.network.NetworkSender;
-import de.steamwar.bungeecore.network.ServerMetaInfo;
-import de.steamwar.bungeecore.tablist.TablistManager;
-import de.steamwar.network.packets.PacketHandler;
-import de.steamwar.network.packets.common.FightInfoPacket;
-import net.md_5.bungee.api.config.ServerInfo;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-public class FightInfoHandler extends PacketHandler {
-
- private static final Set lobbys = new HashSet<>();
-
- public static void addLobby(ServerInfo lobby) {
- lobbys.add(lobby);
- }
-
- public static boolean onLobby(ProxiedPlayer player) {
- return lobbys.contains(player.getServer().getInfo());
- }
-
- @Handler
- public void handle(FightInfoPacket packet) {
- ServerInfo info = ((ServerMetaInfo) packet.getMetaInfos()).getSender();
-
- FightInfoPacket lobbyPacket = packet.withServerName(info.getName());
-
- TablistManager.newFightInfo(info, packet);
-
- Iterator lobbyIt = lobbys.iterator();
- while(lobbyIt.hasNext()) {
- ServerInfo lobby = lobbyIt.next();
- Iterator it = lobby.getPlayers().iterator();
- if(!it.hasNext()){
- lobbyIt.remove();
- continue;
- }
-
- NetworkSender.send(lobby, lobbyPacket);
- }
- }
-}
diff --git a/src/de/steamwar/bungeecore/tablist/Tablist.java b/src/de/steamwar/bungeecore/tablist/Tablist.java
deleted file mode 100644
index 804ff18..0000000
--- a/src/de/steamwar/bungeecore/tablist/Tablist.java
+++ /dev/null
@@ -1,369 +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 .
- */
-
-package de.steamwar.bungeecore.tablist;
-
-import de.steamwar.bungeecore.Storage;
-import de.steamwar.messages.ChatSender;
-import io.netty.channel.ChannelHandler;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelPipeline;
-import io.netty.handler.codec.MessageToMessageDecoder;
-import net.md_5.bungee.ServerConnection;
-import net.md_5.bungee.UserConnection;
-import net.md_5.bungee.api.ProxyServer;
-import net.md_5.bungee.api.chat.BaseComponent;
-import net.md_5.bungee.api.chat.TextComponent;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-import net.md_5.bungee.netty.PipelineUtils;
-import net.md_5.bungee.protocol.DefinedPacket;
-import net.md_5.bungee.protocol.Either;
-import net.md_5.bungee.protocol.PacketWrapper;
-import net.md_5.bungee.protocol.ProtocolConstants;
-import net.md_5.bungee.protocol.packet.*;
-
-import java.util.*;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
-
-@ChannelHandler.Sharable
-public class Tablist extends MessageToMessageDecoder {
-
- private static final UUID[] uuids = IntStream.range(0, 80).mapToObj(i -> UUID.randomUUID()).toArray(UUID[]::new);
- private static final String[] names = IntStream.range(0, 80).mapToObj(i -> " »SW« " + String.format("%02d", i)).toArray(String[]::new);
- private static final String TAB_TEAM = "zzzzzsw-tab";
- private static final Team teamPacket = new Team(TAB_TEAM, (byte) 0, Either.right(TextComponent.fromLegacy("")), Either.right(TextComponent.fromLegacy("")), Either.right(TextComponent.fromLegacy("")), "never", "always", 21, (byte)0x00, names);
-
- private final Map directTabItems;
- private final Set npcs = new HashSet<>();
- private final List current = new ArrayList<>();
-
- private final ProxiedPlayer player;
- private final ChatSender viewer;
- private ServerConnection connection;
-
- public Tablist(ProxiedPlayer player) {
- this.player = player;
- this.viewer = ChatSender.of(player);
- this.directTabItems = Storage.directTabItems.computeIfAbsent(player, p -> new HashMap<>());
- injection();
- }
-
- public void update(TablistPart global, int seconds) {
- if (connection == null)
- return;
-
- player.setTabHeader(header(viewer, seconds), viewer.parse(false, "TABLIST_FOOTER", connection.getInfo().getName(), ping(), ProxyServer.getInstance().getPlayers().size()));
-
- List tablist = new ArrayList<>();
- List direct = new ArrayList<>();
- global.print(viewer, player, tablist, direct);
-
- // NPC handling
- List addNpc = new ArrayList<>();
- List removeNpc = new ArrayList<>();
- List update = new ArrayList<>();
- Set nonNPCs = direct.stream().map(TablistPart.Item::getUuid).collect(Collectors.toSet());
- synchronized (directTabItems) {
- for (TablistPart.Item item : direct) {
- PlayerListItem.Item tabItem = directTabItems.get(item.getUuid());
-
- if(npcs.remove(item.getUuid()))
- removeNpc.add(tabItem.getUsername());
-
- if(tabItem == null) {
- tablist.add(0, item);
- } else if(!tabItem.getDisplayName().equals(item.getDisplayName())) {
- tabItem.setDisplayName(item.getDisplayName());
- tabItem.setListed(true);
- update.add(tabItem);
- }
- }
- boolean playerNotOnTeamserver = !Storage.teamServers.containsValue(player.getServer().getInfo());
- for(PlayerListItem.Item item : directTabItems.values()) {
- if(playerNotOnTeamserver && !nonNPCs.contains(item.getUuid()) && !npcs.contains(item.getUuid()) && !player.getUniqueId().equals(item.getUuid())) {
- npcs.add(item.getUuid());
- addNpc.add(item.getUsername());
- }
- }
- }
- sendNpcPacket(addNpc, false);
- sendNpcPacket(removeNpc, true);
-
- // Main list handling
- int i = 0;
- List add = new ArrayList<>();
- List remove = new ArrayList<>();
- for (; i < tablist.size() && i < 80; i++) {
- PlayerListItem.Item tabItem;
- if(current.size() > i) {
- tabItem = current.get(i);
- } else {
- tabItem = new PlayerListItem.Item();
- tabItem.setUuid(uuids[i]);
- tabItem.setUsername(names[i]);
- tabItem.setGamemode(1);
- tabItem.setListed(true);
- tabItem.setPing(1000);
- current.add(tabItem);
- }
-
- TablistPart.Item item = tablist.get(i);
- if(!Arrays.equals(tabItem.getProperties(), item.getProperties())) {
- tabItem.setProperties(item.getProperties());
- tabItem.setDisplayName(item.getDisplayName());
- add.add(tabItem);
- if(current.size() > i) {
- remove.add(tabItem);
- }
- } else if(!item.getDisplayName().equals(tabItem.getDisplayName())) {
- tabItem.setDisplayName(item.getDisplayName());
- update.add(tabItem);
- }
- }
-
- // Excess removal
- while(i < current.size()) {
- remove.add(current.remove(i));
- }
-
- sendTabPacket(remove, PlayerListItem.Action.REMOVE_PLAYER);
- sendTabPacket(update, PlayerListItem.Action.UPDATE_DISPLAY_NAME);
- sendTabPacket(add, PlayerListItem.Action.ADD_PLAYER);
- }
-
- public void onServerSwitch() {
- injection();
-
- synchronized (directTabItems) {
- sendNpcPacket(npcs.stream().map(npc -> directTabItems.get(npc).getUsername()).collect(Collectors.toList()), true);
- directTabItems.clear();
- npcs.clear();
- }
- }
-
- private void injection() {
- connection = (ServerConnection) player.getServer();
-
- if(connection != null) {
- ChannelPipeline pipeline = connection.getCh().getHandle().pipeline();
- if(pipeline.get("steamwar-tablist") != null) //Catch unclean exit
- pipeline.remove("steamwar-tablist");
-
- pipeline.addBefore(PipelineUtils.BOSS_HANDLER, "steamwar-tablist", this);
- sendQueued(player, teamPacket);
- }
- }
-
- public void disable() {
- sendTabPacket(current, PlayerListItem.Action.REMOVE_PLAYER);
- current.clear();
- synchronized (directTabItems) {
- sendNpcPacket(npcs.stream().map(npc -> directTabItems.get(npc).getUsername()).collect(Collectors.toList()), true);
- npcs.clear();
- }
-
- if(connection != null)
- connection.getCh().getHandle().pipeline().remove(this);
- }
-
- @Override
- protected void decode(ChannelHandlerContext ctx, PacketWrapper packetWrapper, List out) {
- if(!connection.isObsolete()) {
- DefinedPacket packet = packetWrapper.packet;
-
- if(packet instanceof PlayerListHeaderFooter) {
- packetWrapper.trySingleRelease();
- return;
- }
-
- if(packet instanceof PlayerListItem) {
- PlayerListItem list = (PlayerListItem) packet;
- PlayerListItem.Action action = list.getAction();
-
- switch(action) {
- case UPDATE_LATENCY:
- case UPDATE_DISPLAY_NAME:
- packetWrapper.trySingleRelease();
- return;
- case UPDATE_GAMEMODE:
- for (PlayerListItem.Item item : list.getItems()) {
- ProxiedPlayer p = ProxyServer.getInstance().getPlayer(item.getUuid());
- if(p != null && p != player && item.getGamemode() == 3) {
- item.setGamemode(1);
- }
- }
- break;
- case ADD_PLAYER:
- boolean playerNotOnTeamserver = !Storage.teamServers.containsValue(player.getServer().getInfo());
- for (PlayerListItem.Item item : list.getItems()) {
- item.setPing(1);
- if (playerNotOnTeamserver) {
- item.setDisplayName(new TextComponent());
- item.setListed(false);
- } else if (item.getDisplayName() == null) {
- item.setDisplayName(TextComponent.fromLegacy("§7" + item.getUsername()));
- }
- item.setPublicKey(null);
- if(!player.getUniqueId().equals(item.getUuid()) && item.getGamemode() == 3)
- item.setGamemode(1);
-
- synchronized (directTabItems) {
- directTabItems.put(item.getUuid(), item);
- }
- }
- break;
- case REMOVE_PLAYER:
- List names = new ArrayList<>();
- for(PlayerListItem.Item item : list.getItems()) {
- synchronized (directTabItems) {
- PlayerListItem.Item directItem = directTabItems.remove(item.getUuid());
- if(npcs.remove(item.getUuid()))
- names.add(directItem.getUsername());
- }
- }
- sendNpcPacket(names, true);
- break;
- }
- } else if(packet instanceof PlayerListItemRemove) {
- List names = new ArrayList<>();
- for(UUID uuid : ((PlayerListItemRemove) packet).getUuids()) {
- synchronized (directTabItems) {
- PlayerListItem.Item directItem = directTabItems.remove(uuid);
- if(npcs.remove(uuid))
- names.add(directItem.getUsername());
- }
- }
- sendNpcPacket(names, true);
- } else if(packet instanceof PlayerListItemUpdate) {
- PlayerListItemUpdate list = (PlayerListItemUpdate) packet;
- EnumSet actions = list.getActions();
- actions.remove(PlayerListItemUpdate.Action.INITIALIZE_CHAT);
- actions.remove(PlayerListItemUpdate.Action.UPDATE_LATENCY);
- actions.remove(PlayerListItemUpdate.Action.UPDATE_DISPLAY_NAME);
- actions.remove(PlayerListItemUpdate.Action.UPDATE_LISTED);
- if(actions.isEmpty()) {
- packetWrapper.trySingleRelease();
- return;
- }
-
- boolean playerNotOnTeamserver = !Storage.teamServers.containsValue(player.getServer().getInfo());
- for(PlayerListItemUpdate.Action action : actions) {
- switch (action) {
- case ADD_PLAYER:
- for (PlayerListItem.Item item : list.getItems()) {
- item.setPing(1);
- if (playerNotOnTeamserver) {
- item.setDisplayName(new TextComponent());
- item.setListed(false);
- } else if (item.getDisplayName() == null) {
- item.setDisplayName(TextComponent.fromLegacy("§7" + item.getUsername()));
- }
- item.setPublicKey(null);
- if(!player.getUniqueId().equals(item.getUuid()) && item.getGamemode() == 3)
- item.setGamemode(1);
-
- synchronized (directTabItems) {
- directTabItems.put(item.getUuid(), item);
- }
- }
- break;
- case UPDATE_GAMEMODE:
- for (PlayerListItem.Item item : list.getItems()) {
- ProxiedPlayer p = ProxyServer.getInstance().getPlayer(item.getUuid());
- if(p != null && p != player && item.getGamemode() == 3) {
- item.setGamemode(1);
- }
- }
- break;
- case UPDATE_LISTED:
- case INITIALIZE_CHAT:
- case UPDATE_LATENCY:
- case UPDATE_DISPLAY_NAME:
- break;
- }
- }
-
- if(actions.contains(PlayerListItemUpdate.Action.ADD_PLAYER)) {
- actions.add(PlayerListItemUpdate.Action.UPDATE_LISTED);
- actions.add(PlayerListItemUpdate.Action.UPDATE_DISPLAY_NAME);
- actions.add(PlayerListItemUpdate.Action.UPDATE_LATENCY);
- actions.add(PlayerListItemUpdate.Action.UPDATE_GAMEMODE);
- }
- }
- }
- out.add(packetWrapper);
- }
-
- private boolean oldTab() {
- return player.getPendingConnection().getVersion() < ProtocolConstants.MINECRAFT_1_19_3;
- }
-
- private void sendTabPacket(List items, PlayerListItem.Action action) { //Breaks in 1.19.3 if action != UPDATE_DISPLAY_NAME, ADD_PLAYER or REMOVE_PLAYER
- if(!items.isEmpty()) {
- if(oldTab()) {
- PlayerListItem packet = new PlayerListItem();
- packet.setAction(action);
- packet.setItems(items.toArray(new PlayerListItem.Item[0]));
- sendQueued(player, packet);
- } else if(action == PlayerListItem.Action.REMOVE_PLAYER) {
- PlayerListItemRemove packet = new PlayerListItemRemove();
- packet.setUuids(items.stream().map(PlayerListItem.Item::getUuid).toArray(UUID[]::new));
- sendQueued(player, packet);
- } else {
- PlayerListItemUpdate packet = new PlayerListItemUpdate();
- packet.setActions(action == PlayerListItem.Action.UPDATE_DISPLAY_NAME ? EnumSet.of(PlayerListItemUpdate.Action.UPDATE_DISPLAY_NAME, PlayerListItemUpdate.Action.UPDATE_LISTED) : EnumSet.of(PlayerListItemUpdate.Action.ADD_PLAYER, PlayerListItemUpdate.Action.UPDATE_DISPLAY_NAME, PlayerListItemUpdate.Action.UPDATE_LATENCY, PlayerListItemUpdate.Action.UPDATE_LISTED, PlayerListItemUpdate.Action.UPDATE_GAMEMODE));
- packet.setItems(items.toArray(new PlayerListItem.Item[0]));
- sendQueued(player, packet);
- }
- }
- }
-
- private void sendNpcPacket(List names, boolean remove) {
- if(!names.isEmpty()) {
- Team packet = new Team(TAB_TEAM);
- packet.setMode((byte) (remove ? 4 : 3));
- packet.setPlayers(names.toArray(new String[0]));
- sendQueued(player, packet);
- }
- }
-
- private BaseComponent[] header(ChatSender p, int seconds) {
- int phase = (seconds % 10) / 5;
- if (phase == 0)
- return p.parse(false, "TABLIST_PHASE_DISCORD");
- else
- return p.parse(false, "TABLIST_PHASE_WEBSITE");
- }
-
- private String ping() {
- int ping = player.getPing();
- if (ping < 50) {
- return "§a" + ping;
- } else if (ping < 150) {
- return "§e" + ping;
- } else {
- return "§c" + ping;
- }
- }
-
- private static void sendQueued(ProxiedPlayer player, DefinedPacket packet) {
- ((UserConnection)player).sendPacketQueued(packet);
- }
-}
diff --git a/src/de/steamwar/bungeecore/tablist/TablistPart.java b/src/de/steamwar/bungeecore/tablist/TablistPart.java
deleted file mode 100644
index f15a239..0000000
--- a/src/de/steamwar/bungeecore/tablist/TablistPart.java
+++ /dev/null
@@ -1,90 +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 .
- */
-
-package de.steamwar.bungeecore.tablist;
-
-import de.steamwar.messages.ChatSender;
-import de.steamwar.sql.SteamwarUser;
-import de.steamwar.sql.UserPerm;
-import net.md_5.bungee.api.chat.BaseComponent;
-import net.md_5.bungee.api.chat.TextComponent;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-import net.md_5.bungee.connection.InitialHandler;
-import net.md_5.bungee.connection.LoginResult;
-import net.md_5.bungee.protocol.Property;
-
-import java.util.List;
-import java.util.UUID;
-
-interface TablistPart {
- String sortKey();
- void print(ChatSender viewer, ProxiedPlayer player, List- tablist, List
- direct);
-
- class Item {
-
- public static Property[] playerProperties(ProxiedPlayer player) {
- LoginResult loginResult = ((InitialHandler) player.getPendingConnection()).getLoginProfile();
- if(loginResult == null)
- return new Property[0];
-
- return loginResult.getProperties();
- }
-
- private final UUID uuid;
- private final BaseComponent displayName;
- private final Property[] properties;
-
- public Item(UUID uuid, String displayName, Property[] properties) {
- this.uuid = uuid;
- this.displayName = reformat(displayName);
- this.properties = properties;
- }
-
- public Item(ProxiedPlayer player) {
- this(player, false);
- }
-
- public Item(ProxiedPlayer player, boolean sameTeam) {
- this.uuid = player.getUniqueId();
- UserPerm.Prefix prefix = SteamwarUser.get(player.getUniqueId()).prefix();
- if (prefix == UserPerm.emptyPrefix && sameTeam) {
- this.displayName = reformat("§f" + player.getName());
- } else {
- this.displayName = reformat(prefix.getColorCode() + player.getName());
- }
- this.properties = playerProperties(player);
- }
-
- public UUID getUuid() {
- return uuid;
- }
-
- public BaseComponent getDisplayName() {
- return displayName;
- }
-
- public Property[] getProperties() {
- return properties;
- }
-
- private BaseComponent reformat(String string) {
- return TextComponent.fromArray(TextComponent.fromLegacyText(string));
- }
- }
-}
diff --git a/src/de/steamwar/bungeecore/tablist/TablistServer.java b/src/de/steamwar/bungeecore/tablist/TablistServer.java
deleted file mode 100644
index 812588d..0000000
--- a/src/de/steamwar/bungeecore/tablist/TablistServer.java
+++ /dev/null
@@ -1,103 +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
.
- */
-
-package de.steamwar.bungeecore.tablist;
-
-import de.steamwar.bungeecore.Servertype;
-import de.steamwar.bungeecore.Subserver;
-import de.steamwar.sql.SteamwarUser;
-import de.steamwar.messages.ChatSender;
-import de.steamwar.network.packets.common.FightInfoPacket;
-import net.md_5.bungee.BungeeCord;
-import net.md_5.bungee.api.config.ServerInfo;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-import net.md_5.bungee.protocol.Property;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Optional;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-public class TablistServer implements TablistPart {
-
- public static final Property[] GRAY = new Property[]{new Property("textures", "eyJ0aW1lc3RhbXAiOjE0NTU1NzQxMTk0MzMsInByb2ZpbGVJZCI6ImIzYjE4MzQ1MzViZjRiNzU4ZTBjZGJmMGY4MjA2NTZlIiwicHJvZmlsZU5hbWUiOiIxMDExMTEiLCJzaWduYXR1cmVSZXF1aXJlZCI6dHJ1ZSwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlLzZlNzJkMzE0NzczMmQ5NzFkZWZhZTIzMWIzOGQ5NDI0MTRiMDU3YTcxNTFjNTNjNWZkNjI5NmEzYjllZGEwYWIifX19", "ro/ZKHt7278yhCr+CFTcPp/q6wAUlef//85k2DzkfRaZqy0CtGgwisDs2U4pVKvQ2pfXvitzWgbJvD0bLeQ12xWi4c1Fc29LCArosVJoFmrJDHz7N2MlstHT+ynQROb9d2aiFA6uOXfLjPKb1noUZ/YQoZjqcPIvD5oFZtD5DHV5O4hYz0IvgHbIjDqjz6ITsTcKiBlbxNg2loTFxSlW1ZfnNCO+kcAmeyB5NFY3j0e+/AqVANiNoiC3OKsECM/yEx/acf+vKWcT8mQn4wRoIGtxfEU7ZjNtgdh73NvXXBygW+K9AiJ242g8Y06Xxuk8kaNEGmT6H/mM7nbwjZmQQXpi/Pao2gYqyeIofeCPfr8RsGXoDX3nXDAw8/LyhTCHgx+sp6IQYSfGcSMJtoNeTJ0liIFxqn1V9/zKmzOZAPzR6qrQPOjoRFljLAlv7rfzotaEqh/1ldd40GdS8tstczn7f29OQerNDaqvbDb00Gy0STdUr1bVyCDptA54XKjT9WFv7QpBikEculxqSppAXPxD2Fb/ZmphbZx8WEGfG6bVFhf6fQdDAUXlcv8BxjElNPwlolF86M2KJd5VquLluhrCjwID7OK/pffNultAVH+Lxw4QOAXmJqjUrA1KHgyG1S0Cwj/f4E2hdxZJBvkfVtq9qPkd9nignhEoTCTOHf0=")};
- public static final Property[] LIGHT_GRAY = new Property[]{new Property("textures", "eyJ0aW1lc3RhbXAiOjE0NTU2MjU1OTM5NjIsInByb2ZpbGVJZCI6ImIzYjE4MzQ1MzViZjRiNzU4ZTBjZGJmMGY4MjA2NTZlIiwicHJvZmlsZU5hbWUiOiIxMDExMTEiLCJzaWduYXR1cmVSZXF1aXJlZCI6dHJ1ZSwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlLzc4Y2I3ZmMyMDhiMzM4NTUwNGE4MTQ0MjA0NDI4ZmRjZDYzMjRiZWIzMWNhMmNlODZjYzQyNGI5NjNkODVjIn19fQ==", "R/wZUZRC1dishRdM9a2SSxxW3oYa0XSb/MxHbQpEUA791HxyqjaKLDu0wFX2r2a8ZTeVjzXpNzkg3+PkrA11o8h7lt86MTD1pi/rQqj/WRuoqf2LP+ypbssKV+LU15cYez2cj3QQVcJDXgWEnfSLNuBv6NG8BDUpUAjTWldvu99NCJHUoD0jNMHxY/fu4k5vCgOjaBaKgkjVk2bmUhegusmtMwco+3pYx+y8+gUW8ptx5SnePG+dOwTqLyBFiOt2AQ+gSvbU/jP9aAXgxOwz/b1pMaBWtzVhFU865NHlIdSpIHg/sh3uNah3a7gTgtTvxPQv1OzM/KtqYKiamsrRzAQMzRcs4A7Tp0GakLuxEaz401IwvQ7UGVYLFzGUVLB2MyqtPgifiqQSQxZpiqj9sM5QadhsUw00nfX7mTdW46U0MtNIbby1rLrvgQKoj08zt6LJlhI3yjyawy4iZkgF4oc+PCNwZc93GIbVL9LJaGkXk3RVA+JpGwfMJrGVbL7hl8ibbAcUv7uCEWdkAgZCd6w75jEE4tlhDSPDD4rXbn+FeTZRg2n/PGKtnoTZRzbniiFaNoSAHDZSVRG39xvBDFvtmL3SPaKhzKaifiYrgNn453WtR3kymqdAtPf1GN9d1VltGZ/+vMPwqPJb6thcrlcU64UGHbg1olRkiyZHvY8=")};
-
- private final ServerInfo server;
- private final List- players;
-
- public TablistServer(ServerInfo server) {
- this(server, server.getPlayers().stream().sorted((p1, p2) -> p1.getName().compareToIgnoreCase(p2.getName())).map(TablistPart.Item::new).collect(Collectors.toList()));
- }
-
- public TablistServer(ServerInfo server, FightInfoPacket info) {
- this(server, new ArrayList<>());
-
- Collection
onlinePlayers = server.getPlayers();
- addPlayers(info.getBlueName().substring(0, 2), info.getBluePlayers(), onlinePlayers);
- addPlayers(info.getRedName().substring(0, 2), info.getRedPlayers(), onlinePlayers);
- addPlayers("§7", info.getSpectators(), onlinePlayers);
- }
-
- public TablistServer(ServerInfo server, List- players) {
- this.server = server;
- this.players = players;
- }
-
- @Override
- public String sortKey() {
- return server.getName();
- }
-
- @Override
- public void print(ChatSender viewer, ProxiedPlayer player, List
- tablist, List
- direct) {
- boolean onServer = player.getServer().getInfo() == server;
- List
- items = onServer ? direct : tablist;
-
- if(!onServer) {
- items.add(new Item(null, "", GRAY));
- items.add(new Item(null, "§7§l" + server.getName(), LIGHT_GRAY));
- }
-
- teamify(players, player).forEach(items::add);
- }
-
- private void addPlayers(String prefix, List
teamPlayers, Collection onlinePlayers){
- teamPlayers.stream().map(SteamwarUser::get).map(
- user -> onlinePlayers.stream().filter(player -> player.getUniqueId().equals(user.getUUID())).findAny()
- ).filter(Optional::isPresent).map(Optional::get).sorted(
- (p1, p2) -> p1.getName().compareToIgnoreCase(p2.getName())
- ).forEachOrdered(player -> players.add(new Item(player.getUniqueId(), prefix + player.getName(), Item.playerProperties(player))));
- }
-
- public static Stream- teamify(List
- players, ProxiedPlayer player) {
- int team = SteamwarUser.get(player.getUniqueId()).getTeam();
- if (team == 0) return players.stream();
- return players.stream().map(item -> {
- ProxiedPlayer p = BungeeCord.getInstance().getPlayer(item.getUuid());
- if (p == null) return item;
- Subserver subserver = Subserver.getSubserver(p.getServer().getInfo());
- if (subserver != null && subserver.getType() == Servertype.ARENA) return item;
- if (SteamwarUser.get(p.getUniqueId()).getTeam() != team) return item;
- return new Item(p, true);
- });
- }
-}
diff --git a/src/de/steamwar/bungeecore/util/Chat19.java b/src/de/steamwar/bungeecore/util/Chat19.java
deleted file mode 100644
index a543f74..0000000
--- a/src/de/steamwar/bungeecore/util/Chat19.java
+++ /dev/null
@@ -1,48 +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
.
- */
-
-package de.steamwar.bungeecore.util;
-
-import net.md_5.bungee.ServerConnection;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-import net.md_5.bungee.protocol.ChatChain;
-import net.md_5.bungee.protocol.ProtocolConstants;
-import net.md_5.bungee.protocol.SeenMessages;
-import net.md_5.bungee.protocol.packet.ClientChat;
-import net.md_5.bungee.protocol.packet.ClientCommand;
-
-import java.util.BitSet;
-import java.util.Collections;
-
-public class Chat19 {
- private Chat19(){}
-
- public static void chat(ProxiedPlayer p, String message) {
- int version = p.getPendingConnection().getVersion();
- if(version >= ProtocolConstants.MINECRAFT_1_19) {
- if(message.startsWith("/")) {
- ((ServerConnection) p.getServer()).getCh().write(new ClientCommand(message.substring(1), System.currentTimeMillis(), 0, Collections.emptyMap(), false, new ChatChain(Collections.emptyList(), null), new SeenMessages(0, new BitSet(0))));
- } else {
- ((ServerConnection) p.getServer()).getCh().write(new ClientChat(message, System.currentTimeMillis(), 0, version < ProtocolConstants.MINECRAFT_1_19_3 ? new byte[0] : null, false, new ChatChain(Collections.emptyList(), null), new SeenMessages(0, new BitSet(0))));
- }
- } else {
- p.chat(message);
- }
- }
-}
\ No newline at end of file
diff --git a/src/de/steamwar/command/CommandRegistering.java b/src/de/steamwar/command/CommandRegistering.java
deleted file mode 100644
index b6a4994..0000000
--- a/src/de/steamwar/command/CommandRegistering.java
+++ /dev/null
@@ -1,37 +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 .
- */
-
-package de.steamwar.command;
-
-import de.steamwar.bungeecore.BungeeCore;
-import lombok.experimental.UtilityClass;
-import net.md_5.bungee.api.ProxyServer;
-import net.md_5.bungee.api.plugin.Command;
-
-@UtilityClass
-class CommandRegistering {
-
- static void unregister(Command command) {
- ProxyServer.getInstance().getPluginManager().unregisterCommand(command);
- }
-
- static void register(Command command) {
- ProxyServer.getInstance().getPluginManager().registerCommand(BungeeCore.get(), command);
- }
-}
diff --git a/src/de/steamwar/command/SWCommand.java b/src/de/steamwar/command/SWCommand.java
index 83b4d8d..db9421b 100644
--- a/src/de/steamwar/command/SWCommand.java
+++ b/src/de/steamwar/command/SWCommand.java
@@ -19,96 +19,115 @@
package de.steamwar.command;
-import de.steamwar.bungeecore.BungeeCore;
-import de.steamwar.bungeecore.Message;
-import de.steamwar.messages.ChatSender;
-import net.md_5.bungee.BungeeCord;
-import net.md_5.bungee.api.CommandSender;
-import net.md_5.bungee.api.chat.ClickEvent;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-import net.md_5.bungee.api.plugin.Command;
-import net.md_5.bungee.api.plugin.TabExecutor;
+import com.velocitypowered.api.command.SimpleCommand;
+import de.steamwar.velocitycore.VelocityCore;
+import de.steamwar.velocitycore.discord.DiscordBot;
+import de.steamwar.messages.Chatter;
+import de.steamwar.messages.Message;
+import de.steamwar.sql.UserPerm;
+import lombok.Getter;
+import net.kyori.adventure.text.event.ClickEvent;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
-import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
import java.util.logging.Level;
-public class SWCommand extends AbstractSWCommand {
+public class SWCommand extends AbstractSWCommand {
static {
TypeUtils.init();
}
- private String permission;
- private Command command;
+ private final String name;
+ @Getter
+ private final UserPerm permission;
+ private final String[] aliases;
- private List defaultHelpMessages = new ArrayList<>();
+ private SimpleCommand command;
- protected SWCommand(String command) {
- this(command, null);
+ private final List defaultHelpMessages = new ArrayList<>();
+
+ protected SWCommand(String command, String... aliases) {
+ this(command, null, aliases);
}
- protected SWCommand(String command, String permission) {
- this(command, permission, new String[0]);
- }
-
- protected SWCommand(String command, String permission, String... aliases) {
- super(CommandSender.class, command, aliases);
+ protected SWCommand(String command, UserPerm permission, String... aliases) {
+ super(Chatter.class, command, aliases);
+ this.name = command;
this.permission = permission;
+ this.aliases = aliases;
create = true;
createAndSafeCommand(command, aliases);
unregister();
register();
}
+ public void execute(Chatter sender, String[] args) {
+ execute(sender, null, args);
+ }
+
private boolean create = false;
@Override
protected void createAndSafeCommand(String command, String[] aliases) {
if (!create) return;
- this.command = new TabCompletableCommand(command, permission, aliases) {
+ this.command = new SimpleCommand() {
+
@Override
- public void execute(CommandSender commandSender, String[] strings) {
- SWCommand.this.execute(commandSender, null, strings);
+ public void execute(Invocation invocation) {
+ SWCommand.this.execute(Chatter.of(invocation.source()), invocation.alias(), invocation.arguments());
}
@Override
- public Iterable onTabComplete(CommandSender commandSender, String[] strings) {
- return SWCommand.this.tabComplete(commandSender, null, strings);
+ public List suggest(Invocation invocation) {
+ if(invocation.arguments().length == 0)
+ return Collections.emptyList();
+
+ return SWCommand.this.tabComplete(Chatter.of(invocation.source()), invocation.alias(), invocation.arguments());
+ }
+
+ @Override
+ public boolean hasPermission(Invocation invocation) {
+ return permission == null || Chatter.of(invocation.source()).user().perms().contains(permission);
}
};
}
- private abstract static class TabCompletableCommand extends Command implements TabExecutor {
- public TabCompletableCommand(String name, String permission, String... aliases) {
- super(name, permission, aliases);
- }
- }
-
@Override
public void unregister() {
- if (command == null) return;
- CommandRegistering.unregister(this.command);
+ if (command == null)
+ return;
+
+ VelocityCore.getProxy().getCommandManager().unregister(name);
+ DiscordBot.getCommands().remove(name);
+ for(String alias : aliases)
+ DiscordBot.getCommands().remove(alias);
}
@Override
public void register() {
- if (command == null) return;
- CommandRegistering.register(this.command);
+ if (command == null)
+ return;
+
+ VelocityCore.getProxy().getCommandManager().register(VelocityCore.getProxy().getCommandManager().metaBuilder(name).aliases(aliases).plugin(VelocityCore.get()).build(), command);
+ DiscordBot.getCommands().put(name, this);
+ for(String alias : aliases)
+ DiscordBot.getCommands().put(alias, this);
}
@Override
- protected void commandSystemError(CommandSender sender, CommandFrameworkException e) {
- BungeeCore.get().getLogger().log(Level.SEVERE, e.getMessage(), e);
- ChatSender.of(sender).prefixless("COMMAND_SYSTEM_ERROR");
+ protected void commandSystemError(Chatter sender, CommandFrameworkException e) {
+ VelocityCore.getLogger().log(Level.SEVERE, e.getMessage(), e);
+ sender.prefixless("COMMAND_SYSTEM_ERROR");
}
@Override
protected void commandSystemWarning(Supplier message) {
- BungeeCore.get().getLogger().log(Level.WARNING, message);
+ VelocityCore.getLogger().log(Level.WARNING, message);
}
public void addDefaultHelpMessage(String message) {
@@ -116,24 +135,23 @@ public class SWCommand extends AbstractSWCommand {
}
@Override
- protected void sendMessage(CommandSender sender, String message, Object[] args) {
- ChatSender.of(sender).system(message, args);
+ protected void sendMessage(Chatter sender, String message, Object[] args) {
+ sender.system(message, args);
}
@Register(noTabComplete = true)
- public void internalHelp(ProxiedPlayer p, String... args) {
- ChatSender chatSender = ChatSender.of(p);
+ public void internalHelp(Chatter sender, String... args) {
try {
- chatSender.prefixless("COMMAND_HELP_HEAD", command.getName());
- defaultHelpMessages.forEach(chatSender::prefixless);
+ sender.prefixless("COMMAND_HELP_HEAD", name);
+ defaultHelpMessages.forEach(sender::prefixless);
} catch (Exception e) {
- BungeeCore.get().getLogger().log(Level.WARNING, "Failed to send help message", e);
+ VelocityCore.getLogger().log(Level.WARNING, "Failed to send help message", e);
return;
}
AtomicInteger atomicInteger = new AtomicInteger();
if (args.length != 0) {
commandList.forEach(subCommand -> {
- List tabCompletes = subCommand.tabComplete(p, args);
+ List tabCompletes = subCommand.tabComplete(sender, args);
if (tabCompletes == null || tabCompletes.isEmpty()) {
atomicInteger.incrementAndGet();
return;
@@ -141,7 +159,7 @@ public class SWCommand extends AbstractSWCommand {
boolean hasTabCompletes = tabCompletes.stream()
.anyMatch(s -> s.toLowerCase().startsWith(args[args.length - 1].toLowerCase()));
if (hasTabCompletes) {
- send(chatSender, subCommand);
+ send(sender, subCommand);
} else {
atomicInteger.incrementAndGet();
}
@@ -149,22 +167,21 @@ public class SWCommand extends AbstractSWCommand {
}
if (args.length == 0 || atomicInteger.get() == commandList.size()) {
commandList.forEach(subCommand -> {
- if (subCommand.validator == null || subCommand.validator.validate(p, p, (s, args1) -> {})) {
- send(chatSender, subCommand);
+ if (subCommand.validator == null || subCommand.validator.validate(sender, sender, (s, args1) -> {})) {
+ send(sender, subCommand);
}
});
}
}
- private void send(ChatSender chatSender, SubCommand subCommand) {
+ private void send(Chatter chatter, SubCommand subCommand) {
try {
for (String s : subCommand.description) {
- String hover = "§8/§e" + command.getName() + " " + String.join(" ", subCommand.subCommand);
- String suggest = "/" + command.getName() + " " + String.join(" ", subCommand.subCommand);
- chatSender.prefixless(s, new Message("PLAIN_STRING", hover), new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, suggest));
+ String hover = "§8/§e" + name + " " + String.join(" ", subCommand.subCommand);
+ chatter.prefixless(s, new Message("PLAIN_STRING", hover), ClickEvent.suggestCommand("/" + name + " " + String.join(" ", subCommand.subCommand)));
}
} catch (Exception e) {
- BungeeCore.get().getLogger().log(Level.WARNING, "Failed to send description of registered method '" + subCommand.method + "' with description '" + subCommand.description + "'", e);
+ VelocityCore.getLogger().log(Level.WARNING, "Failed to send description of registered method '%s' with description '%s'".formatted(subCommand.method, Arrays.toString(subCommand.description)), e);
}
}
}
diff --git a/src/de/steamwar/command/TypeMapper.java b/src/de/steamwar/command/TypeMapper.java
index 1d9cb72..5b59226 100644
--- a/src/de/steamwar/command/TypeMapper.java
+++ b/src/de/steamwar/command/TypeMapper.java
@@ -19,11 +19,11 @@
package de.steamwar.command;
-import net.md_5.bungee.api.CommandSender;
+import de.steamwar.messages.Chatter;
-public interface TypeMapper extends AbstractTypeMapper {
+public interface TypeMapper extends AbstractTypeMapper {
/**
* The CommandSender can be null!
*/
- T map(CommandSender commandSender, String[] previousArguments, String s);
+ T map(Chatter sender, PreviousArguments previousArguments, String s);
}
diff --git a/src/de/steamwar/command/TypeUtils.java b/src/de/steamwar/command/TypeUtils.java
index b83cb96..a273cda 100644
--- a/src/de/steamwar/command/TypeUtils.java
+++ b/src/de/steamwar/command/TypeUtils.java
@@ -19,20 +19,56 @@
package de.steamwar.command;
-import de.steamwar.bungeecore.commands.TypeMappers;
+import com.velocitypowered.api.network.ProtocolVersion;
+import com.velocitypowered.api.proxy.Player;
+import de.steamwar.velocitycore.ServerVersion;
+import de.steamwar.velocitycore.VelocityCore;
+import de.steamwar.velocitycore.commands.TypeMappers;
+import de.steamwar.messages.Chatter;
import de.steamwar.sql.SteamwarUser;
+import de.steamwar.sql.Team;
import lombok.experimental.UtilityClass;
-import net.md_5.bungee.BungeeCord;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
+import java.util.Collection;
+import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
@UtilityClass
public class TypeUtils {
static void init() {
- SWCommandUtils.addMapper(ProxiedPlayer.class, SWCommandUtils.createMapper(BungeeCord.getInstance()::getPlayer, (s) -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList())));
- SWCommandUtils.addMapper(SteamwarUser.class, SWCommandUtils.createMapper(SteamwarUser::get, s -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList())));
+ SWCommandUtils.addMapper(Player.class, SWCommandUtils.createMapper(s -> VelocityCore.getProxy().getPlayer(s).orElse(null), s -> VelocityCore.getProxy().getAllPlayers().stream().map(Player::getUsername).collect(Collectors.toList())));
+ SWCommandUtils.addMapper(SteamwarUser.class, SWCommandUtils.createMapper(SteamwarUser::get, s -> VelocityCore.getProxy().getAllPlayers().stream().map(Player::getUsername).collect(Collectors.toList())));
+ SWCommandUtils.addMapper(ServerVersion.class, new TypeMapper<>() {
+ @Override
+ public ServerVersion map(Chatter sender, PreviousArguments previousArguments, String s) {
+ Player player = sender.getPlayer();
+ if (player != null && s.isEmpty()) {
+ ProtocolVersion version = player.getProtocolVersion();
+ if (version.greaterThan(ProtocolVersion.MINECRAFT_1_19_4)) {
+ return ServerVersion.PAPER_20;
+ } else if (version.greaterThan(ProtocolVersion.MINECRAFT_1_15_2)) {
+ return ServerVersion.PAPER_19;
+ } else if (version.greaterThan(ProtocolVersion.MINECRAFT_1_12_2)) {
+ return ServerVersion.SPIGOT_15;
+ } else {
+ return ServerVersion.SPIGOT_12;
+ }
+ }
+
+ return ServerVersion.get(s);
+ }
+
+ @Override
+ public Collection tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) {
+ return ServerVersion.chatVersions();
+ }
+ });
+
+ AbstractTypeMapper teamMapper = SWCommandUtils.createMapper(Team::get, s -> Team.getAll().stream().flatMap(team -> Stream.of(team.getTeamKuerzel(), team.getTeamName())).collect(Collectors.toList()));
+ TabCompletionCache.add(teamMapper, true, 10, TimeUnit.SECONDS);
+ SWCommandUtils.addMapper(Team.class, teamMapper);
TypeMappers.init();
}
diff --git a/src/de/steamwar/command/TypeValidator.java b/src/de/steamwar/command/TypeValidator.java
index 6bb76f6..2986b7d 100644
--- a/src/de/steamwar/command/TypeValidator.java
+++ b/src/de/steamwar/command/TypeValidator.java
@@ -19,7 +19,6 @@
package de.steamwar.command;
-import net.md_5.bungee.api.CommandSender;
+import de.steamwar.messages.Chatter;
-public interface TypeValidator extends AbstractValidator {
-}
+public interface TypeValidator extends AbstractValidator {}
diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties
index b847098..5983f53 100644
--- a/src/de/steamwar/messages/BungeeCore.properties
+++ b/src/de/steamwar/messages/BungeeCore.properties
@@ -9,6 +9,7 @@ PLAIN_STRING={0}
UNKNOWN_COMMAND=§cUnknown command.
UNKNOWN_PLAYER=§cUnknown player.
UNKNOWN_TEAM=§cUnknown team.
+UNKNOWN_EVENT=$cUnknown event.
INVALID_TIME=§cInvalid time.
STEAMWAR_BRAND=§eSteam§8War.de §7({0}) §r<- §e{1} §7({2})§r
@@ -19,6 +20,7 @@ DEV_UNKNOWN_SERVER=§cPlease specify a dev server.
DISABLED=§cCurrently disabled.
SERVER_START_OVERLOAD=§cServer start cancelled due to overload. Please try again later.
+UPDATE_INTERRUPTION=§cPlease try again. A software update has interrupted this action.
#Help command
HELP_LOBBY=§7Return from anywhere to the lobby using §8/§el§7!
@@ -114,6 +116,7 @@ MOD_RED_SING=Attempted use of mod {0}
MOD_RED_PLUR=Attempted use of mods:\n{0}
MOD_YELLOW_SING=§7Deactivate the mod §e{0}§7 to continue playing on §eSteam§8War§7.
MOD_YELLOW_PLUR=§7Deactivate the mods\n§e{0}\n§7to continue playing on §eSteam§8War§7.
+MODS_CHECKED=§7Your Mods have been checked.\n§aYou can join §eSteam§8War §anow§8.
#Various commands
ALERT=§f{0}
@@ -253,7 +256,7 @@ EVENT_COMING=§eUpcoming events§8:
EVENT_COMING_EVENT=§7{0}§8-§7{1}§8: §e{2}
EVENT_COMING_DEADLINE=§7 Registration deadline§8: §7{0}
EVENT_COMING_SCHEM_DEADLINE=§7 Submission deadline§8: §7{0}
-EVENT_COMING_TEAMS=§7 With§8:{0}
+EVENT_COMING_TEAMS=§7 With§8: {0}
EVENT_COMING_TEAM= §{0}{1}
EVENT_CURRENT_EVENT=§e§l{0}
EVENT_CURRENT_FIGHT=§7{0} §{1}{2}§8 vs §{3}{4}
@@ -283,7 +286,7 @@ CHECK_HELP_DECLINE=§8/§7check decline §8[§ereason§8] - §7Decline schematic
CHECK_HELP_CANCEL=§8/§7check cancel §8- §7Cancels reviewing process
CHECK_LIST_HEADER=§e§l{0} schematics are left to review
CHECK_LIST_TO_CHECK={0} §8{1} §7{2} §e{3}
-CHECK_LIST_WAIT={0}:{1}
+CHECK_LIST_WAIT=§{0}{1}:{2}
CHECK_LIST_TO_CHECK_HOVER=§eCheck schematic
CHECK_LIST_CHECKING={0} §8{1} §7{2} §e{3} §7is being reviewed by §e{4}
CHECK_LIST_CHECKING_HOVER=§eTo the reviewer
@@ -322,6 +325,7 @@ KICK_USAGE=§8/§7kick §8[§ePlayer§8] [§eMessage§8]
KICK_OFFLINE=§cThis player is currently not online!
KICK_CONFIRM=The player {0} was kicked.
KICK_NORMAL=§cYou were kicked.
+KICK_CUSTOM=§c{0}
#MsgCommand
MSG_USAGE=§8/§7msg §8[§euser§8] [§emessage§8]
@@ -481,7 +485,7 @@ TEAM_LIST_UNKNOWN_PAGE=§cInvalid page entered
TEAM_LIST_HEADER=§7§lTeam list §7{0}§8/§7{1}
TEAM_LIST_TEAM=§{0}{1} §e{2}
TEAM_LIST_TEAM_HOVER=§7Team info
-TEAM_LIST_PAGE=Page
+TEAM_LIST_PAGE=Page »»
TEAM_LIST_NEXT=§eNext page
TEAM_LIST_PREV=§ePrevious page
@@ -493,7 +497,7 @@ TEAM_EVENT_NO_EVENT=§cThis event does not exist
TEAM_EVENT_OVER=§cThe registration period for this event is already over
TEAM_EVENT_LEFT=§7Your team no longer takes part in this event
TEAM_EVENT_JOINED=§7Your team now takes part in the event §e{0}§7!
-TEAM_EVENT_HOW_TO_LEAVE=§7To cancel the participation, repeat the command
+TEAM_EVENT_HOW_TO_LEAVE=§7To cancel the participation repeat the command.
#Team Color
TEAM_COLOR_TITLE=Choose color
@@ -568,8 +572,8 @@ EVENTMODE_KICK=§cYou are not an event participant.
POLL_HEADER=§e§lPoll
POLL_HEADER2=§7Click the answer you like!
POLL_QUESTION=§e{0}
-POLL_ANWSER=§7{0}
-POLL_ANWSER_HOVER=§eChoose {0}
+POLL_ANSWER=§7{0}
+POLL_ANSWER_HOVER=§eChoose {0}
#TablistManager
TABLIST_PHASE_WEBSITE=§8Website: https://§eSteam§8War.de
@@ -620,6 +624,7 @@ VERIFY_INVALID=§cInvalid Code
VERIFY_SUCCESS=§7Successfully linked to the Discord account §e{0}
#Discord
+DISCORD_TICKET_HOVER=§eTo the message
DISCORD_TICKET_MESSAGE=§7Ticket §e{0}§7» §f§l{1}: §7{2}
DISCORD_TICKET_NEW=§7Ticket §e{0}§7» §aTicket was created!
DISCORD_TICKET_CLOSED=§7Ticket §e{0}§7» §cTicket was closed!
@@ -690,9 +695,38 @@ MOD_COMMAND_INFO=§7The mod {0} on platform {1} is of the type {2}.
MOD_COMMAND_GUI_TITLE=Unclassified Mods
MOD_COMMAND_CLASSICIATION_GUI=Mod Type Changer
MOD_OPEN_GUI=§7Open Gui
+MOD_TITLE_FILTER=Filter
MOD_UNCLASSIFIED=§7Unclassified
MOD_ALLOWED=§aAllowed
MOD_FORBIDDEN=§eForbidden
MOD_AUTOBAN=§cAutoban
MOD_YT=§5YT Only
MOD_ITEM_BACK=§7Back
+
+#StreamInv
+INV_PAGE_BACK=§{0}Seite zurück
+INV_PAGE_NEXT=§{0}Seite vor
+
+#Discord
+DC_UNLINKED=For this action your Discord account has to be linked to your Minecraft account. To link your accounts go onto the SteamWar Discord to the `regeln-infos` Channel and click on `Minecraft Verknüpfen`.
+DC_TITLE_SCHEMINFO=Schematic Info
+DC_SCHEM_ACCEPT=Your schematic **{0}** has been accepted.
+DC_SCHEM_DECLINE=Your schematic **{0}** has been declined.\n**Reason:**{1}
+DC_AUTH_SUCCESS=:white_check_mark: You're Discord account has been linked with **{0}**.
+DC_ROLE_ADDED=:tada: You're getting {0} now.
+DC_ROLE_REMOVED=You're not getting {0} anymore.
+
+DC_TICKET_CREATED=You're Ticket {0} has been created.
+DC_TICKET_TITLE=SteamWar Ticket
+DC_TICKETINTRO_REPORT=Please answer for the punishment of the misconduct the following questions as accurately as possible and attach evidence whenever possible:\n - Which player(s)?\n - On which Server?\n - At what time?\n - Type and nature of the misconduct?
+DC_TICKETINTRO_IDEA=Describe your idea as detailed as possible. Hereto belongs: What, Why, How, Where?
+DC_TICKETINTRO_BUG=Please describe the observed unexpected or incorrect behaviour of our software. If necessary describe steps to reproduce the error.
+DC_TICKETINTRO_QUESTION=Please ask your question. A staff member will address the question soon.
+DC_TICKETINTRO_APPEAL=Asking creates wonders.
+DC_TICKET_CLOSE=Close
+
+DC_SCHEMUPLOAD_NOPERM=You're not allowed to upload schematics.
+DC_SCHEMUPLOAD_IGNORED=Skipping `{0}`, not a schematic file.
+DC_SCHEMUPLOAD_INVCHAR=`{0}` has invalid characters in its name.
+DC_SCHEMUPLOAD_SUCCESS=`{0}` was uploaded successfully.
+DC_SCHEMUPLOAD_ERROR=An error has occured during the upload of `{0}`. For more information ask a Developer.
diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties
index 979a5a3..8d4ddca 100644
--- a/src/de/steamwar/messages/BungeeCore_de.properties
+++ b/src/de/steamwar/messages/BungeeCore_de.properties
@@ -7,6 +7,7 @@ TIMEFORMAT=dd.MM.yyyy HH:mm
UNKNOWN_COMMAND=§cUnbekannter Befehl.
UNKNOWN_PLAYER=§cDiesen Spieler gibt es nicht.
UNKNOWN_TEAM=§cDieses Team gibt es nicht.
+UNKNOWN_EVENT=$cDieses Event gibt es nicht.
INVALID_TIME=§cUngültige Zeitangabe.
DEV_NO_SERVER=§cDer Server ist derzeit nicht erreichbar.
@@ -15,6 +16,7 @@ DEV_UNKNOWN_SERVER=§cBitte gib einen DevServer an.
DISABLED=§cDerzeit deaktiviert.
SERVER_START_OVERLOAD=§cDer Serverstart wurde aufgrund von Überlastung abgebrochen. Versuche es später erneut.
+UPDATE_INTERRUPTION=§cBitte erneut versuchen. Ein Softwareupdate hat die Aktion unterbrochen.
#Help command
HELP_LOBBY=§7Kehre von überall mit §8/§el §7zur Lobby zurück!
@@ -99,6 +101,7 @@ MOD_RED_SING=Versuchte Benutzung des Mods {0}
MOD_RED_PLUR=Versuchte Benutzung der Mods:\n{0}
MOD_YELLOW_SING=§7Deaktiviere den Mod §e{0}§7, um weiter auf §eSteam§8War §7spielen zu können.
MOD_YELLOW_PLUR=§7Deaktiviere die Mods\n§e{0}\n§7um weiter auf §eSteam§8War §7spielen zu können.
+MODS_CHECKED=§7Deine installierten Mods wurden überprüft.\n§aDu kannst nun §eSteam§8War §abetreten§8.
#Various commands
STAT_SERVER=§7Server §e{0}§8: §7Startfähig §e{1} §7Serveranzahl §e{2}
@@ -236,7 +239,7 @@ EVENT_COMING=§eKommende Events§8:
EVENT_COMING_EVENT=§7{0}§8-§7{1}§8: §e{2}
EVENT_COMING_DEADLINE=§7 Anmeldeschluss§8: §7{0}
EVENT_COMING_SCHEM_DEADLINE=§7 Einsendeschluss§8: §7{0}
-EVENT_COMING_TEAMS=§7 Mit§8:{0}
+EVENT_COMING_TEAMS=§7 Mit§8: {0}
EVENT_COMING_TEAM= §{0}{1}
EVENT_CURRENT_EVENT=§e§l{0}
EVENT_CURRENT_FIGHT=§7{0} §{1}{2}§8 vs §{3}{4}
@@ -266,7 +269,6 @@ CHECK_HELP_DECLINE=§8/§7check decline §8[§eGrund§8] - §7Schematic ablehnen
CHECK_HELP_CANCEL=§8/§7check cancel §8- §7Bricht den Prüfvorgang ab
CHECK_LIST_HEADER=§e§lZu prüfen sind {0} Schematics
CHECK_LIST_TO_CHECK={0} §8{1} §7{2} §e{3}
-CHECK_LIST_WAIT={0}:{1}
CHECK_LIST_TO_CHECK_HOVER=§eSchematic prüfen
CHECK_LIST_CHECKING={0} §8{1} §7{2} §e{3} §7wird geprüft von §e{4}
CHECK_LIST_CHECKING_HOVER=§eZum Prüfer
@@ -458,7 +460,7 @@ TEAM_LIST_UNKNOWN_PAGE=§cUngültige Seitenzahl angegeben
TEAM_LIST_HEADER=§7§lTeamliste §7{0}§8/§7{1}
TEAM_LIST_TEAM=§{0}{1} §e{2}
TEAM_LIST_TEAM_HOVER=§7Teaminfo
-TEAM_LIST_PAGE=Seite
+TEAM_LIST_PAGE=Seite »»
TEAM_LIST_NEXT=§eNächste Seite
TEAM_LIST_PREV=§eVorherige Seite
@@ -470,7 +472,7 @@ TEAM_EVENT_NO_EVENT=§cDieses Event gibt es nicht
TEAM_EVENT_OVER=§cDie Anmeldephase für dieses Event ist bereits vorbei
TEAM_EVENT_LEFT=§7Dein Team nimmt nicht mehr am Event teil
TEAM_EVENT_JOINED=§7Dein Team nimmt nun am Event §e{0} §7 teil!
-TEAM_EVENT_HOW_TO_LEAVE=§7Um die Teilnahme abzusagen, wiederhole den Befehl
+TEAM_EVENT_HOW_TO_LEAVE=§7Um die Teilnahme abzusagen, wiederhole den Befehl.
#Team Color
TEAM_COLOR_TITLE=Farbe wählen
@@ -546,8 +548,8 @@ EVENTMODE_KICK=§cDu bist kein Eventteilnehmer.
POLL_HEADER=§e§lUmfrage
POLL_HEADER2=§7Klicke die Antwort an, die dir gefällt!
POLL_QUESTION=§e{0}
-POLL_ANWSER=§7{0}
-POLL_ANWSER_HOVER=§e{0} §ewählen
+POLL_ANSWER=§7{0}
+POLL_ANSWER_HOVER=§e{0} §ewählen
#TablistManager
TABLIST_PHASE_WEBSITE=§8Website: https://§eSteam§8War.de
@@ -597,6 +599,7 @@ VERIFY_INVALID=§cInvalider Code
VERIFY_SUCCESS=§7Erfolgreich mit dem Discord Account §e{0} §7verknüpft
#Discord
+DISCORD_TICKET_HOVER=§eZur Nachricht
DISCORD_TICKET_MESSAGE=§7Ticket §e{0}§7» §f§l{1}: §7{2}
DISCORD_TICKET_NEW=§7Ticket §e{0}§7» §aTicket wurde geöffnet!
DISCORD_TICKET_CLOSED=§7Ticket §e{0}§7» §cTicket wurde geschlossen!
@@ -651,4 +654,31 @@ ADVENT_CALENDAR_TITLE=§eAdventskalender
ADVENT_CALENDAR_DAY=§7Tag§8: §e{0}
ADVENT_CALENDAR_MESSAGE=§eHast du heute schon dein Geschenk geholt?
ADVENT_CALENDAR_MESSAGE_HOVER=§eKlicken zum öffnen!
-ADVENT_CALENDAR_OPEN=§7Du hast §e{0}§7 aus dem Adventskalender erhalten!
\ No newline at end of file
+ADVENT_CALENDAR_OPEN=§7Du hast §e{0}§7 aus dem Adventskalender erhalten!
+
+#StreamInv
+INV_PAGE_BACK=§{0}Page back
+INV_PAGE_NEXT=§{0}Next page
+
+#Discord
+DC_UNLINKED=Für diese Aktion muss dein Minecraftaccount mit deinem Discordaccount verknüpft sein, gehe dazu auf dem SteamWar-Discord in den `regeln-infos` Channel und Klicke auf `Minecraft Verknüpfen`.
+DC_TITLE_SCHEMINFO=Schematicinfo
+DC_SCHEM_ACCEPT=Deine Schematic **{0}** wurde angenommen.
+DC_SCHEM_DECLINE=Deine Schematic **{0}** wurde abgelehnt. **Grund:** \n{1}
+DC_AUTH_SUCCESS=:white_check_mark: Dein Discordaccount wurde mit **{0}** verknüpft.
+DC_ROLE_ADDED=:tada: Du bekommst nun {0}.
+DC_ROLE_REMOVED=Du bekommst nun keine {0} mehr.
+
+DC_TICKET_CREATED=Dein Ticket {0} wurde erstellt.
+DC_TICKETINTRO_REPORT=Bitte beantworte für die Ahndung des Fehlverhaltens möglichst genau folgende Fragen und füge nach Möglichkeit Beweismaterial hinzu:\n - Welche(r) Spieler?\n - Auf welchem Server?\n - Zu welchem Zeitpunkt?\n - Art und Natur des Fehlverhaltens?
+DC_TICKETINTRO_IDEA=Beschreibe deine Idee möglichst detailiert. Hierzu gehört: Was, Warum, Wie, Wo?
+DC_TICKETINTRO_BUG=Bitte beschreibe das beobachtete unerwartete bzw. inkorrekte Verhalten der Serversoftware. Falls notwendig, beschreibe die Schritte, mit denen der Fehler reproduziert werden kann.
+DC_TICKETINTRO_QUESTION=Bitte stelle deine Frage, ein Serverteammitglied wird sich dieser zeitnah annehmen.
+DC_TICKETINTRO_APPEAL=Fragen wirkt Wunder!
+DC_TICKET_CLOSE=Schließen
+
+DC_SCHEMUPLOAD_NOPERM=Du darfst keine Schematics hochladen.
+DC_SCHEMUPLOAD_IGNORED=`{0}` wird ignoriert, da die Datei keine Schematic ist.
+DC_SCHEMUPLOAD_INVCHAR=`{0}` hat unzulässige Buchstaben im Namen.
+DC_SCHEMUPLOAD_SUCCESS=`{0}` wurde erfolgreich hochgeladen.
+DC_SCHEMUPLOAD_ERROR=Ein Fehler ist beim Hochladen von `{0}` aufgetreten. Für nähere Informationen wende dich an einen Developer.
diff --git a/src/de/steamwar/messages/ChatSender.java b/src/de/steamwar/messages/ChatSender.java
deleted file mode 100644
index 99916a0..0000000
--- a/src/de/steamwar/messages/ChatSender.java
+++ /dev/null
@@ -1,300 +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 .
-*/
-
-package de.steamwar.messages;
-
-import de.steamwar.bungeecore.*;
-import de.steamwar.bungeecore.bot.listeners.DiscordChatListener;
-import de.steamwar.sql.SteamwarUser;
-import de.steamwar.sql.UserPerm;
-import net.md_5.bungee.api.ChatMessageType;
-import net.md_5.bungee.api.CommandSender;
-import net.md_5.bungee.api.ProxyServer;
-import net.md_5.bungee.api.chat.BaseComponent;
-import net.md_5.bungee.api.chat.ClickEvent;
-import net.md_5.bungee.api.chat.HoverEvent;
-import net.md_5.bungee.api.chat.TextComponent;
-import net.md_5.bungee.api.chat.hover.content.Text;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-import net.md_5.bungee.api.event.LoginEvent;
-import net.md_5.bungee.command.ConsoleCommandSender;
-
-import java.text.DateFormat;
-import java.text.MessageFormat;
-import java.util.Date;
-import java.util.Locale;
-import java.util.ResourceBundle;
-import java.util.function.BiConsumer;
-import java.util.logging.Level;
-import java.util.stream.Stream;
-
-public interface ChatSender {
-
- static Stream all() {
- return ProxyServer.getInstance().getPlayers().stream();
- }
-
- static Stream allReceivers() {
- return all().map(ChatSender::of);
- }
-
- static Stream globalReceivers() {
- return all().filter(player -> {
- Subserver subserver = Subserver.getSubserver(player);
- return subserver == null || !(subserver.getType() == Servertype.ARENA && subserver.getServer() == player.getServer().getInfo());
- }).map(ChatSender::of);
- }
-
- static Stream serverteamReceivers() {
- return allReceivers().filter(player -> player.user().hasPerm(UserPerm.TEAM));
- }
-
- SteamwarUser user();
-
- Locale getLocale();
- boolean chatShown();
- void sendMessage(ChatMessageType type, BaseComponent... msg);
-
- default void chat(Message message) {
- send(false, ChatMessageType.CHAT, null, null, message);
- }
-
- default void system(String format, Object... params) {
- system(new Message(format, params));
- }
-
- default void system(Message message) {
- send(true, ChatMessageType.SYSTEM, null, null, message);
- }
-
- default void system(String format, Message onHover, ClickEvent onClick, Object... params) {
- send(true, ChatMessageType.SYSTEM, onHover, onClick, new Message(format, params));
- }
-
- default void prefixless(String format, Object... params) {
- prefixless(format, null, null, params);
- }
-
- default void prefixless(String format, Message onHover, ClickEvent onClick, Object... params) {
- send(false, ChatMessageType.SYSTEM, onHover, onClick, new Message(format, params));
- }
-
- default void send(boolean prefixed, ChatMessageType type, Message onHover, ClickEvent onClick, Message message) {
- TextComponent msg = parseToComponent(prefixed, message);
- if(onHover != null)
- msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(parse(false, onHover))));
- if(onClick != null)
- msg.setClickEvent(onClick);
- sendMessage(type, msg);
- }
-
- default TextComponent parseToComponent(boolean prefixed, Message message) {
- return new TextComponent(parse(prefixed, message));
- }
-
- default String parseToPlain(String format, Object... params) {
- return parseToPlain(new Message(format, params));
- }
-
- default String parseToPlain(Message message) {
- return parseToComponent(false, message).toPlainText();
- }
-
- default String parseToLegacy(String format, Object... params) {
- return parseToLegacy(new Message(format, params));
- }
-
- default String parseToLegacy(Message message) {
- return parseToComponent(false, message).toLegacyText();
- }
-
- default BaseComponent[] parse(boolean prefixed, String format, Object... params) {
- return parse(prefixed, new Message(format, params));
- }
-
- default BaseComponent[] parse(boolean prefixed, Message message) {
- Locale locale = getLocale();
- ResourceBundle resourceBundle = SteamwarResourceBundle.getResourceBundle(locale);
- String pattern = "";
- if(prefixed)
- pattern = resourceBundle.getObject("PREFIX") + " ";
- pattern += (String)resourceBundle.getObject(message.getFormat());
-
- MessageFormat format = new MessageFormat(pattern, locale);
- Object[] params = message.getParams();
- for (int i = 0; i < params.length; i++) {
- if(params[i] instanceof Message) {
- params[i] = parseToLegacy((Message) params[i]);
- } else if(params[i] instanceof Date) {
- params[i] = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale).format((Date) params[i]);
- } else if(params[i] instanceof SteamwarUser) {
- params[i] = ((SteamwarUser) params[i]).getUserName();
- } else if(params[i] instanceof ProxiedPlayer) {
- params[i] = ((ProxiedPlayer) params[i]).getName();
- } else if(params[i] instanceof ChatSender) {
- params[i] = ((ChatSender) params[i]).user().getUserName();
- }
- }
- return TextComponent.fromLegacyText(format.format(params));
- }
-
- static ChatSender ofProxiedPlayer(ProxiedPlayer player, BiConsumer sendMessage) {
- return new ChatSender() {
- @Override
- public SteamwarUser user() {
- return SteamwarUser.get(player.getUniqueId());
- }
-
- @Override
- public Locale getLocale() {
- return user().getLocale();
- }
-
- @Override
- public boolean chatShown() {
- return player.getChatMode() == ProxiedPlayer.ChatMode.SHOWN;
- }
-
- @Override
- public void sendMessage(ChatMessageType type, BaseComponent... msg) {
- sendMessage.accept(type, msg);
- }
- };
- }
-
- static ChatSender of(ProxiedPlayer player) {
- return ofProxiedPlayer(player, player::sendMessage);
- }
-
- static ChatSender disconnect(ProxiedPlayer player) {
- return ofProxiedPlayer(player, (type, msg) -> player.disconnect(msg));
- }
-
- static ChatSender of(CommandSender sender) {
- if(sender instanceof ProxiedPlayer)
- return of((ProxiedPlayer) sender);
-
- //Console
- return new ChatSender() {
- @Override
- public SteamwarUser user() {
- return SteamwarUser.get(-1);
- }
-
- @Override
- public Locale getLocale() {
- return Locale.getDefault();
- }
-
- @Override
- public boolean chatShown() {
- return true;
- }
-
- @Override
- public void sendMessage(ChatMessageType type, BaseComponent... msg) {
- sender.sendMessage(msg);
- }
- };
- }
-
- static ChatSender console() {
- return of(ConsoleCommandSender.getInstance());
- }
-
- static ChatSender of(LoginEvent event) {
- return new ChatSender() {
- @Override
- public SteamwarUser user() {
- return SteamwarUser.get(event.getConnection().getUniqueId());
- }
-
- @Override
- public Locale getLocale() {
- return Locale.getDefault();
- }
-
- @Override
- public boolean chatShown() {
- return false;
- }
-
- @Override
- public void sendMessage(ChatMessageType type, BaseComponent... msg) {
- event.setCancelReason(msg);
- }
- };
- }
-
- static ChatSender discordChannel(DiscordChatListener channel) {
- return new ChatSender() {
- @Override
- public SteamwarUser user() {
- return SteamwarUser.get(-1);
- }
-
- @Override
- public Locale getLocale() {
- return Locale.getDefault();
- }
-
- @Override
- public boolean chatShown() {
- return true;
- }
-
- @Override
- public void sendMessage(ChatMessageType type, BaseComponent... msg) {
- try {
- channel.send(" " + new TextComponent(msg).toPlainText());
- } catch (Exception e) {
- BungeeCore.get().getLogger().log(Level.SEVERE, "Could not send chat message to discord", e);
- }
- }
- };
- }
-
- static ChatSender of(net.dv8tion.jda.api.entities.Message message, SteamwarUser user) {
- return new ChatSender() {
- @Override
- public SteamwarUser user() {
- return user;
- }
-
- @Override
- public Locale getLocale() {
- return Locale.getDefault();
- }
-
- @Override
- public boolean chatShown() {
- return true;
- }
-
- @Override
- public void sendMessage(ChatMessageType type, BaseComponent... msg) {
- try {
- message.delete().queue();
- } catch (Exception e) {
- BungeeCore.get().getLogger().log(Level.SEVERE, "Could not send chat reply to discord user", e);
- }
- }
- };
- }
-}
diff --git a/src/de/steamwar/messages/Chatter.java b/src/de/steamwar/messages/Chatter.java
new file mode 100644
index 0000000..d61a20d
--- /dev/null
+++ b/src/de/steamwar/messages/Chatter.java
@@ -0,0 +1,275 @@
+/*
+ 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 .
+*/
+
+package de.steamwar.messages;
+
+import com.velocitypowered.api.command.CommandSource;
+import com.velocitypowered.api.event.ResultedEvent;
+import com.velocitypowered.api.event.connection.LoginEvent;
+import com.velocitypowered.api.proxy.Player;
+import de.steamwar.persistent.Servertype;
+import de.steamwar.persistent.Subserver;
+import de.steamwar.velocitycore.VelocityCore;
+import de.steamwar.sql.SteamwarUser;
+import de.steamwar.sql.UserPerm;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.event.ClickEvent;
+import net.kyori.adventure.text.event.HoverEvent;
+import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
+import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
+
+import java.text.DateFormat;
+import java.text.MessageFormat;
+import java.util.Date;
+import java.util.Locale;
+import java.util.ResourceBundle;
+import java.util.UUID;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.Supplier;
+import java.util.stream.Stream;
+
+public interface Chatter {
+
+ static Stream allPlayers() {
+ return VelocityCore.getProxy().getAllPlayers().stream();
+ }
+
+ static Stream allStream() {
+ return Stream.concat(Stream.of(Chatter.console()), allPlayers().map(Chatter::of));
+ }
+
+ static ChatterGroup broadcast() {
+ return new ChatterGroup(allStream());
+ }
+
+ static ChatterGroup globalChat() {
+ return new ChatterGroup(Stream.concat(Stream.of(Chatter.console()), allPlayers().filter(player -> {
+ Subserver subserver = Subserver.getSubserver(player);
+ return subserver == null || !(subserver.getType() == Servertype.ARENA && subserver.getServer() == player.getCurrentServer().get().getServerInfo());
+ }).map(Chatter::of)));
+ }
+
+ static ChatterGroup serverteam() {
+ return new ChatterGroup(allStream().filter(player -> player.user().hasPerm(UserPerm.TEAM)));
+ }
+
+ SteamwarUser user();
+
+ Locale getLocale();
+ boolean chatShown();
+ void sendMessage(Component msg);
+ Player getPlayer();
+
+ default T withPlayerOrOffline(Function withPlayer, Supplier withOffline) {
+ Player player = getPlayer();
+ if(player == null)
+ return withOffline.get();
+ else
+ return withPlayer.apply(player);
+ }
+ default void withPlayerOrOffline(Consumer withPlayer, Runnable withOffline) {
+ Player player = getPlayer();
+ if(player == null)
+ withOffline.run();
+ else
+ withPlayer.accept(player);
+ }
+ default void withPlayer(Consumer function) {
+ withPlayerOrOffline(function, () -> {});
+ }
+
+ default void system(String format, Object... params) {
+ system(new Message(format, params));
+ }
+
+ default void system(Message message) {
+ send(true, null, null, message);
+ }
+
+ default void system(String format, Message onHover, ClickEvent onClick, Object... params) {
+ send(true, onHover, onClick, new Message(format, params));
+ }
+
+ default void prefixless(String format, Object... params) {
+ prefixless(format, null, null, params);
+ }
+
+ default void prefixless(String format, Message onHover, ClickEvent onClick, Object... params) {
+ send(false, onHover, onClick, new Message(format, params));
+ }
+
+ default void send(boolean prefixed, Message onHover, ClickEvent onClick, Message message) {
+ Component msg = parse(prefixed, message);
+ if(onHover != null)
+ msg = msg.hoverEvent(HoverEvent.showText(parse(false, onHover)));
+ if(onClick != null)
+ msg = msg.clickEvent(onClick);
+ sendMessage(msg);
+ }
+
+ default String parseToPlain(String format, Object... params) {
+ return parseToPlain(new Message(format, params));
+ }
+
+ default String parseToPlain(Message message) {
+ return PlainTextComponentSerializer.plainText().serialize(parse(message));
+ }
+
+ default String parseToLegacy(String format, Object... params) {
+ return parseToLegacy(new Message(format, params));
+ }
+
+ default String parseToLegacy(Message message) {
+ return LegacyComponentSerializer.legacySection().serialize(parse(message));
+ }
+
+ default Component parse(String format, Object... params) {
+ return parse(false, new Message(format, params));
+ }
+
+ default Component parse(Message message) {
+ return parse(false, message);
+ }
+
+ default Component parse(boolean prefixed, String format, Object... params) {
+ return parse(prefixed, new Message(format, params));
+ }
+
+ default Component parse(boolean prefixed, Message message) {
+ Locale locale = getLocale();
+ ResourceBundle resourceBundle = SteamwarResourceBundle.getResourceBundle(locale);
+ String pattern = "";
+ if(prefixed)
+ pattern = resourceBundle.getObject("PREFIX") + " ";
+ pattern += (String)resourceBundle.getObject(message.format());
+
+ MessageFormat format = new MessageFormat(pattern, locale);
+ Object[] params = message.params();
+ for (int i = 0; i < params.length; i++) {
+ if(params[i] instanceof Message msg) {
+ params[i] = parseToLegacy(msg);
+ } else if(params[i] instanceof Date date) {
+ params[i] = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale).format(date);
+ } else if(params[i] instanceof SteamwarUser user) {
+ params[i] = user.getUserName();
+ } else if(params[i] instanceof Player player) {
+ params[i] = player.getUsername();
+ } else if(params[i] instanceof Chatter chatter) {
+ params[i] = chatter.user().getUserName();
+ } else if(params[i] instanceof Function func) {
+ params[i] = func.apply(this);
+ }
+ }
+ return LegacyComponentSerializer.legacySection().deserialize(format.format(params));
+ }
+
+ static PlayerChatter of(Player player) {
+ return new PlayerChatter(player, player::sendMessage);
+ }
+
+ static PlayerChatter disconnect(Player player) {
+ return new PlayerChatter(player, player::disconnect);
+ }
+
+ static Chatter of(CommandSource sender) {
+ if(sender instanceof Player player)
+ return of(player);
+
+ //Console
+ return new PlayerlessChatter() {
+ @Override
+ public SteamwarUser user() {
+ return SteamwarUser.get(-1);
+ }
+
+ @Override
+ public boolean chatShown() {
+ return true;
+ }
+
+ @Override
+ public void sendMessage(Component msg) {
+ sender.sendMessage(msg);
+ }
+ };
+ }
+
+ static Chatter of(SteamwarUser user) {
+ return of(user.getUUID());
+ }
+
+ static Chatter of(UUID uuid) {
+ Player player = VelocityCore.getProxy().getPlayer(uuid).orElse(null);
+ if(player != null)
+ return Chatter.of(player);
+
+ return new PlayerlessChatter() {
+ @Override
+ public SteamwarUser user() {
+ return SteamwarUser.get(uuid);
+ }
+
+ @Override
+ public boolean chatShown() {
+ return false;
+ }
+
+ @Override
+ public void sendMessage(Component msg) {
+ // Nowhere to send
+ }
+ };
+ }
+
+ static Chatter console() {
+ return of(VelocityCore.getProxy().getConsoleCommandSource());
+ }
+
+ static Chatter of(LoginEvent event) {
+ return new PlayerlessChatter() {
+ @Override
+ public SteamwarUser user() {
+ return SteamwarUser.get(event.getPlayer().getUniqueId());
+ }
+
+ @Override
+ public boolean chatShown() {
+ return false;
+ }
+
+ @Override
+ public void sendMessage(Component msg) {
+ event.setResult(ResultedEvent.ComponentResult.denied(msg));
+ }
+ };
+ }
+
+ abstract class PlayerlessChatter implements Chatter {
+ @Override
+ public Locale getLocale() {
+ return user().getLocale();
+ }
+
+ @Override
+ public Player getPlayer() {
+ return VelocityCore.getProxy().getPlayer(user().getUUID()).orElse(null);
+ }
+ }
+}
diff --git a/src/de/steamwar/messages/ChatterGroup.java b/src/de/steamwar/messages/ChatterGroup.java
new file mode 100644
index 0000000..c94975d
--- /dev/null
+++ b/src/de/steamwar/messages/ChatterGroup.java
@@ -0,0 +1,63 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2024 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 .
+ */
+
+package de.steamwar.messages;
+
+import de.steamwar.sql.SteamwarUser;
+import lombok.Getter;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.event.ClickEvent;
+
+import java.util.Arrays;
+import java.util.stream.Stream;
+
+@Getter
+public class ChatterGroup extends Chatter.PlayerlessChatter {
+
+ final Chatter[] chatters;
+
+ public ChatterGroup(Stream stream) {
+ chatters = stream.toArray(Chatter[]::new);
+ }
+
+ public ChatterGroup(Chatter... chatters) {
+ this.chatters = chatters;
+ }
+
+ @Override
+ public boolean chatShown() {
+ return Arrays.stream(chatters).allMatch(Chatter::chatShown);
+ }
+
+ @Override
+ public void send(boolean prefixed, Message onHover, ClickEvent onClick, Message message) {
+ for(Chatter sender : chatters)
+ sender.send(prefixed, onHover, onClick, message);
+ }
+
+ @Override
+ public SteamwarUser user() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void sendMessage(Component msg) {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/src/de/steamwar/messages/Message.java b/src/de/steamwar/messages/Message.java
new file mode 100644
index 0000000..3394c27
--- /dev/null
+++ b/src/de/steamwar/messages/Message.java
@@ -0,0 +1,22 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2024 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 .
+ */
+
+package de.steamwar.messages;
+
+public record Message(String format, Object... params) { }
\ No newline at end of file
diff --git a/src/de/steamwar/messages/PlayerChatter.java b/src/de/steamwar/messages/PlayerChatter.java
new file mode 100644
index 0000000..6febd74
--- /dev/null
+++ b/src/de/steamwar/messages/PlayerChatter.java
@@ -0,0 +1,64 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2024 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 .
+ */
+
+package de.steamwar.messages;
+
+import com.velocitypowered.api.proxy.Player;
+import com.velocitypowered.api.proxy.player.PlayerSettings;
+import de.steamwar.sql.SteamwarUser;
+import lombok.AllArgsConstructor;
+import net.kyori.adventure.text.Component;
+
+import java.util.Locale;
+import java.util.function.Consumer;
+
+@AllArgsConstructor
+public class PlayerChatter implements Chatter {
+
+ private final Player player;
+ private final Consumer sendMessage;
+
+ @Override
+ public SteamwarUser user() {
+ return SteamwarUser.get(player.getUniqueId());
+ }
+
+ @Override
+ public Locale getLocale() {
+ return user().getLocale();
+ }
+
+ @Override
+ public boolean chatShown() {
+ if(!player.hasSentPlayerSettings())
+ return false;
+
+ return player.getPlayerSettings().getChatMode() == PlayerSettings.ChatMode.SHOWN;
+ }
+
+ @Override
+ public void sendMessage(Component msg) {
+ sendMessage.accept(msg);
+ }
+
+ @Override
+ public Player getPlayer() {
+ return player;
+ }
+}
diff --git a/src/de/steamwar/messages/SteamwarResourceBundle.java b/src/de/steamwar/messages/SteamwarResourceBundle.java
index 2252609..ffb236f 100644
--- a/src/de/steamwar/messages/SteamwarResourceBundle.java
+++ b/src/de/steamwar/messages/SteamwarResourceBundle.java
@@ -19,8 +19,6 @@
package de.steamwar.messages;
-import de.steamwar.bungeecore.Message;
-
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
diff --git a/src/de/steamwar/sql/SQLConfigImpl.java b/src/de/steamwar/sql/SQLConfigImpl.java
index d1e1701..199afe9 100644
--- a/src/de/steamwar/sql/SQLConfigImpl.java
+++ b/src/de/steamwar/sql/SQLConfigImpl.java
@@ -19,7 +19,7 @@
package de.steamwar.sql;
-import de.steamwar.bungeecore.BungeeCore;
+import de.steamwar.velocitycore.VelocityCore;
import de.steamwar.sql.internal.SQLConfig;
import java.util.logging.Logger;
@@ -27,7 +27,7 @@ import java.util.logging.Logger;
public class SQLConfigImpl implements SQLConfig {
@Override
public Logger getLogger() {
- return BungeeCore.get().getLogger();
+ return VelocityCore.getLogger();
}
@Override
diff --git a/src/de/steamwar/sql/SQLWrapperImpl.java b/src/de/steamwar/sql/SQLWrapperImpl.java
index 42677c5..1ac26bd 100644
--- a/src/de/steamwar/sql/SQLWrapperImpl.java
+++ b/src/de/steamwar/sql/SQLWrapperImpl.java
@@ -19,27 +19,19 @@
package de.steamwar.sql;
-import de.steamwar.bungeecore.BungeeCore;
-import de.steamwar.bungeecore.commands.CheckCommand;
-import net.md_5.bungee.api.ProxyServer;
-import net.md_5.bungee.api.config.ServerInfo;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-import net.md_5.bungee.config.Configuration;
-import net.md_5.bungee.config.ConfigurationProvider;
-import net.md_5.bungee.config.YamlConfiguration;
+import com.velocitypowered.api.proxy.Player;
+import com.velocitypowered.api.proxy.server.RegisteredServer;
+import de.steamwar.velocitycore.GameModeConfig;
+import de.steamwar.velocitycore.VelocityCore;
+import de.steamwar.velocitycore.commands.CheckCommand;
-import java.io.File;
-import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
-import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
-import java.util.stream.Collectors;
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)
@@ -54,52 +46,36 @@ public class SQLWrapperImpl implements SQLWrapper {
@Override
public void loadSchemTypes(List tmpTypes, Map tmpFromDB) {
- File folder = new File(BungeeCore.get().getDataFolder().getParentFile(), "FightSystem");
- if(folder.exists()) {
- for(File configFile : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().collect(Collectors.toList())) {
- Configuration config;
- try {
- config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
- } catch (IOException e) {
- throw new SecurityException("Could not load SchematicTypes", e);
- }
+ GameModeConfig.loadAll(GameModeConfig.class, (file, config) -> {
+ if(config.getSchematic() == null || tmpFromDB.containsKey(config.getSchemType().toLowerCase()))
+ return;
- if(!config.contains("Schematic"))
- continue;
+ String shortcut = config.getSchematic().getShortcut();
+ String material = config.getSchematic().getMaterial();
- String type = config.getString("Schematic.Type");
- assert type != null;
- String shortcut = config.getString("Schematic.Shortcut");
- if(tmpFromDB.containsKey(type.toLowerCase()))
- continue;
-
- SchematicType checktype = null;
- String material = config.getString("Schematic.Material");
-
- if(!config.getStringList("CheckQuestions").isEmpty()) {
- checktype = new SchematicType("C" + type, "C" + shortcut, SchematicType.Type.CHECK_TYPE, null, material, true);
- tmpTypes.add(checktype);
- tmpFromDB.put(checktype.toDB(), checktype);
- CheckCommand.setCheckQuestions(checktype, config);
- }
- boolean manualCheck = config.getBoolean("Schematic.ManualCheck", true);
-
- SchematicType current = new SchematicType(type, shortcut, !config.contains("Server") ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material, parseDeadline(config.getString("deadline", null)), manualCheck);
- tmpTypes.add(current);
- tmpFromDB.put(type.toLowerCase(), current);
- if(checktype != null)
- CheckCommand.addFightType(checktype, current);
+ SchematicType checktype = null;
+ if(!config.getCheckQuestions().isEmpty()) {
+ checktype = new SchematicType("C" + config.getSchemType(), "C" + shortcut, SchematicType.Type.CHECK_TYPE, null, material, true);
+ tmpTypes.add(checktype);
+ tmpFromDB.put(checktype.toDB(), checktype);
+ CheckCommand.setCheckQuestions(checktype, config.getCheckQuestions());
}
- }
+
+ SchematicType current = new SchematicType(config.getSchemType(), shortcut, config.getServer() != null ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material, parseDeadline(config.getDeadline()), config.getSchematic().isManualCheck());
+ tmpTypes.add(current);
+ tmpFromDB.put(config.getSchemType().toLowerCase(), current);
+ if(checktype != null)
+ CheckCommand.addFightType(checktype, current);
+ });
}
@Override
public void additionalExceptionMetadata(StringBuilder builder) {
builder.append("\nServers: ");
- for(Map.Entry server : ProxyServer.getInstance().getServers().entrySet()) {
- builder.append(server.getKey()).append("(");
- for(ProxiedPlayer player : server.getValue().getPlayers()) {
- builder.append(player.getName()).append(" ");
+ for(RegisteredServer server : VelocityCore.getProxy().getAllServers()) {
+ builder.append(server.getServerInfo().getName()).append("(");
+ for(Player player : server.getPlayersConnected()) {
+ builder.append(player.getUsername()).append(" ");
}
builder.append(") ");
}
diff --git a/src/de/steamwar/velocitycore/ArenaMode.java b/src/de/steamwar/velocitycore/ArenaMode.java
new file mode 100644
index 0000000..a185dcb
--- /dev/null
+++ b/src/de/steamwar/velocitycore/ArenaMode.java
@@ -0,0 +1,121 @@
+/*
+ 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