1.0.0-SNAPSHOT-U85

+ Added EntityTypeEditor Panel
+ Finished StatisticsEditor Panels
This commit is contained in:
Charles 2018-11-27 22:33:14 +08:00
parent bff80531fd
commit be18aba374
10 changed files with 272 additions and 13 deletions

View File

@ -33,6 +33,10 @@ Hooks:
- 'blocked_region1'
- 'blocked_region2'
Display:
EntityTypeEditor:
menuName: '&b&l{name} Editor'
selectedName: '&f{name} Entity &a&l** Selected **'
name: '&f{name} Entity'
BossListEditor:
name: '&3{position} Entity'
lore:

View File

@ -0,0 +1,79 @@
package com.songoda.epicbosses.handlers;
import com.songoda.epicbosses.entity.BossEntity;
import com.songoda.epicbosses.entity.elements.EntityStatsElement;
import com.songoda.epicbosses.managers.files.BossesFileManager;
import com.songoda.epicbosses.utils.IHandler;
import com.songoda.epicbosses.utils.ServerUtils;
import com.songoda.epicbosses.utils.panel.base.ISubVariablePanelHandler;
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 27-Nov-18
*/
public class BossDisplayNameHandler implements IHandler {
@Getter private final ISubVariablePanelHandler<BossEntity, EntityStatsElement> panelHandler;
@Getter private final EntityStatsElement entityStatsElement;
@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 BossDisplayNameHandler(Player player, BossEntity bossEntity, EntityStatsElement entityStatsElement, BossesFileManager bossesFileManager, ISubVariablePanelHandler<BossEntity, EntityStatsElement> panelHandler) {
this.entityStatsElement = entityStatsElement;
this.bossEntity = bossEntity;
this.player = player;
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;
}
getEntityStatsElement().getMainStats().setDisplayName(input);
getBossesFileManager().save();
setHandled(true);
finish();
}
};
}
private void finish() {
AsyncPlayerChatEvent.getHandlerList().unregister(this.listener);
getPanelHandler().openFor(getPlayer(), getBossEntity(), getEntityStatsElement());
}
}

View File

