Converted to Core versioning system.

This commit is contained in:
Brianna 2019-10-07 17:24:55 -04:00
parent 6135f9c257
commit 22d58040f2
43 changed files with 173 additions and 369 deletions

View File

@ -1,6 +1,7 @@
package com.songoda.epicbosses.panel.skills.custom;
import com.google.gson.JsonObject;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.EpicBosses;
import com.songoda.epicbosses.api.BossAPI;
import com.songoda.epicbosses.managers.BossPanelManager;
@ -11,7 +12,6 @@ import com.songoda.epicbosses.skills.types.PotionSkillElement;
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.ItemStackUtils;
import com.songoda.epicbosses.utils.panel.Panel;
import com.songoda.epicbosses.utils.panel.base.handlers.VariablePanelHandler;
@ -110,7 +110,7 @@ public class PotionSkillEditorPanel extends VariablePanelHandler<Skill> {
ItemStack itemStack = new ItemStack(Material.POTION);
PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();
if (new VersionHandler().getVersion().isHigherThanOrEqualTo(Versions.v1_13_R1)) {
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
PotionType potionType = PotionType.getByEffect(PotionEffectType.BLINDNESS);
if (potionType == null) potionType = PotionType.WATER;

View File

@ -1,19 +1,18 @@
package com.songoda.epicbosses.panel.skills.custom.potions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.EpicBosses;
import com.songoda.epicbosses.managers.BossPanelManager;
import com.songoda.epicbosses.skills.Skill;
import com.songoda.epicbosses.utils.PotionEffectFinder;
import com.songoda.epicbosses.utils.ServerUtils;
import com.songoda.epicbosses.utils.StringUtils;
import com.songoda.epicbosses.utils.Versions;
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.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;
@ -50,7 +49,7 @@ public class PotionEffectTypeEditorPanel extends SubVariablePanelHandler<Skill,
int maxPage = panel.getMaxPage(list);
panel.setOnPageChange(((player, currentPage, requestedPage) -> {
if(requestedPage < 0 || requestedPage > maxPage) return false;
if (requestedPage < 0 || requestedPage > maxPage) return false;
loadPage(panel, requestedPage, list, skill, potionEffectHolder);
return true;
@ -77,14 +76,15 @@ public class PotionEffectTypeEditorPanel extends SubVariablePanelHandler<Skill,
String type = potionEffectHolder.getType();
ServerUtils.get().runTaskAsync(() -> panel.loadPage(requestedPage, ((slot, realisticSlot) -> {
if(slot >= potionEffectTypes.size()) {
panel.setItem(realisticSlot, new ItemStack(Material.AIR), e -> {});
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();
if (new VersionHandler().getVersion().isHigherThanOrEqualTo(Versions.v1_13_R1)) {
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
PotionType potionType = PotionType.getByEffect(potionEffectType);
if (potionType == null) potionType = PotionType.WATER;
@ -101,7 +101,7 @@ public class PotionEffectTypeEditorPanel extends SubVariablePanelHandler<Skill,
replaceMap.put("{effect}", StringUtils.get().formatString(potionEffectType.getName()));
if(type != null && !type.isEmpty()) {
if (type != null && !type.isEmpty()) {
PotionEffectFinder potionEffectFinder = PotionEffectFinder.getByName(type);
if (potionEffectFinder != null) {
@ -110,14 +110,14 @@ public class PotionEffectTypeEditorPanel extends SubVariablePanelHandler<Skill,
}
}
if(!found) {
if (!found) {
ItemStackUtils.applyDisplayName(itemStack, this.plugin.getDisplay().getString("Display.Skills.CreatePotion.name"), replaceMap);
}
panel.setItem(realisticSlot, itemStack, e -> {
PotionEffectFinder potionEffectFinder = PotionEffectFinder.getByEffect(potionEffectType);
if(potionEffectFinder != null) {
if (potionEffectFinder != null) {
potionEffectHolder.setType(potionEffectFinder.getFancyName());
this.bossPanelManager.getCreatePotionEffectMenu().openFor((Player) e.getWhoClicked(), skill, potionEffectHolder);

View File

@ -1,5 +1,7 @@
package com.songoda.epicbosses.skills.custom;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.EpicBosses;
import com.songoda.epicbosses.api.BossAPI;
import com.songoda.epicbosses.holder.ActiveBossHolder;
@ -83,8 +85,8 @@ public class Cage extends CustomSkillHandler {
@Override
public List<ICustomSettingAction> getOtherSkillDataActions(Skill skill, CustomSkillElement customSkillElement) {
List<ICustomSettingAction> clickActions = new ArrayList<>();
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"));
ItemStack clickStack = CompatibleMaterial.STONE_PRESSURE_PLATE.getItem();
ItemStack duration = CompatibleMaterial.CLOCK.getItem();
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));
@ -140,7 +142,7 @@ public class Cage extends CustomSkillHandler {
BlockState oldState = cageLocationData.getOldBlockState();
if(oldState != null) {
if (versionHandler.getVersion().isHigherThanOrEqualTo(Versions.v1_13_R1)) {
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
location.getBlock().setBlockData(oldState.getBlockData());
} else {
if (setBlockDataMethod == null) {

View File

@ -1,5 +1,6 @@
package com.songoda.epicbosses.skills.custom;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.epicbosses.EpicBosses;
import com.songoda.epicbosses.api.BossAPI;
import com.songoda.epicbosses.holder.ActiveBossHolder;
@ -12,9 +13,7 @@ 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;
@ -31,8 +30,6 @@ import java.util.List;
*/
public class Minions extends CustomSkillHandler {
private static final VersionHandler versionHandler = new VersionHandler();
private EpicBosses plugin;
public Minions(EpicBosses plugin) {
@ -54,7 +51,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(versionHandler.getVersion().isHigherThanOrEqualTo(Versions.v1_13_R1) ? Material.CREEPER_SPAWN_EGG : Material.valueOf("MONSTER_EGG")), getMinionToSpawnAction(skill, customSkillElement)));
clickActions.add(BossSkillManager.createCustomSkillAction("Minion to Spawn Editor", getMinionToSpawnCurrent(customSkillElement), CompatibleMaterial.CREEPER_SPAWN_EGG.getItem(), getMinionToSpawnAction(skill, customSkillElement)));
return clickActions;
}
@ -77,7 +74,7 @@ public class Minions extends CustomSkillHandler {
private String getAmountCurrent(CustomSkillElement customSkillElement) {
CustomMinionSkillElement customMinionSkillElement = customSkillElement.getCustom().getCustomMinionSkillData();
return ""+customMinionSkillElement.getAmount();
return "" + customMinionSkillElement.getAmount();
}
private ClickAction getAmountAction(Skill skill, CustomSkillElement customSkillElement) {
@ -86,7 +83,7 @@ public class Minions extends CustomSkillHandler {
ClickType clickType = event.getClick();
Integer amountToModifyBy;
if(clickType.name().contains("RIGHT")) {
if (clickType.name().contains("RIGHT")) {
amountToModifyBy = -1;
} else {
amountToModifyBy = 1;
@ -96,9 +93,9 @@ public class Minions extends CustomSkillHandler {
String modifyValue;
Integer newAmount;
if(currentAmount == null) currentAmount = 0;
if (currentAmount == null) currentAmount = 0;
if(amountToModifyBy > 0.0) {
if (amountToModifyBy > 0.0) {
modifyValue = "increased";
newAmount = currentAmount + amountToModifyBy;
} else {
@ -106,7 +103,7 @@ public class Minions extends CustomSkillHandler {
newAmount = currentAmount + amountToModifyBy;
}
if(newAmount <= 0) {
if (newAmount <= 0) {
newAmount = 0;
}

View File

@ -1,66 +0,0 @@
package com.songoda.epicbosses.utils;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 27-Jun-18
*/
public enum Versions {
v1_7_R3(1, "1.7.9"),
v1_7_R4(2, "1.7.10"),
v1_8_R1(3, "1.8"),
v1_8_R2(4, "1.8.3"),
v1_8_R3(5, "1.8.9"),
v1_9_R1(6, "1.9"),
v1_9_R2(7, "1.9.4"),
v1_10_R1(8, "1.10"),
v1_11_R1(9, "1.11.2"),
v1_12_R1(10, "1.12.1"),
v1_13_R1(11, "1.13"),
v1_13_R2(12, "1.13.2"),
v1_14_R1(13, "1.14");
private String displayVersion, bukkitVersion;
private int weight;
Versions(int weight, String displayVersion) {
this.weight = weight;
this.displayVersion = displayVersion;
this.bukkitVersion = name();
}
public boolean isLessThan(Versions input) {
return this.weight < input.weight;
}
public boolean isLessThanOrEqualTo(Versions input) {
return this.weight <= input.weight;
}
public boolean isHigherThanOrEqualTo(Versions input) {
return this.weight >= input.weight;
}
public boolean isHigherThan(Versions input) {
return this.weight > input.weight;
}
public static Versions getVersion(String input) {
for(Versions versions : values()) {
if(versions.getBukkitVersion().equalsIgnoreCase(input)) {
return versions;
}
}
return null;
}
public String getDisplayVersion() {
return this.displayVersion;
}
public String getBukkitVersion() {
return this.bukkitVersion;
}
}

View File

@ -1,19 +1,16 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
public class CatHandler implements ICustomEntityHandler {
private VersionHandler versionHandler = new VersionHandler();
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThan(Versions.v1_14_R1)) {
if(ServerVersion.isServerVersionBelow(ServerVersion.V1_14)) {
throw new NullPointerException("This feature is only implemented in version 1.14 and above of Minecraft.");
}

View File

@ -1,6 +1,6 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
@ -13,7 +13,7 @@ public class DolphinHandler implements ICustomEntityHandler {
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThan(Versions.v1_13_R1)) {
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_13)) {
throw new NullPointerException("This feature is only implemented in version 1.13 and above of Minecraft.");
}

View File

@ -1,8 +1,7 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Horse;
@ -15,17 +14,13 @@ import org.bukkit.entity.LivingEntity;
*/
public class DonkeyHorseHandler implements ICustomEntityHandler {
private VersionHandler versionHandler = new VersionHandler();
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThan(Versions.v1_11_R1)) {
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_11))
throw new NullPointerException("This feature is only implemented in version 1.11 and above of Minecraft.");
}
if(this.versionHandler.getVersion().isHigherThanOrEqualTo(Versions.v1_11_R1)) {
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11))
return (LivingEntity) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.DONKEY);
}
Horse horse = (Horse) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.HORSE);
horse.setVariant(Horse.Variant.DONKEY);

View File

@ -1,6 +1,6 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
@ -13,7 +13,7 @@ public class DrownedHandler implements ICustomEntityHandler {
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThan(Versions.v1_13_R1)) {
if(ServerVersion.isServerVersionBelow(ServerVersion.V1_13)) {
throw new NullPointerException("This feature is only implemented in version 1.13 and above of Minecraft.");
}

View File

@ -1,6 +1,6 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
@ -18,9 +18,8 @@ public class ElderGuardianHandler implements ICustomEntityHandler {
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThanOrEqualTo(Versions.v1_7_R4)) {
if(ServerVersion.isServerVersionBelow(ServerVersion.V1_8))
throw new NullPointerException("This feature is only implemented in version 1.8 and above of Minecraft.");
}
return (LivingEntity) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.ELDER_GUARDIAN);
}

View File

@ -1,6 +1,6 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
@ -18,9 +18,8 @@ public class EndermiteHandler implements ICustomEntityHandler {
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThan(Versions.v1_8_R1)) {
if(ServerVersion.isServerVersionBelow(ServerVersion.V1_8))
throw new NullPointerException("This feature is only implemented in version 1.8 and above of Minecraft.");
}
return (LivingEntity) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.ENDERMITE);
}

View File

@ -1,8 +1,7 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
@ -14,11 +13,9 @@ import org.bukkit.entity.LivingEntity;
*/
public class EvokerHandler implements ICustomEntityHandler {
private VersionHandler versionHandler = new VersionHandler();
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThan(Versions.v1_11_R1)) {
if(ServerVersion.isServerVersionBelow(ServerVersion.V1_11)) {
throw new NullPointerException("This feature is only implemented in version 1.11 and above of Minecraft.");
}

View File

@ -1,6 +1,6 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
@ -13,9 +13,8 @@ public class FishHandler implements ICustomEntityHandler {
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThan(Versions.v1_13_R1)) {
if(ServerVersion.isServerVersionBelow(ServerVersion.V1_13))
throw new NullPointerException("This feature is only implemented in version 1.13 and above of Minecraft.");
}
EntityType fishEntityType;

View File

@ -1,6 +1,6 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
@ -13,9 +13,8 @@ public class FoxHandler implements ICustomEntityHandler {
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThan(Versions.v1_14_R1)) {
if(ServerVersion.isServerVersionBelow(ServerVersion.V1_14))
throw new NullPointerException("This feature is only implemented in version 1.14 and above of Minecraft.");
}
return (LivingEntity) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.FOX);
}

View File

@ -1,8 +1,7 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
@ -14,13 +13,10 @@ import org.bukkit.entity.LivingEntity;
*/
public class GuardianHandler implements ICustomEntityHandler {
private VersionHandler versionHandler = new VersionHandler();
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThan(Versions.v1_8_R1)) {
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8))
throw new NullPointerException("This feature is only implemented in version 1.8 and above of Minecraft.");
}
return (LivingEntity) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.GUARDIAN);
}

View File

@ -1,8 +1,7 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
@ -14,13 +13,10 @@ import org.bukkit.entity.LivingEntity;
*/
public class HuskZombieHandler implements ICustomEntityHandler {
private VersionHandler versionHandler = new VersionHandler();
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isHigherThanOrEqualTo(Versions.v1_10_R1)) {
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_10))
return (LivingEntity) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.HUSK);
}
throw new NullPointerException("This feature is only implemented in version 1.10 and above of Minecraft.");
}

View File

@ -1,8 +1,7 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
@ -15,13 +14,10 @@ import org.bukkit.entity.LivingEntity;
*/
public class IllusionerHandler implements ICustomEntityHandler {
private VersionHandler versionHandler = new VersionHandler();
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if (this.versionHandler.getVersion().isLessThan(Versions.v1_11_R1)) {
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_11))
throw new NullPointerException("This feature is only implemented in version 1.11 and above of Minecraft.");
}
return (LivingEntity) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.ILLUSIONER);
}

View File

@ -1,8 +1,7 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
@ -15,13 +14,10 @@ import org.bukkit.entity.Rabbit;
*/
public class KillerBunnyHandler implements ICustomEntityHandler {
private VersionHandler versionHandler = new VersionHandler();
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThanOrEqualTo(Versions.v1_7_R4)) {
if(ServerVersion.isServerVersionBelow(ServerVersion.V1_8))
throw new NullPointerException("This feature is only implemented in version 1.8 and above of Minecraft.");
}
Rabbit rabbit = (Rabbit) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.RABBIT);
rabbit.setRabbitType(Rabbit.Type.THE_KILLER_BUNNY);

View File

@ -1,8 +1,7 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Horse;
@ -15,15 +14,12 @@ import org.bukkit.entity.LivingEntity;
*/
public class LlamaHandler implements ICustomEntityHandler {
private VersionHandler versionHandler = new VersionHandler();
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThan(Versions.v1_11_R1)) {
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_11))
throw new NullPointerException("This feature is only implemented in version 1.11 and above of Minecraft.");
}
if(this.versionHandler.getVersion().isHigherThanOrEqualTo(Versions.v1_11_R1)) {
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11)) {
return (LivingEntity) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.LLAMA);
}

View File

@ -1,8 +1,7 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Horse;
@ -15,17 +14,14 @@ import org.bukkit.entity.LivingEntity;
*/
public class MuleHorseHandler implements ICustomEntityHandler {
private VersionHandler versionHandler = new VersionHandler();
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThan(Versions.v1_11_R1)) {
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_11))
throw new NullPointerException("This feature is only implemented in version 1.11 and above of Minecraft.");
}
if(this.versionHandler.getVersion().isHigherThanOrEqualTo(Versions.v1_11_R1)) {
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11))
return (LivingEntity) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.MULE);
}
Horse horse = (Horse) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.HORSE);
horse.setVariant(Horse.Variant.MULE);

