3.0.0-SNAPSHOT-U27

+ Worked on BossEntityManager
+ Added BossHookManager to handle the Utilities
+ Added BossListenerManager to handle all listeners
+ Added BossLocationManager to handle all location related things
+ Added modified BossMechanicManager to be more understandable
+ Worked on BossSpawn listeners and events
+ Worked the hook system
+ Added more detail to the config
This commit is contained in:
AMinecraftDev 2018-10-16 21:57:18 +08:00
parent 69fdd57d6f
commit f284ae0df1
30 changed files with 789 additions and 26 deletions

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: com.wasteofplastic:askyblock:3.0.8.3">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/wasteofplastic/askyblock/3.0.8.3/askyblock-3.0.8.3.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/wasteofplastic/askyblock/3.0.8.3/askyblock-3.0.8.3-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/wasteofplastic/askyblock/3.0.8.3/askyblock-3.0.8.3-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -32,6 +32,7 @@
<orderEntry type="library" scope="PROVIDED" name="Maven: de.schlichtherle:truezip:6.8.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: rhino:js:1.7R2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:10.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.wasteofplastic:askyblock:3.0.8.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.16.22" level="project" />
<orderEntry type="library" name="Maven: org.bstats:bstats-bukkit:1.2" level="project" />
</component>

View File

@ -31,6 +31,7 @@
<orderEntry type="library" scope="PROVIDED" name="Maven: de.schlichtherle:truezip:6.8.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: rhino:js:1.7R2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:10.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.wasteofplastic:askyblock:3.0.8.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.16.22" level="project" />
<orderEntry type="library" name="Maven: org.bstats:bstats-bukkit:1.2" level="project" />
</component>

View File

@ -31,6 +31,7 @@
<orderEntry type="library" scope="PROVIDED" name="Maven: de.schlichtherle:truezip:6.8.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: rhino:js:1.7R2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:10.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.wasteofplastic:askyblock:3.0.8.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.16.22" level="project" />
<orderEntry type="library" name="Maven: org.bstats:bstats-bukkit:1.2" level="project" />
</component>

View File

@ -31,6 +31,7 @@
<orderEntry type="library" scope="PROVIDED" name="Maven: de.schlichtherle:truezip:6.8.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: rhino:js:1.7R2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:10.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.wasteofplastic:askyblock:3.0.8.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.16.22" level="project" />
<orderEntry type="library" name="Maven: org.bstats:bstats-bukkit:1.2" level="project" />
</component>

View File

@ -29,6 +29,7 @@
<orderEntry type="library" scope="PROVIDED" name="Maven: de.schlichtherle:truezip:6.8.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: rhino:js:1.7R2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:10.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.wasteofplastic:askyblock:3.0.8.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.16.22" level="project" />
<orderEntry type="library" name="Maven: org.bstats:bstats-bukkit:1.2" level="project" />
</component>

View File

@ -37,6 +37,7 @@
<orderEntry type="library" scope="PROVIDED" name="Maven: de.schlichtherle:truezip:6.8.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: rhino:js:1.7R2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:10.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.wasteofplastic:askyblock:3.0.8.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.16.22" level="project" />
<orderEntry type="library" name="Maven: org.bstats:bstats-bukkit:1.2" level="project" />
</component>

View File

@ -1,11 +1,31 @@
Settings:
debug: false
BlockedWorlds:
enabled: false
worlds:
- 'world_the_end'
- 'world_nether'
Toggles:
endermanTeleporting: true
potionsAffectingBoss: true
Hooks:
ASkyBlock: false
Factions: false
StackMob: false
WorldEdit: true
WorldGuard: true
ASkyBlock:
enabled: false
onOwnIsland: false
Factions:
enabled: false
useWarzoneSpawnRegion: false
StackMob:
enabled: false
WorldGuard:
enabled: true
spawnRegions:
- 'spawn_region1'
- 'spawn_region2'
blockedRegions:
- 'blocked_region1'
- 'blocked_region2'
Display:
Bosses:
name: '&e&l{name}'

View File

