Skip to content

Commit 38a68ba

Browse files
committed
Implemented
Everyone happy now?
1 parent 1eab144 commit 38a68ba

File tree

3 files changed

+65
-16
lines changed

3 files changed

+65
-16
lines changed

src/pocketmine/lang/locale/eng.ini

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,13 @@ pocketmine.plugin.load=Loading {%0}
310310
pocketmine.plugin.enable=Enabling {%0}
311311
pocketmine.plugin.disable=Disabling {%0}
312312
pocketmine.plugin.restrictedName=Restricted name
313-
pocketmine.plugin.incompatibleAPI=Incompatible API version
313+
pocketmine.plugin.incompatibleAPI=Error while calculationg
314+
pocketmine.plugin.incompatibleAPI.minorTooNew=Plugin has a too new minor API version. Check pocketmine.yml settings.
315+
pocketmine.plugin.incompatibleAPI.majorTooNew=Plugin has a too new major API version. Check pocketmine.yml settings.
316+
pocketmine.plugin.incompatibleAPI.majorTooOld=Plugin has a too old major API version. Check pocketmine.yml settings.
317+
pocketmine.plugin.incompatibleAPIWarning.minorTooNew=Plugin has a too new minor API version.
318+
pocketmine.plugin.incompatibleAPIWarning.majorTooNew=Plugin has a too new major API version.
319+
pocketmine.plugin.incompatibleAPIWarning.majorTooOld=Plugin has a too old major API version.
314320
pocketmine.plugin.unknownDependency=Unknown dependency
315321
pocketmine.plugin.circularDependency=Circular dependency detected
316322
pocketmine.plugin.genericLoadError=Could not load plugin '{%0}'

src/pocketmine/plugin/PluginManager.php

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,28 +192,60 @@ public function loadPlugins($directory, $newLoaders = null){
192192
continue;
193193
}
194194

195-
$compatible = false;
195+
//1=outdated plugin, 2=outdated server, 4=minor, 8=normal
196+
$compatibility = 0;
196197
//Check multiple dependencies
197-
foreach($description->getCompatibleApis() as $version){
198+
foreach($description->getCompatibleApis() as $versionString){
198199
//Format: majorVersion.minorVersion.patch
199-
$version = array_map("intval", explode(".", $version));
200+
$version = array_map("intval", explode(".", $versionString));
200201
$apiVersion = array_map("intval", explode(".", $this->server->getApiVersion()));
201-
//Completely different API version
202-
if($version[0] !== $apiVersion[0]){
202+
//Completely different API version: too old
203+
if($version[0] < $apiVersion[0]){
204+
$compatibility |= 1;
205+
continue;
206+
}
207+
//Completely different API version: too new
208+
if($version[0] > $apiVersion[0]){
209+
$compatibility |= 2;
203210
continue;
204211
}
205212
//If the plugin requires new API features, being backwards compatible
206213
if($version[1] > $apiVersion[1]){
214+
$compatibility |= 4;
207215
continue;
208216
}
209-
210-
$compatible = true;
217+
$compatibility |= 8;
211218
break;
212219
}
213-
214-
if($compatible === false){
215-
$this->server->getLogger()->error($this->server->getLanguage()->translateString("pocketmine.plugin.loadError", [$name, "%pocketmine.plugin.incompatibleAPI"]));
216-
continue;
220+
if(($compatibility & 8) === 0){
221+
$accept1 = $this->server->getProperty("settings.incompatible-plugins.plugin-too-old", false);
222+
$accept2 = $this->server->getProperty("settings.incompatible-plugins.plugin-too-new.major", false);
223+
$accept4 = $this->server->getProperty("settings.incompatible-plugins.plugin-too-new.minor", false);
224+
if(!$accept1){
225+
$compatibility &= ~1;
226+
}
227+
if(!$accept2){
228+
$compatibility &= ~2;
229+
}
230+
if(!$accept4){
231+
$compatibility &= ~4;
232+
}
233+
if($compatibility === 0){
234+
if(($compatibility & 4) === 0){
235+
$this->server->getLogger()->error($this->server->getLanguage()->translateString("pocketmine.plugin.loadError", [$name, "%pocketmine.plugin.incompatibleAPI.minorTooNew"]));
236+
}elseif(($compatibility & 2) === 0){
237+
$this->server->getLogger()->error($this->server->getLanguage()->translateString("pocketmine.plugin.loadError", [$name, "%pocketmine.plugin.incompatibleAPI.majortooNew"]));
238+
}else{
239+
$this->server->getLogger()->error($this->server->getLanguage()->translateString("pocketmine.plugin.loadError", [$name, "%pocketmine.plugin.incompatibleAPI.majorTooOld"]));
240+
}
241+
continue; #Abort loading of this plugin, move on to the next
242+
}elseif($compatibility & 4){
243+
$this->server->getLogger()->warning($this->server->getLanguage()->translateString("pocketmine.plugin.incompatibleAPIWarning.minorTooNew", [$name]));
244+
}elseif($compatibility & 2){
245+
$this->server->getLogger()->warning($this->server->getLanguage()->translateString("pocketmine.plugin.incompatibleAPIWarning.majorTooNew", [$name]));
246+
}elseif($compatibility & 1){
247+
$this->server->getLogger()->warning($this->server->getLanguage()->translateString("pocketmine.plugin.incompatibleAPIWarning.majorTooOld", [$name]));
248+
}
217249
}
218250

219251
$plugins[$name] = $file;

src/pocketmine/resources/pocketmine.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ settings:
2424
#If set to auto, the server will try to detect the number of cores (or use 2)
2525
config-update: true
2626
#Whether the server should "try" to add new configs automatically here
27+
#Load plugins with incompatible API versions
28+
#Do NOT report any bugs if any of these options is set to true.
29+
#Some plugins may crash the server, or do strange things to your savefiles.
30+
incompatible-plugins:
31+
plugin-too-new:
32+
#Load plugins whose major API version is too new
33+
major: false
34+
#Load plugins whose minor API version is too new
35+
minor: false
36+
#Load plugins whose major API version is too old
37+
plugin-too-old: false
2738

2839
player:
2940
inventory:
@@ -106,12 +117,12 @@ network:
106117
anti-cheat: false
107118
#Prevent cheating , but consider turn it off when have a bad network connection
108119
acceptable-packetlost: 2
109-
#If your server have a bad network connection , increase this
120+
#If your server have a bad network connection, increase this
110121
timeout: 1
111122
#Interrupt Raklib after reach timeout, save CPU usage, may cause packet lost.(-1 for disable , all pkt will send)
112-
protocol: 70
123+
protocol: 81
113124
#MCPE Protocol Version, it will affect the color of version string.
114-
version: "0.14.3"
125+
version: "0.15.0"
115126
#MCPE Version string shown in server list, number and dot(.) allowed
116127
upnp-forwarding: false
117128
#Experimental, only for Windows. Tries to use UPnP to automatically port forward
@@ -217,7 +228,7 @@ anonymous-statistics:
217228
host: stats.pocketmine.net
218229

219230
#!DO NOT EDIT below this line!
220-
version: 24
231+
version: 25
221232
# This is for internal use, changing this will reset your whole pocketmine.yml!
222233

223234
auto-report:

0 commit comments

Comments
 (0)