Skip to content

Commit

Permalink
Merge pull request #86 from falkirks/upgrades
Browse files Browse the repository at this point in the history
Several bugfixes
  • Loading branch information
inxomnyaa authored Dec 28, 2019
2 parents 80f7f05 + ae6ff5c commit 3c8f511
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 141 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Specter
version: 0.6
version: 0.7
author: Falkirks
main: specter\Specter
api: [3.11.0, 4.0.0]
Expand Down
203 changes: 103 additions & 100 deletions src/specter/Specter.php
Original file line number Diff line number Diff line change
@@ -1,73 +1,78 @@
<?php

namespace specter;

use icontrolu\iControlU;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\entity\Entity;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\Listener;
use pocketmine\event\player\cheat\PlayerIllegalMoveEvent;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\InteractPacket;
use pocketmine\network\mcpe\protocol\AnimatePacket;
use pocketmine\network\mcpe\protocol\MovePlayerPacket;
use pocketmine\network\mcpe\protocol\PlayerActionPacket;
use pocketmine\network\mcpe\protocol\RespawnPacket;
use pocketmine\network\mcpe\protocol\TextPacket;
use pocketmine\Player;
use pocketmine\plugin\PluginBase;
use pocketmine\utils\TextFormat;
use specter\network\SpecterInterface;
use specter\network\SpecterPlayer;

