This repository has been archived by the owner on Jul 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
222 additions
and
1 deletion.
There are no files selected for viewing
221 changes: 221 additions & 0 deletions
221
src/main/java/org/magmafoundation/magma/log4j/HighlightTimeConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,221 @@ | ||
/* | ||
* Magma Server | ||
* Copyright (C) 2019-2020. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.magmafoundation.magma.log4j; | ||
|
||
import java.util.List; | ||
import javax.annotation.Nullable; | ||
import org.apache.logging.log4j.Level; | ||
import org.apache.logging.log4j.core.LogEvent; | ||
import org.apache.logging.log4j.core.config.Configuration; | ||
import org.apache.logging.log4j.core.config.plugins.Plugin; | ||
import org.apache.logging.log4j.core.layout.PatternLayout; | ||
import org.apache.logging.log4j.core.pattern.ConverterKeys; | ||
import org.apache.logging.log4j.core.pattern.LogEventPatternConverter; | ||
import org.apache.logging.log4j.core.pattern.PatternConverter; | ||
import org.apache.logging.log4j.core.pattern.PatternFormatter; | ||
import org.apache.logging.log4j.core.pattern.PatternParser; | ||
import org.apache.logging.log4j.util.PerformanceSensitive; | ||
|
||
/** | ||
* HighlightTimeConverter | ||
* | ||
* @author Hexeption [email protected] | ||
* @since 29/11/2020 - 04:04 pm | ||
*/ | ||
@Plugin(name = "highlightTime", category = PatternConverter.CATEGORY) | ||
@ConverterKeys({"highlightTime"}) | ||
@PerformanceSensitive("allocation") | ||
public class HighlightTimeConverter extends LogEventPatternConverter { | ||
|
||
private static final String ANSI_RESET = "\u001B[39;0m"; | ||
private static final String ANSI_ERROR = getError(); | ||
private static final String ANSI_WARN = getWarn(); | ||
private static final String ANSI_INFO = getInfo(); | ||
private static final String ANSI_FATAL = getFatal(); | ||
private static final String ANSI_TRACE = getTrace(); | ||
|
||
private final List<PatternFormatter> formatters; | ||
|
||
/** | ||
* Constructs an instance of LoggingEventPatternConverter. | ||
* | ||
* @param formatters The pattern formatters to generate the text to highlight | ||
*/ | ||
protected HighlightTimeConverter(List<PatternFormatter> formatters) { | ||
super("highlightTime", null); | ||
this.formatters = formatters; | ||
} | ||
|
||
@Override | ||
public void format(LogEvent event, StringBuilder toAppendTo) { | ||
Level level = event.getLevel(); | ||
if (level.isMoreSpecificThan(Level.ERROR)) { | ||
format(ANSI_ERROR, event, toAppendTo); | ||
return; | ||
} else if (level.isMoreSpecificThan(Level.WARN)) { | ||
format(ANSI_WARN, event, toAppendTo); | ||
return; | ||
} else if (level.isMoreSpecificThan(Level.INFO)) { | ||
format(ANSI_INFO, event, toAppendTo); | ||
return; | ||
} else if (level.isMoreSpecificThan(Level.FATAL)) { | ||
format(ANSI_FATAL, event, toAppendTo); | ||
return; | ||
} else if (level.isMoreSpecificThan(Level.TRACE)) { | ||
format(ANSI_TRACE, event, toAppendTo); | ||
return; | ||
} | ||
|
||
//noinspection ForLoopReplaceableByForEach | ||
for (int i = 0, size = formatters.size(); i < size; i++) | ||
{ | ||
formatters.get(i).format(event, toAppendTo); | ||
} | ||
} | ||
|
||
private void format(String style, LogEvent event, StringBuilder toAppendTo) { | ||
int start = toAppendTo.length(); | ||
toAppendTo.append(style); | ||
int end = toAppendTo.length(); | ||
|
||
//noinspection ForLoopReplaceableByForEach | ||
for (int i = 0, size = formatters.size(); i < size; i++) { | ||
formatters.get(i).format(event, toAppendTo); | ||
} | ||
|
||
if (toAppendTo.length() == end) { | ||
// No content so we don't need to append the ANSI escape code | ||
toAppendTo.setLength(start); | ||
} else { | ||
// Append reset code after the line | ||
toAppendTo.append(ANSI_RESET); | ||
} | ||
} | ||
|
||
|
||
public static String getError() { | ||
return getColor("c", "\u001B[31;1m"); | ||
} | ||
|
||
public static String getWarn() { | ||
return getColor("e", "\u001B[33;1m"); | ||
} | ||
|
||
public static String getInfo() { | ||
return getColor("2", "\u001B[32;22m"); | ||
} | ||
|
||
public static String getFatal() { | ||
return getColor("e", "\u001B[31;1m"); | ||
} | ||
|
||
public static String getTrace() { | ||
return getColor("e", "\u001B[31;1m"); | ||
} | ||
|
||
private static String getColor(String text, String d) { | ||
switch (text) { | ||
case "1": | ||
text = "\u001B[34;22m"; | ||
break; | ||
case "2": | ||
text = "\u001B[32;22m"; | ||
break; | ||
case "3": | ||
text = "\u001B[36;22m"; | ||
break; | ||
case "4": | ||
text = "\u001B[31;22m"; | ||
break; | ||
case "5": | ||
text = "\u001B[35;22m"; | ||
break; | ||
case "6": | ||
text = "\u001B[33;22m"; | ||
break; | ||
case "7": | ||
text = "\u001B[37;22m"; | ||
break; | ||
case "8": | ||
text = "\u001B[30;1m"; | ||
break; | ||
case "9": | ||
text = "\u001B[34;1m"; | ||
break; | ||
case "a": | ||
text = "\u001B[32;1m"; | ||
break; | ||
case "b": | ||
text = "\u001B[36;1m"; | ||
break; | ||
case "c": | ||
text = "\u001B[31;1m"; | ||
break; | ||
case "d": | ||
text = "\u001B[35;1m"; | ||
break; | ||
case "e": | ||
text = "\u001B[33;1m"; | ||
break; | ||
case "f": | ||
text = "\u001B[37;1m"; | ||
break; | ||
case "r": | ||
text = "\u001B[39;0m"; | ||
break; | ||
default: | ||
text = d; | ||
} | ||
return text; | ||
} | ||
|
||
|
||
/** | ||
* Gets a new instance of the {@link HighlightTimeConverter} with the specified options. | ||
* | ||
* @param config The current configuration | ||
* @param options The pattern options | ||
* @return The new instance | ||
*/ | ||
@Nullable | ||
public static HighlightTimeConverter newInstance(Configuration config, String[] options) { | ||
if (options.length != 1) { | ||
LOGGER.error("Incorrect number of options on highlightLevel. Expected 1 received " + options.length); | ||
return null; | ||
} | ||
if (options[0] == null) { | ||
LOGGER.error("No pattern supplied on highlightLevel"); | ||
return null; | ||
} | ||
|
||
PatternParser parser = PatternLayout.createPatternParser(config); | ||
List<PatternFormatter> formatters = parser.parse(options[0]); | ||
return new HighlightTimeConverter(formatters); | ||
} | ||
|
||
@Override | ||
public boolean handlesThrowable() { | ||
for (final PatternFormatter formatter : formatters) { | ||
if (formatter.handlesThrowable()) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
faf2949
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look, this is the exact same console code as Mohist, great! Rat tail juice
faf2949
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Says the person who started to steal code first lol. I can confirm hex did not steal your code. As I was watching him do it live yesterday. How about you get your fact right before making stupid posts.
faf2949
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I as well as many others were in video call with hex when he coded it, he definitly made it himself and didnt copy anything.
faf2949
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, Magma already copied a lot of our code. Second, we never copied any Magma code (and don't tell me that we copied with Mohist 1.15.2 because this repo don't exists anymore so just shut your mouth). And then, just explain us why this file is the same as https://github.com/Mohist-Community/Mohist/blob/1.12.2/src/main/java/com/mohistmc/console/log4j/HighlightTimeConverter.java and the getColor method same as in this file https://github.com/Mohist-Community/Mohist/blob/1.12.2/src/main/java/com/mohistmc/util/ANSIColorUtils.java
Please tell me why. But i already have the answer : He copy pasted the code.
You can't tell the opposite.
faf2949
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can say that at least thats not true since i and many others saw him typing that code, but i cant tell if he took a look at your code meanwhile
faf2949
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't tell that it's not true. He copied the code and i say that because his the code is the same as the Mohist's code. If it was not the same code i will not be here to talk, and Mgazul created that code himself so it can't be because Hex had luck or something else. Also know that it's not the first time that Hex copy our code.
If Hex was typing the code in his live, he was able to see Mohist's code on another screen or something else.
faf2949
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you children stop throwing tantrums and just program a server software that works?
Do you seriously think anyone gives a crap about whos code is similar to whos?
All they want is a high performance hybrid server, which i can say for a fact MOHIST is not anymore.
So fix your own project before going and attacking another.
I also find it funny as a development team (Mohist) is attacking magma for using minecraft code. When they straight up copy/pasted the entire magma 1.15.2 branch, claimed its their code. And then stole MY networks custom bungeecord, then told me to pay them $500 or else they would release it online.
Yeah, those guys are crying cause someones code is similar to theirs. The ones who did all of the above. Some great logic there kiddos.
Also those 2 are nothing in common, you are seriously throwing a fit over minecraft color codes. Explain to me how else hes supposed to support color codes? Magically make a new system that minecraft doesn't support just to please you and break everything else? Your all making a server off the same game, in case you forgot. The games code doesnt change. Its functions do not change. Every server is going to have the SAME CODE when referencing minecraft in the server.
faf2949
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lol
faf2949
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For anyone still interested, here is proof that hex made it himself (Screenshot of his old project Kettle, that later became Magma) http://img.hexeption.co.uk/we6B