mirror of
https://github.com/YouHaveTrouble/Enchantio.git
synced 2026-05-11 21:56:55 +00:00
add an option for telepathy config to only make items pick-upable by the player who broke the block
This commit is contained in:
@@ -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
|
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.
|
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
|
## Executioner
|
||||||
|
|
||||||
### maxDamageHpThreshold
|
### maxDamageHpThreshold
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<java.version>21</java.version>
|
<java.version>21</java.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<revision>1.12.0</revision>
|
<revision>1.13.0</revision>
|
||||||
</properties>
|
</properties>
|
||||||
<url>https://youhavetrouble.me</url>
|
<url>https://youhavetrouble.me</url>
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public class TelepathyEnchant implements EnchantioEnchant {
|
|||||||
private final Set<TagEntry<ItemType>> supportedItemTags = new HashSet<>();
|
private final Set<TagEntry<ItemType>> supportedItemTags = new HashSet<>();
|
||||||
private final Set<TagKey<Enchantment>> enchantTagKeys = new HashSet<>();
|
private final Set<TagKey<Enchantment>> enchantTagKeys = new HashSet<>();
|
||||||
private final Set<EquipmentSlotGroup> activeSlots = new HashSet<>();
|
private final Set<EquipmentSlotGroup> activeSlots = new HashSet<>();
|
||||||
|
private final boolean onlyUserCanPickupItems;
|
||||||
|
|
||||||
public TelepathyEnchant(
|
public TelepathyEnchant(
|
||||||
int anvilCost,
|
int anvilCost,
|
||||||
@@ -35,7 +36,8 @@ public class TelepathyEnchant implements EnchantioEnchant {
|
|||||||
EnchantmentRegistryEntry.EnchantmentCost maximumCost,
|
EnchantmentRegistryEntry.EnchantmentCost maximumCost,
|
||||||
Collection<TagKey<Enchantment>> enchantTagKeys,
|
Collection<TagKey<Enchantment>> enchantTagKeys,
|
||||||
Collection<TagEntry<ItemType>> supportedItemTags,
|
Collection<TagEntry<ItemType>> supportedItemTags,
|
||||||
Collection<EquipmentSlotGroup> activeSlots
|
Collection<EquipmentSlotGroup> activeSlots,
|
||||||
|
boolean onlyUserCanPickupItems
|
||||||
) {
|
) {
|
||||||
this.anvilCost = anvilCost;
|
this.anvilCost = anvilCost;
|
||||||
this.weight = weight;
|
this.weight = weight;
|
||||||
@@ -44,6 +46,7 @@ public class TelepathyEnchant implements EnchantioEnchant {
|
|||||||
this.supportedItemTags.addAll(supportedItemTags);
|
this.supportedItemTags.addAll(supportedItemTags);
|
||||||
this.activeSlots.addAll(activeSlots);
|
this.activeSlots.addAll(activeSlots);
|
||||||
this.enchantTagKeys.addAll(enchantTagKeys);
|
this.enchantTagKeys.addAll(enchantTagKeys);
|
||||||
|
this.onlyUserCanPickupItems = onlyUserCanPickupItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -96,6 +99,10 @@ public class TelepathyEnchant implements EnchantioEnchant {
|
|||||||
return Collections.unmodifiableSet(enchantTagKeys);
|
return Collections.unmodifiableSet(enchantTagKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isOnlyUserCanPickupItems() {
|
||||||
|
return onlyUserCanPickupItems;
|
||||||
|
}
|
||||||
|
|
||||||
public static TelepathyEnchant create(ConfigurationSection configurationSection) {
|
public static TelepathyEnchant create(ConfigurationSection configurationSection) {
|
||||||
TelepathyEnchant telepathyEnchant = new TelepathyEnchant(
|
TelepathyEnchant telepathyEnchant = new TelepathyEnchant(
|
||||||
EnchantioConfig.getInt(configurationSection, "anvilCost", 1),
|
EnchantioConfig.getInt(configurationSection, "anvilCost", 1),
|
||||||
@@ -126,7 +133,8 @@ public class TelepathyEnchant implements EnchantioEnchant {
|
|||||||
List.of(
|
List.of(
|
||||||
"MAINHAND"
|
"MAINHAND"
|
||||||
)
|
)
|
||||||
))
|
)),
|
||||||
|
EnchantioConfig.getBoolean(configurationSection, "onlyUserCanPickupItems", false)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (EnchantioConfig.getBoolean(configurationSection, "enabled", true)) {
|
if (EnchantioConfig.getBoolean(configurationSection, "enabled", true)) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package me.youhavetrouble.enchantio.listeners;
|
|||||||
import io.papermc.paper.registry.RegistryAccess;
|
import io.papermc.paper.registry.RegistryAccess;
|
||||||
import io.papermc.paper.registry.RegistryKey;
|
import io.papermc.paper.registry.RegistryKey;
|
||||||
|
|
||||||
|
import me.youhavetrouble.enchantio.EnchantioConfig;
|
||||||
import me.youhavetrouble.enchantio.enchants.TelepathyEnchant;
|
import me.youhavetrouble.enchantio.enchants.TelepathyEnchant;
|
||||||
import org.bukkit.Registry;
|
import org.bukkit.Registry;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
@@ -13,25 +14,25 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.block.BlockDropItemEvent;
|
import org.bukkit.event.block.BlockDropItemEvent;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class TelepathyListener implements Listener {
|
public class TelepathyListener implements Listener {
|
||||||
|
|
||||||
private final Registry<Enchantment> 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);
|
private final Enchantment telepathy = registry.get(TelepathyEnchant.KEY);
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
|
||||||
public void onTelepathyTool(BlockDropItemEvent event) {
|
public void onTelepathyTool(BlockDropItemEvent event) {
|
||||||
if (telepathy == null) return;
|
if (telepathy == null) return;
|
||||||
|
if (!(EnchantioConfig.ENCHANTS.get(TelepathyEnchant.KEY) instanceof TelepathyEnchant telepathyEnchant)) return;
|
||||||
ItemStack tool = event.getPlayer().getInventory().getItemInMainHand();
|
ItemStack tool = event.getPlayer().getInventory().getItemInMainHand();
|
||||||
if (!tool.containsEnchantment(telepathy)) return;
|
if (!tool.containsEnchantment(telepathy)) return;
|
||||||
|
|
||||||
for (Item item : event.getItems()) {
|
for (Item item : event.getItems()) {
|
||||||
item.teleport(event.getPlayer(), PlayerTeleportEvent.TeleportCause.PLUGIN);
|
item.teleport(event.getPlayer(), PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||||
item.setPickupDelay(0);
|
item.setPickupDelay(0);
|
||||||
|
if (!telepathyEnchant.isOnlyUserCanPickupItems()) continue;
|
||||||
|
item.setOwner(event.getPlayer().getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user