Add instakill config option

This commit is contained in:
TomTom 2024-08-01 09:20:53 +02:00
parent 7294b934b5
commit 6639870f5c
3 changed files with 26 additions and 16 deletions

View File

@ -32,6 +32,7 @@ public final class Config {
public static boolean ASYNC_HAND_ANIMATION = false;
public static int ASYNC_PROCESSOR_POOL_SIZE = 3;
public static boolean REQUIRE_TOOL = true;
public static boolean INSTANT_KILL = false;
public static String LANGUAGE = "en_US";
public static boolean USE_BSTATS = true;
public static boolean DEBUG = false;
@ -82,6 +83,7 @@ public final class Config {
ASYNC_HAND_ANIMATION = config.getBoolean("async-hand-animation", ASYNC_HAND_ANIMATION);
ASYNC_PROCESSOR_POOL_SIZE = config.getInt("async-processor-pool-size", ASYNC_PROCESSOR_POOL_SIZE);
REQUIRE_TOOL = config.getBoolean("require-tool", REQUIRE_TOOL);
INSTANT_KILL = config.getBoolean("instant-kill", INSTANT_KILL);
LANGUAGE = config.getString("language", LANGUAGE);
USE_BSTATS = config.getBoolean("use-bstats", USE_BSTATS);
DEBUG = config.getBoolean("debug", DEBUG);

View File

@ -5,15 +5,14 @@ import com.artillexstudios.axapi.loot.LootContextParams;
import com.artillexstudios.axapi.loot.LootParams;
import com.artillexstudios.axapi.loot.LootTables;
import com.artillexstudios.axapi.nms.NMSHandlers;
import com.artillexstudios.axminions.config.Config;
import com.artillexstudios.axminions.integrations.Integrations;
import com.artillexstudios.axminions.minions.Minion;
import com.artillexstudios.axminions.minions.actions.effects.Effect;
import com.artillexstudios.axminions.utils.ItemCollection;
import com.artillexstudios.axminions.utils.LogUtils;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.Collection;
import java.util.Map;
public class DamageEntityEffect extends Effect<Entity, ItemCollection> {
@ -25,21 +24,26 @@ public class DamageEntityEffect extends Effect<Entity, ItemCollection> {
@Override
public ItemCollection run(Minion minion, Entity argument) {
dummyPlayer.getInventory().setItemInMainHand(minion.tool());
LootParams params = new LootParams.Builder(argument.getWorld())
.withParameter(LootContextParams.THIS_ENTITY, argument)
.withParameter(LootContextParams.ORIGIN, argument.getLocation())
.withParameter(LootContextParams.DAMAGE_SOURCE, dummyPlayer)
.withParameter(LootContextParams.ATTACKING_ENTITY, dummyPlayer)
.withParameter(LootContextParams.DIRECT_ATTACKING_ENTITY, dummyPlayer)
.withParameter(LootContextParams.LAST_DAMAGE_PLAYER, dummyPlayer)
.build(LootContextParamSets.ENTITY);
if (Config.INSTANT_KILL) {
// TODO: maybe we can get the loot of an entity with the stacker's api
long stackSize = Integrations.STACKER.getStackSize(argument);
Collection<ItemStack> items = LootTables.entityLootTable(argument.getType())
.randomItems(params);
dummyPlayer.getInventory().setItemInMainHand(minion.tool());
// TODO: We need to handle looting enchantment
LootParams params = new LootParams.Builder(argument.getWorld())
.withParameter(LootContextParams.THIS_ENTITY, argument)
.withParameter(LootContextParams.ORIGIN, argument.getLocation())
.withParameter(LootContextParams.DAMAGE_SOURCE, dummyPlayer)
.withParameter(LootContextParams.ATTACKING_ENTITY, dummyPlayer)
.withParameter(LootContextParams.DIRECT_ATTACKING_ENTITY, dummyPlayer)
.withParameter(LootContextParams.LAST_DAMAGE_PLAYER, dummyPlayer)
.build(LootContextParamSets.ENTITY);
LogUtils.debug("DamageEntityEffect, {} items: {}", argument, items);
return new ItemCollection(items);
return new ItemCollection(LootTables.entityLootTable(argument.getType())
.randomItems(params));
}
return ItemCollection.EMPTY;
}
@Override

View File

@ -37,6 +37,10 @@ async-processor-pool-size: 3
# If this option is false, the minion's default tool will be used
require-tool: true
# If the minion should kill the entity instantly, and not
# deal the amount of damage the item would deal.
instant-kill: false
# What language file should we load from the lang folder?
# You can create your own aswell! We would appreciate if you
# contributed to the plugin by creating a pull request with your translation!