diff --git a/plugin/src/main/java/com/denizenscript/denizen/events/ScriptEventRegistry.java b/plugin/src/main/java/com/denizenscript/denizen/events/ScriptEventRegistry.java index e365ab2df0..92ad2d842d 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/events/ScriptEventRegistry.java +++ b/plugin/src/main/java/com/denizenscript/denizen/events/ScriptEventRegistry.java @@ -230,6 +230,7 @@ public static void registerMainEvents() { ScriptEvent.registerScriptEvent(PlayerTakesFromFurnaceScriptEvent.class); ScriptEvent.registerScriptEvent(PlayerTakesFromLecternScriptEvent.class); ScriptEvent.registerScriptEvent(PlayerThrowsEggScriptEvent.class); + ScriptEvent.registerScriptEvent(PlayerTriggersRaidScriptEvent.class); ScriptEvent.registerScriptEvent(PlayerUsesPortalScriptEvent.class); ScriptEvent.registerScriptEvent(PlayerWalkScriptEvent.class); ScriptEvent.registerScriptEvent(PlayerWalksOverScriptEvent.class); @@ -270,6 +271,9 @@ public static void registerMainEvents() { ScriptEvent.registerScriptEvent(LootGenerateScriptEvent.class); ScriptEvent.registerScriptEvent(PortalCreateScriptEvent.class); ScriptEvent.registerScriptEvent(PotionSplashScriptEvent.class); + ScriptEvent.registerScriptEvent(RaidFinishesScriptEvent.class); + ScriptEvent.registerScriptEvent(RaidSpawnsWaveScriptEvent.class); + ScriptEvent.registerScriptEvent(RaidStopsScriptEvent.class); ScriptEvent.registerScriptEvent(SpawnChangeScriptEvent.class); ScriptEvent.registerScriptEvent(StructureGrowsScriptEvent.class); ScriptEvent.registerScriptEvent(ThunderChangesScriptEvent.class); diff --git a/plugin/src/main/java/com/denizenscript/denizen/events/player/PlayerTriggersRaidScriptEvent.java b/plugin/src/main/java/com/denizenscript/denizen/events/player/PlayerTriggersRaidScriptEvent.java new file mode 100644 index 0000000000..34230c8f41 --- /dev/null +++ b/plugin/src/main/java/com/denizenscript/denizen/events/player/PlayerTriggersRaidScriptEvent.java @@ -0,0 +1,54 @@ +package com.denizenscript.denizen.events.player; + +import com.denizenscript.denizen.events.world.RaidScriptEvent; +import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; +import com.denizenscript.denizencore.scripts.ScriptEntryData; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.raid.RaidTriggerEvent; + +public class PlayerTriggersRaidScriptEvent extends RaidScriptEvent implements Listener { + + // <--[event] + // @Events + // player triggers raid + // + // @Group Player + // + // @Location true + // + // @Cancellable true + // + // @Triggers when a player triggers a village raid. + // + // @Context + // returns the raid data. See <@link language Raid Event Data>. + // + // @Player Always. + // + // --> + + public PlayerTriggersRaidScriptEvent() { + super(false); + registerCouldMatcher("player triggers raid"); + } + + @Override + public boolean matches(ScriptPath path) { + if (!runInCheck(path, event.getPlayer().getLocation())) { + return false; + } + return super.matches(path); + } + + @Override + public ScriptEntryData getScriptEntryData() { + return new BukkitScriptEntryData(event.getPlayer()); + } + + @EventHandler + public void onPlayerTriggersRaid(RaidTriggerEvent event) { + this.event = event; + fire(event); + } +} diff --git a/plugin/src/main/java/com/denizenscript/denizen/events/world/RaidFinishesScriptEvent.java b/plugin/src/main/java/com/denizenscript/denizen/events/world/RaidFinishesScriptEvent.java new file mode 100644 index 0000000000..cf0facda42 --- /dev/null +++ b/plugin/src/main/java/com/denizenscript/denizen/events/world/RaidFinishesScriptEvent.java @@ -0,0 +1,52 @@ +package com.denizenscript.denizen.events.world; + +import com.denizenscript.denizen.objects.PlayerTag; +import com.denizenscript.denizencore.objects.ObjectTag; +import com.denizenscript.denizencore.objects.core.ListTag; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.raid.RaidFinishEvent; + +public class RaidFinishesScriptEvent extends RaidScriptEvent implements Listener { + + // <--[event] + // @Events + // raid finishes + // + // @Group World + // + // @Location true + // + // @Triggers when a village raid finishes normally. + // + // @Context + // returns the raid data. See <@link language Raid Event Data>. + // returns the ListTag of players who completed the raid. This is separate from the raid's heroes in that the winners are guaranteed to be online. + // + // --> + + public RaidFinishesScriptEvent() { + super(true); + registerCouldMatcher("raid finishes"); + } + + @Override + public ObjectTag getContext(String name) { + switch (name) { + case "winners": + ListTag list = new ListTag(); + for (Player player : event.getWinners()) { + list.addObject(new PlayerTag(player)); + } + return list; + } + return super.getContext(name); + } + + @EventHandler + public void onRaidFinishes(RaidFinishEvent event) { + this.event = event; + fire(event); + } +} diff --git a/plugin/src/main/java/com/denizenscript/denizen/events/world/RaidScriptEvent.java b/plugin/src/main/java/com/denizenscript/denizen/events/world/RaidScriptEvent.java new file mode 100644 index 0000000000..e89393e4f8 --- /dev/null +++ b/plugin/src/main/java/com/denizenscript/denizen/events/world/RaidScriptEvent.java @@ -0,0 +1,87 @@ +package com.denizenscript.denizen.events.world; + +import com.denizenscript.denizen.events.BukkitScriptEvent; +import com.denizenscript.denizen.objects.EntityTag; +import com.denizenscript.denizen.objects.LocationTag; +import com.denizenscript.denizen.objects.PlayerTag; +import com.denizenscript.denizencore.objects.ObjectTag; +import com.denizenscript.denizencore.objects.core.DurationTag; +import com.denizenscript.denizencore.objects.core.ElementTag; +import com.denizenscript.denizencore.objects.core.ListTag; +import com.denizenscript.denizencore.objects.core.MapTag; +import org.bukkit.Raid; +import org.bukkit.entity.Raider; +import org.bukkit.event.raid.RaidEvent; + +import java.util.UUID; + +public class RaidScriptEvent extends BukkitScriptEvent { + + // <--[language] + // @name Raid Event Data + // @group Useful Lists + // @description + // Every event related to village raids has a property, a MapTag wrapper around raid data (see <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Raid.html>). + // These events are <@link event player triggers raid>, <@link event raid finishes>, <@link event raid spawns wave>, and <@link event raid stops>. + // + // The data format is as follows: + // location: a LocationTag of the raid's center + // heroes: a list of PlayerTags that have participated in the raid + // raiders: a list of raider EntityTags that remain in the current wave + // status: the current status of the raid. See <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Raid.RaidStatus.html> + // ticks: the raid's age in ticks + // level: the Bad Omen level that the raid was started with + // spawned_groups: the amount of raider groups spawned + // total_groups: the number of groups planned to spawn or already spawned + // health: the combined health of all current raiders + // waves: the number of waves in the raid + // --> + + public boolean checkRaidLocation; + + public RaidScriptEvent(boolean checkRaidLocation) { + this.checkRaidLocation = checkRaidLocation; + } + + public T event; + + public static MapTag getRaidMap(Raid raid) { + MapTag data = new MapTag(); + data.putObject("location", new LocationTag(raid.getLocation())); + ListTag heroes = new ListTag(); + for (UUID uuid : raid.getHeroes()) { + heroes.addObject(new PlayerTag(uuid)); + } + data.putObject("heroes", heroes); + ListTag raiders = new ListTag(); + for (Raider raider : raid.getRaiders()) { + raiders.addObject(new EntityTag(raider)); + } + data.putObject("raiders", raiders); + data.putObject("status", new ElementTag(raid.getStatus().name(), true)); + data.putObject("ticks", new DurationTag(raid.getActiveTicks())); + data.putObject("level", new ElementTag(raid.getBadOmenLevel())); + data.putObject("total_groups", new ElementTag(raid.getTotalGroups())); + data.putObject("spawned_groups", new ElementTag(raid.getSpawnedGroups())); + data.putObject("health", new ElementTag(raid.getTotalHealth())); + data.putObject("waves", new ElementTag(raid.getTotalWaves())); + return data; + } + + @Override + public boolean matches(ScriptPath path) { + if (checkRaidLocation && !runInCheck(path, event.getRaid().getLocation())) { + return false; + } + return super.matches(path); + } + + @Override + public ObjectTag getContext(String name) { + switch (name) { + case "raid": + return getRaidMap(event.getRaid()); + } + return super.getContext(name); + } +} diff --git a/plugin/src/main/java/com/denizenscript/denizen/events/world/RaidSpawnsWaveScriptEvent.java b/plugin/src/main/java/com/denizenscript/denizen/events/world/RaidSpawnsWaveScriptEvent.java new file mode 100644 index 0000000000..60981624b8 --- /dev/null +++ b/plugin/src/main/java/com/denizenscript/denizen/events/world/RaidSpawnsWaveScriptEvent.java @@ -0,0 +1,55 @@ +package com.denizenscript.denizen.events.world; + +import com.denizenscript.denizen.objects.EntityTag; +import com.denizenscript.denizencore.objects.ObjectTag; +import com.denizenscript.denizencore.objects.core.ListTag; +import org.bukkit.entity.Raider; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.raid.RaidSpawnWaveEvent; + +public class RaidSpawnsWaveScriptEvent extends RaidScriptEvent implements Listener { + + // <--[event] + // @Events + // raid spawns wave + // + // @Group World + // + // @Location true + // + // @Triggers when a village raid spawns a new wave of raiders. + // + // @Context + // returns the raid data. See <@link language Raid Event Data>. + // returns the EntityTag of the patrol leader of the wave. + // returns the ListTag of all new raiders. + // + // --> + + public RaidSpawnsWaveScriptEvent() { + super(true); + registerCouldMatcher("raid spawns wave"); + } + + @Override + public ObjectTag getContext(String name) { + switch (name) { + case "leader": + return new EntityTag(event.getPatrolLeader()); + case "new_raiders": + ListTag raiders = new ListTag(); + for (Raider raider : event.getRaiders()) { + raiders.addObject(new EntityTag(raider)); + } + return raiders; + } + return super.getContext(name); + } + + @EventHandler + public void onRaidSpawnsWave(RaidSpawnWaveEvent event) { + this.event = event; + fire(event); + } +} diff --git a/plugin/src/main/java/com/denizenscript/denizen/events/world/RaidStopsScriptEvent.java b/plugin/src/main/java/com/denizenscript/denizen/events/world/RaidStopsScriptEvent.java new file mode 100644 index 0000000000..7ed4808e87 --- /dev/null +++ b/plugin/src/main/java/com/denizenscript/denizen/events/world/RaidStopsScriptEvent.java @@ -0,0 +1,57 @@ +package com.denizenscript.denizen.events.world; + +import com.denizenscript.denizencore.objects.ObjectTag; +import com.denizenscript.denizencore.objects.core.ElementTag; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.raid.RaidStopEvent; + +public class RaidStopsScriptEvent extends RaidScriptEvent implements Listener { + + // <--[event] + // @Events + // raid stops + // + // @Group World + // + // @Location true + // + // @Switch reason: to only process the event if the raid stopped for a certain reason. + // + // @Triggers when a village raid stops for any reason. + // + // @Context + // returns the raid data. See <@link language Raid Event Data>. + // returns the reason for stopping. See <@link url https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/raid/RaidStopEvent.Reason.html>. + // + // --> + + public RaidStopsScriptEvent() { + super(true); + registerCouldMatcher("raid stops"); + registerSwitches("reason"); + } + + @Override + public boolean matches(ScriptPath path) { + if (!runGenericSwitchCheck(path, "reason", event.getReason().name())) { + return false; + } + return super.matches(path); + } + + @Override + public ObjectTag getContext(String name) { + switch (name) { + case "reason": + return new ElementTag(event.getReason().name(), true); + } + return super.getContext(name); + } + + @EventHandler + public void onRaidStops(RaidStopEvent event) { + this.event = event; + fire(event); + } +}