mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-11-15 22:55:24 +01:00
Merge branch 'development'
This commit is contained in:
commit
4478112b17
2
pom.xml
2
pom.xml
@ -2,7 +2,7 @@
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>UltimateStacker</artifactId>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>1.11</version>
|
||||
<version>1.11.1</version>
|
||||
<build>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<finalName>UltimateStacker-${project.version}</finalName>
|
||||
|
@ -25,7 +25,7 @@ public class EntityStackManager {
|
||||
|
||||
public EntityStack addStack(UUID uuid, int amount) {
|
||||
EntityStack stack = new EntityStack(uuid, amount);
|
||||
stacks.put(uuid, new EntityStack(uuid, amount));
|
||||
stacks.put(uuid, stack);
|
||||
return stack;
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ public class EntityStackManager {
|
||||
if (!name.contains(":")) return null;
|
||||
String split = name.split(":")[0];
|
||||
int amount = Methods.isInt(split) ? Integer.parseInt(split) : 0;
|
||||
addStack(entity, amount);
|
||||
return addStack(entity, amount);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -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?");
|
||||
|
||||
|
@ -2,7 +2,9 @@ package com.songoda.ultimatestacker.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@ -16,6 +18,10 @@ public class CachedChunk {
|
||||
this(chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
|
||||
}
|
||||
|
||||
public CachedChunk(Location location) {
|
||||
this(location.getWorld().getName(), (int)location.getX() >> 4, (int)location.getZ() >> 4);
|
||||
}
|
||||
|
||||
public CachedChunk(String world, int x, int z) {
|
||||
this.world = world;
|
||||
this.x = x;
|
||||
@ -41,6 +47,13 @@ public class CachedChunk {
|
||||
return world.getChunkAt(this.x, this.z);
|
||||
}
|
||||
|
||||
public Entity[] getEntities() {
|
||||
if (!Bukkit.getWorld(world).isChunkLoaded(x, z)) {
|
||||
return new Entity[0];
|
||||
}
|
||||
return getChunk().getEntities();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof Chunk) {
|
||||
|
@ -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