SteamWar/BungeeCore
Archiviert
13
2

Velocity #516

Zusammengeführt
Lixfel hat 24 Commits von velocity nach master 2024-06-28 08:39:05 +02:00 zusammengeführt
4 geänderte Dateien mit 54 neuen und 58 gelöschten Zeilen
Nur Änderungen aus Commit a15bd4aa83 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -20,71 +20,63 @@
package de.steamwar.velocitycore;
import de.steamwar.sql.SWException;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.AbstractConfiguration;
import org.apache.logging.log4j.core.config.Property;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
public class ErrorLogger extends Handler /*AbstractAppender*/ {
public class ErrorLogger extends AbstractAppender {
ErrorLogger(){
//super("SW ErrorLogger", filter, layout, false, null);
//((LoggerContext) org.apache.logging.log4j.LogManager.getContext(false)).getConfiguration().addAppender(this);
VelocityCore.getLogger().addHandler(this);
ErrorLogger() {
super("SW ErrorLogger", null, null, false, Property.EMPTY_ARRAY);
start();
LoggerContext context = (LoggerContext) LogManager.getContext(false);
context.getConfiguration().addAppender(this);
context.getRootLogger().addAppender(this);
context.updateLoggers();
}
void unregister(){
Logger.getGlobal().removeHandler(this);
void unregister() {
LoggerContext context = (LoggerContext) LogManager.getContext(false);
((AbstractConfiguration) context.getConfiguration()).removeAppender(getName());
context.getRootLogger().removeAppender(this);
context.updateLoggers();
}
@Override
public void publish(LogRecord logRecord) {
if(logRecord.getLevel().intValue() < Level.WARNING.intValue())
public void append(LogEvent event) {
if(event.getLevel().isLessSpecificThan(Level.WARN))
return;
String message = logRecord.getParameters() != null ? MessageFormat.format(logRecord.getMessage(), logRecord.getParameters()) : logRecord.getMessage();
String message = event.getMessage().getFormattedMessage();
for(String reason : ignoreContains)
if(message.contains(reason))
return;
ByteArrayOutputStream stacktraceOutput = new ByteArrayOutputStream();
if(logRecord.getThrown() != null)
logRecord.getThrown().printStackTrace(new PrintStream(stacktraceOutput));
if(event.getThrown() != null)
event.getThrown().printStackTrace(new PrintStream(stacktraceOutput));
String stacktrace = stacktraceOutput.toString();
if (stacktrace.contains("ErrorLogger")) {
if (stacktrace.contains("ErrorLogger"))
return;
}
SWException.log(message, stacktrace);
}
@Override
public void flush() {
//ignored
}
@Override
public void close() {
//ignored
}
private static final List<String> ignoreContains;
static {
List<String> contains = new ArrayList<>();
ignoreContains = Collections.unmodifiableList(contains);
}
/*@Override
public void append(LogEvent event) {
}*/
}

Datei anzeigen

@ -169,7 +169,7 @@ public class CheckCommand extends SWCommand {
}
public static List<SchematicNode> getSchemsToCheck(){
List<SchematicNode> schematicList = new LinkedList<>();
List<SchematicNode> schematicList = new ArrayList<>();
for (SchematicType type : SchematicType.values()) {
if (type.check())

Datei anzeigen

@ -147,7 +147,7 @@ public class DiscordBot {
.build())
.setActionRows(ActionRow.of(Arrays.stream(DiscordTicketType.values()).map(DiscordTicketType::toButton).toArray(Button[]::new))), DiscordTicketHandler::openTicket);
eventChannel = new StaticMessageChannel(config.channel("events"), EventChannel::get);
StaticMessageChannel checklistChannel = new StaticMessageChannel(config.channel("checklist"), ChecklistChannel::get);
ChecklistChannel checklistChannel = new ChecklistChannel(config.channel("checklist"));
announcementChannel = new DiscordChannel(config.channel("announcement")) {
@Override

Datei anzeigen

@ -19,34 +19,38 @@
package de.steamwar.velocitycore.discord.channels;
import de.steamwar.velocitycore.commands.CheckCommand;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser;
import lombok.experimental.UtilityClass;
import de.steamwar.velocitycore.commands.CheckCommand;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.MessageBuilder;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
@UtilityClass
public class ChecklistChannel {
public class ChecklistChannel extends DiscordChannel {
public MessageBuilder get() {
EmbedBuilder embedBuilder = new EmbedBuilder()
.setColor(Color.GRAY)
.setTitle("Check List")
.setAuthor("SteamWar", "https://www.steamwar.de");
private final List<Integer> lastSchematics = new ArrayList<>();
CheckCommand.getSchemsToCheck().forEach(schematic -> {
StringBuilder st = new StringBuilder();
st.append("Typ: ").append(schematic.getSchemtype().getKuerzel());
st.append("\nVon: ").append(SteamwarUser.get(schematic.getOwner()).getUserName());
String checker = CheckCommand.getChecker(schematic);
if (checker != null) {
st.append("\nWird Geprüft von: ").append(checker);
}
embedBuilder.addField(schematic.getName(), st.toString(), true);
});
public ChecklistChannel(String channel) {
super(channel);
}
return StaticMessageChannel.toMessageBuilder(embedBuilder);
public void update() {
List<SchematicNode> schems = CheckCommand.getSchemsToCheck();
int currentListSize = schems.size();
lastSchematics.removeIf(id -> schems.stream().noneMatch(schem -> schem.getId() == id));
schems.removeIf(schem -> lastSchematics.contains(schem.getId()));
for(SchematicNode schem : schems) {
send(StaticMessageChannel.toMessageBuilder(new EmbedBuilder()
.setColor(Color.GRAY)
.setTitle("Check List (" + currentListSize + ")")
.setAuthor("SteamWar", "https://www.steamwar.de")
.addField(schem.getName(), "Typ: " + schem.getSchemtype().getKuerzel() + "\nVon: " + SteamwarUser.get(schem.getOwner()).getUserName(), true)));
lastSchematics.add(schem.getId());
}
}
}