Giter Club home page Giter Club logo

worldbuilder's Introduction

WorldBuilder

A world editor plugin designed for production use.

WorldBuilder is specifically designed to handle multiple world edit operations efficiently. Unlike most of the async world editor plugins, WorldBuilder while being 100% asynchronous, does not execute world edit tasks on a new thread. It instead executes them on the main thread but splits the task into several smaller tasks which are executed over several game ticks. There is a configurable limit on how many block iterations can occur over a tick which acts as a performance regulator.

NOTE: WorldBuilder is an efficiency-first, annoyance-last world editor plugin so do not expect light-speed world edits. There is a default limit of 65536 block iterations per tick (or about 1,310,720 per second) so if you're editing 78,643,200 million blocks volume region on an "INFINITE frequency" CPU, the task will always take about a minute to complete.

WorldBuilder is great for creative mode servers and provides an API for limiting and monitoring world edits.

Developer Docs

Handling and filtering editor tasks

If you are running a creative-mode server, you may want to disallow players from editing other player's region, or perhaps blacklisting TNTs and falling blocks from being world-edited in.

public function onPlayerTriggerEditorTask(PlayerTriggerEditorTaskEvent $event) : void{
	$player = $event->getPlayer();
	$task = $event->getTask();

	$world = $event->getWorld();
	// TODO: Check if $world is not spawn_world

	$selection = $event->getSelection();
	// TODO: Check if all $selection->getPoints() lie in $player's plot.

	if($task instanceof SetEditorTask){
		$block = $task->getBlock();
		if($block->getId() === BlockLegacyIds::TNT){
			$event->setCancelled();
			$player->sendMessage("//set-ting " . $block->getName() . " is not allowed!");
		}
	}else{
		// disallow players from using anything else besides //set because i am a dick.
		$event->setCancelled();
		$player->sendMessage($task->getName() . " is disallowed on the server.");
	}
}

Monitoring editor tasks

Boy do I need some sick world editor progress bars on my server! Let's start by creating an editor task listener...

class MahEditorTaskListener implements EditorTaskListener{

	public function onRegister(EditorTask $task) : void{
		// Called after PlayerTriggerEditorTaskEvent has been triggered and the
		// event hasn't been cancelled.
	}
	
	public function onCompleteFraction(EditorTask $task, int $completed, int $total) : void{
		// Progress bar material here!
		// $player->sendPopup($task->getName() . " completed: " . sprintf("%0.2f", ($completed / $total) * 100) . "%");
	}
	
	public function onCompletion(EditorTask $task) : void{
		// $player->sendPopup($task->getName() . " completed!");
	}
}

...and then register it to an editor task!

/**
 * @param PlayerTriggerEditorTaskEvent $event
 * @priority MONITOR
 */
public function onPlayerTriggerEditorTask(PlayerTriggerEditorTaskEvent $event) : void{
	$task = $event->getTask();
	$handler = $task->registerListener(new MahEditorTaskListener());
	// Don't forget to call $handler->unregister() once the player quits the server, if
	// your listener is indirectly sending packets to the player.
	// It is not necessary to unregister a handler from a completed task, you can safely
	// register and forget.
}

worldbuilder's People

Contributors

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