View File

@ -1,6 +1,6 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
@ -13,9 +13,8 @@ public class PandaHandler implements ICustomEntityHandler {
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThan(Versions.v1_14_R1)) {
if(ServerVersion.isServerVersionBelow(ServerVersion.V1_14))
throw new NullPointerException("This feature is only implemented in version 1.14 and above of Minecraft.");
}
return (LivingEntity) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.PANDA);
}

View File

@ -1,8 +1,7 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
@ -14,13 +13,10 @@ import org.bukkit.entity.LivingEntity;
*/
public class ParrotHandler implements ICustomEntityHandler {
private VersionHandler versionHandler = new VersionHandler();
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThan(Versions.v1_12_R1)) {
throw new NullPointerException("This feature is only implemented in version 1.12 and above of Minecraft.");
}
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_12))
throw new NullPointerException("This feature is only implemented in version 1.12 and above of Minecraft.");
return (LivingEntity) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.PARROT);
}

View File

@ -1,8 +1,7 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
@ -10,13 +9,10 @@ import org.bukkit.entity.Phantom;
public class PhantomHandler implements ICustomEntityHandler {
private VersionHandler versionHandler = new VersionHandler();
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThan(Versions.v1_13_R1)) {
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_13))
throw new NullPointerException("This feature is only implemented in version 1.13 and above of Minecraft.");
}
int size = 4;
if (entityType.contains(":")) {

View File

@ -1,6 +1,6 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
@ -13,9 +13,8 @@ public class PillagerHandler implements ICustomEntityHandler {
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThan(Versions.v1_14_R1)) {
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_14))
throw new NullPointerException("This feature is only implemented in version 1.14 and above of Minecraft.");
}
return (LivingEntity) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.PILLAGER);
}

