mirror of
https://github.com/songoda/EpicBosses.git
synced 2025-02-18 20:01:20 +01:00
3.0.0-SNAPSHOT-U32
+ Continued working on drop tables, got all file management done + Started working on 1/3 of the drop table types + Added DeadBossHolder to handle drop tables easier + Added RandomUtils to make random number obtaining easier
This commit is contained in:
parent
0f66facf41
commit
fe451b5b0b
@ -4,20 +4,15 @@ import lombok.Getter;
|
|||||||
import net.aminecraftdev.custombosses.api.BossAPI;
|
import net.aminecraftdev.custombosses.api.BossAPI;
|
||||||
import net.aminecraftdev.custombosses.commands.BossCmd;
|
import net.aminecraftdev.custombosses.commands.BossCmd;
|
||||||
import net.aminecraftdev.custombosses.container.BossEntityContainer;
|
import net.aminecraftdev.custombosses.container.BossEntityContainer;
|
||||||
import net.aminecraftdev.custombosses.file.BossesFileHandler;
|
|
||||||
import net.aminecraftdev.custombosses.file.ConfigFileHandler;
|
import net.aminecraftdev.custombosses.file.ConfigFileHandler;
|
||||||
import net.aminecraftdev.custombosses.file.EditorFileHandler;
|
import net.aminecraftdev.custombosses.file.EditorFileHandler;
|
||||||
import net.aminecraftdev.custombosses.file.LangFileHandler;
|
import net.aminecraftdev.custombosses.file.LangFileHandler;
|
||||||
import net.aminecraftdev.custombosses.managers.*;
|
import net.aminecraftdev.custombosses.managers.*;
|
||||||
import net.aminecraftdev.custombosses.managers.files.BossCommandFileManager;
|
import net.aminecraftdev.custombosses.managers.files.*;
|
||||||
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.Debug;
|
||||||
import net.aminecraftdev.custombosses.utils.IReloadable;
|
import net.aminecraftdev.custombosses.utils.IReloadable;
|
||||||
import net.aminecraftdev.custombosses.utils.Message;
|
import net.aminecraftdev.custombosses.utils.Message;
|
||||||
import net.aminecraftdev.custombosses.utils.ServerUtils;
|
import net.aminecraftdev.custombosses.utils.ServerUtils;
|
||||||
import net.aminecraftdev.custombosses.utils.command.SubCommandService;
|
|
||||||
import net.aminecraftdev.custombosses.utils.file.YmlFileHandler;
|
import net.aminecraftdev.custombosses.utils.file.YmlFileHandler;
|
||||||
import net.aminecraftdev.custombosses.utils.version.VersionHandler;
|
import net.aminecraftdev.custombosses.utils.version.VersionHandler;
|
||||||
import org.bstats.bukkit.Metrics;
|
import org.bstats.bukkit.Metrics;
|
||||||
@ -33,10 +28,11 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
*/
|
*/
|
||||||
public class CustomBosses extends JavaPlugin implements IReloadable {
|
public class CustomBosses extends JavaPlugin implements IReloadable {
|
||||||
|
|
||||||
@Getter private BossMessagesFileManager bossMessagesFileManager;
|
@Getter private MessagesFileManager bossMessagesFileManager;
|
||||||
@Getter private BossCommandFileManager bossCommandFileManager;
|
@Getter private CommandsFileManager bossCommandFileManager;
|
||||||
@Getter private BossItemFileManager itemStackManager;
|
@Getter private DropTableFileManager dropTableFileManager;
|
||||||
@Getter private BossesFileManager bossesFileManager;
|
@Getter private BossesFileManager bossesFileManager;
|
||||||
|
@Getter private ItemsFileManager itemStackManager;
|
||||||
|
|
||||||
@Getter private BossEntityContainer bossEntityContainer;
|
@Getter private BossEntityContainer bossEntityContainer;
|
||||||
@Getter private BossMechanicManager bossMechanicManager;
|
@Getter private BossMechanicManager bossMechanicManager;
|
||||||
@ -83,6 +79,7 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
|
|||||||
this.bossesFileManager.reload();
|
this.bossesFileManager.reload();
|
||||||
this.bossCommandFileManager.reload();
|
this.bossCommandFileManager.reload();
|
||||||
this.bossMessagesFileManager.reload();
|
this.bossMessagesFileManager.reload();
|
||||||
|
this.dropTableFileManager.reload();
|
||||||
|
|
||||||
this.bossCommandManager = new BossCommandManager(new BossCmd(), this);
|
this.bossCommandManager = new BossCommandManager(new BossCmd(), this);
|
||||||
this.bossListenerManager = new BossListenerManager(this);
|
this.bossListenerManager = new BossListenerManager(this);
|
||||||
@ -108,6 +105,7 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
|
|||||||
this.bossCommandFileManager.reload();
|
this.bossCommandFileManager.reload();
|
||||||
this.bossesFileManager.reload();
|
this.bossesFileManager.reload();
|
||||||
this.itemStackManager.reload();
|
this.itemStackManager.reload();
|
||||||
|
this.dropTableFileManager.reload();
|
||||||
|
|
||||||
this.bossMechanicManager.load();
|
this.bossMechanicManager.load();
|
||||||
|
|
||||||
@ -122,10 +120,11 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadFileManagersAndHandlers() {
|
private void loadFileManagersAndHandlers() {
|
||||||
this.itemStackManager = new BossItemFileManager(this);
|
this.itemStackManager = new ItemsFileManager(this);
|
||||||
this.bossesFileManager = new BossesFileManager(this);
|
this.bossesFileManager = new BossesFileManager(this);
|
||||||
this.bossCommandFileManager = new BossCommandFileManager(this);
|
this.bossCommandFileManager = new CommandsFileManager(this);
|
||||||
this.bossMessagesFileManager = new BossMessagesFileManager(this);
|
this.bossMessagesFileManager = new MessagesFileManager(this);
|
||||||
|
this.dropTableFileManager = new DropTableFileManager(this);
|
||||||
|
|
||||||
this.langFileHandler = new LangFileHandler(this);
|
this.langFileHandler = new LangFileHandler(this);
|
||||||
this.editorFileHandler = new EditorFileHandler(this);
|
this.editorFileHandler = new EditorFileHandler(this);
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package net.aminecraftdev.custombosses.droptable;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.Expose;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import net.aminecraftdev.custombosses.droptable.elements.RewardsTableElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Charles Cullen
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 25-Oct-18
|
||||||
|
*/
|
||||||
|
public class DropTable {
|
||||||
|
|
||||||
|
@Expose @Getter @Setter private String dropType;
|
||||||
|
@Expose @Getter @Setter private RewardsTableElement rewards;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package net.aminecraftdev.custombosses.droptable.elements;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.Expose;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import net.aminecraftdev.custombosses.droptable.elements.RewardsTableElement;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Charles Cullen
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 25-Oct-18
|
||||||
|
*/
|
||||||
|
public class DropTableElement extends RewardsTableElement {
|
||||||
|
|
||||||
|
@Expose @Getter @Setter private Map<String, Double> dropRewards;
|
||||||
|
@Expose @Getter @Setter private Integer dropMaxDrops;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package net.aminecraftdev.custombosses.droptable.elements;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.Expose;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import net.aminecraftdev.custombosses.droptable.elements.GiveTableSubElement;
|
||||||
|
import net.aminecraftdev.custombosses.droptable.elements.RewardsTableElement;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Charles Cullen
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 25-Oct-18
|
||||||
|
*/
|
||||||
|
public class GiveTableElement extends RewardsTableElement {
|
||||||
|
|
||||||
|
@Expose @Getter @Setter private Map<String, GiveTableSubElement> giveRewards;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package net.aminecraftdev.custombosses.droptable.elements;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.Expose;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Charles Cullen
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 25-Oct-18
|
||||||
|
*/
|
||||||
|
public class GiveTableSubElement {
|
||||||
|
|
||||||
|
@Expose @Getter @Setter private Map<String, Double> items;
|
||||||
|
@Expose @Getter @Setter private Integer maxDrops;
|
||||||
|
@Expose @Getter @Setter private Boolean randomDrops;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package net.aminecraftdev.custombosses.droptable.elements;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Charles Cullen
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 25-Oct-18
|
||||||
|
*/
|
||||||
|
public class RewardsTableElement {
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package net.aminecraftdev.custombosses.droptable.elements;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.Expose;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Charles Cullen
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 25-Oct-18
|
||||||
|
*/
|
||||||
|
public class SprayTableElement extends RewardsTableElement {
|
||||||
|
|
||||||
|
@Expose @Getter @Setter private Map<String, Double> sprayRewards;
|
||||||
|
@Expose @Getter @Setter private Integer sprayMaxDistance, sprayMaxDrops;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,76 @@
|
|||||||
|
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.droptable.DropTable;
|
||||||
|
import net.aminecraftdev.custombosses.utils.file.FileHandler;
|
||||||
|
import net.aminecraftdev.custombosses.utils.itemstack.holder.ItemStackHolder;
|
||||||
|
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.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Charles Cullen
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 25-Oct-18
|
||||||
|
*/
|
||||||
|
public class DropTableFileHandler extends FileHandler<Map<String, DropTable>> {
|
||||||
|
|
||||||
|
private static final Gson GSON = new GsonBuilder()
|
||||||
|
.setPrettyPrinting()
|
||||||
|
.excludeFieldsWithoutExposeAnnotation()
|
||||||
|
.create();
|
||||||
|
|
||||||
|
public DropTableFileHandler(JavaPlugin javaPlugin, boolean saveResource, File file) {
|
||||||
|
super(javaPlugin, saveResource, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, DropTable> loadFile() {
|
||||||
|
Map<String, DropTable> dropTableMap = new HashMap<>();
|
||||||
|
|
||||||
|
createFile();
|
||||||
|
|
||||||
|
try {
|
||||||
|
FileReader fileReader = new FileReader(getFile());
|
||||||
|
JsonObject jsonObject = GSON.fromJson(fileReader, JsonObject.class);
|
||||||
|
|
||||||
|
fileReader.close();
|
||||||
|
|
||||||
|
if(jsonObject != null) {
|
||||||
|
jsonObject.entrySet().forEach(entry -> {
|
||||||
|
String id = entry.getKey();
|
||||||
|
DropTable dropTable = GSON.fromJson(entry.getValue(), DropTable.class);
|
||||||
|
|
||||||
|
dropTableMap.put(id, dropTable);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return dropTableMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveFile(Map<String, DropTable> stringDropTableMap) {
|
||||||
|
try {
|
||||||
|
FileWriter fileWriter = new FileWriter(getFile());
|
||||||
|
Type type = new TypeToken<Map<String, ItemStackHolder>>(){}.getType();
|
||||||
|
|
||||||
|
fileWriter.write(GSON.toJson(new HashMap<>(stringDropTableMap), type));
|
||||||
|
fileWriter.flush();
|
||||||
|
fileWriter.close();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package net.aminecraftdev.custombosses.holder;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import net.aminecraftdev.custombosses.entity.BossEntity;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Charles Cullen
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 25-Oct-18
|
||||||
|
*/
|
||||||
|
public class DeadBossHolder {
|
||||||
|
|
||||||
|
@Getter private final Map<UUID, Double> sortedDamageMap;
|
||||||
|
@Getter private final BossEntity bossEntity;
|
||||||
|
@Getter private final Location location;
|
||||||
|
|
||||||
|
public DeadBossHolder(BossEntity bossEntity, Location deathLocation, Map<UUID, Double> sortedDamageMap) {
|
||||||
|
this.location = deathLocation;
|
||||||
|
this.bossEntity = bossEntity;
|
||||||
|
this.sortedDamageMap = sortedDamageMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,11 +1,14 @@
|
|||||||
package net.aminecraftdev.custombosses.listeners.after;
|
package net.aminecraftdev.custombosses.listeners.after;
|
||||||
|
|
||||||
import net.aminecraftdev.custombosses.CustomBosses;
|
import net.aminecraftdev.custombosses.CustomBosses;
|
||||||
|
import net.aminecraftdev.custombosses.droptable.DropTable;
|
||||||
import net.aminecraftdev.custombosses.entity.BossEntity;
|
import net.aminecraftdev.custombosses.entity.BossEntity;
|
||||||
import net.aminecraftdev.custombosses.events.BossDeathEvent;
|
import net.aminecraftdev.custombosses.events.BossDeathEvent;
|
||||||
import net.aminecraftdev.custombosses.events.PreBossDeathEvent;
|
import net.aminecraftdev.custombosses.events.PreBossDeathEvent;
|
||||||
import net.aminecraftdev.custombosses.holder.ActiveBossHolder;
|
import net.aminecraftdev.custombosses.holder.ActiveBossHolder;
|
||||||
|
import net.aminecraftdev.custombosses.holder.DeadBossHolder;
|
||||||
import net.aminecraftdev.custombosses.managers.BossEntityManager;
|
import net.aminecraftdev.custombosses.managers.BossEntityManager;
|
||||||
|
import net.aminecraftdev.custombosses.utils.Debug;
|
||||||
import net.aminecraftdev.custombosses.utils.NumberUtils;
|
import net.aminecraftdev.custombosses.utils.NumberUtils;
|
||||||
import net.aminecraftdev.custombosses.utils.ServerUtils;
|
import net.aminecraftdev.custombosses.utils.ServerUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -65,6 +68,7 @@ public class BossDeathListener implements Listener {
|
|||||||
BossEntity bossEntity = activeBossHolder.getBossEntity();
|
BossEntity bossEntity = activeBossHolder.getBossEntity();
|
||||||
Location location = event.getLocation();
|
Location location = event.getLocation();
|
||||||
|
|
||||||
|
Map<UUID, Double> mapOfDamage = this.bossEntityManager.getSortedMapOfDamage(activeBossHolder);
|
||||||
List<String> commands = this.bossEntityManager.getOnDeathCommands(bossEntity);
|
List<String> commands = this.bossEntityManager.getOnDeathCommands(bossEntity);
|
||||||
List<String> messages = this.bossEntityManager.getOnDeathMessage(bossEntity);
|
List<String> messages = this.bossEntityManager.getOnDeathMessage(bossEntity);
|
||||||
int messageRadius = this.bossEntityManager.getOnDeathMessageRadius(bossEntity);
|
int messageRadius = this.bossEntityManager.getOnDeathMessageRadius(bossEntity);
|
||||||
@ -79,7 +83,6 @@ public class BossDeathListener implements Listener {
|
|||||||
|
|
||||||
if(messages != null) {
|
if(messages != null) {
|
||||||
if(positionsMessage != null) {
|
if(positionsMessage != null) {
|
||||||
Map<UUID, Double> mapOfDamage = this.bossEntityManager.getSortedMapOfDamage(activeBossHolder);
|
|
||||||
List<String> finalPositionsMessage = new ArrayList<>();
|
List<String> finalPositionsMessage = new ArrayList<>();
|
||||||
int current = 1;
|
int current = 1;
|
||||||
|
|
||||||
@ -132,10 +135,16 @@ public class BossDeathListener implements Listener {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//TODO: Handle DropTable
|
DeadBossHolder deadBossHolder = new DeadBossHolder(bossEntity, location, mapOfDamage);
|
||||||
|
|
||||||
BossDeathEvent bossDeathEvent = new BossDeathEvent(activeBossHolder);
|
BossDeathEvent bossDeathEvent = new BossDeathEvent(activeBossHolder);
|
||||||
|
DropTable dropTable = this.bossEntityManager.getDropTable(bossEntity);
|
||||||
|
|
||||||
|
if(dropTable == null) {
|
||||||
|
Debug.FAILED_TO_FIND_DROP_TABLE.debug(activeBossHolder.getName(), bossEntity.getDrops().getDropTable());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.bossEntityManager.handleDropTable(dropTable, deadBossHolder);
|
||||||
ServerUtils.get().callEvent(bossDeathEvent);
|
ServerUtils.get().callEvent(bossDeathEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,69 @@
|
|||||||
|
package net.aminecraftdev.custombosses.managers;
|
||||||
|
|
||||||
|
import net.aminecraftdev.custombosses.CustomBosses;
|
||||||
|
import net.aminecraftdev.custombosses.api.BossAPI;
|
||||||
|
import net.aminecraftdev.custombosses.droptable.elements.SprayTableElement;
|
||||||
|
import net.aminecraftdev.custombosses.managers.files.ItemsFileManager;
|
||||||
|
import net.aminecraftdev.custombosses.utils.Debug;
|
||||||
|
import net.aminecraftdev.custombosses.utils.RandomUtils;
|
||||||
|
import net.aminecraftdev.custombosses.utils.itemstack.holder.ItemStackHolder;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Charles Cullen
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 25-Oct-18
|
||||||
|
*/
|
||||||
|
public class BossDropTableManager {
|
||||||
|
|
||||||
|
private ItemsFileManager itemsFileManager;
|
||||||
|
|
||||||
|
public BossDropTableManager(CustomBosses plugin) {
|
||||||
|
this.itemsFileManager = plugin.getItemStackManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ItemStack> getSprayItems(SprayTableElement sprayTableElement) {
|
||||||
|
Map<String, Double> rewards = sprayTableElement.getSprayRewards();
|
||||||
|
List<ItemStack> customDrops = new ArrayList<>();
|
||||||
|
Integer maxDropsElement = sprayTableElement.getSprayMaxDrops();
|
||||||
|
|
||||||
|
if(maxDropsElement == null) maxDropsElement = -1;
|
||||||
|
|
||||||
|
final int maxDrops = maxDropsElement;
|
||||||
|
|
||||||
|
for(Map.Entry<String, Double> entry : rewards.entrySet()) {
|
||||||
|
if(maxDrops > 0) {
|
||||||
|
if(customDrops.size() >= maxDrops) return customDrops;
|
||||||
|
}
|
||||||
|
|
||||||
|
double chance = entry.getValue();
|
||||||
|
String itemName = entry.getKey();
|
||||||
|
double randomNumber = RandomUtils.get().getRandomDecimalNumber();
|
||||||
|
|
||||||
|
if(randomNumber > chance) continue;
|
||||||
|
|
||||||
|
ItemStackHolder itemStackHolder = BossAPI.getStoredItemStack(itemName);
|
||||||
|
|
||||||
|
if(itemStackHolder == null) {
|
||||||
|
Debug.FAILED_TO_LOAD_CUSTOM_ITEM.debug(itemName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack itemStack = this.itemsFileManager.getItemStackConverter().from(itemStackHolder);
|
||||||
|
|
||||||
|
if(itemStack == null) {
|
||||||
|
Debug.FAILED_TO_LOAD_CUSTOM_ITEM.debug(itemName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
customDrops.add(itemStack);
|
||||||
|
}
|
||||||
|
|
||||||
|
return customDrops;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,12 +2,13 @@ package net.aminecraftdev.custombosses.managers;
|
|||||||
|
|
||||||
import net.aminecraftdev.custombosses.CustomBosses;
|
import net.aminecraftdev.custombosses.CustomBosses;
|
||||||
import net.aminecraftdev.custombosses.api.BossAPI;
|
import net.aminecraftdev.custombosses.api.BossAPI;
|
||||||
|
import net.aminecraftdev.custombosses.droptable.DropTable;
|
||||||
import net.aminecraftdev.custombosses.entity.BossEntity;
|
import net.aminecraftdev.custombosses.entity.BossEntity;
|
||||||
import net.aminecraftdev.custombosses.holder.ActiveBossHolder;
|
import net.aminecraftdev.custombosses.holder.ActiveBossHolder;
|
||||||
import net.aminecraftdev.custombosses.managers.files.BossCommandFileManager;
|
import net.aminecraftdev.custombosses.holder.DeadBossHolder;
|
||||||
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.managers.files.BossesFileManager;
|
||||||
|
import net.aminecraftdev.custombosses.managers.files.DropTableFileManager;
|
||||||
|
import net.aminecraftdev.custombosses.managers.files.ItemsFileManager;
|
||||||
import net.aminecraftdev.custombosses.utils.Debug;
|
import net.aminecraftdev.custombosses.utils.Debug;
|
||||||
import net.aminecraftdev.custombosses.utils.itemstack.holder.ItemStackHolder;
|
import net.aminecraftdev.custombosses.utils.itemstack.holder.ItemStackHolder;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -26,11 +27,13 @@ public class BossEntityManager {
|
|||||||
|
|
||||||
private static final List<ActiveBossHolder> ACTIVE_BOSS_HOLDERS = new ArrayList<>();
|
private static final List<ActiveBossHolder> ACTIVE_BOSS_HOLDERS = new ArrayList<>();
|
||||||
|
|
||||||
private BossItemFileManager bossItemFileManager;
|
private DropTableFileManager dropTableFileManager;
|
||||||
private BossMechanicManager bossMechanicManager;
|
private BossMechanicManager bossMechanicManager;
|
||||||
|
private ItemsFileManager bossItemFileManager;
|
||||||
private BossesFileManager bossesFileManager;
|
private BossesFileManager bossesFileManager;
|
||||||
|
|
||||||
public BossEntityManager(CustomBosses customBosses) {
|
public BossEntityManager(CustomBosses customBosses) {
|
||||||
|
this.dropTableFileManager = customBosses.getDropTableFileManager();
|
||||||
this.bossMechanicManager = customBosses.getBossMechanicManager();
|
this.bossMechanicManager = customBosses.getBossMechanicManager();
|
||||||
this.bossItemFileManager = customBosses.getItemStackManager();
|
this.bossItemFileManager = customBosses.getItemStackManager();
|
||||||
this.bossesFileManager = customBosses.getBossesFileManager();
|
this.bossesFileManager = customBosses.getBossesFileManager();
|
||||||
@ -211,4 +214,30 @@ public class BossEntityManager {
|
|||||||
return playerDamage / onePercent;
|
return playerDamage / onePercent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DropTable getDropTable(BossEntity bossEntity) {
|
||||||
|
return this.dropTableFileManager.getDropTable(bossEntity.getDrops().getDropTable());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleDropTable(DropTable dropTable, DeadBossHolder deadBossHolder) {
|
||||||
|
String dropType = dropTable.getDropType();
|
||||||
|
BossEntity bossEntity = deadBossHolder.getBossEntity();
|
||||||
|
String tableName = bossEntity.getDrops().getDropTable();
|
||||||
|
|
||||||
|
if(dropType == null) {
|
||||||
|
Debug.FAILED_TO_FIND_DROP_TABLE_TYPE.debug(tableName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(dropType.equalsIgnoreCase("SPRAY")) {
|
||||||
|
|
||||||
|
} else if(dropType.equalsIgnoreCase("GIVE")) {
|
||||||
|
|
||||||
|
} else if(dropType.equalsIgnoreCase("DROP")) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Debug.FAILED_TO_FIND_DROP_TABLE_TYPE.debug(tableName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,12 @@ import java.util.Map;
|
|||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
* @since 17-Oct-18
|
* @since 17-Oct-18
|
||||||
*/
|
*/
|
||||||
public class BossCommandFileManager implements ILoadable, ISavable, IReloadable {
|
public class CommandsFileManager implements ILoadable, ISavable, IReloadable {
|
||||||
|
|
||||||
private Map<String, List<String>> commandsMap = new HashMap<>();
|
private Map<String, List<String>> commandsMap = new HashMap<>();
|
||||||
private CommandsFileHandler commandsFileHandler;
|
private CommandsFileHandler commandsFileHandler;
|
||||||
|
|
||||||
public BossCommandFileManager(CustomBosses customBosses) {
|
public CommandsFileManager(CustomBosses customBosses) {
|
||||||
File file = new File(customBosses.getDataFolder(), "commands.json");
|
File file = new File(customBosses.getDataFolder(), "commands.json");
|
||||||
|
|
||||||
this.commandsFileHandler = new CommandsFileHandler(customBosses, true, file);
|
this.commandsFileHandler = new CommandsFileHandler(customBosses, true, file);
|
@ -0,0 +1,52 @@
|
|||||||
|
package net.aminecraftdev.custombosses.managers.files;
|
||||||
|
|
||||||
|
import net.aminecraftdev.custombosses.droptable.DropTable;
|
||||||
|
import net.aminecraftdev.custombosses.file.DropTableFileHandler;
|
||||||
|
import net.aminecraftdev.custombosses.utils.ILoadable;
|
||||||
|
import net.aminecraftdev.custombosses.utils.IReloadable;
|
||||||
|
import net.aminecraftdev.custombosses.utils.ISavable;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Charles Cullen
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 25-Oct-18
|
||||||
|
*/
|
||||||
|
public class DropTableFileManager implements ILoadable, ISavable, IReloadable {
|
||||||
|
|
||||||
|
private Map<String, DropTable> dropTableMap = new HashMap<>();
|
||||||
|
private DropTableFileHandler dropTableFileHandler;
|
||||||
|
|
||||||
|
public DropTableFileManager(JavaPlugin javaPlugin) {
|
||||||
|
File file = new File(javaPlugin.getDataFolder(), "droptables.json");
|
||||||
|
|
||||||
|
this.dropTableFileHandler = new DropTableFileHandler(javaPlugin, true, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load() {
|
||||||
|
this.dropTableMap = this.dropTableFileHandler.loadFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reload() {
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save() {
|
||||||
|
this.dropTableFileHandler.saveFile(this.dropTableMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DropTable getDropTable(String name) {
|
||||||
|
return this.dropTableMap.getOrDefault(name, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, DropTable> getDropTables() {
|
||||||
|
return new HashMap<>(this.dropTableMap);
|
||||||
|
}
|
||||||
|
}
|
@ -18,14 +18,14 @@ import java.util.Map;
|
|||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
* @since 03-Jun-18
|
* @since 03-Jun-18
|
||||||
*/
|
*/
|
||||||
public class BossItemFileManager implements ILoadable, ISavable, IReloadable {
|
public class ItemsFileManager implements ILoadable, ISavable, IReloadable {
|
||||||
|
|
||||||
@Getter private final ItemStackConverter itemStackConverter = new ItemStackConverter();
|
@Getter private final ItemStackConverter itemStackConverter = new ItemStackConverter();
|
||||||
|
|
||||||
private Map<String, ItemStackHolder> itemStackHolders = new HashMap<>();
|
private Map<String, ItemStackHolder> itemStackHolders = new HashMap<>();
|
||||||
private ItemStackFileHandler itemStackFileHandler;
|
private ItemStackFileHandler itemStackFileHandler;
|
||||||
|
|
||||||
public BossItemFileManager(JavaPlugin javaPlugin) {
|
public ItemsFileManager(JavaPlugin javaPlugin) {
|
||||||
File file = new File(javaPlugin.getDataFolder(), "items.json");
|
File file = new File(javaPlugin.getDataFolder(), "items.json");
|
||||||
|
|
||||||
this.itemStackFileHandler = new ItemStackFileHandler(javaPlugin, file, true);
|
this.itemStackFileHandler = new ItemStackFileHandler(javaPlugin, file, true);
|
@ -16,12 +16,12 @@ import java.util.Map;
|
|||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
* @since 17-Oct-18
|
* @since 17-Oct-18
|
||||||
*/
|
*/
|
||||||
public class BossMessagesFileManager implements ILoadable, ISavable, IReloadable {
|
public class MessagesFileManager implements ILoadable, ISavable, IReloadable {
|
||||||
|
|
||||||
private Map<String, List<String>> messagesMap = new HashMap<>();
|
private Map<String, List<String>> messagesMap = new HashMap<>();
|
||||||
private MessagesFileHandler messagesFileHandler;
|
private MessagesFileHandler messagesFileHandler;
|
||||||
|
|
||||||
public BossMessagesFileManager(CustomBosses customBosses) {
|
public MessagesFileManager(CustomBosses customBosses) {
|
||||||
File file = new File(customBosses.getDataFolder(), "messages.json");
|
File file = new File(customBosses.getDataFolder(), "messages.json");
|
||||||
|
|
||||||
this.messagesFileHandler = new MessagesFileHandler(customBosses, true, file);
|
this.messagesFileHandler = new MessagesFileHandler(customBosses, true, file);
|
@ -20,6 +20,8 @@ public enum Debug {
|
|||||||
|
|
||||||
ATTEMPTED_TO_UPDATE_PLUGIN("Something has attempted to update the PLUGIN variable in the BossAPI class while it is already initialized."),
|
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("A 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_TO_FIND_DROP_TABLE("The {0} boss has been killed however the specified drop table {1} wasn't found."),
|
||||||
|
FAILED_TO_FIND_DROP_TABLE_TYPE("The {0} drop table type was not a valid drop table. Valid types are 'SPRAY', 'DROP', 'GIVE'."),
|
||||||
FAILED_ATTEMPT_TO_SPAWN_BOSS("A boss has attempted to spawn but cannot spawn for the following reason: \n{0}"),
|
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_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_SAVE_THE_NEW_BOSS("The {0} with EntityType boss was successfully created but failed to save."),
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
package net.aminecraftdev.custombosses.utils;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Charles Cullen
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 25-Oct-18
|
||||||
|
*/
|
||||||
|
public class RandomUtils {
|
||||||
|
|
||||||
|
private static RandomUtils INSTANCE = new RandomUtils();
|
||||||
|
|
||||||
|
private Random random = new Random();
|
||||||
|
|
||||||
|
public int getRandomNumber() {
|
||||||
|
return this.random.nextInt(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getRandomDecimalNumber() {
|
||||||
|
double amount = getRandomNumber();
|
||||||
|
|
||||||
|
amount += this.random.nextDouble();
|
||||||
|
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RandomUtils get() {
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
2
pom.xml
2
pom.xml
@ -19,7 +19,7 @@
|
|||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<plugin.version>3.0.0-SNAPSHOT-U30</plugin.version>
|
<plugin.version>3.0.0-SNAPSHOT-U32</plugin.version>
|
||||||
<plugin.name>CustomBosses</plugin.name>
|
<plugin.name>CustomBosses</plugin.name>
|
||||||
<plugin.main>net.aminecraftdev.custombosses.CustomBosses</plugin.main>
|
<plugin.main>net.aminecraftdev.custombosses.CustomBosses</plugin.main>
|
||||||
<plugin.author>AMinecraftDev</plugin.author>
|
<plugin.author>AMinecraftDev</plugin.author>
|
||||||
|
Loading…
Reference in New Issue
Block a user