class Specter extends PluginBase implements Listener {
class Specter extends PluginBase implements Listener
{
/** @var SpecterInterface */
private $interface;
public function onEnable(){

public function onEnable()
{
$this->saveDefaultConfig();
$this->interface = new SpecterInterface($this);
$this->interface = new SpecterInterface($this);
$this->getServer()->getNetwork()->registerInterface($this->interface);
$this->getServer()->getPluginManager()->registerEvents($this, $this);
}
/**
* @param CommandSender $sender
* @param Command $command
* @param string $label
* @param string[] $args
*
* @return bool
*/
public function onCommand(CommandSender $sender, Command $command, string $label, array $args) : bool {
if(isset($args[0])){
switch($args[0]){

/**
* @param CommandSender $sender
* @param Command $command
* @param string $label
* @param string[] $args
*
* @return bool
*/
public function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool
{
if (isset($args[0])) {
switch ($args[0]) {
case 'spawn':
case 'new':
case 'add':
case 's':
if(isset($args[1])) {
if ($this->getInterface()->openSession($args[1], isset($args[2]) ? $args[2] : "SPECTER", isset($args[3]) ? $args[3] : 19133)){
if (isset($args[1])) {
if ($this->getInterface()->openSession($args[1], isset($args[2]) ? $args[2] : "SPECTER", isset($args[3]) ? $args[3] : 19133)) {
$sender->sendMessage("Session started.");
}
else{
} else {
$sender->sendMessage("Failed to open session");
}
return true;
}
else{
} else {
return false;
}
break;
case 'kick':
case 'quit':
case 'close':
case 'q':
if(isset($args[1])) {
if (isset($args[1])) {
$player = $this->getServer()->getPlayer($args[1]);
if($player instanceof SpecterPlayer){
if ($player instanceof SpecterPlayer) {
$player->close("", "client disconnect.");
}
else{
} else {
$sender->sendMessage("That player isn't managed by specter.");
}
}
else{
} else {
$sender->sendMessage("Usage: /specter quit <p>");
}
return true;
Expand All @@ -76,127 +81,122 @@ public function onCommand(CommandSender $sender, Command $command, string $label
case 'm':
case 'teleport':
case 'tp':
if(isset($args[4])) {
if (isset($args[4])) {
$player = $this->getServer()->getPlayer($args[1]);
if($player instanceof SpecterPlayer){
if ($player instanceof SpecterPlayer) {
$pk = new MovePlayerPacket();
$pk->position = new Vector3($args[2],$args[3] + $player->getEyeHeight(),$args[4]);
$pk->yaw = $player->getYaw()+10; //This forces movement even if the movement is not large enough
$pk->position = new Vector3($args[2], $args[3] + $player->getEyeHeight(), $args[4]);
$pk->yaw = $player->getYaw() + 10; //This forces movement even if the movement is not large enough
$pk->pitch = 0;
$this->interface->queueReply($pk, $player->getName());
}
else{
} else {
$sender->sendMessage("That player isn't managed by specter.");
}
}
else{
} else {
$sender->sendMessage("Usage: /specter move <p> <x> <y> <z>");
}
return true;
break;
case 'attack':
case 'a':
if(isset($args[2])){
if (isset($args[2])) {
$player = $this->getServer()->getPlayer($args[1]);
if($player instanceof SpecterPlayer){
if(substr($args[2], 0, 4) === "eid:"){
if ($player instanceof SpecterPlayer) {
if (substr($args[2], 0, 4) === "eid:") {
$victimId = substr($args[2], 4);
if(!is_numeric($victimId)){
if (!is_numeric($victimId)) {
$sender->sendMessage("Usage: /specter attack <attacker> <victim>|<eid:<victim eid>>");
return true;
}
if(!($player->getLevel()->getEntity($victimId) instanceof Entity)){
if (!($victim = $player->getLevel()->getEntity($victimId) instanceof Entity)) {
$sender->sendMessage("There is no entity with entity ID $victimId in {$player->getName()}'s level");
return true;
}
}else{
} else {
$victim = $this->getServer()->getPlayer($args[2]);
if($victim instanceof Player){
if ($victim instanceof Player) {
$victimId = $victim->getId();
}
else{
} else {
$sender->sendMessage("Player $args[2] not found");
return true;
}
}
$pk = new InteractPacket();
$pk->action = InteractPacket::ACTION_RIGHT_CLICK; // unused
$pk->target = $victimId;
$damage = floatval($args[3] ?? 0.0);
$ev = new EntityDamageByEntityEvent($player, $victim, EntityDamageByEntityEvent::CAUSE_ENTITY_ATTACK, $damage, [], 0.0);
$victim->attack($ev);
$pk = new AnimatePacket();
$pk->entityRuntimeId = $player->getId();
$pk->action = AnimatePacket::ACTION_SWING_ARM;
$this->getInterface()->queueReply($pk, $player->getName());
}
else{
$this->getLogger()->info(TextFormat::LIGHT_PURPLE . "{$player->getName()} attacking {$victim->getName()}(eid:{$victimId}) with {$damage} damage");
} else {
$sender->sendMessage("That player isn't managed by specter.");
}
}
else{
$sender->sendMessage("Usage: /specter attack <attacker> [eid:]<victim>");
} else {
$sender->sendMessage("Usage: /specter attack <attacker> [eid:]<victim> [damage]");
}
return true;
break;
case 'c':
case 'chat':
case 'command':
if(isset($args[2])) {
if (isset($args[2])) {
$player = $this->getServer()->getPlayer($args[1]);
if($player instanceof SpecterPlayer){
if ($player instanceof SpecterPlayer) {
$pk = new TextPacket();
$pk->type = TextPacket::TYPE_CHAT;
$pk->type = TextPacket::TYPE_CHAT;
$pk->sourceName = "";
$pk->message = implode(" ", array_slice($args, 2));
$this->getInterface()->queueReply($pk, $player->getName());
}
else{
} else {
$sender->sendMessage("That player isn't managed by specter.");
}
}
else{
} else {
$sender->sendMessage("Usage: /specter chat <p> <data>");
}
return true;
break;
case 'control': //TODO update iControlU with better support
case 'icu':
if($sender instanceof Player) {
if ($sender instanceof Player) {
$icu = $this->getICU();
if($icu instanceof iControlU) {
if ($icu instanceof iControlU) {
$player = $this->getServer()->getPlayer($args[1]);
if ($player instanceof SpecterPlayer) {
if($icu->isControl($sender)) {
if ($icu->isControl($sender)) {
$this->getServer()->dispatchCommand($sender, "icu control " . $args[1]);
}
else{
} else {
$this->getServer()->dispatchCommand($sender, "icu stop ");
}
}
else{
} else {
$sender->sendMessage("That player isn't a specter player");
}
}
else{
} else {
$sender->sendMessage("You need to have iControlU to use this feature.");
}
}
else{
} else {
$sender->sendMessage("This command must be run in game.");
}
return true;
break;
case "respawn":
case "r":
if(!isset($args[1])){
if (!isset($args[1])) {
$sender->sendMessage("Usage: /specter respawn <player>");
return true;
}
$player = $this->getServer()->getPlayer($args[1]);
if($player instanceof SpecterPlayer){
if(!$player->spec_needRespawn){
if ($player instanceof SpecterPlayer) {
if (!$player->spec_needRespawn) {
$this->interface->queueReply(new RespawnPacket(), $player->getName());
}
else{
$respawnPK = new PlayerActionPacket();
$respawnPK->action = PlayerActionPacket::ACTION_RESPAWN;
$respawnPK->entityRuntimeId = $player->getId();
$this->interface->queueReply($respawnPK, $player->getName());
} else {
$sender->sendMessage("{$player->getName()} doesn't need respawning.");
}
}
else{
} else {
$sender->sendMessage("That player isn't a specter player");
}
return true;
Expand All @@ -210,44 +210,47 @@ public function onCommand(CommandSender $sender, Command $command, string $label
* @priority HIGHEST
* @param PlayerIllegalMoveEvent $event
*/
public function onIllegalMove(PlayerIllegalMoveEvent $event){
if($event->getPlayer() instanceof SpecterPlayer && $this->getConfig()->get('allowIllegalMoves')){
public function onIllegalMove(PlayerIllegalMoveEvent $event)
{
if ($event->getPlayer() instanceof SpecterPlayer && $this->getConfig()->get('allowIllegalMoves')) {
$event->setCancelled();
}
}
/*
/**
* @priority MONITOR
* @param DataPacketReceiveEvent $pk
*
public function onDataPacketRecieve(DataPacketReceiveEvent $pk){
if($pk->getPacket() instanceof RequestChunkRadiusPacket){
$this->getLogger()->info("RADIUS:" . $pk->getPacket()->radius);
/*
/**
* @priority MONITOR
* @param DataPacketReceiveEvent $pk
*
public function onDataPacketRecieve(DataPacketReceiveEvent $pk){
if($pk->getPacket() instanceof RequestChunkRadiusPacket){
$this->getLogger()->info("RADIUS:" . $pk->getPacket()->radius);
}
$this->getLogger()->info("GOT:" . get_class($pk->getPacket()));
}
$this->getLogger()->info("GOT:" . get_class($pk->getPacket()));
}
/**
* @priority MONITOR
* @param DataPacketSendEvent $pk
*
public function onDataPacketSend(DataPacketSendEvent $pk){
if(!($pk->getPacket() instanceof SetTimePacket)) {
$this->getLogger()->info("SEND:" . get_class($pk->getPacket()));
/**
* @priority MONITOR
* @param DataPacketSendEvent $pk
*
public function onDataPacketSend(DataPacketSendEvent $pk){
if(!($pk->getPacket() instanceof SetTimePacket)) {
$this->getLogger()->info("SEND:" . get_class($pk->getPacket()));
}
}
}
*/
*/
/**
* @return SpecterInterface
*/
public function getInterface(){
public function getInterface()
{
return $this->interface;
}

/**
* @return null|\icontrolu\iControlU
*/
public function getICU(){
public function getICU()
{
return $this->getServer()->getPluginManager()->getPlugin("iControlU");
}
}
2 changes: 1 addition & 1 deletion src/specter/api/DummyPlayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function close(){
*/
protected function getSpecter(){
$plugin = $this->server->getPluginManager()->getPlugin("Specter");
if($plugin !== null && $plugin->isEnabled()){
if ($plugin instanceof Specter && $plugin->isEnabled()) {
return $plugin;
}
else{
Expand Down
Loading

1 comment on commit 3c8f511

@JaxkDev
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dear @falkirks,

I regret to inform you that your plugin "Specter" (v0.7 submitted on 2019-12-28T04:37:29.000Z) has been rejected.

Tidy up of change log as well please.

B1a — No unknown API versions:

Plugins must not support unreleased API versions, i.e. anything not found in https://github.com/pmmp/PocketMine-MP/releases

Please resolve these issues and submit the plugin again.

This comment is posted here because this is the last commit when the released build was created.

Please sign in to comment.