Coder Social home page Coder Social 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

/**
 * @param UUID $uuid
 * @param string $xuid
 * @param string $username
 * @param mixed[] $extra_data
 */
Loader::addPlayer(UUID $uuid, string $xuid, string $username, array $extra_data) : Player;

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. ye

fakeplayer's People

Contributors

muqsit avatar goosebumps98 avatar poggit-bot avatar

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.