Flatteningfix, vanilla java error logger (<1.12 support!)
Dieser Commit ist enthalten in:
Ursprung
6f116804b7
Commit
95b9551c70
@ -256,9 +256,8 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper
|
|||||||
renamedLegacy.put("RECORD_12", Material.MUSIC_DISC_WAIT);
|
renamedLegacy.put("RECORD_12", Material.MUSIC_DISC_WAIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Class<?> chatComponent = Reflection.getClass("{nms}.ChatComponentText");
|
private static final Reflection.FieldAccessor<?> scoreboardName = Reflection.getField(SWScoreboard.scoreboardObjective, Reflection.getClass("{nms}.IChatBaseComponent"), 0);
|
||||||
private static final Reflection.FieldAccessor<?> scoreboardName = Reflection.getField(SWScoreboard.scoreboardObjective, chatComponent, 0);
|
private static final Reflection.ConstructorInvoker chatComponentConstructor = Reflection.getConstructor(Reflection.getClass("{nms}.ChatComponentText"), String.class);
|
||||||
private static final Reflection.ConstructorInvoker chatComponentConstructor = Reflection.getConstructor(chatComponent, String.class);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setScoreboardTitle(Object packet, String title) {
|
public void setScoreboardTitle(Object packet, String title) {
|
||||||
|
@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
package de.steamwar.core;
|
package de.steamwar.core;
|
||||||
|
|
||||||
import de.steamwar.core.authlib.AuthlibInjector;
|
|
||||||
import de.steamwar.comms.BungeeReceiver;
|
import de.steamwar.comms.BungeeReceiver;
|
||||||
|
import de.steamwar.core.authlib.AuthlibInjector;
|
||||||
import de.steamwar.core.events.ChattingEvent;
|
import de.steamwar.core.events.ChattingEvent;
|
||||||
import de.steamwar.core.events.ChunkListener;
|
import de.steamwar.core.events.ChunkListener;
|
||||||
import de.steamwar.core.events.PlayerJoinedEvent;
|
import de.steamwar.core.events.PlayerJoinedEvent;
|
||||||
@ -57,14 +57,14 @@ public class Core extends JavaPlugin{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
new ErrorHandler();
|
||||||
|
|
||||||
Bukkit.getPluginManager().registerEvents(new PlayerJoinedEvent(), this);
|
Bukkit.getPluginManager().registerEvents(new PlayerJoinedEvent(), this);
|
||||||
Bukkit.getPluginManager().registerEvents(new ChattingEvent(), this);
|
Bukkit.getPluginManager().registerEvents(new ChattingEvent(), this);
|
||||||
Bukkit.getPluginManager().registerEvents(new WorldLoadEvent(), this);
|
Bukkit.getPluginManager().registerEvents(new WorldLoadEvent(), this);
|
||||||
ChunkListener.init();
|
|
||||||
if(version >= 12)
|
|
||||||
ErrorLogger.init();
|
|
||||||
getServer().getMessenger().registerIncomingPluginChannel(this, "sw:bridge", new BungeeReceiver());
|
getServer().getMessenger().registerIncomingPluginChannel(this, "sw:bridge", new BungeeReceiver());
|
||||||
getServer().getMessenger().registerOutgoingPluginChannel(this, "sw:bridge");
|
getServer().getMessenger().registerOutgoingPluginChannel(this, "sw:bridge");
|
||||||
|
ChunkListener.init();
|
||||||
AuthlibInjector.inject();
|
AuthlibInjector.inject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
140
SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java
Normale Datei
140
SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java
Normale Datei
@ -0,0 +1,140 @@
|
|||||||
|
/*
|
||||||
|
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.core;
|
||||||
|
|
||||||
|
import de.steamwar.sql.SWException;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
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 ErrorHandler extends Handler {
|
||||||
|
|
||||||
|
private boolean logDisabled = false;
|
||||||
|
|
||||||
|
public ErrorHandler(){
|
||||||
|
Logger.getLogger("").addHandler(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void publish(LogRecord logRecord) {
|
||||||
|
if(logRecord.getLevel().intValue() < Level.WARNING.intValue())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(logDisabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
String message = logRecord.getMessage();
|
||||||
|
for(String reason : ignoreStartsWith)
|
||||||
|
if(message.startsWith(reason))
|
||||||
|
return;
|
||||||
|
for(String reason : ignoreContains)
|
||||||
|
if(message.contains(reason))
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch (message) {
|
||||||
|
case "The server has stopped responding!":
|
||||||
|
logDisabled = true;
|
||||||
|
return;
|
||||||
|
case "------------------------------":
|
||||||
|
message = "Server stopped responding";
|
||||||
|
logDisabled = true;
|
||||||
|
break;
|
||||||
|
case "Exception stopping the server":
|
||||||
|
logDisabled = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
ByteArrayOutputStream stacktraceOutput = new ByteArrayOutputStream();
|
||||||
|
logRecord.getThrown().printStackTrace(new PrintStream(stacktraceOutput));
|
||||||
|
String stacktrace = stacktraceOutput.toString();
|
||||||
|
if(stacktrace.contains("POI data mismatch"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SWException.log(message, stacktrace);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void flush() {
|
||||||
|
//This is task of the database
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws SecurityException {
|
||||||
|
//Done in the database
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final List<String> ignoreStartsWith;
|
||||||
|
private static final List<String> ignoreContains;
|
||||||
|
|
||||||
|
static {
|
||||||
|
List<String> startsWith = new ArrayList<>();
|
||||||
|
startsWith.add("Could not save the list after adding a user.");
|
||||||
|
startsWith.add("Could not save spigot.yml");
|
||||||
|
startsWith.add("Failed to save operators list:");
|
||||||
|
startsWith.add("Block at");
|
||||||
|
startsWith.add("POI data mismatch");
|
||||||
|
startsWith.add("handleDisconnection() called twice");
|
||||||
|
startsWith.add("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!");
|
||||||
|
startsWith.add("The server will make no attempt to authenticate usernames. Beware.");
|
||||||
|
startsWith.add("Whilst this makes it possible to use BungeeCord,");
|
||||||
|
startsWith.add("Please see http://www.spigotmc.org/wiki/firewall-guide/ for further information.");
|
||||||
|
startsWith.add("To change this, set \"online-mode\" to \"true\" in the server.properties file.");
|
||||||
|
startsWith.add("This crash report has been saved to:");
|
||||||
|
startsWith.add("Could not pass event PlayerQuitEvent to WorldEditSUI");
|
||||||
|
startsWith.add("[ViaVersion] ");
|
||||||
|
startsWith.add("[ViaBackwards] ");
|
||||||
|
startsWith.add("Something went wrong upgrading!");
|
||||||
|
startsWith.add("Tried to load unrecognized recipe");
|
||||||
|
startsWith.add("Invalid BlockState in palette:");
|
||||||
|
startsWith.add("Could not register alias");
|
||||||
|
startsWith.add("Can't keep up! Is the server overloaded?");
|
||||||
|
startsWith.add("\tat ");
|
||||||
|
startsWith.add("java.lang.Exception");
|
||||||
|
startsWith.add("An exceptionCaught()");
|
||||||
|
startsWith.add("Exception verifying");
|
||||||
|
startsWith.add("[WorldEditSUI]");
|
||||||
|
startsWith.add("Unsupported key:");
|
||||||
|
startsWith.add("ThrownPotion entity");
|
||||||
|
startsWith.add("Couldn't load custom particle");
|
||||||
|
startsWith.add("Chunk file at [");
|
||||||
|
startsWith.add("Ignoring unknown attribute");
|
||||||
|
startsWith.add("Skipping player strafe phase because no player was found");
|
||||||
|
startsWith.add("Couldn't save chunk; already in use by another instance of Minecraft?");
|
||||||
|
startsWith.add("Failed to save player data for ");
|
||||||
|
startsWith.add("Failed to check session lock for world located at");
|
||||||
|
startsWith.add("Saving oversized chunk ");
|
||||||
|
ignoreStartsWith = Collections.unmodifiableList(startsWith);
|
||||||
|
|
||||||
|
List<String> contains = new ArrayList<>();
|
||||||
|
contains.add("moved too quickly!");
|
||||||
|
contains.add("moved wrongly!");
|
||||||
|
contains.add("was kicked for floating too long!");
|
||||||
|
contains.add("just tried to change non-editable sign");
|
||||||
|
ignoreContains = Collections.unmodifiableList(contains);
|
||||||
|
}
|
||||||
|
}
|
@ -1,63 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is a part of the SteamWar software.
|
|
||||||
|
|
||||||
Copyright (C) 2020 SteamWar.de-Serverteam
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Affero General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU Affero General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.core;
|
|
||||||
|
|
||||||
import de.steamwar.sql.SWException;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.core.Appender;
|
|
||||||
import org.apache.logging.log4j.core.Core;
|
|
||||||
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.plugins.Plugin;
|
|
||||||
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
|
|
||||||
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
|
|
||||||
import org.apache.logging.log4j.spi.StandardLevel;
|
|
||||||
|
|
||||||
@Plugin(name = "ErrorLogger", category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE)
|
|
||||||
public class ErrorLogger extends AbstractAppender {
|
|
||||||
|
|
||||||
public static void init(){
|
|
||||||
final LoggerContext lc = (LoggerContext) LogManager.getContext(false);
|
|
||||||
ErrorLogger el = ErrorLogger.createAppender("SWErrorLogger");
|
|
||||||
el.start();
|
|
||||||
lc.getConfiguration().addAppender(el);
|
|
||||||
lc.getRootLogger().addAppender(lc.getConfiguration().getAppender(el.getName()));
|
|
||||||
lc.updateLoggers();
|
|
||||||
}
|
|
||||||
|
|
||||||
private ErrorLogger(String name) {
|
|
||||||
super(name, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PluginFactory
|
|
||||||
public static ErrorLogger createAppender(
|
|
||||||
@PluginAttribute("name") String name) {
|
|
||||||
return new ErrorLogger(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void append(LogEvent logEvent) {
|
|
||||||
if(logEvent.getLevel().intLevel() > StandardLevel.WARN.intLevel())
|
|
||||||
return;
|
|
||||||
|
|
||||||
SWException.log(logEvent);
|
|
||||||
}
|
|
||||||
}
|
|
@ -87,6 +87,7 @@ public class SWItem {
|
|||||||
this(material, (byte)0, name, lore, enchanted, c);
|
this(material, (byte)0, name, lore, enchanted, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public SWItem(Material material, byte meta, String name, List<String> lore, boolean enchanted, InvCallback c) {
|
public SWItem(Material material, byte meta, String name, List<String> lore, boolean enchanted, InvCallback c) {
|
||||||
try {
|
try {
|
||||||
itemStack = new ItemStack(material, 1, (short)0, meta);
|
itemStack = new ItemStack(material, 1, (short)0, meta);
|
||||||
|
@ -19,101 +19,13 @@
|
|||||||
|
|
||||||
package de.steamwar.sql;
|
package de.steamwar.sql;
|
||||||
|
|
||||||
import org.apache.logging.log4j.core.LogEvent;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class SWException {
|
public class SWException {
|
||||||
private SWException(){}
|
private SWException(){}
|
||||||
|
|
||||||
private static boolean logDisabled = false;
|
public static void log(String message, String stacktrace){
|
||||||
private static final List<String> ignorereasons;
|
|
||||||
|
|
||||||
static {
|
|
||||||
List<String> reasons = new ArrayList<>();
|
|
||||||
reasons.add("Could not save the list after adding a user.");
|
|
||||||
reasons.add("Could not save spigot.yml");
|
|
||||||
reasons.add("Failed to save operators list:");
|
|
||||||
reasons.add("Block at");
|
|
||||||
reasons.add("POI data mismatch");
|
|
||||||
reasons.add("handleDisconnection() called twice");
|
|
||||||
reasons.add("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!");
|
|
||||||
reasons.add("The server will make no attempt to authenticate usernames. Beware.");
|
|
||||||
reasons.add("Whilst this makes it possible to use BungeeCord,");
|
|
||||||
reasons.add("Please see http://www.spigotmc.org/wiki/firewall-guide/ for further information.");
|
|
||||||
reasons.add("To change this, set \"online-mode\" to \"true\" in the server.properties file.");
|
|
||||||
reasons.add("This crash report has been saved to:");
|
|
||||||
reasons.add("Could not pass event PlayerQuitEvent to WorldEditSUI");
|
|
||||||
reasons.add("[ViaVersion] ");
|
|
||||||
reasons.add("[ViaBackwards] ");
|
|
||||||
reasons.add("Something went wrong upgrading!");
|
|
||||||
reasons.add("Tried to load unrecognized recipe");
|
|
||||||
reasons.add("Invalid BlockState in palette:");
|
|
||||||
reasons.add("Could not register alias");
|
|
||||||
reasons.add("Can't keep up! Is the server overloaded?");
|
|
||||||
reasons.add("\tat ");
|
|
||||||
reasons.add("java.lang.Exception");
|
|
||||||
reasons.add("An exceptionCaught()");
|
|
||||||
reasons.add("Exception verifying");
|
|
||||||
reasons.add("[WorldEditSUI]");
|
|
||||||
reasons.add("Unsupported key:");
|
|
||||||
reasons.add("ThrownPotion entity");
|
|
||||||
reasons.add("Couldn't load custom particle");
|
|
||||||
reasons.add("Chunk file at [");
|
|
||||||
reasons.add("Ignoring unknown attribute");
|
|
||||||
reasons.add("Skipping player strafe phase because no player was found");
|
|
||||||
reasons.add("Couldn't save chunk; already in use by another instance of Minecraft?");
|
|
||||||
reasons.add("Failed to save player data for ");
|
|
||||||
reasons.add("Failed to check session lock for world located at");
|
|
||||||
reasons.add("Saving oversized chunk ");
|
|
||||||
ignorereasons = Collections.unmodifiableList(reasons);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void log(LogEvent logEvent){
|
|
||||||
if(logDisabled)
|
|
||||||
return;
|
|
||||||
|
|
||||||
String message = logEvent.getMessage().getFormattedMessage();
|
|
||||||
for(String reason : ignorereasons)
|
|
||||||
if(message.startsWith(reason))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(message.contains("moved too quickly!") || message.contains("moved wrongly!") || message.contains("was kicked for floating too long!") || message.contains("just tried to change non-editable sign"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
switch (message) {
|
|
||||||
case "The server has stopped responding!":
|
|
||||||
logDisabled = true;
|
|
||||||
return;
|
|
||||||
case "------------------------------":
|
|
||||||
message = "Server stopped responding";
|
|
||||||
logDisabled = true;
|
|
||||||
break;
|
|
||||||
case "Exception stopping the server":
|
|
||||||
logDisabled = true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder stacktrace = new StringBuilder(logEvent.getSource().toString());
|
|
||||||
Throwable throwable = logEvent.getThrown();
|
|
||||||
while(throwable != null){
|
|
||||||
stacktrace.append("\nCaused by ").append(throwable.getClass().getName()).append(": ").append(throwable.getMessage());
|
|
||||||
|
|
||||||
for(StackTraceElement ste : throwable.getStackTrace())
|
|
||||||
stacktrace.append("\n").append(ste.toString());
|
|
||||||
|
|
||||||
throwable = throwable.getCause();
|
|
||||||
}
|
|
||||||
|
|
||||||
String st = stacktrace.toString();
|
|
||||||
if(st.contains("POI data mismatch"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
message += "\n";
|
message += "\n";
|
||||||
for(Player player : Bukkit.getOnlinePlayers())
|
for(Player player : Bukkit.getOnlinePlayers())
|
||||||
message += player.getName() + " ";
|
message += player.getName() + " ";
|
||||||
@ -124,7 +36,6 @@ public class SWException {
|
|||||||
else
|
else
|
||||||
server = Bukkit.getWorlds().get(0).getName();
|
server = Bukkit.getWorlds().get(0).getName();
|
||||||
|
|
||||||
SQL.update("INSERT INTO Exception (server, message, stacktrace) VALUES (?, ?, ?)",
|
SQL.update("INSERT INTO Exception (server, message, stacktrace) VALUES (?, ?, ?)", server, message, stacktrace);
|
||||||
server, message, st);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren