This commit is contained in:
BuildTools 2024-04-22 14:31:52 +05:00
parent 77414a8172
commit 5cfdf14198
22 changed files with 220 additions and 66 deletions

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>ExcellentEnchants</artifactId> <artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<version>4.0.3</version> <version>4.0.4</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>ExcellentEnchants</artifactId> <artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<version>4.0.3</version> <version>4.0.4</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -46,12 +46,6 @@
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.20.4-R0.1-SNAPSHOT</version> <version>1.20.4-R0.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>fr.neatmonster</groupId>
<artifactId>nocheatplus</artifactId>
<version>3.16.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>io.lumine</groupId> <groupId>io.lumine</groupId>
<artifactId>Mythic-Dist</artifactId> <artifactId>Mythic-Dist</artifactId>
@ -73,32 +67,32 @@
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>API</artifactId> <artifactId>API</artifactId>
<version>4.0.3</version> <version>4.0.4</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId> <artifactId>NMS</artifactId>
<version>4.0.3</version> <version>4.0.4</version>
</dependency>
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_19_R3</artifactId>
<version>4.0.3</version>
</dependency>
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_20_R1</artifactId>
<version>4.0.3</version>
</dependency>
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_20_R2</artifactId>
<version>4.0.3</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_20_R3</artifactId> <artifactId>V1_20_R3</artifactId>
<version>4.0.3</version> <version>4.0.4</version>
</dependency>
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_20_R2</artifactId>
<version>4.0.4</version>
</dependency>
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_20_R1</artifactId>
<version>4.0.4</version>
</dependency>
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_19_R3</artifactId>
<version>4.0.4</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -17,6 +17,7 @@ public class Placeholders extends su.nightexpress.nightcore.util.Placeholders {
public static final String GENERIC_ITEM = "%item%"; public static final String GENERIC_ITEM = "%item%";
public static final String GENERIC_LEVEL = "%level%"; public static final String GENERIC_LEVEL = "%level%";
public static final String GENERIC_AMOUNT = "%amount%"; public static final String GENERIC_AMOUNT = "%amount%";
public static final String GENERIC_MODIFIER = "%modifier%";
public static final String GENERIC_DESCRIPTION = "%description%"; public static final String GENERIC_DESCRIPTION = "%description%";
public static final String GENERIC_ENCHANT = "%enchant%"; public static final String GENERIC_ENCHANT = "%enchant%";
public static final String GENERIC_RADIUS = "%radius%"; public static final String GENERIC_RADIUS = "%radius%";

View File

@ -30,7 +30,7 @@ public class StoppingForceEnchant extends AbstractEnchantmentData implements Cha
public StoppingForceEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) { public StoppingForceEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) {
super(plugin, file); super(plugin, file);
this.setDescription(ENCHANTMENT_CHANCE + "% chance to resist knockback in combat by " + GENERIC_AMOUNT + "%."); this.setDescription(ENCHANTMENT_CHANCE + "% chance to get only " + GENERIC_AMOUNT + "% of knockback in combat.");
this.setMaxLevel(3); this.setMaxLevel(3);
this.setRarity(Rarity.UNCOMMON); this.setRarity(Rarity.UNCOMMON);
} }

View File

