Browse Source

Moving forward !

master
Ad5001 3 years ago
parent
commit
9d4e564699
4 changed files with 233 additions and 0 deletions
  1. 31
    0
      LICENSE
  2. 9
    0
      plugin.yml
  3. 18
    0
      resources/config.yml
  4. 175
    0
      src/Ad5001/SpectatorPlus/Main.php

+ 31
- 0
LICENSE View File

@@ -0,0 +1,31 @@
BoxOfDevs General Software License 1.1
=========================================
This license is designed to be used with any free open source softwares. It can be found @ https://products.boxofdevs.com/.
--------------------------------------------------------------------------------------------------------------------------------------
The License: refers to the BoxOfDevs International Software License 1.0.
The Software: refers to any works licensed under The License.
The Modification: refers to any modified version of The Software.
The Redistribution: refers to any redistributions of The Software/The Modification.
The User: refers to any user of The Software licensed under The License.
The Author: refers to any developer, organisation, legal owner, or creator of The Software that has been licensed under the The License.
--------------------------------------------------------------------------------------------------------------------------------------
Section 1 - Allowances:
1. Both The User & The Author Can:
a. Modify private copies of The Software and use in any way they wish.
b. Change which license The Software/The Modification is licensed under.
2. The User Can:
a. Request new features, support, or more rights from The Author.
b. Redistribute The Software/The Modification, ensuring The User gives all appropriate credit to The Author and alerting The Author to The Redistribution.
3. The Author Can:
a. Change or update The Software in any way they wish, ensuring they follow the other terms of The License.
b. Grant extra rights to The User who has requested them.
Section 2 - Restrictions:
1. Both The User & The Author Cannot:
a. Introduce any malicious code into The Software/The Modification.
b. Sell any part of The Software/The Modification for profit.
2. The User Cannot:
a. Hold The Author responsible for any unknown errors.
b. Claim The Software/The Modification/The Redistribution as entirely The User's product.
3. The Author Cannot:
a. Restrict The User in any way not specified by The License.
b. Distribute any form of The Software without proper documentation.

+ 9
- 0
plugin.yml View File

@@ -0,0 +1,9 @@
---
name: SpectatorPlus
author: Ad5001
version: 1.0
api: [2.0.0]
main: Ad5001\SpectatorPlus\Main
commands: []
permissions: []
...

+ 18
- 0
resources/config.yml View File

@@ -0,0 +1,18 @@
---
# Welcome to SpectatorPlus config !
# Here you can configure every name and messages that are managed by this plugin.

# The message used when teleporting to a player in spectator mode using a compass
TeleportMessage: "{player}, you have been teleported to {to}. In-game players remaining: {count}"
# The message when you click the bed to get back to the lobby.
LobbyMessage: Welcome back to lobby {player}

# Here is the name of the compass
TPCompassName: Find player
# Here is the name of the back-to-lobby bed.
BedBackName: Back to lobby

# Name of the lobby world
LobbyWorld:

...

+ 175
- 0
src/Ad5001/SpectatorPlus/Main.php View File

@@ -0,0 +1,175 @@
<?php
namespace Ad5001\SpectatorPlus;
use pocketmine\command\CommandSender;
use pocketmine\command\Command;
use pocketmine\event\Listener;
use pocketmine\plugin\PluginBase;
use pocketmine\event\player\PlayerGameModeChangeEvent;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\event\player\PlayerChatEvent;
use pocketmine\event\block\BlockBreakEvent;
use pocketmine\event\block\BlockPlaceEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\nbt\NBT;
use pocketmine\Server;
use pocketmine\Player;


class Main extends PluginBase implements Listener{


public function onEnable(){
$this->reloadConfig();
$this->getServer()->getPluginManager()->registerEvents($this, $this);
$this->getServer()->getScheduler()->scheduleRepeatingTask(new setGamemodeTask($this), 5);
$this->players = [];
$this->lastPlayer = null;
}


public function onLoad(){
$this->saveDefaultConfig();
}
public function test(Player $p, int $id) {
$this->getLogger()->info("Item : " . $id . ". Is spectator : " . $this->isSpectator($p));
if($this->isSpectator($p) and $id == 345) {
// if($event->getPacket() instanceof \pocketmine\network\protocol\UseItemPacket) {
$founds = [];
foreach($p->getLevel()->getPlayers() as $player) {
if(!$this->isSpectator($player)) {
array_push($founds, $player);
if(!in_array($player, $this->players[$p->getName()]) and !isset($found)) {
array_push($this->players[$p->getName()], $player);
$found = true;
$event->getPlayer()->teleport(new Vector3($player->x, $player->y, $player->z));
$event->getPlayer()->sendTip(str_ireplace("{to}", $player->getName(), str_ireplace("{player}", $p->getName(), str_ireplace("{count}", count($founds), $this->getConfig()->get("TeleportMessage")))));
}
}
}
if(!isset($found)) {
$this->players[$p->getName()] = [];
}
foreach($p->getLevel()->getPlayers() as $player) {
if(!$this->isSpectator($player)) {
array_push($founds, $player);
if(!in_array($player, $this->players[$p->getName()]) and !isset($found)) {
array_push($this->players[$p->getName()], $player);
$found = true;
$p->teleport(new Vector3($player->x, $player->y, $player->z));
$event->getPlayer()->sendTip(str_ireplace("{to}", $player->getName(), str_ireplace("{player}", $p->getName(), str_ireplace("{count}", count($founds), $this->getConfig()->get("TeleportMessage")))));
}
}
}
// }
} elseif($this->isSpectator($event->getPlayer()) and $id == 355) {
// if($event->getPacket() instanceof \pocketmine\network\protocol\UseItemPacket) {
$p->getInventory()->clearAll();
$p->teleport($this->getServer()->getLevelByName($this->getConfig()->get("LobbyWorld"))->getDefaultSpawn());
$p->sendTip(str_ireplace("{lobby}", $this->getConfig()->get("LobbyWorld"), str_ireplace("{player}", $p->getName(), $this->getConfig()->get("LobbyMessage"))));
// }
}
}
public function onInteract(PlayerInteractEvent $event) {
$this->test($event->getPlayer(), $event->getPlayer()->getInventory()->getItemInHand()->getId());
}
public function onBlockPlace(BlockPlaceEvent $event) {
$this->test($event->getPlayer(), $event->getBlock()->getId());
}
public function onBlockBreak(BlockBreakEvent $event) {
$this->test($event->getPlayer(), $event->getPlayer()->getInventory()->getItemInHand()->getId());
}
public function onEntityDamage(EntityDamageEvent $event) {
if($event->getEntity() instanceof Player) {
if($this->isSpectator($event->getEntity())) {
$event->setCancelled();
}
}
if($event instanceof \pocketmine\event\entity\EntityDamageByEntityEvent) {
if($event->getDamager() instanceof Player) {
if($this->isSpectator($event->getDamager())) {
$event->setCancelled();
$this->test($event->getDamager(), $event->getDamager()->getInventory()->getItemInHand()->getId());
}
}
}
}
public function onPlayerChat(PlayerChatEvent $event) {
if($this->getConfig()->get("PrivateSpecChat") == "true") {
foreach($event->getPlayer()->getLevel()->getPlayers() as $p) {
if($this->isSpectator($p)) {
$p->sendMessage
}
}
$event->setCancelled();
}
}
public function onPlayerGameModeChange(PlayerGameModeChangeEvent $event) {
if($event->getNewGamemode() == 3) { // Testing if spectator.
$player = $event->getPlayer();
$this->players[$player->getName()] = [];
$this->lastPlayer = $player;
} elseif($this->lastPlayer !== $player and isset($this->players[$event->getPlayer()->getName()])) {
unset($this->players[$event->getPlayer()->getName()]);
$event->getPlayer()->setAllowFlight(false);
}
}
public function isSpectator(Player $player) {
return isset($this->players[$player->getName()]);
}
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args){
switch($cmd->getName()){
case "default":
break;
}
return false;
}
}


class setGamemodeTask extends \pocketmine\scheduler\PluginTask {
public function __construct(Main $main) {
parent::__construct($main);
$this->main = $main;
}
public function onRun($tick) {
foreach($this->main->players as $playername => $tped) {
$player = $this->main->getServer()->getPlayer($playername);
// $this->main->getLogger()->info($player->getGamemode() . "/" . $player->isSpectator());
if($player->isSpectator()) {
$player->setGamemode(0);
$compass = Item::get(345, 0, 1);
$compass->setNamedTag(NBT::parseJSON('{display:{Name:"§r' . $this->main->getConfig()->get("TPCompassName") . '"}}'));
$player->getInventory()->addItem($compass);
$compass = Item::get(Item::BED, 0, 1);
$compass->setNamedTag(NBT::parseJSON('{display:{Name:"§r' . $this->main->getConfig()->get("BedBackName") . '"}}'));
$player->getInventory()->addItem($compass);
foreach($player->getLevel()->getPlayers() as $p) {
if(!$this->main->isSpectator($p)) {
$p->hidePlayer($player);
}
}
$player->setAllowFlight(true);
}
}
}
}

Loading…
Cancel
Save