Remove built-in spawn protection

Users should use the new BasicSpawnProtection plugin instead.
This commit is contained in:
Dylan K. Taylor 2019-01-24 16:56:15 +00:00
parent df09b0101a
commit 469b24b0a5
5 changed files with 2 additions and 59 deletions

View File

@ -2164,10 +2164,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$target = $this->level->getBlock($pos); $target = $this->level->getBlock($pos);
$ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $target, null, $face, PlayerInteractEvent::LEFT_CLICK_BLOCK); $ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $target, null, $face, PlayerInteractEvent::LEFT_CLICK_BLOCK);
if($this->level->checkSpawnProtection($this, $target)){
$ev->setCancelled();
}
$ev->call(); $ev->call();
if($ev->isCancelled()){ if($ev->isCancelled()){
$this->inventory->sendHeldItem($this); $this->inventory->sendHeldItem($this);
@ -2462,7 +2458,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$this->doCloseInventory(); $this->doCloseInventory();
$pos = new Vector3($packet->x, $packet->y, $packet->z); $pos = new Vector3($packet->x, $packet->y, $packet->z);
if($pos->distanceSquared($this) > 10000 or $this->level->checkSpawnProtection($this, $pos)){ if($pos->distanceSquared($this) > 10000){
return true; return true;
} }
@ -2487,7 +2483,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
if($tile instanceof ItemFrame){ if($tile instanceof ItemFrame){
//TODO: use facing blockstate property instead of damage value //TODO: use facing blockstate property instead of damage value
$ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $tile->getBlock(), null, 5 - $tile->getBlock()->getDamage(), PlayerInteractEvent::LEFT_CLICK_BLOCK); $ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $tile->getBlock(), null, 5 - $tile->getBlock()->getDamage(), PlayerInteractEvent::LEFT_CLICK_BLOCK);
if($this->isSpectator() or $this->level->checkSpawnProtection($this, $tile)){ if($this->isSpectator()){
$ev->setCancelled(); $ev->setCancelled();
} }

View File

@ -455,13 +455,6 @@ class Server{
return $this->getConfigBool("white-list", false); return $this->getConfigBool("white-list", false);
} }
/**
* @return int
*/
public function getSpawnRadius() : int{
return $this->getConfigInt("spawn-protection", 16);
}
/** /**
* @return bool * @return bool
*/ */
@ -1070,7 +1063,6 @@ class Server{
"server-port" => 19132, "server-port" => 19132,
"white-list" => false, "white-list" => false,
"announce-player-achievements" => true, "announce-player-achievements" => true,
"spawn-protection" => 16,
"max-players" => 20, "max-players" => 20,
"gamemode" => 0, "gamemode" => 0,
"force-gamemode" => false, "force-gamemode" => false,

View File

@ -63,7 +63,6 @@ use pocketmine\level\particle\DestroyBlockParticle;
use pocketmine\level\particle\Particle; use pocketmine\level\particle\Particle;
use pocketmine\level\sound\Sound; use pocketmine\level\sound\Sound;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector2;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\metadata\BlockMetadataStore; use pocketmine\metadata\BlockMetadataStore;
use pocketmine\metadata\Metadatable; use pocketmine\metadata\Metadatable;
@ -1623,29 +1622,6 @@ class Level implements ChunkManager, Metadatable{
return $orbs; return $orbs;
} }
/**
* Checks if the level spawn protection radius will prevent the player from using items or building at the specified
* Vector3 position.
*
* @param Player $player
* @param Vector3 $vector
*
* @return bool true if spawn protection cancelled the action, false if not.
*/
public function checkSpawnProtection(Player $player, Vector3 $vector) : bool{
if(!$player->hasPermission("pocketmine.spawnprotect.bypass") and ($distance = $this->server->getSpawnRadius()) > -1){
$t = new Vector2($vector->x, $vector->z);
$spawnLocation = $this->getSpawnLocation();
$s = new Vector2($spawnLocation->x, $spawnLocation->z);
if($t->distance($s) <= $distance){
return true;
}
}
return false;
}
/** /**
* Tries to break a block using a item, including Player time checks if available * Tries to break a block using a item, including Player time checks if available
* It'll try to lower the durability if Item is a tool, and set it to Air if broken. * It'll try to lower the durability if Item is a tool, and set it to Air if broken.
@ -1680,8 +1656,6 @@ class Level implements ChunkManager, Metadatable{
if(($player->isSurvival() and !$target->isBreakable($item)) or $player->isSpectator()){ if(($player->isSurvival() and !$target->isBreakable($item)) or $player->isSpectator()){
$ev->setCancelled(); $ev->setCancelled();
}elseif($this->checkSpawnProtection($player, $target)){
$ev->setCancelled(); //set it to cancelled so plugins can bypass this
} }
if($player->isAdventure(true) and !$ev->isCancelled()){ if($player->isAdventure(true) and !$ev->isCancelled()){
@ -1788,10 +1762,6 @@ class Level implements ChunkManager, Metadatable{
if($player !== null){ if($player !== null){
$ev = new PlayerInteractEvent($player, $item, $blockClicked, $clickVector, $face, PlayerInteractEvent::RIGHT_CLICK_BLOCK); $ev = new PlayerInteractEvent($player, $item, $blockClicked, $clickVector, $face, PlayerInteractEvent::RIGHT_CLICK_BLOCK);
if($this->checkSpawnProtection($player, $blockClicked)){
$ev->setCancelled(); //set it to cancelled so plugins can bypass this
}
$ev->call(); $ev->call();
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
if(!$player->isSneaking() and $blockClicked->onActivate($item, $player)){ if(!$player->isSneaking() and $blockClicked->onActivate($item, $player)){
@ -1842,10 +1812,6 @@ class Level implements ChunkManager, Metadatable{
if($player !== null){ if($player !== null){
$ev = new BlockPlaceEvent($player, $hand, $blockReplace, $blockClicked, $item); $ev = new BlockPlaceEvent($player, $hand, $blockReplace, $blockClicked, $item);
if($this->checkSpawnProtection($player, $blockClicked)){
$ev->setCancelled();
}
if($player->isAdventure(true) and !$ev->isCancelled()){ if($player->isAdventure(true) and !$ev->isCancelled()){
$canPlace = false; $canPlace = false;
$tag = $item->getNamedTagEntry("CanPlaceOn"); $tag = $item->getNamedTagEntry("CanPlaceOn");

View File

@ -51,9 +51,6 @@ abstract class DefaultPermissions{
self::registerPermission(new Permission(self::ROOT . ".broadcast.user", "Allows the user to receive user broadcasts", Permission::DEFAULT_TRUE), $broadcasts); self::registerPermission(new Permission(self::ROOT . ".broadcast.user", "Allows the user to receive user broadcasts", Permission::DEFAULT_TRUE), $broadcasts);
$broadcasts->recalculatePermissibles(); $broadcasts->recalculatePermissibles();
$spawnprotect = self::registerPermission(new Permission(self::ROOT . ".spawnprotect.bypass", "Allows the user to edit blocks within the protected spawn radius", Permission::DEFAULT_OP), $parent);
$spawnprotect->recalculatePermissibles();
$commands = self::registerPermission(new Permission(self::ROOT . ".command", "Allows using all PocketMine commands"), $parent); $commands = self::registerPermission(new Permission(self::ROOT . ".command", "Allows using all PocketMine commands"), $parent);
$whitelist = self::registerPermission(new Permission(self::ROOT . ".command.whitelist", "Allows the user to modify the server whitelist", Permission::DEFAULT_OP), $commands); $whitelist = self::registerPermission(new Permission(self::ROOT . ".command.whitelist", "Allows the user to modify the server whitelist", Permission::DEFAULT_OP), $commands);

View File

@ -158,14 +158,6 @@ LICENSE;
$config->set("max-players", (int) $this->getInput($this->lang->get("max_players"), (string) self::DEFAULT_PLAYERS)); $config->set("max-players", (int) $this->getInput($this->lang->get("max_players"), (string) self::DEFAULT_PLAYERS));
$this->message($this->lang->get("spawn_protection_info"));
if(strtolower($this->getInput($this->lang->get("spawn_protection"), "y", "Y/n")) === "n"){
$config->set("spawn-protection", -1);
}else{
$config->set("spawn-protection", 16);
}
$config->save(); $config->save();
} }