diff --git a/docs/src/content/docs/configuration/reference.md b/docs/src/content/docs/configuration/reference.md index 73e250f..d4cb756 100644 --- a/docs/src/content/docs/configuration/reference.md +++ b/docs/src/content/docs/configuration/reference.md @@ -94,6 +94,12 @@ Maximum level of the enchantment. If set to 1, the enchantment will be a single in the configuration section for specific enchantment, it means it's locked to a single level enchantment, because logic of the enchantment does not support multiple levels. +## Telepathy + +- **Type**: `boolean` + +If set to true, items teleported by the enchant will only be able to be picked up by the player that broke the block. + ## Executioner ### maxDamageHpThreshold diff --git a/pom.xml b/pom.xml index 64eb400..563ae08 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ 21 UTF-8 - 1.12.0 + 1.13.0 https://youhavetrouble.me diff --git a/src/main/java/me/youhavetrouble/enchantio/enchants/TelepathyEnchant.java b/src/main/java/me/youhavetrouble/enchantio/enchants/TelepathyEnchant.java index e02cb2d..6c19ec7 100644 --- a/src/main/java/me/youhavetrouble/enchantio/enchants/TelepathyEnchant.java +++ b/src/main/java/me/youhavetrouble/enchantio/enchants/TelepathyEnchant.java @@ -27,6 +27,7 @@ public class TelepathyEnchant implements EnchantioEnchant { private final Set> supportedItemTags = new HashSet<>(); private final Set> enchantTagKeys = new HashSet<>(); private final Set activeSlots = new HashSet<>(); + private final boolean onlyUserCanPickupItems; public TelepathyEnchant( int anvilCost, @@ -35,7 +36,8 @@ public class TelepathyEnchant implements EnchantioEnchant { EnchantmentRegistryEntry.EnchantmentCost maximumCost, Collection> enchantTagKeys, Collection> supportedItemTags, - Collection activeSlots + Collection activeSlots, + boolean onlyUserCanPickupItems ) { this.anvilCost = anvilCost; this.weight = weight; @@ -44,6 +46,7 @@ public class TelepathyEnchant implements EnchantioEnchant { this.supportedItemTags.addAll(supportedItemTags); this.activeSlots.addAll(activeSlots); this.enchantTagKeys.addAll(enchantTagKeys); + this.onlyUserCanPickupItems = onlyUserCanPickupItems; } @Override @@ -96,6 +99,10 @@ public class TelepathyEnchant implements EnchantioEnchant { return Collections.unmodifiableSet(enchantTagKeys); } + public boolean isOnlyUserCanPickupItems() { + return onlyUserCanPickupItems; + } + public static TelepathyEnchant create(ConfigurationSection configurationSection) { TelepathyEnchant telepathyEnchant = new TelepathyEnchant( EnchantioConfig.getInt(configurationSection, "anvilCost", 1), @@ -126,7 +133,8 @@ public class TelepathyEnchant implements EnchantioEnchant { List.of( "MAINHAND" ) - )) + )), + EnchantioConfig.getBoolean(configurationSection, "onlyUserCanPickupItems", false) ); if (EnchantioConfig.getBoolean(configurationSection, "enabled", true)) { diff --git a/src/main/java/me/youhavetrouble/enchantio/listeners/TelepathyListener.java b/src/main/java/me/youhavetrouble/enchantio/listeners/TelepathyListener.java index 04fcb62..83bbfd6 100644 --- a/src/main/java/me/youhavetrouble/enchantio/listeners/TelepathyListener.java +++ b/src/main/java/me/youhavetrouble/enchantio/listeners/TelepathyListener.java @@ -3,6 +3,7 @@ package me.youhavetrouble.enchantio.listeners; import io.papermc.paper.registry.RegistryAccess; import io.papermc.paper.registry.RegistryKey; +import me.youhavetrouble.enchantio.EnchantioConfig; import me.youhavetrouble.enchantio.enchants.TelepathyEnchant; import org.bukkit.Registry; import org.bukkit.enchantments.Enchantment; @@ -13,25 +14,25 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.BlockDropItemEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.inventory.ItemStack; - +import org.jetbrains.annotations.NotNull; public class TelepathyListener implements Listener { - private final Registry registry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT); + private final Registry<@NotNull Enchantment> registry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT); private final Enchantment telepathy = registry.get(TelepathyEnchant.KEY); @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL) public void onTelepathyTool(BlockDropItemEvent event) { if (telepathy == null) return; - + if (!(EnchantioConfig.ENCHANTS.get(TelepathyEnchant.KEY) instanceof TelepathyEnchant telepathyEnchant)) return; ItemStack tool = event.getPlayer().getInventory().getItemInMainHand(); if (!tool.containsEnchantment(telepathy)) return; - for (Item item : event.getItems()) { item.teleport(event.getPlayer(), PlayerTeleportEvent.TeleportCause.PLUGIN); item.setPickupDelay(0); + if (!telepathyEnchant.isOnlyUserCanPickupItems()) continue; + item.setOwner(event.getPlayer().getUniqueId()); } - } }