1.0.0-SNAPSHOT-U106

+ Completed CreatePotionEffect GUIs
This commit is contained in:
Charles 2018-12-02 22:57:57 +08:00
parent 4b54e5d387
commit 0590ef662e
9 changed files with 362 additions and 11 deletions

View File

@ -132,4 +132,8 @@ Display:
- '&3Duration: &7{duration}'
- '&3Level: &7{level}'
- '&7'
- '&7Click to remove potion effect.'
- '&7Click to remove potion effect.'
CreatePotion:
menuName: '&b&lSelect Potion Effect Type'
name: '&bEffect: &f{effect}'
selectedName: '&bEffect: &f{effect} &a&l** Selected **'

View File

@ -1489,10 +1489,64 @@ PotionSkillEditorPanel:
- '&7Click here to go back.'
CreatePotionEffectEditorPanel:
name: '&b&lCreate Potion Effect'
slots: 27
slots: 9
Settings:
emptySpaceFiller: true
EmptySpaceFiller:
type: WHITE_STAINED_GLASS_PANE
name: '&7'
Items:
'1':
type: GRAY_DYE
name: '&c&lCancel Potion Effect'
lore:
- '&7Click here to cancel the creation'
- '&7of this potion effect.'
Button: Cancel
'4':
type: EMERALD
name: '&e&lLevel'
lore:
- '&bCurrently: &f{level}'
- '&7'
- '&7Click here to change the level'
- '&7of the potion effect.'
- '&7'
- '&bLeft Click &8» &f+1'
- '&bRight Click &8» &f-1'
Button: Level
'5':
type: GUNPOWDER
name: '&e&lPotion Effect Type'
lore:
- '&bCurrently: &f{effect}'
- '&7'
- '&7Click here to change the potion'
- '&7effect type.'
Button: Effect
'6':
type: CLOCK
name: '&e&lDuration'
lore:
- '&bCurrently: &f{duration}s'
- '&7'
- '&7Click here to change the duration'
- '&7of the potion effect.'
- '&7'
- '&bLeft Click &8» &f+1'
- '&bShift Left-Click &8» &f+10'
- '&7'
- '&bRight Click &8» &f-1'
- '&bShift Right-Click &8» &f-10'
Button: Duration
'9':
type: LIME_DYE
name: '&b&lConfirm'
lore:
- '&7Click here to confirm the creation'
- '&7of the potion effect with data:'
- '&7'
- '&bDuration: &f{duration}s'
- '&bEffect: &f{effect}'
- '&bLevel: &f{level}'
Button: Confirm

View File

