mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-23 19:34:15 +00:00
Make CraftingManager::sort() more cool with spaceship operators 😎
This commit is contained in:
parent
145a4fad0f
commit
bc836aaec1
@ -145,21 +145,10 @@ class CraftingManager{
|
|||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public static function sort(Item $i1, Item $i2){
|
public static function sort(Item $i1, Item $i2){
|
||||||
if($i1->getId() > $i2->getId()){
|
//Use spaceship operator to compare each property, then try the next one if they are equivalent.
|
||||||
return 1;
|
($retval = $i1->getId() <=> $i2->getId()) === 0 && ($retval = $i1->getDamage() <=> $i2->getDamage()) === 0 && ($retval = $i1->getCount() <=> $i2->getCount());
|
||||||
}elseif($i1->getId() < $i2->getId()){
|
|
||||||
return -1;
|
return $retval;
|
||||||
}elseif($i1->getDamage() > $i2->getDamage()){
|
|
||||||
return 1;
|
|
||||||
}elseif($i1->getDamage() < $i2->getDamage()){
|
|
||||||
return -1;
|
|
||||||
}elseif($i1->getCount() > $i2->getCount()){
|
|
||||||
return 1;
|
|
||||||
}elseif($i1->getCount() < $i2->getCount()){
|
|
||||||
return -1;
|
|
||||||
}else{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user