View File

@ -1,6 +1,6 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
@ -14,13 +14,10 @@ import org.bukkit.entity.LivingEntity;
*/
public class PolarBearHandler implements ICustomEntityHandler {
private VersionHandler versionHandler = new VersionHandler();
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThan(Versions.v1_10_R1)) {
if(ServerVersion.isServerVersionBelow(ServerVersion.V1_10))
throw new NullPointerException("This feature is only implemented in version 1.10 and above of Minecraft.");
}
return (LivingEntity) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.POLAR_BEAR);
}

View File

@ -1,8 +1,7 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
@ -14,11 +13,10 @@ import org.bukkit.entity.LivingEntity;
*/
public class RabbitHandler implements ICustomEntityHandler {
private VersionHandler versionHandler = new VersionHandler();
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThan(Versions.v1_8_R1)) {
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) {
throw new NullPointerException("This feature is only implemented in version 1.8 and above of Minecraft.");
}

View File

@ -1,6 +1,6 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
@ -9,11 +9,10 @@ import org.bukkit.entity.LivingEntity;
public class RavagerHandler implements ICustomEntityHandler {
private VersionHandler versionHandler = new VersionHandler();
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThan(Versions.v1_14_R1)) {
if(ServerVersion.isServerVersionBelow(ServerVersion.V1_14)) {
throw new NullPointerException("This feature is only implemented in version 1.14 and above of Minecraft.");
}

View File

@ -1,6 +1,6 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
@ -18,7 +18,7 @@ public class ShulkerHandler implements ICustomEntityHandler {
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThan(Versions.v1_9_R1)) {
if(ServerVersion.isServerVersionBelow(ServerVersion.V1_9)) {
throw new NullPointerException("This feature is only implemented in version 1.9 and above of Minecraft.");
}

View File

@ -1,8 +1,7 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Horse;
@ -15,13 +14,10 @@ import org.bukkit.entity.LivingEntity;
*/
public class SkeletonHorseHandler implements ICustomEntityHandler {
private VersionHandler versionHandler = new VersionHandler();
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isHigherThanOrEqualTo(Versions.v1_11_R1)) {
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11))
return (LivingEntity) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.SKELETON_HORSE);
}
Horse horse = (Horse) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.HORSE);
horse.setVariant(Horse.Variant.SKELETON_HORSE);

