1.0.0-SNAPSHOT-U181

+ Added in the IntervalSpawnHandler to keep the IntervalSpawnElement from getting too clustered
+ Added all the custom setting click actions to the IntervalSpawnElement
+ Added a method to AutoSpawnManager to create a new custom click action for the auto spawn system
This commit is contained in:
Charles 2019-01-07 15:34:07 +08:00
parent e130170240
commit dfc8f0d938
4 changed files with 156 additions and 55 deletions

View File

@ -0,0 +1,93 @@
package com.songoda.epicbosses.autospawns.handlers;
import com.songoda.epicbosses.api.BossAPI;
import com.songoda.epicbosses.autospawns.AutoSpawn;
import com.songoda.epicbosses.autospawns.settings.AutoSpawnSettings;
import com.songoda.epicbosses.autospawns.types.IntervalSpawnElement;
import com.songoda.epicbosses.entity.BossEntity;
import com.songoda.epicbosses.holder.ActiveBossHolder;
import com.songoda.epicbosses.holder.autospawn.ActiveIntervalAutoSpawnHolder;
import com.songoda.epicbosses.listeners.IBossDeathHandler;
import com.songoda.epicbosses.utils.MessageUtils;
import com.songoda.epicbosses.utils.NumberUtils;
import com.songoda.epicbosses.utils.ObjectUtils;
import com.songoda.epicbosses.utils.StringUtils;
import com.songoda.epicbosses.utils.panel.base.ClickAction;
import org.bukkit.Location;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 07-Jan-19
*/
public class IntervalSpawnHandler {
public boolean attemptSpawn(ActiveIntervalAutoSpawnHolder activeAutoSpawnHolder, IntervalSpawnElement intervalSpawnElement) {
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 = intervalSpawnElement.getSpawnLocation();
if(bosses == null || bosses.isEmpty()) return false;
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);
}
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;
}
public ClickAction getSpawnAfterLastBossIsKilledAction(IntervalSpawnElement intervalSpawnElement) {
return event -> {};
}
public ClickAction getLocationAction(IntervalSpawnElement intervalSpawnElement) {
return event -> {};
}
public ClickAction getPlaceholderAction(IntervalSpawnElement intervalSpawnElement) {
return event -> {};
}
public ClickAction getSpawnRateAction(IntervalSpawnElement intervalSpawnElement) {
return event -> {};
}
}

View File

