SPIGOT-5211: Add Raid API

By: anhcraft <admin@anhcraft.dev>
This commit is contained in:
Bukkit/Spigot
2019-08-12 18:09:35 +07:00
parent 2ef8482885
commit 71802c602b
7 changed files with 409 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
package org.bukkit.event.raid;
import org.bukkit.Raid;
import org.bukkit.World;
import org.bukkit.event.world.WorldEvent;
import org.jetbrains.annotations.NotNull;
/**
* Represents events related to raids.
*/
public abstract class RaidEvent extends WorldEvent {
private final Raid raid;
protected RaidEvent(@NotNull Raid raid, @NotNull World world) {
super(world);
this.raid = raid;
}
/**
* Returns the raid involved with this event.
*
* @return Raid
*/
@NotNull
public Raid getRaid() {
return raid;
}
}

View File

@@ -0,0 +1,48 @@
package org.bukkit.event.raid;
import java.util.Collections;
import java.util.List;
import org.bukkit.Raid;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* This event is called when a {@link Raid} was complete with a clear result.
*/
public class RaidFinishEvent extends RaidEvent {
private static final HandlerList handlers = new HandlerList();
//
private final List<Player> winners;
public RaidFinishEvent(@NotNull Raid raid, @NotNull World world, @NotNull List<Player> winners) {
super(raid, world);
this.winners = winners;
}
/**
* Returns an immutable list contains all winners.
* <br>
* <b>Note: Players who are considered as heroes but were not online at the
* end would not be included in this list.</b>
*
* @return winners
*/
@NotNull
public List<Player> getWinners() {
return Collections.unmodifiableList(winners);
}
@NotNull
@Override
public HandlerList getHandlers() {
return handlers;
}
@NotNull
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@@ -0,0 +1,58 @@
package org.bukkit.event.raid;
import java.util.Collections;
import java.util.List;
import org.bukkit.Raid;
import org.bukkit.World;
import org.bukkit.entity.Raider;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Called when a raid wave spawns.
*/
public class RaidSpawnWaveEvent extends RaidEvent {
private static final HandlerList handlers = new HandlerList();
//
private final List<Raider> raiders;
private final Raider leader;
public RaidSpawnWaveEvent(@NotNull Raid raid, @NotNull World world, @Nullable Raider leader, @NotNull List<Raider> raiders) {
super(raid, world);
this.raiders = raiders;
this.leader = leader;
}
/**
* Returns the patrol leader.
*
* @return {@link Raider}
*/
@Nullable
public Raider getPatrolLeader() {
return leader;
}
/**
* Returns all {@link Raider} that spawned in this wave.
*
* @return an immutable list of raiders
*/
@NotNull
public List<Raider> getRaiders() {
return Collections.unmodifiableList(raiders);
}
@NotNull
@Override
public HandlerList getHandlers() {
return handlers;
}
@NotNull
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@@ -0,0 +1,66 @@
package org.bukkit.event.raid;
import org.bukkit.Raid;
import org.bukkit.World;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* Called when a {@link Raid} is stopped.
*/
public class RaidStopEvent extends RaidEvent {
private static final HandlerList handlers = new HandlerList();
//
private final Reason reason;
public RaidStopEvent(@NotNull Raid raid, @NotNull World world, @NotNull Reason reason) {
super(raid, world);
this.reason = reason;
}
/**
* Returns the stop reason.
*
* @return Reason
*/
@NotNull
public Reason getReason() {
return reason;
}
@NotNull
@Override
public HandlerList getHandlers() {
return handlers;
}
@NotNull
public static HandlerList getHandlerList() {
return handlers;
}
public enum Reason {
/**
* Because the difficulty has been changed to peaceful.
*/
PEACE,
/**
* The raid took a long time without a final result.
*/
TIMEOUT,
/**
* Finished the raid.
*/
FINISHED,
/**
* Couldn't find a suitable place to spawn raiders.
*/
UNSPAWNABLE,
/**
* The place where the raid occurs no longer be a village.
*/
NOT_IN_VILLAGE
}
}

View File

@@ -0,0 +1,56 @@
package org.bukkit.event.raid;
import org.bukkit.Raid;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* Called when a {@link Raid} is triggered (e.g: a player with Bad Omen effect
* enters a village).
*/
public class RaidTriggerEvent extends RaidEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
//
private final Player player;
private boolean cancel;
public RaidTriggerEvent(@NotNull Raid raid, @NotNull World world, @NotNull Player player) {
super(raid, world);
this.player = player;
}
/**
* Returns the player who triggered the raid.
*
* @return triggering player
*/
@NotNull
public Player getPlayer() {
return player;
}
@Override
public boolean isCancelled() {
return cancel;
}
@Override
public void setCancelled(boolean cancel) {
this.cancel = cancel;
}
@NotNull
@Override
public HandlerList getHandlers() {
return handlers;
}
@NotNull
public static HandlerList getHandlerList() {
return handlers;
}
}