Compare commits
6 Commits
36bc2f743b
...
37322d0a25
Author | SHA1 | Date |
---|---|---|
Brianna O'Keefe | 37322d0a25 | |
Brianna O'Keefe | e92d86a4c4 | |
ceze88 | 29e6750539 | |
ceze88 | 1c79ce5485 | |
ceze88 | d88c61fc94 | |
ceze88 | d9612b0cfe |
|
@ -7,7 +7,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.craftaro</groupId>
|
<groupId>com.craftaro</groupId>
|
||||||
<artifactId>UltimateStacker-Parent</artifactId>
|
<artifactId>UltimateStacker-Parent</artifactId>
|
||||||
<version>3.1.4</version>
|
<version>3.1.5</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>UltimateStacker-API</artifactId>
|
<artifactId>UltimateStacker-API</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.craftaro</groupId>
|
<groupId>com.craftaro</groupId>
|
||||||
<artifactId>UltimateStacker-Parent</artifactId>
|
<artifactId>UltimateStacker-Parent</artifactId>
|
||||||
<version>3.1.4</version>
|
<version>3.1.5</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>UltimateStacker-Plugin</artifactId>
|
<artifactId>UltimateStacker-Plugin</artifactId>
|
||||||
|
|
||||||
|
|
|
@ -181,7 +181,41 @@ public class BlockListeners implements Listener {
|
||||||
if (itemType == blockType) {
|
if (itemType == blockType) {
|
||||||
SpawnerStack stack = UltimateStackerApi.getSpawnerStackManager().getSpawner(block);
|
SpawnerStack stack = UltimateStackerApi.getSpawnerStackManager().getSpawner(block);
|
||||||
if (stack == null) return;
|
if (stack == null) return;
|
||||||
if (player.isSneaking()) return;
|
if (player.isSneaking()) {
|
||||||
|
//Add all to stack from hand
|
||||||
|
if (Settings.SNEAK_TO_ADD_ALL.getBoolean()) {
|
||||||
|
|
||||||
|
//Redo this logic, if we have 10 items in hand and each item is 5 stack size, we need to take into consideration that what happens if we can only add 2 stack total in a stack? We have to remove one extra item and add one spawner with 3 stack back
|
||||||
|
int amountToAdd = Math.min(maxStackSize - stack.getAmount(), itemAmount * inHand.getAmount()); //Multiply by inHand.getAmount() to get the total amount of items in hand
|
||||||
|
int remaining = itemAmount * inHand.getAmount() - amountToAdd; //Calculate the remaining amount of items in hand
|
||||||
|
stack.setAmount(stack.getAmount() + amountToAdd);
|
||||||
|
plugin.updateHologram(stack);
|
||||||
|
plugin.getDataManager().save(stack);
|
||||||
|
if (remaining % itemAmount == 0) { //We don't have to worry about leftovers
|
||||||
|
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||||
|
hand.takeItem(player, amountToAdd / itemAmount);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
int fullStacks = amountToAdd / itemAmount;
|
||||||
|
int overflow = remaining % itemAmount;
|
||||||
|
//remove fullstacks-1 and add back overflow as a new item stack
|
||||||
|
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||||
|
if (overflow > 0) {
|
||||||
|
hand.takeItem(player, fullStacks+1);
|
||||||
|
ItemStack overflowItem = Methods.getSpawnerItem(blockType, overflow);
|
||||||
|
if (player.getInventory().firstEmpty() == -1) {
|
||||||
|
block.getWorld().dropItemNaturally(block.getLocation().add(.5, 0, .5), overflowItem);
|
||||||
|
} else {
|
||||||
|
player.getInventory().addItem(overflowItem);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
hand.takeItem(player, fullStacks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (player.hasPermission("ultimatestacker.spawner.nostack") && !player.isOp()) {
|
if (player.hasPermission("ultimatestacker.spawner.nostack") && !player.isOp()) {
|
||||||
event.setCancelled(false);
|
event.setCancelled(false);
|
||||||
return;
|
return;
|
||||||
|
@ -261,12 +295,16 @@ public class BlockListeners implements Listener {
|
||||||
|
|
||||||
CreatureSpawner cs = (CreatureSpawner) block.getState();
|
CreatureSpawner cs = (CreatureSpawner) block.getState();
|
||||||
|
|
||||||
EntityType blockType = cs.getSpawnedType();
|
EntityType spawnedEntityType = cs.getSpawnedType();
|
||||||
|
|
||||||
|
//Empty spawners return null?? It is annotated as @NotNull
|
||||||
|
if (spawnedEntityType == null) return;
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
ItemStack item = player.getInventory().getItemInHand();
|
ItemStack item = player.getInventory().getItemInHand();
|
||||||
|
|
||||||
SpawnerStack stack = UltimateStackerApi.getSpawnerStackManager().getSpawner(block);
|
SpawnerStack stack = UltimateStackerApi.getSpawnerStackManager().getSpawner(block);
|
||||||
|
if (stack == null) return;
|
||||||
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
@ -280,7 +318,7 @@ public class BlockListeners implements Listener {
|
||||||
remove = true;
|
remove = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpawnerBreakEvent breakEvent = new SpawnerBreakEvent(player, block, blockType, amt);
|
SpawnerBreakEvent breakEvent = new SpawnerBreakEvent(player, block, spawnedEntityType, amt);
|
||||||
Bukkit.getPluginManager().callEvent(breakEvent);
|
Bukkit.getPluginManager().callEvent(breakEvent);
|
||||||
if (breakEvent.isCancelled())
|
if (breakEvent.isCancelled())
|
||||||
return;
|
return;
|
||||||
|
@ -297,7 +335,7 @@ public class BlockListeners implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.hasPermission("ultimatestacker.spawner.nosilkdrop") || item.getEnchantments().containsKey(Enchantment.SILK_TOUCH) && player.hasPermission("ultimatestacker.spawner.silktouch")) {
|
if (player.hasPermission("ultimatestacker.spawner.nosilkdrop") || item.getEnchantments().containsKey(Enchantment.SILK_TOUCH) && player.hasPermission("ultimatestacker.spawner.silktouch")) {
|
||||||
ItemStack spawner = Methods.getSpawnerItem(blockType, amt);
|
ItemStack spawner = Methods.getSpawnerItem(spawnedEntityType, amt);
|
||||||
if (player.getInventory().firstEmpty() == -1 || !Settings.SPAWNERS_TO_INVENTORY.getBoolean())
|
if (player.getInventory().firstEmpty() == -1 || !Settings.SPAWNERS_TO_INVENTORY.getBoolean())
|
||||||
block.getWorld().dropItemNaturally(block.getLocation().add(.5, 0, .5), spawner);
|
block.getWorld().dropItemNaturally(block.getLocation().add(.5, 0, .5), spawner);
|
||||||
else
|
else
|
||||||
|
|
|
@ -239,6 +239,9 @@ public class Settings implements com.craftaro.ultimatestacker.api.Settings {
|
||||||
public static final ConfigSetting SNEAK_FOR_STACK = new ConfigSetting(config, "Spawners.Sneak To Receive A Stacked Spawner", true,
|
public static final ConfigSetting SNEAK_FOR_STACK = new ConfigSetting(config, "Spawners.Sneak To Receive A Stacked Spawner", true,
|
||||||
"Toggle ability to receive a stacked spawner when breaking a spawner while sneaking.");
|
"Toggle ability to receive a stacked spawner when breaking a spawner while sneaking.");
|
||||||
|
|
||||||
|
public static final ConfigSetting SNEAK_TO_ADD_ALL = new ConfigSetting(config, "Spawners.Sneak To Add All", true,
|
||||||
|
"Should the player be able to add all spawners to the stack if they are sneaking?");
|
||||||
|
|
||||||
public static final ConfigSetting SPAWNERS_DONT_EXPLODE = new ConfigSetting(config, "Spawners.Prevent Spawners From Exploding", false,
|
public static final ConfigSetting SPAWNERS_DONT_EXPLODE = new ConfigSetting(config, "Spawners.Prevent Spawners From Exploding", false,
|
||||||
"Should spawners not break when blown up?");
|
"Should spawners not break when blown up?");
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.craftaro.ultimatestacker.tasks;
|
package com.craftaro.ultimatestacker.tasks;
|
||||||
|
|
||||||
import com.craftaro.core.task.TaskScheduler;
|
import com.craftaro.core.thread.TaskScheduler;
|
||||||
import com.craftaro.ultimatestacker.UltimateStacker;
|
import com.craftaro.ultimatestacker.UltimateStacker;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
|
||||||
|
|
|
@ -89,12 +89,15 @@ public class StackingTask extends BukkitRunnable {
|
||||||
//Filter non-stackable entities to improve performance on main thread
|
//Filter non-stackable entities to improve performance on main thread
|
||||||
entities.removeIf(this::isEntityNotStackable);
|
entities.removeIf(this::isEntityNotStackable);
|
||||||
|
|
||||||
for (LivingEntity entity : entities) {
|
List<LivingEntity> remove = new ArrayList<>();
|
||||||
|
for (LivingEntity entity : entities) { //Q: What can cause current modification exception here?
|
||||||
// Check our WorldGuard flag.
|
// Check our WorldGuard flag.
|
||||||
Boolean flag = WorldGuardHook.isEnabled() ? WorldGuardHook.getBooleanFlag(entity.getLocation(), "mob-stacking") : null; //Does this work async?
|
Boolean flag = WorldGuardHook.isEnabled() ? WorldGuardHook.getBooleanFlag(entity.getLocation(), "mob-stacking") : null; //Does this work async?
|
||||||
if (flag != null && !flag)
|
if (flag != null && !flag) {
|
||||||
entities.removeIf(entity1 -> entity1.getUniqueId().equals(entity.getUniqueId()));
|
remove.add(entity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
entities.removeAll(remove);
|
||||||
|
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
// Loop through the entities.
|
// Loop through the entities.
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -7,7 +7,7 @@
|
||||||
<groupId>com.craftaro</groupId>
|
<groupId>com.craftaro</groupId>
|
||||||
<artifactId>UltimateStacker-Parent</artifactId>
|
<artifactId>UltimateStacker-Parent</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>3.1.4</version>
|
<version>3.1.5</version>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>UltimateStacker-API</module>
|
<module>UltimateStacker-API</module>
|
||||||
|
|
Loading…
Reference in New Issue