mirror of
https://github.com/Auxilor/EcoMobs.git
synced 2025-12-19 23:19:17 +00:00
Merge pull request #10
Implemented spawn events for all types of boss spawns (egg, totem, timer)
This commit is contained in:
@@ -3,6 +3,8 @@ package com.willfp.ecobosses.bosses.listeners;
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import com.willfp.ecobosses.bosses.EcoBoss;
|
||||
import com.willfp.ecobosses.bosses.EcoBosses;
|
||||
import com.willfp.ecobosses.events.EcoBossSpawnTimerEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -49,9 +51,13 @@ public class AutoSpawnTimer implements Runnable {
|
||||
|
||||
if (tick % boss.getAutoSpawnInterval() == 0) {
|
||||
Location location = locations.get(NumberUtils.randInt(0, locations.size() - 1));
|
||||
EcoBossSpawnTimerEvent event = new EcoBossSpawnTimerEvent(boss, location);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
boss.spawn(location);
|
||||
boss.setTimeUntilSpawn(boss.getAutoSpawnInterval());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.ecobosses.bosses.EcoBoss;
|
||||
import com.willfp.ecobosses.bosses.EcoBosses;
|
||||
import com.willfp.ecobosses.bosses.util.obj.SpawnTotem;
|
||||
import com.willfp.ecobosses.events.EcoBossSpawnEggEvent;
|
||||
import com.willfp.ecobosses.events.EcoBossSpawnTotemEvent;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.Event;
|
||||
@@ -62,15 +64,20 @@ public class SpawnListeners extends PluginDependent<EcoPlugin> implements Listen
|
||||
if (boss.isSpawnTotemEnabled()) {
|
||||
if (!boss.getSpawnTotemDisabledWorldNames().contains(event.getBlock().getWorld().getName().toLowerCase())) {
|
||||
if (boss.getSpawnTotem().equals(placedTotem)) {
|
||||
|
||||
if (!boss.areRequirementsMet(event.getPlayer())) {
|
||||
event.getPlayer().sendMessage(this.getPlugin().getLangYml().getMessage("requirements-not-met"));
|
||||
return;
|
||||
}
|
||||
|
||||
EcoBossSpawnTotemEvent eggEvent = new EcoBossSpawnTotemEvent(boss, event.getPlayer(), event.getBlock().getLocation(), placedTotem);
|
||||
|
||||
this.getPlugin().getServer().getPluginManager().callEvent(eggEvent);
|
||||
|
||||
if (!eggEvent.isCancelled()) {
|
||||
block1.setType(Material.AIR);
|
||||
block2.setType(Material.AIR);
|
||||
block3.setType(Material.AIR);
|
||||
|
||||
boss.spawn(event.getBlock().getLocation());
|
||||
}
|
||||
}
|
||||
@@ -78,6 +85,7 @@ public class SpawnListeners extends PluginDependent<EcoPlugin> implements Listen
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void spawnEgg(@NotNull final PlayerInteractEvent event) {
|
||||
@@ -118,6 +126,14 @@ public class SpawnListeners extends PluginDependent<EcoPlugin> implements Listen
|
||||
return;
|
||||
}
|
||||
|
||||
EcoBossSpawnEggEvent eggEvent = new EcoBossSpawnEggEvent(boss, event.getPlayer(), event.getClickedBlock().getLocation(), item);
|
||||
|
||||
this.getPlugin().getServer().getPluginManager().callEvent(eggEvent);
|
||||
|
||||
if (eggEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
item.setAmount(item.getAmount() - 1);
|
||||
|
||||
if (event.getHand() == EquipmentSlot.HAND) {
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.willfp.ecobosses.events;
|
||||
|
||||
import com.willfp.ecobosses.bosses.EcoBoss;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class EcoBossSpawnEggEvent extends EcoBossSpawnEvent {
|
||||
|
||||
/**
|
||||
* The egg item.
|
||||
*/
|
||||
@NotNull
|
||||
private final ItemStack egg;
|
||||
|
||||
/**
|
||||
* Bukkit parity.
|
||||
*/
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
* @param boss - The boss to be spawned.
|
||||
* @param player - The player that spawned this boss (can be null)
|
||||
* @param location - The location that boss will spawn at.
|
||||
* @param egg - ItemStack that represents the egg.
|
||||
*/
|
||||
public EcoBossSpawnEggEvent(@NotNull EcoBoss boss, @Nullable Player player, @NotNull Location location, @NotNull ItemStack egg) {
|
||||
super(boss, player, location);
|
||||
this.egg = egg;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public final ItemStack getEgg() {
|
||||
return this.egg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bukkit parity.
|
||||
*
|
||||
* @return The handlers.
|
||||
*/
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bukkit parity.
|
||||
*
|
||||
* @return The handler list.
|
||||
*/
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package com.willfp.ecobosses.events;
|
||||
|
||||
import com.willfp.ecobosses.bosses.EcoBoss;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* This class represents all boss spawn events fired by EcoBosses.
|
||||
*/
|
||||
public class EcoBossSpawnEvent extends Event implements Cancellable {
|
||||
|
||||
/**
|
||||
* Event cancellation state.
|
||||
*/
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* The boss to be spawned.
|
||||
*/
|
||||
private final EcoBoss boss;
|
||||
|
||||
/**
|
||||
* Location that boss will be spawned at.
|
||||
*/
|
||||
private final Location location;
|
||||
|
||||
/**
|
||||
* Player that spawned this boss.
|
||||
* (Will be null if EcoBossSpawnTimerEvent is fired)
|
||||
*/
|
||||
@Nullable
|
||||
private final Player player;
|
||||
|
||||
/**
|
||||
* Bukkit parity.
|
||||
*/
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
/**
|
||||
*
|
||||
* Default constructor
|
||||
*
|
||||
* @param boss - The boss to be spawned.
|
||||
* @param player - The player that spawned this boss (can be null)
|
||||
* @param location - The location that boss will spawn at.
|
||||
*/
|
||||
public EcoBossSpawnEvent(@NotNull final EcoBoss boss, @Nullable final Player player, @NotNull final Location location) {
|
||||
this.cancelled = false;
|
||||
this.boss = boss;
|
||||
this.location = location;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Get the EcoBoss.
|
||||
*
|
||||
* @return - EcoBoss to be spawned.
|
||||
*/
|
||||
@NotNull
|
||||
public EcoBoss getBoss() {
|
||||
return this.boss;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Get the location.
|
||||
*
|
||||
* @return - Location.
|
||||
*/
|
||||
@NotNull
|
||||
public Location getLocation() {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Get the player if present.
|
||||
*
|
||||
* @return - The player.
|
||||
*/
|
||||
@Nullable
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Check if this event has any player presented.
|
||||
*
|
||||
* @return - If any player is presented in this event.
|
||||
*/
|
||||
public boolean hasPlayer() {
|
||||
return this.player != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bukkit parity.
|
||||
*
|
||||
* @return The handlers.
|
||||
*/
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Get if event is cancelled.
|
||||
*
|
||||
* @return Event cancellation state.
|
||||
*/
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Set event cancellation state.
|
||||
*
|
||||
* @param b - The state to set.
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean b) {
|
||||
this.cancelled = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bukkit parity.
|
||||
*
|
||||
* @return The handler list.
|
||||
*/
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.willfp.ecobosses.events;
|
||||
|
||||
import com.willfp.ecobosses.bosses.EcoBoss;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class EcoBossSpawnTimerEvent extends EcoBossSpawnEvent {
|
||||
|
||||
/**
|
||||
* Bukkit parity.
|
||||
*/
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
* @param boss - The boss to be spawned.
|
||||
* @param location - The location that boss will spawn at.
|
||||
*/
|
||||
public EcoBossSpawnTimerEvent(@NotNull EcoBoss boss, @NotNull Location location) {
|
||||
super(boss, null, location);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bukkit parity.
|
||||
*
|
||||
* @return The handlers.
|
||||
*/
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bukkit parity.
|
||||
*
|
||||
* @return The handler list.
|
||||
*/
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.willfp.ecobosses.events;
|
||||
|
||||
import com.willfp.ecobosses.bosses.EcoBoss;
|
||||
import com.willfp.ecobosses.bosses.util.obj.SpawnTotem;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class EcoBossSpawnTotemEvent extends EcoBossSpawnEvent {
|
||||
|
||||
/**
|
||||
* The totem.
|
||||
*/
|
||||
@NotNull
|
||||
private final SpawnTotem totem;
|
||||
|
||||
/**
|
||||
* Bukkit parity.
|
||||
*/
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
* @param boss - The boss to be spawned.
|
||||
* @param player - The player that spawned this boss (can be null)
|
||||
* @param location - The location that boss will spawn at.
|
||||
* @param totem - The totem.
|
||||
*/
|
||||
public EcoBossSpawnTotemEvent(@NotNull final EcoBoss boss, @Nullable final Player player, @NotNull final Location location, @NotNull final SpawnTotem totem) {
|
||||
super(boss, player, location);
|
||||
this.totem = totem;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public SpawnTotem getTotem() {
|
||||
return this.totem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bukkit parity.
|
||||
*
|
||||
* @return The handlers.
|
||||
*/
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bukkit parity.
|
||||
*
|
||||
* @return The handler list.
|
||||
*/
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user