From 8b776ff33e1d50c01d0a0f50f2117d421bef6900 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 12 Aug 2024 17:15:38 +0200 Subject: [PATCH 01/37] Es baut... (Untested) --- .../velocitycore/discord/DiscordBot.java | 40 ++++++------ .../velocitycore/discord/DiscordConfig.java | 6 +- .../discord/DiscordTicketType.java | 6 +- .../discord/channels/DiscordChannel.java | 17 ++--- .../discord/channels/DiscordChatRoom.java | 6 +- .../discord/channels/EventChannel.java | 18 +++--- .../discord/channels/InteractionReply.java | 9 +-- .../channels/StaticMessageChannel.java | 19 +++--- .../discord/listeners/ChannelListener.java | 14 ++--- .../discord/listeners/DiscordSchemUpload.java | 8 ++- .../discord/listeners/DiscordTeamEvent.java | 4 +- .../listeners/DiscordTicketHandler.java | 62 +++++++++---------- .../discord/util/AuthManager.java | 10 +-- .../discord/util/DiscordAlert.java | 10 +-- settings.gradle.kts | 2 +- 15 files changed, 116 insertions(+), 115 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java index 3928da7b..5f770366 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java @@ -32,18 +32,20 @@ import de.steamwar.velocitycore.discord.util.AuthManager; import lombok.Getter; import net.dv8tion.jda.api.*; import net.dv8tion.jda.api.entities.*; -import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; +import net.dv8tion.jda.api.entities.emoji.Emoji; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.exceptions.ErrorResponseException; import net.dv8tion.jda.api.interactions.commands.Command; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.CommandData; +import net.dv8tion.jda.api.interactions.commands.build.Commands; import net.dv8tion.jda.api.interactions.commands.build.OptionData; import net.dv8tion.jda.api.interactions.components.ActionRow; -import net.dv8tion.jda.api.interactions.components.Button; +import net.dv8tion.jda.api.interactions.components.buttons.Button; import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction; import net.dv8tion.jda.api.utils.MemberCachePolicy; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; -import javax.security.auth.login.LoginException; import java.awt.*; import java.util.List; import java.util.*; @@ -87,15 +89,11 @@ public class DiscordBot { public DiscordBot(DiscordConfig config) { this.config = config; - try { - jda = JDABuilder - .createDefault(config.getToken()) - .setStatus(OnlineStatus.ONLINE) - .setMemberCachePolicy(MemberCachePolicy.ONLINE) - .build(); - } catch (LoginException e) { - throw new SecurityException("Could not login", e); - } + jda = JDABuilder + .createDefault(config.getToken()) + .setStatus(OnlineStatus.ONLINE) + .setMemberCachePolicy(MemberCachePolicy.ONLINE) + .build(); instance = this; VelocityCore.schedule(this::asyncInit).schedule(); @@ -109,9 +107,9 @@ public class DiscordBot { } activity(); - new StaticMessageChannel(config.channel("roles"), () -> new MessageBuilder() + new StaticMessageChannel(config.channel("roles"), () -> new MessageCreateBuilder() .setContent("**Rollenvergabe**\nKlicke um eine Rolle zu bekommen:") - .setActionRows(ActionRow.of(config.getRoles().values().stream().map(DiscordConfig.DiscordRole::toButton).toArray(Button[]::new))), event -> InteractionReply.reply(event, reply -> { + .setComponents(ActionRow.of(config.getRoles().values().stream().map(DiscordConfig.DiscordRole::toButton).toArray(Button[]::new))), event -> InteractionReply.reply(event, reply -> { Member member = event.getMember(); Guild guild = event.getGuild(); Role role = guild.getRoleById(event.getComponentId()); @@ -124,33 +122,35 @@ public class DiscordBot { reply.system("DC_ROLE_ADDED", role.getAsMention()); } })); - new StaticMessageChannel(config.channel("rules"), () -> new MessageBuilder() + new StaticMessageChannel(config.channel("rules"), () -> new MessageCreateBuilder() .setEmbeds(new EmbedBuilder() .setDescription(String.join("\n", config.getRules())) .setColor(Color.GRAY) .setAuthor("SteamWar", "https://steamwar.de") .setTitle("Regeln und Infos") .build()) - .setActionRows( + .setComponents( ActionRow.of(Button.link("https://steamwar.de", "Website"), Button.link("https://steamwar.de/youtube", "YouTube")), ActionRow.of(Button.primary("auth", Emoji.fromUnicode("U+2705")).withLabel("Minecraft verknüpfen")) ), event -> { if(event.getComponentId().equals("auth")) event.reply("Gebe innerhalb der nächsten 10 Minuten ``/verify " + AuthManager.createDiscordAuthToken(event.getUser()) + "`` auf dem Minecraft Server ein").setEphemeral(true).queue(); }); - new StaticMessageChannel(config.channel("ticket"), () -> new MessageBuilder() + new StaticMessageChannel(config.channel("ticket"), () -> new MessageCreateBuilder() .setEmbeds(new EmbedBuilder() .setDescription("Hier kannst du Tickets öffnen, welche nur von dir und Teammitgliedern eingesehen werden können.") .setTitle("SteamWar Tickets") .setColor(Color.RED) .build()) - .setActionRows(ActionRow.of(Arrays.stream(DiscordTicketType.values()).map(DiscordTicketType::toButton).toArray(Button[]::new))), DiscordTicketHandler::openTicket); + .setComponents(ActionRow.of(Arrays.stream(DiscordTicketType.values()).map(DiscordTicketType::toButton).toArray(Button[]::new))), DiscordTicketHandler::openTicket); eventChannel = new StaticMessageChannel(config.channel("events"), EventChannel::get); checklistChannel = new ChecklistChannel(config.channel("checklist")); announcementChannel = new DiscordChannel(config.channel("announcement")) { @Override - public void received(GuildMessageReceivedEvent event) { + public void received(MessageReceivedEvent event) { + if (!event.isFromGuild()) return; + Chatter.broadcast().system("ALERT", event.getMessage().getContentDisplay()); } }; @@ -198,7 +198,7 @@ public class DiscordBot { .keySet().stream() .filter(command -> !correctCommands.contains(command)) .filter(command -> command.matches("^[\\w-]+$")) - .map(command -> new CommandData(command, command).addOptions(commandArgument)) + .map(command -> Commands.slash(command, command).addOptions(commandArgument)) .toArray(CommandData[]::new)) .queue(); } diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordConfig.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordConfig.java index 967d74a3..af930d77 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordConfig.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordConfig.java @@ -23,9 +23,9 @@ import de.steamwar.velocitycore.Config; import de.steamwar.velocitycore.VelocityCore; import lombok.Getter; import lombok.NoArgsConstructor; -import net.dv8tion.jda.api.entities.Emoji; -import net.dv8tion.jda.api.interactions.components.Button; -import net.dv8tion.jda.api.interactions.components.ButtonStyle; +import net.dv8tion.jda.api.entities.emoji.Emoji; +import net.dv8tion.jda.api.interactions.components.buttons.Button; +import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle; import java.io.File; import java.util.List; diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordTicketType.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordTicketType.java index 5c6a2187..8cb67e6e 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordTicketType.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordTicketType.java @@ -20,9 +20,9 @@ package de.steamwar.velocitycore.discord; import lombok.AllArgsConstructor; -import net.dv8tion.jda.api.entities.Emoji; -import net.dv8tion.jda.api.interactions.components.Button; -import net.dv8tion.jda.api.interactions.components.ButtonStyle; +import net.dv8tion.jda.api.entities.emoji.Emoji; +import net.dv8tion.jda.api.interactions.components.buttons.Button; +import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle; @AllArgsConstructor public enum DiscordTicketType { diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java index 304e2d0f..35e78714 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java @@ -26,11 +26,12 @@ import de.steamwar.messages.Message; import de.steamwar.sql.SteamwarUser; import lombok.AllArgsConstructor; import lombok.Getter; -import net.dv8tion.jda.api.MessageBuilder; -import net.dv8tion.jda.api.entities.MessageChannel; import net.dv8tion.jda.api.entities.User; -import net.dv8tion.jda.api.events.interaction.GenericComponentInteractionCreateEvent; -import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; +import net.dv8tion.jda.api.events.interaction.component.GenericComponentInteractionCreateEvent; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; +import net.dv8tion.jda.api.utils.messages.MessageCreateData; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; @@ -57,19 +58,19 @@ public class DiscordChannel extends Chatter.PlayerlessChatter { } public void send(String message) { - send(new MessageBuilder() - .append(message + send(new MessageCreateBuilder() + .setContent(message .replace("&", "") .replace("@everyone", "`@everyone`") .replace("@here", "`@here`") .replaceAll("<[@#]!?\\d+>", "`$0`"))); } - public void send(MessageBuilder builder) { + public void send(MessageCreateBuilder builder) { channel.sendMessage(builder.build()).queue(); } - public void received(GuildMessageReceivedEvent event) { + public void received(MessageReceivedEvent event) { event.getMessage().delete().queue(); } diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChatRoom.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChatRoom.java index 2d5f0fb2..7aec1362 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChatRoom.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChatRoom.java @@ -24,7 +24,7 @@ import de.steamwar.messages.Chatter; import de.steamwar.messages.ChatterGroup; import de.steamwar.sql.Punishment; import de.steamwar.sql.SteamwarUser; -import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import java.util.function.Supplier; @@ -40,7 +40,9 @@ public class DiscordChatRoom extends DiscordChannel { } @Override - public void received(GuildMessageReceivedEvent event) { + public void received(MessageReceivedEvent event) { + if (!event.isFromGuild()) return; + SteamwarUser user = SteamwarUser.get(event.getAuthor().getIdLong()); if (user == null || event.getMessage().getContentRaw().length() > 250 || user.isPunished(Punishment.PunishmentType.Ban) || user.isPunished(Punishment.PunishmentType.Mute)) { event.getMessage().delete().queue(); diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/EventChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/EventChannel.java index b8d8b1bc..051b3883 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/EventChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/EventChannel.java @@ -25,10 +25,10 @@ import de.steamwar.sql.Team; import de.steamwar.sql.TeamTeilnahme; 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.emoji.Emoji; import net.dv8tion.jda.api.interactions.components.ActionRow; -import net.dv8tion.jda.api.interactions.components.selections.SelectionMenu; +import net.dv8tion.jda.api.interactions.components.selections.StringSelectMenu; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; import java.awt.*; import java.sql.Timestamp; @@ -40,21 +40,21 @@ import java.util.stream.Collectors; @UtilityClass public class EventChannel { - public MessageBuilder get() { + public MessageCreateBuilder get() { if (Event.get() == null) return updateComing(); return updateCurrent(); } - private MessageBuilder updateComing() { + private MessageCreateBuilder updateComing() { EmbedBuilder embedBuilder = new EmbedBuilder() .setColor(Color.GRAY) .setTitle("Zukünftige Events") .setAuthor("SteamWar", "https://www.steamwar.de"); - SelectionMenu.Builder menuBuilder = SelectionMenu.create("eventName") + StringSelectMenu.Builder menuBuilder = StringSelectMenu.create("eventName") .setPlaceholder("Wähle ein Event aus!") .setMinValues(1) .setMaxValues(1); @@ -77,16 +77,16 @@ public class EventChannel { } }); - MessageBuilder messageBuilder = new MessageBuilder() + MessageCreateBuilder messageBuilder = new MessageCreateBuilder() .setEmbeds(embedBuilder.build()); if(events.stream().anyMatch(event -> event.getDeadline().after(Timestamp.from(Instant.now())))) { - messageBuilder.setActionRows(ActionRow.of(menuBuilder.build())); + messageBuilder.setComponents(ActionRow.of(menuBuilder.build())); } return messageBuilder; } - private MessageBuilder updateCurrent() { + private MessageCreateBuilder updateCurrent() { Event event = Event.get(); EmbedBuilder embedBuilder = new EmbedBuilder() .setColor(Color.GRAY) diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/InteractionReply.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/InteractionReply.java index cbacf536..7366ae96 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/InteractionReply.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/InteractionReply.java @@ -19,7 +19,8 @@ package de.steamwar.velocitycore.discord.channels; -import net.dv8tion.jda.api.interactions.Interaction; +import net.dv8tion.jda.api.interactions.callbacks.IReplyCallback; +import net.dv8tion.jda.api.interactions.components.ComponentInteraction; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; @@ -29,18 +30,18 @@ import java.util.function.Consumer; public class InteractionReply extends DiscordChannel { - public static void reply(Interaction interaction, Consumer consumer) { + public static void reply(IReplyCallback interaction, Consumer consumer) { InteractionReply reply = new InteractionReply(interaction); consumer.accept(reply); reply.submit(); } - private final Interaction interaction; + private final IReplyCallback interaction; private boolean replied = false; private final List messages = new ArrayList<>(); - private InteractionReply(Interaction interaction) { + private InteractionReply(IReplyCallback interaction) { super(interaction.getUser()); this.interaction = interaction; } diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/StaticMessageChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/StaticMessageChannel.java index 2041583f..3a165915 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/StaticMessageChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/StaticMessageChannel.java @@ -20,35 +20,36 @@ package de.steamwar.velocitycore.discord.channels; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.events.interaction.GenericComponentInteractionCreateEvent; +import net.dv8tion.jda.api.events.interaction.component.GenericComponentInteractionCreateEvent; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; +import net.dv8tion.jda.api.utils.messages.MessageEditData; import java.util.function.Consumer; import java.util.function.Supplier; public class StaticMessageChannel extends DiscordChannel { - public static MessageBuilder toMessageBuilder(EmbedBuilder embedBuilder) { - MessageBuilder messageBuilder = new MessageBuilder(); + public static MessageCreateBuilder toMessageBuilder(EmbedBuilder embedBuilder) { + MessageCreateBuilder messageBuilder = new MessageCreateBuilder(); messageBuilder.setEmbeds(embedBuilder.build()); return messageBuilder; } private Message message; - private final Supplier supplier; + private final Supplier supplier; private final Consumer interaction; - public StaticMessageChannel(String channel, Supplier supplier) { + public StaticMessageChannel(String channel, Supplier supplier) { this(channel, supplier, event -> {}); } - public StaticMessageChannel(String channel, Supplier supplier, Consumer interaction) { + public StaticMessageChannel(String channel, Supplier supplier, Consumer interaction) { super(channel); this.supplier = supplier; this.interaction = interaction; - if(getChannel().hasLatestMessage()) + if(getChannel().getLatestMessageIdLong() != 0) message = getChannel().getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null); update(); @@ -58,7 +59,7 @@ public class StaticMessageChannel extends DiscordChannel { if (message == null) { getChannel().sendMessage(supplier.get().build()).queue(m -> message = m); } else { - message.editMessage(supplier.get().build()).queue(); + message.editMessage(MessageEditData.fromCreateData(supplier.get().build())).queue(); } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/ChannelListener.java b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/ChannelListener.java index 7665c40f..fe8795e6 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/ChannelListener.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/ChannelListener.java @@ -25,11 +25,11 @@ import de.steamwar.velocitycore.discord.DiscordBot; import de.steamwar.velocitycore.discord.channels.DiscordChannel; import de.steamwar.velocitycore.discord.channels.InteractionReply; import lombok.Getter; -import net.dv8tion.jda.api.entities.ChannelType; -import net.dv8tion.jda.api.entities.MessageChannel; -import net.dv8tion.jda.api.events.interaction.GenericComponentInteractionCreateEvent; -import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; -import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; +import net.dv8tion.jda.api.entities.channel.ChannelType; +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.events.interaction.component.GenericComponentInteractionCreateEvent; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.interactions.InteractionType; import net.dv8tion.jda.api.interactions.commands.OptionMapping; @@ -44,7 +44,7 @@ public class ChannelListener extends ListenerAdapter { private static final Map channels = new HashMap<>(); @Override - public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) { + public void onMessageReceived(@NotNull MessageReceivedEvent event) { if(event.getAuthor().isBot()) return; @@ -69,7 +69,7 @@ public class ChannelListener extends ListenerAdapter { } @Override - public void onSlashCommand(@NotNull SlashCommandEvent event) { + public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) { InteractionReply.reply(event, sender -> { if(sender.user().getDiscordId() == null) return; diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java index e8969a7c..037eadcd 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java @@ -26,7 +26,7 @@ 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 net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import java.io.IOException; @@ -41,7 +41,9 @@ public class DiscordSchemUpload extends ListenerAdapter { private static final List SCHEM_FILE_ENDINGS = Arrays.asList(".schem", ".schematic"); @Override - public void onPrivateMessageReceived(PrivateMessageReceivedEvent event) { + public void onMessageReceived(MessageReceivedEvent event) { + if (event.isFromGuild()) return; + Message message = event.getMessage(); if(message.getAttachments().isEmpty()) return; @@ -76,7 +78,7 @@ public class DiscordSchemUpload extends ListenerAdapter { if(node == null) node = SchematicNode.createSchematic(user.getId(), name, null); - try (InputStream in = attachment.retrieveInputStream().get()) { + try (InputStream in = attachment.getProxy().download().get()) { NodeData.get(node).saveFromStream(in, fileName.substring(dot).equalsIgnoreCase(".schem")); sender.system("DC_SCHEMUPLOAD_SUCCESS", name); } catch (InterruptedException e) { diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTeamEvent.java b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTeamEvent.java index d18de226..8fd644a3 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTeamEvent.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTeamEvent.java @@ -23,7 +23,7 @@ import de.steamwar.velocitycore.VelocityCore; import de.steamwar.velocitycore.discord.DiscordBot; import de.steamwar.velocitycore.discord.channels.InteractionReply; import de.steamwar.sql.Event; -import net.dv8tion.jda.api.events.interaction.SelectionMenuEvent; +import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import org.jetbrains.annotations.NotNull; @@ -32,7 +32,7 @@ public class DiscordTeamEvent extends ListenerAdapter { private final String eventsChannel = DiscordBot.getInstance().getConfig().channel("events"); @Override - public void onSelectionMenu(@NotNull SelectionMenuEvent event) { + public void onStringSelectInteraction(@NotNull StringSelectInteractionEvent event) { if(!event.getChannel().getId().equals(eventsChannel)) return; diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java index 692d475a..e5cabd91 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java @@ -29,17 +29,18 @@ import de.steamwar.velocitycore.discord.DiscordTicketType; import de.steamwar.velocitycore.discord.channels.DiscordChannel; import de.steamwar.velocitycore.discord.channels.InteractionReply; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.Emoji; -import net.dv8tion.jda.api.entities.MessageChannel; -import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.entities.User; -import net.dv8tion.jda.api.events.interaction.GenericComponentInteractionCreateEvent; -import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; +import net.dv8tion.jda.api.entities.emoji.Emoji; +import net.dv8tion.jda.api.events.interaction.component.GenericComponentInteractionCreateEvent; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.interactions.components.ActionRow; -import net.dv8tion.jda.api.interactions.components.Button; +import net.dv8tion.jda.api.interactions.components.buttons.Button; +import net.dv8tion.jda.api.utils.SplitUtil; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; import net.kyori.adventure.text.event.ClickEvent; import org.jetbrains.annotations.NotNull; @@ -59,24 +60,23 @@ public class DiscordTicketHandler extends ListenerAdapter { SteamwarUser user = SteamwarUser.get(event.getUser().getIdLong()); TextChannel ticketChannel = event.getGuild().getCategoryById(TICKET_CATEGORY).createTextChannel((user == null ? event.getUser().getName() : user.getUserName()) + "-" + event.getComponentId() + "-" + System.currentTimeMillis() % 1000).complete(); - ticketChannel.createPermissionOverride(event.getMember()).setAllow( + ticketChannel.getPermissionContainer().upsertPermissionOverride(event.getMember()).setAllowed( Permission.VIEW_CHANNEL, - Permission.MESSAGE_WRITE, + Permission.MESSAGE_SEND, Permission.MESSAGE_ATTACH_FILES, Permission.MESSAGE_ADD_REACTION, - Permission.MESSAGE_READ, Permission.MESSAGE_EMBED_LINKS, Permission.MESSAGE_HISTORY).complete(); ticketChannel.getManager().setTopic(event.getUser().getId()).complete(); DiscordChannel channel = new DiscordChannel(DiscordChannel.userOrPublic(event.getUser()), ticketChannel); - channel.send(new MessageBuilder() + channel.send(new MessageCreateBuilder() .setEmbeds(new EmbedBuilder() .setTitle(channel.parseToPlain("DC_TICKET_TITLE")) .setDescription(channel.parseToPlain(ticketType.introduction())) .setColor(Color.GREEN) .build()) - .setActionRows(ActionRow.of(Button.danger("close-" + ticketChannel.getName(), channel.parseToPlain("DC_TICKET_CLOSE")).withEmoji(Emoji.fromUnicode("U+26A0"))))); + .setComponents(ActionRow.of(Button.danger("close-" + ticketChannel.getName(), channel.parseToPlain("DC_TICKET_CLOSE")).withEmoji(Emoji.fromUnicode("U+26A0"))))); InteractionReply.reply(event, reply -> reply.system("DC_TICKET_CREATED", ticketChannel.getAsMention())); Chatter.serverteam().prefixless("DISCORD_TICKET_NEW", ticketChannel.getName()); @@ -85,7 +85,7 @@ public class DiscordTicketHandler extends ListenerAdapter { @Override public void onGenericComponentInteractionCreate(@NotNull GenericComponentInteractionCreateEvent event) { MessageChannel messageChannel = event.getChannel(); - if(messageChannel instanceof TextChannel channel && channel.getParent() != null && channel.getParent().getId().equals(TICKET_CATEGORY) && event.getComponentId().startsWith("close-")) { + if(messageChannel instanceof TextChannel channel && channel.getParentCategoryIdLong() != 0 && channel.getParentCategoryId().equals(TICKET_CATEGORY) && event.getComponentId().startsWith("close-")) { LinkedList messages = channel.getIterableHistory().complete().stream() .filter(message -> !message.getAuthor().isSystem() && !message.getAuthor().isBot()) .map(message -> { @@ -106,24 +106,10 @@ public class DiscordTicketHandler extends ListenerAdapter { messages.addFirst(new StringBuilder().append(" **").append(event.getUser().getName()).append("**: Ticket closed")); - LinkedList messageBuilders = new LinkedList<>(); - messageBuilders.add(new StringBuilder()); - messages.descendingIterator() - .forEachRemaining(stringBuilder -> { - if(stringBuilder.length() >= 4096) { - messageBuilders.getLast().append(stringBuilder.substring(0, 4090)); - messageBuilders.add(new StringBuilder(stringBuilder.substring(4090, stringBuilder.length() - 1))); - } else if (stringBuilder.length() + messageBuilders.getLast().length() >= 4096) { - messageBuilders.add(new StringBuilder(stringBuilder.toString())); - } else { - messageBuilders.getLast().append(stringBuilder); - } - }); - EmbedBuilder embedBuilder = new EmbedBuilder() .setColor(Color.GREEN) .setTimestamp(Instant.now()) - .setTitle(event.getTextChannel().getName()); + .setTitle(event.getChannel().getName()); if(channel.getTopic() != null && !channel.getTopic().isEmpty()) { User user = event.getJDA().retrieveUserById(channel.getTopic()).complete(); @@ -131,7 +117,12 @@ public class DiscordTicketHandler extends ListenerAdapter { } TextChannel logChannel = event.getGuild().getTextChannelById(TICKET_LOG); - messageBuilders.forEach(stringBuilder -> logChannel.sendMessage(new MessageBuilder().setEmbeds(embedBuilder.setDescription(stringBuilder.toString()).build()).build()).queue()); + SplitUtil.split( + messages.stream().map(StringBuilder::toString).collect(Collectors.joining("\n")), + 2000, + SplitUtil.Strategy.NEWLINE, + SplitUtil.Strategy.ANYWHERE + ).stream().map(message -> new MessageCreateBuilder().setEmbeds(embedBuilder.setDescription(message).build())).forEach(builder -> logChannel.sendMessage(builder.build()).queue()); Chatter.serverteam().prefixless("DISCORD_TICKET_CLOSED", channel.getName()); channel.delete().reason("Closed").queue(); @@ -139,11 +130,14 @@ public class DiscordTicketHandler extends ListenerAdapter { } @Override - public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) { - TextChannel channel = event.getChannel(); + public void onMessageReceived(@NotNull MessageReceivedEvent event) { + if (!event.isFromGuild()) return; + + MessageChannel channel = event.getChannel(); if( - channel.getParent() != null && - channel.getParent().getId().equals(TICKET_CATEGORY) && + channel instanceof TextChannel textChannel && + textChannel.getParentCategoryIdLong() != 0 && + textChannel.getParentCategoryId().equals(TICKET_CATEGORY) && !channel.getId().equals(TICKET_CHANNEL) && !channel.getId().equals(TICKET_LOG) ) { @@ -152,7 +146,7 @@ public class DiscordTicketHandler extends ListenerAdapter { ChatterGroup receivers = new ChatterGroup(Chatter.allStream().filter(player -> player.user().hasPerm(UserPerm.TICKET_LOG))); try { - SteamwarUser user = SteamwarUser.get(Long.parseLong(channel.getTopic())); + SteamwarUser user = SteamwarUser.get(Long.parseLong(textChannel.getTopic())); if(user != null && !user.perms().contains(UserPerm.TEAM)) receivers = new ChatterGroup(receivers, Chatter.of(user)); } catch(NumberFormatException e) { diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/util/AuthManager.java b/VelocityCore/src/de/steamwar/velocitycore/discord/util/AuthManager.java index 972f77f1..3da3971e 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/util/AuthManager.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/util/AuthManager.java @@ -23,11 +23,11 @@ import de.steamwar.velocitycore.VelocityCore; import de.steamwar.velocitycore.discord.channels.DiscordChannel; import de.steamwar.sql.SteamwarUser; import lombok.experimental.UtilityClass; -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.entities.emoji.Emoji; import net.dv8tion.jda.api.interactions.components.ActionRow; -import net.dv8tion.jda.api.interactions.components.Button; +import net.dv8tion.jda.api.interactions.components.buttons.Button; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; import java.util.Base64; import java.util.HashMap; @@ -63,9 +63,9 @@ public class AuthManager { user.setDiscordId(dcUser.getIdLong()); DiscordChannel channel = new DiscordChannel(dcUser); - channel.send(new MessageBuilder() + channel.send(new MessageCreateBuilder() .setContent(channel.parseToPlain("DC_AUTH_SUCCESS", user)) - .setActionRows(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389"))))); + .setComponents(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389"))))); return dcUser; } diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/util/DiscordAlert.java b/VelocityCore/src/de/steamwar/velocitycore/discord/util/DiscordAlert.java index 0b115d41..6ba23149 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/util/DiscordAlert.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/util/DiscordAlert.java @@ -25,11 +25,11 @@ import de.steamwar.velocitycore.discord.DiscordBot; import de.steamwar.velocitycore.discord.channels.DiscordChannel; 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.entities.emoji.Emoji; import net.dv8tion.jda.api.interactions.components.ActionRow; -import net.dv8tion.jda.api.interactions.components.Button; +import net.dv8tion.jda.api.interactions.components.buttons.Button; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; import java.awt.*; import java.time.Instant; @@ -47,7 +47,7 @@ public class DiscordAlert { if(user == null) return; - MessageBuilder builder = new MessageBuilder() + MessageCreateBuilder builder = new MessageCreateBuilder() .setEmbeds(new EmbedBuilder() .setAuthor("SteamWar", "https://steamwar.de", "https://cdn.discordapp.com/app-icons/869606970099904562/60c884000407c02671d91d8e7182b8a1.png") .setColor(color) @@ -56,7 +56,7 @@ public class DiscordAlert { .setTimestamp(Instant.now()) .build()); if(success) - builder.setActionRows(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389")))); + builder.setComponents(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389")))); new DiscordChannel(user).send(builder); }); diff --git a/settings.gradle.kts b/settings.gradle.kts index 2fed98a6..072ee29a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -106,7 +106,7 @@ dependencyResolutionManagement { library("netty", "io.netty:netty-all:4.1.68.Final") library("junit", "junit:junit:4.13.2") library("hamcrest", "org.hamcrest:hamcrest:2.2") - library("jda", "net.dv8tion:JDA:4.4.0_352") + library("jda", "net.dv8tion:JDA:5.0.2") library("msgpack", "org.msgpack:msgpack-core:0.9.8") library("classindex", "org.atteo.classindex:classindex:3.13") From 8bdb2bad14c481e5db3cee39522d2e3a09a00cdf Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 13 Aug 2024 19:37:37 +0200 Subject: [PATCH 02/37] Fix TinyProtocol spurious ConcurrentModificationExceptions --- .../src/com/comphenix/tinyprotocol/TinyProtocol.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java b/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java index b01690ec..7019c26d 100644 --- a/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java +++ b/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java @@ -36,6 +36,7 @@ import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.plugin.Plugin; import java.util.*; +import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.BiFunction; import java.util.logging.Level; @@ -102,7 +103,7 @@ public class TinyProtocol implements Listener { } public void addFilter(Class packetType, BiFunction filter) { - packetFilters.computeIfAbsent(packetType, c -> Collections.synchronizedList(new ArrayList<>(1))).add(filter); + packetFilters.computeIfAbsent(packetType, c -> new CopyOnWriteArrayList<>()).add(filter); } public void removeFilter(Class packetType, BiFunction filter) { From 7afdfd89b09630b75e73f533fde2bbc1e7c89c66 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 18 Aug 2024 18:02:02 +0200 Subject: [PATCH 03/37] Changes to support AIs, Add DummyAI --- .../fightsystem/FightSystem.properties | 3 + .../fightsystem/FightSystem_de.properties | 3 + .../src/de/steamwar/fightsystem/ai/AI.java | 122 ++++++++++----- .../de/steamwar/fightsystem/ai/AIManager.java | 55 +++++++ .../ai/{LixfelAI.java => DummyAI.java} | 36 ++--- .../fightsystem/ai/LixfelPathplanner.java | 141 ------------------ .../de/steamwar/fightsystem/commands/GUI.java | 32 +++- .../fightsystem/commands/RequestsCommand.java | 8 +- .../fightsystem/fight/FightSchematic.java | 7 +- .../steamwar/fightsystem/fight/FightTeam.java | 9 +- .../fightsystem/fight/JoinRequest.java | 77 +++++++--- .../listener/JoinRequestListener.java | 2 +- .../fightsystem/listener/Recording.java | 11 +- .../steamwar/fightsystem/record/Recorder.java | 2 +- 14 files changed, 268 insertions(+), 240 deletions(-) create mode 100644 FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIManager.java rename FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/{LixfelAI.java => DummyAI.java} (63%) delete mode 100644 FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelPathplanner.java diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties index 3c220d64..9f80ab7e 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties @@ -83,6 +83,8 @@ SCHEM_PRIVATE=§ePrivate {0} SCHEM_NO_PRIVATE=§7No private {0} present SCHEM_PRIVATE_FORBIDDEN=§7No private {0} allowed +ADD_AI_TITLE=Add AI + # Countdowns COUNTDOWN_MINUTES=§e{0} §7Minutes {1} @@ -114,6 +116,7 @@ RESPAWN=§eRespawn REMOVE_PLAYERS=§cKick player CHOOSE_SCHEMATIC=§eChoose {0} SCHEMATIC_REQUIRED=§cChoose a schematic first +ADD_AI=§eAdd AI KIT_PREVIEW_EDIT=§7Edit kit KIT_PREVIEW_CHOOSE=§aSelect kit diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties index 06b07d18..6723bcfb 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties @@ -77,6 +77,8 @@ SCHEM_PRIVATE=§ePrivates {0} SCHEM_NO_PRIVATE=§7Kein privates {0} vorhanden SCHEM_PRIVATE_FORBIDDEN=§7Kein privates {0} erlaubt +ADD_AI_TITLE=KI hinzufügen + # Countdowns COUNTDOWN_MINUTES=§e{0} §7Minuten {1} @@ -107,6 +109,7 @@ RESPAWN=§eRespawn REMOVE_PLAYERS=§cSpieler rauswerfen CHOOSE_SCHEMATIC=§e{0} wählen SCHEMATIC_REQUIRED=§cZuerst muss eine Schematic gewählt sein +ADD_AI=§eKI hinzufügen KIT_PREVIEW_EDIT=§7Kit bearbeiten KIT_PREVIEW_CHOOSE=§aKit wählen diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AI.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AI.java index 6f5cb005..0b681fc2 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AI.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AI.java @@ -19,32 +19,38 @@ package de.steamwar.fightsystem.ai; +import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.fight.JoinRequest; import de.steamwar.fightsystem.listener.Chat; +import de.steamwar.fightsystem.record.GlobalRecorder; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.OneShotStateDependent; import de.steamwar.fightsystem.utils.Region; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; +import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Note; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.block.Lectern; import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.FaceAttachable; import org.bukkit.block.data.Openable; import org.bukkit.block.data.Powerable; import org.bukkit.block.data.type.Comparator; import org.bukkit.block.data.type.NoteBlock; import org.bukkit.block.data.type.Repeater; +import org.bukkit.block.data.type.Switch; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; import org.bukkit.entity.Villager; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.scheduler.BukkitTask; @@ -55,10 +61,16 @@ import java.util.logging.Level; public abstract class AI { + public static final int MOVEMENT_DELAY = 4; + public static final double INTERACTION_RANGE = 5.0; + private static final Map ais = new HashMap<>(); + public static void printPos() { + ais.values().forEach(ai -> ai.chat(ai.entity.isValid() + " " + ai.entity.isDead() + " " + ai.entity.getLocation())); + } static { - new OneShotStateDependent(ArenaMode.All, FightState.Spectate, () -> { + new OneShotStateDependent(ArenaMode.AntiReplay, FightState.Spectate, () -> { ais.values().forEach(AI::stop); ais.clear(); }); @@ -68,7 +80,9 @@ public abstract class AI { return ais.get(uuid); } - private final FightTeam team; + @Getter + protected final FightTeam team; + @Getter private final LivingEntity entity; private final BukkitTask task; private final Queue queue = new ArrayDeque<>(); @@ -83,11 +97,15 @@ public abstract class AI { task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::run, 1, 1); ais.put(entity.getUniqueId(), this); team.addMember(entity, user); + + if(FightState.Schem.contains(FightState.getFightState())) + Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> schematic(team.getClipboard())); } public abstract SchematicNode chooseSchematic(); + public abstract void schematic(Clipboard clipboard); - public boolean acceptJoinRequest(Player player, FightTeam team) { + public boolean acceptJoinRequest(JoinRequest.Enquirer enquirer, FightTeam team) { return true; } @@ -101,11 +119,7 @@ public abstract class AI { task.cancel(); } - public LivingEntity getEntity() { - return entity; - } - - protected void setReady() { + public void setReady() { if(FightState.getFightState() != FightState.POST_SCHEM_SETUP) return; @@ -115,12 +129,12 @@ public abstract class AI { team.setReady(true); } - protected void chat(String message) { + public void chat(String message) { FightSystem.getPlugin().getLogger().log(Level.INFO, () -> entity.getName() + "» " + message); Chat.broadcastChat("PARTICIPANT_CHAT", team.getColoredName(), entity.getName(), message); } - protected Vector getPosition() { + public Vector getPosition() { Location location = entity.getLocation(); Region extend = team.getExtendRegion(); if(Fight.getUnrotated() == team) @@ -137,26 +151,28 @@ public abstract class AI { ); } - protected Material getBlock(Vector pos) { + public Material getBlock(Vector pos) { queue.add(new Action(1)); - return translate(pos, true).getBlock().getType(); + return translate(pos).getBlock().getType(); } - protected boolean isPowered(Vector pos) { + public BlockData getBlockData(Vector pos) { queue.add(new Action(1)); - return translate(pos, true).getBlock().isBlockPowered(); + return translate(pos).getBlock().getBlockData(); } - protected void setTNT(Vector pos) { + public void setTNT(Vector pos) { queue.add(new Action(1) { @Override public void run() { if(FightState.getFightState() != FightState.RUNNING) return; - Location location = translate(pos, true); - if(interactionDistanceViolation(location)) + Location location = translate(pos); + if(interactionDistanceViolation(location)) { + chat("InteractionDistanceViolation: setTNT"); return; + } Block block = location.getBlock(); if(block.getType() == Material.AIR) @@ -165,24 +181,26 @@ public abstract class AI { }); } - protected void interact(Vector pos) { + public void interact(Vector pos) { queue.add(new Action(1) { @Override public void run() { - Location location = translate(pos, true); - if(interactionDistanceViolation(location)) + Location location = translate(pos); + if(interactionDistanceViolation(location)) { + chat("InteractionDistanceViolation: interact"); return; + } interact(location.getBlock()); } }); } - protected void interact(Vector pos, int n) { + public void interact(Vector pos, int n) { queue.add(new Action(1) { @Override public void run() { - Location location = translate(pos, true); + Location location = translate(pos); if (interactionDistanceViolation(location)) return; Block block = location.getBlock(); @@ -199,13 +217,18 @@ public abstract class AI { }); } - protected void move(Vector pos) { - queue.add(new Action(2) { + public void move(Vector pos) { + queue.add(new Action(MOVEMENT_DELAY) { @Override public void run() { Location location = entity.getLocation(); - Location target = translate(pos, false); - if(Math.abs(location.getX() - target.getX()) > 1 || Math.abs(location.getY() - target.getY()) > 1.2 || Math.abs(location.getZ() - target.getZ()) > 1) { + if(!entity.isOnGround() && location.getBlock().getType() != Material.LADDER) { + FightSystem.getPlugin().getLogger().log(Level.INFO, "Entity falling"); + return; + } + + Location target = translate(pos); + if(Math.abs(location.getX() - target.getX()) > 1.0 || Math.abs(location.getY() - target.getY()) > 1.5 || Math.abs(location.getZ() - target.getZ()) > 1.0) { FightSystem.getPlugin().getLogger().log(Level.INFO, () -> entity.getName() + ": Overdistance movement " + location.toVector() + " " + target.toVector()); return; } @@ -213,13 +236,16 @@ public abstract class AI { if(!team.getFightPlayer(entity).canEntern() && !team.getExtendRegion().inRegion(target)) return; - entity.teleport(target, PlayerTeleportEvent.TeleportCause.COMMAND); + if(!entity.teleport(target, PlayerTeleportEvent.TeleportCause.PLUGIN)) + FightSystem.getPlugin().getLogger().log(Level.INFO, "Entity not teleported: " + entity.isValid()); + + GlobalRecorder.getInstance().entityMoves(entity); } }); } private boolean interactionDistanceViolation(Location location) { - return location.distance(entity.getEyeLocation()) > 5; + return location.distance(entity.getEyeLocation()) > INTERACTION_RANGE; } private void interact(Block block) { @@ -249,23 +275,51 @@ public abstract class AI { powerable.setPowered(false); block.setBlockData(powerable); + updateButton(block); }, type.name().endsWith("STONE_BUTTON") ? 20 : 30); } powerable.setPowered(!isPowered); } block.setBlockData(data); + if(data instanceof Switch) { + updateButton(block); + } + } + + private void updateButton(Block block) { + Switch sw = (Switch) block.getBlockData(); + FaceAttachable.AttachedFace face = sw.getAttachedFace(); + if (face == FaceAttachable.AttachedFace.FLOOR) { + update(block.getRelative(BlockFace.DOWN)); + } else if (face == FaceAttachable.AttachedFace.CEILING) { + update(block.getRelative(BlockFace.UP)); + } else { + update(block.getRelative(sw.getFacing().getOppositeFace())); + } + } + + private void update(Block block) { + BlockData data = block.getBlockData(); + block.setType(Material.BARRIER); + block.setBlockData(data); } private void run() { - if(queue.isEmpty()) - plan(); + if(queue.isEmpty()) { + try { + plan(); + } catch (Throwable t) { + stop(); + throw t; + } + } if(!queue.isEmpty() && --queue.peek().delay == 0) queue.poll().run(); } - private Location translate(Vector pos, boolean blockPos) { + public Location translate(Vector pos) { Region extend = team.getExtendRegion(); if(Fight.getUnrotated() == team) return new Location( @@ -277,9 +331,9 @@ public abstract class AI { else return new Location( Config.world, - extend.getMaxX() - pos.getX() - (blockPos ? 1 : 0), + extend.getMaxX() - pos.getX(), pos.getY() + team.getSchemRegion().getMinY(), - extend.getMaxZ() - pos.getZ() - (blockPos ? 1 : 0) + extend.getMaxZ() - pos.getZ() ); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIManager.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIManager.java new file mode 100644 index 00000000..5b9abf4b --- /dev/null +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIManager.java @@ -0,0 +1,55 @@ +/* + * 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.fightsystem.ai; + +import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.fightsystem.fight.FightTeam; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.bukkit.Material; + +import java.util.Arrays; +import java.util.List; +import java.util.function.BooleanSupplier; +import java.util.stream.Collectors; + +@AllArgsConstructor +public class AIManager { + private static final List AIs = Arrays.asList( + new AIManager(DummyAI.class, Material.STONE, () -> true) + ); + + public static List availableAIs() { + return AIs.stream().filter(manager -> manager.available.getAsBoolean()).collect(Collectors.toList()); + } + + private final Class aiClass; + @Getter + private final Material icon; + private final BooleanSupplier available; + + public String name() { + return aiClass.getSimpleName(); + } + + public void join(FightTeam team) { + Reflection.getConstructor(aiClass, FightTeam.class).invoke(team); + } +} diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelAI.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/DummyAI.java similarity index 63% rename from FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelAI.java rename to FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/DummyAI.java index 2a89353c..90fcd3d0 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelAI.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/DummyAI.java @@ -19,42 +19,42 @@ package de.steamwar.fightsystem.ai; +import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.utils.FightStatistics; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; -import org.bukkit.util.Vector; import java.util.List; import java.util.Random; -public class LixfelAI extends AI { +public class DummyAI extends AI { - private final Random random = new Random(); - private LixfelPathplanner pathplanner; + private static final Random random = new Random(); - public LixfelAI(FightTeam team, String user) { - super(team, SteamwarUser.get(user)); + public DummyAI(FightTeam team) { + super(team, SteamwarUser.get("public")); + + FightStatistics.unrank(); + getEntity().setInvulnerable(true); } - @Override public SchematicNode chooseSchematic() { List publics = SchematicNode.getAllSchematicsOfType(0, Config.SchematicType.toDB()); - SchematicNode schem = publics.get(new Random().nextInt(publics.size())); - pathplanner = new LixfelPathplanner(schem); - return schem; + return publics.get(random.nextInt(publics.size())); + } + + @Override + public void schematic(Clipboard clipboard) { + //does nothing } @Override protected void plan() { - setReady(); - Vector destination = pathplanner.getWalkable().get(random.nextInt(pathplanner.getWalkable().size())); - List path = pathplanner.plan(getPosition(), destination); - if(!path.isEmpty()) - chat("Path size: " + path.size()); - for(Vector p : path) { - move(p); - } + if(FightState.getFightState() == FightState.POST_SCHEM_SETUP) + setReady(); } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelPathplanner.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelPathplanner.java deleted file mode 100644 index b2e593e8..00000000 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelPathplanner.java +++ /dev/null @@ -1,141 +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.fightsystem.ai; - -import com.sk89q.worldedit.extent.clipboard.Clipboard; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.world.block.BlockType; -import de.steamwar.fightsystem.Config; -import de.steamwar.sql.SchematicData; -import de.steamwar.sql.SchematicNode; -import org.bukkit.util.Vector; - -import java.io.IOException; -import java.util.*; - -public class LixfelPathplanner { - - private static BlockType getBlockType(Clipboard clipboard, BlockVector3 vector) { - return clipboard.getBlock(vector).getBlockType(); - } - - private static boolean nonsolid(Clipboard clipboard, BlockVector3 vector) { - return !getBlockType(clipboard, vector).getMaterial().isSolid(); - } - - private static Vector toBukkit(BlockVector3 vector) { - return new Vector(vector.getX() + 0.5, vector.getY(), vector.getZ() + 0.5); - } - - private final List walkable = new ArrayList<>(); - private final Map neighbours = new HashMap<>(); - - public LixfelPathplanner(SchematicNode schem) { - try { - fillWalkable(new SchematicData(schem).load()); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - public List getWalkable() { - return walkable; - } - - private void fillWalkable(Clipboard clipboard) { - BlockVector3 min = clipboard.getRegion().getMinimumPoint().subtract(Config.PreperationArea, 0, Config.PreperationArea); //TODO assumes nonextended Schematic with maximal size - Region region = clipboard.getRegion(); - clipboard.getRegion().forEach(vector -> { - BlockVector3 below = vector.subtract(0, 1, 0); - if(!region.contains(below)) - return; - - BlockType belowMaterial = getBlockType(clipboard, below); - BlockVector3 above = vector.add(0, 1, 0); - if(nonsolid(clipboard, vector)) { - if( - (belowMaterial.getMaterial().isSolid() || belowMaterial.getId().equals("minecraft:ladder")) && - (!region.contains(above) || nonsolid(clipboard, above)) - ) - walkable.add(toBukkit(vector.subtract(min))); - } else { - if(!region.contains(above)) - walkable.add(toBukkit(above.subtract(min))); - } - }); - - for(Vector vector : walkable) { - neighbours.put(vector, walkable.stream().filter(neighbour -> neighbouring(neighbour, vector)).filter(neighbour -> neighbour != vector).toArray(Vector[]::new)); - } - } - - public List planToAnywhere(Vector start, Vector destination) { - Vector intermediate = walkable.stream().filter(vector -> neighbouring(vector, destination)).findAny().orElse(null); - - if(intermediate == null) - return Collections.emptyList(); - - List plan = plan(start, intermediate); - plan.add(destination); - - return plan; - } - - public List plan(Vector start, Vector destination) { - if(neighbouring(start, destination)) - return Collections.singletonList(destination); - - Map approach = new HashMap<>(); - Set checking = Collections.singleton(destination); - - while(!checking.isEmpty()) { - Set toCheck = new HashSet<>(); - for(Vector current : checking) { - Vector firstStep = Arrays.stream(neighbours.get(current)) - .filter(vector -> !approach.containsKey(vector)) - .filter(next -> { - approach.put(next, current); - toCheck.add(next); - return neighbouring(next, start); - }) - .findAny().orElse(null); - - if(firstStep != null) { - List path = new ArrayList<>(); - path.add(firstStep); - - while(path.get(path.size()-1) != destination) { - path.add(approach.get(path.get(path.size()-1))); - } - - return path; - } - } - checking = toCheck; - } - - return Collections.emptyList(); - } - - private boolean neighbouring(Vector a, Vector b) { - return Math.abs(a.getX() - b.getX()) <= 1 && Math.abs(a.getY() - b.getY()) <= 1 && Math.abs(a.getZ() - b.getZ()) <= 1; - } -} diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java index 0fba5388..4834bb0a 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java @@ -22,6 +22,7 @@ package de.steamwar.fightsystem.commands; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.ai.AIManager; import de.steamwar.fightsystem.fight.*; import de.steamwar.fightsystem.listener.PersonalKitCreator; import de.steamwar.fightsystem.states.FightState; @@ -38,9 +39,8 @@ import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import java.util.*; +import java.util.stream.Collectors; public class GUI { private GUI(){} @@ -53,7 +53,7 @@ public class GUI { String name = team.getLeader() != null ? team.getLeader().getEntity().getName() : team.getName(); inv.setItem(pos, SWItem.getDye(colorCode), colorCode, msg.parse("JOIN_REQUEST_TEAM", p, team.getColor() + name), click -> { p.closeInventory(); - new JoinRequest(p, team); + JoinRequest.forPlayer(p, team); }); } @@ -89,11 +89,29 @@ public class GUI { inv.open(); } + public static void addAI(Player p) { + SWListInv inv = new SWListInv<>( + p, msg.parse("ADD_AI_TITLE", p), + AIManager.availableAIs().stream().map(manager -> new SWListInv.SWListEntry<>(new SWItem(manager.getIcon(), manager.name()), manager)).collect(Collectors.toList()), + (click, manager) -> { + FightTeam team = Fight.getPlayerTeam(p); + if(FightState.PreLeaderSetup.contains(FightState.getFightState())) { + manager.join(Fight.getOpposite(team)); + } else { + JoinRequest.forAI(manager, team); + } + p.closeInventory(); + } + ); + inv.setCallback(-999, (ClickType click) -> p.closeInventory()); + inv.open(); + } + public static void chooseJoinRequests(Player p){ - List> players = JoinRequest.openRequests(p, Fight.getPlayerTeam(p)); - SWListInv inv = new SWListInv<>(p, msg.parse("REQUESTS_TITLE", p), players, (ClickType click, Player player) -> { + List> players = JoinRequest.openRequests(p, Fight.getPlayerTeam(p)); + SWListInv inv = new SWListInv<>(p, msg.parse("REQUESTS_TITLE", p), players, (ClickType click, JoinRequest request) -> { p.closeInventory(); - RequestsCommand.onJoinRequest(p, player, click.isLeftClick() ? JoinRequest::accept : JoinRequest::decline); + RequestsCommand.onJoinRequest(p, request, click.isLeftClick() ? JoinRequest::accept : JoinRequest::decline); }); inv.setCallback(-999, (ClickType click) -> p.closeInventory()); inv.open(); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/RequestsCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/RequestsCommand.java index 36c2a1e3..131cc898 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/RequestsCommand.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/RequestsCommand.java @@ -59,13 +59,7 @@ public class RequestsCommand implements CommandExecutor { return false; } - public static void onJoinRequest(Player player, Player target, BiConsumer handleJoinRequest) { - JoinRequest request = JoinRequest.get(target); - if(request == null) { - FightSystem.getMessage().send("NO_JOIN_REQUEST", player); - return; - } - + public static void onJoinRequest(Player player, JoinRequest request, BiConsumer handleJoinRequest) { FightTeam team = Fight.getPlayerTeam(player); if(!request.required(team)) { FightSystem.getMessage().send("NO_CONFIRMATION", player); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index 20c304d7..5e84ccdc 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -34,6 +34,7 @@ import de.steamwar.fightsystem.utils.WorldeditWrapper; import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; +import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.DyeColor; import org.bukkit.Location; @@ -52,6 +53,7 @@ public class FightSchematic extends StateDependent { private final Region region; private final boolean rotate; + @Getter private Clipboard clipboard = null; private int schematic = 0; @@ -137,6 +139,7 @@ public class FightSchematic extends StateDependent { private void paste(){ FreezeWorld freezer = new FreezeWorld(); + team.teleportToSpawn(); Vector dims = WorldeditWrapper.impl.getDimensions(clipboard); WorldeditWrapper.impl.pasteClipboard( clipboard, @@ -149,11 +152,11 @@ public class FightSchematic extends StateDependent { new AffineTransform().rotateY(rotate ? 180 : 0) ); FightSystem.getHullHider().initialize(team); + team.getPlayers().forEach(fightPlayer -> fightPlayer.ifAI(ai -> ai.schematic(clipboard))); if(ArenaMode.Check.contains(Config.mode) && !team.isBlue()) - replaceSync(Material.TNT, Material.OBSIDIAN); + replaceSync(Material.TNT, Material.RED_WOOL); Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), freezer::disable, 3); - Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), team::teleportToSpawn, 40); } @Override diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 853646fc..334f3f83 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -23,6 +23,7 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.ai.AIManager; import de.steamwar.fightsystem.commands.GUI; import de.steamwar.fightsystem.countdown.Countdown; import de.steamwar.fightsystem.events.TeamLeaveEvent; @@ -70,9 +71,11 @@ public class FightTeam { static { setKitButton(notReadyKit, true); - if(!ArenaMode.RankedEvent.contains(Config.mode)){ + if(ArenaMode.VariableTeams.contains(Config.mode)){ notReadyKit.setItem(2, "REQUESTS", new ItemBuilder(Material.PAPER).build(), GUI::chooseJoinRequests); notReadyKit.setItem(3, "REMOVE_PLAYERS", new ItemBuilder(SWItem.getMaterial("FIREWORK_CHARGE")).build(), GUI::chooseRemove); + if(!AIManager.availableAIs().isEmpty()) + notReadyKit.setItem(6, "ADD_AI", new ItemBuilder(Material.REDSTONE).build(), GUI::addAI); } if(Config.test()) @@ -452,6 +455,10 @@ public class FightTeam { return schematic.getId(); } + public Clipboard getClipboard() { + return schematic.getClipboard(); + } + public double getCurrentHearts() { return players.values().stream().filter(FightPlayer::isLiving).mapToDouble(fp -> fp.getEntity().getHealth()).sum(); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java index a7756e4c..e4e349c7 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java @@ -20,6 +20,7 @@ package de.steamwar.fightsystem.fight; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.ai.AIManager; import de.steamwar.fightsystem.states.FightState; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; @@ -28,44 +29,66 @@ import net.md_5.bungee.api.chat.ClickEvent; import org.bukkit.entity.Player; import java.util.*; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Consumer; import java.util.stream.Collectors; public class JoinRequest { - private static final Map activeRequests = new HashMap<>(); + private static final Map playerRequests = new HashMap<>(); + private static final List activeRequests = new ArrayList<>(); + public static JoinRequest get(Player player) { + return playerRequests.get(player); + } - public static List> openRequests(Player p, FightTeam team) { - return activeRequests.values().stream().filter( + public static List> openRequests(Player p, FightTeam team) { + return activeRequests.stream().filter( request -> request.waitOnApproval.contains(team) ).map(request -> { - SWItem item = SWItem.getPlayerSkull(request.player); - item.setLore(Arrays.asList( + AtomicReference item = new AtomicReference<>(); + request.enquirer.ifPlayer(player -> item.set(SWItem.getPlayerSkull(player))); + request.enquirer.ifAI(manager -> item.set(new SWItem(manager.getIcon(), manager.name()))); + item.get().setLore(Arrays.asList( FightSystem.getMessage().parse("REQUESTS_LEFT_CLICK", p), FightSystem.getMessage().parse("REQUESTS_RIGHT_CLICK", p) )); - return new SWListInv.SWListEntry<>(item, request.player); + return new SWListInv.SWListEntry<>(item.get(), request); }).collect(Collectors.toList()); } public static void clearRequests() { + playerRequests.clear(); activeRequests.clear(); } - public static JoinRequest get(Player player) { - return activeRequests.get(player); + public static void forPlayer(Player player, FightTeam team) { + new JoinRequest(new Enquirer() { + @Override public String name() { return player.getName(); } + @Override public void ifPlayer(Consumer function) { function.accept(player); } + @Override public void ifAI(Consumer function) {} + }, team, FightState.ingame() ? Fight.teams() : Collections.singleton(team)); } - private final Player player; + public static void forAI(AIManager manager, FightTeam team) { + new JoinRequest(new Enquirer() { + @Override public String name() { return manager.name(); } + @Override public void ifPlayer(Consumer function) {} + @Override public void ifAI(Consumer function) { function.accept(manager); } + }, team, Collections.singleton(Fight.getOpposite(team))); + } + + private final Enquirer enquirer; private final FightTeam team; private final Set waitOnApproval; - public JoinRequest(Player player, FightTeam team) { - this.player = player; + private JoinRequest(Enquirer enquirer, FightTeam team, Collection waitOnApproval) { + this.enquirer = enquirer; this.team = team; - this.waitOnApproval = new HashSet<>(FightState.ingame() ? Fight.teams() : Collections.singleton(team)); + this.waitOnApproval = new HashSet<>(waitOnApproval); Set alreadyAccepted = new HashSet<>(); - activeRequests.put(player, this); + enquirer.ifPlayer(player -> playerRequests.put(player, this)); + activeRequests.add(this); for(FightTeam t : waitOnApproval) { FightPlayer leader = t.getLeader(); if(leader == null) @@ -74,14 +97,14 @@ public class JoinRequest { if(leader.getEntity() == null) continue; - leader.ifPlayer(leaderPlayer -> FightSystem.getMessage().sendPrefixless("JOIN_REQUEST_NOTIFICATION", leaderPlayer, "REQUESTS", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/requests"), player.getName(), team.getColoredName())); + leader.ifPlayer(leaderPlayer -> FightSystem.getMessage().sendPrefixless("JOIN_REQUEST_NOTIFICATION", leaderPlayer, "REQUESTS", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/requests"), enquirer.name(), team.getColoredName())); leader.ifAI(ai -> { - if(ai.acceptJoinRequest(player, team)) + if(ai.acceptJoinRequest(enquirer, team)) alreadyAccepted.add(t); }); } - FightSystem.getMessage().sendPrefixless("JOIN_REQUEST_CONFIRMATION", player, ChatMessageType.ACTION_BAR); + enquirer.ifPlayer(player -> FightSystem.getMessage().sendPrefixless("JOIN_REQUEST_CONFIRMATION", player, ChatMessageType.ACTION_BAR)); alreadyAccepted.forEach(this::accept); } @@ -93,18 +116,26 @@ public class JoinRequest { waitOnApproval.remove(acceptor); if(waitOnApproval.isEmpty()) { - team.addMember(player); - activeRequests.remove(player); + enquirer.ifPlayer(team::addMember); + enquirer.ifAI(manager -> manager.join(team)); + close(); } } public void decline(FightTeam declinor) { - FightSystem.getMessage().sendPrefixless("REQUEST_YOUR_DECLINED", player, ChatMessageType.ACTION_BAR); - waitOnApproval.forEach(t -> t.broadcast("REQUEST_DECLINED", player.getName())); - silentDecline(); + enquirer.ifPlayer(player -> FightSystem.getMessage().sendPrefixless("REQUEST_YOUR_DECLINED", player, ChatMessageType.ACTION_BAR)); + waitOnApproval.forEach(t -> t.broadcast("REQUEST_DECLINED", enquirer.name())); + close(); } - public void silentDecline() { - activeRequests.remove(player); + public void close() { + enquirer.ifPlayer(playerRequests::remove); + activeRequests.remove(this); + } + + public interface Enquirer { + String name(); + void ifPlayer(Consumer function); + void ifAI(Consumer function); } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/JoinRequestListener.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/JoinRequestListener.java index 1ed3fe8b..45121cf7 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/JoinRequestListener.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/JoinRequestListener.java @@ -69,6 +69,6 @@ public class JoinRequestListener implements Listener { public void onLeave(PlayerQuitEvent event) { JoinRequest request = JoinRequest.get(event.getPlayer()); if(request != null) - request.silentDecline(); + request.close(); } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java index f77c1904..889c3c1c 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java @@ -43,6 +43,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -70,7 +71,7 @@ public class Recording implements Listener { return stack; } - public static boolean isNotSent(Player p){ + public static boolean isNotSent(LivingEntity p){ FightPlayer fp = Fight.getFightPlayer(p); return fp == null || !fp.isLiving() || FightState.getFightState() == FightState.SPECTATE; } @@ -193,10 +194,10 @@ public class Recording implements Listener { @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onEntityDamage(EntityDamageEvent e) { - if(e.getEntityType() != EntityType.PLAYER) + if(!e.getEntityType().isAlive()) return; - Player p = (Player) e.getEntity(); + LivingEntity p = (LivingEntity) e.getEntity(); if(isNotSent(p)) return; @@ -208,10 +209,10 @@ public class Recording implements Listener { @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onEntityCombust(EntityCombustEvent e) { - if(e.getEntityType() != EntityType.PLAYER) + if(!e.getEntityType().isAlive()) return; - Player p = (Player) e.getEntity(); + LivingEntity p = (LivingEntity) e.getEntity(); if(isNotSent(p)) return; diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java index d57a29b9..73821e6f 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java @@ -204,7 +204,7 @@ public interface Recorder { write(0x0a, e.getEntityId(), start, offHand); } - default void damageAnimation(Player p) { + default void damageAnimation(LivingEntity p) { write(0x0b, p.getEntityId()); } From d5398cbde2e1ca61a4ed00837121d761660685d5 Mon Sep 17 00:00:00 2001 From: Chaos Date: Thu, 22 Aug 2024 11:17:17 +0200 Subject: [PATCH 04/37] Remove redundant checks --- .../src/de/steamwar/velocitycore/discord/DiscordBot.java | 2 -- .../steamwar/velocitycore/discord/channels/DiscordChatRoom.java | 2 -- .../velocitycore/discord/listeners/DiscordTicketHandler.java | 2 -- 3 files changed, 6 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java index 5f770366..5a80a04f 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java @@ -149,8 +149,6 @@ public class DiscordBot { announcementChannel = new DiscordChannel(config.channel("announcement")) { @Override public void received(MessageReceivedEvent event) { - if (!event.isFromGuild()) return; - Chatter.broadcast().system("ALERT", event.getMessage().getContentDisplay()); } }; diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChatRoom.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChatRoom.java index 7aec1362..ce54b2d5 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChatRoom.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChatRoom.java @@ -41,8 +41,6 @@ public class DiscordChatRoom extends DiscordChannel { @Override public void received(MessageReceivedEvent event) { - if (!event.isFromGuild()) return; - SteamwarUser user = SteamwarUser.get(event.getAuthor().getIdLong()); if (user == null || event.getMessage().getContentRaw().length() > 250 || user.isPunished(Punishment.PunishmentType.Ban) || user.isPunished(Punishment.PunishmentType.Mute)) { event.getMessage().delete().queue(); diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java index e5cabd91..af36de97 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java @@ -131,8 +131,6 @@ public class DiscordTicketHandler extends ListenerAdapter { @Override public void onMessageReceived(@NotNull MessageReceivedEvent event) { - if (!event.isFromGuild()) return; - MessageChannel channel = event.getChannel(); if( channel instanceof TextChannel textChannel && From ea929e06157af95dc0afc02d0a96de2f7270dc43 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 25 Aug 2024 08:04:22 +0200 Subject: [PATCH 05/37] Hotfix Laufbau BoundingBoxLoader --- .../BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 0b1b160c..0d5fa43c 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -25,6 +25,7 @@ import de.steamwar.bausystem.configplayer.ConfigConverter; import de.steamwar.bausystem.features.gui.BauGUI; import de.steamwar.bausystem.features.script.lua.SteamWarLuaPlugin; import de.steamwar.bausystem.features.script.lua.libs.LuaLib; +import de.steamwar.bausystem.features.slaves.laufbau.BoundingBoxLoader; import de.steamwar.bausystem.features.slaves.panzern.Panzern; import de.steamwar.bausystem.features.slaves.panzern.PanzernAlgorithm; import de.steamwar.bausystem.features.tpslimit.TPSFreezeUtils; @@ -184,6 +185,9 @@ public class BauSystem extends JavaPlugin { if (any instanceof ConfigConverter) { Config.addConfigConverter((ConfigConverter) any); } + if (any instanceof BoundingBoxLoader) { + ((BoundingBoxLoader) any).load(); + } }); instances.forEach((clazz, o) -> { From c61c2d808711100d3b1af5689f5b1932e72f10ac Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 25 Aug 2024 15:34:07 +0200 Subject: [PATCH 06/37] Fix output on to small/large speed value --- .../src/de/steamwar/bausystem/features/util/SpeedCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java index 31308830..b73f68d5 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java @@ -41,9 +41,9 @@ public class SpeedCommand extends SWCommand { public void speedCommand(Player p, float speed) { speed = speed / 10F; if (speed < -1F) { - BauSystem.MESSAGE.send("SPEED_TOO_SMALL", p, speed); + BauSystem.MESSAGE.send("SPEED_TOO_SMALL", p, speed * 10); } else if (speed > 1F) { - BauSystem.MESSAGE.send("SPEED_TOO_HIGH", p, speed); + BauSystem.MESSAGE.send("SPEED_TOO_HIGH", p, speed * 10); } else { p.setFlySpeed(speed); p.setWalkSpeed(Math.min(speed + 0.1F, 1F)); From c8381413a34cb49bb9b088d5da82849e6cbd12e5 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 25 Aug 2024 15:46:03 +0200 Subject: [PATCH 07/37] Add SimulatorCommand.rename --- .../BauSystem_Main/src/BauSystem.properties | 2 ++ .../BauSystem_Main/src/BauSystem_de.properties | 2 ++ .../features/simulator/SimulatorCommand.java | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/BauSystem/BauSystem_Main/src/BauSystem.properties b/BauSystem/BauSystem_Main/src/BauSystem.properties index 67a16a47..7cafc797 100644 --- a/BauSystem/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem/BauSystem_Main/src/BauSystem.properties @@ -271,6 +271,7 @@ SIMULATOR_CHANGE_HELP=§8/§esimulator change §8-§7 Change your simulator wand SIMULATOR_DELETE_HELP=§8/§esimulator delete §8[§7name§8] §8-§7 Deletes the simulator SIMULATOR_START_HELP=§8/§esimulator start §8[§7name§8] §8-§7 Starts the simulator SIMULATOR_COPY_HELP=§8/§esimulator copy §8[§7to-copy§8] §8[§7name§8] §8-§7 Copy the simulator +SIMULATOR_RENAME_HELP=§8/§esimulator rename §8[§7to-rename§8] §8[§7name§8] §8-§7 Rename the simulator SIMULATOR_GUI_ITEM_NAME=§eTNT Simulator SIMULATOR_NO_SIM_IN_HAND=§cNo simulator item selected SIMULATOR_GUI_SELECT_SIM=Simulator selection @@ -307,6 +308,7 @@ SIMULATOR_POSITION_Z=§7z-Position SIMULATOR_BACK=§eBack SIMULATOR_GUI_TOTAL_TNT=§7Total TNT§8: §e{0} SIMULATOR_DELETED=§cSimulator deleted +SIMULATOR_RENAMED=§cSimulator renamed ## GUI SIMULATOR_POSITION_EDIT=§eEdit position SIMULATOR_POSITION_ADD=§eSet position diff --git a/BauSystem/BauSystem_Main/src/BauSystem_de.properties b/BauSystem/BauSystem_Main/src/BauSystem_de.properties index 4013f3b2..77b31259 100644 --- a/BauSystem/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem/BauSystem_Main/src/BauSystem_de.properties @@ -254,6 +254,7 @@ SIMULATOR_CHANGE_HELP=§8/§esimulator change §8-§7 Wechsel zu einem anderen S SIMULATOR_DELETE_HELP=§8/§esimulator delete §8[§7name§8] §8-§7 Löscht den Simulator SIMULATOR_START_HELP=§8/§esimulator start §8[§7name§8] §8-§7 Startet die Simulation SIMULATOR_COPY_HELP=§8/§esimulator copy §8[§7to-copy§8] §8[§7name§8] §8-§7 Kopiert einen Simulator +SIMULATOR_RENAME_HELP=§8/§esimulator rename §8[§7to-copy§8] §8[§7name§8] §8-§7 Benennt einen Simulator um SIMULATOR_GUI_ITEM_NAME=§eTNT Simulator SIMULATOR_NO_SIM_IN_HAND=§cKein Simulator Item gewählt SIMULATOR_GUI_SELECT_SIM=Simulator wählen @@ -290,6 +291,7 @@ SIMULATOR_POSITION_Z=§7z-Position SIMULATOR_BACK=§eZurück SIMULATOR_GUI_TOTAL_TNT=§7Gesamt TNT§8: §e{0} SIMULATOR_DELETED=§cSimulator gelöscht +SIMULATOR_RENAMED=§cSimulator umbenannt ## GUI SIMULATOR_POSITION_EDIT=§ePosition bearbeiten SIMULATOR_POSITION_ADD=§ePosition setzen diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java index 06af3e68..199e8952 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java @@ -88,6 +88,24 @@ public class SimulatorCommand extends SWCommand { SimulatorExecutor.run(simulator); } + @Register(value = "rename", description = "SIMULATOR_RENAME_HELP") + public void rename(@Validator Player p, @ErrorMessage("SIMULATOR_NOT_EXISTS") Simulator simulator, String name) { + if (SimulatorStorage.getSimulator(name) != null) { + BauSystem.MESSAGE.send("SIMULATOR_NAME_ALREADY_EXISTS", p); + return; + } + if (!name.matches("[a-zA-Z_0-9-]+")) { + BauSystem.MESSAGE.send("SIMULATOR_NAME_INVALID", p); + return; + } + if (SimulatorStorage.copy(simulator, name)) { + SimulatorStorage.delete(simulator); + BauSystem.MESSAGE.send("SIMULATOR_RENAMED", p); + } else { + BauSystem.MESSAGE.send("SIMULATOR_ERROR_COPY", p); + } + } + @ClassMapper(value = Simulator.class, local = true) public TypeMapper allSimulators() { return new TypeMapper<>() { From a25e55ffdfd60cf1bebb4cb2ef92660be836741e Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 25 Aug 2024 15:49:21 +0200 Subject: [PATCH 08/37] Fix Loader wait time to be 2 gameticks when 1 is selected --- .../src/de/steamwar/bausystem/features/loader/Loader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java index d8489a0f..fee6fdc6 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java @@ -90,7 +90,7 @@ public class Loader implements Listener { while (currentElement < elements.size()) { LoaderElement element = elements.get(currentElement); currentElement++; - element.execute(delay -> waitTime = delay); + element.execute(delay -> waitTime = delay - 1); if (waitTime > 0) { if (element instanceof LoaderTNT) currentElement--; return; From 9e2f2748b67b8c688a3b3b623c3d420773aaaade Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Mon, 26 Aug 2024 07:42:47 +0200 Subject: [PATCH 09/37] BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java aktualisiert --- .../steamwar/bausystem/features/util/SpeedCommand.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java index b73f68d5..c8a6d2de 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java @@ -39,12 +39,12 @@ public class SpeedCommand extends SWCommand { @Register public void speedCommand(Player p, float speed) { - speed = speed / 10F; - if (speed < -1F) { - BauSystem.MESSAGE.send("SPEED_TOO_SMALL", p, speed * 10); - } else if (speed > 1F) { - BauSystem.MESSAGE.send("SPEED_TOO_HIGH", p, speed * 10); + if (speed < -10F) { + BauSystem.MESSAGE.send("SPEED_TOO_SMALL", p, speed); + } else if (speed > 10F) { + BauSystem.MESSAGE.send("SPEED_TOO_HIGH", p, speed); } else { + speed = speed / 10F; p.setFlySpeed(speed); p.setWalkSpeed(Math.min(speed + 0.1F, 1F)); BauSystem.MESSAGE.send("SPEED_CURRENT", p, (p.getFlySpeed() * 10F)); From 6496f33a9e56f16d8f1d3acb8b4f0cace1f0dc5a Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Mon, 26 Aug 2024 07:44:54 +0200 Subject: [PATCH 10/37] Fix argument name of rename command --- BauSystem/BauSystem_Main/src/BauSystem_de.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem/BauSystem_Main/src/BauSystem_de.properties b/BauSystem/BauSystem_Main/src/BauSystem_de.properties index 77b31259..ca5c67d8 100644 --- a/BauSystem/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem/BauSystem_Main/src/BauSystem_de.properties @@ -254,7 +254,7 @@ SIMULATOR_CHANGE_HELP=§8/§esimulator change §8-§7 Wechsel zu einem anderen S SIMULATOR_DELETE_HELP=§8/§esimulator delete §8[§7name§8] §8-§7 Löscht den Simulator SIMULATOR_START_HELP=§8/§esimulator start §8[§7name§8] §8-§7 Startet die Simulation SIMULATOR_COPY_HELP=§8/§esimulator copy §8[§7to-copy§8] §8[§7name§8] §8-§7 Kopiert einen Simulator -SIMULATOR_RENAME_HELP=§8/§esimulator rename §8[§7to-copy§8] §8[§7name§8] §8-§7 Benennt einen Simulator um +SIMULATOR_RENAME_HELP=§8/§esimulator rename §8[§7to-rename§8] §8[§7name§8] §8-§7 Benennt einen Simulator um SIMULATOR_GUI_ITEM_NAME=§eTNT Simulator SIMULATOR_NO_SIM_IN_HAND=§cKein Simulator Item gewählt SIMULATOR_GUI_SELECT_SIM=Simulator wählen From 5f92d4c68c74b1691bc7a7f0404e4741e40464ce Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Tue, 27 Aug 2024 20:16:30 +0200 Subject: [PATCH 11/37] Fix Loader wait time to be 2 gameticks when 1 is selected --- .../src/de/steamwar/bausystem/features/loader/Loader.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java index fee6fdc6..0ce38b9a 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java @@ -90,9 +90,10 @@ public class Loader implements Listener { while (currentElement < elements.size()) { LoaderElement element = elements.get(currentElement); currentElement++; - element.execute(delay -> waitTime = delay - 1); + element.execute(delay -> waitTime = delay); if (waitTime > 0) { if (element instanceof LoaderTNT) currentElement--; + waitTime--; return; } } From ac25dea08ac1767a99bf4924db3677377ddc6cff Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 29 Aug 2024 11:32:34 +0200 Subject: [PATCH 12/37] Fix PR stuff --- .../BauSystem_Main/src/BauSystem.properties | 2 +- .../src/BauSystem_de.properties | 2 +- .../features/simulator/SimulatorCommand.java | 39 +++++++++---------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/BauSystem.properties b/BauSystem/BauSystem_Main/src/BauSystem.properties index 7cafc797..c9116dce 100644 --- a/BauSystem/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem/BauSystem_Main/src/BauSystem.properties @@ -308,7 +308,7 @@ SIMULATOR_POSITION_Z=§7z-Position SIMULATOR_BACK=§eBack SIMULATOR_GUI_TOTAL_TNT=§7Total TNT§8: §e{0} SIMULATOR_DELETED=§cSimulator deleted -SIMULATOR_RENAMED=§cSimulator renamed +SIMULATOR_RENAMED=§cSimulator renamed from {0} to {1} ## GUI SIMULATOR_POSITION_EDIT=§eEdit position SIMULATOR_POSITION_ADD=§eSet position diff --git a/BauSystem/BauSystem_Main/src/BauSystem_de.properties b/BauSystem/BauSystem_Main/src/BauSystem_de.properties index 77b31259..04588bc9 100644 --- a/BauSystem/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem/BauSystem_Main/src/BauSystem_de.properties @@ -291,7 +291,7 @@ SIMULATOR_POSITION_Z=§7z-Position SIMULATOR_BACK=§eZurück SIMULATOR_GUI_TOTAL_TNT=§7Gesamt TNT§8: §e{0} SIMULATOR_DELETED=§cSimulator gelöscht -SIMULATOR_RENAMED=§cSimulator umbenannt +SIMULATOR_RENAMED=§cSimulator von {0} zu {1} umbenannt ## GUI SIMULATOR_POSITION_EDIT=§ePosition bearbeiten SIMULATOR_POSITION_ADD=§ePosition setzen diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java index 199e8952..de0c4b74 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java @@ -20,7 +20,6 @@ package de.steamwar.bausystem.features.simulator; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.execute.SimulatorExecutor; @@ -63,15 +62,7 @@ public class SimulatorCommand extends SWCommand { } @Register(value = "copy", description = "SIMULATOR_COPY_HELP") - public void copy(@Validator Player p, @ErrorMessage("SIMULATOR_NOT_EXISTS") Simulator simulator, String name) { - if (SimulatorStorage.getSimulator(name) != null) { - BauSystem.MESSAGE.send("SIMULATOR_NAME_ALREADY_EXISTS", p); - return; - } - if (!name.matches("[a-zA-Z_0-9-]+")) { - BauSystem.MESSAGE.send("SIMULATOR_NAME_INVALID", p); - return; - } + public void copy(@Validator Player p, @ErrorMessage("SIMULATOR_NOT_EXISTS") Simulator simulator, @Validator("simulatorName") String name) { if (!SimulatorStorage.copy(simulator, name)) { BauSystem.MESSAGE.send("SIMULATOR_ERROR_COPY", p); } @@ -89,18 +80,11 @@ public class SimulatorCommand extends SWCommand { } @Register(value = "rename", description = "SIMULATOR_RENAME_HELP") - public void rename(@Validator Player p, @ErrorMessage("SIMULATOR_NOT_EXISTS") Simulator simulator, String name) { - if (SimulatorStorage.getSimulator(name) != null) { - BauSystem.MESSAGE.send("SIMULATOR_NAME_ALREADY_EXISTS", p); - return; - } - if (!name.matches("[a-zA-Z_0-9-]+")) { - BauSystem.MESSAGE.send("SIMULATOR_NAME_INVALID", p); - return; - } + public void rename(@Validator Player p, @ErrorMessage("SIMULATOR_NOT_EXISTS") Simulator simulator, @Validator("simulatorName") String name) { + String oldName = simulator.getName(); if (SimulatorStorage.copy(simulator, name)) { SimulatorStorage.delete(simulator); - BauSystem.MESSAGE.send("SIMULATOR_RENAMED", p); + BauSystem.MESSAGE.send("SIMULATOR_RENAMED", p, oldName, name); } else { BauSystem.MESSAGE.send("SIMULATOR_ERROR_COPY", p); } @@ -120,4 +104,19 @@ public class SimulatorCommand extends SWCommand { } }; } + + @Validator(value = "simulatorName", local = true) + public TypeValidator simulatorName() { + return (commandSender, name, messageSender) -> { + if (SimulatorStorage.getSimulator(name) != null) { + messageSender.send("SIMULATOR_NAME_ALREADY_EXISTS"); + return false; + } + if (!name.matches("[a-zA-Z_0-9-]+")) { + messageSender.send("SIMULATOR_NAME_INVALID"); + return false; + } + return true; + }; + } } From e1769a42f4f470de2f991b73df4afe157b16978e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 29 Aug 2024 13:58:27 +0200 Subject: [PATCH 13/37] DummyAI only Test arenas --- .../src/de/steamwar/fightsystem/ai/AIManager.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIManager.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIManager.java index 5b9abf4b..2cb13f65 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIManager.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIManager.java @@ -20,6 +20,8 @@ package de.steamwar.fightsystem.ai; import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.fight.FightTeam; import lombok.AllArgsConstructor; import lombok.Getter; @@ -33,7 +35,7 @@ import java.util.stream.Collectors; @AllArgsConstructor public class AIManager { private static final List AIs = Arrays.asList( - new AIManager(DummyAI.class, Material.STONE, () -> true) + new AIManager(DummyAI.class, Material.STONE, () -> ArenaMode.Test.contains(Config.mode)) ); public static List availableAIs() { From 52302dd284310a92b917a92c26540533b746534f Mon Sep 17 00:00:00 2001 From: TheBreadBeard Date: Thu, 29 Aug 2024 22:09:43 +0200 Subject: [PATCH 14/37] Add DiscordTicketType.SCHEMATIC --- VelocityCore/src/de/steamwar/messages/BungeeCore.properties | 1 + .../src/de/steamwar/messages/BungeeCore_de.properties | 1 + .../de/steamwar/velocitycore/discord/DiscordTicketType.java | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties index 5bb5238b..2535aaf3 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties @@ -739,6 +739,7 @@ DC_TICKETINTRO_IDEA=Describe your idea as detailed as possible. Hereto belongs: 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_TICKETINTRO_SCHEMATIC=Please answer the following questions as precisely as possible for the locking of the Schematic and, if possible, add evidence:\n - Which player(s)?\n - On which Arena Server\n - At what time?\n - Rules which the Schematic violates (rules/code of conduct) DC_TICKET_CLOSE=Close DC_SCHEMUPLOAD_NOPERM=You\'re not allowed to upload schematics. diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties index edc46c77..786ad244 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties @@ -692,6 +692,7 @@ DC_TICKETINTRO_IDEA=Beschreibe deine Idee möglichst detailiert. Hierzu gehört: 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_TICKETINTRO_SCHEMATIC=Bitte beantworte für die sperrung der Schematic möglichst genau folgende Fragen und füge nach Möglichkeit Beweismaterial hinzu:\n - Welche(r) Spieler?\n - Auf welchem Arena Server\n - Zu welchem Zeitpunkt?\n - Regeln, gegen welche die Schematic verstößt (Regelwerk/ Verhaltensrichtlinien) DC_TICKET_CLOSE=Schließen DC_SCHEMUPLOAD_NOPERM=Du darfst keine Schematics hochladen. diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordTicketType.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordTicketType.java index 8cb67e6e..f9838e34 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordTicketType.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordTicketType.java @@ -30,7 +30,9 @@ public enum DiscordTicketType { IDEA("U+1F4A1", "Feature vorschlagen", ButtonStyle.SUCCESS), BUG("U+1F41B", "Bug melden", ButtonStyle.SECONDARY), QUESTION("U+2753", "Fragen", ButtonStyle.PRIMARY), - APPEAL("U+1F528", "Entbannungsantrag", ButtonStyle.SECONDARY); + APPEAL("U+1F528", "Entbannungsantrag", ButtonStyle.SECONDARY), + SCHEMATIC("U+1F4BE", "Schematic melden", ButtonStyle.DANGER); + private final String emoji; private final String label; From 94502a15670d439fbddaf50bb8161730e37bca4c Mon Sep 17 00:00:00 2001 From: TheBreadBeard Date: Thu, 29 Aug 2024 22:40:05 +0200 Subject: [PATCH 15/37] Add npc chat messages --- LobbySystem/src/de/steamwar/lobby/LobbySystem.properties | 8 ++++++-- .../src/de/steamwar/lobby/LobbySystem_de.properties | 8 ++++++-- LobbySystem/src/de/steamwar/lobby/team/TeamPlayer.java | 5 ++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/LobbySystem/src/de/steamwar/lobby/LobbySystem.properties b/LobbySystem/src/de/steamwar/lobby/LobbySystem.properties index 4530aaaf..b1c5ccb9 100644 --- a/LobbySystem/src/de/steamwar/lobby/LobbySystem.properties +++ b/LobbySystem/src/de/steamwar/lobby/LobbySystem.properties @@ -4,8 +4,12 @@ DATE=........ COMMAND_HELP_HEAD=§7---=== (§e{0}§7) ===--- # ServerTeamNPC's -NPC_CHAT_1 = §fHello, I''m {0} and I''m a(n) {1}§f. -NPC_CHAT_2 = §fWelcome on §eSteam§8War§f, have fun. +NPC_CHAT_0 = §fHello, I''m {0} and I''m a(n) {1}§f. +NPC_CHAT_1 = §fWelcome on §eSteam§8War§f, have fun. +NPC_CHAT_2 = §eSteam§8War§f was established in 2019. +NPC_CHAT_3 = &fBecome a part of our team by applying via our Discord server (https://steamwar.de/discord). +NPC_CHAT_4 = &fYou can develop your own buildserver features with our Lua script system or activate public ones via our script lybrary. +NPC_CHAT_5 = &fThere are many secrets to discover in this lobby. # Portal Command PORTAL_COMMAND_LIST_HELP = §8/§7portal §elist §8- §7Lists all portals diff --git a/LobbySystem/src/de/steamwar/lobby/LobbySystem_de.properties b/LobbySystem/src/de/steamwar/lobby/LobbySystem_de.properties index 969270ee..8c126add 100644 --- a/LobbySystem/src/de/steamwar/lobby/LobbySystem_de.properties +++ b/LobbySystem/src/de/steamwar/lobby/LobbySystem_de.properties @@ -4,8 +4,12 @@ DATE=........ COMMAND_HELP_HEAD=§7---=== (§e{0}§7) ===--- # ServerTeamNPC's -NPC_CHAT_1 = §fHallo, ich bin {0} und bin ein {1}§f. -NPC_CHAT_2 = §fWillkommen auf §eSteam§8War§f, viel Spaß dir. +NPC_CHAT_0 = §fHallo, ich bin {0} und bin ein {1}§f. +NPC_CHAT_1 = §fWillkommen auf §eSteam§8War§f, viel Spaß dir. +NPC_CHAT_2 = §eSteam§8War§f gibt es seit 2019. +NPC_CHAT_3 = &fBewerbe dich gerne für unser Team über unseren Discord-Server (https://steamwar.de/discord). +NPC_CHAT_4 = &fDu kannst mit unserm Lua Script-System deine eigenen Bau Features programmieren oder öffentliche Skripte über die Script-Lybrary aktivieren. +NPC_CHAT_5 = &fAuf dieser Lobby sind so einige secrets versteckt. # Portal Command PORTAL_COMMAND_LIST_HELP = §8/§7portal §elist §8- §7Listet alle Portale auf diff --git a/LobbySystem/src/de/steamwar/lobby/team/TeamPlayer.java b/LobbySystem/src/de/steamwar/lobby/team/TeamPlayer.java index 296b1d6f..2142d6fe 100644 --- a/LobbySystem/src/de/steamwar/lobby/team/TeamPlayer.java +++ b/LobbySystem/src/de/steamwar/lobby/team/TeamPlayer.java @@ -149,8 +149,11 @@ public class TeamPlayer extends BasicListener { players.remove(event.getPlayer()); return; } + + int randomNum = random.nextInt(6); + String message = "NPC_Chat_" + randomNum; + SteamwarUser user = SteamwarUser.get(event.getRightClicked().getName()); - String message = strings.get(random.nextInt(strings.size())); UserPerm.Prefix prefix = user.prefix(); LobbySystem.getMessage().send(message, event.getPlayer(), event.getRightClicked().getName(), prefix.getColorCode() + prefix.getChatPrefix()); } From 04d9f38f7df3e7dc3c14fa4c8b1869fb75a6b3af Mon Sep 17 00:00:00 2001 From: TheBreadBeard Date: Thu, 29 Aug 2024 22:53:22 +0200 Subject: [PATCH 16/37] Add team changecolor command alias --- .../velocitycore/commands/TeamCommand.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/TeamCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/TeamCommand.java index 32b65e93..04225449 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/TeamCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/TeamCommand.java @@ -478,6 +478,21 @@ public class TeamCommand extends SWCommand { } @Register("color") + public void color(@Validator("isLeader") PlayerChatter sender) { + Team team = Team.get(sender.user().getTeam()); + + if(notDuringEvent(sender)) + return; + + SWListInv inv = new SWListInv<>(sender, new Message("TEAM_COLOR_TITLE"), COLOR_CODES.entrySet().stream().map(entry -> new SWListInv.SWListEntry<>(new SWItem(new Message("PLAIN_STRING", "§" + entry.getKey() + team.getTeamKuerzel()), entry.getValue()), entry.getKey())).toList(), (click, element) -> {}); + inv.setCallback((click, element) -> { + inv.close(); + team.setTeamColor(element); + }); + inv.open(); + } + + @Register("changecolor") public void changeColor(@Validator("isLeader") PlayerChatter sender) { Team team = Team.get(sender.user().getTeam()); From 1f908134a13a9939807196f5f966cf940b67ba83 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Fri, 30 Aug 2024 08:31:29 +0200 Subject: [PATCH 17/37] Hotfix DiscordBot --- .../velocitycore/discord/DiscordBot.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java index 5a80a04f..0c30a2ad 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java @@ -30,8 +30,14 @@ import de.steamwar.velocitycore.discord.listeners.DiscordTeamEvent; import de.steamwar.velocitycore.discord.listeners.DiscordTicketHandler; import de.steamwar.velocitycore.discord.util.AuthManager; import lombok.Getter; -import net.dv8tion.jda.api.*; -import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.JDABuilder; +import net.dv8tion.jda.api.OnlineStatus; +import net.dv8tion.jda.api.entities.Activity; +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.exceptions.ErrorResponseException; @@ -136,13 +142,19 @@ public class DiscordBot { if(event.getComponentId().equals("auth")) event.reply("Gebe innerhalb der nächsten 10 Minuten ``/verify " + AuthManager.createDiscordAuthToken(event.getUser()) + "`` auf dem Minecraft Server ein").setEphemeral(true).queue(); }); + List actionRows = new ArrayList<>(); + List