Advertisement
Guest User

Untitled

a guest
May 24th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.30 KB | None | 0 0
  1. <?php
  2.  
  3. namespace BoyFarmer;
  4.  
  5. use pocketmine\plugin\PluginBase;
  6. use pocketmine\event\Listener;
  7. use pocketmine\event\block\BlockPlaceEvent;
  8. use pocketmine\math\Vector3;
  9. use pocketmine\block\Block;
  10. use pocketmine\utils\TextFormat;
  11. use pocketmine\Player;
  12. use pocketmine\item\Item;
  13. use pocketmine\command\Command;
  14. use pocketmine\command\CommandSender;
  15.  
  16. class Main extends PluginBase implements Listener
  17. {
  18. private $mysqli_player_exists;
  19. private $price;
  20. private $mysqli;
  21. public function getApi() {
  22. return $this->getServer()->getPluginManager()->getPlugin("FactionsPro");
  23. }
  24. public function formatMessage($string) {
  25. return str_replace('&', '§', "&f• &c> [AMPE] $string &f•");
  26. }
  27. public function onEnable()
  28. {
  29. $this->saveDefaultConfig();
  30. $this->getServer()->getPluginManager()->registerEvents($this, $this);
  31.  
  32.  
  33. }
  34.  
  35.  
  36. public function onDisable()
  37. {
  38.  
  39. }
  40.  
  41. public function onCommand(CommandSender $sender, Command $command, $label, array $args)
  42. {
  43. $boyfarmer = Item::get(120, 0, 3);
  44. $boyfarmer->setCustomName("•Boyfarmerâ");
  45. if(strtolower($command->getName()) === "boyfarmer")
  46. {
  47. if(count($args) === 0)
  48. {
  49. foreach($this->getConfig()->getNested("boyfarmer.info") as $i)
  50. {
  51. $sender->sendMessage(str_replace('&', '§', $i));
  52. }
  53. return true;
  54. }
  55. if(count($args) === 1)
  56. {
  57. if($args[0] === "kup")
  58. {
  59. if($sender instanceof Player)
  60. {
  61. if($sender->getInventory()->contains(Item::get(264, 0, $this->getConfig()->getNested("boyfarmer.price.diamond"))) && $sender->getInventory()->contains(Item::get(49, 0, $this->getConfig()->getNested("boyfarmer.price.obsidian")))){
  62. $sender->getInventory()->removeItem(Item::get(264, 0, $this->getConfig()->getNested("boyfarmer.price.diamond")));
  63. $sender->getInventory()->removeItem(Item::get(49, 0, $this->getConfig()->getNested("boyfarmer.price.obsidian")));
  64. $sender->getInventory()->addItem($boyfarmer);
  65. $sender->sendMessage($this->formatMessage("&fPomyslnie kupiles Boyfarmer za " . $this->price . "$."));
  66. } else {
  67. $sender->sendMessage($this->formatMessage("&fNie stac Cie! Potrzebujesz jeszcze " . (($this->price) - $this->getMoney($sender->getName())) . "$."));
  68. return true;
  69. }
  70. }
  71. else
  72. {
  73. $sender->sendMessage("[AMPE] Blad! Musisz byc w grze.");
  74. return true;
  75. }
  76. }
  77. if($args[0] === "reload")
  78. {
  79. if($sender->hasPermission("boyfarmer.admin"))
  80. {
  81. $this->reloadConfig();
  82. $sender->sendMessage(TextFormat::RED . "[AMPE] Plugin zostal przeladowany.");
  83. return true;
  84. }
  85. else
  86. {
  87. $sender->sendMessage(TextFormat::RED . "[AMPE] Nie masz do tego uprawnien.");
  88. return true;
  89. }
  90. }
  91. }
  92. }
  93. return false;
  94. }
  95.  
  96. public function onBlockPlace(BlockPlaceEvent $e)
  97. {
  98. if(!$e->isCancelled())
  99. {
  100.  
  101. if($e->getPlayer()->getInventory()->getIteminHand()->getCustomName() === "•Boyfarmerâ")
  102. {
  103. $cobblex = Item::get(120, 0, 1);
  104. $cobblex->setCustomName("•Boyfarmerâ");
  105. $player = $e->getPlayer()->getName();
  106. $e->setCancelled(true);
  107. $e->getPlayer()->getInventory()->removeItem($cobblex);
  108. if(!$this->getApi()->inOwnPlot($e->getPlayer(), $e->getBlock()->getX(), $e->getBlock()->getZ()) && $this->getApi()->isInPlot($e->getBlock()->getX(), $e->getBlock()->getZ()) && !$e->getPlayer()->isOp()) {
  109. $e->setCancelled(true);
  110. $e->getPlayer()->sendMessage(TextFormat::WHITE . "• " . TextFormat::YELLOW . "[AMPE] " . TextFormat::RED . "Nie mozesz postawic BoyFarmera na terenie innej gildii!" . TextFormat::WHITE . "•");
  111. return true;
  112. }
  113.  
  114. if($e->getBlock()->getY() <= $this->getConfig()->getNested("boyfarmer.coordinator-y"))
  115. {
  116. $e->setCancelled(true);
  117. $e->getPlayer()->sendMessage(TextFormat::WHITE . "• " . TextFormat::YELLOW . "[AMPE] " . TextFormat::GRAY . "BoyFarmer zostal aktywowany! " . TextFormat::WHITE . "•");
  118. $e->getPlayer()->getInventory()->removeItem(Item::get(120, 0, 1));
  119. $e->getBlock()->getLevel()->setBlock(new Vector3($e->getBlock()->x, $e->getBlock()->y, $e->getBlock()->z), Block::get(Block::OBSIDIAN));
  120.  
  121. for($i=1; $i<200; $i++)
  122. {
  123. $block = $e->getBlock()->getLevel()->getBlock(new Vector3($e->getBlock()->x, $e->getBlock()->y -$i, $e->getBlock()->z));
  124. if($block->getId() === 0)
  125. {
  126. $e->getBlock()->getLevel()->setBlock(new Vector3($e->getBlock()->x, $e->getBlock()->y -$i, $e->getBlock()->z), Block::get(Block::OBSIDIAN));
  127. }
  128. }
  129. }
  130. else
  131. {
  132. $e->getPlayer()->sendMessage(TextFormat::WHITE . "• " . TextFormat::YELLOW . "[AMPE] " . TextFormat::RED . "Blad! BoyFarmer nie moze przekroczyc koordynatu Y: " . $this->getConfig()->getNested("boyfarmer.coordinator-y") . TextFormat::RED . ". " . TextFormat::WHITE . "•");
  133. $e->setCancelled();
  134. }
  135. }
  136. } else
  137. {
  138. $e->setCancelled();
  139. }
  140. }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement