Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.SkyPvP.System.Commands;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandExecutor;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.event.Listener;
- import org.bukkit.inventory.ItemStack;
- import de.SkyPvP.System.Data.Data;
- public class Command_Stack implements CommandExecutor, Listener {
- @SuppressWarnings("deprecation")
- @Override
- public boolean onCommand(CommandSender sender, Command cmd, String str,
- String[] args) {
- if ((sender instanceof Player)) {
- Player p = (Player) sender;
- if (cmd.getName().equalsIgnoreCase("stack")) {
- if (p.hasPermission("system.stack")) {
- boolean ignoreMax = true;
- ItemStack[] items = p.getInventory().getContents();
- int len = items.length;
- int affected = 0;
- for (int i = 0; i < len; i++) {
- ItemStack item = items[i];
- if ((item != null)
- && (item.getAmount() > 0)
- && ((ignoreMax) || (item.getMaxStackSize() != 1))) {
- int max = ignoreMax ? 64 : item.getMaxStackSize();
- if (item.getAmount() < max) {
- int needed = max - item.getAmount();
- for (int j = i + 1; j < len; j++) {
- ItemStack item2 = items[j];
- if ((item2 != null)
- && (item2.getAmount() > 0)
- && ((ignoreMax) || (item
- .getMaxStackSize() != 1))) {
- if ((item2.getTypeId() == item
- .getTypeId())
- && (item.getDurability() == item2
- .getDurability())
- && (((item.getItemMeta() == null) && (item2
- .getItemMeta() == null)) || ((item
- .getItemMeta() != null) && (item
- .getItemMeta()
- .equals(item2
- .getItemMeta()))))) {
- if (item2.getAmount() > needed) {
- item.setAmount(max);
- item2.setAmount(item2
- .getAmount() - needed);
- break;
- }
- items[j] = null;
- item.setAmount(item.getAmount()
- + item2.getAmount());
- needed = max - item.getAmount();
- affected++;
- }
- }
- }
- }
- }
- }
- if (affected > 0) {
- p.getInventory().setContents(items);
- }
- p.sendMessage(Data.Prefix +"§7Alle deine Items wurden gestackt!");
- }else{
- p.sendMessage(Data.NOPERM);
- }
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement