1.0.0-SNAPSHOT-U202

+ Completed the BossEntityShop Manager
+ Fixed error with ItemStackUtils.isSimilar
This commit is contained in:
Charles 2019-01-20 02:24:42 +08:00
parent 57ca5c0099
commit 12f6eeef41
8 changed files with 238 additions and 6 deletions

View File

@ -358,6 +358,42 @@ MainEditorPanel:
- '&7Click here to edit the taunts, sayings,'
- '&7etc. for this boss.'
Button: Text
BossShopEditorPanel:
name: '&b&l{name} Editor'
slots: 9
Settings:
backButton: true
Buttons:
backButton: 5
Items:
'3':
type: GUNPOWDER
name: '&3&lBuyable'
lore:
- '&bCurrently: &f{buyable}'
- '&7'
- '&7If this is set to true then this'
- '&7boss spawn egg will be spawnable from'
- '&7the /boss shop while boss editing is'
- '&7disabled.'
Button: Buyable
'5':
type: REDSTONE
name: '&c&lGo Back'
lore:
- '&7Click here to go back to the'
- '&7main boss editor panel.'
'7':
type: GOLD_INGOT
name: '&3&lPrice'
lore:
- '&bCurrently: &a$&f{price}'
- '&7'
- '&7This is the price that the boss will'
- '&7be sold for in the /boss shop menu'
- '&7'
- '&7Click here to adjust the price.'
Button: Price
SpawnItemEditorPanel:
name: '&b&l{name} Editor'
slots: 54

View File

@ -0,0 +1,85 @@
package com.songoda.epicbosses.handlers;
import com.songoda.epicbosses.api.BossAPI;
import com.songoda.epicbosses.entity.BossEntity;
import com.songoda.epicbosses.managers.files.BossesFileManager;
import com.songoda.epicbosses.utils.IHandler;
import com.songoda.epicbosses.utils.Message;
import com.songoda.epicbosses.utils.NumberUtils;
import com.songoda.epicbosses.utils.ServerUtils;
import com.songoda.epicbosses.utils.panel.base.IVariablePanelHandler;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import java.util.UUID;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 20-Jan-19
*/
public class BossShopPriceHandler implements IHandler {
@Getter private final IVariablePanelHandler<BossEntity> panelHandler;
@Getter private final BossesFileManager bossesFileManager;
@Getter private final BossEntity bossEntity;
@Getter private final Player player;
@Getter @Setter private boolean handled = false;
private Listener listener;
public BossShopPriceHandler(Player player, BossEntity bossEntity, BossesFileManager bossesFileManager, IVariablePanelHandler<BossEntity> panelHandler) {
this.player = player;
this.bossEntity = bossEntity;
this.bossesFileManager = bossesFileManager;
this.panelHandler = panelHandler;
this.listener = getListener();
}
@Override
public void handle() {
ServerUtils.get().registerListener(this.listener);
}
private Listener getListener() {
return new Listener() {
@EventHandler
public void onChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
if(!uuid.equals(getPlayer().getUniqueId())) return;
if(isHandled()) return;
String input = event.getMessage();
if(input.equalsIgnoreCase("-")) {
input = null;
}
event.setCancelled(true);
if(NumberUtils.get().isDouble(input)) {
getBossEntity().setPrice(NumberUtils.get().getDouble(input));
getBossesFileManager().save();
setHandled(true);
finish();
} else {
Message.Boss_Edit_Price.msg(getPlayer(), BossAPI.getBossEntityName(getBossEntity()));
}
}
};
}
private void finish() {
AsyncPlayerChatEvent.getHandlerList().unregister(this.listener);
getPanelHandler().openFor(getPlayer(), getBossEntity());
}
}

View File

