PR changes and updated to 8.14.10

This commit is contained in:
Auxilor 2021-11-06 18:52:09 +00:00
parent 4b941fe5b6
commit e807950e5d
7 changed files with 87 additions and 44 deletions

View File

@ -22,7 +22,8 @@ import com.willfp.ecoenchants.enchantments.support.obtaining.VillagerListeners;
import com.willfp.ecoenchants.enchantments.util.ItemConversions;
import com.willfp.ecoenchants.enchantments.util.TimedRunnable;
import com.willfp.ecoenchants.enchantments.util.WatcherTriggers;
import com.willfp.ecoenchants.integrations.mythicmobs.IntegrationMythicMobs;
import com.willfp.ecoenchants.integrations.mythicmobs.MythicMobsManager;
import com.willfp.ecoenchants.integrations.mythicmobs.plugins.IntegrationMythicMobs;
import com.willfp.ecoenchants.integrations.registration.RegistrationManager;
import com.willfp.ecoenchants.integrations.registration.plugins.IntegrationEssentials;
import org.bukkit.Bukkit;
@ -119,7 +120,7 @@ public class EcoEnchantsPlugin extends EcoPlugin {
protected List<IntegrationLoader> loadIntegrationLoaders() {
return Arrays.asList(
new IntegrationLoader("Essentials", () -> RegistrationManager.register(new IntegrationEssentials())),
new IntegrationLoader("MythicMobs", IntegrationMythicMobs::init)
new IntegrationLoader("MythicMobs", () -> MythicMobsManager.register(new IntegrationMythicMobs()))
);
}

View File

@ -8,8 +8,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
import com.willfp.ecoenchants.integrations.mythicmobs.IntegrationMythicMobs;
import io.lumine.xikage.mythicmobs.MythicMobs;
import com.willfp.ecoenchants.integrations.mythicmobs.MythicMobsManager;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -143,7 +142,9 @@ public class Telekinesis extends EcoEnchant {
return;
}
if (!IntegrationMythicMobs.canDropItems(entity)) return;
if (!MythicMobsManager.canDropItems(entity)) {
return;
}
if (event.getKiller() instanceof Player) {
player = (Player) event.getKiller();
@ -160,6 +161,7 @@ public class Telekinesis extends EcoEnchant {
}
}
//noinspection ConstantConditions
if (player == null || item == null) {
return;
}
@ -183,6 +185,7 @@ public class Telekinesis extends EcoEnchant {
if (meta == null) {
return false;
}
//noinspection ConstantConditions
if (meta.getPersistentDataContainer() == null) {
return false;
}

View File

@ -1,38 +0,0 @@
package com.willfp.ecoenchants.integrations.mythicmobs;
import io.lumine.xikage.mythicmobs.MythicMobs;
import org.bukkit.entity.Entity;
public class IntegrationMythicMobs {
/**
* True if MythicMobs integration is enabled.
*/
private static boolean enabled = false;
/**
* Initiate MythicMobs integration.
*/
public static void init() {
enabled = true;
}
/**
*
* Check if given entity should drop items or not.
*
* @param entity - The entity to check.
* @return - If given entity can drop items or not.
*/
public static boolean canDropItems(Entity entity) {
if (!enabled) return true;
if (!MythicMobs.inst().getAPIHelper().isMythicMob(entity)) return true;
return !MythicMobs.inst().getAPIHelper().getMythicMobInstance(entity).getType().getPreventMobKillDrops()
&& !MythicMobs.inst().getAPIHelper().getMythicMobInstance(entity).getType().getPreventOtherDrops();
}
}

View File

@ -0,0 +1,41 @@
package com.willfp.ecoenchants.integrations.mythicmobs;
import lombok.experimental.UtilityClass;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.Set;
@UtilityClass
public class MythicMobsManager {
/**
* All registered MythicMobs integrations.
*/
private static final Set<MythicMobsWrapper> REGISTERED = new HashSet<>();
/**
* Register a new MythicMobs integration.
*
* @param integration The integration to register.
*/
public static void register(@NotNull final MythicMobsWrapper integration) {
REGISTERED.add(integration);
}
/**
* Check if given entity should drop items or not.
*
* @param entity - The entity to check.
* @return - If given entity can drop items or not.
*/
public static boolean canDropItems(@NotNull final Entity entity) {
for (MythicMobsWrapper wrapper : REGISTERED) {
if (!wrapper.canDropItems(entity)) {
return false;
}
}
return true;
}
}

View File

@ -0,0 +1,14 @@
package com.willfp.ecoenchants.integrations.mythicmobs;
import com.willfp.eco.core.integrations.Integration;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
public interface MythicMobsWrapper extends Integration {
/**
* @param entity The entity.
* @see MythicMobsManager#canDropItems(Entity)
*/
boolean canDropItems(@NotNull Entity entity);
}

View File

@ -0,0 +1,22 @@
package com.willfp.ecoenchants.integrations.mythicmobs.plugins;
import com.willfp.ecoenchants.integrations.mythicmobs.MythicMobsWrapper;
import io.lumine.xikage.mythicmobs.MythicMobs;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
public class IntegrationMythicMobs implements MythicMobsWrapper {
public boolean canDropItems(@NotNull final Entity entity) {
if (!MythicMobs.inst().getAPIHelper().isMythicMob(entity)) {
return true;
}
return !MythicMobs.inst().getAPIHelper().getMythicMobInstance(entity).getType().getPreventMobKillDrops()
&& !MythicMobs.inst().getAPIHelper().getMythicMobInstance(entity).getType().getPreventOtherDrops();
}
@Override
public String getPluginName() {
return "MythicMobs";
}
}

View File

@ -1,2 +1,2 @@
version = 8.14.9
version = 8.14.10
plugin-name = EcoEnchants