Z0rdak / Yet-Another-World-Protector

Yet Another World Protector is a server-side protection mod which allows you to protect your creations against various different events/actions of players, mobs and the environment. It was inspired by the forge mod WorldProtector and the WorldGuard plugin.
https://www.curseforge.com/minecraft/mc-mods/yawp
GNU Affero General Public License v3.0
22 stars 9 forks source link

Trigger system for entities leaving/entering a region #11

Open Z0rdak opened 2 years ago

Z0rdak commented 2 years ago

Description

To handle players entering and leaving regions, a trigger-like system (optimal with events) would be handy.

Beside other things, this system would allow it to display the region name or other messages to the player when entering/leaving a region. It also could be extended to execute commands or do other things.

Player tracking around regions

To implement triggers for entering and leaving a region, the position of players relative to regions needs to be tracked.

This system needs to be configurable to be adaptable to different server enviroments to limit the impact on CPU cycles spend on tracking the players.

There will be 3 player tracking caches. They will track players with their distance to nearby regions.

Cache 1 - Players within 100 Block radius around any region, refreshed every 100 ticks Cache 2 - Players within 50 Block radius around any region, refreshed every 40 ticks Cache 3 - Players within 25 Block radius around any region, refreshed every 20 ticks

Map<Player, <List<TrackedRegion>> trackingCache

The Block and tick numbers are just an example and will be configurable. The travel speed of players (Blocks/tick) needs to be considered here.

Additional thoughs

Map<ResourceKey<Level>, TrackingCache> trackingCachesPerDim Where TrackingCache would be an abstraction over the three different caches for a dimension.

API

Triggers will create an event which is fired for other mods to hook into.

These events will also be used by YAWP itself to implement the trigger action handling.

Events:

void PlayerLeave(Player player, IProtectedRegion region);
void PlayerEnter(Player player, IProtectedRegion region);
void EntityLeave(Entity entity, IProtectedRegion region);
void EntityEnter(Entity entity, IProtectedRegion region);

RegionAPI:

Trigger types

There are two types of Trigger: PlayerTrigger and EntityTrigger

With three different TriggerConditions: Enter, Leave, Both

PlayerTrigger

Only triggers when a player enter or leaves a region. Can be modified by a filter.

The filter allows for filtering for players within a certain group.

EntityTrigger

Triggers when a entity enter or leaves a region. Can be modified by a filter.

The filter allows filtering for a specific EntityType, Name or Tag of the Entity.

Actions

An action is a defined command which will be executed when a trigger is activated. Examples for (predefined) triggers are:

Command-Syntax

The syntax could be the following (here for local regions):

For easier management a pagination for trigger and actions should be considered.

Triggers are only applicable for Local Regions and Dimensional Regions

Z0rdak commented 1 month ago

Suggestion from Discord: Trigger for playing music when entering region

Z0rdak commented 2 weeks ago

Updated Feature description