mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2024-12-23 04:47:34 +01:00
Fixed an issue with custom arrows
This commit is contained in:
parent
4dac3c1445
commit
07f6247235
@ -2,6 +2,7 @@ package net.Indyuce.mmoitems.api.interaction.projectile;
|
|||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
|
import io.lumine.mythic.lib.player.particle.ParticleInformation;
|
||||||
import net.Indyuce.mmoitems.MMOItems;
|
import net.Indyuce.mmoitems.MMOItems;
|
||||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||||
|
|
||||||
@ -10,6 +11,10 @@ import org.bukkit.Particle;
|
|||||||
import org.bukkit.entity.Arrow;
|
import org.bukkit.entity.Arrow;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Merge with {@link ParticleInformation}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public class ArrowParticles extends BukkitRunnable {
|
public class ArrowParticles extends BukkitRunnable {
|
||||||
private final Arrow arrow;
|
private final Arrow arrow;
|
||||||
|
|
||||||
|
@ -49,6 +49,6 @@ public class Crossbow extends UntargetedWeapon {
|
|||||||
getPlayer().getEyeLocation().getDirection().multiply(3 * getValue(getNBTItem().getStat(ItemStats.ARROW_VELOCITY.getId()), 1)));
|
getPlayer().getEyeLocation().getDirection().multiply(3 * getValue(getNBTItem().getStat(ItemStats.ARROW_VELOCITY.getId()), 1)));
|
||||||
getPlayer().setVelocity(getPlayer().getVelocity().setX(0).setZ(0));
|
getPlayer().setVelocity(getPlayer().getVelocity().setX(0).setZ(0));
|
||||||
|
|
||||||
MMOItems.plugin.getEntities().registerCustomProjectile(getNBTItem(), stats, arrow, true);
|
MMOItems.plugin.getEntities().registerCustomProjectile(getNBTItem(), stats, arrow, true, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -286,7 +286,7 @@ public class PlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MMOItems.plugin.getEntities().registerCustomProjectile(nbtItem, playerData.getStats().newTemporary(EquipmentSlot.fromBukkit(item.getSlot())), event.getEntity(), type != null);
|
MMOItems.plugin.getEntities().registerCustomProjectile(nbtItem, playerData.getStats().newTemporary(EquipmentSlot.fromBukkit(item.getSlot())), event.getEntity(), type != null, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,12 +32,7 @@ public class EntityManager implements Listener {
|
|||||||
*/
|
*/
|
||||||
private final Map<Integer, EntityData> entities = new HashMap<>();
|
private final Map<Integer, EntityData> entities = new HashMap<>();
|
||||||
|
|
||||||
private final WeakHashMap<Integer, ProjectileData> projectiles = new WeakHashMap<>();
|
private final Map<Integer, ProjectileData> projectiles = new WeakHashMap<>();
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void registerCustomProjectile(NBTItem sourceItem, PlayerMetadata attacker, Entity entity, boolean customWeapon) {
|
|
||||||
registerCustomProjectile(sourceItem, attacker, entity, customWeapon, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a custom projectile. This is used for bows, crossbows and tridents.
|
* Registers a custom projectile. This is used for bows, crossbows and tridents.
|
||||||
@ -53,18 +48,19 @@ public class EntityManager implements Listener {
|
|||||||
*/
|
*/
|
||||||
public void registerCustomProjectile(@NotNull NBTItem sourceItem, @NotNull PlayerMetadata attacker, @NotNull Entity entity, boolean customWeapon, double damageMultiplicator) {
|
public void registerCustomProjectile(@NotNull NBTItem sourceItem, @NotNull PlayerMetadata attacker, @NotNull Entity entity, boolean customWeapon, double damageMultiplicator) {
|
||||||
|
|
||||||
|
// Initialize projectile data
|
||||||
|
ProjectileData projectileData = new ProjectileData(attacker, sourceItem, customWeapon);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For bows, MC default value is 7. When using custom bows, the attack
|
* For bows, MC default value is 7. When using custom bows, the attack
|
||||||
* damage stats returns the correct amount of damage. When using a vanilla
|
* damage stats returns the correct amount of damage. When using a vanilla
|
||||||
* bow, attack damage is set to 2 because it's the default fist damage value.
|
* bow, attack damage is set to 2 because it's the default fist damage value.
|
||||||
* Therefore MMOItems adds 5 to match the vanilla bow damage which is 7.
|
* Therefore MMOItems adds 5 to match the vanilla bow damage which is 7.
|
||||||
*
|
*
|
||||||
* Damage coefficient is how much you pull the bow. It's something between 0
|
* Damage coefficient is how much you pull the bow. It's a float between
|
||||||
* and 1 for bows, and it's always 1 for tridents or crossbows.
|
* 0 and 1 for bows, and it is always 1 for tridents or crossbows.
|
||||||
*/
|
*/
|
||||||
double damage = attacker.getStat("ATTACK_DAMAGE");
|
projectileData.setDamage((attacker.getStat("ATTACK_DAMAGE") + (customWeapon ? 0 : 5)) * damageMultiplicator);
|
||||||
damage = (customWeapon ? damage : 5 + damage) * damageMultiplicator;
|
|
||||||
attacker.setStat("ATTACK_DAMAGE", damage);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Load arrow particles if the entity is an arrow and if the item has
|
* Load arrow particles if the entity is an arrow and if the item has
|
||||||
@ -74,7 +70,7 @@ public class EntityManager implements Listener {
|
|||||||
if (entity instanceof Arrow && sourceItem.hasTag("MMOITEMS_ARROW_PARTICLES"))
|
if (entity instanceof Arrow && sourceItem.hasTag("MMOITEMS_ARROW_PARTICLES"))
|
||||||
new ArrowParticles((Arrow) entity, sourceItem);
|
new ArrowParticles((Arrow) entity, sourceItem);
|
||||||
|
|
||||||
projectiles.put(entity.getEntityId(), new ProjectileData(attacker, sourceItem, customWeapon));
|
projectiles.put(entity.getEntityId(), projectileData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerCustomEntity(Entity entity, EntityData data) {
|
public void registerCustomEntity(Entity entity, EntityData data) {
|
||||||
@ -106,13 +102,13 @@ public class EntityManager implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void a(EntityDeathEvent event) {
|
public void unregisterEntityData(EntityDeathEvent event) {
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(MMOItems.plugin, () -> unregisterCustomEntity(event.getEntity()));
|
Bukkit.getScheduler().scheduleSyncDelayedTask(MMOItems.plugin, () -> unregisterCustomEntity(event.getEntity()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Projectile damage and effects
|
// Projectile damage and effects
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void b(EntityDamageByEntityEvent event) {
|
public void applyOnHitEffects(EntityDamageByEntityEvent event) {
|
||||||
if (!(event.getDamager() instanceof Projectile) || !(event.getEntity() instanceof LivingEntity) || event.getEntity().hasMetadata("NPC"))
|
if (!(event.getDamager() instanceof Projectile) || !(event.getEntity() instanceof LivingEntity) || event.getEntity().hasMetadata("NPC"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -145,17 +141,13 @@ public class EntityManager implements Listener {
|
|||||||
// Unregister custom projectiles from the map
|
// Unregister custom projectiles from the map
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void c(EntityDamageByEntityEvent event) {
|
public void unregisterOnBlockHit(ProjectileHitEvent event) {
|
||||||
projectiles.remove(event.getEntity().getEntityId());
|
if (event.getHitBlock() != null)
|
||||||
|
projectiles.remove(event.getEntity().getEntityId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void d(ProjectileHitEvent event) {
|
public void unregisterOnEntityHit(EntityDeathEvent event) {
|
||||||
projectiles.remove(event.getEntity().getEntityId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void e(EntityDeathEvent event) {
|
|
||||||
projectiles.remove(event.getEntity().getEntityId());
|
projectiles.remove(event.getEntity().getEntityId());
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user