mirror of
https://github.com/songoda/EpicBosses.git
synced 2024-06-26 06:35:03 +02:00
1.0.0-SNAPSHOT-U54
+ Added BossSpawn command
This commit is contained in:
parent
208871c719
commit
1996b87482
|
@ -4,6 +4,8 @@ import com.songoda.epicbosses.CustomBosses;
|
|||
import com.songoda.epicbosses.entity.BossEntity;
|
||||
import com.songoda.epicbosses.entity.MinionEntity;
|
||||
import com.songoda.epicbosses.entity.elements.*;
|
||||
import com.songoda.epicbosses.events.PreBossSpawnEvent;
|
||||
import com.songoda.epicbosses.events.PreBossSpawnItemEvent;
|
||||
import com.songoda.epicbosses.holder.ActiveBossHolder;
|
||||
import com.songoda.epicbosses.managers.files.CommandsFileManager;
|
||||
import com.songoda.epicbosses.managers.files.ItemsFileManager;
|
||||
|
@ -12,9 +14,12 @@ import com.songoda.epicbosses.skills.custom.Minions;
|
|||
import com.songoda.epicbosses.skills.types.CustomSkill;
|
||||
import com.songoda.epicbosses.utils.Debug;
|
||||
import com.songoda.epicbosses.utils.EntityFinder;
|
||||
import com.songoda.epicbosses.utils.ServerUtils;
|
||||
import com.songoda.epicbosses.utils.itemstack.holder.ItemStackHolder;
|
||||
import com.songoda.epicbosses.utils.panel.Panel;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -258,9 +263,11 @@ public class BossAPI {
|
|||
*
|
||||
* @param bossEntity - targetted BossEntity
|
||||
* @param location - Location to spawn the boss.
|
||||
* @param player - Player who spawned the boss.
|
||||
* @param itemStack - The itemstack used to spawn the boss.
|
||||
* @return ActiveBossHolder class with stored information
|
||||
*/
|
||||
public static ActiveBossHolder spawnNewBoss(BossEntity bossEntity, Location location) {
|
||||
public static ActiveBossHolder spawnNewBoss(BossEntity bossEntity, Location location, Player player, ItemStack itemStack) {
|
||||
// if(bossEntity.isEditing()) {
|
||||
// Debug.ATTEMPTED_TO_SPAWN_WHILE_DISABLED.debug();
|
||||
// return null;
|
||||
|
@ -268,7 +275,25 @@ public class BossAPI {
|
|||
|
||||
String name = PLUGIN.getBossEntityContainer().getName(bossEntity);
|
||||
|
||||
return PLUGIN.getBossEntityManager().createActiveBossHolder(bossEntity, location, name);
|
||||
ActiveBossHolder activeBossHolder = PLUGIN.getBossEntityManager().createActiveBossHolder(bossEntity, location, name);
|
||||
|
||||
if(activeBossHolder == null) {
|
||||
Debug.FAILED_TO_CREATE_ACTIVE_BOSS_HOLDER.debug();
|
||||
return null;
|
||||
}
|
||||
|
||||
PreBossSpawnEvent preBossSpawnEvent;
|
||||
|
||||
if(player != null && itemStack != null) {
|
||||
preBossSpawnEvent = new PreBossSpawnItemEvent(activeBossHolder, player, itemStack);
|
||||
} else {
|
||||
preBossSpawnEvent = new PreBossSpawnEvent(activeBossHolder);
|
||||
}
|
||||
|
||||
PLUGIN.getBossTargetManager().initializeTargetHandler(activeBossHolder);
|
||||
ServerUtils.get().callEvent(preBossSpawnEvent);
|
||||
|
||||
return activeBossHolder;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,23 +1,72 @@
|
|||
package com.songoda.epicbosses.commands.boss;
|
||||
|
||||
import com.songoda.epicbosses.api.BossAPI;
|
||||
import com.songoda.epicbosses.entity.BossEntity;
|
||||
import com.songoda.epicbosses.managers.files.BossesFileManager;
|
||||
import com.songoda.epicbosses.utils.Message;
|
||||
import com.songoda.epicbosses.utils.Permission;
|
||||
import com.songoda.epicbosses.utils.StringUtils;
|
||||
import com.songoda.epicbosses.utils.command.SubCommand;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 02-Oct-18
|
||||
*
|
||||
* TODO
|
||||
*/
|
||||
public class BossSpawnCmd extends SubCommand {
|
||||
|
||||
public BossSpawnCmd() {
|
||||
private BossesFileManager bossesFileManager;
|
||||
|
||||
public BossSpawnCmd(BossesFileManager bossesFileManager) {
|
||||
super("spawn");
|
||||
|
||||
this.bossesFileManager = bossesFileManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!Permission.admin.hasPermission(sender)) {
|
||||
Message.Boss_Spawn_NoPermission.msg(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if(args.length < 2) {
|
||||
Message.Boss_Spawn_InvalidArgs.msg(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
Location spawnLocation;
|
||||
|
||||
if(args.length == 3) {
|
||||
Location input = StringUtils.get().fromStringToLocation(args[2]);
|
||||
|
||||
if(input == null) {
|
||||
Message.Boss_Spawn_InvalidLocation.msg(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
spawnLocation = input;
|
||||
} else {
|
||||
if(!(sender instanceof Player)) {
|
||||
Message.Boss_Spawn_MustBePlayer.msg(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
spawnLocation = ((Player) sender).getLocation();
|
||||
}
|
||||
|
||||
String bossInput = args[1];
|
||||
BossEntity bossEntity = this.bossesFileManager.getBossEntity(bossInput);
|
||||
|
||||
if(bossEntity == null) {
|
||||
Message.Boss_Spawn_InvalidBoss.msg(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
BossAPI.spawnNewBoss(bossEntity, spawnLocation, null, null);
|
||||
Message.Boss_Spawn_Spawned.msg(sender, bossInput, StringUtils.get().translateLocation(spawnLocation));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,29 +1,23 @@
|
|||
package com.songoda.epicbosses.events;
|
||||
|
||||
import lombok.Getter;
|
||||
import com.songoda.epicbosses.holder.ActiveBossHolder;
|
||||
import org.bukkit.entity.Player;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 16-Oct-18
|
||||
* @since 17-Nov-18
|
||||
*/
|
||||
public class PreBossSpawnEvent extends Event {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
@Getter private ActiveBossHolder activeBossHolder;
|
||||
@Getter private ItemStack itemStackUsed;
|
||||
@Getter private Player player;
|
||||
|
||||
public PreBossSpawnEvent(ActiveBossHolder activeBossHolder, Player player, ItemStack itemStackUsed) {
|
||||
public PreBossSpawnEvent(ActiveBossHolder activeBossHolder) {
|
||||
this.activeBossHolder = activeBossHolder;
|
||||
this.itemStackUsed = itemStackUsed;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package com.songoda.epicbosses.events;
|
||||
|
||||
import lombok.Getter;
|
||||
import com.songoda.epicbosses.holder.ActiveBossHolder;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 16-Oct-18
|
||||
*/
|
||||
public class PreBossSpawnItemEvent extends PreBossSpawnEvent {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
@Getter private ItemStack itemStackUsed;
|
||||
@Getter private Player player;
|
||||
|
||||
public PreBossSpawnItemEvent(ActiveBossHolder activeBossHolder, Player player, ItemStack itemStackUsed) {
|
||||
super(activeBossHolder);
|
||||
|
||||
this.itemStackUsed = itemStackUsed;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ import com.songoda.epicbosses.container.BossEntityContainer;
|
|||
import com.songoda.epicbosses.entity.BossEntity;
|
||||
import com.songoda.epicbosses.events.BossSpawnEvent;
|
||||
import com.songoda.epicbosses.events.PreBossSpawnEvent;
|
||||
import com.songoda.epicbosses.events.PreBossSpawnItemEvent;
|
||||
import com.songoda.epicbosses.holder.ActiveBossHolder;
|
||||
import com.songoda.epicbosses.managers.BossEntityManager;
|
||||
import com.songoda.epicbosses.managers.BossLocationManager;
|
||||
|
@ -94,18 +95,11 @@ public class BossSpawnListener implements Listener {
|
|||
|
||||
event.setCancelled(true);
|
||||
|
||||
ActiveBossHolder activeBossHolder = BossAPI.spawnNewBoss(bossEntity, location);
|
||||
ActiveBossHolder activeBossHolder = BossAPI.spawnNewBoss(bossEntity, location, player, itemStack);
|
||||
|
||||
if(activeBossHolder == null) {
|
||||
Debug.FAILED_TO_CREATE_ACTIVE_BOSS_HOLDER.debug();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
PreBossSpawnEvent preBossSpawnEvent = new PreBossSpawnEvent(activeBossHolder, player, itemStack);
|
||||
|
||||
this.bossTargetManager.initializeTargetHandler(activeBossHolder);
|
||||
ServerUtils.get().callEvent(preBossSpawnEvent);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -113,12 +107,16 @@ public class BossSpawnListener implements Listener {
|
|||
ActiveBossHolder activeBossHolder = event.getActiveBossHolder();
|
||||
BossEntity bossEntity = activeBossHolder.getBossEntity();
|
||||
Location location = activeBossHolder.getLocation();
|
||||
ItemStack itemStack = event.getItemStackUsed().clone();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
itemStack.setAmount(1);
|
||||
player.getInventory().removeItem(itemStack);
|
||||
player.updateInventory();
|
||||
if(event instanceof PreBossSpawnItemEvent) {
|
||||
PreBossSpawnItemEvent preBossSpawnItemEvent = (PreBossSpawnItemEvent) event;
|
||||
ItemStack itemStack = preBossSpawnItemEvent.getItemStackUsed().clone();
|
||||
Player player = preBossSpawnItemEvent.getPlayer();
|
||||
|
||||
itemStack.setAmount(1);
|
||||
player.getInventory().removeItem(itemStack);
|
||||
player.updateInventory();
|
||||
}
|
||||
|
||||
List<String> commands = this.bossEntityManager.getOnSpawnCommands(bossEntity);
|
||||
List<String> messages = this.bossEntityManager.getOnSpawnMessage(bossEntity);
|
||||
|
|
|
@ -44,7 +44,7 @@ public class BossCommandManager implements ILoadable {
|
|||
this.commandService.registerSubCommand(new BossReloadCmd(this.customBosses, this.customBosses.getBossEntityManager()));
|
||||
this.commandService.registerSubCommand(new BossShopCmd(this.customBosses));
|
||||
this.commandService.registerSubCommand(new BossSkillsCmd(this.customBosses.getBossPanelManager()));
|
||||
this.commandService.registerSubCommand(new BossSpawnCmd());
|
||||
this.commandService.registerSubCommand(new BossSpawnCmd(this.customBosses.getBossesFileManager()));
|
||||
this.commandService.registerSubCommand(new BossTimeCmd());
|
||||
|
||||
this.hasBeenLoaded = true;
|
||||
|
|
|
@ -72,9 +72,9 @@ public enum Debug {
|
|||
|
||||
String finalMsg = message;
|
||||
|
||||
// if(PLUGIN.isDebug()) {
|
||||
if(PLUGIN.isDebug()) {
|
||||
ServerUtils.get().logDebug(finalMsg);
|
||||
// }
|
||||
}
|
||||
|
||||
PLUGIN.getDebugManager().getToggledPlayers().forEach(uuid -> {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
|
|
|
@ -112,7 +112,14 @@ public enum Message {
|
|||
Boss_Shop_NotEnoughBalance("&c&l(!) &cYou do not have enough money to make this purchase! You need &a$&f{0}&c more."),
|
||||
Boss_Shop_Purchased("&b&lEpicBosses &8» &7You have purchased &f1x {0}&7."),
|
||||
|
||||
Boss_Skills_NoPermission("&c&l(!) &cYou do not have access to this command.");
|
||||
Boss_Skills_NoPermission("&c&l(!) &cYou do not have access to this command."),
|
||||
|
||||
Boss_Spawn_NoPermission("&c&l(!) &cYou do not have access to this command."),
|
||||
Boss_Spawn_InvalidArgs("&c&l(!) &cYou must use &n/boss spawn [name] (location)&c to spawn a boss."),
|
||||
Boss_Spawn_InvalidLocation("&c&l(!) &cThe location string you have entered is not a valid location string. A valid location string should look like this: &fworld,100,65,100"),
|
||||
Boss_Spawn_MustBePlayer("&c&l(!) &cTo use this command without an input of location you must be a player."),
|
||||
Boss_Spawn_InvalidBoss("&c&l(!) &cThe specified boss is not a valid type."),
|
||||
Boss_Spawn_Spawned("&c&l(!) &cYou have spawned a {0} boss at {1}.");
|
||||
|
||||
private static FileConfiguration LANG;
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package com.songoda.epicbosses.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
@ -37,6 +39,24 @@ public class StringUtils {
|
|||
.replace("{z}", ""+z);
|
||||
}
|
||||
|
||||
public Location fromStringToLocation(String input) {
|
||||
String[] split = input.split(",");
|
||||
|
||||
if(split.length != 4) return null;
|
||||
|
||||
String worldInput = split[0];
|
||||
String xInput = split[1];
|
||||
String yInput = split[2];
|
||||
String zInput = split[3];
|
||||
World world = Bukkit.getWorld(worldInput);
|
||||
|
||||
if(NumberUtils.get().isInt(xInput) && NumberUtils.get().isInt(yInput) && NumberUtils.get().isInt(zInput)) {
|
||||
return new Location(world, Integer.valueOf(xInput), Integer.valueOf(yInput), Integer.valueOf(zInput));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public <T> String appendList(List<T> list) {
|
||||
Queue<T> queue = new LinkedList<>(list);
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -19,7 +19,7 @@
|
|||
</modules>
|
||||
|
||||
<properties>
|
||||
<plugin.version>1.0.0-SNAPSHOT-U53</plugin.version>
|
||||
<plugin.version>1.0.0-SNAPSHOT-U54</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