View File

@ -1,6 +1,6 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
@ -15,17 +15,13 @@ import org.bukkit.entity.Skeleton;
*/
public class StraySkeletonHandler implements ICustomEntityHandler {
private VersionHandler versionHandler = new VersionHandler();
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThanOrEqualTo(Versions.v1_9_R2)) {
if(ServerVersion.isServerVersionBelow(ServerVersion.V1_10))
throw new NullPointerException("This feature is only implemented in version 1.10 and above of Minecraft.");
}
if(this.versionHandler.getVersion().isHigherThanOrEqualTo(Versions.v1_11_R1)) {
if(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_10))
return (LivingEntity) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.STRAY);
}
Skeleton skeleton = (Skeleton) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.SKELETON);
skeleton.setSkeletonType(Skeleton.SkeletonType.STRAY);

View File

@ -1,21 +1,17 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
public class TraderLlamaHandler implements ICustomEntityHandler {
private VersionHandler versionHandler = new VersionHandler();
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThan(Versions.v1_14_R1)) {
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_12))
throw new NullPointerException("This feature is only implemented in version 1.12 and above of Minecraft.");
}
return (LivingEntity) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.TRADER_LLAMA);
}

View File

@ -1,21 +1,17 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
public class TurtleHandler implements ICustomEntityHandler {
private VersionHandler versionHandler = new VersionHandler();
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThan(Versions.v1_13_R1)) {
if(ServerVersion.isServerVersionBelow(ServerVersion.V1_13))
throw new NullPointerException("This feature is only implemented in version 1.13 and above of Minecraft.");
}
return (LivingEntity) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.TURTLE);
}

View File

@ -1,6 +1,6 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
@ -14,13 +14,10 @@ import org.bukkit.entity.LivingEntity;
*/
public class VexHandler implements ICustomEntityHandler {
private VersionHandler versionHandler = new VersionHandler();
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThan(Versions.v1_11_R1)) {
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_11))
throw new NullPointerException("This feature is only implemented in version 1.11 and above of Minecraft.");
}
return (LivingEntity) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.VEX);
}

View File

@ -1,8 +1,7 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
@ -14,13 +13,10 @@ import org.bukkit.entity.LivingEntity;
*/
public class VindicatorHandler implements ICustomEntityHandler {
private VersionHandler versionHandler = new VersionHandler();
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThan(Versions.v1_11_R1)) {
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_11))
throw new NullPointerException("This feature is only implemented in version 1.11 and above of Minecraft.");
}
return (LivingEntity) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.VINDICATOR);
}

View File

@ -1,19 +1,16 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
public class WanderingTraderHandler implements ICustomEntityHandler {
private VersionHandler versionHandler = new VersionHandler();
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isLessThan(Versions.v1_14_R1)) {
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_14)) {
throw new NullPointerException("This feature is only implemented in version 1.14 and above of Minecraft.");
}

View File

@ -1,6 +1,6 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
@ -19,7 +19,7 @@ public class WitherSkeletonHandler implements ICustomEntityHandler {
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isHigherThanOrEqualTo(Versions.v1_11_R1)) {
if(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11)) {
return (LivingEntity) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.WITHER_SKELETON);
}

View File

@ -1,8 +1,7 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Horse;
@ -15,13 +14,10 @@ import org.bukkit.entity.LivingEntity;
*/
public class ZombieHorseHandler implements ICustomEntityHandler {
private VersionHandler versionHandler = new VersionHandler();
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isHigherThanOrEqualTo(Versions.v1_11_R1)) {
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11))
return (LivingEntity) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.ZOMBIE_HORSE);
}
Horse horse = (Horse) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.HORSE);
horse.setVariant(Horse.Variant.UNDEAD_HORSE);

View File

