mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-09 11:31:49 +00:00
Obligatory Creative mode item enforcement
This commit is contained in:
parent
bc80c01348
commit
fd8166c836
@ -39,6 +39,111 @@ define("BLOCK_UPDATE_TOUCH", 4);
|
|||||||
class BlockAPI{
|
class BlockAPI{
|
||||||
private $server;
|
private $server;
|
||||||
private $scheduledUpdates = array();
|
private $scheduledUpdates = array();
|
||||||
|
public static $creative = array(
|
||||||
|
array(COBBLESTONE, 0),
|
||||||
|
array(STONE_BRICKS, 0),
|
||||||
|
array(STONE_BRICKS, 1),
|
||||||
|
array(STONE_BRICKS, 2),
|
||||||
|
array(MOSS_STONE, 0),
|
||||||
|
array(WOODEN_PLANKS, 0),
|
||||||
|
array(BRICKS, 0),
|
||||||
|
array(STONE, 0),
|
||||||
|
array(DIRT, 0),
|
||||||
|
array(GRASS, 0),
|
||||||
|
array(CLAY_BLOCK, 0),
|
||||||
|
array(SANDSTONE, 0),
|
||||||
|
array(SANDSTONE, 1),
|
||||||
|
array(SANDSTONE, 2),
|
||||||
|
array(SAND, 0),
|
||||||
|
array(GRAVEL, 0),
|
||||||
|
array(TRUNK, 0),
|
||||||
|
array(TRUNK, 1),
|
||||||
|
array(TRUNK, 2),
|
||||||
|
array(NETHER_BRICKS, 0),
|
||||||
|
array(NETHERRACK, 0),
|
||||||
|
array(COBBLESTONE_STAIRS, 0),
|
||||||
|
array(WOODEN_STAIRS, 0),
|
||||||
|
array(BRICK_STAIRS, 0),
|
||||||
|
array(SANDSTONE_STAIRS, 0),
|
||||||
|
array(STONE_BRICK_STAIRS, 0),
|
||||||
|
array(NETHER_BRICKS_STAIRS, 0),
|
||||||
|
array(QUARTZ_STAIRS, 0),
|
||||||
|
array(SLAB, 0),
|
||||||
|
array(SLAB, 1),
|
||||||
|
array(SLAB, 2),
|
||||||
|
array(SLAB, 3),
|
||||||
|
array(SLAB, 4),
|
||||||
|
array(SLAB, 5),
|
||||||
|
array(QUARTZ_BLOCK, 0),
|
||||||
|
array(QUARTZ_BLOCK, 1),
|
||||||
|
array(QUARTZ_BLOCK, 2),
|
||||||
|
array(COAL_ORE, 0),
|
||||||
|
array(IRON_ORE, 0),
|
||||||
|
array(GOLD_ORE, 0),
|
||||||
|
array(DIAMOND_ORE, 0),
|
||||||
|
array(LAPIS_ORE, 0),
|
||||||
|
array(REDSTONE_ORE, 0),
|
||||||
|
array(GOLD_BLOCK, 0),
|
||||||
|
array(IRON_BLOCK, 0),
|
||||||
|
array(DIAMOND_BLOCK, 0),
|
||||||
|
array(LAPIS_BLOCK, 0),
|
||||||
|
array(OBSIDIAN, 0),
|
||||||
|
array(SNOW_BLOCK, 0),
|
||||||
|
array(GLASS, 0),
|
||||||
|
array(GLOWSTONE_BLOCK, 0),
|
||||||
|
array(NETHER_REACTOR, 0),
|
||||||
|
array(WOOL, 0),
|
||||||
|
array(WOOL, 7),
|
||||||
|
array(WOOL, 6),
|
||||||
|
array(WOOL, 5),
|
||||||
|
array(WOOL, 4),
|
||||||
|
array(WOOL, 3),
|
||||||
|
array(WOOL, 2),
|
||||||
|
array(WOOL, 1),
|
||||||
|
array(WOOL, 15),
|
||||||
|
array(WOOL, 14),
|
||||||
|
array(WOOL, 13),
|
||||||
|
array(WOOL, 12),
|
||||||
|
array(WOOL, 11),
|
||||||
|
array(WOOL, 10),
|
||||||
|
array(WOOL, 9),
|
||||||
|
array(WOOL, 8),
|
||||||
|
array(LADDER, 0),
|
||||||
|
array(TORCH, 0),
|
||||||
|
array(GLASS_PANE, 0),
|
||||||
|
array(WOODEN_DOOR, 0),
|
||||||
|
array(TRAPDOOR, 0),
|
||||||
|
array(FENCE, 0),
|
||||||
|
array(FENCE_GATE, 0),
|
||||||
|
array(BED, 0),
|
||||||
|
array(BOOKSHELF, 0),
|
||||||
|
array(PAINTING, 0),
|
||||||
|
array(WORKBENCH, 0),
|
||||||
|
array(STONECUTTER, 0),
|
||||||
|
array(CHEST, 0),
|
||||||
|
array(FURNACE, 0),
|
||||||
|
array(TNT, 0),
|
||||||
|
array(DANDELION, 0),
|
||||||
|
array(CYAN_FLOWER, 0),
|
||||||
|
array(BROWN_MUSHROOM, 0),
|
||||||
|
array(RED_MUSHROOM, 0),
|
||||||
|
array(CACTUS, 0),
|
||||||
|
array(MELON_BLOCK, 0),
|
||||||
|
array(SUGARCANE, 0),
|
||||||
|
array(SAPLING, 0),
|
||||||
|
array(SAPLING, 1),
|
||||||
|
array(SAPLING, 2),
|
||||||
|
array(LEAVES, 0),
|
||||||
|
array(LEAVES, 1),
|
||||||
|
array(LEAVES, 2),
|
||||||
|
array(SEEDS, 0),
|
||||||
|
array(MELON_SEEDS, 0),
|
||||||
|
array(DYE, 15), //Bonemeal
|
||||||
|
array(IRON_HOE, 0),
|
||||||
|
array(IRON_SWORD, 0),
|
||||||
|
array(BOW, 0),
|
||||||
|
array(SIGN, 0),
|
||||||
|
);
|
||||||
|
|
||||||
public static function fromString($str, $multiple = false){
|
public static function fromString($str, $multiple = false){
|
||||||
if($multiple === true){
|
if($multiple === true){
|
||||||
@ -151,6 +256,10 @@ class BlockAPI{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($player instanceof Player){
|
if($player instanceof Player){
|
||||||
|
if($player->gamemode === CREATIVE){
|
||||||
|
$output .= "Player is in creative mode.\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
if($this->server->api->getProperty("item-enforcement") === false){
|
if($this->server->api->getProperty("item-enforcement") === false){
|
||||||
$this->drop(new Vector3($player->entity->x - 0.5, $player->entity->y, $player->entity->z - 0.5), $item, true);
|
$this->drop(new Vector3($player->entity->x - 0.5, $player->entity->y, $player->entity->z - 0.5), $item, true);
|
||||||
}else{
|
}else{
|
||||||
@ -158,7 +267,7 @@ class BlockAPI{
|
|||||||
}
|
}
|
||||||
$output .= "Giving ".$item->count." of ".$item->getName()." (".$item->getID().":".$item->getMetadata().") to ".$player->username."\n";
|
$output .= "Giving ".$item->count." of ".$item->getName()." (".$item->getID().":".$item->getMetadata().") to ".$player->username."\n";
|
||||||
}else{
|
}else{
|
||||||
$output .= "Unknown player\n";
|
$output .= "Unknown player.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -241,7 +350,7 @@ class BlockAPI{
|
|||||||
$block = $this->getBlockFace($target, $face);
|
$block = $this->getBlockFace($target, $face);
|
||||||
$item = $player->equipment;
|
$item = $player->equipment;
|
||||||
|
|
||||||
if($target->getID() === AIR and $this->server->api->dhandle("player.block.place.invalid", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true){ //If no block exists
|
if($target->getID() === AIR and $this->server->api->dhandle("player.block.place.invalid", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true){ //If no block exists or not allowed in CREATIVE
|
||||||
$this->cancelAction($target, $player);
|
$this->cancelAction($target, $player);
|
||||||
return $this->cancelAction($block, $player);
|
return $this->cancelAction($block, $player);
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,7 @@ class Player{
|
|||||||
private $chunksLoaded = array();
|
private $chunksLoaded = array();
|
||||||
private $chunksOrder = array();
|
private $chunksOrder = array();
|
||||||
private $lag = array(0, 0);
|
private $lag = array(0, 0);
|
||||||
|
public $itemEnforcement;
|
||||||
public $lastCorrect;
|
public $lastCorrect;
|
||||||
|
|
||||||
function __construct($clientID, $ip, $port, $MTU){
|
function __construct($clientID, $ip, $port, $MTU){
|
||||||
@ -71,6 +72,7 @@ class Player{
|
|||||||
$this->CID = $this->server->clientID($ip, $port);
|
$this->CID = $this->server->clientID($ip, $port);
|
||||||
$this->ip = $ip;
|
$this->ip = $ip;
|
||||||
$this->port = $port;
|
$this->port = $port;
|
||||||
|
$this->itemEnforcement = $this->server->api->getProperty("item-enforcement");
|
||||||
$this->timeout = microtime(true) + 20;
|
$this->timeout = microtime(true) + 20;
|
||||||
$this->inventory = array_fill(0, 36, array(AIR, 0, 0));
|
$this->inventory = array_fill(0, 36, array(AIR, 0, 0));
|
||||||
$this->armor = array_fill(0, 4, array(AIR, 0, 0));
|
$this->armor = array_fill(0, 4, array(AIR, 0, 0));
|
||||||
@ -268,9 +270,14 @@ class Player{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setSlot($slot, Item $item){
|
||||||
|
$this->inventory[(int) $slot] = array($item->getID(), $item->getMetadata(), $item->count);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public function sendInventorySlot($s){
|
public function sendInventorySlot($s){
|
||||||
$s = (int) $s;
|
$s = (int) $s;
|
||||||
if(!isset($this->inventory[$s]) or $this->server->api->getProperty("item-enforcement") === false){
|
if(!isset($this->inventory[$s]) or ($this->itemEnforcement === false and $this->gamemode !== CREATIVE)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,11 +344,6 @@ class Player{
|
|||||||
$this->dataPacket(MC_PLAYER_ARMOR_EQUIPMENT, $data);
|
$this->dataPacket(MC_PLAYER_ARMOR_EQUIPMENT, $data);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "player.block.place":
|
|
||||||
if($data["eid"] === $this->eid and ($this->gamemode === SURVIVAL or $this->gamemode === ADVENTURE)){
|
|
||||||
$this->removeItem($data["original"]->getID(), $data["original"]->getMetadata(), 1);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "player.pickup":
|
case "player.pickup":
|
||||||
if($data["eid"] === $this->eid){
|
if($data["eid"] === $this->eid){
|
||||||
$data["eid"] = 0;
|
$data["eid"] = 0;
|
||||||
@ -557,6 +559,7 @@ class Player{
|
|||||||
}else{
|
}else{
|
||||||
$this->blocked = true;
|
$this->blocked = true;
|
||||||
$this->gamemode = $gm;
|
$this->gamemode = $gm;
|
||||||
|
$this->inventory = array_fill(0, 36, array(AIR, 0, 0));
|
||||||
$this->eventHandler("Your gamemode has been changed to ".$this->getGamemode().", you've to do a forced reconnect.", "server.chat");
|
$this->eventHandler("Your gamemode has been changed to ".$this->getGamemode().", you've to do a forced reconnect.", "server.chat");
|
||||||
$this->server->schedule(30, array($this, "close"), "gamemode change"); //Forces a kick
|
$this->server->schedule(30, array($this, "close"), "gamemode change"); //Forces a kick
|
||||||
}
|
}
|
||||||
@ -733,6 +736,13 @@ class Player{
|
|||||||
|
|
||||||
$this->auth = true;
|
$this->auth = true;
|
||||||
if(!$this->data->exists("inventory") or $this->gamemode === CREATIVE){
|
if(!$this->data->exists("inventory") or $this->gamemode === CREATIVE){
|
||||||
|
if($this->gamemode === CREATIVE){
|
||||||
|
$this->itemEnforcement = true;
|
||||||
|
$this->inventory = array();
|
||||||
|
foreach(BlockAPI::$creative as $item){
|
||||||
|
$this->inventory[] = array($item[0], $item[1], 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
$this->data->set("inventory", $this->inventory);
|
$this->data->set("inventory", $this->inventory);
|
||||||
}
|
}
|
||||||
$this->data->set("caseusername", $this->username);
|
$this->data->set("caseusername", $this->username);
|
||||||
@ -780,7 +790,6 @@ class Player{
|
|||||||
$this->evid[] = $this->server->event("player.armor", array($this, "eventHandler"));
|
$this->evid[] = $this->server->event("player.armor", array($this, "eventHandler"));
|
||||||
$this->evid[] = $this->server->event("player.pickup", array($this, "eventHandler"));
|
$this->evid[] = $this->server->event("player.pickup", array($this, "eventHandler"));
|
||||||
$this->evid[] = $this->server->event("block.change", array($this, "eventHandler"));
|
$this->evid[] = $this->server->event("block.change", array($this, "eventHandler"));
|
||||||
$this->evid[] = $this->server->event("player.block.place", array($this, "eventHandler"));
|
|
||||||
$this->evid[] = $this->server->event("tile.container.slot", array($this, "eventHandler"));
|
$this->evid[] = $this->server->event("tile.container.slot", array($this, "eventHandler"));
|
||||||
$this->server->schedule(40, array($this, "measureLag"), array(), true);
|
$this->server->schedule(40, array($this, "measureLag"), array(), true);
|
||||||
console("[INFO] \x1b[33m".$this->username."\x1b[0m[/".$this->ip.":".$this->port."] logged in with entity id ".$this->eid." at (".round($this->entity->x, 2).", ".round($this->entity->y, 2).", ".round($this->entity->z, 2).")");
|
console("[INFO] \x1b[33m".$this->username."\x1b[0m[/".$this->ip.":".$this->port."] logged in with entity id ".$this->eid." at (".round($this->entity->x, 2).", ".round($this->entity->y, 2).", ".round($this->entity->z, 2).")");
|
||||||
@ -846,7 +855,7 @@ class Player{
|
|||||||
$data["eid"] = $this->eid;
|
$data["eid"] = $this->eid;
|
||||||
$data["player"] = $this;
|
$data["player"] = $this;
|
||||||
$data["item"] = BlockAPI::getItem($data["block"], $data["meta"]);
|
$data["item"] = BlockAPI::getItem($data["block"], $data["meta"]);
|
||||||
if(($this->hasItem($data["block"], $data["meta"]) or $this->server->api->getProperty("item-enforcement") !== true) and $this->server->handle("player.equipment.change", $data) !== false){
|
if(($this->hasItem($data["block"], $data["meta"]) or $this->itemEnforcement !== true) and $this->server->handle("player.equipment.change", $data) !== false){
|
||||||
$this->equipment = $data["item"];
|
$this->equipment = $data["item"];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -862,7 +871,7 @@ class Player{
|
|||||||
$data["eid"] = $this->eid;
|
$data["eid"] = $this->eid;
|
||||||
if($this->blocked === true or Utils::distance($this->entity->position, $data) > 10){
|
if($this->blocked === true or Utils::distance($this->entity->position, $data) > 10){
|
||||||
break;
|
break;
|
||||||
}elseif(($this->gamemode === SURVIVAL or $this->gamemode === ADVENTURE) and !$this->hasItem($data["block"], $data["meta"]) and $this->server->api->getProperty("item-enforcement") === true){
|
}elseif(!$this->hasItem($data["block"], $data["meta"]) and $this->itemEnforcement === true){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$this->server->api->block->playerBlockAction($this, new Vector3($data["x"], $data["y"], $data["z"]), $data["face"], $data["fx"], $data["fy"], $data["fz"]);
|
$this->server->api->block->playerBlockAction($this, new Vector3($data["x"], $data["y"], $data["z"]), $data["face"], $data["fx"], $data["fy"], $data["fz"]);
|
||||||
@ -1007,7 +1016,7 @@ class Player{
|
|||||||
364 => 8,
|
364 => 8,
|
||||||
);
|
);
|
||||||
if(isset($items[$this->equipment->getID()])){
|
if(isset($items[$this->equipment->getID()])){
|
||||||
if($this->removeItem($this->equipment->getID(), $this->equipment->getMetadata(), 1) === true or $this->server->api->getProperty("item-enforcement") !== true){
|
if($this->removeItem($this->equipment->getID(), $this->equipment->getMetadata(), 1) === true or $this->itemEnforcement !== true){
|
||||||
$this->dataPacket(MC_ENTITY_EVENT, array(
|
$this->dataPacket(MC_ENTITY_EVENT, array(
|
||||||
"eid" => 0,
|
"eid" => 0,
|
||||||
"event" => 9,
|
"event" => 9,
|
||||||
@ -1025,7 +1034,7 @@ class Player{
|
|||||||
$item = BlockAPI::getItem($data["block"], $data["meta"], $data["stack"]);
|
$item = BlockAPI::getItem($data["block"], $data["meta"], $data["stack"]);
|
||||||
$data["item"] = $item;
|
$data["item"] = $item;
|
||||||
if($this->blocked === false and $this->server->handle("player.drop", $data) !== false){
|
if($this->blocked === false and $this->server->handle("player.drop", $data) !== false){
|
||||||
if($this->removeItem($item->getID(), $item->getMetadata(), $item->count) === true or $this->server->api->getProperty("item-enforcement") !== true){
|
if($this->removeItem($item->getID(), $item->getMetadata(), $item->count) === true or $this->itemEnforcement !== true){
|
||||||
$this->server->api->block->drop(new Vector3($this->entity->x - 0.5, $this->entity->y, $this->entity->z - 0.5), $item);
|
$this->server->api->block->drop(new Vector3($this->entity->x - 0.5, $this->entity->y, $this->entity->z - 0.5), $item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1105,14 +1114,14 @@ class Player{
|
|||||||
}
|
}
|
||||||
if($item->getID() !== AIR and $slot->getID() == $item->getID()){
|
if($item->getID() !== AIR and $slot->getID() == $item->getID()){
|
||||||
if($slot->count < $item->count){
|
if($slot->count < $item->count){
|
||||||
if($this->removeItem($item->getID(), $item->getMetadata(), $item->count - $slot->count) === false and $this->server->api->getProperty("item-enforcement") === true){
|
if($this->removeItem($item->getID(), $item->getMetadata(), $item->count - $slot->count) === false and $this->itemEnforcement === true){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}elseif($slot->count > $item->count){
|
}elseif($slot->count > $item->count){
|
||||||
$this->addItem($item->getID(), $item->getMetadata(), $slot->count - $item->count);
|
$this->addItem($item->getID(), $item->getMetadata(), $slot->count - $item->count);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if($this->removeItem($item->getID(), $item->getMetadata(), $item->count) === false and $this->server->api->getProperty("item-enforcement") === true){
|
if($this->removeItem($item->getID(), $item->getMetadata(), $item->count) === false and $this->itemEnforcement === true){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$this->addItem($slot->getID(), $slot->getMetadata(), $slot->count);
|
$this->addItem($slot->getID(), $slot->getMetadata(), $slot->count);
|
||||||
|
@ -34,6 +34,7 @@ define("COBBLE", 4);
|
|||||||
define("PLANK", 5);
|
define("PLANK", 5);
|
||||||
define("PLANKS", 5);
|
define("PLANKS", 5);
|
||||||
define("WOODEN_PLANK", 5);
|
define("WOODEN_PLANK", 5);
|
||||||
|
define("WOODEN_PLANKS", 5);
|
||||||
define("SAPLING", 6);
|
define("SAPLING", 6);
|
||||||
define("SAPLINGS", 6);
|
define("SAPLINGS", 6);
|
||||||
define("BEDROCK", 7);
|
define("BEDROCK", 7);
|
||||||
|
@ -60,7 +60,9 @@ class PaintingItem extends Item{
|
|||||||
$server = ServerAPI::request();
|
$server = ServerAPI::request();
|
||||||
$e = $server->api->entity->add(ENTITY_OBJECT, OBJECT_PAINTING, $data);
|
$e = $server->api->entity->add(ENTITY_OBJECT, OBJECT_PAINTING, $data);
|
||||||
$server->api->entity->spawnToAll($e->eid);
|
$server->api->entity->spawnToAll($e->eid);
|
||||||
|
if($player->gamemode !== CREATIVE){
|
||||||
$player->removeItem($this->getID(), $this->getMetadata(), 1);
|
$player->removeItem($this->getID(), $this->getMetadata(), 1);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user