Code Monkey home page Code Monkey logo

fakeplayer's Introduction

FakePlayer

What does this plugin do?

Similar to Specter, this plugin spawns players to debug stuff on your server. However, this plugin strictly supports API version 4.0.0.

Usage

Who the heck is BoxierChimera37?
My alt xbox live account.

When you first run this plugin, BoxierChimera37 will join the server. You can edit the players.json file to add as many players as you wish. Does this fake your server player count? Yes, but that's not the point of this plugin.
players.json structure:

{
	"uuid-v4-string": {
		"xuid": "required",
		"gamertag": "required",
		"extra_data": {} // this field is OPTIONAL
		"behaviours": [] // this field is OPTIONAL
	}
}

Once a fake player joins, you can chat or run commands on their behalf using:
/fp <player> chat hello wurld!
/fp <player> chat /help 4

API Documentation

Adding a fake player

Loader::addPlayer(FakePlayerInfo $info) : Promise;

Fake players can be spawned in during runtime using Loader::addPlayer(). FakePlayerInfo consists of player identity and miscellaneous data and can be built easily using FakePlayerInfoBuilder.

/** @var Loader $plugin */
$plugin = Server::getInstance()->getPluginManager()->getPlugin("FakePlayer");
$plugin->addPlayer(FakePlayerInfoBuilder::create()
	->setUsername("BlahCoast30765")
	->setXuid("2535431208141398")
	->setUuid("815e76d4-6248-3c27-9dc5-e49230a5dec4")
	->setSkin(/* some skin */) // optional ;), defaults to a white skin
	// ...
->build());

// To obtain a Player instance after adding a player
$plugin->addPlayer(...)->onCompletion(
	function(Player $player) : void{
		echo "Added player ", $player->getName(), " successfully";
	},
	function() : void{
		// adding player failed
	}
);

Test for fake player

/**
 * @param Player $player
 */
Loader::isFakePlayer(Player $player) : bool;

Removing a fake player

/**
 * NOTE: $player MUST be a fake player, or else an InvalidArgumentException will
 * be thrown.
 * @param Player $player
 */
Loader::removePlayer(Player $player) : void;

Listeners

Registering/Unregistering a fake player listener

Loader::registerListener(FakePlayerListener $listener) : void;
Loader::unregisterListener(FakePlayerListener $listener) : void;

Example:

Loader::registerListener(new ClosureFakePlayerListener(
	function(Player $player) : void{
		Server::getInstance()->broadcastMessage("Fake player joined: " . $player->getName());
	},
	function(Player $player) : void{
		Server::getInstance()->broadcastMessage("Fake player is kil: " . $player->getName());
	}
));

Listening to packets sent

Each fake player holds a FakePlayerNetworkSession that you can register packet listeners to.

/** @var Player $fake_player */
/** @var FakePlayerNetworkSession $session */
$session = $fake_player->getNetworkSession();

There are two kinds of packet listeners you can register:

  1. A catch-all packet listener that is notified for every packet sent.
  2. A specific packet listener
Registering a catch-all packet listener
$session->registerPacketListener(new ClosureFakePlayerPacketListener(
	function(ClientboundPacket $packet, NetworkSession $session) : void{
		// do something
	}
));
Registering a specific packet listener
$session->registerSpecificPacketListener(TextPacket::class, new ClosureFakePlayerPacketListener(
	function(ClientboundPacket $packet, NetworkSession $session) : void{
		/** @var TextPacket $packet */
		Server::getInstance()->broadcastMessage($session->getPlayer()->getName() . " was sent text: " . $packet->message);
	}
));

Fake Player Behaviours

Behaviours are basically a way you can do anything you like on a fake player every tick. By default, there's a fakeplayer:pvp behaviour which makes the fake player fight all living entities except non-survival mode players. You can add multiple behaviours to a fake player. Make sure to register your custom behaviours during PluginBase::onEnable().
To register a fake player behaviour:

FakePlayerBehaviourManager::register("myplugin:cool_ai", MyCoolAIThatImplementsFakePlayerBehaviour::class);

To add a behaviour to a player, pass it during Loader::addPlayer() OR specify it in the players.json file.

Frequently Asked Questions

Q. Does this work with encryption enabled?
A. Yes

fakeplayer's People

Contributors

celishere avatar edwinyoo44 avatar iteplenky avatar javierleon9966 avatar kingofturkey38 avatar muqsit avatar nicholass003 avatar poggit-bot avatar superomarking avatar swift-strider avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

fakeplayer's Issues

pm4

Hello, it is possible to update/downgrade the plugin into pm4 version

Crash at Start server.

The plugin crashes the server immediately it starts.

PHP: 8
PM API: 4.0.0
FakePlayer: The last one in poggit

It should be mentioned that this error continues to appear even if there is only the FakePlayer plugin
image

Sorry for my bad English :c

3.0.0

Make it 3.0.0 so its usable...

Bug

[06:49:52.224] [Server thread/CRITICAL]: ArgumentCountError: "Too few arguments to function pocketmine\network\mcpe\StandardPacketBroadcaster::__construct(), 1 passed in phar:///.../plugins/FakePlayer_dev-60.phar/src/muqsit/fakeplayer/Loader.php on line 145 and exactly 2 expected" (EXCEPTION) in "pmsrc/src/network/mcpe/StandardPacketBroadcaster" at line 31
--- Stack trace ---
#0 plugins/FakePlayer_dev-60.phar/src/muqsit/fakeplayer/Loader(145): pocketmine\network\mcpe\StandardPacketBroadcaster->__construct(object pocketmine\Server#11)
#1 plugins/FakePlayer_dev-60.phar/src/muqsit/fakeplayer/Loader(231): muqsit\fakeplayer\Loader->addPlayer(object muqsit\fakeplayer\info\FakePlayerInfo#37583)

Crash

Hi, I have this error :
[Server thread/CRITICAL]: Error: "Class "pocketmine\network\mcpe\protocol\serializer\PacketSerializerContext" not found" (EXCEPTION) in "plugins/FakePlayer_dev-65.phar/src/muqsit/fakeplayer/Loader" at line 141
How can it be repaired?

Plugin suggestion

Can you add a Command that open a Ui and in the UI you can remove Fakeplayers and add Fakeplayers

Suggestion for Plugin

Can you add a Command that open a Ui and in the UI you can remove Fakeplayers and add Fakeplayers

Error on start the server "setViewDistance on null"

[10:16:22.429] [Server thread/CRITICAL]: Error: "Call to a member function setViewDistance() on null" (EXCEPTION) in "plugins/FakePlayer_dev-48.phar/src/muqsit/fakeplayer/Loader" at line 113 --- Stack trace --- #0 plugins/FakePlayer_dev-48.phar/src/muqsit/fakeplayer/Loader(168): muqsit\fakeplayer\Loader->addPlayer(object muqsit\fakeplayer\info\FakePlayerInfo#29626) #1 plugins/FakePlayer_dev-48.phar/src/muqsit/fakeplayer/Loader(66): muqsit\fakeplayer\Loader->addConfiguredPlayers() #2 pmsrc/src/scheduler/ClosureTask(63): muqsit\fakeplayer\Loader->muqsit\fakeplayer\{closure}() #3 pmsrc/src/scheduler/TaskHandler(117): pocketmine\scheduler\ClosureTask->onRun() #4 pmsrc/src/scheduler/TaskScheduler(141): pocketmine\scheduler\TaskHandler->run() #5 pmsrc/src/plugin/PluginManager(466): pocketmine\scheduler\TaskScheduler->mainThreadHeartbeat(integer 20) #6 pmsrc/src/Server(1768): pocketmine\plugin\PluginManager->tickSchedulers(integer 20) #7 pmsrc/src/Server(1657): pocketmine\Server->tick() #8 pmsrc/src/Server(1046): pocketmine\Server->tickProcessor() #9 pmsrc/src/PocketMine(304): pocketmine\Server->__construct(object BaseClassLoader#2, object pocketmine\utils\MainLogger#3, string[39] C:\Users\sarac\Documents\GitHub\server\, string[47] C:\Users\sarac\Documents\GitHub\server\plugins\) #10 pmsrc/src/PocketMine(327): pocketmine\server() #11 pmsrc(11): require(string[83] phar://C:/Users/sarac/Documents/GitHub/server/PocketMine-MP.phar/src/PocketMine.) --- End of exception information --- [10:16:22.432] [Server thread/EMERGENCY]: An unrecoverable error has occurred and the server has crashed. Creating a crash dump [10:16:22.460] [Server thread/EMERGENCY]: Please upload the "C:/Users/sarac/Documents/GitHub/server/crashdumps/Fri_Mar_18-10.16.22-ADT_2022.log" file to the Crash Archive and submit the link to the Bug Reporting page. Give as much info as you can. [Fri_Mar_18-10.16.22-ADT_2022.log](https://github.com/Muqsit/FakePlayer/files/8304744/Fri_Mar_18-10.16.22-ADT_2022.log)

