mirror of
https://github.com/songoda/UltimateStacker.git
synced 2025-01-01 05:17:52 +01:00
Added support for disabling knockback on stacked mobs.
This commit is contained in:
parent
7a1cede33b
commit
6ba64cc391
@ -12,20 +12,22 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class EntityListeners implements Listener {
|
||||
|
||||
@ -77,6 +79,20 @@ public class EntityListeners implements Listener {
|
||||
event.getEntity().setItemStack(item);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onHurt(EntityDamageByEntityEvent event) {
|
||||
if (!Settings.STACK_ENTITIES.getBoolean() || !(event.getDamager() instanceof Player)) return;
|
||||
|
||||
if (plugin.getEntityStackManager().isStacked(event.getEntity())
|
||||
&& Settings.DISABLE_KNOCKBACK.getBoolean()
|
||||
&& ((Player) event.getDamager()).getItemInHand().getEnchantmentLevel(Enchantment.KNOCKBACK) == 0) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {
|
||||
event.getEntity().setVelocity(new Vector());
|
||||
}, 0L);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlow(EntityExplodeEvent event) {
|
||||
if (!plugin.spawnersEnabled()) return;
|
||||
|
@ -163,6 +163,9 @@ public class Settings {
|
||||
public static final ConfigSetting REALISTIC_DAMAGE = new ConfigSetting(config, "Entities.Use Realistic Weapon Damage", true,
|
||||
"Should weapons take damage based on the amount of entites in the stack?");
|
||||
|
||||
public static final ConfigSetting DISABLE_KNOCKBACK = new ConfigSetting(config, "Entities.Disable Knockback", false,
|
||||
"Should knockback be disabled on unstacked mobs?");
|
||||
|
||||
public static final ConfigSetting STACK_ITEMS = new ConfigSetting(config, "Items.Enabled", true,
|
||||
"Should items be stacked?");
|
||||
|
||||
|
@ -5,7 +5,10 @@ import com.songoda.ultimatestacker.UltimateStacker;
|
||||
import com.songoda.ultimatestacker.entity.Check;
|
||||
import com.songoda.ultimatestacker.entity.EntityStack;
|
||||
import com.songoda.ultimatestacker.settings.Settings;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.*;
|
||||
|
||||
import java.util.*;
|
||||
@ -34,8 +37,8 @@ public class EntityUtils {
|
||||
Set<CachedChunk> chunks = new HashSet<>();
|
||||
if (world == null) return chunks;
|
||||
|
||||
Chunk firstChunk = location.getChunk();
|
||||
chunks.add(new CachedChunk(firstChunk));
|
||||
CachedChunk firstChunk = new CachedChunk(location);
|
||||
chunks.add(firstChunk);
|
||||
|
||||
if (singleChunk) return chunks;
|
||||
|
||||
@ -60,7 +63,7 @@ public class EntityUtils {
|
||||
if (cachedChunks.containsKey(chunk)) {
|
||||
entityArray = cachedChunks.get(chunk);
|
||||
} else {
|
||||
entityArray = chunk.getChunk().getEntities();
|
||||
entityArray = chunk.getEntities();
|
||||
cachedChunks.put(chunk, entityArray);
|
||||
}
|
||||
for (Entity e : entityArray) {
|
||||
@ -84,7 +87,13 @@ public class EntityUtils {
|
||||
|
||||
public LivingEntity newEntity(LivingEntity toClone) {
|
||||
LivingEntity newEntity = (LivingEntity) toClone.getWorld().spawnEntity(toClone.getLocation(), toClone.getType());
|
||||
newEntity.setVelocity(toClone.getVelocity());
|
||||
|
||||
Player player = toClone.getKiller();
|
||||
if (player == null
|
||||
|| !Settings.DISABLE_KNOCKBACK.getBoolean()
|
||||
|| player.getItemInHand().getEnchantmentLevel(Enchantment.KNOCKBACK) != 0) {
|
||||
newEntity.setVelocity(toClone.getVelocity());
|
||||
}
|
||||
|
||||
for (String checkStr : checks) {
|
||||
Check check = Check.valueOf(checkStr);
|
||||
|
Loading…
Reference in New Issue
Block a user