更新
This commit is contained in:
@@ -1,71 +1,58 @@
|
||||
package me.skymc.taboolib.damage;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import me.skymc.taboolib.TabooLib;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.skymc.taboolib.TabooLib;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class DamageUtils {
|
||||
|
||||
public static void damage(Player damager, LivingEntity victim, double damage)
|
||||
{
|
||||
dmg(damager, victim, damage);
|
||||
}
|
||||
|
||||
public static void damage(Player damager, Entity victim, double damage)
|
||||
{
|
||||
if (victim instanceof LivingEntity) {
|
||||
dmg(damager, (LivingEntity) victim, damage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void dmg(LivingEntity paramLivingEntity1, LivingEntity paramLivingEntity2, double paramDouble)
|
||||
{
|
||||
if ((paramLivingEntity2.hasMetadata("NPC")) || (paramLivingEntity1.hasMetadata("NPC"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object localObject1 = null;
|
||||
try
|
||||
{
|
||||
localObject1 = paramLivingEntity1.getClass().getDeclaredMethod("getHandle", new Class[0]).invoke(paramLivingEntity1);
|
||||
}
|
||||
catch (IllegalAccessException|IllegalArgumentException|InvocationTargetException|NoSuchMethodException|SecurityException localIllegalAccessException1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Object localObject2 = null;
|
||||
try
|
||||
{
|
||||
localObject2 = paramLivingEntity2.getClass().getDeclaredMethod("getHandle", new Class[0]).invoke(paramLivingEntity2);
|
||||
}
|
||||
catch (IllegalAccessException|IllegalArgumentException|InvocationTargetException|NoSuchMethodException|SecurityException localIllegalAccessException2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Class<?> DamageSource = nmsClass("DamageSource");
|
||||
Object localObject3 = DamageSource.getDeclaredMethod("playerAttack", new Class[]{nmsClass("EntityHuman")}).invoke(DamageSource, localObject1);
|
||||
|
||||
localObject2.getClass().getDeclaredMethod("damageEntity", new Class[]{DamageSource, Float.TYPE}).invoke(localObject2, localObject3, (float) paramDouble);
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException ignored)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private static Class<?> nmsClass(String paramString)
|
||||
{
|
||||
String str = "net.minecraft.server." + TabooLib.getVersion() + "." + paramString;
|
||||
try {
|
||||
return Class.forName(str);
|
||||
} catch (ClassNotFoundException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static void damage(Player player, LivingEntity victim, double damage) {
|
||||
dmg(player, victim, damage);
|
||||
}
|
||||
|
||||
public static void damage(Player player, Entity victim, double damage) {
|
||||
if (victim instanceof LivingEntity) {
|
||||
dmg(player, (LivingEntity) victim, damage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void dmg(LivingEntity paramLivingEntity1, LivingEntity paramLivingEntity2, double paramDouble) {
|
||||
if ((paramLivingEntity2.hasMetadata("NPC")) || (paramLivingEntity1.hasMetadata("NPC"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object localObject1;
|
||||
try {
|
||||
localObject1 = paramLivingEntity1.getClass().getDeclaredMethod("getHandle").invoke(paramLivingEntity1);
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException localIllegalAccessException1) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object localObject2;
|
||||
try {
|
||||
localObject2 = paramLivingEntity2.getClass().getDeclaredMethod("getHandle").invoke(paramLivingEntity2);
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException localIllegalAccessException2) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Class<?> DamageSource = nmsClass("DamageSource");
|
||||
Object localObject3 = DamageSource.getDeclaredMethod("playerAttack", nmsClass("EntityHuman")).invoke(DamageSource, localObject1);
|
||||
|
||||
localObject2.getClass().getDeclaredMethod("damageEntity", new Class[]{DamageSource, Float.TYPE}).invoke(localObject2, localObject3, (float) paramDouble);
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private static Class<?> nmsClass(String paramString) {
|
||||
String str = "net.minecraft.server." + TabooLib.getVersion() + "." + paramString;
|
||||
try {
|
||||
return Class.forName(str);
|
||||
} catch (ClassNotFoundException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,19 +5,18 @@ import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
||||
public class GetDamager {
|
||||
|
||||
public static Player get(EntityDamageByEntityEvent e) {
|
||||
Player p = null;
|
||||
if (e.getDamager() instanceof Projectile) {
|
||||
Projectile arrow = (Projectile) e.getDamager();
|
||||
if (arrow.getShooter() instanceof Player) {
|
||||
p = (Player) arrow.getShooter();
|
||||
}
|
||||
}
|
||||
else if (e.getDamager() instanceof Player) {
|
||||
p = (Player) e.getDamager();
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
public static Player get(EntityDamageByEntityEvent e) {
|
||||
Player p = null;
|
||||
if (e.getDamager() instanceof Projectile) {
|
||||
Projectile arrow = (Projectile) e.getDamager();
|
||||
if (arrow.getShooter() instanceof Player) {
|
||||
p = (Player) arrow.getShooter();
|
||||
}
|
||||
} else if (e.getDamager() instanceof Player) {
|
||||
p = (Player) e.getDamager();
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,19 +5,18 @@ import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
|
||||
public class GetKiller {
|
||||
|
||||
public static Player get(EntityDeathEvent e) {
|
||||
Player p = null;
|
||||
if (e.getEntity().getKiller() instanceof Projectile) {
|
||||
Projectile arrow = (Projectile) e.getEntity().getKiller();
|
||||
if (arrow.getShooter() instanceof Player) {
|
||||
p = (Player) arrow.getShooter();
|
||||
}
|
||||
}
|
||||
else if (e.getEntity().getKiller() instanceof Player) {
|
||||
p = e.getEntity().getKiller();
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
public static Player get(EntityDeathEvent e) {
|
||||
Player p = null;
|
||||
if (e.getEntity().getKiller() instanceof Projectile) {
|
||||
Projectile arrow = (Projectile) e.getEntity().getKiller();
|
||||
if (arrow.getShooter() instanceof Player) {
|
||||
p = (Player) arrow.getShooter();
|
||||
}
|
||||
} else if (e.getEntity().getKiller() != null) {
|
||||
p = e.getEntity().getKiller();
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user