@ -102,7 +102,7 @@ public class BossPanelManager implements ILoadable, IReloadable {
@Getter private ISubVariablePanelHandler<BossEntity, EntityStatsElement> statisticMainEditMenu, entityTypeEditMenu;
@Getter private IVariablePanelHandler<BossEntity> mainBossEditMenu, dropsEditMenu, targetingEditMenu, skillsBossEditMenu, skillListBossEditMenu, commandsMainEditMenu, onSpawnCommandEditMenu,
onDeathCommandEditMenu, mainDropsEditMenu, mainTextEditMenu, mainTauntEditMenu, onSpawnTextEditMenu, onSpawnSubTextEditMenu, onDeathTextEditMenu, onDeathSubTextEditMenu, onDeathPositionTextEditMenu,
onTauntTextEditMenu, spawnItemEditMenu;
onTauntTextEditMenu, spawnItemEditMenu, bossShopEditMenu;
@Getter private BossListEditorPanel equipmentListEditMenu, weaponListEditMenu, statisticListEditMenu;
@Getter private IVariablePanelHandler<Skill> mainSkillEditMenu, customMessageEditMenu, skillTypeEditMenu, potionSkillEditorPanel, commandSkillEditorPanel, groupSkillEditorPanel, customSkillEditorPanel;
@ -813,10 +813,12 @@ public class BossPanelManager implements ILoadable, IReloadable {
private void loadShopMenu() {
this.shopPanel = new ShopPanel(this, new PanelBuilder(this.customBosses.getEditor().getConfigurationSection("ShopListPanel")), this.customBosses);
this.bossShopEditMenu = new BossShopEditorPanel(this, new PanelBuilder(this.customBosses.getEditor().getConfigurationSection("BossShopEditorPanel")), this.customBosses);
}
private void reloadShopMenu() {
this.shopPanel.initializePanel(new PanelBuilder(this.customBosses.getEditor().getConfigurationSection("ShopListPanel")));
this.bossShopEditMenu.initializePanel(new PanelBuilder(this.customBosses.getEditor().getConfigurationSection("BossShopEditorPanel")));
}
//---------------------------------------------

View File

@ -0,0 +1,95 @@
package com.songoda.epicbosses.panel.bosses;
import com.songoda.epicbosses.CustomBosses;
import com.songoda.epicbosses.api.BossAPI;
import com.songoda.epicbosses.entity.BossEntity;
import com.songoda.epicbosses.handlers.BossShopPriceHandler;
import com.songoda.epicbosses.managers.BossPanelManager;
import com.songoda.epicbosses.managers.files.BossesFileManager;
import com.songoda.epicbosses.utils.Message;
import com.songoda.epicbosses.utils.NumberUtils;
import com.songoda.epicbosses.utils.ObjectUtils;
import com.songoda.epicbosses.utils.panel.Panel;
import com.songoda.epicbosses.utils.panel.base.ClickAction;
import com.songoda.epicbosses.utils.panel.base.handlers.VariablePanelHandler;
import com.songoda.epicbosses.utils.panel.builder.PanelBuilder;
import com.songoda.epicbosses.utils.panel.builder.PanelBuilderCounter;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.Map;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 19-Jan-19
*/
public class BossShopEditorPanel extends VariablePanelHandler<BossEntity> {
private BossesFileManager bossesFileManager;
public BossShopEditorPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) {
super(bossPanelManager, panelBuilder);
this.bossesFileManager = plugin.getBossesFileManager();
}
@Override
public void fillPanel(Panel panel, BossEntity bossEntity) {
}
@Override
public void openFor(Player player, BossEntity bossEntity) {
Map<String, String> replaceMap = new HashMap<>();
PanelBuilder panelBuilder = getPanelBuilder().cloneBuilder();
PanelBuilderCounter counter = panelBuilder.getPanelBuilderCounter();
replaceMap.put("{name}", BossAPI.getBossEntityName(bossEntity));
replaceMap.put("{buyable}", bossEntity.isBuyable()+"");
replaceMap.put("{price}", NumberUtils.get().formatDouble(ObjectUtils.getValue(bossEntity.getPrice(), 0.0)));
panelBuilder.addReplaceData(replaceMap);
Panel panel = panelBuilder.getPanel()
.setParentPanelHandler(this.bossPanelManager.getMainBossEditMenu(), bossEntity);
counter.getSlotsWith("Buyable").forEach(slot -> panel.setOnClick(slot, getBuyableAction(bossEntity)));
counter.getSlotsWith("Price").forEach(slot -> panel.setOnClick(slot, event -> {
if(!bossEntity.isEditing()) {
Message.Boss_Edit_CannotBeModified.msg(event.getWhoClicked());
return;
}
Player whoClick = (Player) event.getWhoClicked();
BossShopPriceHandler bossShopPriceHandler = new BossShopPriceHandler(whoClick, bossEntity, this.bossesFileManager, this);
Message.Boss_Edit_Price.msg(event.getWhoClicked(), BossAPI.getBossEntityName(bossEntity));
whoClick.closeInventory();
bossShopPriceHandler.handle();
}));
panel.openFor(player);
}
@Override
public void initializePanel(PanelBuilder panelBuilder) {
}
public ClickAction getBuyableAction(BossEntity bossEntity) {
return event -> {
if(!bossEntity.isEditing()) {
Message.Boss_Edit_CannotBeModified.msg(event.getWhoClicked());
return;
}
boolean current = bossEntity.isBuyable();
bossEntity.setBuyable(!current);
this.bossesFileManager.save();
openFor((Player) event.getWhoClicked(), bossEntity);
};
}
}

View File

@ -76,6 +76,7 @@ public class MainBossEditPanel extends VariablePanelHandler<BossEntity> {
counter.getSlotsWith("Command").forEach(slot -> panel.setOnClick(slot, e -> this.bossPanelManager.getCommandsMainEditMenu().openFor((Player) e.getWhoClicked(), bossEntity)));
counter.getSlotsWith("Text").forEach(slot -> panel.setOnClick(slot, e -> this.bossPanelManager.getMainTextEditMenu().openFor((Player) e.getWhoClicked(), bossEntity)));
counter.getSlotsWith("SpawnItem").forEach(slot -> panel.setOnClick(slot, e -> this.bossPanelManager.getSpawnItemEditMenu().openFor((Player) e.getWhoClicked(), bossEntity)));
counter.getSlotsWith("Shop").forEach(slot -> panel.setOnClick(slot, e -> this.bossPanelManager.getBossShopEditMenu().openFor((Player) e.getWhoClicked(), bossEntity)));
});
panel.openFor(player);

