3.0.0-SNAPSHOT-U28

+ Completed BossSpawn setup
+ Debuged and fixed a few things
+ Added BossCommands File
+ Added BossMessages File
This commit is contained in:
AMinecraftDev 2018-10-17 23:52:57 +08:00
parent f284ae0df1
commit f90716bcc6
16 changed files with 392 additions and 35 deletions

View File

@ -0,0 +1,8 @@
{
"SKOnSpawn": [
"broadcast this is a default command that is broadcasted when the Skeleton King is spawned."
],
"SKOnDeath": [
"broadcast this is the default command when the Skeleton King is defeated!"
]
}

View File

@ -0,0 +1,30 @@
{
"SKMainSkillMessage": [
"&6&l{boss} &7has used the &e{skill} &7skill."
],
"SKOnSpawn": [
"&8&m-----*--------------------*-----",
"&7",
"&fA &e{boss} &fhas been spawned at &e{location}&f!",
"&7",
"&8&m-----*--------------------*-----"
],
"SKOnDeath": [
"&8&m-----*--------------------*-----",
"&7",
"&e{boss}&f has been killed,",
"&fbelow are the top damagers:",
"&7",
"&6&l#1 &e{pos1}&f - &e{pos1%}% &f(&e{pos1dmg} dmg&f)",
"&6&l#2 &e{pos2}&f - &e{pos2%}% &f(&e{pos2dmg} dmg&f)",
"&6&l#3 &e{pos3}&f - &e{pos3%}% &f(&e{pos3dmg} dmg&f)",
"&7",
"&8&m-----*--------------------*-----"
],
"SKTaunt1": [
"&6&lSkeleton King &f» &7My pocket knife is sharper then that sword! &o*cackle*"
],
"SKTaunt2": [
"&6&lSkeleton King &f» &7You think you humans can defeat me?! I am the notorious Skeleton King!"
]
}

View File

