Disable bukkits stacking of items

Discussion in 'Archived: Plugin Requests' started by shoter, Oct 23, 2013.

  1. Offline

    shoter

    Basically I need a plugin which disables bukkits item stacking, the reason is if you drop an item with the same name, lore, id but different sub id like 321:100 and 321:32 they will stack and choose only one id when dropped.
     
  2. Offline

    one4me

    There's no option in the API as far as I know, but you can always extend EntityItem and override a(EntityItem entityitem) so that it always returns false.

    Edit - I just saw this was in the requests section, so here you go.

    Download:
    NoStack.jar

    Source:
    Code:
    package com.github.one4me;
    
    import net.minecraft.server.v1_6_R3.EntityItem;
    import org.bukkit.Location;
    import org.bukkit.craftbukkit.v1_6_R3.CraftWorld;
    import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack;
    import org.bukkit.entity.Item;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerDropItemEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class NoStack extends JavaPlugin implements Listener {
      @Override
      public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this);
      }
      @Override
      public void onDisable() {
      }
      @EventHandler
      public void onPlayerDropItemEvent(PlayerDropItemEvent event) {
        Item item = event.getItemDrop();
        ItemStack itemstack = item.getItemStack();
        Location location = item.getLocation();
        EntityItem ei = new EntityItem(
          ((CraftWorld)location.getWorld()).getHandle(),
          location.getX(),
          location.getY(),
          location.getZ(),
          CraftItemStack.asNMSCopy(itemstack)) {
          @Override
          public boolean a(EntityItem entityitem) {
            return false;
          }
        };
        ei.pickupDelay = 20;
        ((Item)ei.getBukkitEntity()).setVelocity(item.getVelocity());
        ((CraftWorld)location.getWorld()).getHandle().addEntity(ei);
        item.remove();
      }
    }
    
    Note: If you disable items from merging like this, players may be able to cause severe lag by dropping a lot of item's at once.
     
    shoter likes this.

Share This Page