Skip to content

Commit ce700d5

Browse files
committed
indirect kill logic update 1
1 parent e04e81a commit ce700d5

File tree

6 files changed

+46
-34
lines changed

6 files changed

+46
-34
lines changed

configs/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ head-place-overwrite-blocks: ['AIR', 'WATER', 'SHORT_GRASS']
148148
# Possible values: [LOWEST, LOW, NORMAL, HIGH, HIGHEST, MONITOR]
149149
death-listener-priority: LOW
150150

151+
# In vanilla, the main-hand item is used for looting even if shot from offhand
152+
use-ranged-weapon-for-looting: true
153+
151154
# Attempt to replace headA with headB whenever possible (server-wide)
152155
# The head on the left is replaced with the one on the right when updated
153156
replace-heads:

configs/entity-settings.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,14 @@ drop-for-nonplayer-kills:
1313
default: false
1414
creaking: true
1515

16-
# Whether to drop heads if last-damage-cause is not a valid entity
17-
# Instead, any entity damaged by a player within the time threshold is able
18-
# to drop its head. Set threshold <= 0 to allow head drops for any death
19-
drop-for-indirect-kills:
20-
default: false
21-
creaking: true
16+
# Only applies for entities that must be killed by a player
17+
# Any entity damaged by a player within the threshold can drop a head
18+
drop-for-indirect-player-kills: false
2219
indirect-kill-threshold: '30s'
2320

2421
# Whether to drop heads if killed by a projectile weapon
2522
drop-for-ranged-kills: false
2623

27-
# In vanilla, the main-hand item is used for looting even if shot from offhand
28-
use-ranged-weapon-for-looting: true
29-
3024
# Drop chances are multiplied by this number for each level of looting
3125
looting-multiplier: 1.1
3226

plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Heads for every mob and player.
55
website: https://dev.bukkit.org/projects/dropheads
66
#3=major rewrite
77
#10=Java8->Java21, entity-settings grouping, config file reorg
8-
#1=fix translation loading, fix creaking head not dropping, fix entity settings not applying
8+
#1=fix translation loading, fix creaking head not dropping, fix entity settings not applying, creaking head drops enabled by default
99
version: 3.10.1
1010
api-version: 1.13
1111
softdepend: [HeadDatabase, Essentials, VanishNoPacket]

