1.0.0-SNAPSHOT-U49

+ More small tweaks
+ Added boss giveEgg cmd
+ Completed BossInfo cmd
+ Completed BossKillAll cmd
+ Completed BossList cmd
+ begun working on boss nearby cmd
+ Improved some other methods of how the plugin works
+ Fixed bugs with loading and killing the boss
This commit is contained in:
AMinecraftDev 2018-11-14 22:23:42 +08:00
parent 945f55a81d
commit 7130f9acd3
21 changed files with 307 additions and 25 deletions

View File

@ -1,6 +1,7 @@
Settings:
debug: false
bossTargetRange: 50.0
defaultNearbyRadius: 250.0
BlockedWorlds:
enabled: false

View File

@ -0,0 +1,9 @@
package com.songoda.epicbosses.commands.boss;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 14-Nov-18
*/
public class BossGiveEggCmd {
}

View File

@ -34,8 +34,9 @@ public class BossHelpCmd extends SubCommand {
case 2:
Message.Boss_Help_Page2.msg(sender);
break;
case 3:
Message.Boss_Help_Page3.msg(sender);
break;
}
return;
}
}

View File

@ -1,5 +1,10 @@
package com.songoda.epicbosses.commands.boss;
import com.songoda.epicbosses.entity.BossEntity;
import com.songoda.epicbosses.managers.BossEntityManager;
import com.songoda.epicbosses.managers.files.BossesFileManager;
import com.songoda.epicbosses.utils.Message;
import com.songoda.epicbosses.utils.Permission;
import com.songoda.epicbosses.utils.command.SubCommand;
import org.bukkit.command.CommandSender;
@ -7,17 +12,43 @@ import org.bukkit.command.CommandSender;
* @author Charles Cullen
* @version 1.0.0
* @since 02-Oct-18
*
* TODO
*/
public class BossInfoCmd extends SubCommand {
public BossInfoCmd() {
private BossEntityManager bossEntityManager;
private BossesFileManager bossesFileManager;
public BossInfoCmd(BossesFileManager bossesFileManager, BossEntityManager bossEntityManager) {
super("info");
this.bossesFileManager = bossesFileManager;
this.bossEntityManager = bossEntityManager;
}
@Override
public void execute(CommandSender sender, String[] args) {
if(!Permission.admin.hasPermission(sender)) {
Message.Boss_Info_NoPermission.msg(sender);
return;
}
if(args.length != 2) {
Message.Boss_Info_InvalidArgs.msg(sender);
return;
}
String input = args[1];
BossEntity bossEntity = this.bossesFileManager.getBossEntity(input);
if(bossEntity == null) {
Message.Boss_Info_CouldntFindBoss.msg(sender);
return;
}
boolean editing = bossEntity.isEditing();
int active = this.bossEntityManager.getCurrentlyActive(bossEntity);
boolean complete = bossEntity.isCompleteEnoughToSpawn();
Message.Boss_Info_Display.msg(sender, input, editing, active, complete);
}
}

View File

@ -1,23 +1,51 @@
package com.songoda.epicbosses.commands.boss;
import com.songoda.epicbosses.managers.BossEntityManager;
import com.songoda.epicbosses.utils.Message;
import com.songoda.epicbosses.utils.Permission;
import com.songoda.epicbosses.utils.command.SubCommand;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 02-Oct-18
*
* TODO
*/
public class BossKillAllCmd extends SubCommand {
public BossKillAllCmd() {
private BossEntityManager bossEntityManager;
public BossKillAllCmd(BossEntityManager bossEntityManager) {
super("killall");
this.bossEntityManager = bossEntityManager;
}
@Override
public void execute(CommandSender sender, String[] args) {
if(!Permission.admin.hasPermission(sender)) {
Message.Boss_KillAll_NoPermission.msg(sender);
return;
}
World world = null;
if(args.length == 2) {
String worldArgs = args[1];
world = Bukkit.getWorld(worldArgs);
if(world == null) {
Message.Boss_KillAll_WorldNotFound.msg(sender);
return;
}
}
int amount = this.bossEntityManager.killAllHolders(world);
if(args.length == 2) Message.Boss_KillAll_KilledWorld.msg(sender, amount, world.getName());
else Message.Boss_KillAll_KilledAll.msg(sender, amount);
}
}

View File

@ -1,23 +1,41 @@
package com.songoda.epicbosses.commands.boss;
import com.songoda.epicbosses.managers.BossPanelManager;
import com.songoda.epicbosses.utils.Message;
import com.songoda.epicbosses.utils.Permission;
import com.songoda.epicbosses.utils.command.SubCommand;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 02-Oct-18
*
* TODO
*/
public class BossListCmd extends SubCommand {
public BossListCmd() {
private BossPanelManager bossPanelManager;
public BossListCmd(BossPanelManager bossPanelManager) {
super("list", "show");
this.bossPanelManager = bossPanelManager;
}
@Override
public void execute(CommandSender sender, String[] args) {
if(!Permission.admin.hasPermission(sender)) {
Message.Boss_List_NoPermission.msg(sender);
return;
}
if(!(sender instanceof Player)) {
Message.General_MustBePlayer.msg(sender);
return;
}
Player player = (Player) sender;
this.bossPanelManager.getBosses().openFor(player);
}
}

View File

@ -1,23 +1,57 @@
package com.songoda.epicbosses.commands.boss;
import com.songoda.epicbosses.CustomBosses;
import com.songoda.epicbosses.file.ConfigFileHandler;
import com.songoda.epicbosses.holder.ActiveBossHolder;
import com.songoda.epicbosses.utils.Message;
import com.songoda.epicbosses.utils.NumberUtils;
import com.songoda.epicbosses.utils.Permission;
import com.songoda.epicbosses.utils.command.SubCommand;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 02-Oct-18
*
* TODO
*/
public class BossNearbyCmd extends SubCommand {
public BossNearbyCmd() {
private CustomBosses plugin;
public BossNearbyCmd(CustomBosses plugin) {
super("nearby");
this.plugin = plugin;
}
@Override
public void execute(CommandSender sender, String[] args) {
if(!Permission.nearby.hasPermission(sender)) {
Message.Boss_Nearby_NoPermission.msg(sender);
return;
}
if(!(sender instanceof Player)) {
Message.General_MustBePlayer.msg(sender);
return;
}
Player player = (Player) sender;
Location location = player.getLocation();
double radius = this.plugin.getConfig().getDouble("Settings.defaultNearbyRadius", 250.0);
if(args.length == 2) {
Integer newNumber = NumberUtils.get().getInteger(args[1]);
if(newNumber != null) radius = newNumber;
}
List<ActiveBossHolder> nearbyBosses = this.plugin.getBossEntityManager().getActiveBossHoldersWithinRadius(radius, location);
//TODO Finish
}
}

View File

@ -33,4 +33,20 @@ public class BossEntity {
this.messages = messages;
this.commands = commands;
}
public boolean isCompleteEnoughToSpawn() {
boolean complete = true;
if(this.entityStats == null) return false;
EntityStatsElement entityStatsElement = this.entityStats.get(0);
if(entityStatsElement == null) return false;
MainStatsElement mainStatsElement = entityStatsElement.getMainStats();
if(mainStatsElement == null) return false;
return mainStatsElement.getPosition() != null && mainStatsElement.getEntityType() != null && mainStatsElement.getHealth() != null;
}
}

View File

@ -6,6 +6,7 @@ import com.songoda.epicbosses.targeting.TargetHandler;
import com.songoda.epicbosses.entity.BossEntity;
import com.songoda.epicbosses.exception.AlreadySetException;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.LivingEntity;
import java.util.*;
@ -49,7 +50,41 @@ public class ActiveBossHolder {
return null;
}
public LivingEntity getMinionEntity() {
for(LivingEntity livingEntity : getMinionEntityMap().values()) {
if(livingEntity != null) return livingEntity;
}
return null;
}
public boolean hasAttacked(UUID uuid) {
return this.mapOfDamagingUsers.containsKey(uuid);
}
public void killAllMinions() {
this.minionEntityMap.values().forEach(LivingEntity::remove);
this.minionEntityMap.clear();
}
public void killAllMinions(World world) {
LivingEntity livingEntity = getMinionEntity();
if(livingEntity == null) return;
if(world != null && !livingEntity.getWorld().equals(world)) return;
this.minionEntityMap.values().forEach(LivingEntity::remove);
this.minionEntityMap.clear();
}
public boolean killAllSubBosses(World world) {
LivingEntity livingEntity = getLivingEntity();
if(livingEntity == null) return false;
if(world != null && !livingEntity.getWorld().equals(world)) return false;
this.livingEntityMap.values().forEach(LivingEntity::remove);
this.livingEntityMap.clear();
return true;
}
}

View File

@ -31,7 +31,6 @@ public class BossDeathListener implements Listener {
private BossEntityManager bossEntityManager;
public BossDeathListener(CustomBosses plugin) {
this.bossEntityManager = plugin.getBossEntityManager();
}
@ -66,6 +65,7 @@ public class BossDeathListener implements Listener {
PreBossDeathEvent preBossDeathEvent = new PreBossDeathEvent(activeBossHolder, location);
activeBossHolder.setDead(true);
activeBossHolder.killAllMinions();
ServerUtils.get().callEvent(preBossDeathEvent);
}
}

View File

@ -36,6 +36,8 @@ public class BossDamageListener implements Listener {
double damage = event.getDamage();
Player player = null;
System.out.println(livingEntity.getActivePotionEffects());
if(activeBossHolder == null) return;
if(entityDamaging instanceof Player) {

View File

@ -36,7 +36,7 @@ public class BossCommandManager implements ILoadable {
this.commandService.registerSubCommand(new BossHelpCmd());
this.commandService.registerSubCommand(new BossInfoCmd());
this.commandService.registerSubCommand(new BossItemsCmd(this.customBosses.getBossPanelManager()));
this.commandService.registerSubCommand(new BossKillAllCmd());
this.commandService.registerSubCommand(new BossKillAllCmd(this.customBosses.getBossEntityManager()));
this.commandService.registerSubCommand(new BossListCmd());
this.commandService.registerSubCommand(new BossMenuCmd(this.customBosses.getBossPanelManager()));
this.commandService.registerSubCommand(new BossNearbyCmd());

View File

@ -21,6 +21,7 @@ import com.songoda.epicbosses.utils.Debug;
import com.songoda.epicbosses.utils.RandomUtils;
import com.songoda.epicbosses.utils.itemstack.holder.ItemStackHolder;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.ItemStack;
@ -56,6 +57,60 @@ public class BossEntityManager {
this.bossesFileManager = customBosses.getBossesFileManager();
}
public double getRadius(ActiveBossHolder activeBossHolder, Location centerLocation) {
if(activeBossHolder.isDead()) return Double.MAX_VALUE;
LivingEntity livingEntity = activeBossHolder.getLivingEntity();
if(livingEntity == null) return Double.MAX_VALUE;
Location location = livingEntity.getLocation();
return centerLocation.distance(location);
}
public List<ActiveBossHolder> getActiveBossHoldersWithinRadius(double radius, Location centerLocation) {
List<ActiveBossHolder> activeBossHolders = new ArrayList<>();
getActiveBossHolders().forEach(activeBossHolder -> {
double distance = getRadius(activeBossHolder, centerLocation);
if(distance > radius) return;
activeBossHolders.add(activeBossHolder);
});
return activeBossHolders;
}
public int getCurrentlyActive(BossEntity bossEntity) {
int amountOfBosses = 0;
for(ActiveBossHolder activeBossHolder : getActiveBossHolders()) {
if(activeBossHolder.getBossEntity().equals(bossEntity)) {
amountOfBosses++;
}
}
return amountOfBosses;
}
public int killAllHolders(World world) {
int amountOfBosses = 0;
for(ActiveBossHolder activeBossHolder : getActiveBossHolders()) {
if(activeBossHolder.killAllSubBosses(world)) {
activeBossHolder.killAllMinions(world);
activeBossHolder.setDead(true);
amountOfBosses++;
ACTIVE_BOSS_HOLDERS.remove(activeBossHolder);
}
}
return amountOfBosses;
}
//TODO: Add default item if spawnItem is not set.
public ItemStack getSpawnItem(BossEntity bossEntity) {
if(bossEntity == null) return null;
@ -216,7 +271,7 @@ public class BossEntityManager {
}
public ActiveBossHolder getActiveBossHolder(LivingEntity livingEntity) {
List<ActiveBossHolder> currentList = new ArrayList<>(ACTIVE_BOSS_HOLDERS);
List<ActiveBossHolder> currentList = getActiveBossHolders();
for(ActiveBossHolder activeBossHolder : currentList) {
for(Map.Entry<Integer, LivingEntity> entry : activeBossHolder.getLivingEntityMap().entrySet()) {
@ -338,4 +393,8 @@ public class BossEntityManager {
});
}
private List<ActiveBossHolder> getActiveBossHolders() {
return new ArrayList<>(ACTIVE_BOSS_HOLDERS);
}
}

View File

@ -80,6 +80,9 @@ public class BossMechanicManager implements IMechanicManager<BossEntity, ActiveB
IMechanic<BossEntity> mechanic = queue.poll();
if(mechanic == null) continue;
ServerUtils.get().logDebug("Applying " + mechanic.getClass().getSimpleName());
if(didMechanicApplicationFail(mechanic, bossEntity, activeBossHolder)) continue;
}
}

View File

@ -10,6 +10,7 @@ import com.songoda.epicbosses.utils.mechanics.IOptionalMechanic;
import com.songoda.epicbosses.utils.potion.PotionEffectConverter;
import com.songoda.epicbosses.utils.potion.holder.PotionEffectHolder;
import org.bukkit.entity.LivingEntity;
import org.bukkit.potion.PotionEffect;
import java.util.List;
@ -38,7 +39,15 @@ public class PotionMechanic implements IOptionalMechanic<BossEntity> {
if(livingEntity == null) return false;
if(potionElements != null && !potionElements.isEmpty()) {
potionElements.forEach(potionElement -> livingEntity.addPotionEffect(this.potionEffectConverter.from(potionElement)));
potionElements.forEach(potionElement -> {
PotionEffect potionEffect = this.potionEffectConverter.from(potionElement);
System.out.println(potionEffect);
System.out.println(potionEffect.getAmplifier());
System.out.println(potionEffect.getDuration());
System.out.println(livingEntity);
livingEntity.addPotionEffect(potionEffect);
});
}
}

View File

@ -33,6 +33,7 @@ public class EntityTypeMechanic implements IPrimaryMechanic<MinionEntity> {
LivingEntity livingEntity = entityFinder.spawnNewLivingEntity(bossEntityType, activeBossHolder.getLivingEntity().getLocation());
if(livingEntity == null) return false;
if(!activeBossHolder.getMinionEntityMap().isEmpty()) activeBossHolder.killAllMinions(null);
activeBossHolder.getMinionEntityMap().put(position, livingEntity);

View File

@ -28,7 +28,7 @@ public abstract class TargetHandler implements ITarget {
}
public void runTargetCycle() {
ServerUtils.get().runLaterAsync(100L, () -> {
ServerUtils.get().runLaterAsync(10L, () -> {
updateTarget();
if(!getActiveBossHolder().isDead()) runTargetCycle();

View File

@ -26,10 +26,10 @@ public enum Message {
Boss_Create_NoEntitySpecified("&c&l(!) &cNo entity type was specified. Make sure to add an entity type! Possible entity types are: \n&7{0}"),
Boss_Create_NoPermission("&c&l(!) &cYou do not have access to this command."),
Boss_Create_SomethingWentWrong("&c&l(!) &cSomething went wrong in the API class while finalising the boss creation."),
Boss_Create_SuccessfullyCreated("&e&lCustomBosses &8» &7A boss has successfully been created with the name &f{0}&7 and the entity type &f{1}&7."),
Boss_Create_SuccessfullyCreated("&e&lEpicBosses &8» &7A boss has successfully been created with the name &f{0}&7 and the entity type &f{1}&7."),
Boss_Debug_NoPermission("&c&l(!) &cYou do not have access to this command."),
Boss_Debug_Toggled("&e&lCustomBosses &8» &7You have toggled debug mode for &fCustomBosses &7to {0}."),
Boss_Debug_Toggled("&e&lEpicBosses &8» &7You have toggled debug mode for &fEpicBosses &7to {0}."),
Boss_DropTable_NoPermission("&c&l(!) &cYou do not have access to this command."),
@ -45,6 +45,7 @@ public enum Message {
"&e/boss info [name] &8» &7Shows information on the specified boss.\n" +
"&e/boss nearby (radius) &8» &7Shows the nearby bosses.\n" +
"&e/boss reload &8» &7Reloads the boss plugin.\n" +
"&e/boss killall (world) &8» &7Kills all bosses/minions." +
"&7\n" +
"&7Use /boss help 2 to view the next page.\n" +
"&8&m----*-----------------------------------*----"),
@ -58,13 +59,41 @@ public enum Message {
"&e/boss skills &8» &7Shows all current set skills.\n" +
"&7\n" +
"&8&m----*-----------------------------------*----"),
Boss_Help_Page3(
"&8&m----*--------&6&l[ &e&lBoss Help &7(Page 3) &6&l]&8&m--------*----\n" +
"&e/boss debug &8» &7Used to toggle the debug aspect of the plugin.\n" +
"&e/boss giveegg [name] [name] &8» &7Used to be given a spawn item of the boss.\n" +
"&e/boss list &8» &7Shows all the list of current boss entities.\n" +
"&e/boss nearby (radius) &8» &7Shows all nearby bosses.\n" +
"&e\n" +
"&e\n" +
"&7\n" +
"&8&m----*-----------------------------------*----"),
Boss_Info_NoPermission("&c&l(!) &cYou do not have access to this command."),
Boss_Info_InvalidArgs("&c&l(!) &cYou must use &n/boss info [name]&c to view info on a boss."),
Boss_Info_CouldntFindBoss("&c&l(!) &cThe specified boss was not able to be retrieved, please try again."),
Boss_Info_Display(
"&8&m----*--------&6&l[ &e&l{0} Info &6&l]&8&m--------*----\n" +
"&6&lEditing: &f{1}\n" +
"&6&lCurrently Active: &f{2}\n" +
"&6&lComplete enough to spawn: &f{3}"),
Boss_Items_NoPermission("&c&l(!) &cYou do not have access to this command."),
Boss_KillAll_WorldNotFound("&c&l(!) &cThe specified world was not found. If you'd like to kill every boss/minion just use &f/boss killall&c without any arguments."),
Boss_KillAll_KilledAll("&e&lEpicBosses &8» &7You have killed {0} boss(es) and minions that were currently active on the server."),
Boss_KillAll_KilledWorld("&e&lEpicBosses &8» &7You have killed {0} boss(es) and minions that were in the world {1}."),
Boss_KillAll_NoPermission("&c&l(!) &cYou do not have access to this command."),
Boss_List_NoPermission("&c&l(!) &cYou do not have access to this command."),
Boss_Menu_NoPermission("&c&l(!) &cYou do not have access to this command."),
Boss_Nearby_NoPermission("&c&l(!) &cYou do not have access to this command."),
Boss_Reload_NoPermission("&c&l(!) &cYou do not have access to this command."),
Boss_Reload_Successful("&e&lCustomBosses &8» &7All boss data has been reloaded. The process took &f{0}ms&7."),
Boss_Reload_Successful("&e&lEpicBosses &8» &7All boss data has been reloaded. The process took &f{0}ms&7."),
Boss_Skills_NoPermission("&c&l(!) &cYou do not have access to this command.");

View File

@ -13,7 +13,8 @@ public enum Permission {
admin("boss.admin"),
create("boss.create"),
debug("boss.debug"),
reload("boss.reload");
reload("boss.reload"),
nearby("boss.nearby");
@Getter private String permission;

View File

@ -35,8 +35,13 @@ public class PotionEffectConverter implements IConverter<PotionEffectHolder, Pot
Integer level = potionHolder.getLevel();
PotionEffectType potionEffectTypeConverted = this.potionEffectTypeConverter.from(potionEffectType);
if(duration == null) duration = 5;
if(level == null) level = 1;
if(duration < 1) duration = (Integer.MAX_VALUE / 20);
if(potionEffectTypeConverted == null) return null;
if(potionEffectType != null && duration != null && level != null) return new PotionEffect(potionEffectTypeConverted, level-1, (duration*20));
if(potionEffectType != null) return new PotionEffect(potionEffectTypeConverted, level-1, (duration*20));
return null;
}

View File

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