mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Did changes
This commit is contained in:
parent
2264b85399
commit
4dad8a1589
@ -7,6 +7,7 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler;
|
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -16,13 +17,23 @@ import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface EntityHitHandler extends ItemHandler {
|
public interface WeaponUseHandler extends ItemHandler {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is called when an {@link Player} attacks an {@link Entity} with a {@link SlimefunItem}
|
||||||
|
*
|
||||||
|
* @param e
|
||||||
|
* The {@link EntityDamageByEntityEvent} that was fired
|
||||||
|
* @param player
|
||||||
|
* The {@link Player} that used the weapon
|
||||||
|
* @param item
|
||||||
|
* The {@link ItemStack} that was used to attack
|
||||||
|
*/
|
||||||
void onHit(@Nonnull EntityDamageByEntityEvent e, @Nonnull Player player, @Nonnull ItemStack item);
|
void onHit(@Nonnull EntityDamageByEntityEvent e, @Nonnull Player player, @Nonnull ItemStack item);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default Class<? extends ItemHandler> getIdentifier() {
|
default Class<? extends ItemHandler> getIdentifier() {
|
||||||
return EntityHitHandler.class;
|
return WeaponUseHandler.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -13,7 +13,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
|
|
||||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
|
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
|
||||||
import io.github.thebusybiscuit.slimefun4.api.items.settings.IntRangeSetting;
|
import io.github.thebusybiscuit.slimefun4.api.items.settings.IntRangeSetting;
|
||||||
import io.github.thebusybiscuit.slimefun4.core.handlers.EntityHitHandler;
|
import io.github.thebusybiscuit.slimefun4.core.handlers.WeaponUseHandler;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
|
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.SlimefunItemHitListener;
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.SlimefunItemHitListener;
|
||||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||||
@ -29,7 +29,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
|||||||
* @see SlimefunItemHitListener
|
* @see SlimefunItemHitListener
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class VampireBlade extends SimpleSlimefunItem<EntityHitHandler> {
|
public class VampireBlade extends SimpleSlimefunItem<WeaponUseHandler> {
|
||||||
|
|
||||||
private static final double HEALING_AMOUNT = 4.0;
|
private static final double HEALING_AMOUNT = 4.0;
|
||||||
|
|
||||||
@ -42,9 +42,8 @@ public class VampireBlade extends SimpleSlimefunItem<EntityHitHandler> {
|
|||||||
addItemSetting(chance);
|
addItemSetting(chance);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public EntityHitHandler getItemHandler() {
|
public @Nonnull WeaponUseHandler getItemHandler() {
|
||||||
return (e, p, item) -> {
|
return (e, p, item) -> {
|
||||||
if (ThreadLocalRandom.current().nextInt(100) < getChance()) {
|
if (ThreadLocalRandom.current().nextInt(100) < getChance()) {
|
||||||
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 0.7F, 0.7F);
|
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 0.7F, 0.7F);
|
||||||
|
@ -2,7 +2,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.listeners;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@ -10,13 +9,13 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import io.github.thebusybiscuit.slimefun4.core.handlers.EntityHitHandler;
|
import io.github.thebusybiscuit.slimefun4.core.handlers.WeaponUseHandler;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.VampireBlade;
|
import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.VampireBlade;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This {@link Listener} is responsible for calling the {@link EntityHitHandler}.
|
* This {@link Listener} is responsible for calling the {@link WeaponUseHandler}.
|
||||||
*
|
*
|
||||||
* @author Mooy1
|
* @author Mooy1
|
||||||
*
|
*
|
||||||
@ -36,14 +35,13 @@ public class SlimefunItemHitListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Player p = (Player) e.getDamager();
|
Player p = (Player) e.getDamager();
|
||||||
|
|
||||||
ItemStack item = p.getInventory().getItemInMainHand();
|
ItemStack item = p.getInventory().getItemInMainHand();
|
||||||
|
|
||||||
if (item.getType() != Material.AIR) {
|
if (!item.getType().isAir()) {
|
||||||
SlimefunItem sfItem = SlimefunItem.getByItem(item);
|
SlimefunItem sfItem = SlimefunItem.getByItem(item);
|
||||||
|
|
||||||
if (sfItem != null && sfItem.canUse(p, true)) {
|
if (sfItem != null && sfItem.canUse(p, true)) {
|
||||||
sfItem.callItemHandler(EntityHitHandler.class, handler -> handler.onHit(e, p, item));
|
sfItem.callItemHandler(WeaponUseHandler.class, handler -> handler.onHit(e, p, item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user