View File

@ -66,6 +66,7 @@ public enum Message {
Boss_Edit_Toggled("&b&lEpicBosses &8» &7You have toggled the editing mode for &f{0}&7 to &f{1}&7."),
Boss_Edit_NotCompleteEnough("&c&l(!) &cThe boss is not set up enough to be enabled. Please make sure it has the following things: &f{0}&c Once these things are set try toggling again."),
Boss_Edit_DoesntExist("&c&l(!) &cThe specified boss does not exist. Please try again with the proper name. If you cannot figure it out please check the bosses.json file to find the one you're looking for."),
Boss_Edit_Price("&b&lEpicBosses &8» &7Please input the new price of the &f{0}&7 Boss Entity. Please do not add commas and only use numbers. To cancel this input in to chat &f- &7."),
Boss_GiveEgg_NoPermission("&c&l(!) &cYou do not have access to this command."),
Boss_GiveEgg_InvalidArgs("&c&l(!) &cYou must use &n/boss giveegg [name] [player] (amount)&c to give an egg."),

View File

@ -349,10 +349,22 @@ public class ItemStackUtils {
ItemMeta itemMeta2 = itemStack2.getItemMeta();
if(itemMeta1 == null || itemMeta2 == null) return false;
if(itemMeta1.hasDisplayName() != itemMeta2.hasDisplayName()) return false;
if(!itemMeta1.getDisplayName().equals(itemMeta2.getDisplayName())) return false;
if(itemMeta1.hasLore() != itemMeta2.hasLore()) return false;
if(!itemMeta1.getLore().equals(itemMeta2.getLore())) return false;
if(itemMeta1.hasDisplayName() == itemMeta2.hasDisplayName()) {
if(itemMeta1.hasDisplayName()) {
if(!itemMeta1.getDisplayName().equals(itemMeta2.getDisplayName())) return false;
}
} else {
return false;
}
if(itemMeta1.hasLore() == itemMeta2.hasLore()) {
if(itemMeta1.hasLore()) {
if(!itemMeta1.getLore().equals(itemMeta2.getLore())) return false;
}
} else {
return false;
}
return true;
}

View File

@ -19,7 +19,7 @@
</modules>
<properties>
<plugin.version>1.0.0-U201</plugin.version>
<plugin.version>1.0.0-U202</plugin.version>
<plugin.name>EpicBosses</plugin.name>
<plugin.main>com.songoda.epicbosses.CustomBosses</plugin.main>
<plugin.author>AMinecraftDev</plugin.author>