2019-01-02 16:12:18 +01:00
package com.songoda.epicbosses.autospawns.types ;
import com.google.gson.annotations.Expose ;
2019-01-08 18:53:14 +01:00
import com.songoda.epicbosses.api.BossAPI ;
2019-01-07 11:25:30 +01:00
import com.songoda.epicbosses.autospawns.AutoSpawn ;
2019-01-07 08:13:38 +01:00
import com.songoda.epicbosses.autospawns.IAutoSpawnCustomSettingsHandler ;
2019-01-07 08:34:07 +01:00
import com.songoda.epicbosses.autospawns.handlers.IntervalSpawnHandler ;
2019-01-08 18:53:14 +01:00
import com.songoda.epicbosses.autospawns.settings.AutoSpawnSettings ;
import com.songoda.epicbosses.entity.BossEntity ;
2019-03-21 06:34:45 +01:00
import com.songoda.epicbosses.events.BossSpawnEvent ;
2019-01-08 18:53:14 +01:00
import com.songoda.epicbosses.holder.ActiveBossHolder ;
2019-01-03 16:58:29 +01:00
import com.songoda.epicbosses.holder.autospawn.ActiveIntervalAutoSpawnHolder ;
2019-01-08 18:53:14 +01:00
import com.songoda.epicbosses.listeners.IBossDeathHandler ;
2019-01-07 08:34:07 +01:00
import com.songoda.epicbosses.managers.AutoSpawnManager ;
2019-01-07 08:13:38 +01:00
import com.songoda.epicbosses.skills.interfaces.ICustomSettingAction ;
2019-02-01 14:04:23 +01:00
import com.songoda.epicbosses.utils.* ;
2019-01-07 08:34:07 +01:00
import com.songoda.epicbosses.utils.panel.base.ClickAction ;
2019-01-07 13:27:04 +01:00
import com.songoda.epicbosses.utils.panel.base.handlers.VariablePanelHandler ;
2019-01-02 16:12:18 +01:00
import lombok.Getter ;
import lombok.Setter ;
2019-01-03 14:41:35 +01:00
import org.bukkit.Location ;
2019-01-07 08:34:07 +01:00
import org.bukkit.Material ;
import org.bukkit.inventory.ItemStack ;
2019-01-02 16:12:18 +01:00
2019-01-03 17:38:18 +01:00
import java.util.* ;
2019-01-02 16:12:18 +01:00
/ * *
* @author Charles Cullen
* @version 1 . 0 . 0
* @since 02 - Jan - 19
* /
2019-01-07 08:13:38 +01:00
public class IntervalSpawnElement implements IAutoSpawnCustomSettingsHandler {
2019-01-02 16:12:18 +01:00
2019-01-03 15:58:21 +01:00
@Expose @Getter @Setter private Boolean spawnAfterLastBossIsKilled ;
2019-01-02 16:12:18 +01:00
@Expose @Getter @Setter private String location , placeholder ;
@Expose @Getter @Setter private Integer spawnRate ;
2019-01-03 15:58:21 +01:00
public IntervalSpawnElement ( String location , String placeholder , Integer spawnRate , boolean spawnAfterLastBossIsKilled ) {
2019-01-02 16:12:18 +01:00
this . location = location ;
this . placeholder = placeholder ;
this . spawnRate = spawnRate ;
2019-01-03 15:58:21 +01:00
this . spawnAfterLastBossIsKilled = spawnAfterLastBossIsKilled ;
2019-01-02 16:12:18 +01:00
}
2019-01-07 08:13:38 +01:00
@Override
2019-01-07 13:27:04 +01:00
public List < ICustomSettingAction > getCustomSettingActions ( AutoSpawn autoSpawn , VariablePanelHandler < AutoSpawn > variablePanelHandler ) {
2019-01-07 08:34:07 +01:00
List < ICustomSettingAction > clickActions = new ArrayList < > ( ) ;
ItemStack clickStack = new ItemStack ( Material . IRON_BLOCK ) ;
2019-01-08 18:53:14 +01:00
IntervalSpawnHandler intervalSpawnHandler = new IntervalSpawnHandler ( ) ;
ClickAction lastBossKilledAction = intervalSpawnHandler . getSpawnAfterLastBossIsKilledAction ( this , autoSpawn , variablePanelHandler ) ;
ClickAction locationAction = intervalSpawnHandler . getLocationAction ( this , autoSpawn , variablePanelHandler ) ;
ClickAction placeholderAction = intervalSpawnHandler . getPlaceholderAction ( this , autoSpawn , variablePanelHandler ) ;
ClickAction spawnRateAction = intervalSpawnHandler . getSpawnRateAction ( this , autoSpawn , variablePanelHandler ) ;
2019-01-07 08:34:07 +01:00
2019-01-08 18:53:14 +01:00
clickActions . add ( AutoSpawnManager . createAutoSpawnAction ( " Spawn After Last Boss Is Killed " , getSpawnAfterLastBossIsKilled ( ) + " " , intervalSpawnHandler . getSpawnAfterLastBossIsKilledExtraInformation ( ) , clickStack . clone ( ) , lastBossKilledAction ) ) ;
clickActions . add ( AutoSpawnManager . createAutoSpawnAction ( " Location " , getLocation ( ) , intervalSpawnHandler . getLocationExtraInformation ( ) , clickStack . clone ( ) , locationAction ) ) ;
clickActions . add ( AutoSpawnManager . createAutoSpawnAction ( " Placeholder " , getPlaceholder ( ) , intervalSpawnHandler . getPlaceholderExtraInformation ( ) , clickStack . clone ( ) , placeholderAction ) ) ;
clickActions . add ( AutoSpawnManager . createAutoSpawnAction ( " Spawn Rate " , getSpawnRate ( ) + " " , intervalSpawnHandler . getSpawnRateExtraInformation ( ) , clickStack . clone ( ) , spawnRateAction ) ) ;
2019-01-07 08:34:07 +01:00
return clickActions ;
2019-01-07 08:13:38 +01:00
}
2019-01-03 16:58:29 +01:00
public boolean attemptSpawn ( ActiveIntervalAutoSpawnHolder activeAutoSpawnHolder ) {
2019-01-08 18:53:14 +01:00
IBossDeathHandler bossDeathHandler = activeAutoSpawnHolder . getPostDeathHandler ( ) ;
AutoSpawn autoSpawn = activeAutoSpawnHolder . getAutoSpawn ( ) ;
AutoSpawnSettings autoSpawnSettings = autoSpawn . getAutoSpawnSettings ( ) ;
boolean customSpawnMessage = ObjectUtils . getValue ( autoSpawnSettings . getOverrideDefaultSpawnMessage ( ) , false ) ;
String spawnMessage = autoSpawnSettings . getSpawnMessage ( ) ;
int amountToSpawn = ObjectUtils . getValue ( autoSpawnSettings . getAmountPerSpawn ( ) , 1 ) ;
boolean shuffleList = ObjectUtils . getValue ( autoSpawnSettings . getShuffleEntitiesList ( ) , false ) ;
List < String > bosses = autoSpawn . getEntities ( ) ;
Location location = getSpawnLocation ( ) ;
2019-02-01 14:04:23 +01:00
if ( bosses = = null | | bosses . isEmpty ( ) ) {
ServerUtils . get ( ) . logDebug ( " BOSSES IS EMPTY! " ) ;
return false ;
}
2019-01-08 18:53:14 +01:00
if ( shuffleList ) Collections . shuffle ( bosses ) ;
Queue < String > queue = new LinkedList < > ( bosses ) ;
for ( int i = 1 ; i < = amountToSpawn ; i + + ) {
if ( queue . isEmpty ( ) ) queue = new LinkedList < > ( bosses ) ;
BossEntity bossEntity = BossAPI . getBossEntity ( queue . poll ( ) ) ;
ActiveBossHolder activeBossHolder = BossAPI . spawnNewBoss ( bossEntity , location , null , null , customSpawnMessage ) ;
if ( activeBossHolder = = null ) continue ;
activeBossHolder . getPostBossDeathHandlers ( ) . add ( bossDeathHandler ) ;
activeAutoSpawnHolder . getActiveBossHolders ( ) . add ( activeBossHolder ) ;
2019-03-21 06:34:45 +01:00
BossSpawnEvent bossSpawnEvent = new BossSpawnEvent ( activeBossHolder , true ) ;
ServerUtils . get ( ) . callEvent ( bossSpawnEvent ) ;
2019-01-08 18:53:14 +01:00
}
if ( customSpawnMessage & & spawnMessage ! = null ) {
String x = NumberUtils . get ( ) . formatDouble ( location . getBlockX ( ) ) ;
String y = NumberUtils . get ( ) . formatDouble ( location . getBlockY ( ) ) ;
String z = NumberUtils . get ( ) . formatDouble ( location . getBlockZ ( ) ) ;
String world = StringUtils . get ( ) . formatString ( location . getWorld ( ) . getName ( ) ) ;
List < String > spawnMessages = BossAPI . getStoredMessages ( spawnMessage ) ;
if ( spawnMessages ! = null ) {
spawnMessages . replaceAll ( s - > s . replace ( " {x} " , x ) . replace ( " {y} " , y ) . replace ( " {z} " , z ) . replace ( " {world} " , world ) ) ;
MessageUtils . get ( ) . sendMessage ( location , - 1 , spawnMessages ) ;
}
}
return true ;
2019-01-03 12:11:31 +01:00
}
2019-01-03 14:41:35 +01:00
public Location getSpawnLocation ( ) {
return StringUtils . get ( ) . fromStringToLocation ( this . location ) ;
}
2019-01-02 16:12:18 +01:00
}