@ -1,13 +1,17 @@
package su.nightexpress.excellentenchants.enchantment.impl.fishing; package su.nightexpress.excellentenchants.enchantment.impl.fishing;
import org.bukkit.Material;
import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.EnchantsPlugin;
import su.nightexpress.excellentenchants.api.enchantment.Rarity; import su.nightexpress.excellentenchants.api.enchantment.Rarity;
import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant; import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant;
import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData; import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.config.FileConfig;
import java.io.File; import java.io.File;
@ -38,11 +42,17 @@ public class AutoReelEnchant extends AbstractEnchantmentData implements FishingE
public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) { public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) {
if (event.getState() != PlayerFishEvent.State.BITE) return false; if (event.getState() != PlayerFishEvent.State.BITE) return false;
Player player = event.getPlayer();
EquipmentSlot slot = EnchantUtils.getItemHand(player, Material.FISHING_ROD);
if (slot == null) return false;
int id = slot == EquipmentSlot.HAND ? 0 : 3;
this.plugin.runTask(task -> { this.plugin.runTask(task -> {
if (event.isCancelled()) return; if (event.isCancelled()) return;
plugin.getEnchantNMS().sendAttackPacket(event.getPlayer(), 0); plugin.getEnchantNMS().sendAttackPacket(event.getPlayer(), id);
plugin.getEnchantNMS().retrieveHook(event.getHook(), item); plugin.getEnchantNMS().retrieveHook(event.getHook(), item, slot);
}); });
return true; return true;
} }

View File

@ -24,6 +24,7 @@ import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl;
import su.nightexpress.excellentenchants.enchantment.data.PotionSettingsImpl; import su.nightexpress.excellentenchants.enchantment.data.PotionSettingsImpl;
import su.nightexpress.nightcore.config.FileConfig; import su.nightexpress.nightcore.config.FileConfig;
import su.nightexpress.nightcore.util.BukkitThing; import su.nightexpress.nightcore.util.BukkitThing;
import su.nightexpress.nightcore.util.Version;
import su.nightexpress.nightcore.util.random.Rnd; import su.nightexpress.nightcore.util.random.Rnd;
import su.nightexpress.nightcore.util.wrapper.UniParticle; import su.nightexpress.nightcore.util.wrapper.UniParticle;
@ -45,6 +46,15 @@ public class SurpriseEnchant extends AbstractEnchantmentData implements ChanceDa
this.setRarity(Rarity.RARE); this.setRarity(Rarity.RARE);
} }
@Override
public boolean checkServerRequirements() {
if (Version.isBehind(Version.V1_20_R2)) {
this.error("Enchantment is available for 1.20.2+ only.");
return false;
}
return true;
}
@Override @Override
protected void loadAdditional(@NotNull FileConfig config) { protected void loadAdditional(@NotNull FileConfig config) {
this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(3, 2, 1)); this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(3, 2, 1));

View File

@ -27,7 +27,7 @@ public class WisdomEnchant extends AbstractEnchantmentData implements DeathEncha
public WisdomEnchant(@NotNull EnchantsPlugin plugin, File file) { public WisdomEnchant(@NotNull EnchantsPlugin plugin, File file) {
super(plugin, file); super(plugin, file);
this.setDescription("Increases XP dropped from mobs by " + GENERIC_AMOUNT + "%."); this.setDescription("Mobs drops x" + GENERIC_MODIFIER + " more XP.");
this.setMaxLevel(5); this.setMaxLevel(5);
this.setRarity(Rarity.UNCOMMON); this.setRarity(Rarity.UNCOMMON);
} }
@ -39,6 +39,7 @@ public class WisdomEnchant extends AbstractEnchantmentData implements DeathEncha
"Exp modifier value. The original exp amount will be multiplied on this value."); "Exp modifier value. The original exp amount will be multiplied on this value.");
this.addPlaceholder(GENERIC_AMOUNT, level -> NumberUtil.format(this.getXPModifier(level) * 100D - 100D)); this.addPlaceholder(GENERIC_AMOUNT, level -> NumberUtil.format(this.getXPModifier(level) * 100D - 100D));
this.addPlaceholder(GENERIC_MODIFIER, level -> NumberUtil.format(this.getXPModifier(level)));
} }
public final double getXPModifier(int level) { public final double getXPModifier(int level) {
@ -53,10 +54,10 @@ public class WisdomEnchant extends AbstractEnchantmentData implements DeathEncha
@Override @Override
public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, ItemStack weapon, int level) { public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, ItemStack weapon, int level) {
double expModifier = this.getXPModifier(level); double xpModifier = this.getXPModifier(level);
double expFinal = Math.ceil((double) event.getDroppedExp() * expModifier); double xpFinal = Math.ceil((double) event.getDroppedExp() * xpModifier);
event.setDroppedExp((int) expFinal); event.setDroppedExp((int) xpFinal);
return true; return true;
} }

