Skip to content

Commit

Permalink
attempt support of spawnermobbehavior setting
Browse files Browse the repository at this point in the history
ref #77
  • Loading branch information
crashdemons committed Feb 16, 2021
1 parent 845de26 commit dd9451c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -218,6 +219,13 @@ private DeathParameters getDeathParameters(EntityDeathEvent event) {
}
//end vanilla head event

if(plugin.getConfig().getBoolean("trackspawnermobs")){
if(isSpawnerMob(event.getEntity())){
VanillDropBehavior spawnerMobBehavior = VanillDropBehavior.fromString( plugin.configFile.getString("spawnermobbehavior") );
params.vanillaBehavior = params.vanillaBehavior.apply(spawnerMobBehavior);
if(!params.vanillaBehavior.allowsPhBehavior()) return params.cancel();
}
}

VanillDropBehavior chargedcreeperBehavior=VanillDropBehavior.IGNORE;
if (params.killer != null) {
Expand Down Expand Up @@ -320,6 +328,28 @@ public void onEntityDeath(EntityDeathEvent event) {

}

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled=true)
public void onEntitySpawn(CreatureSpawnEvent event){
if(!plugin.getConfig().getBoolean("trackspawnermobs")) return;
LivingEntity entity = event.getEntity();
boolean persistenceSupported = Compatibility.getProvider().supportsEntityTagType(true);
Compatibility.getProvider().setEntityTag(entity, plugin, "phspawnreason", event.getSpawnReason().name().toUpperCase(), persistenceSupported);
}

private CreatureSpawnEvent.SpawnReason getMobSpawnReason(Entity entity){
boolean persistenceSupported = Compatibility.getProvider().supportsEntityTagType(true);
String reason = Compatibility.getProvider().getEntityTag(entity, plugin, "phspawnreason", persistenceSupported);
try{
return CreatureSpawnEvent.SpawnReason.valueOf(reason);
}catch(Exception e){
return null;
}
}

private boolean isSpawnerMob(Entity entity){
return getMobSpawnReason(entity)==CreatureSpawnEvent.SpawnReason.SPAWNER;
}


/**
* Event handler for entity deaths.
Expand Down
11 changes: 11 additions & 0 deletions PlayerHeads-core/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ requireditems: [wooden_axe,stone_axe,golden_axe,iron_axe,diamond_axe]
considermobkillers: false
considertameowner: false

#controls whether spawner mobs should be tracked
trackspawnermobs: false

#spawnermobbehavior can be:
# vanilla - don't allow PlayerHeads to modify deaths caused by spawner mobs at all
# ignore - don't consider spawner mobs at all, add PlayerHeads drop chances anyway if applicable
# block - block all spawner mob caused head drops (including vanilla drops)
# replace - remove vanilla spawner mob caused head drops and add PlayerHeads drop chances instead
# NOTE: requires 'trackspawnermobs' to be enabled.
spawnermobbehavior: ignore

#prevent PlayerHeads from interacting/modifying third-party heads with these names or UUIDs
ignoredheadnames: [CSCoreLib,CsCoreLib,CS-CoreLib]
ignoredheaduuids: []
Expand Down

0 comments on commit dd9451c

Please sign in to comment.