mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-11-14 06:07:09 +01:00
Compare commits
4 Commits
1210047197
...
e47ec63db4
Author | SHA1 | Date | |
---|---|---|---|
|
e47ec63db4 | ||
|
cad46cec15 | ||
|
a22746b9d5 | ||
|
3230710f76 |
@ -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.8</version>
|
<version>3.1.9</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>UltimateStacker-API</artifactId>
|
<artifactId>UltimateStacker-API</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
@ -10,6 +10,9 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called before we spawn a stacked items
|
* Called before we spawn a stacked items
|
||||||
*/
|
*/
|
||||||
@ -20,6 +23,7 @@ public class StackedItemSpawnEvent extends Event implements Cancellable {
|
|||||||
private ItemStack itemStack;
|
private ItemStack itemStack;
|
||||||
private long amount;
|
private long amount;
|
||||||
private boolean cancelled = false;
|
private boolean cancelled = false;
|
||||||
|
private Map<String, Object> extraData = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -34,6 +38,32 @@ public class StackedItemSpawnEvent extends Event implements Cancellable {
|
|||||||
this.amount = amount;
|
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
|
* 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.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Item;
|
import org.bukkit.entity.Item;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@ -20,6 +21,8 @@ public interface StackedItemManager {
|
|||||||
*/
|
*/
|
||||||
@NotNull StackedItem getStackedItem(Item item);
|
@NotNull StackedItem getStackedItem(Item item);
|
||||||
|
|
||||||
|
@Nullable StackedItem createStack(ItemStack item, Location location, int amount, LivingEntity killed);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new StackedItem for the given item
|
* Create a new StackedItem for the given item
|
||||||
* @param item The item to create the stack for
|
* @param item The item to create the stack for
|
||||||
|
@ -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.8</version>
|
<version>3.1.9</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>UltimateStacker-Plugin</artifactId>
|
<artifactId>UltimateStacker-Plugin</artifactId>
|
||||||
|
|
||||||
|
@ -2,7 +2,9 @@ package com.craftaro.ultimatestacker.listeners;
|
|||||||
|
|
||||||
import com.craftaro.core.compatibility.CompatibleHand;
|
import com.craftaro.core.compatibility.CompatibleHand;
|
||||||
import com.craftaro.core.compatibility.ServerVersion;
|
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.third_party.de.tr7zw.nbtapi.NBTItem;
|
||||||
import com.craftaro.core.utils.EntityUtils;
|
import com.craftaro.core.utils.EntityUtils;
|
||||||
import com.craftaro.ultimatestacker.UltimateStacker;
|
import com.craftaro.ultimatestacker.UltimateStacker;
|
||||||
@ -124,13 +126,16 @@ public class SpawnerListeners implements Listener {
|
|||||||
.replace("MOOSHROOM", "MUSHROOM_COW")
|
.replace("MOOSHROOM", "MUSHROOM_COW")
|
||||||
.replace("ZOMBIE_PIGMAN", "PIG_ZOMBIE"));
|
.replace("ZOMBIE_PIGMAN", "PIG_ZOMBIE"));
|
||||||
else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_12)) {
|
else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_12)) {
|
||||||
String str = NmsManager.getNbt().of(event.getItem()).toString();
|
Nms.getImplementations().getNbt().of(event.getItem()).toString();
|
||||||
if (str.contains("minecraft:"))
|
NBTCompound entityTag = new NBTItem(event.getItem()).getCompound("EntityTag");
|
||||||
entityType = EntityType.fromName(str.substring(str.indexOf("minecraft:") + 10, str.indexOf("\"}")));
|
if (entityTag != null) {
|
||||||
else
|
entityType = EntityType.fromName(entityTag.getString("id"));
|
||||||
entityType = EntityType.fromName(str.substring(str.indexOf("EntityTag:{id:") + 15, str.indexOf("\"}")));
|
} else {
|
||||||
} else
|
entityType = EntityType.fromName(event.getItem().getItemMeta().getDisplayName().replace(" Spawn Egg", ""));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
entityType = ((SpawnEgg) event.getItem().getData()).getSpawnedType();
|
entityType = ((SpawnEgg) event.getItem().getData()).getSpawnedType();
|
||||||
|
}
|
||||||
|
|
||||||
if (!player.hasPermission("ultimatestacker.egg." + entityType.name())) {
|
if (!player.hasPermission("ultimatestacker.egg." + entityType.name())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.craftaro.ultimatestacker.listeners.item;
|
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.third_party.org.apache.commons.lang3.StringUtils;
|
||||||
import com.craftaro.ultimatestacker.UltimateStacker;
|
import com.craftaro.ultimatestacker.UltimateStacker;
|
||||||
import com.craftaro.ultimatestacker.api.UltimateStackerApi;
|
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.api.stack.item.StackedItemManager;
|
||||||
import com.craftaro.ultimatestacker.settings.Settings;
|
import com.craftaro.ultimatestacker.settings.Settings;
|
||||||
import com.craftaro.ultimatestacker.utils.Methods;
|
import com.craftaro.ultimatestacker.utils.Methods;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -52,7 +55,7 @@ public class ItemListeners implements Listener {
|
|||||||
Methods.updateInventory(event.getItem(), event.getInventory());
|
Methods.updateInventory(event.getItem(), event.getInventory());
|
||||||
if (event.getInventory().getHolder() instanceof BlockState) {
|
if (event.getInventory().getHolder() instanceof BlockState) {
|
||||||
Block invHolder = ((BlockState) event.getInventory().getHolder()).getBlock();
|
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)))
|
if (disabledWorlds.stream().anyMatch(worldStr -> event.getEntity().getWorld().getName().equalsIgnoreCase(worldStr)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (UltimateStackerApi.getStackedItemManager().isStackedItem(event.getEntity())) return;
|
||||||
|
|
||||||
ItemStack itemStack = event.getEntity().getItemStack();
|
ItemStack itemStack = event.getEntity().getItemStack();
|
||||||
|
|
||||||
if (itemStack.hasItemMeta() && itemStack.getItemMeta().hasDisplayName() &&
|
if (itemStack.hasItemMeta() && itemStack.getItemMeta().hasDisplayName() &&
|
||||||
StringUtils.substring(itemStack.getItemMeta().getDisplayName(), 0, 3).equals("***")) {
|
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/
|
return; //Compatibility with Shop instance: https://www.spigotmc.org/resources/shop-a-simple-intuitive-shop-instance.9628/
|
||||||
}
|
}
|
||||||
|
|
||||||
UltimateStackerApi.getStackedItemManager().createStack(event.getEntity(), itemStack.getAmount());
|
UltimateStackerApi.getStackedItemManager().createStack(event.getEntity(), itemStack.getAmount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,9 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Item;
|
import org.bukkit.entity.Item;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@ -39,6 +41,22 @@ public class StackedItemManagerImpl implements StackedItemManager {
|
|||||||
return new StackedItemImpl(dropped, amount);
|
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
|
@Override
|
||||||
public StackedItem createStack(Item item, int amount) {
|
public StackedItem createStack(Item item, int amount) {
|
||||||
StackedItemSpawnEvent event = new StackedItemSpawnEvent(item, item.getItemStack(), amount);
|
StackedItemSpawnEvent event = new StackedItemSpawnEvent(item, item.getItemStack(), amount);
|
||||||
|
4
pom.xml
4
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.8</version>
|
<version>3.1.9</version>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>UltimateStacker-API</module>
|
<module>UltimateStacker-API</module>
|
||||||
@ -19,7 +19,7 @@
|
|||||||
<url>https://craftaro.com/marketplace/product/16</url>
|
<url>https://craftaro.com/marketplace/product/16</url>
|
||||||
|
|
||||||
<properties>
|
<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.release>8</maven.compiler.release>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
Loading…
Reference in New Issue
Block a user