This commit is contained in:
nulli0n 2023-05-16 01:53:13 +06:00
parent ce07be4c8f
commit 15f367c22f
33 changed files with 513 additions and 63 deletions

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId>
<version>3.3.4</version>
<version>3.4.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -72,32 +72,32 @@
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId>
<version>3.3.4</version>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_19_R3</artifactId>
<version>3.3.4</version>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_19_R2</artifactId>
<version>3.3.4</version>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_19_R1</artifactId>
<version>3.3.4</version>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_18_R2</artifactId>
<version>3.3.4</version>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_17_R1</artifactId>
<version>3.3.4</version>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>fr.neatmonster</groupId>

View File

@ -29,9 +29,9 @@ import su.nightexpress.excellentenchants.tier.TierManager;
public class ExcellentEnchants extends NexPlugin<ExcellentEnchants> {
private EnchantRegistry enchantRegistry;
private EnchantManager enchantManager;
private EnchantNMS enchantNMS;
private TierManager tierManager;
private EnchantManager enchantManager;
private EnchantNMS enchantNMS;
private TierManager tierManager;
@Override
@NotNull

View File

@ -10,7 +10,7 @@ import su.nightexpress.excellentenchants.config.Config;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.armor.*;
import su.nightexpress.excellentenchants.enchantment.impl.bow.*;
import su.nightexpress.excellentenchants.enchantment.impl.fishing.AutoFishEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.fishing.*;
import su.nightexpress.excellentenchants.enchantment.impl.tool.*;
import su.nightexpress.excellentenchants.enchantment.impl.universal.EnchantCurseOfFragility;
import su.nightexpress.excellentenchants.enchantment.impl.weapon.*;
@ -35,14 +35,22 @@ public class EnchantRegistry {
public void setup() {
// Prevent to register enchantments during the runtime.
if (this.isLocked) {
REGISTRY_MAP.values().forEach(ExcellentEnchant::loadSettings);
REGISTRY_MAP.values().forEach(enchant -> {
enchant.loadSettings();
enchant.registerListeners();
});
return;
}
Reflex.setFieldValue(Enchantment.class, "acceptingNew", true);
// Fising Enchants
this.register(AutoFishEnchant.ID,() -> new AutoFishEnchant(plugin));
this.register(AutoReelEnchant.ID,() -> new AutoReelEnchant(plugin));
this.register(DoubleCatchEnchant.ID, () -> new DoubleCatchEnchant(plugin));
this.register(SeasonedAnglerEnchant.ID, () -> new SeasonedAnglerEnchant(plugin));
this.register(SurvivalistEnchant.ID, () -> new SurvivalistEnchant(plugin));
this.register(CurseOfDrownedEnchant.ID, () -> new CurseOfDrownedEnchant(plugin));
this.register(RiverMasterEnchant.ID, () -> new RiverMasterEnchant(plugin));
// Tool enchants
this.register(EnchantBlastMining.ID, () -> new EnchantBlastMining(plugin));

View File

@ -97,6 +97,9 @@ public abstract class ExcellentEnchant extends Enchantment implements IEnchantme
@NotNull
public PlaceholderMap getPlaceholders(int level) {
if (level > this.getMaxLevel()) level = this.getMaxLevel();
if (level < this.getStartLevel()) level = this.getStartLevel();
return this.placeholdersMap.get(level);
}

View File

@ -20,6 +20,7 @@ import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.manager.ICleanable;
import su.nexmedia.engine.api.particle.SimpleParticle;
import su.nexmedia.engine.api.server.AbstractTask;
import su.nexmedia.engine.utils.Pair;
import su.nexmedia.engine.utils.random.Rnd;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
@ -29,6 +30,7 @@ import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
public class EnchantFlameWalker extends ExcellentEnchant implements ICleanable {
@ -36,7 +38,7 @@ public class EnchantFlameWalker extends ExcellentEnchant implements ICleanable {
public static final String ID = "flame_walker";
private static final BlockFace[] FACES = {BlockFace.SOUTH, BlockFace.NORTH, BlockFace.EAST, BlockFace.WEST};
private static final Map<Block, Long> BLOCKS_TO_DESTROY = new ConcurrentHashMap<>();
private static final Map<Block, Pair<Long, Integer>> BLOCKS_TO_DESTROY = new ConcurrentHashMap<>();
private EnchantScaler blockDecayTime;
private BlockTickTask blockTickTask;
@ -70,7 +72,7 @@ public class EnchantFlameWalker extends ExcellentEnchant implements ICleanable {
}
public static void addBlock(@NotNull Block block, double seconds) {
BLOCKS_TO_DESTROY.put(block, (long) (System.currentTimeMillis() + seconds * 1000L));
BLOCKS_TO_DESTROY.put(block, Pair.of(System.currentTimeMillis() + (long) seconds * 1000L, Rnd.get(100)));
}
@Override
@ -148,13 +150,32 @@ public class EnchantFlameWalker extends ExcellentEnchant implements ICleanable {
BLOCKS_TO_DESTROY.keySet().removeIf(block -> {
if (block.isEmpty()) return true;
long time = BLOCKS_TO_DESTROY.get(block);
Pair<Long, Integer> pair = BLOCKS_TO_DESTROY.get(block);
long time = pair.getFirst();
if (now >= time) {
block.getWorld().getPlayers().forEach(player -> {
player.sendBlockDamage(block.getLocation(), 0F, pair.getSecond());
});
block.setType(Material.LAVA);
SimpleParticle.of(Particle.BLOCK_CRACK, Material.MAGMA_BLOCK)
SimpleParticle.of(Particle.BLOCK_CRACK, Material.MAGMA_BLOCK.createBlockData())
.play(block.getLocation(), 0.5, 0.7, 0.5, 0.03, 30);
return true;
}
else {
long diff = TimeUnit.MILLISECONDS.toSeconds(time - now);
float progress = (float) (1D - Math.min(1D, diff / 5D));
if (progress > 1F) progress = 1F;
if (progress < 0F) progress = 0F;
float finalProgress = progress;
block.getWorld().getPlayers().forEach(player -> {
player.sendBlockDamage(block.getLocation(), finalProgress, pair.getSecond());
});
}
return false;
});
}

View File

@ -74,7 +74,7 @@ public class EnchantIceShield extends ExcellentEnchant implements Chanced, Potio
damager.setFreezeTicks(damager.getMaxFreezeTicks());
if (this.hasVisualEffects()) {
SimpleParticle.of(Particle.BLOCK_CRACK, Material.ICE)
SimpleParticle.of(Particle.BLOCK_CRACK, Material.ICE.createBlockData())
.play(damager.getEyeLocation(), 0.25, 0.1, 20);
}
return true;

View File

@ -92,7 +92,7 @@ public class EnchantElectrifiedArrows extends ExcellentEnchant implements Chance
block.getWorld().strikeLightning(block.getLocation()).setMetadata(META_NO_ITEM_DAMAGE, new FixedMetadataValue(plugin, true));
if (this.hasVisualEffects()) {
Location center = LocationUtil.getCenter(block.getLocation());
SimpleParticle.of(Particle.BLOCK_CRACK, block.getType()).play(center, 1, 0.05, 120);
SimpleParticle.of(Particle.BLOCK_CRACK, block.getType().createBlockData()).play(center, 1, 0.05, 120);
SimpleParticle.of(Particle.FIREWORKS_SPARK).play(center, 1, 0.05, 120);
}
return true;

View File

@ -9,11 +9,11 @@ import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class AutoFishEnchant extends ExcellentEnchant implements FishingEnchant {
public class AutoReelEnchant extends ExcellentEnchant implements FishingEnchant {
public static final String ID = "auto_fish";
public static final String ID = "auto_reel";
public AutoFishEnchant(@NotNull ExcellentEnchants plugin) {
public AutoReelEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
this.getDefaults().setDescription("Automatically reels in a hook on bite.");
this.getDefaults().setLevelMax(1);
@ -29,6 +29,7 @@ public class AutoFishEnchant extends ExcellentEnchant implements FishingEnchant
@Override
public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) {
if (event.getState() != PlayerFishEvent.State.BITE) return false;
if (!this.isAvailableToUse(event.getPlayer())) return false;
this.plugin.runTask(task -> {
if (event.isCancelled()) return;

View File

@ -0,0 +1,72 @@
package su.nightexpress.excellentenchants.enchantment.impl.fishing;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.Drowned;
import org.bukkit.entity.FishHook;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.particle.SimpleParticle;
import su.nexmedia.engine.utils.MessageUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class CurseOfDrownedEnchant extends ExcellentEnchant implements FishingEnchant, Chanced {
public static final String ID = "curse_of_drowned";
private ChanceImplementation chanceImplementation;
public CurseOfDrownedEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.HIGHEST);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to fish up a Drowned Zombie.");
this.getDefaults().setLevelMax(5);
this.getDefaults().setTier(0D);
}
@Override
public void loadSettings() {
super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this,
"5.0 + " + Placeholders.ENCHANTMENT_LEVEL);
}
@NotNull
@Override
public ChanceImplementation getChanceImplementation() {
return chanceImplementation;
}
@NotNull
@Override
public EnchantmentTarget getItemTarget() {
return EnchantmentTarget.FISHING_ROD;
}
@Override
public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) {
if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) return false;
if (!this.isAvailableToUse(event.getPlayer())) return false;
if (!this.checkTriggerChance(level)) return false;
FishHook hook = event.getHook();
Drowned drowned = hook.getWorld().spawn(hook.getLocation(), Drowned.class);
hook.setHookedEntity(drowned);
hook.pullHookedEntity();
event.setCancelled(true);
if (this.hasVisualEffects()) {
SimpleParticle.of(Particle.WATER_SPLASH).play(hook.getLocation(), 0.5, 0.1, 50);
MessageUtil.sound(event.getPlayer(), Sound.ENTITY_DROWNED_AMBIENT);
}
return true;
}
}

View File

@ -0,0 +1,61 @@
package su.nightexpress.excellentenchants.enchantment.impl.fishing;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.Item;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class DoubleCatchEnchant extends ExcellentEnchant implements FishingEnchant, Chanced {
public static final String ID = "double_catch";
private ChanceImplementation chanceImplementation;
public DoubleCatchEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.LOWEST);
this.getDefaults().setDescription("Increases amount of caught item by x2 with " + Placeholders.ENCHANTMENT_CHANCE + "% chance.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.5);
}
@Override
public void loadSettings() {
super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this,
"10.0 * " + Placeholders.ENCHANTMENT_LEVEL);
}
@NotNull
@Override
public EnchantmentTarget getItemTarget() {
return EnchantmentTarget.FISHING_ROD;
}
@Override
@NotNull
public ChanceImplementation getChanceImplementation() {
return this.chanceImplementation;
}
@Override
public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) {
if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) return false;
if (!(event.getCaught() instanceof Item drop)) return false;
if (!this.isAvailableToUse(event.getPlayer())) return false;
if (!this.checkTriggerChance(level)) return false;
ItemStack stack = drop.getItemStack();
stack.setAmount(Math.min(stack.getMaxStackSize(), stack.getAmount() * 2));
drop.setItemStack(stack);
return true;
}
}

View File

@ -0,0 +1,68 @@
package su.nightexpress.excellentenchants.enchantment.impl.fishing;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
public class RiverMasterEnchant extends ExcellentEnchant {
public static final String ID = "river_master";
private EnchantScaler distanceMod;
public RiverMasterEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
this.getDefaults().setDescription("Increases casting distance.");
this.getDefaults().setLevelMax(5);
this.getDefaults().setTier(0.1);
}
@Override
public void loadSettings() {
super.loadSettings();
this.distanceMod = EnchantScaler.read(this, "Settings.Distance_Modifier",
"1.25 + " + Placeholders.ENCHANTMENT_LEVEL + " / 5",
"Multiplies the casted fish hook's velocity by specified value.",
"Setting too high values will result in hook auto removal by vanilla game/server mechanics.");
}
@NotNull
@Override
public EnchantmentTarget getItemTarget() {
return EnchantmentTarget.FISHING_ROD;
}
public double getDistanceMod(int level) {
return this.distanceMod.getValue(level);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onHookLaunch(ProjectileLaunchEvent event) {
if (!(event.getEntity() instanceof FishHook hook)) return;
if (!(hook.getShooter() instanceof Player player)) return;
if (!this.isAvailableToUse(player)) return;
ItemStack rod = EnchantUtils.getFishingRod(player);
if (rod == null) return;
int level = EnchantUtils.getLevel(rod, this);
if (level < 1) return;
if (this.isOutOfCharges(rod)) return;
hook.setVelocity(hook.getVelocity().multiply(this.getDistanceMod(level)));
this.consumeCharges(rod);
}
}

View File

@ -0,0 +1,61 @@
package su.nightexpress.excellentenchants.enchantment.impl.fishing;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class SeasonedAnglerEnchant extends ExcellentEnchant implements FishingEnchant {
public static final String ID = "seasoned_angler";
private EnchantScaler expMod;
public SeasonedAnglerEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
this.getDefaults().setDescription("Increases amount of XP gained from fishing by " + Placeholders.GENERIC_AMOUNT + "%.");
this.getDefaults().setLevelMax(4);
this.getDefaults().setTier(0.1);
}
@Override
public void loadSettings() {
super.loadSettings();
this.expMod = EnchantScaler.read(this, "Settings.Exp_Percent",
"25.0 * " + Placeholders.ENCHANTMENT_LEVEL,
"Amount (in percent) of additional XP from fishing.");
this.addPlaceholder(Placeholders.GENERIC_AMOUNT, level -> NumberUtil.format(this.getExpPercent(level)));
}
public int getExpPercent(int level) {
return (int) this.expMod.getValue(level);
}
@NotNull
@Override
public EnchantmentTarget getItemTarget() {
return EnchantmentTarget.FISHING_ROD;
}
@Override
public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) {
if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) return false;
if (!this.isAvailableToUse(event.getPlayer())) return false;
if (event.getExpToDrop() == 0) return false;
int expDrop = event.getExpToDrop();
int expPercent = this.getExpPercent(level);
int expModified = (int) Math.ceil(expDrop * (1D + expPercent / 100D));
event.setExpToDrop(expModified);
return true;
}
}