@ -1,22 +1,18 @@
package com.songoda.epicbosses.autospawns.types;
import com.google.gson.annotations.Expose;
import com.songoda.epicbosses.api.BossAPI;
import com.songoda.epicbosses.autospawns.AutoSpawn;
import com.songoda.epicbosses.autospawns.IAutoSpawnCustomSettingsHandler;
import com.songoda.epicbosses.autospawns.settings.AutoSpawnSettings;
import com.songoda.epicbosses.entity.BossEntity;
import com.songoda.epicbosses.holder.ActiveBossHolder;
import com.songoda.epicbosses.autospawns.handlers.IntervalSpawnHandler;
import com.songoda.epicbosses.holder.autospawn.ActiveIntervalAutoSpawnHolder;
import com.songoda.epicbosses.listeners.IBossDeathHandler;
import com.songoda.epicbosses.managers.AutoSpawnManager;
import com.songoda.epicbosses.skills.interfaces.ICustomSettingAction;
import com.songoda.epicbosses.utils.MessageUtils;
import com.songoda.epicbosses.utils.NumberUtils;
import com.songoda.epicbosses.utils.ObjectUtils;
import com.songoda.epicbosses.utils.StringUtils;
import com.songoda.epicbosses.utils.panel.base.ClickAction;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.util.*;
@ -27,6 +23,8 @@ import java.util.*;
*/
public class IntervalSpawnElement implements IAutoSpawnCustomSettingsHandler {
private final IntervalSpawnHandler intervalSpawnHandler = new IntervalSpawnHandler();
@Expose @Getter @Setter private Boolean spawnAfterLastBossIsKilled;
@Expose @Getter @Setter private String location, placeholder;
@Expose @Getter @Setter private Integer spawnRate;
@ -40,54 +38,23 @@ public class IntervalSpawnElement implements IAutoSpawnCustomSettingsHandler {
@Override
public List<ICustomSettingAction> getCustomSettingActions() {
return null;
List<ICustomSettingAction> clickActions = new ArrayList<>();
ItemStack clickStack = new ItemStack(Material.IRON_BLOCK);
ClickAction lastBossKilledAction = this.intervalSpawnHandler.getSpawnAfterLastBossIsKilledAction(this);
ClickAction locationAction = this.intervalSpawnHandler.getLocationAction(this);
ClickAction placeholderAction = this.intervalSpawnHandler.getPlaceholderAction(this);
ClickAction spawnRateAction = this.intervalSpawnHandler.getSpawnRateAction(this);
clickActions.add(AutoSpawnManager.createAutoSpawnAction("Spawn After Last Boss Is Killed", getSpawnAfterLastBossIsKilled()+"", clickStack.clone(), lastBossKilledAction));
clickActions.add(AutoSpawnManager.createAutoSpawnAction("Location", getLocation(), clickStack.clone(), locationAction));
clickActions.add(AutoSpawnManager.createAutoSpawnAction("Placeholder", getPlaceholder(), clickStack.clone(), placeholderAction));
clickActions.add(AutoSpawnManager.createAutoSpawnAction("Spawn Rate", getSpawnRate()+"", clickStack.clone(), spawnRateAction));
return clickActions;
}
public boolean attemptSpawn(ActiveIntervalAutoSpawnHolder activeAutoSpawnHolder) {
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();
if(bosses == null || bosses.isEmpty()) return false;
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);
}
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;
return this.intervalSpawnHandler.attemptSpawn(activeAutoSpawnHolder, this);
}
public Location getSpawnLocation() {

View File

@ -7,6 +7,9 @@ import com.songoda.epicbosses.autospawns.SpawnType;
import com.songoda.epicbosses.holder.ActiveAutoSpawnHolder;
import com.songoda.epicbosses.holder.autospawn.ActiveIntervalAutoSpawnHolder;
import com.songoda.epicbosses.managers.files.AutoSpawnFileManager;
import com.songoda.epicbosses.skills.interfaces.ICustomSettingAction;
import com.songoda.epicbosses.utils.panel.base.ClickAction;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.HashMap;
@ -133,4 +136,42 @@ public class AutoSpawnManager {
}
}
public static ICustomSettingAction createAutoSpawnAction(String name, String current, ItemStack displayStack, ClickAction clickAction) {
return new CustomAutoSpawnActionCreator(name, current, displayStack, clickAction);
}
private static class CustomAutoSpawnActionCreator implements ICustomSettingAction {
private final ClickAction clickAction;
private final String name, current;
private final ItemStack itemStack;
public CustomAutoSpawnActionCreator(String name, String current, ItemStack itemStack, ClickAction clickAction) {
this.name = name;
this.current = current;
this.itemStack = itemStack;
this.clickAction = clickAction;
}
@Override
public ClickAction getAction() {
return this.clickAction;
}
@Override
public String getSettingName() {
return this.name;
}
@Override
public ItemStack getDisplayItemStack() {
return this.itemStack;
}
@Override
public String getCurrent() {
return this.current;
}
}
}

View File

@ -19,7 +19,7 @@
</modules>
<properties>
<plugin.version>1.0.0-U180</plugin.version>
<plugin.version>1.0.0-U181</plugin.version>
<plugin.name>EpicBosses</plugin.name>
<plugin.main>com.songoda.epicbosses.CustomBosses</plugin.main>
<plugin.author>AMinecraftDev</plugin.author>