mirror of
https://github.com/songoda/EpicBosses.git
synced 2024-11-12 21:13:55 +01:00
Material differences, not json/yml files yet
This commit is contained in:
parent
cd26b92584
commit
2192ee683b
@ -17,7 +17,7 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.12.2</version>
|
||||
<version>1.14.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -17,7 +17,7 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.12.2</version>
|
||||
<version>1.14.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -17,7 +17,7 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.12.2</version>
|
||||
<version>1.14.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -17,7 +17,7 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.12.2</version>
|
||||
<version>1.14.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -17,7 +17,7 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.14.1</version>
|
||||
<version>1.14.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -17,7 +17,7 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.12.2</version>
|
||||
<version>1.14.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -35,19 +35,17 @@ public class EntityTypeEditorPanel extends SubVariablePanelHandler<BossEntity, E
|
||||
|
||||
@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, Short> filteredMap = getFilteredMap(list);
|
||||
List<EntityType> filteredList = new ArrayList<>(filteredMap.keySet());
|
||||
int maxPage = panel.getMaxPage(filteredMap);
|
||||
List<EntityType> list = ItemStackUtils.getSpawnableEntityTypes();
|
||||
int maxPage = panel.getMaxPage(ItemStackUtils.getSpawnableEntityTypes());
|
||||
|
||||
panel.setOnPageChange(((player, currentPage, requestedPage) -> {
|
||||
if(requestedPage < 0 || requestedPage > maxPage) return false;
|
||||
|
||||
loadPage(panel, requestedPage, filteredMap, filteredList, bossEntity, entityStatsElement);
|
||||
loadPage(panel, requestedPage, list, bossEntity, entityStatsElement);
|
||||
return true;
|
||||
}));
|
||||
|
||||
loadPage(panel, 0, filteredMap, filteredList, bossEntity, entityStatsElement);
|
||||
loadPage(panel, 0, list, bossEntity, entityStatsElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -74,23 +72,15 @@ public class EntityTypeEditorPanel extends SubVariablePanelHandler<BossEntity, E
|
||||
|
||||
}
|
||||
|
||||
private Map<EntityType, Short> getFilteredMap(List<EntityType> entityTypes) {
|
||||
Map<EntityType, Short> filteredMap = new HashMap<>();
|
||||
|
||||
entityTypes.forEach(entityType -> filteredMap.put(entityType, entityType.getTypeId()));
|
||||
|
||||
return filteredMap;
|
||||
}
|
||||
|
||||
private void loadPage(Panel panel, int requestedPage, Map<EntityType, Short> filteredMap, List<EntityType> filteredList, BossEntity bossEntity, EntityStatsElement entityStatsElement) {
|
||||
private void loadPage(Panel panel, int requestedPage, List<EntityType> filteredList, BossEntity bossEntity, EntityStatsElement entityStatsElement) {
|
||||
String entityTypeValue = entityStatsElement.getMainStats().getEntityType();
|
||||
|
||||
ServerUtils.get().runTaskAsync(() -> panel.loadPage(requestedPage, ((slot, realisticSlot) -> {
|
||||
if(slot >= filteredMap.size()) {
|
||||
if(slot >= filteredList.size()) {
|
||||
panel.setItem(realisticSlot, new ItemStack(Material.AIR), e -> {});
|
||||
} else {
|
||||
EntityType entityType = filteredList.get(slot);
|
||||
ItemStack itemStack = new ItemStack(Material.MONSTER_EGG, filteredMap.get(entityType));
|
||||
ItemStack itemStack = ItemStackUtils.getSpawnEggForEntity(entityType);
|
||||
Map<String, String> replaceMap = new HashMap<>();
|
||||
boolean found = false;
|
||||
|
||||
@ -122,7 +112,7 @@ public class EntityTypeEditorPanel extends SubVariablePanelHandler<BossEntity, E
|
||||
entityStatsElement.getMainStats().setEntityType(entityFinder.getFancyName());
|
||||
this.plugin.getBossesFileManager().save();
|
||||
|
||||
loadPage(panel, requestedPage, filteredMap, filteredList, bossEntity, entityStatsElement);
|
||||
loadPage(panel, requestedPage, filteredList, bossEntity, entityStatsElement);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -10,11 +10,14 @@ import com.songoda.epicbosses.utils.panel.base.handlers.SubVariablePanelHandler;
|
||||
import com.songoda.epicbosses.utils.panel.builder.PanelBuilder;
|
||||
import com.songoda.epicbosses.utils.potion.PotionEffectConverter;
|
||||
import com.songoda.epicbosses.utils.potion.holder.PotionEffectHolder;
|
||||
import com.songoda.epicbosses.utils.version.VersionHandler;
|
||||
import org.bukkit.Material;
|
||||
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;
|
||||
@ -78,7 +81,16 @@ public class PotionEffectTypeEditorPanel extends SubVariablePanelHandler<Skill,
|
||||
ItemStack itemStack = new ItemStack(Material.POTION);
|
||||
PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();
|
||||
|
||||
potionMeta.addCustomEffect(this.potionEffectConverter.from(potionEffectHolder), true);
|
||||
if (new VersionHandler().getVersion().isHigherThanOrEqualTo(Versions.v1_13_R1)) {
|
||||
PotionType potionType = PotionType.getByEffect(potionEffectType);
|
||||
|
||||
if (potionType == null) potionType = PotionType.WATER;
|
||||
|
||||
potionMeta.setBasePotionData(new PotionData(potionType));
|
||||
} else {
|
||||
potionMeta.addCustomEffect(this.potionEffectConverter.from(potionEffectHolder), true);
|
||||
}
|
||||
|
||||
itemStack.setItemMeta(potionMeta);
|
||||
|
||||
Map<String, String> replaceMap = new HashMap<>();
|
||||
|
@ -22,9 +22,11 @@ import com.songoda.epicbosses.utils.itemstack.converters.MaterialConverter;
|
||||
import com.songoda.epicbosses.utils.panel.base.ClickAction;
|
||||
import com.songoda.epicbosses.utils.panel.base.ISubVariablePanelHandler;
|
||||
import com.songoda.epicbosses.utils.time.TimeUnit;
|
||||
import com.songoda.epicbosses.utils.version.VersionHandler;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -32,6 +34,8 @@ import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@ -42,10 +46,13 @@ import java.util.*;
|
||||
public class Cage extends CustomSkillHandler {
|
||||
|
||||
private static final MaterialConverter MATERIAL_CONVERTER = new MaterialConverter();
|
||||
private static final VersionHandler versionHandler = new VersionHandler();
|
||||
|
||||
@Getter private static final Map<Location, CageLocationData> cageLocationDataMap = new HashMap<>();
|
||||
@Getter private static final List<UUID> playersInCage = new ArrayList<>();
|
||||
|
||||
private static Method setBlockDataMethod;
|
||||
|
||||
private final MaterialTypeEditorPanel flatTypeEditor, wallTypeEditor, insideTypeEditor;
|
||||
private BossPanelManager bossPanelManager;
|
||||
private CustomBosses plugin;
|
||||
@ -72,8 +79,8 @@ public class Cage extends CustomSkillHandler {
|
||||
@Override
|
||||
public List<ICustomSettingAction> getOtherSkillDataActions(Skill skill, CustomSkillElement customSkillElement) {
|
||||
List<ICustomSettingAction> clickActions = new ArrayList<>();
|
||||
ItemStack clickStack = new ItemStack(Material.STONE_PLATE);
|
||||
ItemStack duration = new ItemStack(Material.WATCH);
|
||||
ItemStack clickStack = new ItemStack(versionHandler.getVersion().isHigherThanOrEqualTo(Versions.v1_13_R1) ? Material.STONE_PRESSURE_PLATE : Material.valueOf("STONE_PLATE"));
|
||||
ItemStack duration = new ItemStack(versionHandler.getVersion().isHigherThanOrEqualTo(Versions.v1_13_R1) ? Material.CLOCK : Material.valueOf("WATCH"));
|
||||
ClickAction flatAction = (event -> this.flatTypeEditor.openFor((Player) event.getWhoClicked(), skill, customSkillElement));
|
||||
ClickAction wallAction = (event -> this.wallTypeEditor.openFor((Player) event.getWhoClicked(), skill, customSkillElement));
|
||||
ClickAction insideAction = (event -> this.insideTypeEditor.openFor((Player) event.getWhoClicked(), skill, customSkillElement));
|
||||
@ -129,8 +136,24 @@ public class Cage extends CustomSkillHandler {
|
||||
BlockState oldState = cageLocationData.getOldBlockState();
|
||||
|
||||
if(oldState != null) {
|
||||
location.getBlock().setType(oldState.getType());
|
||||
location.getBlock().setData(oldState.getData().getData());
|
||||
if (versionHandler.getVersion().isHigherThanOrEqualTo(Versions.v1_13_R1)) {
|
||||
location.getBlock().setBlockData(oldState.getBlockData());
|
||||
} else {
|
||||
if (setBlockDataMethod == null) {
|
||||
try {
|
||||
setBlockDataMethod = Block.class.getMethod("setData", byte.class);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
location.getBlock().setType(oldState.getType());
|
||||
try {
|
||||
setBlockDataMethod.invoke(location.getBlock(), oldState.getData().getData());
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getCageLocationDataMap().remove(location);
|
||||
|
@ -12,7 +12,9 @@ import com.songoda.epicbosses.skills.interfaces.IOtherSkillDataElement;
|
||||
import com.songoda.epicbosses.skills.types.CustomSkillElement;
|
||||
import com.songoda.epicbosses.utils.Message;
|
||||
import com.songoda.epicbosses.utils.NumberUtils;
|
||||
import com.songoda.epicbosses.utils.Versions;
|
||||
import com.songoda.epicbosses.utils.panel.base.ClickAction;
|
||||
import com.songoda.epicbosses.utils.version.VersionHandler;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -29,6 +31,8 @@ import java.util.List;
|
||||
*/
|
||||
public class Minions extends CustomSkillHandler {
|
||||
|
||||
private static final VersionHandler versionHandler = new VersionHandler();
|
||||
|
||||
private CustomBosses plugin;
|
||||
|
||||
public Minions(CustomBosses plugin) {
|
||||
@ -50,7 +54,7 @@ public class Minions extends CustomSkillHandler {
|
||||
List<ICustomSettingAction> clickActions = new ArrayList<>();
|
||||
|
||||
clickActions.add(BossSkillManager.createCustomSkillAction("Amount Editor", getAmountCurrent(customSkillElement), new ItemStack(Material.REDSTONE), getAmountAction(skill, customSkillElement)));
|
||||
clickActions.add(BossSkillManager.createCustomSkillAction("Minion to Spawn Editor", getMinionToSpawnCurrent(customSkillElement), new ItemStack(Material.MONSTER_EGG), getMinionToSpawnAction(skill, customSkillElement)));
|
||||
clickActions.add(BossSkillManager.createCustomSkillAction("Minion to Spawn Editor", getMinionToSpawnCurrent(customSkillElement), new ItemStack(versionHandler.getVersion().isHigherThanOrEqualTo(Versions.v1_13_R1) ? Material.CREEPER_SPAWN_EGG : Material.valueOf("MONSTER_EGG")), getMinionToSpawnAction(skill, customSkillElement)));
|
||||
|
||||
return clickActions;
|
||||
}
|
||||
|
@ -27,9 +27,9 @@ public class ItemStackHolderConverter implements IConverter<ItemStackHolder, Con
|
||||
List<String> enchants = (List<String>) configurationSection.getList("enchants", null);
|
||||
String skullOwner = configurationSection.getString("skullOwner", null);
|
||||
Short spawnerId = (Short) configurationSection.get("spawnerId", null);
|
||||
Boolean isGlowing = (Boolean) configurationSection.get("isGlowing", null);
|
||||
//Boolean isGlowing = (Boolean) configurationSection.get("isGlowing", null);
|
||||
|
||||
return new ItemStackHolder(amount, type, durability, name, lore, enchants, skullOwner, spawnerId, isGlowing);
|
||||
return new ItemStackHolder(amount, type, durability, name, lore, enchants, skullOwner, spawnerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,12 +3,15 @@ package com.songoda.epicbosses.utils.itemstack;
|
||||
import com.songoda.epicbosses.utils.NumberUtils;
|
||||
import com.songoda.epicbosses.utils.ServerUtils;
|
||||
import com.songoda.epicbosses.utils.StringUtils;
|
||||
import com.songoda.epicbosses.utils.Versions;
|
||||
import com.songoda.epicbosses.utils.itemstack.enchants.GlowEnchant;
|
||||
import com.songoda.epicbosses.utils.itemstack.holder.ItemStackHolder;
|
||||
import com.songoda.epicbosses.utils.version.VersionHandler;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
@ -22,6 +25,47 @@ import java.util.*;
|
||||
*/
|
||||
public class ItemStackUtils {
|
||||
|
||||
private static final VersionHandler versionHandler = new VersionHandler();
|
||||
private static final Map<EntityType, Material> spawnableEntityMaterials;
|
||||
private static final Map<EntityType, Short> spawnableEntityIds;
|
||||
|
||||
static {
|
||||
spawnableEntityMaterials = new HashMap<>();
|
||||
spawnableEntityIds = new HashMap<>();
|
||||
|
||||
boolean isLegacy = versionHandler.getVersion().isLessThanOrEqualTo(Versions.v1_12_R1);
|
||||
|
||||
Arrays.stream(EntityType.values()).filter(EntityType::isSpawnable).forEach(entityType -> {
|
||||
if (isLegacy) {
|
||||
spawnableEntityIds.put(entityType, entityType.getTypeId());
|
||||
} else {
|
||||
String materialName = entityType.name() + "_SPAWN_EGG";
|
||||
Material material = Material.matchMaterial(materialName);
|
||||
if (material != null)
|
||||
spawnableEntityMaterials.put(entityType, material);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static List<EntityType> getSpawnableEntityTypes() {
|
||||
if (versionHandler.getVersion().isLessThanOrEqualTo(Versions.v1_12_R1)) {
|
||||
return new ArrayList<>(spawnableEntityIds.keySet());
|
||||
} else {
|
||||
return new ArrayList<>(spawnableEntityMaterials.keySet());
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack getSpawnEggForEntity(EntityType entityType) {
|
||||
if (!entityType.isSpawnable())
|
||||
return new ItemStack(Material.AIR);
|
||||
|
||||
if (versionHandler.getVersion().isLessThanOrEqualTo(Versions.v1_12_R1)) {
|
||||
return new ItemStack(Material.valueOf("MONSTER_EGG"), spawnableEntityIds.get(entityType));
|
||||
} else {
|
||||
return new ItemStack(spawnableEntityMaterials.get(entityType));
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack createItemStack(ItemStack itemStack, Map<String,String> replaceMap) {
|
||||
return createItemStack(itemStack, replaceMap, null);
|
||||
}
|
||||
@ -83,14 +127,14 @@ public class ItemStackUtils {
|
||||
Material mat;
|
||||
|
||||
if(NumberUtils.get().isInt(type)) {
|
||||
mat = Material.getMaterial(NumberUtils.get().getInteger(type));
|
||||
mat = MaterialUtils.fromId(NumberUtils.get().getInteger(type));
|
||||
} else {
|
||||
if(type.contains(":")) {
|
||||
String[] split = type.split(":");
|
||||
String typeSplit = split[0];
|
||||
|
||||
if(NumberUtils.get().isInt(typeSplit)) {
|
||||
mat = Material.getMaterial(NumberUtils.get().getInteger(typeSplit));
|
||||
mat = MaterialUtils.fromId(NumberUtils.get().getInteger(typeSplit));
|
||||
} else {
|
||||
mat = Material.getMaterial(typeSplit);
|
||||
}
|
||||
@ -179,7 +223,7 @@ public class ItemStackUtils {
|
||||
itemStack.setDurability(dura);
|
||||
}
|
||||
|
||||
if(configurationSection.contains("owner") && itemStack.getType() == Material.SKULL_ITEM) {
|
||||
if(configurationSection.contains("owner") && itemStack.getType() == MaterialUtils.getSkullMaterial()) {
|
||||
SkullMeta skullMeta = (SkullMeta) itemStack.getItemMeta();
|
||||
|
||||
skullMeta.setOwner(owner);
|
||||
|
@ -0,0 +1,37 @@
|
||||
package com.songoda.epicbosses.utils.itemstack;
|
||||
|
||||
import com.songoda.epicbosses.utils.Versions;
|
||||
import com.songoda.epicbosses.utils.version.VersionHandler;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MaterialUtils {
|
||||
|
||||
private static final VersionHandler versionHandler = new VersionHandler();
|
||||
private static Map<Integer, Material> materialIdMap;
|
||||
|
||||
static {
|
||||
materialIdMap = new HashMap<>();
|
||||
|
||||
for (Material material : Material.values()) {
|
||||
try {
|
||||
materialIdMap.put(material.getId(), material);
|
||||
} catch (Exception ignored) { }
|
||||
}
|
||||
}
|
||||
|
||||
public static Material fromId(int id) {
|
||||
return materialIdMap.get(id);
|
||||
}
|
||||
|
||||
public static Material getSkullMaterial() {
|
||||
if (versionHandler.getVersion().isHigherThanOrEqualTo(Versions.v1_13_R1)) {
|
||||
return Material.PLAYER_HEAD;
|
||||
} else {
|
||||
return Material.getMaterial("SKULL_ITEM");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -2,6 +2,7 @@ package com.songoda.epicbosses.utils.itemstack.converters;
|
||||
|
||||
import com.songoda.epicbosses.utils.IConverter;
|
||||
import com.songoda.epicbosses.utils.NumberUtils;
|
||||
import com.songoda.epicbosses.utils.itemstack.MaterialUtils;
|
||||
import org.bukkit.Material;
|
||||
|
||||
/**
|
||||
@ -25,7 +26,7 @@ public class MaterialConverter implements IConverter<String, Material> {
|
||||
}
|
||||
|
||||
if(NumberUtils.get().isInt(input)) {
|
||||
return Material.getMaterial(NumberUtils.get().getInteger(input));
|
||||
return MaterialUtils.fromId(NumberUtils.get().getInteger(input));
|
||||
}
|
||||
|
||||
return Material.matchMaterial(input);
|
||||
|
@ -16,7 +16,7 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.12.2</version>
|
||||
<version>1.14.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -16,7 +16,7 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.12.2</version>
|
||||
<version>1.14.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
Loading…
Reference in New Issue
Block a user