PlaceholderAPI support for interval autospawn timers
This commit is contained in:
parent
25734f5415
commit
32181ed01a
|
@ -3,5 +3,4 @@ main: ${plugin.main}
|
|||
version: ${plugin.version}
|
||||
author: ${plugin.author}
|
||||
api-version: 1.13
|
||||
#TODO: softdepend:
|
||||
#TODO: depends:
|
||||
softdepend: [PlaceholderAPI] # TODO: Add other softdepends
|
|
@ -54,6 +54,7 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
|
|||
@Getter private BossHookManager bossHookManager;
|
||||
|
||||
@Getter private AutoSpawnManager autoSpawnManager;
|
||||
@Getter private PlaceholderManager placeholderManager;
|
||||
|
||||
@Getter private MinionMechanicManager minionMechanicManager;
|
||||
@Getter private MinionEntityContainer minionEntityContainer;
|
||||
|
@ -129,6 +130,11 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
|
|||
|
||||
this.autoSpawnManager = new AutoSpawnManager(this);
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
this.placeholderManager = new PlaceholderManager(this);
|
||||
this.placeholderManager.register();
|
||||
}
|
||||
|
||||
createFiles();
|
||||
reloadFiles();
|
||||
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
package com.songoda.epicbosses.managers;
|
||||
|
||||
import com.songoda.epicbosses.CustomBosses;
|
||||
import com.songoda.epicbosses.holder.ActiveAutoSpawnHolder;
|
||||
import com.songoda.epicbosses.holder.autospawn.ActiveIntervalAutoSpawnHolder;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
public class PlaceholderManager extends PlaceholderExpansion {
|
||||
|
||||
private AutoSpawnManager autoSpawnManager;
|
||||
|
||||
public PlaceholderManager(CustomBosses plugin) {
|
||||
this.autoSpawnManager = plugin.getAutoSpawnManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onRequest(OfflinePlayer player, String identifier) {
|
||||
for (String autoSpawnName : this.autoSpawnManager.getIntervalAutoSpawns()) {
|
||||
ActiveAutoSpawnHolder autoSpawnHolder = this.autoSpawnManager.getActiveAutoSpawnHolder(autoSpawnName);
|
||||
if (!(autoSpawnHolder instanceof ActiveIntervalAutoSpawnHolder))
|
||||
continue;
|
||||
|
||||
ActiveIntervalAutoSpawnHolder intervalAutoSpawnHolder = (ActiveIntervalAutoSpawnHolder) autoSpawnHolder;
|
||||
long duration = (long) (intervalAutoSpawnHolder.getRemainingMs() / 1000D);
|
||||
|
||||
String formattedIdentifier = intervalAutoSpawnHolder.getIntervalSpawnElement().getPlaceholder() + "_formatted";
|
||||
if (identifier.equalsIgnoreCase(formattedIdentifier)) {
|
||||
return this.getTimeFormatted(duration);
|
||||
} else if (identifier.equals(intervalAutoSpawnHolder.getIntervalSpawnElement().getPlaceholder())) {
|
||||
return String.valueOf((int) (intervalAutoSpawnHolder.getRemainingMs() / 1000D));
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getTimeFormatted(long timeInSeconds) {
|
||||
long hours = (long) Math.floor(timeInSeconds / 60D / 60D);
|
||||
long minutes = (long) Math.floor(timeInSeconds / 60D) % 60;
|
||||
long seconds = timeInSeconds % 60;
|
||||
String formatted = "";
|
||||
|
||||
if (hours > 0)
|
||||
formatted += hours + "h ";
|
||||
|
||||
if (minutes > 0 || hours > 0)
|
||||
formatted += minutes + "m ";
|
||||
|
||||
return formatted + seconds + "s";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "epicbosses";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Songoda";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return CustomBosses.get().getDescription().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean persist() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -30,7 +30,7 @@ public enum Message {
|
|||
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_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 placeholder."),
|
||||
|
||||
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."),
|
||||
|
|
Loading…
Reference in New Issue