Merge branch 'development'

This commit is contained in:
Brianna 2020-04-05 17:15:28 -04:00
commit df1134a35e
5 changed files with 33 additions and 20 deletions

View File

@ -2,7 +2,7 @@
<groupId>com.songoda</groupId>
<artifactId>UltimateStacker</artifactId>
<modelVersion>4.0.0</modelVersion>
<version>1.11.7</version>
<version>1.11.8</version>
<build>
<defaultGoal>clean install</defaultGoal>
<finalName>UltimateStacker-${project.version}</finalName>

View File

@ -1,6 +1,8 @@
package com.songoda.ultimatestacker.entity;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public enum Check {
@ -52,6 +54,13 @@ public enum Check {
this.isEnabledByDefault = isEnabledByDefault;
}
public static List<Check> getChecks(List<String> strChecks) {
List<Check> checks = new ArrayList<>();
for (String checkStr : strChecks)
checks.add(getCheck(checkStr));
return checks;
}
public boolean isEnabledByDefault() {
return isEnabledByDefault;
}

View File

@ -7,6 +7,7 @@ import com.songoda.ultimatestacker.settings.Settings;
import com.songoda.ultimatestacker.utils.Methods;
import org.apache.commons.lang.StringUtils;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Item;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -88,16 +89,16 @@ public class ItemListeners implements Listener {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPickup(PlayerPickupItemEvent event) {
if (!Settings.STACK_ITEMS.getBoolean()) return;
if (!Settings.STACK_ITEMS.getBoolean() || event.getItem() instanceof Arrow) return;
// Amount here is not the total amount of item (32 if more than 32) but the amount of item the player can retrieve
// ie there is x64 diamonds blocks (so 32), the player pick 8 items so the amount is 8 and not 32
int amount = UltimateStacker.getActualItemAmount(event.getItem());
if (/*event.getItem().getItemStack().getAmount()*/amount < (event.getItem().getItemStack().getMaxStackSize() / 2)) {
// Update
UltimateStacker.updateItemAmount(event.getItem(), event.getRemaining());
return;
}
event.setCancelled(true);
Item item = event.getItem();
ItemStack stack = item.getItemStack();
int amount = UltimateStacker.getActualItemAmount(item);
if (amount < (stack.getMaxStackSize() / 2)) return;
event.getItem().setItemStack(stack);
event.getPlayer().playSound(event.getPlayer().getLocation(), CompatibleSound.ENTITY_ITEM_PICKUP.getSound(), .2f, (float) (1 + Math.random()));

View File

@ -146,9 +146,11 @@ public class StackingTask extends BukkitRunnable {
int maxEntityStackSize = getEntityStackSize(livingEntity);
// Get similar entities around our entity and make sure those entities are both compatible and stackable.
List<LivingEntity> stackableFriends = plugin.getEntityUtils().getSimilarEntitiesAroundEntity(livingEntity, location)
.stream().filter(entity -> isEntityStackable(entity, location))
.collect(Collectors.toCollection(LinkedList::new));
List<LivingEntity> stackableFriends = new LinkedList<>();
for (LivingEntity entity : plugin.getEntityUtils().getSimilarEntitiesAroundEntity(livingEntity, location)) {
if (!isEntityStackable(entity, location)) continue;
stackableFriends.add(entity);
}
// Loop through our similar stackable entities.
for (LivingEntity entity : stackableFriends) {

View File

@ -19,7 +19,7 @@ public class EntityUtils {
UltimateStacker plugin = UltimateStacker.getInstance();
private final List<String> checks = Settings.STACK_CHECKS.getStringList();
private final List<Check> checks = Check.getChecks(Settings.STACK_CHECKS.getStringList());
private final boolean stackFlyingDown = Settings.ONLY_STACK_FLYING_DOWN.getBoolean(),
keepFire = Settings.KEEP_FIRE.getBoolean(),
keepPotion = Settings.KEEP_POTION.getBoolean(),
@ -100,8 +100,7 @@ public class EntityUtils {
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_12))
newEntity.setInvulnerable(false);
for (String checkStr : checks) {
Check check = Check.valueOf(checkStr);
for (Check check : checks) {
switch (check) {
case AGE: {
if (!(toClone instanceof Ageable) || ((Ageable) toClone).isAdult()) break;
@ -255,15 +254,17 @@ public class EntityUtils {
public List<LivingEntity> getSimilarEntitiesAroundEntity(LivingEntity initialEntity, Location location) {
// Create a list of all entities around the initial entity of the same type.
List<LivingEntity> entityList = getNearbyEntities(location, searchRadius, stackWholeChunk)
.stream().filter(entity -> entity.getType() == initialEntity.getType() && entity != initialEntity)
.collect(Collectors.toCollection(LinkedList::new));
List<LivingEntity> entityList = new LinkedList<>();
for (LivingEntity entity : getNearbyEntities(location, searchRadius, stackWholeChunk)) {
if (entity.getType() != initialEntity.getType() || entity == initialEntity)
continue;
entityList.add(entity);
}
if (stackFlyingDown && Methods.canFly(initialEntity))
entityList.removeIf(entity -> entity.getLocation().getY() > initialEntity.getLocation().getY());
for (String checkStr : checks) {
Check check = Check.getCheck(checkStr);
for (Check check : checks) {
if (check == null) continue;
switch (check) {
case SPAWN_REASON: {