geforkt von SteamWar/BungeeCore
Add IngameChatListener
Add ServerTeamchatCommand
Dieser Commit ist enthalten in:
Ursprung
daa800a182
Commit
268fa2d508
@ -22,20 +22,16 @@ package de.steamwar.bungeecore.bot;
|
||||
import de.steamwar.bungeecore.BungeeCore;
|
||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||
import de.steamwar.bungeecore.bot.events.EventManager;
|
||||
import de.steamwar.bungeecore.bot.listeners.AnnouncementListener;
|
||||
import de.steamwar.bungeecore.bot.listeners.DiscordAuthListener;
|
||||
import de.steamwar.bungeecore.bot.listeners.DiscordTicketListener;
|
||||
import de.steamwar.bungeecore.bot.listeners.RolesInteractionButtonListener;
|
||||
import de.steamwar.bungeecore.bot.util.DiscordTicketMessage;
|
||||
import de.steamwar.bungeecore.bot.listeners.*;
|
||||
import de.steamwar.bungeecore.bot.util.DiscordRolesMessage;
|
||||
import de.steamwar.bungeecore.bot.util.DiscordRulesMessage;
|
||||
import de.steamwar.bungeecore.bot.util.DiscordTicketMessage;
|
||||
import de.steamwar.bungeecore.sql.Event;
|
||||
import lombok.Getter;
|
||||
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.Member;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.dv8tion.jda.api.utils.MemberCachePolicy;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
@ -54,6 +50,12 @@ public class SteamwarDiscordBot {
|
||||
@Getter
|
||||
private AnnouncementListener announcementListener;
|
||||
|
||||
@Getter
|
||||
private IngameChatListener ingameChatListener;
|
||||
|
||||
@Getter
|
||||
private ServerTeamChatListener serverTeamChatListener;
|
||||
|
||||
@Getter
|
||||
private final JDA jda;
|
||||
|
||||
@ -86,6 +88,8 @@ public class SteamwarDiscordBot {
|
||||
new DiscordTicketListener();
|
||||
new DiscordAuthListener();
|
||||
announcementListener = new AnnouncementListener();
|
||||
ingameChatListener = new IngameChatListener();
|
||||
serverTeamChatListener = new ServerTeamChatListener();
|
||||
}
|
||||
|
||||
private int index = 0;
|
||||
|
@ -33,6 +33,8 @@ public class SteamwarDiscordBotConfig {
|
||||
public static String GUILD;
|
||||
public static String ANNOUNCEMENTS_CHANNEL;
|
||||
public static String EVENTS_CHANNEL;
|
||||
public static String INGAME_CHANNEL;
|
||||
public static String SERVER_TEAM_CHANNEL;
|
||||
public static String ROLES_CHANNEL;
|
||||
public static String ROLES_BASE_MESSAGE;
|
||||
public static String ROLES_ADDED;
|
||||
@ -55,6 +57,8 @@ public class SteamwarDiscordBotConfig {
|
||||
GUILD = config.getString("guild");
|
||||
ANNOUNCEMENTS_CHANNEL = config.getString("announcements-channel");
|
||||
EVENTS_CHANNEL = config.getString("events-channel");
|
||||
INGAME_CHANNEL = config.getString("ingame-channel");
|
||||
SERVER_TEAM_CHANNEL = config.getString("server-team-channel");
|
||||
Configuration rolesSection = config.getSection("roles-claim");
|
||||
ROLES_CHANNEL = rolesSection.getString("channel");
|
||||
ROLES_BASE_MESSAGE = rolesSection.getString("base");
|
||||
|
58
src/de/steamwar/bungeecore/bot/listeners/IngameChatListener.java
Normale Datei
58
src/de/steamwar/bungeecore/bot/listeners/IngameChatListener.java
Normale Datei
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bungeecore.bot.listeners;
|
||||
|
||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||
import de.steamwar.bungeecore.listeners.ChatListener;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class IngameChatListener extends BasicDiscordListener {
|
||||
|
||||
@Override
|
||||
public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
|
||||
if (!event.getChannel().getId().equals(SteamwarDiscordBotConfig.INGAME_CHANNEL)) {
|
||||
return;
|
||||
}
|
||||
if (event.getAuthor().isBot()) {
|
||||
return;
|
||||
}
|
||||
Member member = event.getMember();
|
||||
SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong());
|
||||
if (steamwarUser == null) {
|
||||
event.getMessage().delete().complete();
|
||||
} else {
|
||||
ChatListener.discordChat(steamwarUser, event.getMessage().getContentRaw());
|
||||
}
|
||||
}
|
||||
|
||||
public void send(String message) {
|
||||
TextChannel textChannel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.INGAME_CHANNEL);
|
||||
assert textChannel != null;
|
||||
MessageBuilder messageBuilder = new MessageBuilder();
|
||||
messageBuilder.append(message.replace("&", ""));
|
||||
textChannel.sendMessage(messageBuilder.build()).complete();
|
||||
}
|
||||
}
|
59
src/de/steamwar/bungeecore/bot/listeners/ServerTeamChatListener.java
Normale Datei
59
src/de/steamwar/bungeecore/bot/listeners/ServerTeamChatListener.java
Normale Datei
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bungeecore.bot.listeners;
|
||||
|
||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||
import de.steamwar.bungeecore.commands.ServerTeamchatCommand;
|
||||
import de.steamwar.bungeecore.listeners.ChatListener;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ServerTeamChatListener extends BasicDiscordListener {
|
||||
|
||||
@Override
|
||||
public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
|
||||
if (!event.getChannel().getId().equals(SteamwarDiscordBotConfig.SERVER_TEAM_CHANNEL)) {
|
||||
return;
|
||||
}
|
||||
if (event.getAuthor().isBot()) {
|
||||
return;
|
||||
}
|
||||
Member member = event.getMember();
|
||||
SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong());
|
||||
if (steamwarUser == null) {
|
||||
event.getMessage().delete().complete();
|
||||
} else {
|
||||
ServerTeamchatCommand.sendToTeam(event.getMessage().getContentRaw(), steamwarUser);
|
||||
}
|
||||
}
|
||||
|
||||
public void send(String message) {
|
||||
TextChannel textChannel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.SERVER_TEAM_CHANNEL);
|
||||
assert textChannel != null;
|
||||
MessageBuilder messageBuilder = new MessageBuilder();
|
||||
messageBuilder.append(message.replace("&", ""));
|
||||
textChannel.sendMessage(messageBuilder.build()).complete();
|
||||
}
|
||||
}
|
@ -20,7 +20,9 @@
|
||||
package de.steamwar.bungeecore.commands;
|
||||
|
||||
import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||
import de.steamwar.bungeecore.listeners.ChatListener;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
@ -49,10 +51,20 @@ public class ServerTeamchatCommand extends BasicCommand {
|
||||
String msg = msgBuilder.toString();
|
||||
msg = ChatColor.translateAlternateColorCodes('&', msg);
|
||||
|
||||
SteamwarDiscordBot.instance().getServerTeamChatListener().send("<t:" + (System.currentTimeMillis() / 1000) + "> " + (player.getName() + "» " + msg).replaceAll("§[a-f0-9r]", ""));
|
||||
sendToTeam(msg, player);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendToTeam(String message, SteamwarUser sender){
|
||||
for (ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
|
||||
if ((target.hasPermission("bungeecore.teamchat"))
|
||||
&& target.getChatMode() == ProxiedPlayer.ChatMode.SHOWN){
|
||||
Message.sendPrefixless("STC_FORMAT", target, sender.getUserName(), ChatListener.parseAtMessage(message, "§r", target));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendToTeam(String message, ProxiedPlayer sender){
|
||||
for (ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
|
||||
if ((target.hasPermission("bungeecore.teamchat"))
|
||||
|
@ -20,6 +20,8 @@
|
||||
package de.steamwar.bungeecore.listeners;
|
||||
|
||||
import de.steamwar.bungeecore.*;
|
||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||
import de.steamwar.bungeecore.bot.listeners.IngameChatListener;
|
||||
import de.steamwar.bungeecore.commands.BauCommand;
|
||||
import de.steamwar.bungeecore.commands.TpCommand;
|
||||
import de.steamwar.bungeecore.comms.packets.PingPacket;
|
||||
@ -170,6 +172,27 @@ public class ChatListener extends BasicListener {
|
||||
}
|
||||
}
|
||||
|
||||
public static void discordChat(SteamwarUser user, String message){
|
||||
String name = user.getUserGroup().getColorCode() + user.getUserGroup().name() + " " + user.getUserName() + "§r";
|
||||
String chatcolor = user.getUserGroup().getChatColorCode();
|
||||
|
||||
if(user.getUserGroup() != UserGroup.Member || user.getTeam() == 12 || user.getTeam() == 285 || user.getTeam() == 54)
|
||||
message = ChatColor.translateAlternateColorCodes('&', message);
|
||||
|
||||
String msg = name + "§7»" + chatcolor + " " + message;
|
||||
if(user.getTeam() != 0){
|
||||
Team team = Team.get(user.getTeam());
|
||||
msg = "§" + team.getTeamColor() + team.getTeamKuerzel() + " §r" + msg;
|
||||
}
|
||||
|
||||
for(ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
|
||||
Subserver targetServer = Subserver.getSubserver(target);
|
||||
if(!(targetServer == null || targetServer.getType() != Servertype.ARENA || targetServer.getServer() != target.getServer().getInfo())) continue;
|
||||
|
||||
BungeeCore.send(target, ChatMessageType.CHAT, parseAtMessage(msg, chatcolor, target));
|
||||
}
|
||||
}
|
||||
|
||||
private void publicChat(SteamwarUser user, ProxiedPlayer sender, String message){
|
||||
String name = sender.getDisplayName();
|
||||
String chatcolor = user.getUserGroup().getChatColorCode();
|
||||
@ -183,6 +206,7 @@ public class ChatListener extends BasicListener {
|
||||
msg = "§" + team.getTeamColor() + team.getTeamKuerzel() + " §r" + msg;
|
||||
}
|
||||
|
||||
SteamwarDiscordBot.instance().getIngameChatListener().send("<t:" + (System.currentTimeMillis() / 1000) + "> " + msg.replaceAll("§[a-f0-9r]", ""));
|
||||
for(ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
|
||||
Subserver targetServer = Subserver.getSubserver(target);
|
||||
if(!(targetServer == null || targetServer.getType() != Servertype.ARENA || targetServer.getServer() != target.getServer().getInfo())) continue;
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren