Compare commits

..

4 Commits

Author SHA1 Message Date
ceze88
e47ec63db4 Release v3.1.9 2024-04-06 13:13:55 +02:00
ceze88
cad46cec15 Add better compatibility with EpicFarming 2024-04-06 13:13:22 +02:00
ceze88
a22746b9d5 Update SongodaCore methods 2024-04-06 13:13:03 +02:00
ceze88
3230710f76 Uopdate SongodaCore version 2024-04-06 13:08:58 +02:00
8 changed files with 75 additions and 14 deletions

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.craftaro</groupId>
<artifactId>UltimateStacker-Parent</artifactId>
<version>3.1.8</version>
<version>3.1.9</version>
</parent>
<artifactId>UltimateStacker-API</artifactId>
<version>1.0.0-SNAPSHOT</version>

View File

@ -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
*

View File

@ -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,8 @@ public interface StackedItemManager {
*/
@NotNull StackedItem getStackedItem(Item item);
@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

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.craftaro</groupId>
<artifactId>UltimateStacker-Parent</artifactId>
<version>3.1.8</version>
<version>3.1.9</version>
</parent>
<artifactId>UltimateStacker-Plugin</artifactId>

View File

@ -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);

View File

@ -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());
}
}

View File

@ -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);

View File

@ -7,7 +7,7 @@
<groupId>com.craftaro</groupId>
<artifactId>UltimateStacker-Parent</artifactId>
<packaging>pom</packaging>
<version>3.1.8</version>
<version>3.1.9</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.5-SNAPSHOT</craftaro.coreVersion>
<maven.compiler.release>8</maven.compiler.release>
<maven.compiler.target>1.8</maven.compiler.target>