@ -9,7 +9,9 @@ import net.aminecraftdev.custombosses.file.ConfigFileHandler;
import net.aminecraftdev.custombosses.file.EditorFileHandler;
import net.aminecraftdev.custombosses.file.LangFileHandler;
import net.aminecraftdev.custombosses.managers.*;
import net.aminecraftdev.custombosses.managers.files.BossCommandFileManager;
import net.aminecraftdev.custombosses.managers.files.BossItemFileManager;
import net.aminecraftdev.custombosses.managers.files.BossMessagesFileManager;
import net.aminecraftdev.custombosses.managers.files.BossesFileManager;
import net.aminecraftdev.custombosses.utils.Debug;
import net.aminecraftdev.custombosses.utils.IReloadable;
@ -26,17 +28,22 @@ import org.bukkit.plugin.java.JavaPlugin;
* @author AMinecraftDev
* @version 1.0.0
* @since 06-Sep-17
*
* TODO: In menu when toggling Edit mode, make sure that it has all needed mechanics
*/
public class CustomBosses extends JavaPlugin implements IReloadable {
@Getter private BossMessagesFileManager bossMessagesFileManager;
@Getter private BossCommandFileManager bossCommandFileManager;
@Getter private BossItemFileManager itemStackManager;
@Getter private BossesFileManager bossesFileManager;
@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;
@ -60,28 +67,31 @@ 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();
//Managers that rely on Files
this.bossPanelManager = new BossPanelManager(this);
this.bossEntityManager = new BossEntityManager(this);
createFiles();
reloadFiles();
this.itemStackManager.reload();
this.bossesFileManager.reload();
this.bossCommandFileManager.reload();
this.bossMessagesFileManager.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();
saveMessagesToFile();
@ -94,8 +104,11 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
@Override
public void reload() {
this.itemStackManager.reload();
this.bossMessagesFileManager.reload();
this.bossCommandFileManager.reload();
this.bossesFileManager.reload();
this.itemStackManager.reload();
this.bossMechanicManager.load();
reloadFiles();
@ -111,6 +124,8 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
private void loadFileManagersAndHandlers() {
this.itemStackManager = new BossItemFileManager(this);
this.bossesFileManager = new BossesFileManager(this);
this.bossCommandFileManager = new BossCommandFileManager(this);
this.bossMessagesFileManager = new BossMessagesFileManager(this);
this.langFileHandler = new LangFileHandler(this);
this.editorFileHandler = new EditorFileHandler(this);

View File

@ -140,10 +140,10 @@ public class BossAPI {
* @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;
}
// if(bossEntity.isEditing()) {
// Debug.ATTEMPTED_TO_SPAWN_WHILE_DISABLED.debug();
// return null;
// }
return PLUGIN.getBossEntityManager().createActiveBossHolder(bossEntity, location);
}

View File

@ -0,0 +1,77 @@
package net.aminecraftdev.custombosses.file;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import net.aminecraftdev.custombosses.utils.file.FileHandler;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 17-Oct-18
*/
public class CommandsFileHandler extends FileHandler<Map<String, List<String>>> {
private static final Gson GSON = new GsonBuilder()
.setPrettyPrinting()
.excludeFieldsWithoutExposeAnnotation()
.create();
public CommandsFileHandler(JavaPlugin javaPlugin, boolean saveResource, File file) {
super(javaPlugin, saveResource, file);
}
@Override
public Map<String, List<String>> loadFile() {
Map<String, List<String>> commandsMap = new HashMap<>();
createFile();
try {
FileReader fileReader = new FileReader(getFile());
JsonObject jsonObject = GSON.fromJson(fileReader, JsonObject.class);
fileReader.close();
if(jsonObject != null) {
Type listType = new TypeToken<List<String>>(){}.getType();
jsonObject.entrySet().forEach(entry -> {
String id = entry.getKey();
List<String> commands = GSON.fromJson(entry.getValue(), listType);
commandsMap.put(id, commands);
});
}
} catch (IOException ex) {
ex.printStackTrace();
}
return commandsMap;
}
@Override
public void saveFile(Map<String, List<String>> stringListMap) {
try {
FileWriter fileWriter = new FileWriter(getFile());
Type type = new TypeToken<Map<String, List<String>>>(){}.getType();
fileWriter.write(GSON.toJson(new HashMap<>(stringListMap), type));
fileWriter.flush();
fileWriter.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}

View File

@ -0,0 +1,78 @@
package net.aminecraftdev.custombosses.file;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import net.aminecraftdev.custombosses.utils.file.FileHandler;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 17-Oct-18
*/
public class MessagesFileHandler extends FileHandler<Map<String, List<String>>> {
private static final Gson GSON = new GsonBuilder()
.setPrettyPrinting()
.excludeFieldsWithoutExposeAnnotation()
.create();
public MessagesFileHandler(JavaPlugin javaPlugin, boolean saveResource, File file) {
super(javaPlugin, saveResource, file);
}
@Override
public Map<String, List<String>> loadFile() {
Map<String, List<String>> messagesMap = new HashMap<>();
createFile();
try {
FileReader fileReader = new FileReader(getFile());
JsonObject jsonObject = GSON.fromJson(fileReader, JsonObject.class);
fileReader.close();
if(jsonObject != null) {
Type listType = new TypeToken<List<String>>(){}.getType();
jsonObject.entrySet().forEach(entry -> {
String id = entry.getKey();
List<String> messages = GSON.fromJson(entry.getValue(), listType);
messagesMap.put(id, messages);
});
}
} catch (IOException ex) {
ex.printStackTrace();
}
return messagesMap;
}
@Override
public void saveFile(Map<String, List<String>> stringListMap) {
try {
FileWriter fileWriter = new FileWriter(getFile());
Type type = new TypeToken<Map<String, List<String>>>(){}.getType();
fileWriter.write(GSON.toJson(new HashMap<>(stringListMap), type));
fileWriter.flush();
fileWriter.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}

View File

@ -46,7 +46,6 @@ public class BossSpawnListener implements Listener {
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();
@ -67,10 +66,13 @@ public class BossSpawnListener implements Listener {
if(bossEntity == null) return;
if(bossEntity.isEditing()) {
Message.Boss_Edit_CannotSpawn.msg(player);
return;
}
// if(bossEntity.isEditing()) {
// Message.Boss_Edit_CannotSpawn.msg(player);
// event.setCancelled(true);
// return;
// }
Location location = block.getLocation().clone();
if(blockFace == BlockFace.UP) {
location.add(0,1,0);
@ -86,6 +88,12 @@ public class BossSpawnListener implements Listener {
ActiveBossHolder activeBossHolder = BossAPI.spawnNewBoss(bossEntity, location);
if(activeBossHolder == null) {
//TODO: Make log file to store when a boss was spawned, where, what boss, and who spawned it, and the debug reason to why it couldn't spawn.
event.setCancelled(true);
return;
}
//TODO: Set TargetHandler to the boss
PreBossSpawnEvent preBossSpawnEvent = new PreBossSpawnEvent(activeBossHolder, player, itemStack);
@ -107,6 +115,9 @@ public class BossSpawnListener implements Listener {
//TODO: Handle onSpawn commands, and messages
BossSpawnEvent bossSpawnEvent = new BossSpawnEvent(activeBossHolder);
ServerUtils.get().callEvent(bossSpawnEvent);
System.out.println("SPAWN EVENT CALLED");
}
}

View File

@ -30,5 +30,8 @@ public class BossListenerManager implements ILoadable {
ServerUtils serverUtils = ServerUtils.get();
serverUtils.registerListener(new BossSpawnListener(this.plugin));
this.hasBeenLoaded = true;
}
}

View File

@ -44,7 +44,7 @@ public class BossLocationManager implements IReloadable {
Location l = new Location(location.getWorld(), x, y, z);
Block block = l.getBlock();
if(block.getType() != Material.AIR) return false;
if(block.getType().isSolid()) return false;
}
}
}
@ -57,14 +57,16 @@ public class BossLocationManager implements IReloadable {
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(currentRegions != null) {
for(String s : this.bossHookManager.getWorldguardBlockedRegions()) {
if(currentRegions.contains(s)) {
blocked = true;
break;
}
}
}
if(blocked) return false;
if(blocked) return false;
}
}
if(this.bossHookManager.isFactionsEnabled() && this.bossHookManager.getFactionHelper() != null) {
@ -75,14 +77,16 @@ public class BossLocationManager implements IReloadable {
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(currentRegions != null) {
for(String s : this.bossHookManager.getWorldGuardSpawnRegions()) {
if(currentRegions.contains(s)) {
allowed = true;
break;
}
}
}
if(!allowed) return false;
if(!allowed) return false;
}
}
if(this.bossHookManager.isAskyblockEnabled() && this.bossHookManager.getASkyblockHelper() != null) {

View File

@ -54,10 +54,10 @@ 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;
}
// if(bossEntity.isEditing()) {
// Debug.ATTEMPTED_TO_SPAWN_WHILE_DISABLED.debug();
// return false;
// }
Queue<IMechanic> queue = new LinkedList<>(this.primaryMechanics);

View File

@ -0,0 +1,64 @@
package net.aminecraftdev.custombosses.managers.files;
import lombok.Getter;
import net.aminecraftdev.custombosses.CustomBosses;
import net.aminecraftdev.custombosses.file.CommandsFileHandler;
import net.aminecraftdev.custombosses.utils.ILoadable;
import net.aminecraftdev.custombosses.utils.IReloadable;
import net.aminecraftdev.custombosses.utils.ISavable;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 17-Oct-18
*/
public class BossCommandFileManager implements ILoadable, ISavable, IReloadable {
private Map<String, List<String>> commandsMap = new HashMap<>();
private CommandsFileHandler commandsFileHandler;
public BossCommandFileManager(CustomBosses customBosses) {
File file = new File(customBosses.getDataFolder(), "commands.json");
this.commandsFileHandler = new CommandsFileHandler(customBosses, true, file);
}
@Override
public void load() {
this.commandsMap = this.commandsFileHandler.loadFile();
}
@Override
public void reload() {
load();
}
@Override
public void save() {
this.commandsFileHandler.saveFile(this.commandsMap);
}
public List<String> getCommands(String id) {
return this.commandsMap.getOrDefault(id, null);
}
public Map<String, List<String>> getCommandsMap() {
return new HashMap<>(this.commandsMap);
}
public boolean addNewCommand(String id, List<String> commands) {
if(this.commandsMap.containsKey(id)) return false;
commandsMap.put(id, commands);
return true;
}
public void removeCommand(String id) {
commandsMap.remove(id);
}
}

View File

@ -0,0 +1,63 @@
package net.aminecraftdev.custombosses.managers.files;
import net.aminecraftdev.custombosses.CustomBosses;
import net.aminecraftdev.custombosses.file.MessagesFileHandler;
import net.aminecraftdev.custombosses.utils.ILoadable;
import net.aminecraftdev.custombosses.utils.IReloadable;
import net.aminecraftdev.custombosses.utils.ISavable;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 17-Oct-18
*/
public class BossMessagesFileManager implements ILoadable, ISavable, IReloadable {
private Map<String, List<String>> messagesMap = new HashMap<>();
private MessagesFileHandler messagesFileHandler;
public BossMessagesFileManager(CustomBosses customBosses) {
File file = new File(customBosses.getDataFolder(), "messages.json");
this.messagesFileHandler = new MessagesFileHandler(customBosses, true, file);
}
@Override
public void load() {
this.messagesMap = this.messagesFileHandler.loadFile();
}
@Override
public void reload() {
load();
}
@Override
public void save() {
this.messagesFileHandler.saveFile(this.messagesMap);
}
public List<String> getMessages(String id) {
return this.messagesMap.getOrDefault(id, null);
}
public Map<String, List<String>> getMessagesMap() {
return new HashMap<>(this.messagesMap);
}
public boolean addNewMessage(String id, List<String> message) {
if(this.messagesMap.containsKey(id)) return false;
messagesMap.put(id, message);
return true;
}
public void removeMessage(String id) {
messagesMap.remove(id);
}
}

View File

@ -11,6 +11,8 @@ import org.bukkit.entity.LivingEntity;
* @author Charles Cullen
* @version 1.0.0
* @since 27-Jun-18
*
* TODO: Make a hologram above name instead of using default CustomName
*/
public class NameMechanic implements IOptionalMechanic {

View File

@ -51,7 +51,9 @@ public enum Debug {
String finalMsg = message;
if(PLUGIN.isDebug()) ServerUtils.get().logDebug(finalMsg);
// if(PLUGIN.isDebug()) {
ServerUtils.get().logDebug(finalMsg);
// }
PLUGIN.getDebugManager().getToggledPlayers().forEach(uuid -> {
Player player = Bukkit.getPlayer(uuid);

View File

@ -334,7 +334,7 @@ public class ItemStackUtils {
if(itemMeta1 == null || itemMeta2 == null) return false;
if(itemMeta1.hasDisplayName() != itemMeta2.hasDisplayName()) return false;
if(itemMeta1.getDisplayName().equals(itemMeta2.getDisplayName())) 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;

View File

@ -19,7 +19,7 @@
</modules>
<properties>
<plugin.version>3.0.0-SNAPSHOT-U27</plugin.version>
<plugin.version>3.0.0-SNAPSHOT-U28</plugin.version>
<plugin.name>CustomBosses</plugin.name>
<plugin.main>net.aminecraftdev.custombosses.CustomBosses</plugin.main>
<plugin.author>AMinecraftDev</plugin.author>