-
-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add caveat to warning msg about Java agents
- Loading branch information
Showing
5 changed files
with
126 additions
and
5 deletions.
There are no files selected for viewing
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
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
44 changes: 44 additions & 0 deletions
44
spark-common/src/main/java/me/lucko/spark/common/util/JavaVersion.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,44 @@ | ||
/* | ||
* This file is part of spark. | ||
* | ||
* Copyright (c) lucko (Luck) <[email protected]> | ||
* Copyright (c) contributors | ||
* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package me.lucko.spark.common.util; | ||
|
||
public class JavaVersion { | ||
; | ||
|
||
private static final int JAVA_VERSION; | ||
static { | ||
JAVA_VERSION = parseJavaVersion(System.getProperty("java.version")); | ||
} | ||
|
||
private static int parseJavaVersion(String version) { | ||
if (version.startsWith("1.")) { | ||
// Java 8 and below | ||
return Integer.parseInt(version.substring(2, 3)); | ||
} else { | ||
// Java 9 and above | ||
return Integer.parseInt(version.split("\\.")[0]); | ||
} | ||
} | ||
|
||
public static int getJavaVersion() { | ||
return JAVA_VERSION; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
spark-common/src/main/java/me/lucko/spark/common/util/SparkStaticLogger.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,61 @@ | ||
/* | ||
* This file is part of spark. | ||
* | ||
* Copyright (c) lucko (Luck) <[email protected]> | ||
* Copyright (c) contributors | ||
* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package me.lucko.spark.common.util; | ||
|
||
import java.util.logging.Level; | ||
|
||
/** | ||
* Special logger for use by classes that don't easily have access to a | ||
* {@link me.lucko.spark.common.SparkPlatform} instance. | ||
* | ||
* <p>This avoids warnings on platforms like Paper that get upset if plugins use | ||
* {@link System#out} or {@link System#err}.</p> | ||
*/ | ||
public enum SparkStaticLogger { | ||
; | ||
|
||
private static Logger logger = null; | ||
|
||
public synchronized static void setLogger(Logger logger) { | ||
if (SparkStaticLogger.logger == null) { | ||
SparkStaticLogger.logger = logger; | ||
} | ||
} | ||
|
||
public static void log(Level level, String msg) { | ||
Logger logger = SparkStaticLogger.logger; | ||
if (logger == null) { | ||
if (level.intValue() >= 1000) { | ||
System.err.println(msg); | ||
} else { | ||
System.out.println(msg); | ||
} | ||
return; | ||
} | ||
|
||
logger.log(level, msg); | ||
} | ||
|
||
public interface Logger { | ||
void log(Level level, String msg); | ||
} | ||
|
||
} |
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