Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial impl * cleanup * event and data format meta entries * dont lowercase enum values * fix false event override * change ticks to a durationtag
- Loading branch information
Showing
6 changed files
with
309 additions
and
0 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
54 changes: 54 additions & 0 deletions
54
.../src/main/java/com/denizenscript/denizen/events/player/PlayerTriggersRaidScriptEvent.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,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<RaidTriggerEvent> implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// player triggers raid | ||
// | ||
// @Group Player | ||
// | ||
// @Location true | ||
// | ||
// @Cancellable true | ||
// | ||
// @Triggers when a player triggers a village raid. | ||
// | ||
// @Context | ||
// <context.raid> 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); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
plugin/src/main/java/com/denizenscript/denizen/events/world/RaidFinishesScriptEvent.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,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<RaidFinishEvent> implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// raid finishes | ||
// | ||
// @Group World | ||
// | ||
// @Location true | ||
// | ||
// @Triggers when a village raid finishes normally. | ||
// | ||
// @Context | ||
// <context.raid> returns the raid data. See <@link language Raid Event Data>. | ||
// <context.winners> 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); | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
plugin/src/main/java/com/denizenscript/denizen/events/world/RaidScriptEvent.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,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<T extends RaidEvent> extends BukkitScriptEvent { | ||
|
||
// <--[language] | ||
// @name Raid Event Data | ||
// @group Useful Lists | ||
// @description | ||
// Every event related to village raids has a <context.raid> 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); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
plugin/src/main/java/com/denizenscript/denizen/events/world/RaidSpawnsWaveScriptEvent.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,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<RaidSpawnWaveEvent> implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// raid spawns wave | ||
// | ||
// @Group World | ||
// | ||
// @Location true | ||
// | ||
// @Triggers when a village raid spawns a new wave of raiders. | ||
// | ||
// @Context | ||
// <context.raid> returns the raid data. See <@link language Raid Event Data>. | ||
// <context.leader> returns the EntityTag of the patrol leader of the wave. | ||
// <context.new_raiders> 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); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
plugin/src/main/java/com/denizenscript/denizen/events/world/RaidStopsScriptEvent.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,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<RaidStopEvent> implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// raid stops | ||
// | ||
// @Group World | ||
// | ||
// @Location true | ||
// | ||
// @Switch reason:<reason> to only process the event if the raid stopped for a certain reason. | ||
// | ||
// @Triggers when a village raid stops for any reason. | ||
// | ||
// @Context | ||
// <context.raid> returns the raid data. See <@link language Raid Event Data>. | ||
// <context.reason> 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); | ||
} | ||
} |