mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 11:06:29 +01:00
SPIGOT-5106: Config option to prevent plugins with incompatible API's from loading
This commit is contained in:
parent
c69979247b
commit
63cde5caa5
@ -220,6 +220,7 @@ public final class CraftServer implements Server {
|
|||||||
private int ambientSpawn = -1;
|
private int ambientSpawn = -1;
|
||||||
private File container;
|
private File container;
|
||||||
private WarningState warningState = WarningState.DEFAULT;
|
private WarningState warningState = WarningState.DEFAULT;
|
||||||
|
public String minimumAPI;
|
||||||
public CraftScoreboardManager scoreboardManager;
|
public CraftScoreboardManager scoreboardManager;
|
||||||
public boolean playerCommandState;
|
public boolean playerCommandState;
|
||||||
private boolean printSaveWarning;
|
private boolean printSaveWarning;
|
||||||
@ -305,6 +306,7 @@ public final class CraftServer implements Server {
|
|||||||
ambientSpawn = configuration.getInt("spawn-limits.ambient");
|
ambientSpawn = configuration.getInt("spawn-limits.ambient");
|
||||||
console.autosavePeriod = configuration.getInt("ticks-per.autosave");
|
console.autosavePeriod = configuration.getInt("ticks-per.autosave");
|
||||||
warningState = WarningState.value(configuration.getString("settings.deprecated-verbose"));
|
warningState = WarningState.value(configuration.getString("settings.deprecated-verbose"));
|
||||||
|
minimumAPI = configuration.getString("settings.minimum-api");
|
||||||
loadIcon();
|
loadIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -714,6 +716,7 @@ public final class CraftServer implements Server {
|
|||||||
waterAnimalSpawn = configuration.getInt("spawn-limits.water-animals");
|
waterAnimalSpawn = configuration.getInt("spawn-limits.water-animals");
|
||||||
ambientSpawn = configuration.getInt("spawn-limits.ambient");
|
ambientSpawn = configuration.getInt("spawn-limits.ambient");
|
||||||
warningState = WarningState.value(configuration.getString("settings.deprecated-verbose"));
|
warningState = WarningState.value(configuration.getString("settings.deprecated-verbose"));
|
||||||
|
minimumAPI = configuration.getString("settings.minimum-api");
|
||||||
printSaveWarning = false;
|
printSaveWarning = false;
|
||||||
console.autosavePeriod = configuration.getInt("ticks-per.autosave");
|
console.autosavePeriod = configuration.getInt("ticks-per.autosave");
|
||||||
loadIcon();
|
loadIcon();
|
||||||
|
@ -8,8 +8,10 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
|||||||
import com.mojang.datafixers.Dynamic;
|
import com.mojang.datafixers.Dynamic;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -245,14 +247,29 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|||||||
return file.delete();
|
return file.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final List<String> SUPPORTED_API = Arrays.asList("1.13", "1.14");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void checkSupported(PluginDescriptionFile pdf) throws InvalidPluginException {
|
public void checkSupported(PluginDescriptionFile pdf) throws InvalidPluginException {
|
||||||
|
String minimumVersion = MinecraftServer.getServer().server.minimumAPI;
|
||||||
|
int minimumIndex = SUPPORTED_API.indexOf(minimumVersion);
|
||||||
|
|
||||||
if (pdf.getAPIVersion() != null) {
|
if (pdf.getAPIVersion() != null) {
|
||||||
if (!pdf.getAPIVersion().equals("1.13") && !pdf.getAPIVersion().equals("1.14")) {
|
int pluginIndex = SUPPORTED_API.indexOf(pdf.getAPIVersion());
|
||||||
|
|
||||||
|
if (pluginIndex == -1) {
|
||||||
throw new InvalidPluginException("Unsupported API version " + pdf.getAPIVersion());
|
throw new InvalidPluginException("Unsupported API version " + pdf.getAPIVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pluginIndex < minimumIndex) {
|
||||||
|
throw new InvalidPluginException("Plugin API version " + pdf.getAPIVersion() + " is lower than the minimum allowed version. Please update or replace it.");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Plugin " + pdf.getFullName() + " does not specify an api-version.");
|
if (minimumIndex == -1) {
|
||||||
|
Bukkit.getLogger().log(Level.WARNING, "Plugin " + pdf.getFullName() + " does not specify an api-version.");
|
||||||
|
} else {
|
||||||
|
throw new InvalidPluginException("Plugin API version " + pdf.getAPIVersion() + " is lower than the minimum allowed version. Please update or replace it.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ settings:
|
|||||||
query-plugins: true
|
query-plugins: true
|
||||||
deprecated-verbose: default
|
deprecated-verbose: default
|
||||||
shutdown-message: Server closed
|
shutdown-message: Server closed
|
||||||
|
minimum-api: none
|
||||||
spawn-limits:
|
spawn-limits:
|
||||||
monsters: 70
|
monsters: 70
|
||||||
animals: 10
|
animals: 10
|
||||||
|
Loading…
Reference in New Issue
Block a user