View File

@ -1,23 +1,23 @@
package su.nightexpress.excellentenchants.enchantment.listener; package su.nightexpress.excellentenchants.enchantment.listener;
import org.bukkit.entity.Item; import org.bukkit.block.Chest;
import org.bukkit.entity.Player; import org.bukkit.entity.*;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.enchantment.EnchantItemEvent; import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.*;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent; import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.world.LootGenerateEvent;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.MerchantRecipe;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.EnchantsPlugin;
import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData;
import su.nightexpress.excellentenchants.config.Config;
import su.nightexpress.excellentenchants.enchantment.EnchantManager; import su.nightexpress.excellentenchants.enchantment.EnchantManager;
import su.nightexpress.excellentenchants.enchantment.registry.EnchantRegistry; import su.nightexpress.excellentenchants.enchantment.registry.EnchantRegistry;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
@ -107,4 +107,33 @@ public class EnchantGenericListener extends AbstractListener<EnchantsPlugin> {
inventory.setItem(0, result); inventory.setItem(0, result);
}); });
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEnchantDisplayUpdateVillagerAcquire(VillagerAcquireTradeEvent event) {
if (Config.isCustomDistribution()) return;
MerchantRecipe origin = event.getRecipe();
ItemStack result = origin.getResult();
if (!EnchantUtils.isEnchantable(result)) return;
EnchantUtils.updateDisplay(result);
event.setRecipe(origin);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEnchantDisplayUpdateLoot(LootGenerateEvent event) {
if (Config.isCustomDistribution()) return;
Entity entity = event.getEntity();
InventoryHolder holder = event.getInventoryHolder();
if (entity instanceof Minecart || holder instanceof Chest) {
event.getLoot().forEach(item -> {
if (item != null && EnchantUtils.isEnchantable(item)) {
EnchantUtils.updateDisplay(item);
}
});
}
}
} }

View File

