mirror of
https://github.com/songoda/EpicBosses.git
synced 2025-01-21 22:31:21 +01:00
Spawner/Killer replacements in onDeath messages/commands
This commit is contained in:
parent
7f4a1ad4de
commit
5f80888524
@ -4,7 +4,7 @@ stages:
|
||||
variables:
|
||||
name: "EpicBosses"
|
||||
path: "/builds/$CI_PROJECT_PATH"
|
||||
version: "1.1.0"
|
||||
version: "1.1.1"
|
||||
|
||||
build:
|
||||
stage: build
|
||||
|
@ -476,7 +476,7 @@ public class BossAPI {
|
||||
|
||||
String name = PLUGIN.getBossEntityContainer().getName(bossEntity);
|
||||
|
||||
ActiveBossHolder activeBossHolder = PLUGIN.getBossEntityManager().createActiveBossHolder(bossEntity, location, name);
|
||||
ActiveBossHolder activeBossHolder = PLUGIN.getBossEntityManager().createActiveBossHolder(bossEntity, location, name, player);
|
||||
|
||||
if(activeBossHolder == null) {
|
||||
Debug.FAILED_TO_CREATE_ACTIVE_BOSS_HOLDER.debug();
|
||||
|
@ -3,6 +3,7 @@ package com.songoda.epicbosses.events;
|
||||
import lombok.Getter;
|
||||
import com.songoda.epicbosses.holder.ActiveBossHolder;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
@ -17,10 +18,12 @@ public class PreBossDeathEvent extends Event {
|
||||
|
||||
@Getter private ActiveBossHolder activeBossHolder;
|
||||
@Getter private Location location;
|
||||
@Getter private Player killer;
|
||||
|
||||
public PreBossDeathEvent(ActiveBossHolder activeBossHolder, Location location) {
|
||||
public PreBossDeathEvent(ActiveBossHolder activeBossHolder, Location location, Player killer) {
|
||||
this.activeBossHolder = activeBossHolder;
|
||||
this.location = location;
|
||||
this.killer = killer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -12,6 +12,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -30,14 +31,19 @@ public class ActiveBossHolder implements IActiveHolder {
|
||||
@Getter private Map<Integer, UUID> livingEntityMap = new HashMap<>();
|
||||
@Getter private List<IBossDeathHandler> postBossDeathHandlers = new ArrayList<>();
|
||||
@Getter private Map<UUID, Double> mapOfDamagingUsers = new HashMap<>();
|
||||
@Getter private String spawningPlayerName;
|
||||
|
||||
@Getter @Setter private TargetHandler<ActiveBossHolder> targetHandler = null;
|
||||
@Getter @Setter private boolean isDead = false, customSpawnMessage = false;
|
||||
|
||||
public ActiveBossHolder(BossEntity bossEntity, Location spawnLocation, String name) {
|
||||
public ActiveBossHolder(BossEntity bossEntity, Location spawnLocation, String name, Player spawningPlayer) {
|
||||
this.location = spawnLocation;
|
||||
this.bossEntity = bossEntity;
|
||||
this.name = name;
|
||||
|
||||
if (spawningPlayer != null) {
|
||||
this.spawningPlayerName = spawningPlayer.getName();
|
||||
}
|
||||
}
|
||||
|
||||
public void setLivingEntity(int position, LivingEntity livingEntity) {
|
||||
|
@ -16,6 +16,7 @@ import com.songoda.epicbosses.utils.ServerUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
@ -63,7 +64,7 @@ public class BossDeathListener implements Listener {
|
||||
|
||||
|
||||
if(this.bossEntityManager.isAllEntitiesDead(activeBossHolder)) {
|
||||
PreBossDeathEvent preBossDeathEvent = new PreBossDeathEvent(activeBossHolder, location);
|
||||
PreBossDeathEvent preBossDeathEvent = new PreBossDeathEvent(activeBossHolder, location, event.getEntity().getKiller());
|
||||
|
||||
activeBossHolder.setDead(true);
|
||||
activeBossHolder.killAllMinions();
|
||||
@ -86,6 +87,8 @@ public class BossDeathListener implements Listener {
|
||||
ServerUtils serverUtils = ServerUtils.get();
|
||||
|
||||
if(commands != null) {
|
||||
if (activeBossHolder.getSpawningPlayerName() != null) commands.replaceAll(s -> s.replace("{spawner}", activeBossHolder.getSpawningPlayerName()));
|
||||
if (event.getKiller() != null) commands.replaceAll(s -> s.replace("{killer}", event.getKiller().getName()));
|
||||
commands.forEach(serverUtils::sendConsoleCommand);
|
||||
}
|
||||
|
||||
@ -123,6 +126,8 @@ public class BossDeathListener implements Listener {
|
||||
}
|
||||
|
||||
if(activeBossHolder.getName() != null) messages.replaceAll(s -> s.replace("{boss}", activeBossHolder.getName()));
|
||||
if (activeBossHolder.getSpawningPlayerName() != null) messages.replaceAll(s -> s.replace("{spawner}", activeBossHolder.getSpawningPlayerName()));
|
||||
if (event.getKiller() != null) messages.replaceAll(s -> s.replace("{killer}", event.getKiller().getName()));
|
||||
|
||||
messages.replaceAll(s -> s.replace('&', '§'));
|
||||
|
||||
|
@ -87,7 +87,7 @@ public class BossSpawnListener implements Listener {
|
||||
location.add(0,1,0);
|
||||
}
|
||||
|
||||
if(!this.bossLocationManager.canSpawnBoss(player, location)) {
|
||||
if(!this.bossLocationManager.canSpawnBoss(player, location.clone())) {
|
||||
Message.General_CannotSpawn.msg(player);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
|
@ -29,6 +29,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@ -269,8 +270,8 @@ public class BossEntityManager {
|
||||
return newMap;
|
||||
}
|
||||
|
||||
public ActiveBossHolder createActiveBossHolder(BossEntity bossEntity, Location spawnLocation, String name) {
|
||||
ActiveBossHolder activeBossHolder = new ActiveBossHolder(bossEntity, spawnLocation, name);
|
||||
public ActiveBossHolder createActiveBossHolder(BossEntity bossEntity, Location spawnLocation, String name, Player spawningPlayer) {
|
||||
ActiveBossHolder activeBossHolder = new ActiveBossHolder(bossEntity, spawnLocation, name, spawningPlayer);
|
||||
|
||||
this.bossMechanicManager.handleMechanicApplication(bossEntity, activeBossHolder);
|
||||
|
||||
|
@ -5,6 +5,7 @@ import com.songoda.epicbosses.entity.elements.EntityStatsElement;
|
||||
import com.songoda.epicbosses.entity.elements.MainStatsElement;
|
||||
import com.songoda.epicbosses.holder.ActiveBossHolder;
|
||||
import com.songoda.epicbosses.mechanics.IBossMechanic;
|
||||
import com.songoda.epicbosses.utils.ServerUtils;
|
||||
import com.songoda.epicbosses.utils.potion.PotionEffectConverter;
|
||||
import com.songoda.epicbosses.utils.potion.holder.PotionEffectHolder;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
@ -39,6 +40,11 @@ public class PotionMechanic implements IBossMechanic {
|
||||
if(potionElements != null && !potionElements.isEmpty()) {
|
||||
potionElements.forEach(potionElement -> {
|
||||
PotionEffect potionEffect = this.potionEffectConverter.from(potionElement);
|
||||
if (potionEffect == null) {
|
||||
ServerUtils.get().logDebug("Failed to apply potion effect to boss: " +
|
||||
"[type=" + potionElement.getType() + ",duration=" + potionElement.getDuration() + ",level=" + potionElement.getLevel() + "]");
|
||||
return;
|
||||
}
|
||||
|
||||
livingEntity.addPotionEffect(potionEffect);
|
||||
});
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.songoda.epicbosses.utils.itemstack;
|
||||
|
||||
import com.songoda.epicbosses.utils.NumberUtils;
|
||||
import com.songoda.epicbosses.utils.ServerUtils;
|
||||
import com.songoda.epicbosses.utils.StringUtils;
|
||||
//import com.songoda.epicbosses.utils.factory.NbtFactory;
|
||||
import com.songoda.epicbosses.utils.itemstack.enchants.GlowEnchant;
|
||||
@ -117,6 +118,11 @@ public class ItemStackUtils {
|
||||
for(String x : replacedMap.keySet()) {
|
||||
if(!y.contains(x)) continue;
|
||||
|
||||
if (!replacedMap.containsKey(x)) {
|
||||
ServerUtils.get().logDebug("Failed to apply replaced lore: [y=" + y + "x=" + x + "]");
|
||||
continue;
|
||||
}
|
||||
|
||||
y = y.replace(x, replacedMap.get(x));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user