View File

@ -0,0 +1,78 @@
package su.nightexpress.excellentenchants.enchantment.impl.fishing;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.Item;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.inventory.CookingRecipe;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import java.util.HashSet;
import java.util.Set;
public class SurvivalistEnchant extends ExcellentEnchant implements FishingEnchant, Chanced {
public static final String ID = "survivalist";
private final Set<CookingRecipe<?>> cookingRecipes;
private ChanceImplementation chanceImplementation;
public SurvivalistEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.HIGH);
this.getDefaults().setDescription("Automatically cooks fish if what is caught is raw.");
this.getDefaults().setLevelMax(1);
this.getDefaults().setTier(0.4);
this.cookingRecipes = new HashSet<>();
}
@Override
public void loadSettings() {
super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, "100");
this.cookingRecipes.clear();
this.plugin.getServer().recipeIterator().forEachRemaining(recipe -> {
if (recipe instanceof CookingRecipe<?> cookingRecipe) {
this.cookingRecipes.add(cookingRecipe);
}
});
}
@NotNull
@Override
public ChanceImplementation getChanceImplementation() {
return chanceImplementation;
}
@NotNull
@Override
public EnchantmentTarget getItemTarget() {
return EnchantmentTarget.FISHING_ROD;
}
@Override
public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) {
if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) return false;
if (!this.isAvailableToUse(event.getPlayer())) return false;
if (!this.checkTriggerChance(level)) return false;
if (!(event.getCaught() instanceof Item drop)) return false;
ItemStack stack = drop.getItemStack();
CookingRecipe<?> recipe = this.cookingRecipes.stream().filter(r -> r.getInput().isSimilar(stack)).findFirst().orElse(null);
if (recipe == null) return false;
ItemStack cooked = recipe.getResult();
cooked.setAmount(stack.getAmount());
drop.setItemStack(cooked);
return false;
}
}