@ -43,7 +43,7 @@ public class BossPanelManager implements ILoadable, IReloadable {
@Getter private ISubVariablePanelHandler<BossEntity, EntityStatsElement> equipmentEditMenu, helmetEditorMenu, chestplateEditorMenu, leggingsEditorMenu, bootsEditorMenu;
@Getter private ISubVariablePanelHandler<BossEntity, EntityStatsElement> weaponEditMenu, offHandEditorMenu, mainHandEditorMenu;
@Getter private ISubVariablePanelHandler<BossEntity, EntityStatsElement> statisticMainEditMenu;
@Getter private ISubVariablePanelHandler<BossEntity, EntityStatsElement> statisticMainEditMenu, entityTypeEditMenu;
@Getter private IVariablePanelHandler<BossEntity> mainBossEditMenu, dropsEditMenu, targetingEditMenu, skillsBossEditMenu, skillListBossEditMenu;
@Getter private BossListEditorPanel equipmentListEditMenu, weaponListEditMenu, statisticListEditMenu;
@ -193,12 +193,14 @@ public class BossPanelManager implements ILoadable, IReloadable {
PanelBuilder panelBuilder = new PanelBuilder(this.customBosses.getEditor().getConfigurationSection("StatisticsMainEditorPanel"));
this.statisticMainEditMenu = new StatisticMainEditorPanel(this, panelBuilder, this.customBosses);
this.entityTypeEditMenu = new EntityTypeEditorPanel(this, getListMenu("EntityTypeEditor"), this.customBosses);
}
private void reloadStatEditMenu() {
PanelBuilder panelBuilder = new PanelBuilder(this.customBosses.getEditor().getConfigurationSection("StatisticsMainEditorPanel"));
this.statisticMainEditMenu.initializePanel(panelBuilder);
this.entityTypeEditMenu.initializePanel(getListMenu("EntityTypeEditor"));
}
//---------------------------------------------

View File

@ -30,8 +30,6 @@ public class EntityTypeMechanic implements IBossMechanic {
if(position == null) position = 1;
if(entityFinder == null) return false;
System.out.println("SPAWNING BOSS #" + position);
LivingEntity livingEntity = entityFinder.spawnNewLivingEntity(bossEntityType, activeBossHolder.getLocation());
if(livingEntity == null) return false;

View File

@ -0,0 +1,140 @@
package com.songoda.epicbosses.panel;
import com.songoda.epicbosses.CustomBosses;
import com.songoda.epicbosses.api.BossAPI;
import com.songoda.epicbosses.entity.BossEntity;
import com.songoda.epicbosses.entity.elements.EntityStatsElement;
import com.songoda.epicbosses.managers.BossPanelManager;
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 org.bukkit.Material;
import org.bukkit.entity.EntityType;
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 27-Nov-18
*/
public class EntityTypeEditorPanel extends SubVariablePanelHandler<BossEntity, EntityStatsElement> {
private CustomBosses plugin;
public EntityTypeEditorPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) {
super(bossPanelManager, panelBuilder);
this.plugin = plugin;
}
@Override
public void fillPanel(Panel panel, BossEntity bossEntity, EntityStatsElement entityStatsElement) {
List<EntityType> list = Arrays.stream(EntityType.values()).filter(EntityType::isSpawnable).collect(Collectors.toList());
Map<EntityType, Material> filteredMap = getFilteredMap(list);
List<EntityType> filteredList = new ArrayList<>(filteredMap.keySet());
int maxPage = panel.getMaxPage(filteredMap);
panel.setOnPageChange(((player, currentPage, requestedPage) -> {
if(requestedPage < 0 || requestedPage > maxPage) return false;
loadPage(panel, requestedPage, filteredMap, filteredList, bossEntity, entityStatsElement);
return true;
}));
loadPage(panel, 0, filteredMap, filteredList, bossEntity, entityStatsElement);
}
@Override
public void openFor(Player player, BossEntity bossEntity, EntityStatsElement entityStatsElement) {
Map<String, String> replaceMap = new HashMap<>();
PanelBuilder panelBuilder = getPanelBuilder().cloneBuilder();
replaceMap.put("{name}", BossAPI.getBossEntityName(bossEntity));
panelBuilder.addReplaceData(replaceMap);
Panel panel = panelBuilder.getPanel()
.setDestroyWhenDone(true)
.setCancelClick(true)
.setCancelLowerClick(true)
.setParentPanelHandler(this.bossPanelManager.getStatisticMainEditMenu(), bossEntity, entityStatsElement);
fillPanel(panel, bossEntity, entityStatsElement);
panel.openFor(player);
}
@Override
public void initializePanel(PanelBuilder panelBuilder) {
}
private Map<EntityType, Material> getFilteredMap(List<EntityType> entityTypes) {
Map<EntityType, Material> filteredMap = new HashMap<>();
entityTypes.forEach(entityType -> {
String materialName = entityType + "_SPAWN_EGG";
Material material = Material.matchMaterial(materialName);
if(material == null) return;
filteredMap.put(entityType, material);
});
return filteredMap;
}
private void loadPage(Panel panel, int requestedPage, Map<EntityType, Material> filteredMap, List<EntityType> filteredList, BossEntity bossEntity, EntityStatsElement entityStatsElement) {
String entityTypeValue = entityStatsElement.getMainStats().getEntityType();
ServerUtils.get().runTaskAsync(() -> panel.loadPage(requestedPage, ((slot, realisticSlot) -> {
if(slot >= filteredMap.size()) {
panel.setItem(realisticSlot, new ItemStack(Material.AIR), e -> {});
} else {
EntityType entityType = filteredList.get(slot);
Material material = filteredMap.get(entityType);
ItemStack itemStack = new ItemStack(material);
Map<String, String> replaceMap = new HashMap<>();
boolean found = false;
replaceMap.put("{name}", StringUtils.get().formatString(entityType.name()));
if(entityTypeValue != null) {
EntityFinder entityFinder = EntityFinder.get(entityTypeValue);
if (entityFinder != null) {
for (String s : entityFinder.getNames()) {
if (s.equalsIgnoreCase(entityType.name())) {
ItemStackUtils.applyDisplayName(itemStack, this.plugin.getConfig().getString("Display.EntityTypeEditor.selectedName"), replaceMap);
found = true;
break;
}
}
}
}
if(!found) {
ItemStackUtils.applyDisplayName(itemStack, this.plugin.getConfig().getString("Display.EntityTypeEditor.name"), replaceMap);
}
panel.setItem(realisticSlot, itemStack, e -> {
EntityFinder entityFinder = EntityFinder.get(entityType.name());
if(entityFinder != null) {
Message.Boss_Statistics_SetEntityFinder.msg(e.getWhoClicked(), entityFinder.getFancyName());
entityStatsElement.getMainStats().setEntityType(entityFinder.getFancyName());
this.plugin.getBossesFileManager().save();
loadPage(panel, requestedPage, filteredMap, filteredList, bossEntity, entityStatsElement);
}
});
}
})));
}
}

View File

@ -80,6 +80,7 @@ public class MainBossEditPanel extends VariablePanelHandler<BossEntity> {
counter.getSlotsWith("Equipment").forEach(slot -> panel.setOnClick(slot, e -> this.bossPanelManager.getEquipmentListEditMenu().openFor((Player) e.getWhoClicked(), bossEntity)));
counter.getSlotsWith("Weapon").forEach(slot -> panel.setOnClick(slot, e -> this.bossPanelManager.getWeaponListEditMenu().openFor((Player) e.getWhoClicked(), bossEntity)));
counter.getSlotsWith("Skill").forEach(slot -> panel.setOnClick(slot, e -> this.bossPanelManager.getSkillsBossEditMenu().openFor((Player) e.getWhoClicked(), bossEntity)));
counter.getSlotsWith("Stats").forEach(slot -> panel.setOnClick(slot, e -> this.bossPanelManager.getStatisticListEditMenu().openFor((Player) e.getWhoClicked(), bossEntity)));
panel.openFor(player);
}

View File

@ -4,8 +4,10 @@ import com.songoda.epicbosses.CustomBosses;
import com.songoda.epicbosses.api.BossAPI;
import com.songoda.epicbosses.entity.BossEntity;
import com.songoda.epicbosses.entity.elements.EntityStatsElement;
import com.songoda.epicbosses.handlers.BossDisplayNameHandler;
import com.songoda.epicbosses.managers.BossPanelManager;
import com.songoda.epicbosses.managers.files.BossesFileManager;
import com.songoda.epicbosses.utils.EntityFinder;
import com.songoda.epicbosses.utils.Message;
import com.songoda.epicbosses.utils.NumberUtils;
import com.songoda.epicbosses.utils.panel.Panel;
@ -13,6 +15,7 @@ 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 org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
@ -45,6 +48,7 @@ public class StatisticMainEditorPanel extends SubVariablePanelHandler<BossEntity
PanelBuilder panelBuilder = getPanelBuilder().cloneBuilder();
String displayName = entityStatsElement.getMainStats().getDisplayName();
Double health = entityStatsElement.getMainStats().getHealth();
PanelBuilderCounter counter = panelBuilder.getPanelBuilderCounter();
if(health == null) health = 0.0;
if(displayName == null) displayName = "N/A";
@ -54,17 +58,21 @@ public class StatisticMainEditorPanel extends SubVariablePanelHandler<BossEntity
replaceMap.put("{displayName}", displayName);
panelBuilder.addReplaceData(replaceMap);
counter
.addSlotCounter("DisplayName")
.addSlotCounter("EntityType")
.addSlotCounter("Health");
Panel panel = panelBuilder.getPanel()
.setDestroyWhenDone(true)
.setCancelClick(true)
.setCancelLowerClick(true)
.setParentPanelHandler(this.bossPanelManager.getStatisticListEditMenu(), bossEntity);
PanelBuilderCounter counter = panel.getPanelBuilderCounter();
fillPanel(panel, bossEntity, entityStatsElement);
counter.getSlotsWith("DisplayName").forEach(slot -> panel.setOnClick(slot, event -> {}));
counter.getSlotsWith("EntityType").forEach(slot -> panel.setOnClick(slot, event -> this.bossPanelManager.getSkillListBossEditMenu().openFor((Player) event.getWhoClicked(), bossEntity)));
counter.getSlotsWith("DisplayName").forEach(slot -> panel.setOnClick(slot, getDisplayNameAction(bossEntity, entityStatsElement)));
counter.getSlotsWith("EntityType").forEach(slot -> panel.setOnClick(slot, event -> this.bossPanelManager.getEntityTypeEditMenu().openFor((Player) event.getWhoClicked(), bossEntity, entityStatsElement)));
counter.getSlotsWith("Health").forEach(slot -> panel.setOnClick(slot, getHealthAction(bossEntity, entityStatsElement)));
panel.openFor(player);
@ -75,6 +83,17 @@ public class StatisticMainEditorPanel extends SubVariablePanelHandler<BossEntity
}
private ClickAction getDisplayNameAction(BossEntity bossEntity, EntityStatsElement entityStatsElement) {
return event -> {
Player humanEntity = (Player) event.getWhoClicked();
BossDisplayNameHandler bossDisplayNameHandler = new BossDisplayNameHandler(humanEntity, bossEntity, entityStatsElement, this.bossesFileManager, this);
Message.Boss_Statistics_SetDisplayName.msg(humanEntity);
bossDisplayNameHandler.handle();
humanEntity.closeInventory();
};
}
private ClickAction getHealthAction(BossEntity bossEntity, EntityStatsElement entityStatsElement) {
return event -> {
ClickType clickType = event.getClick();
@ -95,15 +114,15 @@ public class StatisticMainEditorPanel extends SubVariablePanelHandler<BossEntity
if(currentChance == null) currentChance = 0.0;
double newChance = currentChance + healthToModifyBy;
double newHealth = currentChance + healthToModifyBy;
if(newChance < 0.0) {
newChance = 1.0;
if(newHealth < 0.0) {
newHealth = 1.0;
}
entityStatsElement.getMainStats().setHealth(newChance);
entityStatsElement.getMainStats().setHealth(newHealth);
this.bossesFileManager.save();
Message.Boss_Skills_SetChance.msg(event.getWhoClicked(), modifyValue, NumberUtils.get().formatDouble(newChance));
Message.Boss_Statistics_SetChance.msg(event.getWhoClicked(), modifyValue, NumberUtils.get().formatDouble(newHealth));
openFor((Player) event.getWhoClicked(), bossEntity, entityStatsElement);
};
}

View File

@ -0,0 +1,12 @@
package com.songoda.epicbosses.utils;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 27-Nov-18
*/
public interface IHandler {
void handle();
}

View File

@ -135,7 +135,11 @@ public enum Message {
Boss_Spawn_InvalidLocation("&c&l(!) &cThe location string you have entered is not a valid location string. A valid location string should look like this: &fworld,100,65,100"),
Boss_Spawn_MustBePlayer("&c&l(!) &cTo use this command without an input of location you must be a player."),
Boss_Spawn_InvalidBoss("&c&l(!) &cThe specified boss is not a valid type."),
Boss_Spawn_Spawned("&c&l(!) &cYou have spawned a {0} boss at {1}.");
Boss_Spawn_Spawned("&c&l(!) &cYou have spawned a {0} boss at {1}."),
Boss_Statistics_SetChance("&b&lEpicBosses &8» &7You have {0} the health of the entity to &f{1}&7."),
Boss_Statistics_SetDisplayName("&b&lEpicBosses &8» &7Your next input in to chat will be the display name for the entity. If you enter &f-&7 it will remove/clear the display name of the entity. For color codes use the &f& &7sign."),
Boss_Statistics_SetEntityFinder("&b&lEpicBosses &8» &7You have selected &f{0}&7 as the entity type for the boss.");
private static FileConfiguration LANG;

View File

@ -19,7 +19,7 @@
</modules>
<properties>
<plugin.version>maven-version-number-SNAPSHOT-U84</plugin.version>
<plugin.version>maven-version-number-SNAPSHOT-U85</plugin.version>
<plugin.name>EpicBosses</plugin.name>
<plugin.main>com.songoda.epicbosses.CustomBosses</plugin.main>
<plugin.author>AMinecraftDev</plugin.author>