Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'player creates shopkeeper' event, fixes #297
- Loading branch information
1 parent
5540c06
commit ba36c37
Showing
4 changed files
with
78 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...a/com/denizenscript/depenizen/bukkit/events/shopkeepers/ShopKeeperCreatedScriptEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.denizenscript.depenizen.bukkit.events.shopkeepers; | ||
|
||
import com.denizenscript.denizen.events.BukkitScriptEvent; | ||
import com.denizenscript.denizen.objects.LocationTag; | ||
import com.denizenscript.denizen.objects.PlayerTag; | ||
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.denizencore.scripts.ScriptEntryData; | ||
import com.nisovin.shopkeepers.api.events.PlayerCreateShopkeeperEvent; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
|
||
public class ShopKeeperCreatedScriptEvent extends BukkitScriptEvent implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// player creates shopkeeper | ||
// | ||
// @Regex ^on player creates shopkeeper$ | ||
// | ||
// @Cancellable true | ||
// | ||
// @Triggers when a player creates a shopkeeper. | ||
// | ||
// @Context | ||
// <context.location> Returns the location of the shopkeeper being created. | ||
// | ||
// @Plugin Depenizen, ShopKeepers | ||
// | ||
// --> | ||
|
||
public ShopKeeperCreatedScriptEvent() { | ||
instance = this; | ||
} | ||
|
||
public static ShopKeeperCreatedScriptEvent instance; | ||
public PlayerCreateShopkeeperEvent event; | ||
public PlayerTag player; | ||
|
||
@Override | ||
public boolean couldMatch(ScriptPath path) { | ||
return path.eventLower.startsWith("player creates shopkeeper"); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "ShopKeeperCreated"; | ||
} | ||
|
||
@Override | ||
public ScriptEntryData getScriptEntryData() { | ||
return new BukkitScriptEntryData(player, null); | ||
} | ||
|
||
@Override | ||
public ObjectTag getContext(String name) { | ||
if (name.startsWith("location")) { | ||
return new LocationTag(event.getShopCreationData().getSpawnLocation()); | ||
} | ||
return super.getContext(name); | ||
} | ||
|
||
@EventHandler | ||
public void onShopKeeperCreated(PlayerCreateShopkeeperEvent event) { | ||
player = new PlayerTag(event.getShopCreationData().getCreator()); | ||
this.event = event; | ||
fire(event); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters