3.0.0-SNAPSHOT-U25

+ Continued work on GUI
+ 90% completed Bosses List GUI
This commit is contained in:
AMinecraftDev 2018-10-10 23:09:18 +08:00
parent f1d94b52ea
commit 8ad2ae8b3a
16 changed files with 205 additions and 45 deletions

View File

@ -9,7 +9,7 @@
"displayName": "&6&lSkeleton King Boss"
}
],
"spawnItem": "SKSpawnEgg",
"spawnItem": "SKSpawnItem",
"equipment": {
"helmet": "SKHelmet",
"chestplate": "SKChestplate",

View File

@ -1,7 +1,6 @@
{
"SKSpawnItem": {
"type": "383",
"durability": "51",
"type": "SKELETON_SPAWN_EGG",
"name": "&6&lSkeleton King Boss Spawn Egg",
"lore": [
"&7Right click a block to spawn",
@ -9,26 +8,26 @@
]
},
"SKHelmet": {
"type": "gold_helmet",
"type": "GOLDEN_HELMET",
"enchants": [ "protection:4", "unbreaking:3" ]
},
"SKChestplate": {
"type": "gold_chestplate",
"type": "GOLDEN_CHESTPLATE",
"enchants": [ "protection:4", "unbreaking:3" ]
},
"SKLeggings": {
"type": "gold_leggings",
"type": "GOLDEN_LEGGINGS",
"enchants": [ "protection:4", "unbreaking:3" ]
},
"SKBoots": {
"type": "diamond_boots",
"type": "DIAMOND_BOOTS",
"enchants": [ "protection:4", "unbreaking:3" ]
},
"SKMainHand": {
"type": "diamond_sword",
"type": "DIAMOND_SWORD",
"enchants": [ "sharpness:4", "unbreaking:3" ]
},
"SKOffHand": {
"type": "shield"
"type": "SHIELD"
}
}

View File

@ -85,7 +85,10 @@ ListPanel:
name: '{panelName}'
slots: 54
Settings:
backButton: true
fillTo: 45
Buttons:
backButton: 50
Items:
'46':
type: GLASS_PANE

View File

@ -2,5 +2,6 @@ name: ${plugin.name}
main: ${plugin.main}
version: ${plugin.version}
author: ${plugin.author}
api-version: 1.13
#TODO: softdepend:
#TODO: depends:

View File

@ -41,45 +41,33 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
@Override
public void onEnable() {
final long startMs = System.currentTimeMillis();
long beginMs = System.currentTimeMillis();
new BossAPI(this);
new Metrics(this);
System.out.println("Boss API loaded (took " + (System.currentTimeMillis() - beginMs) + "ms)");
beginMs = System.currentTimeMillis();
this.debugManager = new DebugManager();
this.bossPanelManager = new BossPanelManager(this);
this.bossEntityContainer = new BossEntityContainer();
this.bossMechanicManager = new BossMechanicManager(this);
System.out.println("Managers and Containers loaded (took " + (System.currentTimeMillis() - beginMs) + "ms)");
beginMs = System.currentTimeMillis();
loadFileManagersAndHandlers();
System.out.println("File Handlers and File Managers loaded (took " + (System.currentTimeMillis() - beginMs) + "ms)");
beginMs = System.currentTimeMillis();
this.bossPanelManager = new BossPanelManager(this);
createFiles();
reloadFiles();
System.out.println("All default YML files have been created (took " + (System.currentTimeMillis() - beginMs) + "ms)");
beginMs = System.currentTimeMillis();
this.itemStackManager.reload();
this.bossesFileManager.reload();
this.bossCommandManager = new BossCommandManager(new BossCmd(), this);
this.bossPanelManager.load();
this.bossCommandManager.load();
System.out.println("All commands and listeners loaded (took " + (System.currentTimeMillis() - beginMs) + "ms)");
beginMs = System.currentTimeMillis();
reload();
saveMessagesToFile();
System.out.println("Reloaded all fields, saved messages (took " + (System.currentTimeMillis() - beginMs) + "ms) and plugin is now loaded. Took a total of " + (System.currentTimeMillis() - startMs) + "ms.");
this.bossCommandManager.load();
System.out.println("Loaded all fields and managers, saved messages and plugin is initialized and ready to go. (took " + (System.currentTimeMillis() - beginMs) + "ms).");
}
@Override
@ -88,8 +76,7 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
this.bossesFileManager.reload();
this.bossMechanicManager.load();
this.lang = this.langFileHandler.loadFile();
this.editor = this.editorFileHandler.loadFile();
reloadFiles();
this.bossPanelManager.reload();
@ -104,6 +91,11 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
this.editorFileHandler = new EditorFileHandler(this);
}
private void reloadFiles() {
this.lang = this.langFileHandler.loadFile();
this.editor = this.editorFileHandler.loadFile();
}
private void createFiles() {
this.editorFileHandler.createFile();
this.langFileHandler.createFile();

View File

@ -3,8 +3,10 @@ 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.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;
@ -127,4 +129,18 @@ public class BossAPI {
return bossEntity;
}
/**
* Used to obtain an item stack holder
* of the specified item stack from the
* ItemStack bank.
*
* @param name - name of the ItemStack
* @return null if not found, instance if found
*/
public static ItemStackHolder getStoredItemStack(String name) {
BossItemFileManager bossItemFileManager = PLUGIN.getItemStackManager();
return bossItemFileManager.getItemStackHolder(name);
}
}

View File

@ -5,6 +5,7 @@ import net.aminecraftdev.custombosses.CustomBosses;
import net.aminecraftdev.custombosses.panel.*;
import net.aminecraftdev.custombosses.utils.ILoadable;
import net.aminecraftdev.custombosses.utils.IReloadable;
import net.aminecraftdev.custombosses.utils.StringUtils;
import net.aminecraftdev.custombosses.utils.panel.base.IPanelHandler;
import net.aminecraftdev.custombosses.utils.panel.builder.PanelBuilder;
@ -92,7 +93,7 @@ public class BossPanelManager implements ILoadable, IReloadable {
//---------------------------------------------
private void loadCustomBossesMenu() {
this.bosses = new CustomBossesPanel(this, getListMenu(this.customBossesTitle));
this.bosses = new CustomBossesPanel(this, getListMenu(this.customBossesTitle), this.customBosses);
}
private void reloadCustomBosses() {
@ -150,7 +151,7 @@ public class BossPanelManager implements ILoadable, IReloadable {
private PanelBuilder getListMenu(String name) {
Map<String, String> replaceMap = new HashMap<>();
replaceMap.put("{panelName}", name);
replaceMap.put("{panelName}", StringUtils.get().translateColor(name));
return new PanelBuilder(this.customBosses.getEditor().getConfigurationSection("ListPanel"), replaceMap);
}

View File

@ -50,4 +50,8 @@ public class BossItemFileManager implements ILoadable, ISavable, IReloadable {
return this.itemStackHolders.getOrDefault(name, null);
}
public Map<String, ItemStackHolder> getItemStackHolders() {
return new HashMap<>(this.itemStackHolders);
}
}

View File

@ -1,24 +1,92 @@
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.BossPanelManager;
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.StringUtils;
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;
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 10-Oct-18
*
* TODO
*/
public class CustomBossesPanel extends PanelHandler {
public CustomBossesPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder) {
private BossItemFileManager bossItemFileManager;
private BossesFileManager bossesFileManager;
public CustomBossesPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses customBosses) {
super(bossPanelManager, panelBuilder);
this.bossItemFileManager = customBosses.getItemStackManager();
this.bossesFileManager = customBosses.getBossesFileManager();
this.panel.setParentPanel(this.bossPanelManager.getMainMenu().getPanel());
fillPanel();
}
@Override
public void fillPanel() {
this.panel.setParentPanel(this.bossPanelManager.getMainMenu().getPanel());
Map<String, BossEntity> currentEntities = new HashMap<>(this.bossesFileManager.getBossEntities());
List<String> entryList = new ArrayList<>(currentEntities.keySet());
int maxPage = this.panel.getMaxPage(entryList);
this.panel.setOnPageChange(((player, currentPage, requestedPage) -> {
if(requestedPage < 0 || requestedPage > maxPage) return false;
loadPage(requestedPage, currentEntities, entryList);
return true;
}));
loadPage(0, currentEntities, entryList);
}
private void loadPage(int page, Map<String, BossEntity> bossEntityMap, List<String> entryList) {
int fillTo = getPanel().getPanelBuilderSettings().getFillTo();
int startIndex = page * fillTo;
for(int i = startIndex; i < startIndex + fillTo; i++) {
if(i >= bossEntityMap.size()) {
// getPanel().setItem(i-startIndex, new ItemStack(Material.AIR), e -> {});
} 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.bossItemFileManager.getItemStackConverter().from(itemStackHolder);
if(itemStack == null) {
Debug.FAILED_TO_LOAD_CUSTOM_ITEM.debug(entity.getSpawnItem(), name);
// getPanel().setItem(i-startIndex, new ItemStack(Material.AIR), e -> {});
continue;
}
System.out.println("--- ITEM SET ---");
System.out.println(itemStack);
getPanel().setItem(i-startIndex, itemStack, e -> {});
System.out.println(getPanel().getInventory().getItem(i-startIndex));
}
}
}
}

