mirror of
https://github.com/songoda/EpicBosses.git
synced 2025-03-12 22:49:13 +01:00
1.0.0-SNAPSHOT-U41
+ Finished how a Potion, Command and CustomSkill is handled. + Updated RandomUtils with a method that makes it easier for anything that is based on chance + Updated ServerUtils to have a dispatchCommand through console to make sending commands one single lambda expression + Added some debug messages for the skills
This commit is contained in:
parent
dad1bdfcd0
commit
29b9138ec2
@ -41,6 +41,7 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
|
||||
@Getter private BossEntityManager bossEntityManager;
|
||||
@Getter private BossTargetManager bossTargetManager;
|
||||
@Getter private BossPanelManager bossPanelManager;
|
||||
@Getter private BossSkillManager bossSkillManager;
|
||||
@Getter private BossTauntManager bossTauntManager;
|
||||
@Getter private BossHookManager bossHookManager;
|
||||
@Getter private VersionHandler versionHandler;
|
||||
@ -62,11 +63,12 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
|
||||
|
||||
this.debugManager = new DebugManager();
|
||||
this.versionHandler = new VersionHandler();
|
||||
this.bossSkillManager = new BossSkillManager();
|
||||
this.bossHookManager = new BossHookManager(this);
|
||||
this.bossTauntManager = new BossTauntManager(this);
|
||||
this.bossTargetManager = new BossTargetManager(this);
|
||||
this.bossEntityContainer = new BossEntityContainer();
|
||||
this.bossMechanicManager = new BossMechanicManager(this);
|
||||
this.bossHookManager = new BossHookManager(this);
|
||||
this.bossLocationManager = new BossLocationManager(this);
|
||||
this.bossDropTableManager = new BossDropTableManager(this);
|
||||
|
||||
|
@ -7,6 +7,7 @@ import com.songoda.epicbosses.holder.ActiveBossHolder;
|
||||
import com.songoda.epicbosses.managers.files.CommandsFileManager;
|
||||
import com.songoda.epicbosses.managers.files.ItemsFileManager;
|
||||
import com.songoda.epicbosses.managers.files.MessagesFileManager;
|
||||
import com.songoda.epicbosses.skills.types.CustomSkill;
|
||||
import com.songoda.epicbosses.utils.Debug;
|
||||
import com.songoda.epicbosses.utils.EntityFinder;
|
||||
import com.songoda.epicbosses.utils.itemstack.holder.ItemStackHolder;
|
||||
@ -65,6 +66,35 @@ public class BossAPI {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to register skills into the
|
||||
* system so that when a boss uses a
|
||||
* skill it will be recognised with
|
||||
* custom coding. All skills will be
|
||||
* instantly detected once registered
|
||||
* with this method.
|
||||
*
|
||||
* @param customSkill - The custom skill you are registering
|
||||
* @return boolean if the registration succeeded or failed
|
||||
*/
|
||||
public static boolean registerCustomSkill(CustomSkill customSkill) {
|
||||
return PLUGIN.getBossSkillManager().registerSkill(customSkill);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to unregister one of the
|
||||
* custom skills that are in the
|
||||
* system. You do not need to unregister
|
||||
* any external skills onDisable of the
|
||||
* server as it will have no impact on
|
||||
* the way it closes.
|
||||
*
|
||||
* @param customSkill - The custom skill you are trying to remove
|
||||
*/
|
||||
public static void removeCustomSkill(CustomSkill customSkill) {
|
||||
PLUGIN.getBossSkillManager().removeSkill(customSkill);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the Boss configuration section name
|
||||
* from a BossEntity instance.
|
||||
|
@ -73,9 +73,10 @@ public class BossDeathListener implements Listener {
|
||||
List<String> messages = this.bossEntityManager.getOnDeathMessage(bossEntity);
|
||||
int messageRadius = this.bossEntityManager.getOnDeathMessageRadius(bossEntity);
|
||||
int onlyShow = this.bossEntityManager.getOnDeathShowAmount(bossEntity);
|
||||
ServerUtils serverUtils = ServerUtils.get();
|
||||
|
||||
if(commands != null) {
|
||||
commands.forEach(command -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command));
|
||||
commands.forEach(serverUtils::sendConsoleCommand);
|
||||
}
|
||||
|
||||
ServerUtils.get().runTaskAsync(() -> {
|
||||
|
@ -123,9 +123,10 @@ public class BossSpawnListener implements Listener {
|
||||
List<String> commands = this.bossEntityManager.getOnSpawnCommands(bossEntity);
|
||||
List<String> messages = this.bossEntityManager.getOnSpawnMessage(bossEntity);
|
||||
int messageRadius = this.bossEntityManager.getOnSpawnMessageRadius(bossEntity);
|
||||
ServerUtils serverUtils = ServerUtils.get();
|
||||
|
||||
if(commands != null) {
|
||||
commands.forEach(command -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command));
|
||||
commands.forEach(serverUtils::sendConsoleCommand);
|
||||
}
|
||||
if(messages != null) {
|
||||
if(activeBossHolder.getName() != null) messages.replaceAll(s -> s.replace("{boss}", activeBossHolder.getName()));
|
||||
|
@ -14,6 +14,7 @@ import com.songoda.epicbosses.managers.files.ItemsFileManager;
|
||||
import com.songoda.epicbosses.utils.Debug;
|
||||
import com.songoda.epicbosses.utils.NumberUtils;
|
||||
import com.songoda.epicbosses.utils.RandomUtils;
|
||||
import com.songoda.epicbosses.utils.ServerUtils;
|
||||
import com.songoda.epicbosses.utils.itemstack.holder.ItemStackHolder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@ -64,6 +65,7 @@ public class BossDropTableManager {
|
||||
Map<UUID, Double> mapOfDamage = deadBossHolder.getSortedDamageMap();
|
||||
Map<UUID, Double> percentMap = deadBossHolder.getPercentageMap();
|
||||
List<UUID> positions = new ArrayList<>(mapOfDamage.keySet());
|
||||
ServerUtils serverUtils = ServerUtils.get();
|
||||
|
||||
rewards.forEach((positionString, lootMap) -> {
|
||||
if(!NumberUtils.get().isInt(positionString)) {
|
||||
@ -101,8 +103,8 @@ public class BossDropTableManager {
|
||||
});
|
||||
|
||||
totalCommands.replaceAll(s -> s.replace("%player%", player.getName()));
|
||||
totalCommands.forEach(serverUtils::sendConsoleCommand);
|
||||
|
||||
totalCommands.forEach(s -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), s));
|
||||
totalRewards.forEach(itemStack -> {
|
||||
if(player.getInventory().firstEmpty() == -1) {
|
||||
player.getWorld().dropItemNaturally(player.getLocation(), itemStack);
|
||||
@ -125,9 +127,8 @@ public class BossDropTableManager {
|
||||
|
||||
for(String itemName : keyList) {
|
||||
Double chance = chanceMap.get(itemName);
|
||||
double randomNumber = RandomUtils.get().getRandomDecimalNumber();
|
||||
|
||||
if(randomNumber > chance) continue;
|
||||
if(!RandomUtils.get().canPreformAction(chance)) continue;
|
||||
if((max > 0) && (newListToMerge.size() >= max)) break;
|
||||
|
||||
ItemStack itemStack = this.getDropTableItemStack.getListItem(itemName);
|
||||
@ -154,9 +155,8 @@ public class BossDropTableManager {
|
||||
|
||||
for(String itemName : keyList) {
|
||||
Double chance = chanceMap.get(itemName);
|
||||
double randomNumber = RandomUtils.get().getRandomDecimalNumber();
|
||||
|
||||
if(randomNumber > chance) continue;
|
||||
if(!RandomUtils.get().canPreformAction(chance)) continue;
|
||||
if((max > 0) && (newListToMerge.size() >= max)) break;
|
||||
|
||||
List<String> commands = this.getDropTableCommand.getListItem(itemName);
|
||||
|
@ -1,9 +1,30 @@
|
||||
package com.songoda.epicbosses.managers;
|
||||
|
||||
import com.songoda.epicbosses.skills.Skill;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 05-Nov-18
|
||||
*/
|
||||
public class BossSkillManager {
|
||||
|
||||
private static final Set<Skill> SKILLS = new HashSet<>();
|
||||
|
||||
public boolean registerSkill(Skill skill) {
|
||||
if(SKILLS.contains(skill)) return false;
|
||||
|
||||
SKILLS.add(skill);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void removeSkill(Skill skill) {
|
||||
if(!SKILLS.contains(skill)) return;
|
||||
|
||||
SKILLS.remove(skill);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
package com.songoda.epicbosses.skills;
|
||||
|
||||
import com.songoda.epicbosses.holder.ActiveBossHolder;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
@ -9,6 +12,6 @@ import com.songoda.epicbosses.holder.ActiveBossHolder;
|
||||
*/
|
||||
public interface ISkillHandler {
|
||||
|
||||
void castSkill(ActiveBossHolder activeBossHolder);
|
||||
void castSkill(ActiveBossHolder activeBossHolder, List<LivingEntity> nearbyEntities);
|
||||
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import lombok.Setter;
|
||||
* @version 1.0.0
|
||||
* @since 05-Nov-18
|
||||
*/
|
||||
public class Skill {
|
||||
public abstract class Skill implements ISkillHandler {
|
||||
|
||||
@Expose @Getter @Setter private String mode, type, displayName, customMessage;
|
||||
@Expose @Getter @Setter private Double radius;
|
||||
|
@ -0,0 +1,9 @@
|
||||
package com.songoda.epicbosses.skills.custom;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 06-Nov-18
|
||||
*/
|
||||
public class Cage {
|
||||
}
|
@ -1,10 +1,15 @@
|
||||
package com.songoda.epicbosses.skills.types;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.songoda.epicbosses.holder.ActiveBossHolder;
|
||||
import com.songoda.epicbosses.skills.Skill;
|
||||
import com.songoda.epicbosses.skills.elements.CommandSkillElement;
|
||||
import com.songoda.epicbosses.utils.Debug;
|
||||
import com.songoda.epicbosses.utils.RandomUtils;
|
||||
import com.songoda.epicbosses.utils.ServerUtils;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -17,4 +22,28 @@ public class CommandSkill extends Skill {
|
||||
|
||||
@Expose @Getter @Setter private List<CommandSkillElement> commands;
|
||||
|
||||
@Override
|
||||
public void castSkill(ActiveBossHolder activeBossHolder, List<LivingEntity> nearbyEntities) {
|
||||
List<CommandSkillElement> commandSkillElements = getCommands();
|
||||
ServerUtils serverUtils = ServerUtils.get();
|
||||
|
||||
if(commandSkillElements.isEmpty()) {
|
||||
Debug.SKILL_COMMANDS_ARE_EMPTY.debug(getDisplayName());
|
||||
return;
|
||||
}
|
||||
|
||||
nearbyEntities.forEach(livingEntity ->
|
||||
commandSkillElements.forEach(commandSkillElement -> {
|
||||
Double chance = commandSkillElement.getChance();
|
||||
List<String> commands = commandSkillElement.getCommands();
|
||||
|
||||
if(commands == null || commands.isEmpty()) return;
|
||||
if(chance == null) chance = 100.0;
|
||||
if(!RandomUtils.get().canPreformAction(chance)) return;
|
||||
|
||||
commands.replaceAll(s -> s.replace("%player%", livingEntity.getName()));
|
||||
commands.forEach(serverUtils::sendConsoleCommand);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import lombok.Setter;
|
||||
* @version 1.0.0
|
||||
* @since 05-Nov-18
|
||||
*/
|
||||
public class CustomSkill extends Skill {
|
||||
public abstract class CustomSkill extends Skill {
|
||||
|
||||
@Expose @Getter @Setter private CustomSkillElement custom;
|
||||
|
||||
|
@ -1,8 +1,11 @@
|
||||
package com.songoda.epicbosses.skills.types;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.songoda.epicbosses.holder.ActiveBossHolder;
|
||||
import com.songoda.epicbosses.skills.Skill;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -11,8 +14,12 @@ import java.util.List;
|
||||
* @version 1.0.0
|
||||
* @since 05-Nov-18
|
||||
*/
|
||||
public class GroupSkill {
|
||||
public class GroupSkill extends Skill {
|
||||
|
||||
@Expose @Getter @Setter private List<String> groupedSkills;
|
||||
|
||||
@Override
|
||||
public void castSkill(ActiveBossHolder activeBossHolder, List<LivingEntity> nearbyEntities) {
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,14 @@
|
||||
package com.songoda.epicbosses.skills.types;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.songoda.epicbosses.holder.ActiveBossHolder;
|
||||
import com.songoda.epicbosses.skills.Skill;
|
||||
import com.songoda.epicbosses.utils.Debug;
|
||||
import com.songoda.epicbosses.utils.potion.PotionEffectConverter;
|
||||
import com.songoda.epicbosses.utils.potion.holder.PotionEffectHolder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -17,4 +21,22 @@ public class PotionSkill extends Skill {
|
||||
|
||||
@Expose @Getter @Setter private List<PotionEffectHolder> potions;
|
||||
|
||||
private final PotionEffectConverter potionEffectConverter;
|
||||
|
||||
public PotionSkill() {
|
||||
this.potionEffectConverter = new PotionEffectConverter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void castSkill(ActiveBossHolder activeBossHolder, List<LivingEntity> nearbyEntities) {
|
||||
List<PotionEffectHolder> potionElements = getPotions();
|
||||
|
||||
if(potionElements == null) return;
|
||||
if(potionElements.isEmpty()) {
|
||||
Debug.SKILL_POTIONS_ARE_EMPTY.debug(getDisplayName());
|
||||
return;
|
||||
}
|
||||
|
||||
nearbyEntities.forEach(livingEntity -> potionElements.forEach(potionElement -> livingEntity.addPotionEffect(this.potionEffectConverter.from(potionElement))));
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,10 @@ public enum Debug {
|
||||
DROP_TABLE_FAILED_INVALID_NUMBER("The specified position ({0}) on the drop table is not a valid number."),
|
||||
DROP_TABLE_FAILED_TO_GET_ITEM("The drop table failed to get the specific item for the list."),
|
||||
|
||||
MECHANIC_TYPE_NOT_STORED("This mechanic type is not stored, therefore will not be applied. Valid mechanic types are IOptionalMechanic and IPrimaryMechanic.");
|
||||
MECHANIC_TYPE_NOT_STORED("This mechanic type is not stored, therefore will not be applied. Valid mechanic types are IOptionalMechanic and IPrimaryMechanic."),
|
||||
|
||||
SKILL_COMMANDS_ARE_EMPTY("The commands list for the skill {0} is empty."),
|
||||
SKILL_POTIONS_ARE_EMPTY("The potions list for the skill {0} is empty.");
|
||||
|
||||
private static CustomBosses PLUGIN;
|
||||
|
||||
|
@ -35,6 +35,12 @@ public class RandomUtils {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public boolean canPreformAction(double chanceOfSuccess) {
|
||||
double randomChance = getRandomDecimalNumber();
|
||||
|
||||
return (randomChance <= chanceOfSuccess);
|
||||
}
|
||||
|
||||
public static RandomUtils get() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
@ -77,6 +77,10 @@ public class ServerUtils {
|
||||
Bukkit.getPluginManager().registerEvents(listener, this.javaPlugin);
|
||||
}
|
||||
|
||||
public void sendConsoleCommand(String command) {
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||
}
|
||||
|
||||
public static ServerUtils get() {
|
||||
return serverUtils;
|
||||
}
|
||||
|
2
pom.xml
2
pom.xml
@ -19,7 +19,7 @@
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<plugin.version>1.0.0-SNAPSHOT-U40</plugin.version>
|
||||
<plugin.version>1.0.0-SNAPSHOT-U41</plugin.version>
|
||||
<plugin.name>EpicBosses</plugin.name>
|
||||
<plugin.main>com.songoda.epicbosses.CustomBosses</plugin.main>
|
||||
<plugin.author>AMinecraftDev</plugin.author>
|
||||
|
Loading…
Reference in New Issue
Block a user