Added a deprecation Error

This commit is contained in:
Shoghi Cervantes Pueyo 2013-01-21 19:01:00 +01:00
parent ef76138a1c
commit 039011d9bb
2 changed files with 72 additions and 10 deletions

View File

@ -0,0 +1,35 @@
<?php
/*
-
/ \
/ \
/ PocketMine \
/ MP \
|\ @shoghicp /|
|. \ / .|
| .. \ / .. |
| .. | .. |
| .. | .. |
\ | /
\ | /
\ | /
\ | /
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
*/
class Deprecation{
public static $events = array(
"world.block.change" => "block.change",
);
}

View File

@ -191,6 +191,12 @@ class PocketMinecraftServer{
public function addHandler($event, $callable, $priority = 5){ public function addHandler($event, $callable, $priority = 5){
if(!is_callable($callable)){ if(!is_callable($callable)){
return false; return false;
}elseif(isset(Deprecation::$events[$event])){
$sub = "";
if(Deprecation::$events[$event] !== false){
$sub = " Substitute \"".Deprecation::$events[$event]."\" found.";
}
console("[ERROR] Event \"$event\" has been deprecated.$sub [Adding handle to ".(is_array($callable) ? get_class($callable[0])."::".$callable[1]:$callable)."]");
} }
$priority = (int) $priority; $priority = (int) $priority;
$hnid = $this->handCnt++; $hnid = $this->handCnt++;
@ -227,7 +233,14 @@ class PocketMinecraftServer{
break; break;
} }
} }
}elseif(isset(Deprecation::$events[$event])){
$sub = "";
if(Deprecation::$events[$event] !== false){
$sub = " Substitute \"".Deprecation::$events[$event]."\" found.";
}
console("[ERROR] Event \"$event\" has been deprecated.$sub [Handler]");
} }
if($result !== false){ if($result !== false){
$this->trigger($event, $data); $this->trigger($event, $data);
} }
@ -533,18 +546,26 @@ class PocketMinecraftServer{
$call[(int) $evn["ID"]] = true; $call[(int) $evn["ID"]] = true;
} }
$events->finalize(); $events->finalize();
foreach($call as $evid => $boolean){ if(count($call) > 0){
$ev = $this->events[$evid]; foreach($call as $evid => $boolean){
if(!is_callable($ev)){ $ev = $this->events[$evid];
$this->deleteEvent($evid); if(!is_callable($ev)){
continue; $this->deleteEvent($evid);
continue;
}
if(is_array($ev)){
$method = $ev[1];
$ev[0]->$method($data, $event);
}else{
$ev($data, $event);
}
} }
if(is_array($ev)){ }elseif(isset(Deprecation::$events[$event])){
$method = $ev[1]; $sub = "";
$ev[0]->$method($data, $event); if(Deprecation::$events[$event] !== false){
}else{ $sub = " Substitute \"".Deprecation::$events[$event]."\" found.";
$ev($data, $event);
} }
console("[ERROR] Event \"$event\" has been deprecated.$sub [Trigger]");
} }
return true; return true;
@ -595,6 +616,12 @@ class PocketMinecraftServer{
public function event($event, $func){ public function event($event, $func){
if(!is_callable($func)){ if(!is_callable($func)){
return false; return false;
}elseif(isset(Deprecation::$events[$event])){
$sub = "";
if(Deprecation::$events[$event] !== false){
$sub = " Substitute \"".Deprecation::$events[$event]."\" found.";
}
console("[ERROR] Event \"$event\" has been deprecated.$sub [Attach to ".(is_array($func) ? get_class($func[0])."::".$func[1]:$func)."]");
} }
$evid = $this->evCnt++; $evid = $this->evCnt++;
$this->events[$evid] = $func; $this->events[$evid] = $func;