View File

@ -13,7 +13,7 @@ import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
public final class PotionImplementation implements Potioned {
//private final ExcellentEnchant enchant;
private final ExcellentEnchant enchant;
private final PotionEffectType effectType;
private final Scaler duration;
private final Scaler amplifier;
@ -22,7 +22,7 @@ public final class PotionImplementation implements Potioned {
private PotionImplementation(@NotNull ExcellentEnchant enchant,
@NotNull PotionEffectType effectType, boolean isPermanent,
@NotNull EnchantScaler duration, @NotNull EnchantScaler amplifier) {
//this.enchant = enchant;
this.enchant = enchant;
this.effectType = effectType;
this.duration = duration;
this.amplifier = amplifier;
@ -82,7 +82,7 @@ public final class PotionImplementation implements Potioned {
int duration = this.getEffectDuration(level);
int amplifier = Math.max(0, this.getEffectAmplifier(level) - 1);
return new PotionEffect(this.getEffectType(), duration, amplifier, false, false);
return new PotionEffect(this.getEffectType(), duration, amplifier, false, this.enchant.hasVisualEffects());
}
public boolean addEffect(@NotNull LivingEntity target, int level) {

View File

@ -233,7 +233,7 @@ public class EnchantDecapitator extends ExcellentEnchant implements Chanced, Dea
entity.getWorld().dropItemNaturally(entity.getLocation(), item);
if (this.hasVisualEffects()) {
SimpleParticle.of(Particle.BLOCK_CRACK, Material.REDSTONE_BLOCK).play(entity.getEyeLocation(), 0.25, 0.15, 30);
SimpleParticle.of(Particle.BLOCK_CRACK, Material.REDSTONE_BLOCK.createBlockData()).play(entity.getEyeLocation(), 0.25, 0.15, 30);
}
return true;
}

View File

@ -69,7 +69,7 @@ public class EnchantIceAspect extends ExcellentEnchant implements Chanced, Potio
victim.setFreezeTicks(victim.getMaxFreezeTicks());
if (this.hasVisualEffects()) {
SimpleParticle.of(Particle.BLOCK_CRACK, Material.ICE).play(victim.getEyeLocation(), 0.25, 0.15, 30);
SimpleParticle.of(Particle.BLOCK_CRACK, Material.ICE.createBlockData()).play(victim.getEyeLocation(), 0.25, 0.15, 30);
}
return true;
}

View File

@ -1,6 +1,5 @@
package su.nightexpress.excellentenchants.enchantment.impl.weapon;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.EntityType;
@ -89,16 +88,10 @@ public class EnchantThrifty extends ExcellentEnchant implements Chanced, DeathEn
if (PDCUtil.getBoolean(entity, this.keyEntityIgnored).orElse(false)) return false;
if (!this.checkTriggerChance(level)) return false;
Material material = Material.getMaterial(entity.getType().name() + "_SPAWN_EGG");
if (material == null) {
if (entity.getType() == EntityType.MUSHROOM_COW) {
material = Material.MOOSHROOM_SPAWN_EGG;
}
else return false;
}
ItemStack eggItem = plugin.getEnchantNMS().getSpawnEgg(entity);
if (eggItem == null) return false;
ItemStack egg = new ItemStack(material);
e.getDrops().add(egg);
e.getDrops().add(eggItem);
return true;
}

View File

@ -144,8 +144,11 @@ public class EnchantGenericListener extends AbstractListener<ExcellentEnchants>
boolean expReward = recipe.hasExperienceReward();
int villagerExperience = recipe.getVillagerExperience();
float priceMultiplier = recipe.getPriceMultiplier();
int demand = recipe.getDemand();
int specialPrice = recipe.getSpecialPrice();
MerchantRecipe recipe2 = new MerchantRecipe(result, uses, maxUses, expReward, villagerExperience, priceMultiplier);
MerchantRecipe recipe2 = new MerchantRecipe(result, uses, maxUses, expReward, villagerExperience,
priceMultiplier, demand, specialPrice);
recipe2.setIngredients(recipe.getIngredients());
e.setRecipe(recipe2);
}

