mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-11-22 10:05:23 +01:00
Merge branch 'development'
This commit is contained in:
commit
be7e4c4be1
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.craftaro</groupId>
|
||||
<artifactId>UltimateStacker-Parent</artifactId>
|
||||
<version>3.1.7</version>
|
||||
<version>3.1.10</version>
|
||||
</parent>
|
||||
<artifactId>UltimateStacker-API</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
|
@ -10,6 +10,9 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Called before we spawn a stacked items
|
||||
*/
|
||||
@ -20,6 +23,7 @@ public class StackedItemSpawnEvent extends Event implements Cancellable {
|
||||
private ItemStack itemStack;
|
||||
private long amount;
|
||||
private boolean cancelled = false;
|
||||
private Map<String, Object> extraData = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -34,6 +38,32 @@ public class StackedItemSpawnEvent extends Event implements Cancellable {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public StackedItemSpawnEvent(@Nullable Item item, @NotNull ItemStack itemStack, long amount, @NotNull Map<String, Object> extraData) {
|
||||
this.item = item;
|
||||
this.itemStack = itemStack;
|
||||
this.amount = amount;
|
||||
this.extraData = extraData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extra data related to the event
|
||||
*
|
||||
* @return extra data
|
||||
*/
|
||||
public @NotNull Map<String, Object> getExtraData() {
|
||||
return extraData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the extra data for the event
|
||||
*
|
||||
* @param key Key
|
||||
* @param value Value
|
||||
*/
|
||||
public void addExtraData(String key, Object value) {
|
||||
this.extraData.put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the item that will be modified
|
||||
*
|
||||
|
@ -3,6 +3,7 @@ package com.craftaro.ultimatestacker.api.stack.item;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -20,6 +21,16 @@ public interface StackedItemManager {
|
||||
*/
|
||||
@NotNull StackedItem getStackedItem(Item item);
|
||||
|
||||
/**
|
||||
* Create a new StackedItem for the given ItemStack
|
||||
* @param item The ItemStack to create the stack for
|
||||
* @param location The location to spawn the stack
|
||||
* @param amount The amount of items in the stack
|
||||
* @param killed The entity that is dropping the item
|
||||
* @return The StackedItem for the given Item or null if it could not be created
|
||||
*/
|
||||
@Nullable StackedItem createStack(ItemStack item, Location location, int amount, LivingEntity killed);
|
||||
|
||||
/**
|
||||
* Create a new StackedItem for the given item
|
||||
* @param item The item to create the stack for
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.craftaro</groupId>
|
||||
<artifactId>UltimateStacker-Parent</artifactId>
|
||||
<version>3.1.7</version>
|
||||
<version>3.1.10</version>
|
||||
</parent>
|
||||
<artifactId>UltimateStacker-Plugin</artifactId>
|
||||
|
||||
|
@ -124,7 +124,7 @@ public class BlockListeners implements Listener {
|
||||
player.getWorld().dropItemNaturally(block.getLocation(), stack.getMaterial().parseItem());
|
||||
}
|
||||
}
|
||||
if (stack.getAmount() == 0) {
|
||||
if (stack.getAmount() == 1) {
|
||||
//Remove stack
|
||||
stack.destroy();
|
||||
return;
|
||||
|
@ -2,7 +2,9 @@ package com.craftaro.ultimatestacker.listeners;
|
||||
|
||||
import com.craftaro.core.compatibility.CompatibleHand;
|
||||
import com.craftaro.core.compatibility.ServerVersion;
|
||||
import com.craftaro.core.nms.NmsManager;
|
||||
import com.craftaro.core.nms.Nms;
|
||||
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTCompound;
|
||||
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTEntity;
|
||||
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
|
||||
import com.craftaro.core.utils.EntityUtils;
|
||||
import com.craftaro.ultimatestacker.UltimateStacker;
|
||||
@ -124,13 +126,16 @@ public class SpawnerListeners implements Listener {
|
||||
.replace("MOOSHROOM", "MUSHROOM_COW")
|
||||
.replace("ZOMBIE_PIGMAN", "PIG_ZOMBIE"));
|
||||
else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_12)) {
|
||||
String str = NmsManager.getNbt().of(event.getItem()).toString();
|
||||
if (str.contains("minecraft:"))
|
||||
entityType = EntityType.fromName(str.substring(str.indexOf("minecraft:") + 10, str.indexOf("\"}")));
|
||||
else
|
||||
entityType = EntityType.fromName(str.substring(str.indexOf("EntityTag:{id:") + 15, str.indexOf("\"}")));
|
||||
} else
|
||||
Nms.getImplementations().getNbt().of(event.getItem()).toString();
|
||||
NBTCompound entityTag = new NBTItem(event.getItem()).getCompound("EntityTag");
|
||||
if (entityTag != null) {
|
||||
entityType = EntityType.fromName(entityTag.getString("id"));
|
||||
} else {
|
||||
entityType = EntityType.fromName(event.getItem().getItemMeta().getDisplayName().replace(" Spawn Egg", ""));
|
||||
}
|
||||
} else {
|
||||
entityType = ((SpawnEgg) event.getItem().getData()).getSpawnedType();
|
||||
}
|
||||
|
||||
if (!player.hasPermission("ultimatestacker.egg." + entityType.name())) {
|
||||
event.setCancelled(true);
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.craftaro.ultimatestacker.listeners.item;
|
||||
|
||||
import com.craftaro.core.nms.NmsManager;
|
||||
import com.craftaro.core.nms.Nms;
|
||||
import com.craftaro.core.nms.world.WorldCore;
|
||||
import com.craftaro.core.world.SWorld;
|
||||
import com.craftaro.third_party.org.apache.commons.lang3.StringUtils;
|
||||
import com.craftaro.ultimatestacker.UltimateStacker;
|
||||
import com.craftaro.ultimatestacker.api.UltimateStackerApi;
|
||||
@ -8,6 +10,7 @@ import com.craftaro.ultimatestacker.api.stack.item.StackedItem;
|
||||
import com.craftaro.ultimatestacker.api.stack.item.StackedItemManager;
|
||||
import com.craftaro.ultimatestacker.settings.Settings;
|
||||
import com.craftaro.ultimatestacker.utils.Methods;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -52,7 +55,7 @@ public class ItemListeners implements Listener {
|
||||
Methods.updateInventory(event.getItem(), event.getInventory());
|
||||
if (event.getInventory().getHolder() instanceof BlockState) {
|
||||
Block invHolder = ((BlockState) event.getInventory().getHolder()).getBlock();
|
||||
NmsManager.getWorld().updateAdjacentComparators(invHolder);
|
||||
Nms.getImplementations().getWorld().updateAdjacentComparators(invHolder);
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,13 +67,15 @@ public class ItemListeners implements Listener {
|
||||
if (disabledWorlds.stream().anyMatch(worldStr -> event.getEntity().getWorld().getName().equalsIgnoreCase(worldStr)))
|
||||
return;
|
||||
|
||||
if (UltimateStackerApi.getStackedItemManager().isStackedItem(event.getEntity())) return;
|
||||
|
||||
ItemStack itemStack = event.getEntity().getItemStack();
|
||||
|
||||
if (itemStack.hasItemMeta() && itemStack.getItemMeta().hasDisplayName() &&
|
||||
StringUtils.substring(itemStack.getItemMeta().getDisplayName(), 0, 3).equals("***")) {
|
||||
return; //Compatibility with Shop instance: https://www.spigotmc.org/resources/shop-a-simple-intuitive-shop-instance.9628/
|
||||
}
|
||||
|
||||
|
||||
UltimateStackerApi.getStackedItemManager().createStack(event.getEntity(), itemStack.getAmount());
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public class BlockStackImpl implements BlockStack {
|
||||
// The id that identifies this stack in the database.
|
||||
private int id;
|
||||
|
||||
private int amount = 1;
|
||||
private int amount = 2;
|
||||
private XMaterial material;
|
||||
private Location location;
|
||||
|
||||
@ -79,7 +79,7 @@ public class BlockStackImpl implements BlockStack {
|
||||
|
||||
@Override
|
||||
public void setAmount(int amount) {
|
||||
if (amount < 1) {
|
||||
if (amount == 1) {
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
|
@ -30,18 +30,22 @@ import java.util.UUID;
|
||||
public class EntityStackImpl implements EntityStack {
|
||||
|
||||
private final UltimateStacker plugin = UltimateStacker.getInstance();
|
||||
private Object STACKED_ENTITY_KEY;
|
||||
private static Object STACKED_ENTITY_KEY;
|
||||
private int amount;
|
||||
private LivingEntity hostEntity;
|
||||
|
||||
static {
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_14)) {
|
||||
STACKED_ENTITY_KEY = new org.bukkit.NamespacedKey(UltimateStacker.getInstance(), "US_AMOUNT");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an existing stack from an entity or creates a new one if it doesn't exist.
|
||||
*
|
||||
* @param entity The entity to get the stack from.
|
||||
*/
|
||||
public EntityStackImpl(LivingEntity entity) {
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_14))
|
||||
this.STACKED_ENTITY_KEY = new org.bukkit.NamespacedKey(plugin, "US_AMOUNT");
|
||||
if (entity == null) return;
|
||||
if (!UltimateStacker.getInstance().getEntityStackManager().isStackedEntity(entity)) {
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_14)) {
|
||||
|
@ -11,7 +11,9 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -39,6 +41,22 @@ public class StackedItemManagerImpl implements StackedItemManager {
|
||||
return new StackedItemImpl(dropped, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable StackedItem createStack(ItemStack item, Location location, int amount, LivingEntity killed) {
|
||||
if (item.getType() == Material.AIR) return null;
|
||||
if (killed == null) return createStack(item, location, amount);
|
||||
World world = location.getWorld();
|
||||
if (world == null) return null;
|
||||
StackedItemSpawnEvent event = new StackedItemSpawnEvent(null, item, amount);
|
||||
if (killed.hasMetadata("EFA-TAGGED")) {
|
||||
event.addExtraData("EFA-TAGGED", killed.getMetadata("EFA-TAGGED").get(0).value());
|
||||
}
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) return null;
|
||||
Item dropped = world.dropItem(location, item);
|
||||
return new StackedItemImpl(dropped, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackedItem createStack(Item item, int amount) {
|
||||
StackedItemSpawnEvent event = new StackedItemSpawnEvent(item, item.getItemStack(), amount);
|
||||
|
4
pom.xml
4
pom.xml
@ -7,7 +7,7 @@
|
||||
<groupId>com.craftaro</groupId>
|
||||
<artifactId>UltimateStacker-Parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>3.1.7</version>
|
||||
<version>3.1.10</version>
|
||||
|
||||
<modules>
|
||||
<module>UltimateStacker-API</module>
|
||||
@ -19,7 +19,7 @@
|
||||
<url>https://craftaro.com/marketplace/product/16</url>
|
||||
|
||||
<properties>
|
||||
<craftaro.coreVersion>3.0.1-SNAPSHOT</craftaro.coreVersion>
|
||||
<craftaro.coreVersion>3.0.6-SNAPSHOT</craftaro.coreVersion>
|
||||
|
||||
<maven.compiler.release>8</maven.compiler.release>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
|
Loading…
Reference in New Issue
Block a user