geforkt von SteamWar/BungeeCore
Merge branch 'master' into Punishment++
# Conflicts: # src/de/steamwar/bungeecore/sql/SteamwarUser.java
Dieser Commit ist enthalten in:
Commit
b24c3d0d6b
@ -72,6 +72,8 @@ public class BungeeCore extends Plugin {
|
|||||||
public static final Map<String, String> serverPermissions = new HashMap<>();
|
public static final Map<String, String> serverPermissions = new HashMap<>();
|
||||||
public static final Map<String, String> commands = new HashMap<>();
|
public static final Map<String, String> commands = new HashMap<>();
|
||||||
|
|
||||||
|
private ErrorLogger errorLogger;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable(){
|
public void onEnable(){
|
||||||
getProxy().registerChannel("sw:bridge");
|
getProxy().registerChannel("sw:bridge");
|
||||||
@ -79,7 +81,7 @@ public class BungeeCore extends Plugin {
|
|||||||
setInstance(this);
|
setInstance(this);
|
||||||
loadConfig();
|
loadConfig();
|
||||||
|
|
||||||
new ErrorLogger();
|
errorLogger = new ErrorLogger();
|
||||||
new ConnectionListener();
|
new ConnectionListener();
|
||||||
new Forge();
|
new Forge();
|
||||||
new LabyMod();
|
new LabyMod();
|
||||||
@ -160,7 +162,11 @@ public class BungeeCore extends Plugin {
|
|||||||
}, 1, 1, TimeUnit.HOURS);
|
}, 1, 1, TimeUnit.HOURS);
|
||||||
|
|
||||||
if (SteamwarDiscordBotConfig.loaded) {
|
if (SteamwarDiscordBotConfig.loaded) {
|
||||||
|
try {
|
||||||
new SteamwarDiscordBot();
|
new SteamwarDiscordBot();
|
||||||
|
} catch (Throwable e) {
|
||||||
|
getLogger().log(Level.SEVERE, "Could not initialize discord bot", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +177,11 @@ public class BungeeCore extends Plugin {
|
|||||||
SteamwarDiscordBot.instance().getJda().awaitStatus(JDA.Status.SHUTDOWN);
|
SteamwarDiscordBot.instance().getJda().awaitStatus(JDA.Status.SHUTDOWN);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
|
} catch (Throwable e) {
|
||||||
|
getLogger().log(Level.SEVERE, "Could not shutdown discord bot", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errorLogger.unregister();
|
||||||
Statement.close();
|
Statement.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,10 @@ public class ErrorLogger extends Handler {
|
|||||||
Logger.getLogger("").addHandler(this);
|
Logger.getLogger("").addHandler(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void unregister(){
|
||||||
|
Logger.getLogger("").removeHandler(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void publish(LogRecord logRecord) {
|
public void publish(LogRecord logRecord) {
|
||||||
if(logRecord.getLevel().intValue() < Level.WARNING.intValue())
|
if(logRecord.getLevel().intValue() < Level.WARNING.intValue())
|
||||||
|
@ -27,7 +27,6 @@ import net.dv8tion.jda.api.entities.Emoji;
|
|||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
||||||
import net.dv8tion.jda.api.interactions.components.Button;
|
import net.dv8tion.jda.api.interactions.components.Button;
|
||||||
import net.md_5.bungee.api.scheduler.ScheduledTask;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -56,7 +55,7 @@ public class AuthManager {
|
|||||||
if (TOKENS.containsKey(code)) {
|
if (TOKENS.containsKey(code)) {
|
||||||
Member member = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).retrieveMemberById(TOKENS.get(code).longValue()).complete();
|
Member member = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).retrieveMemberById(TOKENS.get(code).longValue()).complete();
|
||||||
if(member == null) return null;
|
if(member == null) return null;
|
||||||
user.setDiscordId(member.getId());
|
user.setDiscordId(member.getIdLong());
|
||||||
MessageBuilder builder = new MessageBuilder();
|
MessageBuilder builder = new MessageBuilder();
|
||||||
builder.setContent(":white_check_mark: Dein Discord Konto wurde mit **" + user.getUserName() + "** verknüpft");
|
builder.setContent(":white_check_mark: Dein Discord Konto wurde mit **" + user.getUserName() + "** verknüpft");
|
||||||
builder.setActionRows(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389")), Button.danger("invalid", "Ich war das nicht")));
|
builder.setActionRows(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389")), Button.danger("invalid", "Ich war das nicht")));
|
||||||
|
@ -44,6 +44,7 @@ import javax.security.auth.login.LoginException;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class SteamwarDiscordBot {
|
public class SteamwarDiscordBot {
|
||||||
|
|
||||||
@ -54,13 +55,13 @@ public class SteamwarDiscordBot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private AnnouncementListener announcementListener;
|
private volatile AnnouncementListener announcementListener;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private IngameChatListener ingameChatListener;
|
private volatile IngameChatListener ingameChatListener;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private ServerTeamChatListener serverTeamChatListener;
|
private volatile ServerTeamChatListener serverTeamChatListener;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final JDA jda;
|
private final JDA jda;
|
||||||
@ -84,7 +85,11 @@ public class SteamwarDiscordBot {
|
|||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
activity();
|
activity();
|
||||||
|
} catch (Exception e) {
|
||||||
|
BungeeCore.get().getLogger().log(Level.SEVERE, "Could not set initial activity to discord", e);
|
||||||
|
}
|
||||||
EventManager.update();
|
EventManager.update();
|
||||||
SchematicsManager.update();
|
SchematicsManager.update();
|
||||||
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
|
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
|
||||||
@ -95,7 +100,6 @@ public class SteamwarDiscordBot {
|
|||||||
DiscordRolesMessage.sendMessage();
|
DiscordRolesMessage.sendMessage();
|
||||||
DiscordRulesMessage.sendMessage();
|
DiscordRulesMessage.sendMessage();
|
||||||
DiscordTicketMessage.sendMessage();
|
DiscordTicketMessage.sendMessage();
|
||||||
|
|
||||||
new RolesInteractionButtonListener();
|
new RolesInteractionButtonListener();
|
||||||
new DiscordTicketListener();
|
new DiscordTicketListener();
|
||||||
new DiscordAuthListener();
|
new DiscordAuthListener();
|
||||||
@ -104,7 +108,6 @@ public class SteamwarDiscordBot {
|
|||||||
ingameChatListener = new IngameChatListener();
|
ingameChatListener = new IngameChatListener();
|
||||||
serverTeamChatListener = new ServerTeamChatListener();
|
serverTeamChatListener = new ServerTeamChatListener();
|
||||||
new SlashCommandListener();
|
new SlashCommandListener();
|
||||||
|
|
||||||
jda.retrieveCommands().complete().forEach(command -> jda.deleteCommandById(command.getId()).queue());
|
jda.retrieveCommands().complete().forEach(command -> jda.deleteCommandById(command.getId()).queue());
|
||||||
|
|
||||||
Guild guild = jda.getGuildById(SteamwarDiscordBotConfig.GUILD);
|
Guild guild = jda.getGuildById(SteamwarDiscordBotConfig.GUILD);
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore.commands;
|
package de.steamwar.bungeecore.commands;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.BungeeCore;
|
||||||
import de.steamwar.bungeecore.Message;
|
import de.steamwar.bungeecore.Message;
|
||||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||||
import de.steamwar.bungeecore.listeners.ChatListener;
|
import de.steamwar.bungeecore.listeners.ChatListener;
|
||||||
@ -28,6 +29,8 @@ import net.md_5.bungee.api.CommandSender;
|
|||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class ServerTeamchatCommand extends BasicCommand {
|
public class ServerTeamchatCommand extends BasicCommand {
|
||||||
|
|
||||||
public ServerTeamchatCommand() {
|
public ServerTeamchatCommand() {
|
||||||
@ -51,7 +54,11 @@ public class ServerTeamchatCommand extends BasicCommand {
|
|||||||
String msg = msgBuilder.toString();
|
String msg = msgBuilder.toString();
|
||||||
msg = ChatColor.translateAlternateColorCodes('&', msg);
|
msg = ChatColor.translateAlternateColorCodes('&', msg);
|
||||||
|
|
||||||
|
try {
|
||||||
SteamwarDiscordBot.instance().getServerTeamChatListener().send("<t:" + (System.currentTimeMillis() / 1000) + "> " + (player.getName() + "» " + msg).replaceAll("§[a-f0-9r]", ""));
|
SteamwarDiscordBot.instance().getServerTeamChatListener().send("<t:" + (System.currentTimeMillis() / 1000) + "> " + (player.getName() + "» " + msg).replaceAll("§[a-f0-9r]", ""));
|
||||||
|
} catch (Exception e) {
|
||||||
|
BungeeCore.get().getLogger().log(Level.SEVERE, "Could not send stc message to discord", e);
|
||||||
|
}
|
||||||
sendToTeam(msg, player);
|
sendToTeam(msg, player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ import net.md_5.bungee.event.EventHandler;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class ChatListener extends BasicListener {
|
public class ChatListener extends BasicListener {
|
||||||
|
|
||||||
@ -150,7 +151,7 @@ public class ChatListener extends BasicListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!sender.hasPermission(ConnectionListener.TEAM_GROUP) && (e.getMessage().contains("http") || e.getMessage().contains("www"))){
|
if(!sender.hasPermission(ConnectionListener.TEAM_GROUP) && (e.getMessage().contains("http:") || e.getMessage().contains("https:") || e.getMessage().contains("www."))){
|
||||||
Message.send("CHAT_NO_LINKS", sender);
|
Message.send("CHAT_NO_LINKS", sender);
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
@ -203,7 +204,11 @@ public class ChatListener extends BasicListener {
|
|||||||
msg = "§" + team.getTeamColor() + team.getTeamKuerzel() + " §r" + msg;
|
msg = "§" + team.getTeamColor() + team.getTeamKuerzel() + " §r" + msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
SteamwarDiscordBot.instance().getIngameChatListener().send("<t:" + (System.currentTimeMillis() / 1000) + "> " + msg.replaceAll("§[a-f0-9r]", ""));
|
SteamwarDiscordBot.instance().getIngameChatListener().send("<t:" + (System.currentTimeMillis() / 1000) + "> " + msg.replaceAll("§[a-f0-9r]", ""));
|
||||||
|
} catch (Exception e) {
|
||||||
|
BungeeCore.get().getLogger().log(Level.SEVERE, "Could not send chat message to discord", e);
|
||||||
|
}
|
||||||
for(ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
|
for(ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
|
||||||
Subserver targetServer = Subserver.getSubserver(target);
|
Subserver targetServer = Subserver.getSubserver(target);
|
||||||
if(!(targetServer == null || targetServer.getType() != Servertype.ARENA || targetServer.getServer() != target.getServer().getInfo())) continue;
|
if(!(targetServer == null || targetServer.getType() != Servertype.ARENA || targetServer.getServer() != target.getServer().getInfo())) continue;
|
||||||
|
@ -40,7 +40,7 @@ public class Statement {
|
|||||||
Statement.user = user;
|
Statement.user = user;
|
||||||
Statement.password = password;
|
Statement.password = password;
|
||||||
try {
|
try {
|
||||||
con = DriverManager.getConnection(url + "?autoreconnect=true&useServerPrepStmts=true", user, password);
|
con = DriverManager.getConnection(url + "?autoReconnect=true&useServerPrepStmts=true", user, password);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
ProxyServer.getInstance().stop();
|
ProxyServer.getInstance().stop();
|
||||||
throw new SecurityException("Could not start SQL-Connection", e);
|
throw new SecurityException("Could not start SQL-Connection", e);
|
||||||
|
@ -63,7 +63,7 @@ public class SteamwarUser {
|
|||||||
private static final Map<String, SteamwarUser> usersByName = new HashMap<>();
|
private static final Map<String, SteamwarUser> usersByName = new HashMap<>();
|
||||||
private static final Map<UUID, SteamwarUser> usersByUUID = new HashMap<>();
|
private static final Map<UUID, SteamwarUser> usersByUUID = new HashMap<>();
|
||||||
private static final Map<Integer, SteamwarUser> usersById = new HashMap<>();
|
private static final Map<Integer, SteamwarUser> usersById = new HashMap<>();
|
||||||
private static final Map<String, SteamwarUser> usersByDiscord = new HashMap<>();
|
private static final Map<Long, SteamwarUser> usersByDiscord = new HashMap<>();
|
||||||
private static final InetAddress LIXFEL_DE;
|
private static final InetAddress LIXFEL_DE;
|
||||||
private static final String API_URL = "https://api.mojang.com/users/profiles/minecraft/";
|
private static final String API_URL = "https://api.mojang.com/users/profiles/minecraft/";
|
||||||
private static final JsonParser jsonParser = new JsonParser();
|
private static final JsonParser jsonParser = new JsonParser();
|
||||||
@ -75,7 +75,7 @@ public class SteamwarUser {
|
|||||||
private int team;
|
private int team;
|
||||||
private boolean leader;
|
private boolean leader;
|
||||||
private final Map<Punishment.PunishmentType, Punishment> punishments;
|
private final Map<Punishment.PunishmentType, Punishment> punishments;
|
||||||
private String discordId;
|
private Long discordId;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
@ -93,7 +93,10 @@ public class SteamwarUser {
|
|||||||
userGroup = UserGroup.getUsergroup(rs.getString("UserGroup"));
|
userGroup = UserGroup.getUsergroup(rs.getString("UserGroup"));
|
||||||
team = rs.getInt("Team");
|
team = rs.getInt("Team");
|
||||||
leader = rs.getBoolean("Leader");
|
leader = rs.getBoolean("Leader");
|
||||||
discordId = rs.getString("DiscordId");
|
discordId = rs.getLong("DiscordId");
|
||||||
|
if(rs.wasNull()) {
|
||||||
|
discordId = null;
|
||||||
|
}
|
||||||
usersById.put(id, this);
|
usersById.put(id, this);
|
||||||
usersByName.put(userName.toLowerCase(), this);
|
usersByName.put(userName.toLowerCase(), this);
|
||||||
usersByUUID.put(uuid, this);
|
usersByUUID.put(uuid, this);
|
||||||
@ -183,8 +186,8 @@ public class SteamwarUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static SteamwarUser get(Long discordId) {
|
public static SteamwarUser get(Long discordId) {
|
||||||
if (usersByDiscord.containsKey(discordId.toString()))
|
if(usersByDiscord.containsKey(discordId))
|
||||||
return usersByDiscord.get(discordId.toString());
|
return usersByDiscord.get(discordId);
|
||||||
return byDiscord.select(rs -> {
|
return byDiscord.select(rs -> {
|
||||||
if (rs.next())
|
if (rs.next())
|
||||||
return new SteamwarUser(rs);
|
return new SteamwarUser(rs);
|
||||||
@ -240,11 +243,11 @@ public class SteamwarUser {
|
|||||||
return punishments.getOrDefault(type, null);
|
return punishments.getOrDefault(type, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDiscordId() {
|
public Long getDiscordId() {
|
||||||
return discordId;
|
return discordId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDiscordId(String discordId) {
|
public void setDiscordId(Long discordId) {
|
||||||
usersByDiscord.remove(this.discordId);
|
usersByDiscord.remove(this.discordId);
|
||||||
this.discordId = discordId;
|
this.discordId = discordId;
|
||||||
updateDiscord.update(discordId, id);
|
updateDiscord.update(discordId, id);
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren