mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-23 09:37:50 +01:00
Add option to remove vanishing items from keepinv users (#3328)
This commit is contained in:
parent
846043e9a0
commit
2ab4dcbc11
@ -1,8 +1,10 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -174,6 +176,57 @@ public class EssentialsEntityListener implements Listener {
|
||||
if (user.isAuthorized("essentials.keepinv")) {
|
||||
event.setKeepInventory(true);
|
||||
event.getDrops().clear();
|
||||
ISettings.KeepInvPolicy vanish = ess.getSettings().getVanishingItemsPolicy();
|
||||
ISettings.KeepInvPolicy bind = ess.getSettings().getBindingItemsPolicy();
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_11_2_R01) && (vanish != ISettings.KeepInvPolicy.KEEP || bind != ISettings.KeepInvPolicy.KEEP)) {
|
||||
for (ItemStack stack : event.getEntity().getInventory()) {
|
||||
if (stack != null) {
|
||||
if (stack.getEnchantments().containsKey(Enchantment.VANISHING_CURSE)) {
|
||||
if (vanish == ISettings.KeepInvPolicy.DELETE) {
|
||||
event.getEntity().getInventory().remove(stack);
|
||||
} else if (vanish == ISettings.KeepInvPolicy.DROP) {
|
||||
event.getDrops().add(stack);
|
||||
event.getEntity().getInventory().remove(stack);
|
||||
}
|
||||
}
|
||||
if (stack.getEnchantments().containsKey(Enchantment.BINDING_CURSE)) {
|
||||
if (bind == ISettings.KeepInvPolicy.DELETE) {
|
||||
event.getEntity().getInventory().remove(stack);
|
||||
} else if (bind == ISettings.KeepInvPolicy.DROP) {
|
||||
event.getEntity().getInventory().remove(stack);
|
||||
event.getDrops().add(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ItemStack[] armor = event.getEntity().getInventory().getArmorContents();
|
||||
for (int i = 0; i < armor.length; i++) {
|
||||
ItemStack stack = armor[i];
|
||||
if (stack != null) {
|
||||
if (stack.getEnchantments().containsKey(Enchantment.VANISHING_CURSE)) {
|
||||
if (vanish == ISettings.KeepInvPolicy.DELETE) {
|
||||
armor[i] = null;
|
||||
} else if (vanish == ISettings.KeepInvPolicy.DROP) {
|
||||
if (!event.getDrops().contains(stack)) {
|
||||
event.getDrops().add(stack);
|
||||
}
|
||||
armor[i] = null;
|
||||
}
|
||||
}
|
||||
if (stack.getEnchantments().containsKey(Enchantment.BINDING_CURSE)) {
|
||||
if (bind == ISettings.KeepInvPolicy.DELETE) {
|
||||
armor[i] = null;
|
||||
} else if (bind == ISettings.KeepInvPolicy.DROP) {
|
||||
if (!event.getDrops().contains(stack)) {
|
||||
event.getDrops().add(stack);
|
||||
}
|
||||
armor[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
event.getEntity().getInventory().setArmorContents(armor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,6 +204,16 @@ public interface ISettings extends IConf {
|
||||
|
||||
boolean areDeathMessagesEnabled();
|
||||
|
||||
KeepInvPolicy getVanishingItemsPolicy();
|
||||
|
||||
KeepInvPolicy getBindingItemsPolicy();
|
||||
|
||||
enum KeepInvPolicy {
|
||||
KEEP,
|
||||
DELETE,
|
||||
DROP
|
||||
}
|
||||
|
||||
void setDebug(boolean debug);
|
||||
|
||||
Set<String> getNoGodWorlds();
|
||||
|
@ -571,6 +571,8 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
nickBlacklist = _getNickBlacklist();
|
||||
maxProjectileSpeed = _getMaxProjectileSpeed();
|
||||
removeEffectsOnHeal = _isRemovingEffectsOnHeal();
|
||||
vanishingItemPolicy = _getVanishingItemsPolicy();
|
||||
bindingItemPolicy = _getBindingItemsPolicy();
|
||||
}
|
||||
|
||||
void _lateLoadItemSpawnBlacklist() {
|
||||
@ -977,6 +979,38 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
return config.getBoolean("death-messages", true);
|
||||
}
|
||||
|
||||
private KeepInvPolicy vanishingItemPolicy;
|
||||
|
||||
public KeepInvPolicy _getVanishingItemsPolicy() {
|
||||
String value = config.getString("vanishing-items-policy", "keep").toLowerCase(Locale.ENGLISH);
|
||||
try {
|
||||
return KeepInvPolicy.valueOf(value.toUpperCase(Locale.ENGLISH));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return KeepInvPolicy.KEEP;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeepInvPolicy getVanishingItemsPolicy() {
|
||||
return vanishingItemPolicy;
|
||||
}
|
||||
|
||||
private KeepInvPolicy bindingItemPolicy;
|
||||
|
||||
public KeepInvPolicy _getBindingItemsPolicy() {
|
||||
String value = config.getString("binding-items-policy", "keep").toLowerCase(Locale.ENGLISH);
|
||||
try {
|
||||
return KeepInvPolicy.valueOf(value.toUpperCase(Locale.ENGLISH));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return KeepInvPolicy.KEEP;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeepInvPolicy getBindingItemsPolicy() {
|
||||
return bindingItemPolicy;
|
||||
}
|
||||
|
||||
private Set<String> noGodWorlds = new HashSet<>();
|
||||
|
||||
@Override
|
||||
|
@ -459,6 +459,18 @@ broadcast-afk-message: true
|
||||
# You can disable the death messages of Minecraft here.
|
||||
death-messages: true
|
||||
|
||||
# How should essentials handle players with the essentials.keepinv permission who have items with
|
||||
# curse of vanishing when they die?
|
||||
# You can set this to "keep" (to keep the item), "drop" (to drop the item), or "delete" (to delete the item).
|
||||
# Defaults to "keep"
|
||||
vanishing-items-policy: keep
|
||||
|
||||
# How should essentials handle players with the essentials.keepinv permission who have items with
|
||||
# curse of binding when they die?
|
||||
# You can set this to "keep" (to keep the item), "drop" (to drop the item), or "delete" (to delete the item).
|
||||
# Defaults to "keep"
|
||||
binding-items-policy: keep
|
||||
|
||||
# When players die, should they receive the coordinates they died at?
|
||||
send-info-after-death: false
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user