@ -21,11 +21,13 @@ import com.songoda.epicbosses.panel.bosses.weapons.OffHandEditorPanel;
import com.songoda.epicbosses.panel.handlers.*;
import com.songoda.epicbosses.panel.skills.MainSkillEditorPanel;
import com.songoda.epicbosses.panel.skills.SkillTypeEditorPanel;
import com.songoda.epicbosses.panel.skills.custom.CreatePotionEffectEditorPanel;
import com.songoda.epicbosses.panel.skills.custom.PotionEffectTypeEditorPanel;
import com.songoda.epicbosses.panel.skills.custom.PotionSkillEditorPanel;
import com.songoda.epicbosses.skills.Skill;
import com.songoda.epicbosses.skills.types.PotionSkillElement;
import com.songoda.epicbosses.utils.panel.base.ISubVariablePanelHandler;
import com.songoda.epicbosses.utils.panel.base.IVariablePanelHandler;
import com.songoda.epicbosses.utils.potion.holder.PotionEffectHolder;
import lombok.Getter;
import com.songoda.epicbosses.CustomBosses;
import com.songoda.epicbosses.panel.*;
@ -34,7 +36,6 @@ import com.songoda.epicbosses.utils.IReloadable;
import com.songoda.epicbosses.utils.StringUtils;
import com.songoda.epicbosses.utils.panel.base.IPanelHandler;
import com.songoda.epicbosses.utils.panel.builder.PanelBuilder;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import java.util.Collection;
@ -64,7 +65,7 @@ public class BossPanelManager implements ILoadable, IReloadable {
@Getter private BossListEditorPanel equipmentListEditMenu, weaponListEditMenu, statisticListEditMenu;
@Getter private IVariablePanelHandler<Skill> mainSkillEditMenu, customMessageEditMenu, skillTypeEditMenu, potionSkillEditorPanel;
@Getter private ISubVariablePanelHandler<Skill, PotionSkillElement> createPotionEffectMenu;
@Getter private ISubVariablePanelHandler<Skill, PotionEffectHolder> createPotionEffectMenu, potionEffectTypeEditMenu;
private final CustomBosses customBosses;
@ -163,6 +164,7 @@ public class BossPanelManager implements ILoadable, IReloadable {
PanelBuilder panelBuilder = new PanelBuilder(editor.getConfigurationSection("SkillEditorPanel"));
PanelBuilder panelBuilder1 = new PanelBuilder(editor.getConfigurationSection("SkillTypeEditorPanel"));
PanelBuilder panelBuilder2 = new PanelBuilder(editor.getConfigurationSection("PotionSkillEditorPanel"));
PanelBuilder panelBuilder3 = new PanelBuilder(editor.getConfigurationSection("CreatePotionEffectEditorPanel"));
this.mainSkillEditMenu = new MainSkillEditorPanel(this, panelBuilder, this.customBosses);
this.customMessageEditMenu = new SingleMessageListEditor<Skill>(this, getListMenu("Skills.MainEdit"), this.customBosses) {
@ -190,6 +192,8 @@ public class BossPanelManager implements ILoadable, IReloadable {
};
this.skillTypeEditMenu = new SkillTypeEditorPanel(this, panelBuilder1, this.customBosses);
this.potionSkillEditorPanel = new PotionSkillEditorPanel(this, panelBuilder2, this.customBosses);
this.createPotionEffectMenu = new CreatePotionEffectEditorPanel(this, panelBuilder3, this.customBosses);
this.potionEffectTypeEditMenu = new PotionEffectTypeEditorPanel(this, getListMenu("Skills.CreatePotion"), this.customBosses);
}
private void reloadSkillEditMenus() {
@ -197,11 +201,14 @@ public class BossPanelManager implements ILoadable, IReloadable {
PanelBuilder panelBuilder = new PanelBuilder(editor.getConfigurationSection("SkillEditorPanel"));
PanelBuilder panelBuilder1 = new PanelBuilder(editor.getConfigurationSection("SkillTypeEditorPanel"));
PanelBuilder panelBuilder2 = new PanelBuilder(editor.getConfigurationSection("PotionSkillEditorPanel"));
PanelBuilder panelBuilder3 = new PanelBuilder(editor.getConfigurationSection("CreatePotionEffectEditorPanel"));
this.mainSkillEditMenu.initializePanel(panelBuilder);
this.customMessageEditMenu.initializePanel(getListMenu("Skills.MainEdit"));
this.skillTypeEditMenu.initializePanel(panelBuilder1);
this.potionSkillEditorPanel.initializePanel(panelBuilder2);
this.createPotionEffectMenu.initializePanel(panelBuilder3);
this.potionEffectTypeEditMenu.initializePanel(getListMenu("Skills.CreatePotion"));
}
//---------------------------------------------

View File

@ -1,9 +1,171 @@
package com.songoda.epicbosses.panel.skills.custom;
import com.songoda.epicbosses.CustomBosses;
import com.songoda.epicbosses.managers.BossPanelManager;
import com.songoda.epicbosses.managers.BossSkillManager;
import com.songoda.epicbosses.managers.files.SkillsFileManager;
import com.songoda.epicbosses.skills.Skill;
import com.songoda.epicbosses.skills.types.PotionSkillElement;
import com.songoda.epicbosses.utils.Message;
import com.songoda.epicbosses.utils.NumberUtils;
import com.songoda.epicbosses.utils.PotionEffectFinder;
import com.songoda.epicbosses.utils.panel.Panel;
import com.songoda.epicbosses.utils.panel.base.ClickAction;
import com.songoda.epicbosses.utils.panel.base.handlers.SubVariablePanelHandler;
import com.songoda.epicbosses.utils.panel.builder.PanelBuilder;
import com.songoda.epicbosses.utils.panel.builder.PanelBuilderCounter;
import com.songoda.epicbosses.utils.potion.holder.PotionEffectHolder;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 02-Dec-18
*/
public class CreatePotionEffectEditorPanel {
public class CreatePotionEffectEditorPanel extends SubVariablePanelHandler<Skill, PotionEffectHolder> {
private SkillsFileManager skillsFileManager;
private BossSkillManager bossSkillManager;
public CreatePotionEffectEditorPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) {
super(bossPanelManager, panelBuilder);
this.bossSkillManager = plugin.getBossSkillManager();
this.skillsFileManager = plugin.getSkillsFileManager();
}
@Override
public void initializePanel(PanelBuilder panelBuilder) {
PanelBuilderCounter panelBuilderCounter = panelBuilder.getPanelBuilderCounter();
panelBuilderCounter
.addSlotCounter("Cancel")
.addSlotCounter("Level")
.addSlotCounter("Effect")
.addSlotCounter("Duration")
.addSlotCounter("Confirm");
}
@Override
public void fillPanel(Panel panel, Skill skill, PotionEffectHolder potionEffectHolder) {
}
@Override
public void openFor(Player player, Skill skill, PotionEffectHolder potionEffectHolder) {
Map<String, String> replaceMap = new HashMap<>();
String effect = potionEffectHolder.getType();
PanelBuilder panelBuilder = getPanelBuilder().cloneBuilder();
if(effect == null || effect.isEmpty()) effect = "N/A";
replaceMap.put("{duration}", NumberUtils.get().formatDouble(potionEffectHolder.getDuration()));
replaceMap.put("{level}", NumberUtils.get().formatDouble(potionEffectHolder.getLevel()));
replaceMap.put("{effect}", effect);
panelBuilder.addReplaceData(replaceMap);
Panel panel = panelBuilder.getPanel()
.setCancelClick(true)
.setCancelLowerClick(true)
.setDestroyWhenDone(true)
.setParentPanelHandler(this.bossPanelManager.getPotionSkillEditorPanel(), skill);
PanelBuilderCounter counter = panel.getPanelBuilderCounter();
counter.getSlotsWith("Cancel").forEach(slot -> panel.setOnClick(slot, event -> this.bossPanelManager.getPotionSkillEditorPanel().openFor((Player) event.getWhoClicked(), skill)));
counter.getSlotsWith("Confirm").forEach(slot -> panel.setOnClick(slot, getConfirmAction(skill, potionEffectHolder)));
counter.getSlotsWith("Level").forEach(slot -> panel.setOnClick(slot, getLevelAction(skill, potionEffectHolder)));
counter.getSlotsWith("Duration").forEach(slot -> panel.setOnClick(slot, getDurationAction(skill, potionEffectHolder)));
counter.getSlotsWith("Effect").forEach(slot -> panel.setOnClick(slot, event -> this.bossPanelManager.getPotionEffectTypeEditMenu().openFor((Player) event.getWhoClicked(), skill, potionEffectHolder)));
panel.openFor(player);
}
private ClickAction getDurationAction(Skill skill, PotionEffectHolder potionEffectHolder) {
return event -> {
ClickType clickType = event.getClick();
int amountToModifyBy;
if(clickType == ClickType.RIGHT) {
amountToModifyBy = -1;
} else if(clickType == ClickType.SHIFT_RIGHT) {
amountToModifyBy = -10;
} else if(clickType == ClickType.SHIFT_LEFT) {
amountToModifyBy = 10;
}else {
amountToModifyBy = 1;
}
int currentAmount = potionEffectHolder.getDuration();
int totalAmount = amountToModifyBy + currentAmount;
if(totalAmount < 0) {
totalAmount = -1;
}
potionEffectHolder.setDuration(totalAmount);
openFor((Player) event.getWhoClicked(), skill, potionEffectHolder);
};
}
private ClickAction getLevelAction(Skill skill, PotionEffectHolder potionEffectHolder) {
return event -> {
ClickType clickType = event.getClick();
int amountToModifyBy;
if(clickType.name().contains("RIGHT")) {
amountToModifyBy = -1;
} else {
amountToModifyBy = 1;
}
int currentAmount = potionEffectHolder.getLevel();
int totalAmount = amountToModifyBy + currentAmount;
if(totalAmount <= 0) {
totalAmount = 1;
}
if(totalAmount > 255) {
totalAmount = 255;
}
potionEffectHolder.setLevel(totalAmount);
openFor((Player) event.getWhoClicked(), skill, potionEffectHolder);
};
}
private ClickAction getConfirmAction(Skill skill, PotionEffectHolder potionEffectHolder) {
return event -> {
Integer duration = potionEffectHolder.getDuration();
Integer level = potionEffectHolder.getLevel();
String type = potionEffectHolder.getType();
if(duration != null && level != null && type != null && !type.isEmpty()) {
PotionSkillElement potionSkillElement = this.bossSkillManager.getPotionSkillElement(skill);
PotionEffectFinder potionEffectFinder = PotionEffectFinder.getByName(type);
if(potionEffectFinder != null) {
List<PotionEffectHolder> currentList = potionSkillElement.getPotions();
currentList.add(potionEffectHolder);
potionSkillElement.setPotions(currentList);
this.skillsFileManager.save();
} else {
Message.Boss_Skills_NotCompleteEnough.msg(event.getWhoClicked());
}
} else {
Message.Boss_Skills_NotCompleteEnough.msg(event.getWhoClicked());
}
this.bossPanelManager.getPotionSkillEditorPanel().openFor((Player) event.getWhoClicked(), skill);
};
}
}

View File

@ -0,0 +1,122 @@
package com.songoda.epicbosses.panel.skills.custom;
import com.songoda.epicbosses.CustomBosses;
import com.songoda.epicbosses.entity.BossEntity;
import com.songoda.epicbosses.entity.elements.EntityStatsElement;
import com.songoda.epicbosses.managers.BossPanelManager;
import com.songoda.epicbosses.skills.Skill;
import com.songoda.epicbosses.utils.*;
import com.songoda.epicbosses.utils.itemstack.ItemStackUtils;
import com.songoda.epicbosses.utils.panel.Panel;
import com.songoda.epicbosses.utils.panel.base.handlers.SubVariablePanelHandler;
import com.songoda.epicbosses.utils.panel.builder.PanelBuilder;
import com.songoda.epicbosses.utils.potion.holder.PotionEffectHolder;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 02-Dec-18
*/
public class PotionEffectTypeEditorPanel extends SubVariablePanelHandler<Skill, PotionEffectHolder> {
private CustomBosses plugin;
public PotionEffectTypeEditorPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) {
super(bossPanelManager, panelBuilder);
this.plugin = plugin;
}
@Override
public void fillPanel(Panel panel, Skill skill, PotionEffectHolder potionEffectHolder) {
List<PotionEffectType> list = Arrays.stream(PotionEffectType.values()).collect(Collectors.toList());
int maxPage = panel.getMaxPage(list);
panel.setOnPageChange(((player, currentPage, requestedPage) -> {
if(requestedPage < 0 || requestedPage > maxPage) return false;
loadPage(panel, requestedPage, list, skill, potionEffectHolder);
return true;
}));
loadPage(panel, 0, list, skill, potionEffectHolder);
}
@Override
public void openFor(Player player, Skill skill, PotionEffectHolder potionEffectHolder) {
Panel panel = getPanelBuilder().getPanel()
.setParentPanelHandler(this.bossPanelManager.getCreatePotionEffectMenu(), skill, potionEffectHolder);
fillPanel(panel, skill, potionEffectHolder);
panel.openFor(player);
}
@Override
public void initializePanel(PanelBuilder panelBuilder) {
}
private void loadPage(Panel panel, int requestedPage, List<PotionEffectType> potionEffectTypes, Skill skill, PotionEffectHolder potionEffectHolder) {
String type = potionEffectHolder.getType();
ServerUtils.get().runTaskAsync(() -> panel.loadPage(requestedPage, ((slot, realisticSlot) -> {
if(slot >= potionEffectTypes.size()) {
panel.setItem(realisticSlot, new ItemStack(Material.AIR), e -> {});
} else {
PotionEffectType potionEffectType = potionEffectTypes.get(slot);
ItemStack itemStack = new ItemStack(Material.POTION);
PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();
PotionType potionType = PotionType.getByEffect(potionEffectType);
if(potionType == null) potionType = PotionType.WATER;
potionMeta.setBasePotionData(new PotionData(potionType));
itemStack.setItemMeta(potionMeta);
Map<String, String> replaceMap = new HashMap<>();
boolean found = false;
replaceMap.put("{name}", StringUtils.get().formatString(potionEffectType.getName()));
if(type != null && !type.isEmpty()) {
PotionEffectFinder potionEffectFinder = PotionEffectFinder.getByName(type);
if (potionEffectFinder != null) {
ItemStackUtils.applyDisplayName(itemStack, this.plugin.getConfig().getString("Display.Skills.CreatePotion.selectedName"), replaceMap);
found = true;
}
}
if(!found) {
ItemStackUtils.applyDisplayName(itemStack, this.plugin.getConfig().getString("Display.Skills.CreatePotion.name"), replaceMap);
}
panel.setItem(realisticSlot, itemStack, e -> {
PotionEffectFinder potionEffectFinder = PotionEffectFinder.getByEffect(potionEffectType);
if(potionEffectFinder != null) {
potionEffectHolder.setType(potionEffectFinder.getFancyName());
this.plugin.getSkillsFileManager().save();
this.bossPanelManager.getCreatePotionEffectMenu().openFor((Player) e.getWhoClicked(), skill, potionEffectHolder);
}
});
}
})));
}
}

View File

@ -76,14 +76,14 @@ public class PotionSkillEditorPanel extends VariablePanelHandler<Skill> {
panelBuilder.addReplaceData(replaceMap);
PanelBuilderCounter counter = panelBuilder.getPanelBuilderCounter();
PotionSkillElement potionSkillElement = this.bossSkillManager.getPotionSkillElement(skill);
Panel panel = panelBuilder.getPanel()
.setDestroyWhenDone(true)
.setCancelClick(true)
.setCancelLowerClick(true)
.setParentPanelHandler(this.bossPanelManager.getMainSkillEditMenu(), skill);
counter.getSlotsWith("PotionEffect").forEach(slot -> panel.setOnClick(slot, event -> this.bossPanelManager.getCreatePotionEffectMenu().openFor((Player) event.getWhoClicked(), skill, potionSkillElement)));
counter.getSlotsWith("PotionEffect").forEach(slot -> panel.setOnClick(slot,
event -> this.bossPanelManager.getCreatePotionEffectMenu().openFor((Player) event.getWhoClicked(), skill, new PotionEffectHolder("", 1, 1))));
fillPanel(panel, skill);
panel.openFor(player);

View File

@ -139,6 +139,7 @@ public enum Message {
Boss_Skills_SetRadius("&b&lEpicBosses &8» &7You have {0} the radius for the skill to &f{1}&7."),
Boss_Skills_SetMode("&b&lEpicBosses &8» &7You have set the skill mode to &f{0}&7."),
Boss_Skills_SetDisplayName("&b&lEpicBosses &8» &7Your next input in to chat will be the display name for the skill. If you enter &f-&7 it will remove/clear the display name of the skill. For color codes use the &f& &7sign."),
Boss_Skills_NotCompleteEnough("&c&l(!) &cThe potion effect was unable to be created due to it not having enough information. Please make sure that the potion effect type is selected."),
Boss_Spawn_NoPermission("&c&l(!) &cYou do not have access to this command."),
Boss_Spawn_InvalidArgs("&c&l(!) &cYou must use &n/boss spawn [name] (location)&c to spawn a boss."),

View File

@ -2,6 +2,7 @@ package com.songoda.epicbosses.utils.potion.holder;
import com.google.gson.annotations.Expose;
import lombok.Getter;
import lombok.Setter;
/**
* @author Charles Cullen
@ -10,8 +11,8 @@ import lombok.Getter;
*/
public class PotionEffectHolder {
@Expose @Getter private String type;
@Expose @Getter private Integer level, duration;
@Expose @Getter @Setter private String type;
@Expose @Getter @Setter private Integer level, duration;
public PotionEffectHolder(String type, Integer level, Integer duration) {
this.type = type;

View File

@ -20,7 +20,7 @@
<properties>
<!--<plugin.version>maven-version-number-SNAPSHOT-U90</plugin.version>-->
<plugin.version>1.0.0-U105</plugin.version>
<plugin.version>1.0.0-U106</plugin.version>
<plugin.name>EpicBosses</plugin.name>
<plugin.main>com.songoda.epicbosses.CustomBosses</plugin.main>
<plugin.author>AMinecraftDev</plugin.author>