diff --git a/api/src/main/java/de/erethon/dungeonsxl/api/dungeon/GameRule.java b/api/src/main/java/de/erethon/dungeonsxl/api/dungeon/GameRule.java index 28554857..8da1a8e6 100644 --- a/api/src/main/java/de/erethon/dungeonsxl/api/dungeon/GameRule.java +++ b/api/src/main/java/de/erethon/dungeonsxl/api/dungeon/GameRule.java @@ -328,6 +328,18 @@ public class GameRule { * If Citizens NPCs should be copied to the native registry. */ public static final GameRule USE_NATIVE_CITIZENS_REGISTRY = new GameRule<>(Boolean.class, "useNativeCitizensRegistry", false); + /** + * If mobs shall drop experience or a whitelist of mobs that drop experience, while all others do not. + */ + public static final GameRule MOB_EXP_DROPS = new GameRule(Object.class, "mobExpDrops", false, + (api, value) -> value instanceof Boolean ? value : ConfigReader.EX_MOB_SET_READER.read(api, value) + ); + /** + * If mobs shall drop items or a whitelist of mobs that drop items, while all others do not. + */ + public static final GameRule MOB_ITEM_DROPS = new GameRule(Object.class, "mobItemDrops", false, + (api, value) -> value instanceof Boolean ? value : ConfigReader.EX_MOB_SET_READER.read(api, value) + ); /** * An array of all game rules that exist natively in DungeonsXL. diff --git a/core/src/main/java/de/erethon/dungeonsxl/DungeonsXL.java b/core/src/main/java/de/erethon/dungeonsxl/DungeonsXL.java index 33a84aca..93a9a068 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/DungeonsXL.java +++ b/core/src/main/java/de/erethon/dungeonsxl/DungeonsXL.java @@ -384,7 +384,7 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI { externalMobProviderRegistry.add(externalMobPlugin.getIdentifier(), externalMobPlugin); } if (manager.getPlugin("Citizens") != null) { - CitizensMobProvider citizensMobProvider = new CitizensMobProvider(); + CitizensMobProvider citizensMobProvider = new CitizensMobProvider(this); externalMobProviderRegistry.add("CI", citizensMobProvider); manager.registerEvents(citizensMobProvider, this); } else { @@ -696,7 +696,7 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI { if (mob != null) { return mob; } else { - return new DMob(entity, gameWorld, triggerId); + return new DMob(entity, gameWorld, caliburn.getExMob(triggerId), triggerId); } } diff --git a/core/src/main/java/de/erethon/dungeonsxl/mob/CitizensMobProvider.java b/core/src/main/java/de/erethon/dungeonsxl/mob/CitizensMobProvider.java index 516653cf..6dc543be 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/mob/CitizensMobProvider.java +++ b/core/src/main/java/de/erethon/dungeonsxl/mob/CitizensMobProvider.java @@ -16,7 +16,7 @@ */ package de.erethon.dungeonsxl.mob; -import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.DungeonsAPI; import de.erethon.dungeonsxl.api.dungeon.GameRule; import de.erethon.dungeonsxl.api.mob.ExternalMobProvider; import de.erethon.dungeonsxl.api.world.GameWorld; @@ -40,11 +40,17 @@ import org.bukkit.event.Listener; */ public class CitizensMobProvider implements ExternalMobProvider, Listener { + private DungeonsAPI api; + private static final String IDENTIFIER = "CI"; private DNPCRegistry registry = new DNPCRegistry(); private Set spawnedNPCs = new HashSet<>(); + public CitizensMobProvider(DungeonsAPI api) { + this.api = api; + } + /** * @return the DungeonsXL NPC registry */ @@ -106,7 +112,7 @@ public class CitizensMobProvider implements ExternalMobProvider, Listener { return; } - GameWorld gameWorld = DungeonsXL.getInstance().getGameWorld(location.getWorld()); + GameWorld gameWorld = api.getGameWorld(location.getWorld()); if (gameWorld == null) { return; } @@ -119,7 +125,7 @@ public class CitizensMobProvider implements ExternalMobProvider, Listener { npc.spawn(location); spawnedNPCs.add(npc); - new DMob((LivingEntity) npc.getEntity(), gameWorld, mob); + api.wrapEntity((LivingEntity) npc.getEntity(), gameWorld, mob); } /* Listeners */ diff --git a/core/src/main/java/de/erethon/dungeonsxl/mob/DMob.java b/core/src/main/java/de/erethon/dungeonsxl/mob/DMob.java index 90629dfe..d5a81f91 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/mob/DMob.java +++ b/core/src/main/java/de/erethon/dungeonsxl/mob/DMob.java @@ -19,6 +19,7 @@ package de.erethon.dungeonsxl.mob; import de.erethon.caliburn.mob.ExMob; import de.erethon.caliburn.mob.VanillaMob; import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.dungeon.GameRule; import de.erethon.dungeonsxl.api.event.mob.DungeonMobDeathEvent; import de.erethon.dungeonsxl.api.event.mob.DungeonMobSpawnEvent; import de.erethon.dungeonsxl.api.mob.DungeonMob; @@ -43,10 +44,11 @@ public class DMob implements DungeonMob { private String trigger; - private DMob(LivingEntity entity, GameWorld gameWorld) { + public DMob(LivingEntity entity, GameWorld gameWorld, ExMob type) { this.entity = entity; + this.type = type; - if (!isExternalMob()) { + if (!getDrops(gameWorld.getDungeon().getRules().getState(GameRule.MOB_ITEM_DROPS))) { entity.getEquipment().setHelmetDropChance(0); entity.getEquipment().setChestplateDropChance(0); entity.getEquipment().setLeggingsDropChance(0); @@ -62,22 +64,11 @@ public class DMob implements DungeonMob { DungeonMobSpawnEvent event = new DungeonMobSpawnEvent(this); Bukkit.getPluginManager().callEvent(event); - } - - public DMob(LivingEntity entity, GameWorld gameWorld, String trigger) { - this(entity, gameWorld); - this.trigger = trigger; - } - - public DMob(LivingEntity entity, GameWorld gameWorld, ExMob type) { - this(entity, gameWorld); - this.type = type; this.trigger = type.getId(); } public DMob(LivingEntity entity, GameWorld gameWorld, ExMob type, String trigger) { - this(entity, gameWorld); - this.type = type; + this(entity, gameWorld, type); this.trigger = trigger; } @@ -101,8 +92,6 @@ public class DMob implements DungeonMob { public void onDeath(DungeonsXL plugin, EntityDeathEvent event) { LivingEntity victim = event.getEntity(); DGameWorld gameWorld = (DGameWorld) plugin.getGameWorld(victim.getWorld()); - String name = null; - if (gameWorld == null) { return; } @@ -113,12 +102,18 @@ public class DMob implements DungeonMob { return; } + if (!getDrops(gameWorld.getDungeon().getRules().getState(GameRule.MOB_ITEM_DROPS))) { + event.getDrops().clear(); + } + if (!getDrops(gameWorld.getDungeon().getRules().getState(GameRule.MOB_EXP_DROPS))) { + event.setDroppedExp(0); + } + + String name; if (!isExternalMob()) { name = type.getId(); - } else if (isExternalMob() && trigger != null) { name = trigger; - } else { name = VanillaMob.get(victim.getType()).getId(); } @@ -138,6 +133,19 @@ public class DMob implements DungeonMob { gameWorld.removeMob(this); } + private boolean getDrops(Object drops) { + if (drops instanceof Boolean) { + return (Boolean) drops; + } else if (drops instanceof Set) { + for (ExMob whitelisted : (Set) drops) { + if (type.isSubsumableUnder(whitelisted)) { + return true; + } + } + } + return false; + } + @Override public String toString() { return getClass().getSimpleName() + "{type=" + type + "}"; diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/windup/MobSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/windup/MobSign.java index a874a019..17501275 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/windup/MobSign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/windup/MobSign.java @@ -120,7 +120,7 @@ public class MobSign extends Windup { initialAmount = n; provider = attributes.length == 3 ? providers.get(attributes[2]) : null; - setRunnable(new MobSpawnTask(this, n)); + setRunnable(new MobSpawnTask(api, this, n)); } /** diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/windup/MobSpawnTask.java b/core/src/main/java/de/erethon/dungeonsxl/sign/windup/MobSpawnTask.java index e8989f10..7b6e77c1 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/windup/MobSpawnTask.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/windup/MobSpawnTask.java @@ -16,7 +16,7 @@ */ package de.erethon.dungeonsxl.sign.windup; -import de.erethon.dungeonsxl.mob.DMob; +import de.erethon.dungeonsxl.api.DungeonsAPI; import org.bukkit.entity.LivingEntity; import org.bukkit.scheduler.BukkitRunnable; @@ -25,10 +25,13 @@ import org.bukkit.scheduler.BukkitRunnable; */ public class MobSpawnTask extends BukkitRunnable { + private DungeonsAPI api; + private MobSign sign; private int k = 1, n; - public MobSpawnTask(MobSign sign, int n) { + public MobSpawnTask(DungeonsAPI api, MobSign sign, int n) { + this.api = api; this.sign = sign; this.n = n; } @@ -42,7 +45,7 @@ public class MobSpawnTask extends BukkitRunnable { LivingEntity entity = sign.spawn(); if (entity != null) { - new DMob(entity, sign.getGameWorld(), sign.getMob()); + api.wrapEntity(entity, sign.getGameWorld(), api.getCaliburn().getExMob(entity), sign.getMob()); } if (k < n) {