Strip away colors from log manager if we are not on Bukkit. Colors must be handled by the implementation and cannot be cross-platform. Everything remains white on other platforms or unknown implementations, unless they implement it correctly.
This commit is contained in:
1 parent
a16cc34f8d
commit
db1ca78fbb
4 files changed
+16
-26
No files matched your search
@@ -5,10 +5,13 @@ import com.github.retrooper.packetevents.protocol.chat.Color;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class LogManager {
|
||||
|
||||
private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + '\u00A7' + "[0-9A-FK-ORX]");
|
||||
protected void log(Level level, @Nullable Color color, String message) {
|
||||
//First we must strip away the color codes that might be in this message
|
||||
message = STRIP_COLOR_PATTERN.matcher(message).replaceAll("");
|
||||
PacketEvents.getAPI().getLogger().log(level, color != null ? (color.toString()) : "" + message);
|
||||
}
|
||||
|
||||
|
||||
+5
-24
@@ -19,6 +19,7 @@
|
||||
package com.github.retrooper.packetevents.util.updatechecker;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.protocol.chat.Color;
|
||||
import com.github.retrooper.packetevents.protocol.chat.component.serializer.ComponentSerializer;
|
||||
import com.github.retrooper.packetevents.util.LogManager;
|
||||
import com.github.retrooper.packetevents.util.PEVersion;
|
||||
@@ -64,16 +65,16 @@ public class UpdateChecker {
|
||||
newVersion = null;
|
||||
}
|
||||
if (newVersion != null && localVersion.isOlderThan(newVersion)) {
|
||||
inform("There is an update available for packetevents! Your build: (" + localVersion + ") | Latest released build: (" + newVersion + ")");
|
||||
PacketEvents.getAPI().getLogManager().warn("There is an update available for packetevents! Your build: (" + Color.YELLOW + localVersion + Color.WHITE + ") | Latest released build: (" + Color.BRIGHT_GREEN + newVersion + Color.RED + ")");
|
||||
return UpdateCheckerStatus.OUTDATED;
|
||||
} else if (newVersion != null && localVersion.isNewerThan(newVersion)) {
|
||||
inform("You are on a dev or pre released build of packetevents. Your build: (" + localVersion + ") | Latest released build: (" + newVersion + ")");
|
||||
PacketEvents.getAPI().getLogManager().info("You are on a dev or pre released build of packetevents. Your build: (" + Color.CYAN + localVersion + Color.WHITE + ") | Latest released build: (" + Color.DARK_CYAN + newVersion + Color.WHITE + ")");
|
||||
return UpdateCheckerStatus.PRE_RELEASE;
|
||||
} else if (localVersion.equals(newVersion)) {
|
||||
inform("You are on the latest released version of packetevents. (" + newVersion + ")");
|
||||
PacketEvents.getAPI().getLogManager().info("You are on the latest released version of packetevents. (" + Color.BRIGHT_GREEN + newVersion + Color.WHITE + ")");
|
||||
return UpdateCheckerStatus.UP_TO_DATE;
|
||||
} else {
|
||||
report("Something went wrong while checking for an update. Your build: (" + localVersion + ")");
|
||||
PacketEvents.getAPI().getLogManager().warn("Something went wrong while checking for an update. Your build: (" + localVersion + ")");
|
||||
return UpdateCheckerStatus.FAILED;
|
||||
}
|
||||
}
|
||||
@@ -111,26 +112,6 @@ public class UpdateChecker {
|
||||
}, "packetevents-update-check-thread");
|
||||
thread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a positive message in the console.
|
||||
*
|
||||
* @param message Message
|
||||
*/
|
||||
private void inform(String message) {
|
||||
PacketEvents.getAPI().getLogManager().info(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a negative message in the console.
|
||||
*
|
||||
* @param message Message
|
||||
*/
|
||||
private void report(String message) {
|
||||
//TODO Maybe find some universal way to make it red
|
||||
PacketEvents.getAPI().getLogManager().warn(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Result of an update check.
|
||||
*
|
||||
|
||||
+5
@@ -35,6 +35,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class PacketDecoderModern extends ByteToMessageDecoder {
|
||||
@@ -95,6 +96,7 @@ public class PacketDecoderModern extends ByteToMessageDecoder {
|
||||
@Override
|
||||
public void decode(ChannelHandlerContext ctx, ByteBuf byteBuf, List<Object> out) {
|
||||
if (byteBuf.readableBytes() != 0) {
|
||||
System.out.println("pipe: " + Arrays.toString(ctx.pipeline().names().toArray(new String[0])));
|
||||
handle(PacketEvents.getAPI().getNettyManager().wrapChannelHandlerContext(ctx), PacketEvents.getAPI().getNettyManager().wrapByteBuf(byteBuf), out);
|
||||
if (!decoders.isEmpty()) {
|
||||
//Call custom decoders
|
||||
@@ -120,6 +122,9 @@ public class PacketDecoderModern extends ByteToMessageDecoder {
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
System.out.println("suii");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean handleCompressionOrder(ChannelHandlerContextAbstract ctx, ByteBufAbstract buf) {
|
||||
|
||||
+2
-1
@@ -31,6 +31,7 @@ import io.github.retrooper.packetevents.utils.dependencies.DependencyUtil;
|
||||
import io.github.retrooper.packetevents.utils.dependencies.protocolsupport.ProtocolSupportUtil;
|
||||
import io.github.retrooper.packetevents.utils.dependencies.viaversion.ViaVersionUtil;
|
||||
import io.github.retrooper.packetevents.utils.v1_7.SpigotVersionLookup_1_7;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -104,9 +105,9 @@ public class PlayerManagerImpl implements PlayerManager {
|
||||
@Override
|
||||
public void sendPacket(ChannelAbstract channel, ByteBufAbstract byteBuf) {
|
||||
if (channel.isOpen()) {
|
||||
ChatColor.stripColor()
|
||||
//TODO Also check if our encoder is RIGHT before minecraft's,
|
||||
//if it is, then don't use context to writeflush, otherwise use it (to support multiple packetevents instances)
|
||||
|
||||
if (ViaVersionUtil.isAvailable() && !ProtocolSupportUtil.isAvailable()) {
|
||||
channel.writeAndFlush(byteBuf);
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user