@ -1,5 +1,6 @@
package su.nightexpress.excellentenchants.enchantment.registry.wrapper; package su.nightexpress.excellentenchants.enchantment.registry.wrapper;
import org.bukkit.Material;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -18,7 +19,6 @@ import su.nightexpress.excellentenchants.api.enchantment.data.ArrowData;
import su.nightexpress.excellentenchants.api.enchantment.type.*; import su.nightexpress.excellentenchants.api.enchantment.type.*;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import su.nightexpress.excellentenchants.enchantment.util.EnchantedProjectile; import su.nightexpress.excellentenchants.enchantment.util.EnchantedProjectile;
import su.nightexpress.nightcore.util.Version;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -352,9 +352,7 @@ public class DataGathers {
@NotNull @NotNull
@Override @Override
public EquipmentSlot[] getEnchantSlots(@NotNull PlayerFishEvent event) { public EquipmentSlot[] getEnchantSlots(@NotNull PlayerFishEvent event) {
if (Version.isBehind(Version.V1_19_R3)) return new EquipmentSlot[] {EquipmentSlot.HAND}; return event.getHand() == null ? new EquipmentSlot[] {EnchantUtils.getItemHand(event.getPlayer(), Material.FISHING_ROD)} : new EquipmentSlot[]{event.getHand()};
return event.getHand() == null ? new EquipmentSlot[] {EquipmentSlot.HAND} : new EquipmentSlot[]{event.getHand()};
} }
@Override @Override

View File

@ -207,6 +207,18 @@ public class EnchantUtils {
return null; return null;
} }
@Nullable
public static EquipmentSlot getItemHand(@NotNull Player player, @NotNull Material material) {
for (EquipmentSlot slot : new EquipmentSlot[]{EquipmentSlot.HAND, EquipmentSlot.OFF_HAND}) {
ItemStack itemStack = player.getInventory().getItem(slot);
if (itemStack != null && itemStack.getType() == material) {
return slot;
}
}
return null;
}
@NotNull @NotNull
public static Map<Enchantment, Integer> getEnchantments(@NotNull ItemStack item) { public static Map<Enchantment, Integer> getEnchantments(@NotNull ItemStack item) {
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();

View File

@ -16,6 +16,7 @@ import org.jetbrains.annotations.Nullable;
import su.nightexpress.excellentenchants.EnchantsPlugin; import su.nightexpress.excellentenchants.EnchantsPlugin;
import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData; import su.nightexpress.excellentenchants.api.enchantment.EnchantmentData;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import su.nightexpress.nightcore.util.text.NightMessage;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -105,7 +106,7 @@ public class ProtocolHook {
} }
enchants.forEach((enchant, level) -> { enchants.forEach((enchant, level) -> {
int charges = enchant.getCharges(meta); int charges = enchant.getCharges(meta);
lore.add(0, enchant.getNameFormatted(level, charges)); lore.add(0, NightMessage.asLegacy(enchant.getNameFormatted(level, charges)));
}); });
meta.setLore(lore); meta.setLore(lore);

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>ExcellentEnchants</artifactId> <artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<version>4.0.3</version> <version>4.0.4</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -33,7 +33,7 @@
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>API</artifactId> <artifactId>API</artifactId>
<version>4.0.3</version> <version>4.0.4</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.FishHook;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -26,7 +27,7 @@ public interface EnchantNMS {
void sendAttackPacket(@NotNull Player player, int id); void sendAttackPacket(@NotNull Player player, int id);
void retrieveHook(@NotNull FishHook hook, @NotNull ItemStack item); void retrieveHook(@NotNull FishHook hook, @NotNull ItemStack item, @NotNull EquipmentSlot slot);
@NotNull Map<Integer, Map<Enchantment, Integer>> getEnchantLists(@NotNull Inventory inventory, @NotNull ItemStack bukkitItem); @NotNull Map<Integer, Map<Enchantment, Integer>> getEnchantLists(@NotNull Inventory inventory, @NotNull ItemStack bukkitItem);

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>ExcellentEnchants</artifactId> <artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<version>4.0.3</version> <version>4.0.4</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -27,7 +27,7 @@
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId> <artifactId>NMS</artifactId>
<version>4.0.3</version> <version>4.0.4</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -8,6 +8,7 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.Container; import net.minecraft.world.Container;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.item.ItemEntity;
@ -39,6 +40,7 @@ import org.bukkit.entity.FishHook;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -127,10 +129,23 @@ public class V1_19_R3 implements EnchantNMS {
} }
@Override @Override
public void retrieveHook(@NotNull FishHook hook, @NotNull ItemStack item) { public void retrieveHook(@NotNull FishHook hook, @NotNull ItemStack item, @NotNull EquipmentSlot slot) {
CraftFishHook craftFishHook = (CraftFishHook) hook; CraftFishHook craftFishHook = (CraftFishHook) hook;
FishingHook handle = craftFishHook.getHandle(); FishingHook handle = craftFishHook.getHandle();
handle.retrieve(CraftItemStack.asNMSCopy(item));
net.minecraft.world.entity.player.Player owner = handle.getPlayerOwner();
if (owner == null) return;
int result = handle.retrieve(CraftItemStack.asNMSCopy(item));
net.minecraft.world.entity.EquipmentSlot hand = slot == EquipmentSlot.HAND ? net.minecraft.world.entity.EquipmentSlot.MAINHAND : net.minecraft.world.entity.EquipmentSlot.OFFHAND;
net.minecraft.world.item.ItemStack itemStack = owner.getItemBySlot(hand);
if (itemStack == null) return;
itemStack.hurtAndBreak(result, handle.getPlayerOwner(), player -> {
player.broadcastBreakEvent(hand);
});
} }
@NotNull @NotNull

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>ExcellentEnchants</artifactId> <artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<version>4.0.3</version> <version>4.0.4</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -27,7 +27,7 @@
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId> <artifactId>NMS</artifactId>
<version>4.0.3</version> <version>4.0.4</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -9,6 +9,7 @@ import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.Container; import net.minecraft.world.Container;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.item.ItemEntity;
@ -40,6 +41,7 @@ import org.bukkit.entity.FishHook;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -128,10 +130,23 @@ public class V1_20_R1 implements EnchantNMS {
} }
@Override @Override
public void retrieveHook(@NotNull FishHook hook, @NotNull ItemStack item) { public void retrieveHook(@NotNull FishHook hook, @NotNull ItemStack item, @NotNull EquipmentSlot slot) {
CraftFishHook craftFishHook = (CraftFishHook) hook; CraftFishHook craftFishHook = (CraftFishHook) hook;
FishingHook handle = craftFishHook.getHandle(); FishingHook handle = craftFishHook.getHandle();
handle.retrieve(CraftItemStack.asNMSCopy(item));
net.minecraft.world.entity.player.Player owner = handle.getPlayerOwner();
if (owner == null) return;
int result = handle.retrieve(CraftItemStack.asNMSCopy(item));
net.minecraft.world.entity.EquipmentSlot hand = slot == EquipmentSlot.HAND ? net.minecraft.world.entity.EquipmentSlot.MAINHAND : net.minecraft.world.entity.EquipmentSlot.OFFHAND;
net.minecraft.world.item.ItemStack itemStack = owner.getItemBySlot(hand);
if (itemStack == null) return;
itemStack.hurtAndBreak(result, handle.getPlayerOwner(), player -> {
player.broadcastBreakEvent(hand);
});
} }
@NotNull @NotNull

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>ExcellentEnchants</artifactId> <artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<version>4.0.3</version> <version>4.0.4</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -27,7 +27,7 @@
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId> <artifactId>NMS</artifactId>
<version>4.0.3</version> <version>4.0.4</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -9,6 +9,7 @@ import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.Container; import net.minecraft.world.Container;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.item.ItemEntity;
@ -40,6 +41,7 @@ import org.bukkit.entity.FishHook;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -127,10 +129,23 @@ public class V1_20_R2 implements EnchantNMS {
} }
@Override @Override
public void retrieveHook(@NotNull FishHook hook, @NotNull ItemStack item) { public void retrieveHook(@NotNull FishHook hook, @NotNull ItemStack item, @NotNull EquipmentSlot slot) {
CraftFishHook craftFishHook = (CraftFishHook) hook; CraftFishHook craftFishHook = (CraftFishHook) hook;
FishingHook handle = craftFishHook.getHandle(); FishingHook handle = craftFishHook.getHandle();
handle.retrieve(CraftItemStack.asNMSCopy(item));
net.minecraft.world.entity.player.Player owner = handle.getPlayerOwner();
if (owner == null) return;
int result = handle.retrieve(CraftItemStack.asNMSCopy(item));
net.minecraft.world.entity.EquipmentSlot hand = slot == EquipmentSlot.HAND ? net.minecraft.world.entity.EquipmentSlot.MAINHAND : net.minecraft.world.entity.EquipmentSlot.OFFHAND;
net.minecraft.world.item.ItemStack itemStack = owner.getItemBySlot(hand);
if (itemStack == null) return;
itemStack.hurtAndBreak(result, handle.getPlayerOwner(), player -> {
player.broadcastBreakEvent(hand);
});
} }
@NotNull @NotNull

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>ExcellentEnchants</artifactId> <artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<version>4.0.3</version> <version>4.0.4</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -27,12 +27,12 @@
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>API</artifactId> <artifactId>API</artifactId>
<version>4.0.3</version> <version>4.0.4</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId> <artifactId>NMS</artifactId>
<version>4.0.3</version> <version>4.0.4</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -40,6 +40,7 @@ import org.bukkit.entity.FishHook;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -120,13 +121,64 @@ public class V1_20_R3 implements EnchantNMS {
ServerPlayer entity = craftPlayer.getHandle(); ServerPlayer entity = craftPlayer.getHandle();
ClientboundAnimatePacket packet = new ClientboundAnimatePacket(entity, id); ClientboundAnimatePacket packet = new ClientboundAnimatePacket(entity, id);
craftPlayer.getHandle().connection.send(packet); craftPlayer.getHandle().connection.send(packet);
player.spigot().sendMessage();
}
/*public ItemStack setItemLore(@NotNull ItemStack item, @NotNull List<String> lore) {
lore.add("<translate>enchantment.level.5</translate>");
CraftItemStack craftItem = ensureCraftItemStack(item);
net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(craftItem);
CompoundTag tag = nmsItem.getTag() == null ? new CompoundTag() : nmsItem.getTag();
if (!tag.contains(net.minecraft.world.item.ItemStack.TAG_DISPLAY)) {
tag.put(net.minecraft.world.item.ItemStack.TAG_DISPLAY, new CompoundTag());
}
CompoundTag displayTag = tag.getCompound(net.minecraft.world.item.ItemStack.TAG_DISPLAY);
ListTag loreTag = new ListTag();
for (int index = 0; index < lore.size(); index++) {
String text = lore.get(index);
System.out.println("text = " + text);
String json = ComponentSerializer.toString(NightMessage.create(text).parseIfAbsent());
System.out.println("json = " + json);
Component component = CraftChatMessage.fromJSON(json);
System.out.println("component = " + component);
String fromComponent = CraftChatMessage.toJSON(component);
System.out.println("fromComponent = " + fromComponent);
loreTag.add(index, StringTag.valueOf(fromComponent));
}
displayTag.put(net.minecraft.world.item.ItemStack.TAG_LORE, loreTag);
return CraftItemStack.asBukkitCopy(nmsItem);
}*/
private CraftItemStack ensureCraftItemStack(ItemStack item) {
return item instanceof CraftItemStack craftItem ? craftItem : CraftItemStack.asCraftCopy(item);
} }
@Override @Override
public void retrieveHook(@NotNull FishHook hook, @NotNull ItemStack item) { public void retrieveHook(@NotNull FishHook hook, @NotNull ItemStack item, @NotNull EquipmentSlot slot) {
CraftFishHook craftFishHook = (CraftFishHook) hook; CraftFishHook craftFishHook = (CraftFishHook) hook;
FishingHook handle = craftFishHook.getHandle(); FishingHook handle = craftFishHook.getHandle();
handle.retrieve(CraftItemStack.asNMSCopy(item));
net.minecraft.world.entity.player.Player owner = handle.getPlayerOwner();
if (owner == null) return;
int result = handle.retrieve(CraftItemStack.asNMSCopy(item));
net.minecraft.world.entity.EquipmentSlot hand = slot == EquipmentSlot.HAND ? net.minecraft.world.entity.EquipmentSlot.MAINHAND : net.minecraft.world.entity.EquipmentSlot.OFFHAND;
net.minecraft.world.item.ItemStack itemStack = owner.getItemBySlot(hand);
if (itemStack == null) return;
itemStack.hurtAndBreak(result, handle.getPlayerOwner(), player -> {
player.broadcastBreakEvent(hand);
});
} }
/*@Override /*@Override

View File

@ -7,7 +7,7 @@
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>ExcellentEnchants</artifactId> <artifactId>ExcellentEnchants</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>
<version>4.0.3</version> <version>4.0.4</version>
<modules> <modules>
<module>Core</module> <module>Core</module>
<module>NMS</module> <module>NMS</module>