mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-30 12:57:41 +01:00
26734e83b0
* Updated Upstream (Bukkit/CraftBukkit/Spigot) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 8085edde SPIGOT-6918: Add SpawnCategory API and configurations for Axolotls 04c7e13c PR-719: Add Player Profile API 71564210 SPIGOT-6910: Add BlockDamageAbortEvent CraftBukkit Changes: febaa1c6 SPIGOT-6918: Add SpawnCategory API and configurations for Axolotls 9dafd109 Don't send updates over large distances bdac46b0 SPIGOT-6782: EntityPortalEvent should not destroy entity when setTo() uses same world as getFrom() 8f361ece PR-1002: Add Player Profile API 911875d4 Increase outdated build delay e5f8a767 SPIGOT-6917: Use main scoreboard for /trigger a672a531 Clean up callBlockDamageEvent 8e1bdeef SPIGOT-6910: Add BlockDamageAbortEvent Spigot Changes: 6edb62f3 Rebuild patches 7fbc6a1e Rebuild patches * Updated Upstream (CraftBukkit) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing CraftBukkit Changes: de951355 SPIGOT-6927: Fix default value of spawn-limits in Worlds
87 lines
5.1 KiB
Diff
87 lines
5.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Mariell Hoversholm <proximyst@proximyst.com>
|
|
Date: Mon, 27 Apr 2020 12:31:59 +0200
|
|
Subject: [PATCH] Prioritise own classes where possible
|
|
|
|
This adds the server property `Paper.DisableClassPrioritization` to disable
|
|
prioritization of own classes for plugins' classloaders.
|
|
|
|
This value is by default not present, and this will therefore break any
|
|
plugins which abuse behaviour related to not using their own classes
|
|
while still loading their own. This is often an issue with failing to
|
|
relocate or shade properly, such as when shading plugin APIs like Vault.
|
|
|
|
A plugin's classloader will first look in the same jar as it is loading
|
|
in for a requested class, then load it. It does not re-use other
|
|
plugins' classes if it has the chance to avoid doing so.
|
|
|
|
If a class is not found in the same jar as it is loading for and it does
|
|
find it elsewhere, it will still choose the class elsewhere. This is
|
|
intended behaviour, as it will only prioritise classes it has in its own
|
|
jar, no other plugins' classes will be prioritised in any other order
|
|
than the one they were registered in.
|
|
|
|
The patch in general terms just loads the class in the plugin's jar
|
|
before it starts looking elsewhere for it.
|
|
|
|
diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
|
index 4397fed2b41e5ab444aa7e3c9b5d7dccc50f4e04..d2712f45dbcf26fabe8463d99f378bf422c66970 100644
|
|
--- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
|
+++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
|
@@ -51,6 +51,7 @@ import org.yaml.snakeyaml.error.YAMLException;
|
|
*/
|
|
public final class JavaPluginLoader implements PluginLoader {
|
|
final Server server;
|
|
+ private static final boolean DISABLE_CLASS_PRIORITIZATION = Boolean.getBoolean("Paper.DisableClassPrioritization"); // Paper
|
|
private final Pattern[] fileFilters = new Pattern[]{Pattern.compile("\\.jar$")};
|
|
private final Map<String, java.util.concurrent.locks.ReentrantReadWriteLock> classLoadLock = new java.util.HashMap<String, java.util.concurrent.locks.ReentrantReadWriteLock>(); // Paper
|
|
private final Map<String, Integer> classLoadLockCount = new java.util.HashMap<String, Integer>(); // Paper
|
|
@@ -203,6 +204,11 @@ public final class JavaPluginLoader implements PluginLoader {
|
|
|
|
@Nullable
|
|
Class<?> getClassByName(final String name, boolean resolve, PluginDescriptionFile description) {
|
|
+ // Paper start - prioritize self
|
|
+ return getClassByName(name, resolve, description, null);
|
|
+ }
|
|
+ Class<?> getClassByName(final String name, boolean resolve, PluginDescriptionFile description, PluginClassLoader requester) {
|
|
+ // Paper end
|
|
// Paper start - make MT safe
|
|
java.util.concurrent.locks.ReentrantReadWriteLock lock;
|
|
synchronized (classLoadLock) {
|
|
@@ -210,6 +216,13 @@ public final class JavaPluginLoader implements PluginLoader {
|
|
classLoadLockCount.compute(name, (x, prev) -> prev != null ? prev + 1 : 1);
|
|
}
|
|
lock.writeLock().lock();try {
|
|
+ // Paper start - prioritize self
|
|
+ if (!DISABLE_CLASS_PRIORITIZATION && requester != null) {
|
|
+ try {
|
|
+ return requester.loadClass0(name, false, false, ((SimplePluginManager) server.getPluginManager()).isTransitiveDepend(description, requester.getDescription()));
|
|
+ } catch (ClassNotFoundException cnfe) {}
|
|
+ }
|
|
+ // Paper end
|
|
// Paper end
|
|
for (PluginClassLoader loader : loaders) {
|
|
try {
|
|
diff --git a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
|
|
index 684d7b1105350660fe7fc66f57a49db7f39610b4..46b705197e7520cea19da24769bce71406ec6a31 100644
|
|
--- a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
|
|
+++ b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
|
|
@@ -33,7 +33,7 @@ public final class PluginClassLoader extends URLClassLoader { // Spigot
|
|
public JavaPlugin getPlugin() { return plugin; } // Spigot
|
|
private final JavaPluginLoader loader;
|
|
private final Map<String, Class<?>> classes = new ConcurrentHashMap<String, Class<?>>();
|
|
- private final PluginDescriptionFile description;
|
|
+ private final PluginDescriptionFile description; PluginDescriptionFile getDescription() { return description; } // Paper
|
|
private final File dataFolder;
|
|
private final File file;
|
|
private final JarFile jar;
|
|
@@ -123,7 +123,7 @@ public final class PluginClassLoader extends URLClassLoader { // Spigot
|
|
|
|
if (checkGlobal) {
|
|
// This ignores the libraries of other plugins, unless they are transitive dependencies.
|
|
- Class<?> result = loader.getClassByName(name, resolve, description);
|
|
+ Class<?> result = loader.getClassByName(name, resolve, description, this); // Paper - prioritize self
|
|
|
|
if (result != null) {
|
|
// If the class was loaded from a library instead of a PluginClassLoader, we can assume that its associated plugin is a transitive dependency and can therefore skip this check.
|