Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Error anticheat...

Comments in 'Plugin Development' started by MrReskill, Apr 3, 2016.

  1. MrReskill
    Offline

    MrReskill New Member

    Joined:
    Sep 21, 2015
    Posts:
    29
    Minecraft User:
    MrReskillYT
    Hello,
    I created a small script that is supposed to kick a player slap it over 6block (which is possible on f5 MCPE).
    He even kick off if players step 1 block ...

    CODE:
    Code:
    <?php
    namespace ReachTracker;
    use pocketmine\plugin\PluginBase;
    use pocketmine\event\Listener;
    use pocketmine\Player;
    use pocketmine\Server;
    use pocketmine\level\format\FullChunk;
    use pocketmine\nbt\tag\Compound;
    use pocketmine\network\Network;
    use pocketmine\network\protocol\AddEntityPacket;
    use pocketmine\item\Item;
    use pocketmine\math\Vector3;
    use pocketmine\level\Explosion;
    use pocketmine\level\Position;
    use pocketmine\level\Level;
    use pocketmine\block\Block;
    use pocketmine\event\player\PlayerJoinEvent;
    use pocketmine\utils\TextFormat;
    use pocketmine\inventory\PlayerInventory;
    use pocketmine\event\player\PlayerItemHeldEvent;
    use pocketmine\event\player\PlayerInteractEvent;
    use pocketmine\event\entity\EntityDamageEvent;
    use pocketmine\event\entity\EntityDamageByEntityEvent;
    use pocketmine\entity\Effect;
    class MainClass extends PluginBase implements Listener{               
        public function onEnable(){
            $this->getServer()->getPluginManager()->registerEvents($this, $this);       
        }
    
    
    
        public function onPvP(EntityDamageEvent $event) {
         if($event instanceof EntityDamageByEntityEvent){
        $pos1 = new Vector3($event->getDamager()->getX(),$event->getDamager()->getY,$event->getDamager()->getZ());
            $distance = $pos1->distance(new Vector3($event->getEntity()->getX(),$event->getEntity()->getY(),$event->getEntity()->getZ()));
      
            if ($distance > 6){
            $event->getDamager()->close("§c§l[ForCHEAT][F5]", "§3 Cheat detecté");
            Server::getInstance()->broadcastMessage("§c§l[ForCHEAT][F5]§3".$event->getDamager()." vien d'ètre kick pour§a: F5/CHEAT§3 bon jeu. (Spam gg autorisé!)");
            }
            }
        }
    }
    Thanks for helping...
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    As a side note, $pos1 can be directly $event->getDamager(). $event->getDamager() returns an Entity, and an Entity is already a Vector3 that represents its position, and you can call distance() upon.

    And avoid using Server::getInstance(). Simply use $this->getServer().

    And don't use close(). It is internal. Use kick() instead.
    applqpak likes this.
  3. MrReskill
    Offline

    MrReskill New Member

    Joined:
    Sep 21, 2015
    Posts:
    29
    Minecraft User:
    MrReskillYT
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    If you can't read English, how do you expect us to help you...
    AndrewBit and applqpak like this.
  5. MrReskill
    Offline

    MrReskill New Member

    Joined:
    Sep 21, 2015
    Posts:
    29
    Minecraft User:
    MrReskillYT
    @PEMapModder
    You can debug my code I can comply with the code
  6. Ritch
    Offline

    Ritch Active Member

    Joined:
    Oct 4, 2015
    Posts:
    184
    Minecraft User:
    anonymous
    Learn api ...
  7. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    what is difference between $this->getServer() and Server::getInstance() ? i think you said we shouldn't use Server::getInstance() if we can use non satic method but why? are static methods slower?
    applqpak likes this.
  8. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Why would you when you have $this->getServer to use?
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Bad practice. If you always use Server::getInstance(), one day you would accidentally use them in scopes that you must not use it. Using calls with reference ensure that you are passing the server instance correctly.
    Also, sometimes strange things happen, and static object fields would become null if you use them incorrectly.
    applqpak likes this.
  10. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    As I said tons of times, we're here to help you improve, not to code for you.
    If you want a plugin, Plugin Request is your section.
    PEMapModder likes this.

Share This Page

Advertisement