From 306aab0d8df5994ffc058dc905fb7ffe8a2f4e14 Mon Sep 17 00:00:00 2001 From: vemacs Date: Sun, 28 Jun 2015 10:28:55 -0500 Subject: [PATCH] Implement drop-items-if-full for /give command (default false) --- Essentials/src/com/earth2me/essentials/ISettings.java | 2 ++ Essentials/src/com/earth2me/essentials/Settings.java | 5 +++++ .../com/earth2me/essentials/commands/Commandgive.java | 10 +++++++++- Essentials/src/config.yml | 3 +++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Essentials/src/com/earth2me/essentials/ISettings.java b/Essentials/src/com/earth2me/essentials/ISettings.java index c4111450a..922240f5a 100644 --- a/Essentials/src/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/com/earth2me/essentials/ISettings.java @@ -225,4 +225,6 @@ public interface ISettings extends IConf { String getCustomQuitMessage(); boolean isNotifyNoNewMail(); + + boolean isDropItemsIfFull(); } diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index 8271de9ed..88750a8bd 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -1106,6 +1106,11 @@ public class Settings implements net.ess3.api.ISettings { return config.getBoolean("notify-no-new-mail", true); } + @Override + public boolean isDropItemsIfFull() { + return config.getBoolean("drop-items-if-full", false); + } + // #easteregg @Override public int getMaxUserCacheCount() { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java index 8411103f1..e243bd0c3 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java @@ -7,6 +7,7 @@ import com.earth2me.essentials.craftbukkit.InventoryWorkaround; import com.earth2me.essentials.utils.NumberUtil; import org.bukkit.Material; import org.bukkit.Server; +import org.bukkit.World; import org.bukkit.inventory.ItemStack; import java.util.Locale; @@ -85,8 +86,15 @@ public class Commandgive extends EssentialsCommand { leftovers = InventoryWorkaround.addItems(giveTo.getBase().getInventory(), stack); } + boolean isDropItemsIfFull = ess.getSettings().isDropItemsIfFull(); + for (ItemStack item : leftovers.values()) { - sender.sendMessage(tl("giveSpawnFailure", item.getAmount(), itemName, giveTo.getDisplayName())); + if (isDropItemsIfFull) { + World w = giveTo.getWorld(); + w.dropItemNaturally(giveTo.getLocation(), item); + } else { + sender.sendMessage(tl("giveSpawnFailure", item.getAmount(), itemName, giveTo.getDisplayName())); + } } giveTo.getBase().updateInventory(); diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 057dcf19b..fc1395369 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -95,6 +95,9 @@ spawnmob-limit: 10 # Shall we notify users when using /lightning? warn-on-smite: true +# Shall we drop items instead of adding to inventory if the target inventory is full? +drop-items-if-full: false + # Essentials Mail Notification # Should we notify players if they have no new mail? notify-no-new-mail: true