View File

@ -1,10 +1,13 @@
package net.aminecraftdev.custombosses.panel;
import net.aminecraftdev.custombosses.managers.BossPanelManager;
import net.aminecraftdev.custombosses.utils.Message;
import net.aminecraftdev.custombosses.utils.panel.base.ClickAction;
import net.aminecraftdev.custombosses.utils.panel.base.PanelHandler;
import net.aminecraftdev.custombosses.utils.panel.builder.PanelBuilder;
import net.aminecraftdev.custombosses.utils.panel.builder.PanelBuilderCounter;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
/**
* @author Charles Cullen
@ -22,15 +25,80 @@ public class MainMenuPanel extends PanelHandler {
PanelBuilderCounter panelBuilderCounter = panelBuilder.getPanelBuilderCounter();
panelBuilderCounter
.addSlotCounter("CustomBosses", event -> this.bossPanelManager.getBosses().openFor((Player) event.getWhoClicked()))
.addSlotCounter("CustomItems", event -> this.bossPanelManager.getCustomItems().openFor((Player) event.getWhoClicked()))
.addSlotCounter("AutoSpawns", event -> this.bossPanelManager.getAutoSpawns().openFor((Player) event.getWhoClicked()))
.addSlotCounter("DropTables", event -> this.bossPanelManager.getDropTables().openFor((Player) event.getWhoClicked()))
.addSlotCounter("CustomSkills", event -> this.bossPanelManager.getCustomSkills().openFor((Player) event.getWhoClicked()));
.addSlotCounter("CustomBosses", getBossesAction())
.addSlotCounter("CustomItems", getCustomItemsAction())
.addSlotCounter("AutoSpawns", getAutoSpawnsAction())
.addSlotCounter("DropTables", getDropTablesAction())
.addSlotCounter("CustomSkills", getCustomSkillsAction());
this.panel = panelBuilder.getPanel()
.setCancelClick(true)
.setDestroyWhenDone(false)
.setCancelLowerClick(true);
}
private ClickAction getBossesAction() {
return event -> {
Player player = (Player) event.getWhoClicked();
if(event.getClick() == ClickType.LEFT || event.getClick() == ClickType.SHIFT_LEFT) {
this.bossPanelManager.getBosses().openFor(player);
} else if(event.getClick() == ClickType.RIGHT || event.getClick() == ClickType.SHIFT_RIGHT) {
Message.Boss_Create_InvalidArgs.msg(player);
player.closeInventory();
}
};
}
private ClickAction getCustomItemsAction() {
return event -> {
Player player = (Player) event.getWhoClicked();
if(event.getClick() == ClickType.LEFT || event.getClick() == ClickType.SHIFT_LEFT) {
this.bossPanelManager.getCustomItems().openFor(player);
} else if(event.getClick() == ClickType.RIGHT || event.getClick() == ClickType.SHIFT_RIGHT) {
//TODO: Set up create item inventory
player.closeInventory();
}
};
}
private ClickAction getAutoSpawnsAction() {
return event -> {
Player player = (Player) event.getWhoClicked();
if(event.getClick() == ClickType.LEFT || event.getClick() == ClickType.SHIFT_LEFT) {
this.bossPanelManager.getAutoSpawns().openFor(player);
} else if(event.getClick() == ClickType.RIGHT || event.getClick() == ClickType.SHIFT_RIGHT) {
//TODO: Set up create auto spawn command
player.closeInventory();
}
};
}
private ClickAction getDropTablesAction() {
return event -> {
Player player = (Player) event.getWhoClicked();
if(event.getClick() == ClickType.LEFT || event.getClick() == ClickType.SHIFT_LEFT) {
this.bossPanelManager.getDropTables().openFor(player);
} else if(event.getClick() == ClickType.RIGHT || event.getClick() == ClickType.SHIFT_RIGHT) {
//TODO: Set up create drop table command
player.closeInventory();
}
};
}
private ClickAction getCustomSkillsAction() {
return event -> {
Player player = (Player) event.getWhoClicked();
if(event.getClick() == ClickType.LEFT || event.getClick() == ClickType.SHIFT_LEFT) {
this.bossPanelManager.getCustomSkills().openFor(player);
} else if(event.getClick() == ClickType.RIGHT || event.getClick() == ClickType.SHIFT_RIGHT) {
//TODO: Set up create skills command
player.closeInventory();
}
};
}
}

View File

@ -20,6 +20,7 @@ public enum Debug {
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."),
MECHANIC_TYPE_NOT_STORED("This mechanic type is not stored, therefore will not be applied. Valid mechanic types are IOptionalMechanic and IPrimaryMechanic.");

View File

@ -31,6 +31,7 @@ public enum Message {
Boss_DropTable_NoPermission("&c&l(!) &cYou do not have access to this command."),
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_Help_Page1(
"&8&m----*--------&6&l[ &e&lBoss Help &7(Page 1) &6&l]&8&m--------*----\n" +

View File

@ -169,7 +169,7 @@ public class ItemStackUtils {
itemStack.setDurability(dura);
}
if(configurationSection.contains("owner") && itemStack.getType() == Material.LEGACY_SKULL_ITEM) {
if(configurationSection.contains("owner") && itemStack.getType() == Material.PLAYER_HEAD) {
SkullMeta skullMeta = (SkullMeta) itemStack.getItemMeta();
skullMeta.setOwner(owner);

View File

@ -454,6 +454,14 @@ public class Panel implements Listener, ICloneable<Panel> {
return panel;
}
public int getMaxPage(List<?> list) {
return (int) Math.ceil((double) list.size() / (double) getPanelBuilderSettings().getFillTo()) - 1;
}
public int getMaxPage(Map<?,?> map) {
return (int) Math.ceil((double) map.size() / (double) getPanelBuilderSettings().getFillTo()) - 1;
}
//--------------------------------------------------
//
// P A N E L S T A T I C M E T H O D

View File

@ -29,8 +29,6 @@ public class PanelHandler implements IPanelHandler {
.setDestroyWhenDone(false)
.setCancelClick(true)
.setCancelLowerClick(true);
fillPanel();
}
@Override

View File

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