2016-05-21 23:37:13 +02:00
|
|
|
/**
|
2022-07-16 17:00:01 +02:00
|
|
|
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. Copyright (C) 2015 dmulloy2
|
|
|
|
* <p>
|
|
|
|
* 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 2 of the License, or (at your option) any later
|
|
|
|
* version.
|
|
|
|
* <p>
|
|
|
|
* 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.
|
|
|
|
* <p>
|
|
|
|
* You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
|
|
|
|
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2016-05-21 23:37:13 +02:00
|
|
|
*/
|
|
|
|
package com.comphenix.protocol.utility;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* General utility class
|
2022-07-24 16:16:05 +02:00
|
|
|
*
|
2016-05-21 23:37:13 +02:00
|
|
|
* @author dmulloy2
|
|
|
|
*/
|
2022-06-25 17:32:42 +02:00
|
|
|
public final class Util {
|
2016-05-21 23:37:13 +02:00
|
|
|
|
2023-05-12 16:35:34 +02:00
|
|
|
private static final boolean SPIGOT = classExists("org.spigotmc.SpigotConfig");
|
|
|
|
private static Class<?> cachedBundleClass;
|
2016-05-21 23:37:13 +02:00
|
|
|
|
2023-05-12 16:35:34 +02:00
|
|
|
public static boolean classExists(String className) {
|
|
|
|
try {
|
|
|
|
Class.forName(className);
|
|
|
|
return true;
|
|
|
|
} catch (ClassNotFoundException ex) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2020-05-25 02:35:25 +02:00
|
|
|
|
2023-05-12 16:35:34 +02:00
|
|
|
/**
|
|
|
|
* Whether this server is running Spigot or a Spigot fork. This works by checking if the SpigotConfig exists, which
|
|
|
|
* should be true of all forks.
|
|
|
|
*
|
|
|
|
* @return True if it is, false if not.
|
|
|
|
*/
|
|
|
|
public static boolean isUsingSpigot() {
|
|
|
|
return SPIGOT;
|
|
|
|
}
|
2022-07-16 17:00:01 +02:00
|
|
|
|
2023-05-12 16:35:34 +02:00
|
|
|
/**
|
|
|
|
* Checks if the server is getting reloaded by walking down the current thread stack trace.
|
|
|
|
*
|
|
|
|
* @return true if the server is getting reloaded, false otherwise.
|
|
|
|
*/
|
|
|
|
public static boolean isCurrentlyReloading() {
|
|
|
|
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
|
|
|
for (StackTraceElement element : stackTrace) {
|
|
|
|
String clazz = element.getClassName();
|
|
|
|
if (clazz.startsWith("org.bukkit.craftbukkit.")
|
|
|
|
&& clazz.endsWith(".CraftServer")
|
|
|
|
&& element.getMethodName().equals("reload")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-21 23:37:13 +02:00
|
|
|
}
|