@ -8,11 +8,8 @@ import net.aminecraftdev.custombosses.file.BossesFileHandler;
import net.aminecraftdev.custombosses.file.ConfigFileHandler;
import net.aminecraftdev.custombosses.file.EditorFileHandler;
import net.aminecraftdev.custombosses.file.LangFileHandler;
import net.aminecraftdev.custombosses.managers.BossCommandManager;
import net.aminecraftdev.custombosses.managers.BossPanelManager;
import net.aminecraftdev.custombosses.managers.DebugManager;
import net.aminecraftdev.custombosses.managers.*;
import net.aminecraftdev.custombosses.managers.files.BossItemFileManager;
import net.aminecraftdev.custombosses.managers.BossMechanicManager;
import net.aminecraftdev.custombosses.managers.files.BossesFileManager;
import net.aminecraftdev.custombosses.utils.Debug;
import net.aminecraftdev.custombosses.utils.IReloadable;
@ -34,10 +31,14 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
@Getter private BossEntityContainer bossEntityContainer;
@Getter private BossMechanicManager bossMechanicManager;
@Getter private BossLocationManager bossLocationManager;
@Getter private BossListenerManager bossListenerManager;
@Getter private BossCommandManager bossCommandManager;
@Getter private BossItemFileManager itemStackManager;
@Getter private BossEntityManager bossEntityManager;
@Getter private BossesFileManager bossesFileManager;
@Getter private BossPanelManager bossPanelManager;
@Getter private BossHookManager bossHookManager;
@Getter private VersionHandler versionHandler;
@Getter private DebugManager debugManager;
@ -59,6 +60,9 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
this.versionHandler = new VersionHandler();
this.bossEntityContainer = new BossEntityContainer();
this.bossMechanicManager = new BossMechanicManager(this);
this.bossEntityManager = new BossEntityManager(this);
this.bossHookManager = new BossHookManager(this);
this.bossLocationManager = new BossLocationManager(this);
loadFileManagersAndHandlers();
@ -70,9 +74,12 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
this.itemStackManager.reload();
this.bossesFileManager.reload();
this.bossCommandManager = new BossCommandManager(new BossCmd(), this);
this.bossListenerManager = new BossListenerManager(this);
this.bossPanelManager.load();
//RELOAD/LOAD ALL MANAGERS
this.bossHookManager.reload();
this.bossLocationManager.reload();
this.itemStackManager.reload();
this.bossesFileManager.reload();
this.bossMechanicManager.load();
@ -80,6 +87,7 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
saveMessagesToFile();
this.bossCommandManager.load();
this.bossListenerManager.load();
ServerUtils.get().logDebug("Loaded all fields and managers, saved messages and plugin is initialized and ready to go. (took " + (System.currentTimeMillis() - beginMs) + "ms).");
}
@ -93,6 +101,8 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
reloadFiles();
this.bossPanelManager.reload();
this.bossHookManager.reload();
this.bossLocationManager.reload();
this.debug = getConfig().getBoolean("Settings.debug", false);
Message.setFile(getLang());

View File

