diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/autospawns/handlers/IntervalSpawnHandler.java b/plugin-modules/Core/src/com/songoda/epicbosses/autospawns/handlers/IntervalSpawnHandler.java index 3466e81..3f0da21 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/autospawns/handlers/IntervalSpawnHandler.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/autospawns/handlers/IntervalSpawnHandler.java @@ -7,6 +7,9 @@ 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.handlers.AutoSpawnVariableHandler; +import com.songoda.epicbosses.handlers.variables.AutoSpawnLocationVariableHandler; +import com.songoda.epicbosses.handlers.variables.AutoSpawnPlaceholderVariableHandler; import com.songoda.epicbosses.holder.ActiveBossHolder; import com.songoda.epicbosses.holder.autospawn.ActiveIntervalAutoSpawnHolder; import com.songoda.epicbosses.listeners.IBossDeathHandler; @@ -74,15 +77,24 @@ public class IntervalSpawnHandler { } public ClickAction getSpawnAfterLastBossIsKilledAction(IntervalSpawnElement intervalSpawnElement) { - return event -> {}; + return event -> { + + }; } public List getSpawnAfterLastBossIsKilledExtraInformation() { return Arrays.asList("&7Click here to toggle the timer", "&7being enabled/reset after the last boss is killed.", "&7This will make it so only one active", "&7boss from this section can be spawned", "&7at a time."); } - public ClickAction getLocationAction(IntervalSpawnElement intervalSpawnElement) { - return event -> {}; + public ClickAction getLocationAction(IntervalSpawnElement intervalSpawnElement, AutoSpawn autoSpawn, VariablePanelHandler variablePanelHandler) { + return event -> { + Player player = (Player) event.getWhoClicked(); + AutoSpawnVariableHandler autoSpawnVariableHandler = new AutoSpawnLocationVariableHandler(player, autoSpawn, intervalSpawnElement, CustomBosses.get().getAutoSpawnFileManager(), variablePanelHandler); + + Message.Boss_AutoSpawn_SetLocation.msg(player); + autoSpawnVariableHandler.handle(); + player.closeInventory(); + }; } public List getLocationExtraInformation() { @@ -90,7 +102,14 @@ public class IntervalSpawnHandler { } public ClickAction getPlaceholderAction(IntervalSpawnElement intervalSpawnElement, AutoSpawn autoSpawn, VariablePanelHandler variablePanelHandler) { - return event -> {}; + return event -> { + Player player = (Player) event.getWhoClicked(); + AutoSpawnVariableHandler autoSpawnVariableHandler = new AutoSpawnPlaceholderVariableHandler(player, autoSpawn, intervalSpawnElement, CustomBosses.get().getAutoSpawnFileManager(), variablePanelHandler); + + Message.Boss_AutoSpawn_SetLocation.msg(player); + autoSpawnVariableHandler.handle(); + player.closeInventory(); + }; } public List getPlaceholderExtraInformation() { diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/handlers/AutoSpawnLocationHandler.java b/plugin-modules/Core/src/com/songoda/epicbosses/handlers/AutoSpawnVariableHandler.java similarity index 71% rename from plugin-modules/Core/src/com/songoda/epicbosses/handlers/AutoSpawnLocationHandler.java rename to plugin-modules/Core/src/com/songoda/epicbosses/handlers/AutoSpawnVariableHandler.java index 27f007e..a791cd0 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/handlers/AutoSpawnLocationHandler.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/handlers/AutoSpawnVariableHandler.java @@ -1,6 +1,8 @@ package com.songoda.epicbosses.handlers; +import com.songoda.epicbosses.api.BossAPI; import com.songoda.epicbosses.autospawns.AutoSpawn; +import com.songoda.epicbosses.autospawns.types.IntervalSpawnElement; import com.songoda.epicbosses.managers.files.AutoSpawnFileManager; import com.songoda.epicbosses.utils.IHandler; import com.songoda.epicbosses.utils.Message; @@ -20,28 +22,32 @@ import java.util.UUID; /** * @author Charles Cullen * @version 1.0.0 - * @since 07-Jan-19 + * @since 08-Jan-19 */ -public class AutoSpawnLocationHandler implements IHandler { +public abstract class AutoSpawnVariableHandler implements IHandler { @Getter private final IVariablePanelHandler panelHandler; - @Getter private AutoSpawnFileManager autoSpawnFileManager; + @Getter private final IntervalSpawnElement intervalSpawnElement; + @Getter private final AutoSpawnFileManager autoSpawnFileManager; @Getter private final AutoSpawn autoSpawn; @Getter private final Player player; @Getter @Setter private boolean handled = false; private Listener listener; - public AutoSpawnLocationHandler(Player player, AutoSpawn autoSpawn, AutoSpawnFileManager autoSpawnFileManager, IVariablePanelHandler panelHandler) { + public AutoSpawnVariableHandler(Player player, AutoSpawn autoSpawn, IntervalSpawnElement intervalSpawnElement, AutoSpawnFileManager autoSpawnFileManager, IVariablePanelHandler panelHandler) { this.player = player; this.autoSpawn = autoSpawn; this.panelHandler = panelHandler; this.autoSpawnFileManager = autoSpawnFileManager; + this.intervalSpawnElement = intervalSpawnElement; this.listener = getListener(); } + protected abstract boolean confirmValue(String input, IntervalSpawnElement intervalSpawnElement); + @Override public void handle() { ServerUtils.get().registerListener(this.listener); @@ -64,17 +70,13 @@ public class AutoSpawnLocationHandler implements IHandler { } if(input == null) { - - } - - Location location = StringUtils.get().fromStringToLocation(input); - - if(location == null) { - Message.Boss_AutoSpawn_InvalidLocation.msg(getPlayer(), input); + finish(); return; } - autoSpawn.getIntervalSpawnData().setLocation(input); + if(!confirmValue(input, getIntervalSpawnElement())) return; + + getAutoSpawn().setCustomData(BossAPI.convertObjectToJsonObject(getIntervalSpawnElement())); getAutoSpawnFileManager().save(); event.setCancelled(true); setHandled(true); diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/handlers/variables/AutoSpawnLocationVariableHandler.java b/plugin-modules/Core/src/com/songoda/epicbosses/handlers/variables/AutoSpawnLocationVariableHandler.java new file mode 100644 index 0000000..5443d0f --- /dev/null +++ b/plugin-modules/Core/src/com/songoda/epicbosses/handlers/variables/AutoSpawnLocationVariableHandler.java @@ -0,0 +1,37 @@ +package com.songoda.epicbosses.handlers.variables; + +import com.songoda.epicbosses.autospawns.AutoSpawn; +import com.songoda.epicbosses.autospawns.types.IntervalSpawnElement; +import com.songoda.epicbosses.handlers.AutoSpawnVariableHandler; +import com.songoda.epicbosses.managers.files.AutoSpawnFileManager; +import com.songoda.epicbosses.utils.Message; +import com.songoda.epicbosses.utils.StringUtils; +import com.songoda.epicbosses.utils.panel.base.IVariablePanelHandler; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +/** + * @author Charles Cullen + * @version 1.0.0 + * @since 07-Jan-19 + */ +public class AutoSpawnLocationVariableHandler extends AutoSpawnVariableHandler { + + public AutoSpawnLocationVariableHandler(Player player, AutoSpawn autoSpawn, IntervalSpawnElement intervalSpawnElement, AutoSpawnFileManager autoSpawnFileManager, IVariablePanelHandler panelHandler) { + super(player, autoSpawn, intervalSpawnElement, autoSpawnFileManager, panelHandler); + } + + @Override + protected boolean confirmValue(String input, IntervalSpawnElement intervalSpawnElement) { + Location location = StringUtils.get().fromStringToLocation(input); + + if(location == null) { + Message.Boss_AutoSpawn_InvalidLocation.msg(getPlayer(), input); + return false; + } + + intervalSpawnElement.setLocation(StringUtils.get().translateLocation(location)); + return true; + } + +} diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/handlers/variables/AutoSpawnPlaceholderVariableHandler.java b/plugin-modules/Core/src/com/songoda/epicbosses/handlers/variables/AutoSpawnPlaceholderVariableHandler.java new file mode 100644 index 0000000..c7f4451 --- /dev/null +++ b/plugin-modules/Core/src/com/songoda/epicbosses/handlers/variables/AutoSpawnPlaceholderVariableHandler.java @@ -0,0 +1,26 @@ +package com.songoda.epicbosses.handlers.variables; + +import com.songoda.epicbosses.autospawns.AutoSpawn; +import com.songoda.epicbosses.autospawns.types.IntervalSpawnElement; +import com.songoda.epicbosses.handlers.AutoSpawnVariableHandler; +import com.songoda.epicbosses.managers.files.AutoSpawnFileManager; +import com.songoda.epicbosses.utils.panel.base.IVariablePanelHandler; +import org.bukkit.entity.Player; + +/** + * @author Charles Cullen + * @version 1.0.0 + * @since 08-Jan-19 + */ +public class AutoSpawnPlaceholderVariableHandler extends AutoSpawnVariableHandler { + + public AutoSpawnPlaceholderVariableHandler(Player player, AutoSpawn autoSpawn, IntervalSpawnElement intervalSpawnElement, AutoSpawnFileManager autoSpawnFileManager, IVariablePanelHandler panelHandler) { + super(player, autoSpawn, intervalSpawnElement, autoSpawnFileManager, panelHandler); + } + + @Override + protected boolean confirmValue(String input, IntervalSpawnElement intervalSpawnElement) { + intervalSpawnElement.setPlaceholder(input); + return true; + } +} diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/utils/Message.java b/plugin-modules/Core/src/com/songoda/epicbosses/utils/Message.java index c35eb92..1a1c8c2 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/utils/Message.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/utils/Message.java @@ -28,6 +28,8 @@ public enum Message { Boss_AutoSpawn_NotCompleteEnough("&c&l(!) &cThe auto spawn is not set up enough to be enabled. Please make sure it has: &fA Spawn Entity(s) and Type&c before you try and enable the auto spawn."), Boss_AutoSpawn_SpawnRate("&b&lEpicBosses &8» &7You have {0} the spawn rate of the auto spawn to &f{1}&7."), Boss_AutoSpawn_InvalidLocation("&c&l(!) &cThe specified location string, &f{0}&c, is invalid. A correct example should be &fworld,10,150,-30&c . If you want to cancel the location update type &f- &cand you will be brought back to the settings menu."), + Boss_AutoSpawn_SetLocation("&b&lEpicBosses &8» &7Your next input in to chat will be the location for the auto spawn. If you enter &f-&7 it will cancel the updating of the location. Use the format &fworld,10,150,-30&7."), + Boss_AutoSpawn_SetPlaceholder("&b&lEpicBosses &8» &7Your next input in to chat will be the placeholder for the auto spawn. If you enter &f-&7 it will cancel the updating of the location."), Boss_Create_EntityTypeNotFound("&c&l(!) &cThe specified entity type {0} was not found. If you think this is an error please contact &fAMinecraftDev&c."), Boss_Create_InvalidArgs("&c&l(!) &cYou must use &n/boss create [name] [entity] &c to create a boss."), diff --git a/pom.xml b/pom.xml index 009a97f..89b7755 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ - 1.0.0-U185 + 1.0.0-U186 EpicBosses com.songoda.epicbosses.CustomBosses AMinecraftDev