src/net/evmodder/DropHeads/DropHeads.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.io.InputStreamReader;
2424
import org.bukkit.configuration.file.YamlConfiguration;
2525
import net.evmodder.DropHeads.commands.*;
26+
import net.evmodder.DropHeads.datatypes.EntitySetting;
2627
import net.evmodder.DropHeads.datatypes.NoteblockMode;
2728
import net.evmodder.DropHeads.listeners.*;
2829
import net.evmodder.EvLib.EvPlugin;
@@ -62,6 +63,7 @@ public final class DropHeads extends EvPlugin{
6263
private static DropHeads instance; public static DropHeads getPlugin(){return instance;}
6364
private InternalAPI api; public HeadAPI getAPI(){return api;} public InternalAPI getInternalAPI(){return api;}
6465
private DropChanceAPI dropChanceAPI; public DropChanceAPI getDropChanceAPI(){return dropChanceAPI;}
66+
private EntityDeathListener entityDeathListener; public EntityDeathListener getEntityDeathListener(){return entityDeathListener;}
6567
private DeathMessagePacketIntercepter deathMessageBlocker;
6668
private boolean LOGFILE_ENABLED;
6769
private String LOGFILE_NAME;
@@ -121,15 +123,19 @@ public final class DropHeads extends EvPlugin{
121123
deathMessageBlocker = new DeathMessagePacketIntercepter(REPLACE_PLAYER_DEATH_MSG, REPLACE_PET_DEATH_MSG);
122124
}
123125
dropChanceAPI = new DropChanceAPI(REPLACE_PLAYER_DEATH_MSG, REPLACE_PET_DEATH_MSG, deathMessageBlocker);
124-
new EntityDeathListener(deathMessageBlocker);
126+
127+
EntitySetting<Boolean> allowNonPlayerKills = EntitySetting.fromConfig(this, "drop-for-nonplayer-kills", false, null);
128+
EntitySetting<Boolean> allowIndirectPlayerKills = EntitySetting.fromConfig(this, "drop-for-indirect-player-kills", false, null);
129+
EntitySetting<Boolean> allowProjectileKills = EntitySetting.fromConfig(this, "drop-for-ranged-kills", false, null);
130+
new EntityDeathListener(deathMessageBlocker, allowNonPlayerKills, allowIndirectKills, allowProjectileKills);
125131

126132
if(config.getBoolean("track-mob-spawns", true)){
127133
getServer().getPluginManager().registerEvents(new EntitySpawnListener(), this);
128134
}
129-
if(config.getBoolean("drop-for-ranged-kills", false) && config.getBoolean("use-ranged-weapon-for-looting", true)){
135+
if(allowProjectileKills.hasAnyValue() && config.getBoolean("use-ranged-weapon-for-looting", true)){
130136
getServer().getPluginManager().registerEvents(new ProjectileFireListener(), this);
131137
}
132-
if(config.getBoolean("drop-for-indirect-kills", false) && !config.getBoolean("drop-for-nonplayer-kills", false)){
138+
if(allowIndirectPlayerKills.hasAnyValue()){
133139
getServer().getPluginManager().registerEvents(new EntityDamageListener(), this);
134140
}
135141
if(config.getBoolean("refresh-textures", false)){

src/net/evmodder/DropHeads/listeners/EntityDamageListener.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@
88
import org.bukkit.event.entity.EntityDamageByEntityEvent;
99
import org.bukkit.metadata.FixedMetadataValue;
1010
import net.evmodder.DropHeads.DropHeads;
11+
import net.evmodder.DropHeads.datatypes.EntitySetting;
1112

13+
//Only enabled if drop-for-indirect-kills:TRUE && drop-for-nonplayer-kills:FALSE
1214
public class EntityDamageListener implements Listener{
1315
private final DropHeads pl;
14-
private final boolean ALLOW_PROJECTILE_KILLS;
16+
private final EntitySetting<Boolean> allowProjectileKills;
1517

16-
// Only enabled if drop-for-indirect-kills:TRUE && drop-for-nonplayer-kills:FALSE
17-
public EntityDamageListener(){
18+
public EntityDamageListener(EntitySetting<Boolean> allowProjectileKills){
1819
pl = DropHeads.getPlugin();
19-
ALLOW_PROJECTILE_KILLS = pl.getConfig().getBoolean("drop-for-ranged-kills", false);
20+
this.allowProjectileKills = allowProjectileKills;
2021
}
2122
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
2223
public void entityDamageEvent(EntityDamageByEntityEvent evt){
23-
if(evt.getDamager() instanceof Player || (ALLOW_PROJECTILE_KILLS && evt.getDamager() instanceof Projectile
24-
&& ((Projectile)evt.getDamager()).getShooter() instanceof Player)){
24+
if(evt.getDamager() instanceof Player ||
25+
(allowProjectileKills.get(evt.getEntity()) && evt.getDamager() instanceof Projectile proj && proj.getShooter() instanceof Player)
26+
){
27+
pl.getLogger().warning("entity dmged by player: "+evt.getEntityType());
2528
evt.getEntity().setMetadata("PlayerDamage", new FixedMetadataValue(pl, System.currentTimeMillis()));
2629
}
2730
}

src/net/evmodder/DropHeads/listeners/EntityDeathListener.java

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.HashSet;
66
import java.util.Iterator;
77
import java.util.Map;
8+
import java.util.Objects;
89
import java.util.Random;
910
import java.util.UUID;
1011
import javax.annotation.Nonnull;
@@ -33,6 +34,7 @@
3334
import net.evmodder.DropHeads.DropHeads;
3435
import net.evmodder.DropHeads.JunkUtils;
3536
import net.evmodder.DropHeads.TextureKeyLookup;
37+
import net.evmodder.DropHeads.commands.CommandDropRate;
3638
import net.evmodder.DropHeads.datatypes.EntitySetting;
3739
import net.evmodder.DropHeads.events.HeadRollEvent;
3840
import net.evmodder.EvLib.EvUtils;
@@ -45,23 +47,24 @@ public class EntityDeathListener implements Listener{
4547
private final Random rand;
4648
private final HashSet<UUID> explodingChargedCreepers;
4749
private final EventPriority PRIORITY;
48-
private final boolean USE_RANGED_WEAPON_FOR_LOOTING;
49-
private final EntitySetting<Boolean> allowNonPlayerKills, allowIndirectKills, allowProjectileKills;//, useRangedWeaponForLooting;
50+
private final EntitySetting<Boolean> allowNonPlayerKills, allowIndirectPlayerKills, allowProjectileKills;//, useRangedWeaponForLooting;
5051
//TODO: pkillonly config per-mob?
52+
private final boolean USE_RANGED_WEAPON_FOR_LOOTING;
5153
private final boolean CHARGED_CREEPER_DROPS, VANILLA_WSKELE_HANDLING;
5254
private final long INDIRECT_KILL_THRESHOLD_MILLIS;
5355
private final boolean DEBUG_MODE;
5456

5557
public static final class Friend{private Friend(){}}
5658

57-
public EntityDeathListener(DeathMessagePacketIntercepter deathMessageBlocker){
58-
pl = DropHeads.getPlugin();
59+
public EntityDeathListener(DeathMessagePacketIntercepter deathMessageBlocker,
60+
EntitySetting<Boolean> allowNonPlayerKills, EntitySetting<Boolean> allowIndirectPlayerKills, EntitySetting<Boolean> allowProjectileKills){
5961
this.deathMessageBlocker = deathMessageBlocker;
62+
this.allowNonPlayerKills = allowNonPlayerKills;
63+
this.allowIndirectPlayerKills = allowIndirectPlayerKills;
64+
this.allowProjectileKills = allowProjectileKills;
65+
pl = DropHeads.getPlugin();
6066
rand = new Random();
6167
USE_RANGED_WEAPON_FOR_LOOTING = pl.getConfig().getBoolean("use-ranged-weapon-for-looting", true);
62-
allowNonPlayerKills = EntitySetting.fromConfig(pl, "drop-for-nonplayer-kills", false, null);
63-
allowIndirectKills = EntitySetting.fromConfig(pl, "drop-for-indirect-kills", false, null);
64-
allowProjectileKills = EntitySetting.fromConfig(pl, "drop-for-ranged-kills", false, null);
6568

6669
CHARGED_CREEPER_DROPS = pl.getConfig().getBoolean("charged-creeper-drops", true);
6770
VANILLA_WSKELE_HANDLING = pl.getConfig().getBoolean("vanilla-wither-skeleton-skulls", false);
@@ -157,6 +160,17 @@ boolean onEntityDeath(@Nonnull final Entity victim, final Entity killer, final E
157160
}
158161
}
159162
// Check if killer qualifies to trigger a behead.
163+
// if(killer != null){
164+
// if(!allowProjectileKills.get(victim) && killer instanceof Projectile) return false;
165+
// if(!allowNonPlayerKills.get(victim) && killer instanceof Player == false &&
166+
// !(allowProjectileKills.get(victim) && killer instanceof Projectile proj && proj.getShooter() instanceof Player)
167+
// ) return false;
168+
// }
169+
// else if(!allowNonPlayerKills.get(victim) &&
170+
// (!allowIndirectPlayerKills.get(victim) || JunkUtils.timeSinceLastPlayerDamage(victim) > INDIRECT_KILL_THRESHOLD_MILLIS)
171+
// ) return false;
172+
//
173+
// }
160174
if(killer == null
161175
? (!allowIndirectKills.get(victim) ||
162176
(INDIRECT_KILL_THRESHOLD_MILLIS >= 0 && JunkUtils.timeSinceLastPlayerDamage(victim) > INDIRECT_KILL_THRESHOLD_MILLIS))
@@ -166,14 +180,6 @@ boolean onEntityDeath(@Nonnull final Entity victim, final Entity killer, final E
166180
!(allowProjectileKills.get(victim) && killer instanceof Projectile proj && proj.getShooter() instanceof Player)
167181
)
168182
) return false;
169-
// if(
170-
// // Note: Won't use timeSinceLastEntityDamage()... it would be expensive to keep track of
171-
// (killer == null && (!allowIndirectKills.get(victim) || JunkUtils.timeSinceLastPlayerDamage(victim) > INDIRECT_KILL_THRESHOLD_MILLIS)) ||
172-
// (killer != null && !allowProjectileKills.get(victim) && killer instanceof Projectile) ||
173-
// (killer != null && !allowNonPlayerKills.get(victim) &&
174-
// !(allowProjectileKills.get(victim) && killer instanceof Projectile proj && proj.getShooter() instanceof Player)
175-
// )
176-
// ) return false;
177183

178184
final ItemStack murderWeapon = getWeaponFromKiller(killer);
179185
final Material murderWeaponType = murderWeapon == null ? Material.AIR : murderWeapon.getType();

0 commit comments

Comments
 (0)