mirror of
https://github.com/songoda/EpicBosses.git
synced 2025-03-12 22:49:13 +01:00
1.0.0-SNAPSHOT-U53
+ Added BossShop command + Added ShopPanel + Updated bosses.json to have supporting shop variables + Added shop permissions + Added Shop messages + Added Vault dependency support + Updated Panel to have a loadPage method to reduce the repetitive code for loading pages from a list panel
This commit is contained in:
parent
77975dd912
commit
208871c719
@ -1,8 +1,10 @@
|
||||
{
|
||||
"SkeletonKing": {
|
||||
"editing": true,
|
||||
"spawnItem": "SKSpawnItem",
|
||||
"targeting": "RandomNearby",
|
||||
"editing": true,
|
||||
"buyable": true,
|
||||
"price": 500000.0,
|
||||
"entityStats": [
|
||||
{
|
||||
"mainStats": {
|
||||
|
@ -10,6 +10,7 @@ Settings:
|
||||
- 'world_the_end'
|
||||
- 'world_nether'
|
||||
Toggles:
|
||||
bossShop: true
|
||||
endermanTeleporting: true
|
||||
potionsAffectingBoss: true
|
||||
Limits:
|
||||
@ -32,7 +33,10 @@ Hooks:
|
||||
- 'blocked_region1'
|
||||
- 'blocked_region2'
|
||||
Display:
|
||||
AutoSpawns:
|
||||
menuName: '&b&lEpicBosses &3&lAutoSpawns'
|
||||
Bosses:
|
||||
menuName: '&b&lEpicBosses &3&lItems'
|
||||
name: '&b&l{name}'
|
||||
lore:
|
||||
- '&3Editing: &f{enabled}'
|
||||
@ -42,4 +46,15 @@ Display:
|
||||
- '&7boss.'
|
||||
- '&7'
|
||||
- '&3Right Click »'
|
||||
- '&7Edit the custom boss.'
|
||||
- '&7Edit the custom boss.'
|
||||
DropTable:
|
||||
menuName: '&b&lEpicBosses &3&lDropTables'
|
||||
Items:
|
||||
menuName: '&b&lEpicBosses &3&lCustom Items'
|
||||
Shop:
|
||||
menuName: '&b&lEpicBosses &3&lShop'
|
||||
name: '&b&lBuy {name}''s Egg'
|
||||
lore:
|
||||
- '&3Cost: &a$&f{price}'
|
||||
Skills:
|
||||
menuName: '&b&lEpicBosses &3&lSkills'
|
@ -1,6 +1,7 @@
|
||||
package com.songoda.epicbosses;
|
||||
|
||||
import com.songoda.epicbosses.container.MinionEntityContainer;
|
||||
import com.songoda.epicbosses.utils.dependencies.VaultHelper;
|
||||
import lombok.Getter;
|
||||
import com.songoda.epicbosses.api.BossAPI;
|
||||
import com.songoda.epicbosses.commands.BossCmd;
|
||||
@ -56,19 +57,27 @@ public class CustomBosses extends JavaPlugin implements IReloadable {
|
||||
@Getter private VersionHandler versionHandler;
|
||||
@Getter private DebugManager debugManager;
|
||||
|
||||
|
||||
@Getter private YmlFileHandler langFileHandler, editorFileHandler, configFileHandler;
|
||||
@Getter private FileConfiguration lang, editor, config;
|
||||
|
||||
@Getter private VaultHelper vaultHelper;
|
||||
|
||||
@Getter private boolean debug = false;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Debug.setPlugin(this);
|
||||
|
||||
instance = this;
|
||||
vaultHelper = new VaultHelper();
|
||||
|
||||
long beginMs = System.currentTimeMillis();
|
||||
|
||||
Debug.setPlugin(this);
|
||||
if(!this.vaultHelper.isConnected()) {
|
||||
Debug.FAILED_TO_CONNECT_TO_VAULT.debug();
|
||||
return;
|
||||
}
|
||||
|
||||
new BossAPI(this);
|
||||
new Metrics(this);
|
||||
new ServerUtils(this);
|
||||
|
@ -189,7 +189,7 @@ public class BossAPI {
|
||||
MessagesElement messagesElement = new MessagesElement();
|
||||
CommandsElement commandsElement = new CommandsElement();
|
||||
|
||||
BossEntity bossEntity = new BossEntity(true, null, entityStatsElements, skillsElement, dropsElement, messagesElement, commandsElement);
|
||||
BossEntity bossEntity = new BossEntity(true, null, false, 100.0, entityStatsElements, skillsElement, dropsElement, messagesElement, commandsElement);
|
||||
boolean result = PLUGIN.getBossEntityContainer().saveData(name, bossEntity);
|
||||
|
||||
if (!result) {
|
||||
|
@ -2,6 +2,7 @@ package com.songoda.epicbosses.commands.boss;
|
||||
|
||||
import com.songoda.epicbosses.utils.Message;
|
||||
import com.songoda.epicbosses.utils.NumberUtils;
|
||||
import com.songoda.epicbosses.utils.Permission;
|
||||
import com.songoda.epicbosses.utils.command.SubCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@ -18,25 +19,31 @@ public class BossHelpCmd extends SubCommand {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
int pageNumber = 0;
|
||||
if(Permission.admin.hasPermission(sender) || Permission.help.hasPermission(sender)) {
|
||||
int pageNumber = 0;
|
||||
|
||||
if(args.length > 1) {
|
||||
Integer newNumber = NumberUtils.get().getInteger(args[1]);
|
||||
if(args.length > 1) {
|
||||
Integer newNumber = NumberUtils.get().getInteger(args[1]);
|
||||
|
||||
if(newNumber != null) pageNumber = newNumber;
|
||||
if(newNumber != null) pageNumber = newNumber;
|
||||
}
|
||||
|
||||
switch (pageNumber) {
|
||||
default:
|
||||
case 1:
|
||||
Message.Boss_Help_Page1.msg(sender);
|
||||
break;
|
||||
case 2:
|
||||
Message.Boss_Help_Page2.msg(sender);
|
||||
break;
|
||||
case 3:
|
||||
Message.Boss_Help_Page3.msg(sender);
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
switch (pageNumber) {
|
||||
default:
|
||||
case 1:
|
||||
Message.Boss_Help_Page1.msg(sender);
|
||||
break;
|
||||
case 2:
|
||||
Message.Boss_Help_Page2.msg(sender);
|
||||
break;
|
||||
case 3:
|
||||
Message.Boss_Help_Page3.msg(sender);
|
||||
break;
|
||||
}
|
||||
Message.Boss_Help_NoPermission.msg(sender);
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,46 @@
|
||||
package com.songoda.epicbosses.commands.boss;
|
||||
|
||||
import com.songoda.epicbosses.CustomBosses;
|
||||
import com.songoda.epicbosses.utils.Message;
|
||||
import com.songoda.epicbosses.utils.Permission;
|
||||
import com.songoda.epicbosses.utils.command.SubCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 10-Oct-18
|
||||
*
|
||||
* TODO
|
||||
*/
|
||||
public class BossShopCmd extends SubCommand {
|
||||
|
||||
public BossShopCmd() {
|
||||
private CustomBosses plugin;
|
||||
|
||||
public BossShopCmd(CustomBosses plugin) {
|
||||
super("shop", "buy", "store");
|
||||
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!Permission.shop.hasPermission(sender)) {
|
||||
Message.Boss_Shop_NoPermission.msg(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!(sender instanceof Player)) {
|
||||
Message.General_MustBePlayer.msg(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!this.plugin.getConfig().getBoolean("Toggles.bossShop", true)) {
|
||||
Message.Boss_Shop_Disabled.msg(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
|
||||
plugin.getBossPanelManager().getShopPanel().openFor(player);
|
||||
}
|
||||
}
|
||||
|
@ -15,16 +15,17 @@ import java.util.List;
|
||||
*/
|
||||
public class BossEntity {
|
||||
|
||||
@Expose @Getter @Setter private String spawnItem, targeting;
|
||||
@Expose @Getter @Setter private boolean editing, buyable;
|
||||
@Expose @Getter @Setter private Double price;
|
||||
|
||||
@Expose @Getter private final List<EntityStatsElement> entityStats;
|
||||
@Expose @Getter private final MessagesElement messages;
|
||||
@Expose @Getter private final CommandsElement commands;
|
||||
@Expose @Getter private final SkillsElement skills;
|
||||
@Expose @Getter private final DropsElement drops;
|
||||
|
||||
@Expose @Getter @Setter private String spawnItem, targeting;
|
||||
@Expose @Getter @Setter private boolean editing;
|
||||
|
||||
public BossEntity(boolean editing, String spawnItem, List<EntityStatsElement> entityStats, SkillsElement skills, DropsElement drops, MessagesElement messages, CommandsElement commands) {
|
||||
public BossEntity(boolean editing, String spawnItem, boolean buyable, Double price, List<EntityStatsElement> entityStats, SkillsElement skills, DropsElement drops, MessagesElement messages, CommandsElement commands) {
|
||||
this.editing = editing;
|
||||
this.entityStats = entityStats;
|
||||
this.spawnItem = spawnItem;
|
||||
@ -32,11 +33,11 @@ public class BossEntity {
|
||||
this.drops = drops;
|
||||
this.messages = messages;
|
||||
this.commands = commands;
|
||||
this.buyable = buyable;
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public boolean isCompleteEnoughToSpawn() {
|
||||
boolean complete = true;
|
||||
|
||||
if(this.entityStats == null) return false;
|
||||
|
||||
EntityStatsElement entityStatsElement = this.entityStats.get(0);
|
||||
@ -49,4 +50,8 @@ public class BossEntity {
|
||||
|
||||
return mainStatsElement.getPosition() != null && mainStatsElement.getEntityType() != null && mainStatsElement.getHealth() != null;
|
||||
}
|
||||
|
||||
public boolean canBeBought() {
|
||||
return /*!isEditing() &&*/ isBuyable() && (getPrice() != null) && isCompleteEnoughToSpawn();
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ public class BossCommandManager implements ILoadable {
|
||||
this.commandService.registerSubCommand(new BossMenuCmd(this.customBosses.getBossPanelManager()));
|
||||
this.commandService.registerSubCommand(new BossNearbyCmd(this.customBosses));
|
||||
this.commandService.registerSubCommand(new BossReloadCmd(this.customBosses, this.customBosses.getBossEntityManager()));
|
||||
this.commandService.registerSubCommand(new BossShopCmd());
|
||||
this.commandService.registerSubCommand(new BossShopCmd(this.customBosses));
|
||||
this.commandService.registerSubCommand(new BossSkillsCmd(this.customBosses.getBossPanelManager()));
|
||||
this.commandService.registerSubCommand(new BossSpawnCmd());
|
||||
this.commandService.registerSubCommand(new BossTimeCmd());
|
||||
|
@ -240,10 +240,10 @@ public class BossEntityManager {
|
||||
}
|
||||
|
||||
public Map<BossEntity, ItemStack> getMapOfEntitiesAndSpawnItems() {
|
||||
Map<String, BossEntity> currentEntities = new HashMap<>(this.bossesFileManager.getBossEntities());
|
||||
List<BossEntity> currentEntities = this.bossesFileManager.getBossEntities();
|
||||
Map<BossEntity, ItemStack> newMap = new HashMap<>();
|
||||
|
||||
currentEntities.forEach((name, bossEntity) -> newMap.put(bossEntity, getSpawnItem(bossEntity)));
|
||||
currentEntities.forEach(bossEntity -> newMap.put(bossEntity, getSpawnItem(bossEntity)));
|
||||
|
||||
return newMap;
|
||||
}
|
||||
|
@ -19,11 +19,8 @@ import java.util.Map;
|
||||
*/
|
||||
public class BossPanelManager implements ILoadable, IReloadable {
|
||||
|
||||
@Getter private IPanelHandler mainMenu, customItems, bosses, autoSpawns, dropTables, customSkills;
|
||||
@Getter private IPanelHandler mainMenu, customItems, bosses, autoSpawns, dropTables, customSkills, shopPanel;
|
||||
|
||||
private final String customItemsTitle = "&6&lCustomBosses &e&lItems", autoSpawnsTitle = "&6&lCustomBosses &e&lAutoSpawns",
|
||||
customBossesTitle = "&6&lCustomBosses &e&lBosses", customSkillsTitle = "&6&lCustomBosses &e&lSkills",
|
||||
dropTableTitle = "&6&lCustomBosses &e&lDropTable";
|
||||
private final CustomBosses customBosses;
|
||||
|
||||
public BossPanelManager(CustomBosses customBosses) {
|
||||
@ -33,6 +30,7 @@ public class BossPanelManager implements ILoadable, IReloadable {
|
||||
@Override
|
||||
public void load() {
|
||||
loadMainMenu();
|
||||
loadShopMenu();
|
||||
|
||||
loadAutoSpawnsMenu();
|
||||
loadCustomBossesMenu();
|
||||
@ -45,6 +43,7 @@ public class BossPanelManager implements ILoadable, IReloadable {
|
||||
@Override
|
||||
public void reload() {
|
||||
reloadMainMenu();
|
||||
reloadShopMenu();
|
||||
|
||||
reloadAutoSpawnsMenu();
|
||||
reloadCustomBosses();
|
||||
@ -54,6 +53,20 @@ public class BossPanelManager implements ILoadable, IReloadable {
|
||||
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
//
|
||||
// S H O P P A N E L
|
||||
//
|
||||
//---------------------------------------------
|
||||
|
||||
private void loadShopMenu() {
|
||||
this.shopPanel = new ShopPanel(this, getListMenu("Shop"), this.customBosses);
|
||||
}
|
||||
|
||||
private void reloadShopMenu() {
|
||||
this.shopPanel.initializePanel(getListMenu("Shop"));
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
//
|
||||
// M A I N M E N U P A N E L
|
||||
@ -79,11 +92,11 @@ public class BossPanelManager implements ILoadable, IReloadable {
|
||||
//---------------------------------------------
|
||||
|
||||
private void loadAutoSpawnsMenu() {
|
||||
this.autoSpawns = new AutoSpawnsPanel(this, getListMenu(this.autoSpawnsTitle));
|
||||
this.autoSpawns = new AutoSpawnsPanel(this, getListMenu("AutoSpawns"));
|
||||
}
|
||||
|
||||
private void reloadAutoSpawnsMenu() {
|
||||
this.autoSpawns.initializePanel(getListMenu(this.autoSpawnsTitle));
|
||||
this.autoSpawns.initializePanel(getListMenu("AutoSpawns"));
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
@ -93,11 +106,11 @@ public class BossPanelManager implements ILoadable, IReloadable {
|
||||
//---------------------------------------------
|
||||
|
||||
private void loadCustomBossesMenu() {
|
||||
this.bosses = new CustomBossesPanel(this, getListMenu(this.customBossesTitle), this.customBosses);
|
||||
this.bosses = new CustomBossesPanel(this, getListMenu("Bosses"), this.customBosses);
|
||||
}
|
||||
|
||||
private void reloadCustomBosses() {
|
||||
this.bosses.initializePanel(getListMenu(this.customBossesTitle));
|
||||
this.bosses.initializePanel(getListMenu("Bosses"));
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
@ -107,11 +120,11 @@ public class BossPanelManager implements ILoadable, IReloadable {
|
||||
//---------------------------------------------
|
||||
|
||||
private void loadCustomSkillsMenu() {
|
||||
this.customSkills = new CustomSkillsPanel(this, getListMenu(this.customSkillsTitle));
|
||||
this.customSkills = new CustomSkillsPanel(this, getListMenu("Skills"));
|
||||
}
|
||||
|
||||
private void reloadCustomSkills() {
|
||||
this.customSkills.initializePanel(getListMenu(this.customSkillsTitle));
|
||||
this.customSkills.initializePanel(getListMenu("Skills"));
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
@ -121,11 +134,11 @@ public class BossPanelManager implements ILoadable, IReloadable {
|
||||
//---------------------------------------------
|
||||
|
||||
private void loadDropTableMenu() {
|
||||
this.dropTables = new DropTablePanel(this, getListMenu(this.dropTableTitle));
|
||||
this.dropTables = new DropTablePanel(this, getListMenu("DropTable"));
|
||||
}
|
||||
|
||||
private void reloadDropTable() {
|
||||
this.dropTables.initializePanel(getListMenu(this.dropTableTitle));
|
||||
this.dropTables.initializePanel(getListMenu("DropTable"));
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
@ -135,11 +148,11 @@ public class BossPanelManager implements ILoadable, IReloadable {
|
||||
//---------------------------------------------
|
||||
|
||||
private void loadCustomItemsMenu() {
|
||||
this.customItems = new CustomItemsPanel(this, getListMenu(this.customItemsTitle));
|
||||
this.customItems = new CustomItemsPanel(this, getListMenu("Items"));
|
||||
}
|
||||
|
||||
private void reloadCustomItems() {
|
||||
this.customItems.initializePanel(getListMenu(this.customItemsTitle));
|
||||
this.customItems.initializePanel(getListMenu("Items"));
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
@ -148,13 +161,16 @@ public class BossPanelManager implements ILoadable, IReloadable {
|
||||
//
|
||||
//---------------------------------------------
|
||||
|
||||
private PanelBuilder getListMenu(String name) {
|
||||
private PanelBuilder getListMenu(String path) {
|
||||
Map<String, String> replaceMap = new HashMap<>();
|
||||
|
||||
replaceMap.put("{panelName}", StringUtils.get().translateColor(name));
|
||||
replaceMap.put("{panelName}", StringUtils.get().translateColor(this.customBosses.getConfig().getString(getPath(path))));
|
||||
|
||||
return new PanelBuilder(this.customBosses.getEditor().getConfigurationSection("ListPanel"), replaceMap);
|
||||
}
|
||||
|
||||
private String getPath(String key) {
|
||||
return "Display." + key + ".menuName";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ import com.songoda.epicbosses.utils.IReloadable;
|
||||
import com.songoda.epicbosses.utils.ISavable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -55,7 +57,11 @@ public class BossesFileManager implements ILoadable, ISavable, IReloadable {
|
||||
return this.bossEntityContainer.getData().getOrDefault(name, null);
|
||||
}
|
||||
|
||||
public Map<String, BossEntity> getBossEntities() {
|
||||
return this.bossEntityContainer.getData();
|
||||
public Map<String, BossEntity> getBossEntitiesMap() {
|
||||
return new HashMap<>(this.bossEntityContainer.getData());
|
||||
}
|
||||
|
||||
public List<BossEntity> getBossEntities() {
|
||||
return new ArrayList<>(this.bossEntityContainer.getData().values());
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public class CustomBossesPanel extends PanelHandler {
|
||||
|
||||
@Override
|
||||
public void fillPanel(Panel panel) {
|
||||
Map<String, BossEntity> currentEntities = new HashMap<>(this.bossesFileManager.getBossEntities());
|
||||
Map<String, BossEntity> currentEntities = this.bossesFileManager.getBossEntitiesMap();
|
||||
List<String> entryList = new ArrayList<>(currentEntities.keySet());
|
||||
int maxPage = panel.getMaxPage(entryList);
|
||||
|
||||
@ -75,32 +75,28 @@ public class CustomBossesPanel extends PanelHandler {
|
||||
}
|
||||
|
||||
private void loadPage(Panel panel, int page, Map<String, BossEntity> bossEntityMap, List<String> entryList) {
|
||||
int fillTo = panel.getPanelBuilderSettings().getFillTo();
|
||||
int startIndex = page * fillTo;
|
||||
|
||||
for(int i = startIndex; i < startIndex + fillTo; i++) {
|
||||
if(i >= bossEntityMap.size()) {
|
||||
panel.setItem(i-startIndex, new ItemStack(Material.AIR), e -> {});
|
||||
panel.loadPage(page, (slot, realisticSlot) -> {
|
||||
if(slot >= bossEntityMap.size()) {
|
||||
panel.setItem(realisticSlot, new ItemStack(Material.AIR), e -> {});
|
||||
} else {
|
||||
String name = entryList.get(i);
|
||||
String name = entryList.get(slot);
|
||||
|
||||
BossEntity entity = bossEntityMap.get(name);
|
||||
ItemStack itemStack = this.bossEntityManager.getDisplaySpawnItem(entity);
|
||||
|
||||
if(itemStack == null) {
|
||||
panel.setItem(i-startIndex, new ItemStack(Material.AIR), e -> {});
|
||||
continue;
|
||||
itemStack = new ItemStack(Material.BARRIER);
|
||||
}
|
||||
|
||||
Map<String, String> replaceMap = new HashMap<>();
|
||||
ItemStack clone = itemStack.clone();
|
||||
|
||||
replaceMap.put("{name}", name);
|
||||
replaceMap.put("{enabled}", ""+entity.isEditing());
|
||||
|
||||
ItemStackUtils.applyDisplayName(clone, this.customBosses.getConfig().getString("Display.Bosses.name"), replaceMap);
|
||||
ItemStackUtils.applyDisplayLore(clone, this.customBosses.getConfig().getStringList("Display.Bosses.lore"), replaceMap);
|
||||
ItemStackUtils.applyDisplayName(itemStack, this.customBosses.getConfig().getString("Display.Bosses.name"), replaceMap);
|
||||
ItemStackUtils.applyDisplayLore(itemStack, this.customBosses.getConfig().getStringList("Display.Bosses.lore"), replaceMap);
|
||||
|
||||
panel.setItem(i-startIndex, clone, e -> {
|
||||
panel.setItem(realisticSlot, itemStack, e -> {
|
||||
if(e.getClick() == ClickType.RIGHT || e.getClick() == ClickType.SHIFT_RIGHT) {
|
||||
//TODO
|
||||
} else if(e.getClick() == ClickType.LEFT || e.getClick() == ClickType.SHIFT_LEFT) {
|
||||
@ -115,6 +111,6 @@ public class CustomBossesPanel extends PanelHandler {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,122 @@
|
||||
package com.songoda.epicbosses.panel;
|
||||
|
||||
import com.songoda.epicbosses.CustomBosses;
|
||||
import com.songoda.epicbosses.entity.BossEntity;
|
||||
import com.songoda.epicbosses.managers.BossEntityManager;
|
||||
import com.songoda.epicbosses.managers.BossPanelManager;
|
||||
import com.songoda.epicbosses.managers.files.BossesFileManager;
|
||||
import com.songoda.epicbosses.utils.Debug;
|
||||
import com.songoda.epicbosses.utils.Message;
|
||||
import com.songoda.epicbosses.utils.NumberUtils;
|
||||
import com.songoda.epicbosses.utils.dependencies.VaultHelper;
|
||||
import com.songoda.epicbosses.utils.itemstack.ItemStackUtils;
|
||||
import com.songoda.epicbosses.utils.panel.Panel;
|
||||
import com.songoda.epicbosses.utils.panel.base.PanelHandler;
|
||||
import com.songoda.epicbosses.utils.panel.builder.PanelBuilder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 17-Nov-18
|
||||
*/
|
||||
public class ShopPanel extends PanelHandler {
|
||||
|
||||
private BossEntityManager bossEntityManager;
|
||||
private BossesFileManager bossesFileManager;
|
||||
private VaultHelper vaultHelper;
|
||||
private CustomBosses plugin;
|
||||
|
||||
public ShopPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) {
|
||||
super(bossPanelManager, panelBuilder);
|
||||
|
||||
this.plugin = plugin;
|
||||
this.vaultHelper = plugin.getVaultHelper();
|
||||
this.bossEntityManager = plugin.getBossEntityManager();
|
||||
this.bossesFileManager = plugin.getBossesFileManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializePanel(PanelBuilder panelBuilder) {}
|
||||
|
||||
@Override
|
||||
public void fillPanel(Panel panel) {
|
||||
Map<String, BossEntity> currentEntities = this.bossesFileManager.getBossEntitiesMap();
|
||||
Map<String, BossEntity> filteredMap = currentEntities.entrySet().stream()
|
||||
.filter(entry -> entry.getValue().canBeBought())
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
List<String> entryList = new ArrayList<>(filteredMap.keySet());
|
||||
int maxPage = panel.getMaxPage(filteredMap);
|
||||
|
||||
panel.setOnPageChange(((player, currentPage, requestedPage) -> {
|
||||
if(requestedPage < 0 || requestedPage > maxPage) return false;
|
||||
|
||||
loadPage(panel, requestedPage, entryList, filteredMap);
|
||||
return true;
|
||||
}));
|
||||
|
||||
loadPage(panel, 0, entryList, filteredMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openFor(Player player) {
|
||||
Panel panel = getPanelBuilder().getPanel()
|
||||
.setDestroyWhenDone(true)
|
||||
.setCancelClick(true)
|
||||
.setCancelLowerClick(true);
|
||||
|
||||
fillPanel(panel);
|
||||
panel.openFor(player);
|
||||
}
|
||||
|
||||
private void loadPage(Panel panel, int page, List<String> entryList, Map<String, BossEntity> filteredMap) {
|
||||
panel.loadPage(page, ((slot, realisticSlot) -> {
|
||||
if(slot >= filteredMap.size()) {
|
||||
panel.setItem(realisticSlot, new ItemStack(Material.AIR), e -> {});
|
||||
} else {
|
||||
String name = entryList.get(slot);
|
||||
BossEntity bossEntity = filteredMap.get(name);
|
||||
ItemStack itemStack = this.bossEntityManager.getDisplaySpawnItem(bossEntity);
|
||||
double price = bossEntity.getPrice();
|
||||
|
||||
if(itemStack == null) {
|
||||
itemStack = new ItemStack(Material.BARRIER);
|
||||
}
|
||||
|
||||
Map<String, String> replaceMap = new HashMap<>();
|
||||
|
||||
replaceMap.put("{name}", name);
|
||||
replaceMap.put("{price}", NumberUtils.get().formatDouble(price));
|
||||
|
||||
ItemStackUtils.applyDisplayName(itemStack, this.plugin.getConfig().getString("Display.Shop.name"), replaceMap);
|
||||
ItemStackUtils.applyDisplayLore(itemStack, this.plugin.getConfig().getStringList("Display.Shop.lore"), replaceMap);
|
||||
|
||||
panel.setItem(realisticSlot, itemStack, e -> {
|
||||
ItemStack spawnItem = this.bossEntityManager.getSpawnItem(bossEntity);
|
||||
Player player = (Player) e.getWhoClicked();
|
||||
|
||||
if(spawnItem == null) {
|
||||
Debug.FAILED_TO_GIVE_SPAWN_EGG.debug(e.getWhoClicked().getName(), name);
|
||||
return;
|
||||
}
|
||||
|
||||
double balance = this.vaultHelper.getEconomy().getBalance(player);
|
||||
|
||||
if(balance < price) {
|
||||
Message.Boss_Shop_NotEnoughBalance.msg(player, NumberUtils.get().formatDouble(price - balance));
|
||||
return;
|
||||
}
|
||||
|
||||
this.vaultHelper.getEconomy().withdrawPlayer(player, price);
|
||||
player.getInventory().addItem(spawnItem);
|
||||
Message.Boss_Shop_Purchased.msg(player, spawnItem.getItemMeta().getDisplayName());
|
||||
});
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
@ -38,6 +38,7 @@ public enum Debug {
|
||||
FAILED_TO_LOAD_COMMANDS("The commands name that is provided ({0}) 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."),
|
||||
FAILED_TO_GIVE_SPAWN_EGG("{0} tried to obtain a spawn egg for the boss {1} but it has not been set yet."),
|
||||
FAILED_TO_CONNECT_TO_VAULT("Something went wrong while trying to connect to Vault. Please make sure you have an Economy and Permission plugin connected to your Vault plugin such as Essentials and GroupManager."),
|
||||
|
||||
DROP_TABLE_FAILED_INVALID_NUMBER("The specified position ({0}) on the drop table is not a valid number."),
|
||||
DROP_TABLE_FAILED_TO_GET_ITEM("The drop table failed to get the specific item for the list."),
|
||||
|
@ -0,0 +1,12 @@
|
||||
package com.songoda.epicbosses.utils;
|
||||
|
||||
/**
|
||||
* @author AMinecraftDev
|
||||
* @version 1.0.0
|
||||
* @since 13-Dec-17
|
||||
*/
|
||||
public interface IHelper {
|
||||
|
||||
boolean isConnected();
|
||||
|
||||
}
|
@ -46,6 +46,7 @@ public enum Message {
|
||||
Boss_GiveEgg_Given("&b&lEpicBosses &8» &7You have given {0} {1}x {2}'s boss spawn item."),
|
||||
Boss_GiveEgg_Received("&b&lEpicBosses &8» &7You have received {0}x {1} boss spawn item(s)."),
|
||||
|
||||
Boss_Help_NoPermission("&c&l(!) &cYou do not have access to this command."),
|
||||
Boss_Help_Page1(
|
||||
"&8&m----*--------&3&l[ &b&lBoss Help &7(Page 1/3) &3&l]&8&m--------*----\n" +
|
||||
"&b/boss help (page) &8» &7Displays boss commands.\n" +
|
||||
@ -106,6 +107,11 @@ public enum Message {
|
||||
Boss_Reload_NoPermission("&c&l(!) &cYou do not have access to this command."),
|
||||
Boss_Reload_Successful("&b&lEpicBosses &8» &7All boss data has been reloaded. The process took &f{0}ms&7."),
|
||||
|
||||
Boss_Shop_Disabled("&c&l(!) &cThe boss shop is currently disabled."),
|
||||
Boss_Shop_NoPermission("&c&l(!) &cYou do not have access to this command."),
|
||||
Boss_Shop_NotEnoughBalance("&c&l(!) &cYou do not have enough money to make this purchase! You need &a$&f{0}&c more."),
|
||||
Boss_Shop_Purchased("&b&lEpicBosses &8» &7You have purchased &f1x {0}&7."),
|
||||
|
||||
Boss_Skills_NoPermission("&c&l(!) &cYou do not have access to this command.");
|
||||
|
||||
private static FileConfiguration LANG;
|
||||
|
@ -13,9 +13,12 @@ public enum Permission {
|
||||
admin("boss.admin"),
|
||||
create("boss.create"),
|
||||
debug("boss.debug"),
|
||||
edit("boss.edit"),
|
||||
give("boss.give"),
|
||||
help("boss.help"),
|
||||
nearby("boss.nearby"),
|
||||
reload("boss.reload"),
|
||||
nearby("boss.nearby");
|
||||
shop("boss.shop");
|
||||
|
||||
@Getter private String permission;
|
||||
|
||||
|
@ -0,0 +1,63 @@
|
||||
package com.songoda.epicbosses.utils.dependencies;
|
||||
|
||||
import com.songoda.epicbosses.utils.IHelper;
|
||||
import lombok.Getter;
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
/**
|
||||
* @author AMinecraftDev
|
||||
* @version 1.0.0
|
||||
* @since 25-May-17
|
||||
*/
|
||||
public class VaultHelper implements IHelper {
|
||||
|
||||
@Getter private Permission permission;
|
||||
@Getter private Economy economy;
|
||||
@Getter private Chat chat;
|
||||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return (setupChat() && setupPermission() && setupEconomy());
|
||||
}
|
||||
|
||||
private boolean setupChat() {
|
||||
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
return false;
|
||||
}
|
||||
RegisteredServiceProvider<Chat> rsp = Bukkit.getServer().getServicesManager().getRegistration(Chat.class);
|
||||
if (rsp == null) {
|
||||
return false;
|
||||
}
|
||||
chat = rsp.getProvider();
|
||||
return chat != null;
|
||||
}
|
||||
|
||||
private boolean setupEconomy() {
|
||||
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
return false;
|
||||
}
|
||||
RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (rsp == null) {
|
||||
return false;
|
||||
}
|
||||
this.economy = rsp.getProvider();
|
||||
return this.economy != null;
|
||||
}
|
||||
|
||||
private boolean setupPermission() {
|
||||
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
return false;
|
||||
}
|
||||
RegisteredServiceProvider<Permission> rsp = Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
|
||||
if (rsp == null) {
|
||||
return false;
|
||||
}
|
||||
this.permission = rsp.getProvider();
|
||||
return this.permission != null;
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.songoda.epicbosses.utils.panel;
|
||||
|
||||
import com.songoda.epicbosses.utils.panel.base.IPageHandler;
|
||||
import com.songoda.epicbosses.utils.panel.builder.PanelBuilder;
|
||||
import lombok.Getter;
|
||||
import com.songoda.epicbosses.utils.ICloneable;
|
||||
@ -347,6 +348,16 @@ public class Panel implements Listener, ICloneable<Panel> {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public void loadPage(int page, IPageHandler pageHandler) {
|
||||
int fillTo = getPanelBuilderSettings().getFillTo();
|
||||
int startIndex = page * fillTo;
|
||||
|
||||
for(int i = startIndex; i < startIndex + fillTo; i++) {
|
||||
pageHandler.handleSlot(i, i-startIndex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to set the parent panel for this Panel, which
|
||||
* will be used if the Back Button is set up for this
|
||||
|
@ -0,0 +1,12 @@
|
||||
package com.songoda.epicbosses.utils.panel.base;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 17-Nov-18
|
||||
*/
|
||||
public interface IPageHandler {
|
||||
|
||||
void handleSlot(int slot, int realisticSlot);
|
||||
|
||||
}
|
2
pom.xml
2
pom.xml
@ -19,7 +19,7 @@
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<plugin.version>1.0.0-SNAPSHOT-U52</plugin.version>
|
||||
<plugin.version>1.0.0-SNAPSHOT-U53</plugin.version>
|
||||
<plugin.name>EpicBosses</plugin.name>
|
||||
<plugin.main>com.songoda.epicbosses.CustomBosses</plugin.main>
|
||||
<plugin.author>AMinecraftDev</plugin.author>
|
||||
|
Loading…
Reference in New Issue
Block a user