View File

@ -18,7 +18,6 @@ import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.jetbrains.annotations.NotNull;
@ -26,10 +25,10 @@ import org.jetbrains.annotations.Nullable;
import su.nexmedia.engine.api.manager.AbstractListener;
import su.nexmedia.engine.utils.EntityUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.enchantment.util.EnchantDropContainer;
import su.nightexpress.excellentenchants.api.enchantment.type.*;
import su.nightexpress.excellentenchants.api.enchantment.meta.Arrowed;
import su.nightexpress.excellentenchants.api.enchantment.type.*;
import su.nightexpress.excellentenchants.enchantment.EnchantManager;
import su.nightexpress.excellentenchants.enchantment.util.EnchantDropContainer;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
public class EnchantHandlerListener extends AbstractListener<ExcellentEnchants> {
@ -211,14 +210,11 @@ public class EnchantHandlerListener extends AbstractListener<ExcellentEnchants>
public void onEnchantFishing(PlayerFishEvent event) {
Player player = event.getPlayer();
ItemStack item;
ItemStack main = player.getInventory().getItem(EquipmentSlot.HAND);
ItemStack off = player.getInventory().getItem(EquipmentSlot.OFF_HAND);
if (main != null && main.getType() == Material.FISHING_ROD) item = main;
else if (off != null && off.getType() == Material.FISHING_ROD) item = off;
else return;
ItemStack item = EnchantUtils.getFishingRod(player);
if (item == null) return;
EnchantUtils.getExcellents(item, FishingEnchant.class).forEach((enchant, level) -> {
if (event.isCancelled()) return; // Check if event was cancelled by some enchantment.
if (enchant.isOutOfCharges(item)) return;
if (enchant.onFishing(event, item, level)) {
enchant.consumeCharges(item);

View File

@ -5,6 +5,7 @@ import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
@ -102,14 +103,14 @@ public class EnchantUtils {
ExcellentEnchant enchant = populator.getEnchantByChance(tier);
// В тире нет подходящих чар (вообще) для итема, исключаем и идем дальше.
if (enchant == null) {
populator.getEnchants().remove(tier);
populator.purge(tier);
continue;
}
// Среди уже добавленных чар есть конфликты с тем, что нашли.
// Исключаем, идем дальше.
if (enchantsToAdd.keySet().stream().anyMatch(has -> has.conflictsWith(enchant) || enchant.conflictsWith(has))) {
populator.getEnchants(tier).remove(enchant);
populator.purge(tier, enchant);
continue;
}
@ -117,12 +118,12 @@ public class EnchantUtils {
// Исключаем, идем дальше.
int level = levelFunc.apply(enchant);
if (level < enchant.getStartLevel()) {
populator.getEnchants(tier).remove(enchant);
populator.purge(tier, enchant);
continue;
}
// Добавляем чар, засчитываем попытку.
populator.getEnchants(tier).remove(enchant);
populator.purge(tier, enchant);
enchantsToAdd.put(enchant, level);
enchRoll--;
}
@ -202,6 +203,17 @@ public class EnchantUtils {
return true;
}
@Nullable
public static ItemStack getFishingRod(@NotNull Player player) {
ItemStack main = player.getInventory().getItem(EquipmentSlot.HAND);
if (main != null && main.getType() == Material.FISHING_ROD) return main;
ItemStack off = player.getInventory().getItem(EquipmentSlot.OFF_HAND);
if (off != null && off.getType() == Material.FISHING_ROD) return off;
return null;
}
@NotNull
public static Map<Enchantment, Integer> getAll(@NotNull ItemStack item) {
ItemMeta meta = item.getItemMeta();

View File

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

View File

@ -7,6 +7,7 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Set;
@ -16,5 +17,7 @@ public interface EnchantNMS {
void retrieveHook(@NotNull FishHook hook, @NotNull ItemStack item);
@Nullable ItemStack getSpawnEgg(@NotNull LivingEntity entity);
@NotNull Set<Block> handleFlameWalker(@NotNull LivingEntity entity, @NotNull Location location, int level);
}

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId>
<version>3.3.4</version>
<version>3.4.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -26,7 +26,7 @@
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId>
<version>3.3.4</version>
<version>3.4.0</version>
</dependency>
</dependencies>

View File

@ -5,6 +5,7 @@ import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.projectile.FishingHook;
import net.minecraft.world.item.SpawnEggItem;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.state.BlockState;
@ -22,6 +23,7 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nightexpress.excellentenchants.nms.EnchantNMS;
import java.util.HashSet;
@ -44,6 +46,18 @@ public class V1_17_R1 implements EnchantNMS {
handle.retrieve(CraftItemStack.asNMSCopy(item));
}
@Override
@Nullable
public ItemStack getSpawnEgg(@NotNull LivingEntity entity) {
CraftLivingEntity craftLivingEntity = (CraftLivingEntity) entity;
net.minecraft.world.entity.LivingEntity livingEntity = craftLivingEntity.getHandle();
SpawnEggItem eggItem = SpawnEggItem.byId(livingEntity.getType());
if (eggItem == null) return null;
return CraftItemStack.asBukkitCopy(eggItem.getDefaultInstance());
}
@Override
@NotNull
public Set<Block> handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) {

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId>
<version>3.3.4</version>
<version>3.4.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -26,7 +26,7 @@
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId>
<version>3.3.4</version>
<version>3.4.0</version>
</dependency>
</dependencies>

View File

@ -5,6 +5,7 @@ import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.projectile.FishingHook;
import net.minecraft.world.item.SpawnEggItem;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.state.BlockState;
@ -22,6 +23,7 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nightexpress.excellentenchants.nms.EnchantNMS;
import java.util.HashSet;
@ -44,6 +46,18 @@ public class V1_18_R2 implements EnchantNMS {
handle.retrieve(CraftItemStack.asNMSCopy(item));
}
@Override
@Nullable
public ItemStack getSpawnEgg(@NotNull LivingEntity entity) {
CraftLivingEntity craftLivingEntity = (CraftLivingEntity) entity;
net.minecraft.world.entity.LivingEntity livingEntity = craftLivingEntity.getHandle();
SpawnEggItem eggItem = SpawnEggItem.byId(livingEntity.getType());
if (eggItem == null) return null;
return CraftItemStack.asBukkitCopy(eggItem.getDefaultInstance());
}
@Override
@NotNull
public Set<Block> handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) {

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId>
<version>3.3.4</version>
<version>3.4.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -26,7 +26,7 @@
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId>
<version>3.3.4</version>
<version>3.4.0</version>
</dependency>
</dependencies>

View File

@ -5,6 +5,7 @@ import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.projectile.FishingHook;
import net.minecraft.world.item.SpawnEggItem;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.state.BlockState;
@ -22,6 +23,7 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nightexpress.excellentenchants.nms.EnchantNMS;
import java.util.HashSet;
@ -44,6 +46,18 @@ public class V1_19_R1 implements EnchantNMS {
handle.retrieve(CraftItemStack.asNMSCopy(item));
}
@Override
@Nullable
public ItemStack getSpawnEgg(@NotNull LivingEntity entity) {
CraftLivingEntity craftLivingEntity = (CraftLivingEntity) entity;
net.minecraft.world.entity.LivingEntity livingEntity = craftLivingEntity.getHandle();
SpawnEggItem eggItem = SpawnEggItem.byId(livingEntity.getType());
if (eggItem == null) return null;
return CraftItemStack.asBukkitCopy(eggItem.getDefaultInstance());
}
@Override
@NotNull
public Set<Block> handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) {

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId>
<version>3.3.4</version>
<version>3.4.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -26,7 +26,7 @@
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId>
<version>3.3.4</version>
<version>3.4.0</version>
</dependency>
</dependencies>

View File

@ -5,6 +5,7 @@ import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.projectile.FishingHook;
import net.minecraft.world.item.SpawnEggItem;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.state.BlockState;
@ -22,6 +23,7 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nightexpress.excellentenchants.nms.EnchantNMS;
import java.util.HashSet;
@ -44,6 +46,18 @@ public class V1_19_R2 implements EnchantNMS {
handle.retrieve(CraftItemStack.asNMSCopy(item));
}
@Override
@Nullable
public ItemStack getSpawnEgg(@NotNull LivingEntity entity) {
CraftLivingEntity craftLivingEntity = (CraftLivingEntity) entity;
net.minecraft.world.entity.LivingEntity livingEntity = craftLivingEntity.getHandle();
SpawnEggItem eggItem = SpawnEggItem.byId(livingEntity.getType());
if (eggItem == null) return null;
return CraftItemStack.asBukkitCopy(eggItem.getDefaultInstance());
}
@Override
@NotNull
public Set<Block> handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) {

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId>
<version>3.3.4</version>
<version>3.4.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -26,7 +26,7 @@
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId>
<version>3.3.4</version>
<version>3.4.0</version>
</dependency>
</dependencies>

View File

@ -5,6 +5,7 @@ import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.projectile.FishingHook;
import net.minecraft.world.item.SpawnEggItem;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.state.BlockState;
@ -22,6 +23,7 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nightexpress.excellentenchants.nms.EnchantNMS;
import java.util.HashSet;
@ -44,6 +46,18 @@ public class V1_19_R3 implements EnchantNMS {
handle.retrieve(CraftItemStack.asNMSCopy(item));
}
@Override
@Nullable
public ItemStack getSpawnEgg(@NotNull LivingEntity entity) {
CraftLivingEntity craftLivingEntity = (CraftLivingEntity) entity;
net.minecraft.world.entity.LivingEntity livingEntity = craftLivingEntity.getHandle();
SpawnEggItem eggItem = SpawnEggItem.byId(livingEntity.getType());
if (eggItem == null) return null;
return CraftItemStack.asBukkitCopy(eggItem.getDefaultInstance());
}
@Override
@NotNull
public Set<Block> handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) {

View File

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