@ -1,8 +1,7 @@
package com.songoda.epicbosses.utils.entity.handlers;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicbosses.utils.entity.ICustomEntityHandler;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Location;
import org.bukkit.entity.*;
@ -13,15 +12,13 @@ import org.bukkit.entity.*;
*/
public class ZombieVillagerHandler implements ICustomEntityHandler {
private VersionHandler versionHandler = new VersionHandler();
@Override
public LivingEntity getBaseEntity(String entityType, Location spawnLocation) {
if(this.versionHandler.getVersion().isHigherThanOrEqualTo(Versions.v1_11_R1)) {
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11)) {
ZombieVillager zombieVillager = (ZombieVillager) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.ZOMBIE_VILLAGER);
String[] split = entityType.split(":");
if(split.length == 2) {
if (split.length == 2) {
String type = split[1];
Villager.Profession profession;

View File

@ -1,13 +1,8 @@
package com.songoda.epicbosses.utils.file;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
/**
* @author Charles Cullen
@ -29,18 +24,11 @@ public abstract class FileHandler<T> implements IFileHandler<T> {
@Override
public void createFile() {
if(!this.file.exists()) {
if(this.saveResource) {
if (!this.file.exists()) {
if (this.saveResource) {
String name = this.file.getName();
String folder = new VersionHandler().getVersion().isHigherThanOrEqualTo(Versions.v1_13_R1) ? "/current/" : "/legacy/";
String path = folder + name;
try (InputStream resourceStream = this.getClass().getResourceAsStream(path)) {
Files.copy(resourceStream, new File(this.javaPlugin.getDataFolder(), name).toPath());
return;
} catch (IOException e) {
e.printStackTrace();
}
javaPlugin.saveResource(name, false);
}
FileUtils.get().createFile(this.file);

View File

@ -1,14 +1,9 @@
package com.songoda.epicbosses.utils.file;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
/**
* @author Charles Cullen
@ -30,8 +25,8 @@ public class YmlFileHandler implements IFileHandler<FileConfiguration> {
@Override
public void createFile() {
if(!this.file.exists()) {
if(this.saveResource) {
if (!this.file.exists()) {
if (this.saveResource) {
String name = this.file.getName();
System.out.println(name);

View File

@ -1,9 +1,10 @@
package com.songoda.epicbosses.utils.itemstack;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.ServerVersion;
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;
@ -33,7 +34,7 @@ public class ItemStackUtils {
spawnableEntityMaterials = new HashMap<>();
spawnableEntityIds = new HashMap<>();
boolean isLegacy = versionHandler.getVersion().isLessThanOrEqualTo(Versions.v1_12_R1);
boolean isLegacy = ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_12);
Arrays.stream(EntityType.values()).filter(EntityType::isSpawnable).forEach(entityType -> {
if (isLegacy) {
@ -48,7 +49,7 @@ public class ItemStackUtils {
}
public static List<EntityType> getSpawnableEntityTypes() {
if (versionHandler.getVersion().isLessThanOrEqualTo(Versions.v1_12_R1)) {
if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_12)) {
return new ArrayList<>(spawnableEntityIds.keySet());
} else {
return new ArrayList<>(spawnableEntityMaterials.keySet());
@ -59,18 +60,18 @@ public class ItemStackUtils {
if (!entityType.isSpawnable())
return new ItemStack(Material.AIR);
if (versionHandler.getVersion().isLessThanOrEqualTo(Versions.v1_12_R1)) {
if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_12)) {
return new ItemStack(Material.valueOf("MONSTER_EGG"), 1, spawnableEntityIds.get(entityType));
} else {
return new ItemStack(spawnableEntityMaterials.get(entityType));
}
}
public static ItemStack createItemStack(ItemStack itemStack, Map<String,String> replaceMap) {
public static ItemStack createItemStack(ItemStack itemStack, Map<String, String> replaceMap) {
return createItemStack(itemStack, replaceMap, null);
}
public static ItemStack createItemStack(ItemStack itemStack, Map<String,String> replaceMap, Map<String,Object> compoundData) {
public static ItemStack createItemStack(ItemStack itemStack, Map<String, String> replaceMap, Map<String, Object> compoundData) {
ItemStack cloneStack = itemStack.clone();
ItemMeta itemMeta = cloneStack.getItemMeta();
boolean hasName = cloneStack.getItemMeta().hasDisplayName();
@ -78,21 +79,21 @@ public class ItemStackUtils {
String name = "";
List<String> newLore = new ArrayList<>();
if(hasName) name = cloneStack.getItemMeta().getDisplayName();
if (hasName) name = cloneStack.getItemMeta().getDisplayName();
if(replaceMap != null && !replaceMap.isEmpty()) {
if(hasName) {
for(String s : replaceMap.keySet()) {
if (replaceMap != null && !replaceMap.isEmpty()) {
if (hasName) {
for (String s : replaceMap.keySet()) {
name = name.replace(s, replaceMap.get(s));
}
itemMeta.setDisplayName(name);
}
if(hasLore) {
for(String s : itemMeta.getLore()) {
for(String z : replaceMap.keySet()) {
if(s.contains(z)) s = s.replace(z, replaceMap.get(z));
if (hasLore) {
for (String s : itemMeta.getLore()) {
for (String z : replaceMap.keySet()) {
if (s.contains(z)) s = s.replace(z, replaceMap.get(z));
}
newLore.add(s);
@ -104,7 +105,7 @@ public class ItemStackUtils {
cloneStack.setItemMeta(itemMeta);
if(compoundData == null || compoundData.isEmpty()) return cloneStack;
if (compoundData == null || compoundData.isEmpty()) return cloneStack;
return cloneStack;
}
@ -126,14 +127,14 @@ public class ItemStackUtils {
short meta = 0;
Material mat;
if(NumberUtils.get().isInt(type)) {
if (NumberUtils.get().isInt(type)) {
mat = MaterialUtils.fromId(NumberUtils.get().getInteger(type));
} else {
if(type.contains(":")) {
if (type.contains(":")) {
String[] split = type.split(":");
String typeSplit = split[0];
if(NumberUtils.get().isInt(typeSplit)) {
if (NumberUtils.get().isInt(typeSplit)) {
mat = MaterialUtils.fromId(NumberUtils.get().getInteger(typeSplit));
} else {
mat = Material.getMaterial(typeSplit);
@ -145,21 +146,21 @@ public class ItemStackUtils {
}
}
if((replacedMap != null) && (name != null)) {
for(String z : replacedMap.keySet()) {
if(!name.contains(z)) continue;
if ((replacedMap != null) && (name != null)) {
for (String z : replacedMap.keySet()) {
if (!name.contains(z)) continue;
name = name.replace(z, replacedMap.get(z));
}
}
if(lore != null && !lore.isEmpty()) {
for(String z : lore) {
if (lore != null && !lore.isEmpty()) {
for (String z : lore) {
String y = z;
if(replacedMap != null) {
for(String x : replacedMap.keySet()) {
if(x == null || !y.contains(x)) continue;
if (replacedMap != null) {
for (String x : replacedMap.keySet()) {
if (x == null || !y.contains(x)) continue;
if (replacedMap.get(x) == null) {
ServerUtils.get().logDebug("Failed to apply replaced lore: [y=" + y + "x=" + x + "]");
@ -170,10 +171,10 @@ public class ItemStackUtils {
}
}
if(y.contains("\n")) {
if (y.contains("\n")) {
String[] split = y.split("\n");
for(String s2 : split) {
for (String s2 : split) {
newLore.add(ChatColor.translateAlternateColorCodes('&', s2));
}
} else {
@ -182,12 +183,12 @@ public class ItemStackUtils {
}
}
if(enchants != null) {
for(String s : enchants) {
if (enchants != null) {
for (String s : enchants) {
String[] spl = s.split(":");
String ench = spl[0];
if(ench.equalsIgnoreCase("GLOW")) {
if (ench.equalsIgnoreCase("GLOW")) {
addGlow = true;
} else {
int level = Integer.parseInt(spl[1]);
@ -197,33 +198,33 @@ public class ItemStackUtils {
}
}
if(mat == null) return null;
if (mat == null) return null;
ItemStack itemStack = new ItemStack(mat, amount, meta);
ItemMeta itemMeta = itemStack.getItemMeta();
if(!newLore.isEmpty()) {
if (!newLore.isEmpty()) {
itemMeta.setLore(newLore);
}
if(name != null) {
if(!name.equals("")) {
if (name != null) {
if (!name.equals("")) {
itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
}
}
itemStack.setItemMeta(itemMeta);
if(!map.isEmpty()) {
if (!map.isEmpty()) {
itemStack.addUnsafeEnchantments(map);
}
if(configurationSection.contains("durability")) {
if (configurationSection.contains("durability")) {
short dura = itemStack.getType().getMaxDurability();
dura -= (short) durability - 1;
itemStack.setDurability(dura);
}
if(configurationSection.contains("owner") && itemStack.getType() == MaterialUtils.getSkullMaterial()) {
if (configurationSection.contains("owner") && itemStack.getType() == CompatibleMaterial.PLAYER_HEAD.getMaterial()) {
SkullMeta skullMeta = (SkullMeta) itemStack.getItemMeta();
skullMeta.setOwner(owner);
@ -231,7 +232,7 @@ public class ItemStackUtils {
itemStack.setItemMeta(skullMeta);
}
return addGlow? addGlow(itemStack) : itemStack;
return addGlow ? addGlow(itemStack) : itemStack;
}
public static void applyDisplayName(ItemStack itemStack, String name) {
@ -241,13 +242,13 @@ public class ItemStackUtils {
public static void applyDisplayName(ItemStack itemStack, String name, Map<String, String> replaceMap) {
ItemMeta itemMeta = itemStack.getItemMeta();
if(replaceMap != null) {
for(String s : replaceMap.keySet()) {
if(name.contains(s)) name = name.replace(s, replaceMap.get(s));
if (replaceMap != null) {
for (String s : replaceMap.keySet()) {
if (name.contains(s)) name = name.replace(s, replaceMap.get(s));
}
}
if(itemMeta == null) return;
if (itemMeta == null) return;
itemMeta.setDisplayName(StringUtils.get().translateColor(name));
itemStack.setItemMeta(itemMeta);
@ -262,13 +263,13 @@ public class ItemStackUtils {
if (itemStack == null || (itemMeta = itemStack.getItemMeta()) == null)
return;
if (lore == null || lore.isEmpty()) {
itemMeta.setLore(Collections.EMPTY_LIST);
itemStack.setItemMeta(itemMeta);
itemMeta.setLore(Collections.EMPTY_LIST);
itemStack.setItemMeta(itemMeta);
return;
}
if(replaceMap != null) {
for(String s : replaceMap.keySet()) {
if (replaceMap != null) {
for (String s : replaceMap.keySet()) {
lore.replaceAll(loreLine -> loreLine
.replace(s, replaceMap.get(s))
.replace('&', '§')
@ -281,7 +282,7 @@ public class ItemStackUtils {
}
public static String getName(ItemStack itemStack) {
if(!itemStack.hasItemMeta() || !itemStack.getItemMeta().hasDisplayName()) {
if (!itemStack.hasItemMeta() || !itemStack.getItemMeta().hasDisplayName()) {
return StringUtils.get().formatString(itemStack.getType().name());
}
@ -293,15 +294,15 @@ public class ItemStackUtils {
public static Material getType(String string) {
Material material = Material.getMaterial(string);
if(material == null) {
if(NumberUtils.get().isInt(string)) {
if (material == null) {
if (NumberUtils.get().isInt(string)) {
return null;
} else {
String[] split = string.split(":");
material = Material.getMaterial(split[0]);
if(material != null) return material;
if (material != null) return material;
return null;
}
@ -321,16 +322,16 @@ public class ItemStackUtils {
public static void giveItems(Player player, List<ItemStack> items) {
PlayerInventory inventory = player.getInventory();
for(ItemStack itemStack : items) {
for (ItemStack itemStack : items) {
int amount = itemStack.getAmount();
while(amount > 0) {
int toGive = amount > 64? 64 : amount;
while (amount > 0) {
int toGive = amount > 64 ? 64 : amount;
ItemStack stack = itemStack.clone();
stack.setAmount(toGive);
if(inventory.firstEmpty() != -1) {
if (inventory.firstEmpty() != -1) {
inventory.addItem(stack);
} else {
player.getWorld().dropItemNaturally(player.getLocation(), stack);
@ -344,18 +345,18 @@ public class ItemStackUtils {
public static void takeItems(Player player, Map<ItemStack, Integer> items) {
PlayerInventory inventory = player.getInventory();
for(ItemStack itemStack : items.keySet()) {
for (ItemStack itemStack : items.keySet()) {
int toTake = items.get(itemStack);
int i = 0;
while(toTake > 0 && i < inventory.getSize()) {
while (toTake > 0 && i < inventory.getSize()) {
if (inventory.getItem(i) != null && inventory.getItem(i).getType() == itemStack.getType() && (inventory.getItem(i).getData().getData() == itemStack.getData().getData() || itemStack.getData().getData() == -1)) {
ItemStack target = inventory.getItem(i);
if(target.getAmount() > toTake) {
target.setAmount(target.getAmount()-toTake);
if (target.getAmount() > toTake) {
target.setAmount(target.getAmount() - toTake);
inventory.setItem(i, target);
break;
} else if(target.getAmount() == toTake) {
} else if (target.getAmount() == toTake) {
inventory.setItem(i, new ItemStack(Material.AIR));
break;
} else {
@ -372,7 +373,7 @@ public class ItemStackUtils {
PlayerInventory playerInventory = player.getInventory();
int amountInInventory = 0;
for(int i = 0; i < playerInventory.getSize(); i++) {
for (int i = 0; i < playerInventory.getSize(); i++) {
if (playerInventory.getItem(i) != null && playerInventory.getItem(i).getType() == itemStack.getType() && (playerInventory.getItem(i).getData().getData() == itemStack.getData().getData() || itemStack.getData().getData() == -1)) {
amountInInventory += playerInventory.getItem(i).getAmount();
}
@ -397,25 +398,25 @@ public class ItemStackUtils {
}
public static boolean isItemStackSame(ItemStack itemStack1, ItemStack itemStack2) {
if(itemStack1 == null || itemStack2 == null) return false;
if(itemStack1.getType() != itemStack2.getType()) return false;
if (itemStack1 == null || itemStack2 == null) return false;
if (itemStack1.getType() != itemStack2.getType()) return false;
// Durability checks are too tempermental to be reliable for all versions
//if(itemStack1.getDurability() != itemStack2.getDurability()) return false;
ItemMeta itemMeta1 = itemStack1.getItemMeta();
ItemMeta itemMeta2 = itemStack2.getItemMeta();
if(itemMeta1 == null || itemMeta2 == null) return false;
if (itemMeta1 == null || itemMeta2 == null) return false;
if(itemMeta1.hasDisplayName() == itemMeta2.hasDisplayName()) {
if(itemMeta1.hasDisplayName() && !itemMeta1.getDisplayName().equals(itemMeta2.getDisplayName()))
if (itemMeta1.hasDisplayName() == itemMeta2.hasDisplayName()) {
if (itemMeta1.hasDisplayName() && !itemMeta1.getDisplayName().equals(itemMeta2.getDisplayName()))
return false;
} else {
return false;
}
if(itemMeta1.hasLore() == itemMeta2.hasLore()) {
if(itemMeta1.hasLore() && !itemMeta1.getLore().equals(itemMeta2.getLore()))
if (itemMeta1.hasLore() == itemMeta2.hasLore()) {
if (itemMeta1.hasLore() && !itemMeta1.getLore().equals(itemMeta2.getLore()))
return false;
} else {
return false;

View File

@ -1,6 +1,5 @@
package com.songoda.epicbosses.utils.itemstack;
import com.songoda.epicbosses.utils.Versions;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.Material;
@ -9,7 +8,6 @@ import java.util.Map;
public class MaterialUtils {
private static final VersionHandler versionHandler = new VersionHandler();
private static Map<Integer, Material> materialIdMap;
static {
@ -26,12 +24,4 @@ public class MaterialUtils {
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");
}
}
}

View File

@ -1,7 +1,6 @@
package com.songoda.epicbosses.utils.version;
import com.songoda.epicbosses.utils.Versions;
import org.bukkit.Bukkit;
import com.songoda.core.compatibility.ServerVersion;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.ItemStack;
@ -12,22 +11,12 @@ import org.bukkit.inventory.ItemStack;
*/
public class VersionHandler {
private Versions version;
public VersionHandler() {
String v = Bukkit.getServer().getClass().getPackage().getName();
v = v.substring(v.lastIndexOf(".") + 1);
this.version = Versions.getVersion(v);
}
public boolean canUseOffHand() {
return this.version.isHigherThanOrEqualTo(Versions.v1_9_R1);
return ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9);
}
public ItemStack getItemInHand(HumanEntity humanEntity) {
if(this.version.isLessThanOrEqualTo(Versions.v1_8_R3)) {
if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_8)) {
return humanEntity.getItemInHand();
} else {
return humanEntity.getInventory().getItemInMainHand();
@ -35,14 +24,10 @@ public class VersionHandler {
}
public void setItemInHand(HumanEntity humanEntity, ItemStack itemStack) {
if(this.version.isLessThanOrEqualTo(Versions.v1_8_R3)) {
if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_8)) {
humanEntity.setItemInHand(itemStack);
} else {
humanEntity.getInventory().setItemInMainHand(itemStack);
}
}
public Versions getVersion() {
return this.version;
}
}