-
Notifications
You must be signed in to change notification settings - Fork 11
SimulateEvents
HSP has long had the ability to test your strategies by setting core.verboseStrategyLogging = true in your config file. One downside is that as an admin, you either have to get your players to help you test strategies since the results can very based on permissions which are often different for different players, or you need to create a test account and change permissions on your test account to run through all the scenarios.
While nothing beats the real test since you can experience the actual results in-game, HSP 2.0 now offers a quick way to simulate events so that you can easily make changes to your events and verify they are working as you expect.
I think an example is the easiest way to show this feature in action. Let's say we want to test our onJoin strategy to see the difference between when we have a new player login vs. not. Here is what our onJoin strategy looks like:
onJoin:
- message:onJoin
- spawnNewPlayer
- default
And here's an example session of us testing it with HSP 2.0's new DummyPlayer/SimulateEvent feature:
>hsp dp create Foo
[21:49:28 INFO]: Dummy player object named "Foo" created. Location = world,65,71,202
>hsp se Foo onJoin
[21:50:03 INFO]: [HomeSpawnPlus] Strategy evaluation started, type=onjoin player={DummyPlayer:Foo}
[21:50:03 INFO]: [proxyMsg Foo] onJoin
[21:50:03 INFO]: [HomeSpawnPlus] (strategy Message) result is null
[21:50:03 INFO]: [HomeSpawnPlus] (strategy spawnNewPlayer) player is detemined to NOT be a new player
[21:50:03 INFO]: [HomeSpawnPlus] (strategy spawnNewPlayer) result is [loc={null}, home=null, spawn={null}]
[21:50:03 INFO]: [HomeSpawnPlus] (strategy default) result is [loc={null}, home=null, spawn={null}]
[21:50:03 INFO]: [HomeSpawnPlus] Evaluation chain complete, result = explicit default
[21:50:03 INFO]: StrategyResult returned explicit default. This means HSP will do nothing with this event.
>hsp dp show Foo
[21:50:50 INFO]: Details for dummy player "Foo":
[21:50:50 INFO]: Location=world,65,71,202
[21:50:50 INFO]: isNewPlayer=false
[21:50:50 INFO]: state isLocked?=false
>hsp dp setNewPlayer Foo true
[21:50:58 INFO]: newPlayer state for DummyPlayer "Foo" is now set to: true
>hsp se Foo onJoin
[21:51:06 INFO]: [HomeSpawnPlus] Strategy evaluation started, type=onjoin player={DummyPlayer:Foo}
[21:51:06 INFO]: [proxyMsg Foo] onJoin
[21:51:06 INFO]: [HomeSpawnPlus] (strategy Message) result is null
[21:51:06 INFO]: [HomeSpawnPlus] (strategy spawnNewPlayer) player is detemined to be a new player
[21:51:06 INFO]: [HomeSpawnPlus] (strategy spawnNewPlayer) result is [loc={world,77,64,190}, home=null, spawn={com.andune.minecraft.hsp.entity.SpawnImpl$$EntityBean$HomeSpawnPlus@7a98a7b6}]
[21:51:06 INFO]: [HomeSpawnPlus] Evaluation chain complete, result = [loc={world,77,64,190}, home=null, spawn={com.andune.minecraft.hsp.entity.SpawnImpl$$EntityBean$HomeSpawnPlus@7a98a7b6}]
[21:51:06 INFO]: StrategyResult returned a spawn object: SpawnId={5}, SpawnName={newPlayerSpawn}, SpawnLoc={world,77,64,190},
There are a few things of note here:
- I have core.verboseStrategyLogging enabled so you're seeing the VerboseLogging messages right on the console as the events are being simulated.
- I'm using the new HSP message strategy and you'll notice messages sent to the DummyPlayer actually go through to the person that created it (in this case, the Console). Eventually I will have the verboseStrategy message sent directly to DummyPlayer objects so that if you run this in-game, you can see those messages as a "proxyMsg" sent directly to you without having to check the console.
- Notice I manipulated the isNewPlayer boolean on the player so that I could test newPlayer functionality. Note that HSP automatically detects new players and calls the separate "onNewPlayer" event if you have it defined, so you'll want to simulate that event instead if you use it (just running onJoin as I did here doesn't do that).
While simulating events on Dummy objects has no effect on the actual game, if you name a Dummy the same as a real player on your server and your permission system supports offline permissions (most decent ones do such as PEX or GroupManager - plain Vanilla Bukkit does not), the actual permissions will be checked as if the Dummy was the real player. An example:
permission:
VIP:
permissions: [group.VIP]
onJoin:
- spawnNamedSpawn:VIP
Here we see I have a per-Permission strategy defined for 'group.VIP'. We can see below that my player 'Anduune' is verified to have this permission set and as a result the onJoin strategy follows this event chain for Anduune. Player Foo does not have the permission set and so follows the normal onJoin.
>hsp pc group.VIP Anduune
[22:25:03 INFO]: Player Anduune HAS permission group.VIP on world world (perm system in use = VAULT:PermissionsEx).
>hsp dp create Anduune
[22:25:09 INFO]: Dummy player object named "Anduune" created. Location = world,65,71,202
>hsp se Anduune onJoin
[22:25:14 INFO]: [HomeSpawnPlus] Strategy evaluation started, type=onjoin player={DummyPlayer:Anduune}
[22:25:14 INFO]: [HomeSpawnPlus] (strategy spawnNamedSpawn) result is [loc={world,76,64,223}, home=null, spawn={com.andune.minecraft.hsp.entity.SpawnImpl$$EntityBean$HomeSpawnPlus@22d108eb}]
[22:25:14 INFO]: [HomeSpawnPlus] Evaluation chain complete, result = [loc={world,76,64,223}, home=null, spawn={com.andune.minecraft.hsp.entity.SpawnImpl$$EntityBean$HomeSpawnPlus@22d108eb}]
[22:25:14 INFO]: [HomeSpawnPlus] result changed to safeLocation, new result = [loc={world,76,64,223}, home=null, spawn={com.andune.minecraft.hsp.entity.SpawnImpl$$EntityBean$HomeSpawnPlus@22d108eb}]
[22:25:14 INFO]: StrategyResult returned a spawn object: SpawnId={6}, SpawnName={VIP}, SpawnLoc={world,76,64,223},
>hsp pc group.VIP Foo
[22:25:25 INFO]: Player Foo DOES NOT HAVE permission group.VIP on world world (perm system in use = VAULT:PermissionsEx).
>hsp dp create Foo
[22:25:30 INFO]: Dummy player object named "Foo" created. Location = world,65,71,202
>hsp se Foo onJoin
[22:25:40 INFO]: [HomeSpawnPlus] Strategy evaluation started, type=onjoin player={DummyPlayer:Foo}
[22:25:40 INFO]: [HomeSpawnPlus] (strategy default) result is [loc={null}, home=null, spawn={null}]
[22:25:40 INFO]: [HomeSpawnPlus] Evaluation chain complete, result = explicit default
[22:25:40 INFO]: StrategyResult returned explicit default. This means HSP will do nothing with this event.
>