mirror of
https://github.com/songoda/UltimateStacker.git
synced 2025-02-07 06:51:21 +01:00
Merge branch 'development'
This commit is contained in:
commit
a4db75fe1c
4
pom.xml
4
pom.xml
@ -2,7 +2,7 @@
|
|||||||
<groupId>com.songoda</groupId>
|
<groupId>com.songoda</groupId>
|
||||||
<artifactId>UltimateStacker</artifactId>
|
<artifactId>UltimateStacker</artifactId>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<version>2.3.0</version>
|
<version>2.3.1</version>
|
||||||
<build>
|
<build>
|
||||||
<defaultGoal>clean install</defaultGoal>
|
<defaultGoal>clean install</defaultGoal>
|
||||||
<finalName>UltimateStacker-${project.version}</finalName>
|
<finalName>UltimateStacker-${project.version}</finalName>
|
||||||
@ -112,7 +112,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.songoda</groupId>
|
<groupId>com.songoda</groupId>
|
||||||
<artifactId>SongodaCore</artifactId>
|
<artifactId>SongodaCore</artifactId>
|
||||||
<version>2.6.16</version>
|
<version>2.6.17-SNAPSHOT</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -49,6 +49,7 @@ import com.songoda.ultimatestacker.tasks.StackingTask;
|
|||||||
import com.songoda.ultimatestacker.utils.Methods;
|
import com.songoda.ultimatestacker.utils.Methods;
|
||||||
import org.apache.commons.lang.WordUtils;
|
import org.apache.commons.lang.WordUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Item;
|
import org.bukkit.entity.Item;
|
||||||
@ -382,6 +383,19 @@ public class UltimateStacker extends SongodaPlugin {
|
|||||||
|
|
||||||
//////// Convenient API //////////
|
//////// Convenient API //////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spawn a stacked item at a location
|
||||||
|
*
|
||||||
|
* @param item The item to spawn
|
||||||
|
* @param amount The amount of items to spawn
|
||||||
|
* @param location The location to spawn the item
|
||||||
|
*/
|
||||||
|
public static void spawnStackedItem(ItemStack item, int amount, Location location) {
|
||||||
|
location.getWorld().dropItem(location, item, dropped -> {
|
||||||
|
updateItemAmount(dropped, amount);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the stacked amount for this item
|
* Change the stacked amount for this item
|
||||||
*
|
*
|
||||||
|
@ -7,6 +7,7 @@ import com.songoda.core.lootables.loot.DropUtils;
|
|||||||
import com.songoda.ultimatestacker.UltimateStacker;
|
import com.songoda.ultimatestacker.UltimateStacker;
|
||||||
import com.songoda.ultimatestacker.settings.Settings;
|
import com.songoda.ultimatestacker.settings.Settings;
|
||||||
import com.songoda.ultimatestacker.stackable.entity.EntityStack;
|
import com.songoda.ultimatestacker.stackable.entity.EntityStack;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.GameRule;
|
import org.bukkit.GameRule;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
@ -153,8 +154,9 @@ public class DeathListeners implements Listener {
|
|||||||
if (!plugin.getEntityStackManager().isStackedAndLoaded(entity)) return;
|
if (!plugin.getEntityStackManager().isStackedAndLoaded(entity)) return;
|
||||||
EntityStack stack = plugin.getEntityStackManager().getStack(entity);
|
EntityStack stack = plugin.getEntityStackManager().getStack(entity);
|
||||||
|
|
||||||
if (Settings.KILL_WHOLE_STACK_ON_DEATH.getBoolean() && Settings.REALISTIC_DAMAGE.getBoolean()) {
|
Player player = (Player) event.getDamager();
|
||||||
Player player = (Player) event.getDamager();
|
|
||||||
|
if (Settings.KILL_WHOLE_STACK_ON_DEATH.getBoolean() && Settings.REALISTIC_DAMAGE.getBoolean() && !player.getGameMode().equals(GameMode.CREATIVE)) {
|
||||||
ItemStack tool = player.getInventory().getItemInHand();
|
ItemStack tool = player.getInventory().getItemInHand();
|
||||||
if (tool.getType().getMaxDurability() < 1 || (tool.getItemMeta() != null && (tool.getItemMeta().isUnbreakable()
|
if (tool.getType().getMaxDurability() < 1 || (tool.getItemMeta() != null && (tool.getItemMeta().isUnbreakable()
|
||||||
|| (ServerProject.isServer(ServerProject.SPIGOT, ServerProject.PAPER) && tool.getItemMeta().isUnbreakable()))))
|
|| (ServerProject.isServer(ServerProject.SPIGOT, ServerProject.PAPER) && tool.getItemMeta().isUnbreakable()))))
|
||||||
|
@ -17,7 +17,32 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.*;
|
import org.bukkit.entity.AbstractHorse;
|
||||||
|
import org.bukkit.entity.Ageable;
|
||||||
|
import org.bukkit.entity.ArmorStand;
|
||||||
|
import org.bukkit.entity.Cat;
|
||||||
|
import org.bukkit.entity.ChestedHorse;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Horse;
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Llama;
|
||||||
|
import org.bukkit.entity.Ocelot;
|
||||||
|
import org.bukkit.entity.Parrot;
|
||||||
|
import org.bukkit.entity.Phantom;
|
||||||
|
import org.bukkit.entity.Pig;
|
||||||
|
import org.bukkit.entity.PufferFish;
|
||||||
|
import org.bukkit.entity.Rabbit;
|
||||||
|
import org.bukkit.entity.Sheep;
|
||||||
|
import org.bukkit.entity.Skeleton;
|
||||||
|
import org.bukkit.entity.Slime;
|
||||||
|
import org.bukkit.entity.Snowman;
|
||||||
|
import org.bukkit.entity.Tameable;
|
||||||
|
import org.bukkit.entity.TropicalFish;
|
||||||
|
import org.bukkit.entity.Villager;
|
||||||
|
import org.bukkit.entity.Wolf;
|
||||||
|
import org.bukkit.entity.Zombie;
|
||||||
import org.bukkit.inventory.EntityEquipment;
|
import org.bukkit.inventory.EntityEquipment;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
@ -30,6 +55,9 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
public class StackingTask extends BukkitRunnable {
|
public class StackingTask extends BukkitRunnable {
|
||||||
|
|
||||||
@ -42,7 +70,7 @@ public class StackingTask extends BukkitRunnable {
|
|||||||
|
|
||||||
private final Map<CachedChunk, Entity[]> cachedChunks = new HashMap<>();
|
private final Map<CachedChunk, Entity[]> cachedChunks = new HashMap<>();
|
||||||
|
|
||||||
private final HashMap<EntityType, Integer> entityStackSizes = new HashMap();
|
private final Map<EntityType, Integer> entityStackSizes = new HashMap<>();
|
||||||
private final int maxEntityStackSize = Settings.MAX_STACK_ENTITIES.getInt(),
|
private final int maxEntityStackSize = Settings.MAX_STACK_ENTITIES.getInt(),
|
||||||
minEntityStackSize = Settings.MIN_STACK_ENTITIES.getInt(),
|
minEntityStackSize = Settings.MIN_STACK_ENTITIES.getInt(),
|
||||||
searchRadius = Settings.SEARCH_RADIUS.getInt(),
|
searchRadius = Settings.SEARCH_RADIUS.getInt(),
|
||||||
@ -83,11 +111,10 @@ public class StackingTask extends BukkitRunnable {
|
|||||||
// Get the loaded entities from the current world and reverse them.
|
// Get the loaded entities from the current world and reverse them.
|
||||||
List<LivingEntity> entities;
|
List<LivingEntity> entities;
|
||||||
try {
|
try {
|
||||||
entities = sWorld.getLivingEntities();
|
entities = getLivingEntitiesSync(sWorld).get();
|
||||||
} catch (Exception ignored) {
|
} catch (ExecutionException | InterruptedException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
continue;
|
continue;
|
||||||
// Sometimes accessing this method asynchronously throws an error. This is super rare and
|
|
||||||
// as such doesn't really affect the plugin so we're just going to ignore this failure.
|
|
||||||
}
|
}
|
||||||
Collections.reverse(entities);
|
Collections.reverse(entities);
|
||||||
|
|
||||||
@ -113,6 +140,20 @@ public class StackingTask extends BukkitRunnable {
|
|||||||
this.cachedChunks.clear();
|
this.cachedChunks.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Future<List<LivingEntity>> getLivingEntitiesSync(SWorld sWorld) {
|
||||||
|
CompletableFuture<List<LivingEntity>> future = new CompletableFuture<>();
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, () -> future.complete(sWorld.getLivingEntities()));
|
||||||
|
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Future<Entity[]> getEntitiesInChunkSync(CachedChunk cachedChunk) {
|
||||||
|
CompletableFuture<Entity[]> future = new CompletableFuture<>();
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, () -> future.complete(cachedChunk.getEntities()));
|
||||||
|
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isWorldDisabled(World world) {
|
public boolean isWorldDisabled(World world) {
|
||||||
return disabledWorlds.stream().anyMatch(worldStr -> world.getName().equalsIgnoreCase(worldStr));
|
return disabledWorlds.stream().anyMatch(worldStr -> world.getName().equalsIgnoreCase(worldStr));
|
||||||
}
|
}
|
||||||
@ -243,6 +284,10 @@ public class StackingTask extends BukkitRunnable {
|
|||||||
// Make the friend the new stack host.
|
// Make the friend the new stack host.
|
||||||
EntityStack newStack = stackManager.updateStack(livingEntity, entity);
|
EntityStack newStack = stackManager.updateStack(livingEntity, entity);
|
||||||
|
|
||||||
|
if (newStack == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Add our entity to that stack
|
// Add our entity to that stack
|
||||||
plugin.getDataManager().createStackedEntity(newStack, newStack.addEntityToStack(livingEntity));
|
plugin.getDataManager().createStackedEntity(newStack, newStack.addEntityToStack(livingEntity));
|
||||||
|
|
||||||
@ -367,19 +412,21 @@ public class StackingTask extends BukkitRunnable {
|
|||||||
List<LivingEntity> entities = new ArrayList<>();
|
List<LivingEntity> entities = new ArrayList<>();
|
||||||
for (CachedChunk chunk : getNearbyChunks(sWorld, location, radius, singleChunk)) {
|
for (CachedChunk chunk : getNearbyChunks(sWorld, location, radius, singleChunk)) {
|
||||||
if (chunk == null) continue;
|
if (chunk == null) continue;
|
||||||
Entity[] entityArray = new Entity[0];
|
Entity[] entityArray;
|
||||||
if (cachedChunks.containsKey(chunk)) {
|
if (cachedChunks.containsKey(chunk)) {
|
||||||
entityArray = cachedChunks.get(chunk);
|
entityArray = cachedChunks.get(chunk);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
entityArray = chunk.getEntities();
|
entityArray = getEntitiesInChunkSync(chunk).get();
|
||||||
cachedChunks.put(chunk, entityArray);
|
cachedChunks.put(chunk, entityArray);
|
||||||
} catch (Exception ignored) {
|
} catch (ExecutionException | InterruptedException ex) {
|
||||||
// Sometimes accessing this method asynchronously throws an error. This is super rare and
|
ex.printStackTrace();
|
||||||
// as such doesn't really affect the plugin so we're just going to ignore this failure.
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entityArray == null) continue;
|
if (entityArray == null) continue;
|
||||||
|
|
||||||
for (Entity e : entityArray) {
|
for (Entity e : entityArray) {
|
||||||
if (e == null) continue;
|
if (e == null) continue;
|
||||||
if (e.getWorld() != location.getWorld()
|
if (e.getWorld() != location.getWorld()
|
||||||
@ -388,6 +435,7 @@ public class StackingTask extends BukkitRunnable {
|
|||||||
entities.add((LivingEntity) e);
|
entities.add((LivingEntity) e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return entities;
|
return entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user