Call to a member function setViewDistance() on null

Error: Call to a member function setViewDistance() on null
File: plugins/FakePlayer.phar/src/muqsit/fakeplayer/Loader
Line: 151
Type: Error

Code:
[142] $rp->setAccessible(true);
[143] $rp->invoke($session);
[144]
[145] $packet = new ResourcePackClientResponsePacket();
[146] $packet->status = ResourcePackClientResponsePacket::STATUS_COMPLETED;
[147] $serializer = PacketSerializer::encoder(new PacketSerializerContext(GlobalItemTypeDictionary::getInstance()->getDictionary()));
[148] $packet->encode($serializer);
[149] $session->handleDataPacket($packet, $serializer->getBuffer());
[150]
[151] $session->getPlayer()->setViewDistance(4);
[152]
[153] $player = $session->getPlayer();
[154] assert($player !== null);
[155] $this->fake_players[$player->getUniqueId()->getBytes()] = $fake_player = new FakePlayer($session);
[156]
[157] $movement_data = FakePlayerMovementData::new();
[158] $fake_player->addBehaviour(new TryChangeMovementInternalFakePlayerBehaviour($movement_data), Limits::INT32_MIN);
[159] $fake_player->addBehaviour(new UpdateMovementInternalFakePlayerBehaviour($movement_data), Limits::INT32_MAX);
[160] foreach($info->behaviours as $behaviour_identifier => $behaviour_data){
[161] $fake_player->addBehaviour(FakePlayerBehaviourFactory::create($behaviour_identifier, $behaviour_data));

FakePlayer flying at me

is there a way to not make the fakeplayer fly towards you after it gets hit back or sees you

Tutorial

Hello how to use it? Do i have to put the file in the FiveM resources file and start it then it would work? Or is there other steps to do?

how can i use

how can start the script in server.cfg or use on my own server

More convenient ways to handle events

I'd like to use this in my integration tests. I need to programmatically handle the case where the player receives a message, so that I can check it against expected message. Currently the API only supports packets, which is an unstable API.

There are PocketMine events I can use to handle other stuff like playerinteractevent (and using AwaitStd for the API), but there is no event for receiving messages.

Error

TypeError: "Argument 2 passed to pocketmine\network\mcpe\handler\PreSpawnPacketHandler::__construct() must be an instance of pocketmine\player\Player, null given,
called in phar:///root/PocketMine-MP/server/PocketMine-MP
.phar/src/network/mcpe/NetworkSession.php on line 699" (EXCEPTION) in "pmsrc/src/networ
k/mcpe/handler/PreSpawnPacketHandler" at line 54

Duplicate Chat

Running /fakeplayer (name) chat (message) will display the message in chat twice

Example: /fakeplayer box chat hi

image

Changes

Argument 2 must be an instance of pocketmine\player\Player, null given.

image

Bug player chat

When the player sends the message it is sent twice when using the command

fp b chat hi                                                                           
[03:03:02.498] [Server thread/INFO]: <BlahCoast30765> hi                               
[03:03:02.498] [Server thread/INFO]: <BlahCoast30765> hi

Question

Does they fake players count as a player slot?

Only one FakePlayer spawned?

If I understand correctly, FakePlayer only spawns one fake player by default. Shouldn't this be customizable like Specter?

TypeError: "PreSpawnPacketHandler::__construct(): Argument #2 ($player) must be of type Player, null given

https://crash.pmmp.io/view/6092328

[06:55:17.439] [Server thread/INFO]: [NetworkSession: 0.0.0.0 19132] Session opened
[06:55:17.440] [Server thread/DEBUG]: [NetworkSession: 0.0.0.0 19132] Initiating resource packs phase
[06:55:17.440] [Server thread/DEBUG]: [NetworkSession: 0.0.0.0 19132] Waiting for client to accept resource packs
[06:55:17.442] [Server thread/DEBUG]: [NetworkSession: 0.0.0.0 19132] Resource packs sequence completed
[06:55:17.443] [Server thread/CRITICAL]: TypeError: "pocketmine\network\mcpe\handler\PreSpawnPacketHandler::__construct(): Argument #2 ($player) must be of type pocketmine\player\Player, null given, called in phar:///pocketmine/PocketMine-MP.phar/src/network/mcpe/NetworkSession.php on line 694" (EXCEPTION) in "pmsrc/src/network/mcpe/handler/PreSpawnPacketHandler" at line 61
--- Stack trace ---
  #0 pmsrc/src/network/mcpe/NetworkSession(694): pocketmine\network\mcpe\handler\PreSpawnPacketHandler->__construct(object pocketmine\Server#10, NULL , object muqsit\fakeplayer\network\FakePlayerNetworkSession#24411, NULL )
  #1 (): pocketmine\network\mcpe\NetworkSession->beginSpawnSequence()
  #2 plugins/FakePlayer.phar/src/muqsit/fakeplayer/Loader(128): ReflectionMethod->invoke(object muqsit\fakeplayer\network\FakePlayerNetworkSession#24411)
  #3 plugins/FakePlayer.phar/src/muqsit/fakeplayer/Loader(64): muqsit\fakeplayer\Loader->addPlayer(object Ramsey\Uuid\Lazy\LazyUuidFromString#24410, string[16] 2535448890738751, string[5] Alice, object pocketmine\entity\Skin#24412, array[3], array[1])
  #4 pmsrc/src/scheduler/ClosureTask(63): muqsit\fakeplayer\Loader->muqsit\fakeplayer\{closure}()
  #5 pmsrc/src/scheduler/TaskHandler(117): pocketmine\scheduler\ClosureTask->onRun()
  #6 pmsrc/src/scheduler/TaskScheduler(141): pocketmine\scheduler\TaskHandler->run()
  #7 pmsrc/src/plugin/PluginManager(467): pocketmine\scheduler\TaskScheduler->mainThreadHeartbeat(integer 20)
  #8 pmsrc/src/Server(1765): pocketmine\plugin\PluginManager->tickSchedulers(integer 20)
  #9 pmsrc/src/Server(1654): pocketmine\Server->tick()
  #10 pmsrc/src/Server(1044): pocketmine\Server->tickProcessor()
  #11 pmsrc/src/PocketMine(303): pocketmine\Server->__construct(object BaseClassLoader#3, object pocketmine\utils\MainLogger#2, string[6] /data/, string[9] /plugins/)
  #12 pmsrc/src/PocketMine(326): pocketmine\server()
  #13 pmsrc(11): require(string[56] phar:///pocketmine/PocketMine-MP.phar/src/PocketMine.php)
--- End of exception information ---
[06:55:17.444] [Server thread/EMERGENCY]: An unrecoverable error has occurred and the server has crashed. Creating a crash dump
[06:55:17.446] [Server thread/EMERGENCY]: Please upload the "/data/crashdumps/Sun_Mar_6-06.55.17-UTC_2022.log" file to the Crash Archive and submit the link to the Bug Reporting page. Give as much info as you can.
[06:55:18.383] [Server thread/EMERGENCY]: The crash dump has been automatically submitted to the Crash Archive. You can view it on https://crash.pmmp.io/view/6092328 or use the ID #6092328.
[06:55:18.383] [Server thread/EMERGENCY]: Forcing server shutdown

Crash on starting the server

Error: Too few arguments to function pocketmine\network\mcpe\StandardPacketBroadcaster::__construct(), 1 passed in phar:///home/container/plugins/FakePlayer_dev-59.phar/src/muqsit/fakeplayer/Loader.php on line 148 and exactly 2 expected
File: pmsrc/src/network/mcpe/StandardPacketBroadcaster
Line: 31
Type: ArgumentCountError

Crash

BAD PLUGIN: FakePlayer

Thread: Main
Error: Class "pocketmine\network\mcpe\protocol\serializer\PacketSerializerContext" not found
File: plugins/FakePlayer_dev-65.phar/src/muqsit/fakeplayer/Loader
Line: 141

Crash

[13:17:33.398] [Server thread/CRITICAL]: ArgumentCountError: "Too few arguments to function pocketmine\network\mcpe\StandardPacketBroadcaster::__construct(), 1 passed in /home/container/plugins/FakePlayer-master/src/muqsit/fakeplayer/Loader.php on line 146 and exactly 2 expected" (EXCEPTION) in "pmsrc/src/network/mcpe/StandardPacketBroadcaster" at line 38

Preparing for initial release

Before releasing this plugin on poggit, I'd like to address a few things:

  • The plugin excessively uses reflection, sometimes in places where reflection may not even be necessary (see Loader::addPlayer() for example).
  • #15 - To a non-developer (or a non-programmer rather), this plugin is delivered mostly static as it lacking commands. Players cannot be spawned without modifying the configuration pre-startup.
  • Document default behaviours (see default registered behaviours: FakePlayerBehaviourFactory::registerDefaults()).

Crash

This plugin doesn't work on 5.14.2, please fix it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.