@ -3,12 +3,14 @@ package net.aminecraftdev.custombosses.api;
import net.aminecraftdev.custombosses.CustomBosses;
import net.aminecraftdev.custombosses.entity.BossEntity;
import net.aminecraftdev.custombosses.entity.elements.*;
import net.aminecraftdev.custombosses.holder.ActiveBossHolder;
import net.aminecraftdev.custombosses.managers.files.BossItemFileManager;
import net.aminecraftdev.custombosses.utils.Debug;
import net.aminecraftdev.custombosses.utils.EntityFinder;
import net.aminecraftdev.custombosses.utils.itemstack.holder.ItemStackHolder;
import net.aminecraftdev.custombosses.utils.panel.Panel;
import net.aminecraftdev.custombosses.utils.potion.holder.PotionEffectHolder;
import org.bukkit.Location;
import java.util.ArrayList;
import java.util.Arrays;
@ -129,6 +131,23 @@ public class BossAPI {
return bossEntity;
}
/**
* Used to spawn a new active boss for the
* specified bossEntity.
*
* @param bossEntity - targetted BossEntity
* @param location - Location to spawn the boss.
* @return ActiveBossHolder class with stored information
*/
public static ActiveBossHolder spawnNewBoss(BossEntity bossEntity, Location location) {
if(bossEntity.isEditing()) {
Debug.ATTEMPTED_TO_SPAWN_WHILE_DISABLED.debug();
return null;
}
return PLUGIN.getBossEntityManager().createActiveBossHolder(bossEntity, location);
}
/**
* Used to obtain an item stack holder
* of the specified item stack from the

View File

@ -0,0 +1,31 @@
package net.aminecraftdev.custombosses.events;
import lombok.Getter;
import net.aminecraftdev.custombosses.holder.ActiveBossHolder;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 16-Oct-18
*/
public class BossSpawnEvent extends Event {
private static final HandlerList handlers = new HandlerList();
@Getter private ActiveBossHolder activeBossHolder;
public BossSpawnEvent(ActiveBossHolder activeBossHolder) {
this.activeBossHolder = activeBossHolder;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -0,0 +1,37 @@
package net.aminecraftdev.custombosses.events;
import lombok.Getter;
import net.aminecraftdev.custombosses.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 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) {
this.activeBossHolder = activeBossHolder;
this.itemStackUsed = itemStackUsed;
this.player = player;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -1,7 +1,18 @@
package net.aminecraftdev.custombosses.listeners.pre;
import net.aminecraftdev.custombosses.CustomBosses;
import net.aminecraftdev.custombosses.api.BossAPI;
import net.aminecraftdev.custombosses.entity.BossEntity;
import net.aminecraftdev.custombosses.events.BossSpawnEvent;
import net.aminecraftdev.custombosses.events.PreBossSpawnEvent;
import net.aminecraftdev.custombosses.holder.ActiveBossHolder;
import net.aminecraftdev.custombosses.managers.BossEntityManager;
import net.aminecraftdev.custombosses.managers.BossLocationManager;
import net.aminecraftdev.custombosses.utils.Message;
import net.aminecraftdev.custombosses.utils.ServerUtils;
import net.aminecraftdev.custombosses.utils.itemstack.ItemStackUtils;
import net.aminecraftdev.custombosses.utils.version.VersionHandler;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@ -12,6 +23,8 @@ import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import java.util.Map;
/**
* @author Charles Cullen
* @version 1.0.0
@ -19,16 +32,21 @@ import org.bukkit.inventory.ItemStack;
*/
public class BossSpawnListener implements Listener {
private BossLocationManager bossLocationManager;
private BossEntityManager bossEntityManager;
private VersionHandler versionHandler;
public BossSpawnListener(CustomBosses customBosses) {
this.versionHandler = customBosses.getVersionHandler();
this.bossEntityManager = customBosses.getBossEntityManager();
this.bossLocationManager = customBosses.getBossLocationManager();
}
@EventHandler
public void onInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
Block block = event.getClickedBlock();
Location location = block.getLocation().clone();
BlockFace blockFace = event.getBlockFace();
Action action = event.getAction();
@ -36,9 +54,59 @@ public class BossSpawnListener implements Listener {
if(action != Action.RIGHT_CLICK_BLOCK) return;
if(block.getType() == Material.AIR) return;
ItemStack itemStack = this.versionHandler.getItemInHand(player);
Map<BossEntity, ItemStack> entitiesAndSpawnItems = this.bossEntityManager.getMapOfEntitiesAndSpawnItems();
ItemStack itemStack = this.versionHandler.getItemInHand(player).clone();
BossEntity bossEntity = null;
for(Map.Entry<BossEntity, ItemStack> entry : entitiesAndSpawnItems.entrySet()) {
if(ItemStackUtils.isItemStackSame(itemStack, entry.getValue())) {
bossEntity = entry.getKey();
break;
}
}
if(bossEntity == null) return;
if(bossEntity.isEditing()) {
Message.Boss_Edit_CannotSpawn.msg(player);
return;
}
if(blockFace == BlockFace.UP) {
location.add(0,1,0);
}
if(!this.bossLocationManager.canSpawnBoss(player, location)) {
Message.General_CannotSpawn.msg(player);
event.setCancelled(true);
return;
}
event.setCancelled(true);
ActiveBossHolder activeBossHolder = BossAPI.spawnNewBoss(bossEntity, location);
//TODO: Set TargetHandler to the boss
PreBossSpawnEvent preBossSpawnEvent = new PreBossSpawnEvent(activeBossHolder, player, itemStack);
ServerUtils.get().callEvent(preBossSpawnEvent);
}
@EventHandler
public void onPreBossSpawnEvent(PreBossSpawnEvent event) {
ActiveBossHolder activeBossHolder = event.getActiveBossHolder();
ItemStack itemStack = event.getItemStackUsed().clone();
Player player = event.getPlayer();
itemStack.setAmount(1);
player.getInventory().removeItem(itemStack);
player.updateInventory();
//TODO: Create AutoTarget for TargetHandler
//TODO: Handle onSpawn commands, and messages
BossSpawnEvent bossSpawnEvent = new BossSpawnEvent(activeBossHolder);
}
}

View File

@ -0,0 +1,77 @@
package net.aminecraftdev.custombosses.managers;
import net.aminecraftdev.custombosses.CustomBosses;
import net.aminecraftdev.custombosses.api.BossAPI;
import net.aminecraftdev.custombosses.entity.BossEntity;
import net.aminecraftdev.custombosses.holder.ActiveBossHolder;
import net.aminecraftdev.custombosses.managers.files.BossItemFileManager;
import net.aminecraftdev.custombosses.managers.files.BossesFileManager;
import net.aminecraftdev.custombosses.utils.Debug;
import net.aminecraftdev.custombosses.utils.itemstack.holder.ItemStackHolder;
import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 16-Oct-18
*/
public class BossEntityManager {
private static final List<ActiveBossHolder> ACTIVE_BOSS_HOLDERS = new ArrayList<>();
private BossItemFileManager bossItemFileManager;
private BossMechanicManager bossMechanicManager;
private BossesFileManager bossesFileManager;
public BossEntityManager(CustomBosses customBosses) {
this.bossMechanicManager = customBosses.getBossMechanicManager();
this.bossItemFileManager = customBosses.getItemStackManager();
this.bossesFileManager = customBosses.getBossesFileManager();
}
public ItemStack getSpawnItem(BossEntity bossEntity) {
ItemStackHolder itemStackHolder = BossAPI.getStoredItemStack(bossEntity.getSpawnItem());
if(itemStackHolder == null) {
Debug.FAILED_TO_LOAD_CUSTOM_ITEM.debug(bossEntity.getSpawnItem());
return null;
}
ItemStack itemStack = this.bossItemFileManager.getItemStackConverter().from(itemStackHolder);
if(itemStack == null) {
Debug.FAILED_TO_LOAD_CUSTOM_ITEM.debug(bossEntity.getSpawnItem());
return null;
}
return itemStack;
}
public Map<BossEntity, ItemStack> getMapOfEntitiesAndSpawnItems() {
Map<String, BossEntity> currentEntities = new HashMap<>(this.bossesFileManager.getBossEntities());
Map<BossEntity, ItemStack> newMap = new HashMap<>();
currentEntities.forEach((name, bossEntity) -> newMap.put(bossEntity, getSpawnItem(bossEntity)));
return newMap;
}
public ActiveBossHolder createActiveBossHolder(BossEntity bossEntity, Location spawnLocation) {
ActiveBossHolder activeBossHolder = new ActiveBossHolder(bossEntity, spawnLocation);
if(!this.bossMechanicManager.handleMechanicApplication(bossEntity, activeBossHolder)) {
Debug.FAILED_TO_CREATE_ACTIVE_BOSS_HOLDER.debug();
return null;
}
ACTIVE_BOSS_HOLDERS.add(activeBossHolder);
return activeBossHolder;
}
}

View File

@ -0,0 +1,100 @@
package net.aminecraftdev.custombosses.managers;
import lombok.Getter;
import net.aminecraftdev.custombosses.CustomBosses;
import net.aminecraftdev.custombosses.utils.IASkyblockHelper;
import net.aminecraftdev.custombosses.utils.IFactionHelper;
import net.aminecraftdev.custombosses.utils.IReloadable;
import net.aminecraftdev.custombosses.utils.IWorldGuardHelper;
import net.aminecraftdev.custombosses.utils.askyblock.ASkyblockHelper;
import net.aminecraftdev.custombosses.utils.factions.FactionsM;
import net.aminecraftdev.custombosses.utils.factions.FactionsOne;
import net.aminecraftdev.custombosses.utils.factions.FactionsUUID;
import net.aminecraftdev.custombosses.utils.factions.LegacyFactions;
import net.aminecraftdev.custombosses.utils.worldguard.WorldGuardHelper;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.Plugin;
import java.util.List;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 16-Oct-18
*/
public class BossHookManager implements IReloadable {
@Getter private boolean askyblockEnabled, factionsEnabled, stackmobEnabled, worldguardEnabld;
@Getter private List<String> worldGuardSpawnRegions, worldguardBlockedRegions;
@Getter private boolean askyblockOwnIsland, factionWarzone;
@Getter private IWorldGuardHelper worldGuardHelper;
@Getter private IASkyblockHelper aSkyblockHelper;
@Getter private IFactionHelper factionHelper;
private final CustomBosses plugin;
public BossHookManager(CustomBosses customBosses) {
this.plugin = customBosses;
}
@Override
public void reload() {
FileConfiguration config = this.plugin.getConfig();
ConfigurationSection askyblock = config.getConfigurationSection("Hooks.ASkyBlock");
ConfigurationSection factions = config.getConfigurationSection("Hooks.Factions");
ConfigurationSection stackMob = config.getConfigurationSection("Hooks.StackMob");
ConfigurationSection worldGuard = config.getConfigurationSection("Hooks.WorldGuard");
this.askyblockEnabled = askyblock.getBoolean("enabled", false);
this.factionsEnabled = factions.getBoolean("enabled", false);
this.stackmobEnabled = stackMob.getBoolean("enabled", false);
this.worldguardEnabld = worldGuard.getBoolean("enabled", true);
this.worldGuardSpawnRegions = worldGuard.getStringList("spawnRegions");
this.worldguardBlockedRegions = worldGuard.getStringList("blockedRegions");
this.askyblockOwnIsland = askyblock.getBoolean("onOwnIsland", false);
this.factionWarzone = factions.getBoolean("useWarzoneSpawnRegion", false);
setupFactions();
setupWorldGuard();
}
private void setupAskyblock() {
if(!isAskyblockEnabled()) return;
this.aSkyblockHelper = new ASkyblockHelper();
}
private void setupWorldGuard() {
if(!isWorldguardEnabld()) return;
this.worldGuardHelper = new WorldGuardHelper();
}
private void setupFactions() {
if(!isFactionsEnabled()) return;
if(Bukkit.getServer().getPluginManager().getPlugin("LegacyFactions") != null) {
this.factionHelper = new LegacyFactions();
}
if(Bukkit.getServer().getPluginManager().getPlugin("Factions") == null) return;
Plugin factions = Bukkit.getServer().getPluginManager().getPlugin("Factions");
String version = factions.getDescription().getVersion();
String uuidVer = "1.6.";
String oneVer = "1.8.";
if(version.startsWith(uuidVer)) {
this.factionHelper = new FactionsUUID();
} else if(version.startsWith(oneVer)) {
this.factionHelper = new FactionsOne();
} else {
this.factionHelper = new FactionsM();
}
}
}

View File

@ -0,0 +1,34 @@
package net.aminecraftdev.custombosses.managers;
import net.aminecraftdev.custombosses.CustomBosses;
import net.aminecraftdev.custombosses.listeners.pre.BossSpawnListener;
import net.aminecraftdev.custombosses.utils.Debug;
import net.aminecraftdev.custombosses.utils.ILoadable;
import net.aminecraftdev.custombosses.utils.ServerUtils;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 16-Oct-18
*/
public class BossListenerManager implements ILoadable {
private boolean hasBeenLoaded = false;
private CustomBosses plugin;
public BossListenerManager(CustomBosses plugin) {
this.plugin = plugin;
}
@Override
public void load() {
if(this.hasBeenLoaded) {
Debug.FAILED_TO_LOAD_BOSSLISTENERMANAGER.debug();
return;
}
ServerUtils serverUtils = ServerUtils.get();
serverUtils.registerListener(new BossSpawnListener(this.plugin));
}
}

View File

@ -0,0 +1,97 @@
package net.aminecraftdev.custombosses.managers;
import lombok.Getter;
import net.aminecraftdev.custombosses.CustomBosses;
import net.aminecraftdev.custombosses.utils.IReloadable;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import java.util.List;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 16-Oct-18
*/
public class BossLocationManager implements IReloadable {
@Getter private boolean useBlockedWorlds;
@Getter private List<String> blockedWorlds;
private final BossHookManager bossHookManager;
private final CustomBosses plugin;
public BossLocationManager(CustomBosses customBosses) {
this.bossHookManager = customBosses.getBossHookManager();
this.plugin = customBosses;
}
@Override
public void reload() {
FileConfiguration config = this.plugin.getConfig();
this.useBlockedWorlds = config.getBoolean("Settings.BlockedWorlds.enabled");
this.blockedWorlds = config.getStringList("Settings.BlockedWorlds.worlds");
}
public boolean canSpawnBoss(Player player, Location location) {
for(int x = location.getBlockX() - 2; x <= location.getBlockX() + 2; x++) {
for(int y = location.getBlockY(); y <= location.getBlockY() + 2; y++) {
for(int z = location.getBlockZ() - 2; z <= location.getBlockZ() + 2; z++) {
Location l = new Location(location.getWorld(), x, y, z);
Block block = l.getBlock();
if(block.getType() != Material.AIR) return false;
}
}
}
if(isUseBlockedWorlds()) {
if(getBlockedWorlds().contains(location.getWorld().getName())) return false;
}
if(this.bossHookManager.isWorldguardEnabld() && this.bossHookManager.getWorldGuardHelper() != null) {
List<String> currentRegions = this.bossHookManager.getWorldGuardHelper().getRegionNames(location);
boolean blocked = false;
for(String s : this.bossHookManager.getWorldguardBlockedRegions()) {
if(currentRegions.contains(s)) {
blocked = true;
break;
}
}
if(blocked) return false;
}
if(this.bossHookManager.isFactionsEnabled() && this.bossHookManager.getFactionHelper() != null) {
if(!this.bossHookManager.getFactionHelper().isInWarzone(location)) return false;
}
if(this.bossHookManager.isWorldguardEnabld() && this.bossHookManager.getWorldGuardHelper() != null) {
List<String> currentRegions = this.bossHookManager.getWorldGuardHelper().getRegionNames(location);
boolean allowed = false;
for(String s : this.bossHookManager.getWorldGuardSpawnRegions()) {
if(currentRegions.contains(s)) {
allowed = true;
break;
}
}
if(!allowed) return false;
}
if(this.bossHookManager.isAskyblockEnabled() && this.bossHookManager.getASkyblockHelper() != null) {
if(this.bossHookManager.isAskyblockOwnIsland()) {
return this.bossHookManager.getASkyblockHelper().isOnOwnIsland(player);
}
}
return true;
}
}

View File

@ -54,6 +54,11 @@ public class BossMechanicManager implements ILoadable {
public boolean handleMechanicApplication(BossEntity bossEntity, ActiveBossHolder activeBossHolder) {
if(bossEntity != null && activeBossHolder != null) {
if(bossEntity.isEditing()) {
Debug.ATTEMPTED_TO_SPAWN_WHILE_DISABLED.debug();
return false;
}
Queue<IMechanic> queue = new LinkedList<>(this.primaryMechanics);
while(!queue.isEmpty()) {

View File

@ -3,10 +3,10 @@ package net.aminecraftdev.custombosses.panel;
import net.aminecraftdev.custombosses.CustomBosses;
import net.aminecraftdev.custombosses.api.BossAPI;
import net.aminecraftdev.custombosses.entity.BossEntity;
import net.aminecraftdev.custombosses.managers.BossEntityManager;
import net.aminecraftdev.custombosses.managers.BossPanelManager;
import net.aminecraftdev.custombosses.utils.Debug;
import net.aminecraftdev.custombosses.managers.files.BossesFileManager;
import net.aminecraftdev.custombosses.utils.itemstack.ItemStackUtils;
import net.aminecraftdev.custombosses.utils.itemstack.holder.ItemStackHolder;
import net.aminecraftdev.custombosses.utils.panel.base.PanelHandler;
import net.aminecraftdev.custombosses.utils.panel.builder.PanelBuilder;
import org.bukkit.Material;
@ -25,12 +25,16 @@ import java.util.Map;
*/
public class CustomBossesPanel extends PanelHandler {
private BossEntityManager bossEntityManager;
private BossesFileManager bossesFileManager;
private CustomBosses customBosses;
public CustomBossesPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses customBosses) {
super(bossPanelManager, panelBuilder);
this.customBosses = customBosses;
this.bossEntityManager = customBosses.getBossEntityManager();
this.bossesFileManager = customBosses.getBossesFileManager();
this.panel.setParentPanel(this.bossPanelManager.getMainMenu().getPanel());
fillPanel();
@ -38,7 +42,7 @@ public class CustomBossesPanel extends PanelHandler {
@Override
public void fillPanel() {
Map<String, BossEntity> currentEntities = new HashMap<>(this.customBosses.getBossesFileManager().getBossEntities());
Map<String, BossEntity> currentEntities = new HashMap<>(this.bossesFileManager.getBossEntities());
List<String> entryList = new ArrayList<>(currentEntities.keySet());
int maxPage = this.panel.getMaxPage(entryList);
@ -62,18 +66,9 @@ public class CustomBossesPanel extends PanelHandler {
} else {
String name = entryList.get(i);
BossEntity entity = bossEntityMap.get(name);
ItemStackHolder itemStackHolder = BossAPI.getStoredItemStack(entity.getSpawnItem());
if(itemStackHolder == null) {
Debug.FAILED_TO_LOAD_CUSTOM_ITEM.debug(entity.getSpawnItem(), name);
getPanel().setItem(i-startIndex, new ItemStack(Material.AIR), e -> {});
continue;
}
ItemStack itemStack = this.customBosses.getItemStackManager().getItemStackConverter().from(itemStackHolder);
ItemStack itemStack = this.bossEntityManager.getSpawnItem(entity);
if(itemStack == null) {
Debug.FAILED_TO_LOAD_CUSTOM_ITEM.debug(entity.getSpawnItem(), name);
getPanel().setItem(i-startIndex, new ItemStack(Material.AIR), e -> {});
continue;
}

View File

@ -19,12 +19,14 @@ public enum Debug {
BOSS_CONTAINER_SAVE("The BossEntity map was saved in, {0} succeeded, and {1} failed. Listed below are the saved data which already existed in the container: \n{2}"),
ATTEMPTED_TO_UPDATE_PLUGIN("Something has attempted to update the PLUGIN variable in the BossAPI class while it is already initialized."),
ATTEMPTED_TO_SPAWN_WHILE_DISABLED("The {0} boss/minion attempted to spawn while editing is enabled."),
ATTEMPTED_TO_SPAWN_WHILE_DISABLED("A boss/minion attempted to spawn while editing is enabled."),
FAILED_ATTEMPT_TO_SPAWN_BOSS("A boss has attempted to spawn but cannot spawn for the following reason: \n{0}"),
FAILED_ATTEMPT_TO_STACK_BOSSES("A boss has failed to stack on top of another boss under the {0} boss configuration."),
FAILED_TO_SAVE_THE_NEW_BOSS("The {0} with EntityType boss was successfully created but failed to save."),
FAILED_TO_LOAD_BOSSCOMMANDMANAGER("The boss command manager tried to load again, but it has already loaded previously."),
FAILED_TO_LOAD_CUSTOM_ITEM("The itemstack name that is provided ({0}) for the spawn item for {1} doesn't exist or wasn't found."),
FAILED_TO_LOAD_BOSSLISTENERMANAGER("The boss listener manager tried to load again, but it has already loaded previously."),
FAILED_TO_LOAD_CUSTOM_ITEM("The itemstack name that is provided ({0}) for the spawn item doesn't exist or wasn't found."),
FAILED_TO_CREATE_ACTIVE_BOSS_HOLDER("Something went wrong while trying to create an active boss holder for someone who is trying to spawn a boss."),
MECHANIC_TYPE_NOT_STORED("This mechanic type is not stored, therefore will not be applied. Valid mechanic types are IOptionalMechanic and IPrimaryMechanic.");

View File

@ -0,0 +1,14 @@
package net.aminecraftdev.custombosses.utils;
import org.bukkit.entity.Player;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 16-Oct-18
*/
public interface IASkyblockHelper {
boolean isOnOwnIsland(Player player);
}

View File

@ -0,0 +1,18 @@
package net.aminecraftdev.custombosses.utils;
import org.bukkit.entity.LivingEntity;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 16-Oct-18
*/
public interface ITargetHandler {
boolean canTarget(LivingEntity livingEntity);
void updateTarget();
void createAutoTarget();
}

View File

@ -0,0 +1,24 @@
package net.aminecraftdev.custombosses.utils;
import org.bukkit.Location;
import java.util.List;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 16-Oct-18
*/
public interface IWorldGuardHelper {
boolean isPvpAllowed(Location location);
boolean isBreakAllowed(Location location);
boolean isExplosionsAllowed(Location location);
List<String> getRegionNames(Location location);
boolean isMobSpawningAllowed(Location location);
}

View File

@ -16,6 +16,7 @@ import org.bukkit.inventory.ItemStack;
public enum Message {
General_MustBePlayer("&c&l(!) &cYou must be a player to use this command."),
General_CannotSpawn("&c&l(!) &cYou cannot spawn a boss at this location! &c&l(!)"),
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."),
@ -32,6 +33,7 @@ public enum Message {
Boss_Edit_NoPermission("&c&l(!) &cYou do not have access to this command."),
Boss_Edit_ItemStackHolderNull("&c&l(!) &cThe itemstack name that is provided for the spawn item doesn't exist or wasn't found."),
Boss_Edit_CannotSpawn("&c&l(!) &cYou cannot spawn this boss while editing is enabled. If you think this is a mistake please contact an administrator to disable the editing of the boss."),
Boss_Help_Page1(
"&8&m----*--------&6&l[ &e&lBoss Help &7(Page 1) &6&l]&8&m--------*----\n" +

View File

@ -0,0 +1,23 @@
package net.aminecraftdev.custombosses.utils.askyblock;
import com.wasteofplastic.askyblock.ASkyBlock;
import com.wasteofplastic.askyblock.Island;
import net.aminecraftdev.custombosses.utils.IASkyblockHelper;
import org.bukkit.entity.Player;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 16-Oct-18
*/
public class ASkyblockHelper implements IASkyblockHelper {
@Override
public boolean isOnOwnIsland(Player player) {
Island island = ASkyBlock.getPlugin().getGrid().getProtectedIslandAt(player.getLocation());
if(island == null) return false;
return island.getMembers().contains(player.getUniqueId());
}
}

View File

@ -323,4 +323,21 @@ public class ItemStackUtils {
return new ItemStackHolder(amount, type, durability, name, lore, enchants, skullOwner, spawnerId, isGlowing);
}
public static boolean isItemStackSame(ItemStack itemStack1, ItemStack itemStack2) {
if(itemStack1 == null || itemStack2 == null) return false;
if(itemStack1.getType() != itemStack2.getType()) return false;
if(itemStack1.getDurability() != itemStack2.getDurability()) return false;
ItemMeta itemMeta1 = itemStack1.getItemMeta();
ItemMeta itemMeta2 = itemStack2.getItemMeta();
if(itemMeta1 == null || itemMeta2 == null) return false;
if(itemMeta1.hasDisplayName() != itemMeta2.hasDisplayName()) return false;
if(itemMeta1.getDisplayName().equals(itemMeta2.getDisplayName())) return false;
if(itemMeta1.hasLore() != itemMeta2.hasLore()) return false;
if(!itemMeta1.getLore().equals(itemMeta2.getLore())) return false;
return true;
}
}

View File

@ -0,0 +1,43 @@
package net.aminecraftdev.custombosses.utils.target;
import net.aminecraftdev.custombosses.holder.ActiveBossHolder;
import net.aminecraftdev.custombosses.utils.ITargetHandler;
import net.aminecraftdev.custombosses.utils.ServerUtils;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.LivingEntity;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 16-Oct-18
*/
public abstract class TargetHandler implements ITargetHandler {
protected ActiveBossHolder activeBossHolder;
protected LivingEntity currentTarget;
public TargetHandler(ActiveBossHolder activeBossHolder) {
this.activeBossHolder = activeBossHolder;
}
@Override
public boolean canTarget(LivingEntity livingEntity) {
//TODO: Implement feature to allow targetting of PetMaster pet's too
return (livingEntity instanceof HumanEntity);
}
@Override
public void createAutoTarget() {
ServerUtils.get().runLaterAsync(100L, () -> {
updateTarget();
if(this.currentTarget == null || this.currentTarget.isDead()) return;
createAutoTarget();
});
}
}

View File

@ -0,0 +1,101 @@
package net.aminecraftdev.custombosses.utils.worldguard;
import com.sk89q.worldguard.bukkit.WGBukkit;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import net.aminecraftdev.custombosses.utils.IWorldGuardHelper;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import java.util.LinkedList;
import java.util.List;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 16-Oct-18
*/
public class WorldGuardHelper implements IWorldGuardHelper {
@Override
public boolean isPvpAllowed(Location loc) {
if(Bukkit.getServer().getPluginManager().getPlugin("WorldEdit") != null
&& Bukkit.getServer().getPluginManager().getPlugin("WorldGuard") != null) {
ApplicableRegionSet set = WGBukkit.getPlugin().getRegionManager(loc.getWorld()).getApplicableRegions(loc);
if(set.queryState(null, DefaultFlag.PVP) == StateFlag.State.DENY) return false;
}
return true;
}
@Override
public boolean isBreakAllowed(Location loc) {
if(Bukkit.getServer().getPluginManager().getPlugin("WorldEdit") != null
&& Bukkit.getServer().getPluginManager().getPlugin("WorldGuard") != null) {
ApplicableRegionSet set = WGBukkit.getPlugin().getRegionManager(loc.getWorld()).getApplicableRegions(loc);
if(set.queryState(null, DefaultFlag.BLOCK_BREAK) == StateFlag.State.DENY) return false;
}
return true;
}
@Override
public boolean isExplosionsAllowed(Location loc) {
if(Bukkit.getServer().getPluginManager().getPlugin("WorldEdit") != null
&& Bukkit.getServer().getPluginManager().getPlugin("WorldGuard") != null) {
ApplicableRegionSet set = WGBukkit.getPlugin().getRegionManager(loc.getWorld()).getApplicableRegions(loc);
if(set.queryState(null, DefaultFlag.OTHER_EXPLOSION) == StateFlag.State.DENY) return false;
}
return true;
}
@Override
public List<String> getRegionNames(Location loc) {
if(Bukkit.getServer().getPluginManager().getPlugin("WorldEdit") != null
&& Bukkit.getServer().getPluginManager().getPlugin("WorldGuard") != null) {
ApplicableRegionSet set = WGBukkit.getPlugin().getRegionManager(loc.getWorld()).getApplicableRegions(loc);
LinkedList<String> parentNames = new LinkedList<String>();
LinkedList<String> regions = new LinkedList<String>();
for(ProtectedRegion region : set) {
String id = region.getId();
regions.add(id);
ProtectedRegion parent = region.getParent();
while(parent != null) {
parentNames.add(parent.getId());
parent = parent.getParent();
}
}
for(String name : parentNames) {
regions.remove(name);
}
return regions;
}
return null;
}
@Override
public boolean isMobSpawningAllowed(Location loc) {
if(Bukkit.getServer().getPluginManager().getPlugin("WorldEdit") != null
&& Bukkit.getServer().getPluginManager().getPlugin("WorldGuard") != null) {
ApplicableRegionSet set = WGBukkit.getPlugin().getRegionManager(loc.getWorld()).getApplicableRegions(loc);
if(set.queryState(null, DefaultFlag.MOB_SPAWNING) == StateFlag.State.DENY) return false;
}
return true;
}
}

View File

@ -29,6 +29,7 @@
<orderEntry type="library" scope="PROVIDED" name="Maven: de.schlichtherle:truezip:6.8.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: rhino:js:1.7R2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:10.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.wasteofplastic:askyblock:3.0.8.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.16.22" level="project" />
<orderEntry type="library" name="Maven: org.bstats:bstats-bukkit:1.2" level="project" />
</component>

View File

@ -19,7 +19,7 @@
</modules>
<properties>
<plugin.version>3.0.0-SNAPSHOT-U26</plugin.version>
<plugin.version>3.0.0-SNAPSHOT-U27</plugin.version>
<plugin.name>CustomBosses</plugin.name>
<plugin.main>net.aminecraftdev.custombosses.CustomBosses</plugin.main>
<plugin.author>AMinecraftDev</plugin.author>
@ -50,6 +50,12 @@
<version>6.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.wasteofplastic</groupId>
<artifactId>askyblock</artifactId>
<version>3.0.8.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>